libfs

package
v0.0.0-...-fa4cddc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WriteLock int = 0
	ReadLock  int = 1
)
View Source
const InvalidHandle = int(-1)

Variables

This section is empty.

Functions

func Assert

func Assert(bOk bool)

func PullThirdPartyUser

func PullThirdPartyUser(cfg conf.Config, log *ClientLogger) (u *conf.UserInfo, err error)

TODO: pull user info and update mem periodically

Types

type Buffer

type Buffer struct {
	Id uint32

	BlkIdx uint64
	Offset uint32
	Len    uint32

	LastUpdateTime time.Time
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer(Id uint32) *Buffer

func (*Buffer) CanMerge

func (buf *Buffer) CanMerge(Offset uint32) bool

func (*Buffer) GetAlignOffset

func (buf *Buffer) GetAlignOffset() uint64

func (*Buffer) GetData

func (buf *Buffer) GetData() []byte

func (*Buffer) GetFileOffset

func (buf *Buffer) GetFileOffset() uint64

func (*Buffer) GetRangeData

func (buf *Buffer) GetRangeData(Start uint32, End uint32) []byte

func (*Buffer) GetTailOffset

func (buf *Buffer) GetTailOffset() uint64

func (*Buffer) IsFull

func (buf *Buffer) IsFull(BlockSize uint32) bool

func (*Buffer) MergeData

func (buf *Buffer) MergeData(data []byte)

func (*Buffer) ReSet

func (buf *Buffer) ReSet(fe *FileEntry, BlkIdx uint64)

func (*Buffer) Skip

func (buf *Buffer) Skip(Offset uint32)

type CacheLock

type CacheLock struct {
	// contains filtered or unexported fields
}

type CfaMountInfo

type CfaMountInfo struct {
	Volume    string // "CFA"
	ClientId  string
	Path      string   // path prefix
	MountStu  MountStu // mount status
	User      *conf.UserInfo
	MountMode MountMode // Access permission of the mount path
	Cfg       conf.Config
	sync.Mutex

	// file operation related
	OpenFileMax int    // max open files
	LsSize      uint16 // max items for a single 'ls' op, default 2000
	// contains filtered or unexported fields
}

func NewMount

func NewMount(cfg conf.Config) (*CfaMountInfo, error)

func (*CfaMountInfo) Chmod

func (mount *CfaMountInfo) Chmod(path string, mode uint32) error

change permission

func (*CfaMountInfo) Chown

func (mount *CfaMountInfo) Chown(path string, uid, gid uint32) error

func (*CfaMountInfo) ChownEx

func (mount *CfaMountInfo) ChownEx(path string, owner, group string) error

change owner, group

func (*CfaMountInfo) Close

func (mount *CfaMountInfo) Close(fd int) error

func (*CfaMountInfo) DelMount

func (mount *CfaMountInfo) DelMount()

func (*CfaMountInfo) Fchmod

func (mount *CfaMountInfo) Fchmod(fd int, mode uint32) error

change permission

func (*CfaMountInfo) Fgetxattr

func (mount *CfaMountInfo) Fgetxattr(fd int, key string) ([]byte, error)

func (*CfaMountInfo) Flistxattr

func (mount *CfaMountInfo) Flistxattr(fd int) ([]string, error)

func (*CfaMountInfo) Flush

func (mount *CfaMountInfo) Flush(fd int) error

func (*CfaMountInfo) Fremovexattr

func (mount *CfaMountInfo) Fremovexattr(fd int, key string) error

func (*CfaMountInfo) Fsetxattr

func (mount *CfaMountInfo) Fsetxattr(fd int, key string, value []byte, flag int) error

func (*CfaMountInfo) Fstat

func (mount *CfaMountInfo) Fstat(fd int) (*Dentry, error)

func (*CfaMountInfo) Fsync

func (mount *CfaMountInfo) Fsync(fd int, datasync int) error

func (*CfaMountInfo) Ftruncate

func (mount *CfaMountInfo) Ftruncate(fd int, size uint64) error

func (*CfaMountInfo) GetLogger

func (mount *CfaMountInfo) GetLogger() *zap.Logger

func (*CfaMountInfo) GetProxyClient

func (mount *CfaMountInfo) GetProxyClient() *api.ProxyClient

func (*CfaMountInfo) GetSimpleFileEntry

func (mount *CfaMountInfo) GetSimpleFileEntry(dentry *Dentry) *FileEntry

func (*CfaMountInfo) Getxattr

func (mount *CfaMountInfo) Getxattr(path string, key string) ([]byte, error)
func (mount *CfaMountInfo) Link(path, linkPath string) error

create hard link

func (*CfaMountInfo) Listxattr

func (mount *CfaMountInfo) Listxattr(path string) ([]string, error)

func (*CfaMountInfo) Mkdir

func (mount *CfaMountInfo) Mkdir(path string, mode uint32) error

mkdir

func (*CfaMountInfo) MkdirAll

func (mount *CfaMountInfo) MkdirAll(path string, mode uint32) error

cmd line 'mkdir -p'

func (*CfaMountInfo) Mknod

func (mount *CfaMountInfo) Mknod(path string, mode uint32, dev int) error

func (*CfaMountInfo) Mount

func (mount *CfaMountInfo) Mount() error

func (*CfaMountInfo) Open

func (mount *CfaMountInfo) Open(path string, flags int, mode uint32) (int, error)

func (*CfaMountInfo) Opendir

func (mount *CfaMountInfo) Opendir(path string) (*Dir, error)

Opendir reads all items under the dir

func (*CfaMountInfo) Read

func (mount *CfaMountInfo) Read(fd int, buffer []byte, offset uint64) (int, error)
func (mount *CfaMountInfo) Readlink(path string) (string, error)

reads a soft link file and returns the target file name

func (*CfaMountInfo) Removexattr

func (mount *CfaMountInfo) Removexattr(path string, key string) error

func (*CfaMountInfo) Rename

func (mount *CfaMountInfo) Rename(srcpath string, dstpath string) error

the rename op

func (*CfaMountInfo) RmDirTree

func (mount *CfaMountInfo) RmDirTree(path string) error

force remove a dir and it's subdirs

func (*CfaMountInfo) Rmdir

func (mount *CfaMountInfo) Rmdir(path string) error

remove an empty directory

func (*CfaMountInfo) SetLogLevel

func (mount *CfaMountInfo) SetLogLevel(flag int)

flag > 0 turns up the level

func (*CfaMountInfo) Setxattr

func (mount *CfaMountInfo) Setxattr(path string, key string, value []byte, flag SetXattrFlag) error

func (*CfaMountInfo) Stat

func (mount *CfaMountInfo) Stat(path string) (*Dentry, error)

func (*CfaMountInfo) StatTo

func (mount *CfaMountInfo) StatTo()

do the statistics log job

func (*CfaMountInfo) Statfs

func (mount *CfaMountInfo) Statfs(path string, stat *Statfs) error
func (mount *CfaMountInfo) Symlink(path, linkPath string) error

create soft link

func (*CfaMountInfo) Truncate

func (mount *CfaMountInfo) Truncate(path string, length uint64) error
func (mount *CfaMountInfo) UnLink(path string) error

delete a file

func (*CfaMountInfo) UseRWCache

func (mount *CfaMountInfo) UseRWCache(fdEntry *FileEntry) bool

func (*CfaMountInfo) Utime

func (mount *CfaMountInfo) Utime(path string, utime uint64, atime uint64) error

func (*CfaMountInfo) Write

func (mount *CfaMountInfo) Write(fd int, buffer []byte, offset uint64) (int, error)

type DentryCache

type DentryCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDentryCache

func NewDentryCache(cacheSize int, expireTimeMs int) *DentryCache

func (*DentryCache) Get

func (cache *DentryCache) Get(k interface{}) (v interface{}, ret bool, err error)

func (*DentryCache) Remove

func (cache *DentryCache) Remove(k interface{}) bool

func (*DentryCache) RemovePrefix

func (cache *DentryCache) RemovePrefix(prefix interface{}) error

func (*DentryCache) Set

func (cache *DentryCache) Set(k, v interface{}) error

type Dir

type Dir struct {
	Error error

	sync.Mutex
	// contains filtered or unexported fields
}

func (*Dir) CloseDir

func (dir *Dir) CloseDir() error

func (*Dir) Readdir

func (dir *Dir) Readdir(count uint) ([]Dentry, error)

read 'count' items under the dir

type FileBuffer

type FileBuffer struct {
	sync.RWMutex

	BufferMap map[uint64]*Buffer
	LockMap   map[uint64]*CacheLock
	// contains filtered or unexported fields
}

func NewFileBuffer

func NewFileBuffer(fe *FileEntry) *FileBuffer

func (*FileBuffer) AttachBuffer

func (fileBuf *FileBuffer) AttachBuffer(blkIdx uint64, buffer *Buffer)

func (*FileBuffer) DetachBuffer

func (fileBuf *FileBuffer) DetachBuffer(blkIdx uint64)

func (*FileBuffer) GetAllBufferIndex

func (fileBuf *FileBuffer) GetAllBufferIndex() []uint64

func (*FileBuffer) GetBuffer

func (fileBuf *FileBuffer) GetBuffer(blkIdx uint64) *Buffer

func (*FileBuffer) IsZeroCache

func (fileBuf *FileBuffer) IsZeroCache() bool

func (*FileBuffer) LockBuffer

func (fileBuf *FileBuffer) LockBuffer(blkIdx uint64)

func (*FileBuffer) RLockBuffer

func (fileBuf *FileBuffer) RLockBuffer(blkIdx uint64)

func (*FileBuffer) RUnLockBuffer

func (fileBuf *FileBuffer) RUnLockBuffer(blkIdx uint64)

func (*FileBuffer) UnLockBuffer

func (fileBuf *FileBuffer) UnLockBuffer(blkIdx uint64)

func (*FileBuffer) UpperIdx

func (fileBuf *FileBuffer) UpperIdx() uint64

func (*FileBuffer) Wait

func (fileBuf *FileBuffer) Wait()

type FileCache

type FileCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

read write Cache

func NewFileCache

func NewFileCache(openFileMax int) *FileCache

func (*FileCache) CloseFile

func (fileCache *FileCache) CloseFile(handle uint32) error

func (*FileCache) GetFileEntry

func (fileCache *FileCache) GetFileEntry(handle uint32) (*FileEntry, error)

func (*FileCache) GetMinEntryIndex

func (fileCache *FileCache) GetMinEntryIndex() uint32

func (*FileCache) IsLastRefer

func (fileCache *FileCache) IsLastRefer(fileEntry *FileEntry) bool

func (*FileCache) NewFile

func (fileCache *FileCache) NewFile(fd *int, fileEntry *FileEntry) error

type FileEntry

type FileEntry struct {
	sync.RWMutex
	Id        uint64 // file's dentry id
	BlockSize uint32 // block size
	Handle    int    // upper-layer file handle
	FilePath  string // file path
	OpenFlag  int
	Mode      uint32 // permission

	DirectIO bool // Direct IO

	Owner          string // Flock owner
	Pid            uint32 // Flock pid
	LastAccessTime time.Time
	// contains filtered or unexported fields
}

type LsStatus

type LsStatus int
const (
	LsFetching LsStatus = iota
	LsDone
	LsError
	LsUserAbort
)

type MountStu

type MountStu int
const (
	MountStuNew     MountStu = 0
	MountStuMounted MountStu = 1
	MountStuDel     MountStu = 2
)

type PrefetchWindow

type PrefetchWindow struct {
	BlkStart uint64
	BlkEnd   uint64
}

func NewPrefetchWindow

func NewPrefetchWindow() *PrefetchWindow

func (*PrefetchWindow) Cross

func (pw *PrefetchWindow) Cross(rw *PrefetchWindow) bool

func (*PrefetchWindow) Extend

func (pw *PrefetchWindow) Extend(Times uint32)

func (*PrefetchWindow) GetEnd

func (pw *PrefetchWindow) GetEnd() uint64

func (*PrefetchWindow) GetStart

func (pw *PrefetchWindow) GetStart() uint64

func (*PrefetchWindow) Move

func (pw *PrefetchWindow) Move()

func (*PrefetchWindow) Reset

func (pw *PrefetchWindow) Reset()

func (*PrefetchWindow) Shift

func (pw *PrefetchWindow) Shift(Step uint64)

func (*PrefetchWindow) Size

func (pw *PrefetchWindow) Size() uint32

type RCache

type RCache struct {
	sync.RWMutex
	Mount     *CfaMountInfo
	BufferMax int
	FreeList  *list.List
	Cache     map[uint64]*FileBuffer
	LruList   *list.List

	ExpireTime int

	PrefetchRoutine int
	PrefetchTimes   int

	Stop bool
	// contains filtered or unexported fields
}

func NewRCache

func NewRCache(mount *CfaMountInfo, BufferMax int, ExpireTime int, PrefetchRoutine int, PrefetchTimes int) *RCache

func (*RCache) AllocBuffer

func (cache *RCache) AllocBuffer(fe *FileEntry, BlkIdx uint64) *Buffer

func (*RCache) CheckExpire

func (cache *RCache) CheckExpire() error

func (*RCache) Clean

func (cache *RCache) Clean(fe *FileEntry, Size int, offset uint64) error

func (*RCache) Close

func (cache *RCache) Close(fe *FileEntry) error

func (*RCache) CloseAll

func (cache *RCache) CloseAll()

func (*RCache) DetachFileBuffer

func (cache *RCache) DetachFileBuffer(fe *FileEntry)

func (*RCache) DirectRead

func (cache *RCache) DirectRead(fe *FileEntry, buffer []byte, offset uint64) (int, error)

func (*RCache) DoLru

func (cache *RCache) DoLru(buf *Buffer)

func (*RCache) DoPrefetch

func (cache *RCache) DoPrefetch(fileBuf *FileBuffer, Size uint32, offset uint64)

func (*RCache) DoPrefetchRead

func (cache *RCache) DoPrefetchRead(fileBuf *FileBuffer, op *RWBlockOp) error

func (*RCache) FreeBuffer

func (cache *RCache) FreeBuffer(buf *Buffer)

func (*RCache) GetFileBuffer

func (cache *RCache) GetFileBuffer(fe *FileEntry, bAlloc bool) *FileBuffer

func (*RCache) GetReadWindow

func (cache *RCache) GetReadWindow(fe *FileEntry, Size uint32, offset uint64) *PrefetchWindow

func (*RCache) LruExpire

func (cache *RCache) LruExpire() (fe *FileEntry, blkIdx uint64)

func (*RCache) PrefetchRead

func (cache *RCache) PrefetchRead() error

func (*RCache) ReadOp

func (cache *RCache) ReadOp(fe *FileEntry, fileBuf *FileBuffer, op RWBlockOp) (int, error)

func (*RCache) Release

func (cache *RCache) Release(fe *FileEntry) error

func (*RCache) ReleaseBuffer

func (cache *RCache) ReleaseBuffer(fileBuf *FileBuffer, Index uint64) error

func (*RCache) RemoveLru

func (cache *RCache) RemoveLru(buf *Buffer)

func (*RCache) Slice

func (cache *RCache) Slice(fe *FileEntry, buffer []byte, offset uint64) []RWBlockOp

func (*RCache) TryDoPrefetch

func (cache *RCache) TryDoPrefetch(fileBuf *FileBuffer, Size uint32, offset uint64)

type RWBlockOp

type RWBlockOp struct {
	Index    uint64 //	fragment index
	RwOffset uint32 //	fragment internal offset corresponding to the write operation
	RwSize   uint32 //	data size corresponding to the Write operation
	// contains filtered or unexported fields
}

func (*RWBlockOp) GetAlignOffset

func (op *RWBlockOp) GetAlignOffset() uint64

func (*RWBlockOp) GetFileOffset

func (op *RWBlockOp) GetFileOffset() uint64

func (*RWBlockOp) IsFull

func (op *RWBlockOp) IsFull() bool

type RWCache

type RWCache struct {
	Mount *CfaMountInfo
	// contains filtered or unexported fields
}

func NewRWCache

func NewRWCache(mount *CfaMountInfo, BufferMax int, ExpireTime int, SyncRoutine int, PrefetchRoutine int, PrefetchTimes int) *RWCache

func (*RWCache) Close

func (cache *RWCache) Close(fe *FileEntry) error

func (*RWCache) CloseAll

func (cache *RWCache) CloseAll()

func (*RWCache) Flush

func (cache *RWCache) Flush(fe *FileEntry) error

func (*RWCache) Read

func (cache *RWCache) Read(fe *FileEntry, buffer []byte, offset uint64) (int, error)

func (*RWCache) Release

func (cache *RWCache) Release(fe *FileEntry) error

func (*RWCache) Write

func (cache *RWCache) Write(fe *FileEntry, buffer []byte, offset uint64) (int, error)

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(mount *CfaMountInfo, entry *FileEntry) *Reader

func (*Reader) Read

func (reader *Reader) Read(id uint64, buffer []byte, offset uint64) (int, error)

type Statfs

type Statfs struct {
	BlockSize uint32 // block size of the current file system
	Blocks    uint32 // block number of the current file system
	Files     uint32 // file numbers of the current dir, non-recursive
	Folders   uint32 // sub dir numbers under the current dir, non-recursive
	Fbytes    uint64 // size of all files under the current dir, non-recursive
	Fubytes   uint64 // space occupied by files in the current directory, non-recursive
	Rfiles    uint64 // file numbers of the current dir, the whole subtree
	Rfolders  uint64 // sub dir numbers under the current dir, the whole subtree
	Rbytes    uint64 // size of all files under the current dir, the whole subtree
	Rubytes   uint64 // space occupied by files in the current directory, the whole subtree
}

目录的统计信息

type WCache

type WCache struct {
	sync.RWMutex
	Mount     *CfaMountInfo
	BufferMax int
	FreeList  *list.List
	Cache     map[uint64]*FileBuffer
	LruList   *list.List

	ExpireTime int

	SyncRoutine int

	Stop bool
	// contains filtered or unexported fields
}

func NewWCache

func NewWCache(mount *CfaMountInfo, BufferMax int, ExpireTime int, SyncRoutine int) *WCache

func (*WCache) AllocBuffer

func (cache *WCache) AllocBuffer(fe *FileEntry, BlkIdx uint64) *Buffer

func (*WCache) CheckExpire

func (cache *WCache) CheckExpire() error

func (*WCache) Close

func (cache *WCache) Close(fe *FileEntry) error

func (*WCache) CloseAll

func (cache *WCache) CloseAll()

func (*WCache) DetachFileBuffer

func (cache *WCache) DetachFileBuffer(fe *FileEntry)

func (*WCache) DirectWrite

func (cache *WCache) DirectWrite(fe *FileEntry, buffer []byte, offset uint64) (int, error)

func (*WCache) DoLru

func (cache *WCache) DoLru(buf *Buffer)

func (*WCache) Flush

func (cache *WCache) Flush(fe *FileEntry) error

func (*WCache) FlushBuffer

func (cache *WCache) FlushBuffer(fileBuf *FileBuffer, Index uint64) error

func (*WCache) FreeBuffer

func (cache *WCache) FreeBuffer(buf *Buffer)

func (*WCache) GetFileBuffer

func (cache *WCache) GetFileBuffer(fe *FileEntry, bAlloc bool) *FileBuffer

bAlloc 是否申请file buf

func (*WCache) LruExpire

func (cache *WCache) LruExpire() (fe *FileEntry, blkIdx uint64)

func (*WCache) MergeOp

func (cache *WCache) MergeOp(fileBuf *FileBuffer, op RWBlockOp, dataSize int) int

func (*WCache) RemoveLru

func (cache *WCache) RemoveLru(buf *Buffer)

func (*WCache) Slice

func (cache *WCache) Slice(fe *FileEntry, buffer []byte, offset uint64) []RWBlockOp

func (*WCache) StatSize

func (cache *WCache) StatSize(fe *FileEntry) (uint64, error)

func (*WCache) SyncIo

func (cache *WCache) SyncIo() bool

func (*WCache) SyncWrite

func (cache *WCache) SyncWrite() error

func (*WCache) Write

func (cache *WCache) Write(fe *FileEntry, buffer []byte, offset uint64) (int, error)

func (*WCache) WriteOp

func (cache *WCache) WriteOp(fe *FileEntry, fileBuf *FileBuffer, op RWBlockOp) (bool, int, error)

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(mount *CfaMountInfo, fdEntry *FileEntry) *Writer

func (*Writer) Write

func (writer *Writer) Write(id uint64, buffer []byte, offset uint64) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL