Documentation ¶
Overview ¶
ossfs 这个包 主要是从objectfs copy过来,然后进行调整性优化。 为了避免 1 不成熟的修改直接影响代码的本来面目
2 假若修改失败,能够进行一定程度的比对
Index ¶
- Constants
- Variables
- func CleanLoop(root Node)
- func Getinodesum() int
- func InodeCacheCheck(nodesum int)
- type DataCache
- type Driver
- type FileInfo
- type FileSystemConnector
- func (c *FileSystemConnector) DeleteNotify(dir *Inode, child *Inode, name string) fuse.Status
- func (c *FileSystemConnector) EntryNotify(node *Inode, name string) fuse.Status
- func (c *FileSystemConnector) FileNotify(node *Inode, off int64, length int64) fuse.Status
- func (c *FileSystemConnector) InodeHandleCount() int
- func (c *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode
- func (c *FileSystemConnector) Mount(parent *Inode, name string, root Node, opts *Options) fuse.Status
- func (c *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []string)
- func (c *FileSystemConnector) RawFS() fuse.RawFileSystem
- func (c *FileSystemConnector) Server() *fuse.Server
- func (c *FileSystemConnector) SetDebug(debug bool)
- func (c *FileSystemConnector) Unmount(node *Inode) fuse.Status
- type Inode
- func (n *Inode) AddChild(name string, child *Inode)
- func (n *Inode) AddOpenedFile(opfile *openedFile)
- func (n *Inode) AddParent(parent *parentData)
- func (n *Inode) Children() (out map[string]*Inode)
- func (n *Inode) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file *FileInfo, child *Inode, code fuse.Status)
- func (n *Inode) EventFileFree(opflags uint32)
- func (n *Inode) EventFileUsed(opflags uint32)
- func (n *Inode) EventNodeFree()
- func (n *Inode) EventNodeUsed()
- func (n *Inode) EventRefreshLastAccessTime()
- func (n *Inode) Fileinfo() *FileInfo
- func (n *Inode) FsChildren() (out map[string]*Inode)
- func (n *Inode) GetAllParent() []*parentData
- func (n *Inode) GetChild(name string) *Inode
- func (n *Inode) GetChildren() []fuse.DirEntry
- func (n *Inode) GetDirChildren() []*Inode
- func (n *Inode) GetFilesWithMask(mask uint32) (files []*FileInfo)
- func (n *Inode) GetFirstParent() *parentData
- func (o *Inode) GetLocOpenedCount() (r, w, t int)
- func (n *Inode) GetParentCount() int
- func (n *Inode) GetRefreshSolt() bool
- func (o *Inode) GetTolOpenedCount() (r, w, t int)
- func (n *Inode) IsDir() bool
- func (n *Inode) NewChild(fileinfo *FileInfo, fsi Node) *Inode
- func (n *Inode) Node() Node
- func (n *Inode) RefreshCheck(fixname string)
- func (n *Inode) RefreshChild(fixname string) map[string]*FileInfo
- func (n *Inode) ReleaseOpenedFile(handle uint64, opfile *openedFile)
- func (n *Inode) ReleaseRefreshSolt(isfull bool)
- func (n *Inode) RemoveParent(parentinode *Inode)
- func (n *Inode) RenameChild(name, newname string) bool
- func (n *Inode) RmChild(name string) (ch *Inode)
- type InodeRefreshQueue
- type InodeRefreshQueueNode
- type Node
- type Options
- type Ossfs
- type TreeWatcher
- type WithFlags
Constants ¶
const ( PROCESSING = iota DONE )
Variables ¶
var Debug = false
Manage filehandles of open files.
var FullRefreshThreshold = int(20)
对同一个文件的刷新子请求,大于指定值,直接刷新全目录
var MaxInodeSumErr = errors.New("no free inode")
var MaxInodesSum = int(5000000)
Functions ¶
func Getinodesum ¶
func Getinodesum() int
func InodeCacheCheck ¶
func InodeCacheCheck(nodesum int)
Types ¶
type DataCache ¶
type DataCache interface { WriteAt(handle uint64, fullpath string, fileinfo *FileInfo, data []byte, off int64) (err error) ReadAt(handle uint64, fullpath string, fileinfo *FileInfo, size, off int64, data []byte) (ressize int64, err error) Truncate(fileinfo *FileInfo, size uint64) RemoveFile(fileinfo *FileInfo) SyncFile(fileinfo *FileInfo, anywrite bool) error CloseFile(fileinfo *FileInfo, fullpath string, anywrite bool) error RenameOpFile(fileinfo *FileInfo, oldfullpath string, newfullpath string) error }
type Driver ¶
type Driver interface { // Used for pretty printing. String() string // Attributes. This function is the main entry point, through // which FUSE discovers which files and directories exist. // // If the filesystem wants to implement hard-links, it should // return consistent non-zero FileInfo.Ino data. Using // hardlinks incurs a performance hit. GetAttr(name string, context *fuse.Context) (*FileInfo, fuse.Status) // These should update the file's ctime too. Chmod(name string, mode uint32, context *fuse.Context) (code fuse.Status) Chown(name string, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *fuse.Context) (code fuse.Status) Truncate(name string, size uint64, context *fuse.Context) (code fuse.Status) Access(name string, mode uint32, context *fuse.Context) (code fuse.Status) // Tree structure Link(oldName string, newName string, context *fuse.Context) (code fuse.Status) Mkdir(name string, mode uint32, context *fuse.Context) fuse.Status Mknod(name string, mode uint32, dev uint32, context *fuse.Context) fuse.Status Rename(file *FileInfo, oldName string, newName string, context *fuse.Context) (code fuse.Status) Rmdir(name string, context *fuse.Context) (code fuse.Status) Unlink(name string, context *fuse.Context) (code fuse.Status) // Extended attributes. GetXAttr(name string, attribute string, context *fuse.Context) (data []byte, code fuse.Status) ListXAttr(name string, context *fuse.Context) (attributes []string, code fuse.Status) RemoveXAttr(name string, attr string, context *fuse.Context) fuse.Status SetXAttr(name string, attr string, data []byte, flags int, context *fuse.Context) fuse.Status // Called after mount. OnMount(nodeFs *Ossfs) OnUnmount() // File handling. If opening for writing, the file's mtime // should be updated too. Open(name string, flags uint32, context *fuse.Context) (file *FileInfo, code fuse.Status) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file *FileInfo, code fuse.Status) Read(name string, dest []byte, off int64, size int64, context *fuse.Context) (fuse.ReadResult, fuse.Status) ReadData(name string, off int64, size int64, context *fuse.Context) ([]byte, fuse.Status) Write(name string, data []byte, off int64, context *fuse.Context) (written uint32, code fuse.Status) WriteReader(name string, data io.Reader, off int64, context *fuse.Context) (written uint32, code fuse.Status) Release(file *FileInfo) Flush(file *FileInfo) fuse.Status Fsync(name string, data []byte) (code fuse.Status) // Directory handling OpenDir(name string, fixname string, context *fuse.Context) (stream map[string]*FileInfo, code fuse.Status) // Symlinks. Symlink(value string, linkName string, context *fuse.Context) (code fuse.Status) Readlink(name string, context *fuse.Context) (string, fuse.Status) StatFs(name string) *fuse.StatfsOut }
A filesystem API that uses paths rather than inodes. A minimal file system should have at least a functional GetAttr method. Typically, each call happens in its own goroutine, so take care to make the file system thread-safe.
NewDefaultFileSystem provides a null implementation of required methods.
type FileInfo ¶
type FileInfo struct { IsDir bool Name string LastModified string Size int64 Etag string Expire string }
文件的基本信息,没有实际操作
type FileSystemConnector ¶
type FileSystemConnector struct {
// contains filtered or unexported fields
}
FilesystemConnector translates the raw FUSE protocol (serialized structs of uint32/uint64) to operations on Go objects representing files and directories.
func MountRoot ¶
func MountRoot(mountpoint string, root Node, opts *Options) (*fuse.Server, *FileSystemConnector, error)
Mounts a filesystem with the given root node on the given directory 保留每个node都有mount的意义的意义在于,以后可以根据用户权限来设定不同的挂载根目录
func NewFileSystemConnector ¶
func NewFileSystemConnector(root Node, opts *Options) (c *FileSystemConnector)
NewFileSystemConnector creates a FileSystemConnector with the given options.
func (*FileSystemConnector) DeleteNotify ¶
DeleteNotify signals to the kernel that the named entry in dir for the child disappeared. No filesystem related locks should be held when calling this.
func (*FileSystemConnector) EntryNotify ¶
func (c *FileSystemConnector) EntryNotify(node *Inode, name string) fuse.Status
EntryNotify makes the kernel forget the entry data from the given name from a directory. After this call, the kernel will issue a new lookup request for the given name when necessary. No filesystem related locks should be held when calling this.
func (*FileSystemConnector) FileNotify ¶
FileNotify notifies the kernel that data and metadata of this inode has changed. After this call completes, the kernel will issue a new GetAttr requests for metadata and new Read calls for content. Use negative offset for metadata-only invalidation, and zero-length for invalidating all content. 这个动作之后的inode是不允许删除的。 也就是说这个inode的handle已经被系统记录了
func (*FileSystemConnector) InodeHandleCount ¶
func (c *FileSystemConnector) InodeHandleCount() int
InodeCount returns the number of inodes registered with the kernel.
func (*FileSystemConnector) LookupNode ¶
func (c *FileSystemConnector) LookupNode(parent *Inode, path string) *Inode
Follows the path from the given parent, doing lookups as necesary. The path should be '/' separated without leading slash.
func (*FileSystemConnector) Mount ¶
func (c *FileSystemConnector) Mount(parent *Inode, name string, root Node, opts *Options) fuse.Status
Mount() generates a synthetic directory node, and mounts the file system there. If opts is nil, the mount options of the root file system are inherited. The encompassing filesystem should pretend the mount point does not exist.
It returns ENOENT if the directory containing the mount point does not exist, and EBUSY if the intended mount point already exists.
func (*FileSystemConnector) Node ¶
func (c *FileSystemConnector) Node(parent *Inode, fullPath string) (*Inode, []string)
Finds a node within the currently known inodes, returns the last known node and the remaining unknown path components. If parent is nil, start from FUSE mountpoint.
func (*FileSystemConnector) RawFS ¶
func (c *FileSystemConnector) RawFS() fuse.RawFileSystem
Returns the RawFileSystem so it can be mounted.
func (*FileSystemConnector) Server ¶
func (c *FileSystemConnector) Server() *fuse.Server
Server returns the fuse.Server that talking to the kernel.
func (*FileSystemConnector) SetDebug ¶
func (c *FileSystemConnector) SetDebug(debug bool)
SetDebug toggles printing of debug information. This function is deprecated. Set the Debug option in the Options struct instead.
type Inode ¶
type Inode struct {
// contains filtered or unexported fields
}
linux中的INODE 已经包含了所有文件信息, 这里主要也是给更底层调用, 定位节点一定要从上往下定位,(已知nodeid的除外)
func (*Inode) AddOpenedFile ¶
func (n *Inode) AddOpenedFile(opfile *openedFile)
func (*Inode) Create ¶
func (n *Inode) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file *FileInfo, child *Inode, code fuse.Status)
创建一个子文件 先直接创建一个有标识的元数据,直到close。节点刷新的时候碰到带新建标识的不会进行移除
func (*Inode) EventNodeFree ¶
func (n *Inode) EventNodeFree()
func (*Inode) EventNodeUsed ¶
func (n *Inode) EventNodeUsed()
func (*Inode) EventRefreshLastAccessTime ¶
func (n *Inode) EventRefreshLastAccessTime()
func (*Inode) FsChildren ¶
FsChildren returns all the children from the same filesystem. It will skip mountpoints.
func (*Inode) GetAllParent ¶
func (n *Inode) GetAllParent() []*parentData
func (*Inode) GetChild ¶
GetChild returns a child inode with the given name, or nil if it does not exist. 1 先看自己的缓存时间 2没过期,直接返回查询结果 3 过期了,需要刷新下本地的缓存信息
func (*Inode) GetChildren ¶
func (*Inode) GetDirChildren ¶
func (*Inode) GetFilesWithMask ¶
func (*Inode) GetFirstParent ¶
func (n *Inode) GetFirstParent() *parentData
func (*Inode) GetParentCount ¶
func (*Inode) GetRefreshSolt ¶
func (*Inode) GetTolOpenedCount ¶
func (o *Inode) GetTolOpenedCount() (r, w, t int)
包括子节点一共几个读,几个写,一共几个
func (*Inode) RefreshCheck ¶
刷新自己的子,假如fixname是“”,表示刷新所有,否则指定刷新 同一时间只有1个在刷新 优先刷新fixname="" 的
func (*Inode) ReleaseOpenedFile ¶
func (*Inode) ReleaseRefreshSolt ¶
func (*Inode) RemoveParent ¶
func (*Inode) RenameChild ¶
type InodeRefreshQueue ¶
type InodeRefreshQueueNode ¶
type InodeRefreshQueueNode struct {
// contains filtered or unexported fields
}
type Node ¶
type Node interface { // Inode and SetInode are basic getter/setters. They are // called by the FileSystemConnector. You get them for free by // embedding the result of NewDefaultNode() in your node // struct. Inode() *Inode SetInode(node *Inode) // OnMount is called on the root node just after a mount is // executed, either when the actual root is mounted, or when a // filesystem is mounted in-process. The passed-in // FileSystemConnector gives access to Notify methods and // Debug settings. OnMount(conn *FileSystemConnector) // OnUnmount is executed just before a submount is removed, // and when the process receives a forget for the FUSE root // node. OnUnmount() // Lookup finds a child node to this node; it is only called // for directory Nodes. Lookup(out *fuse.Attr, name string, context *fuse.Context) (*Inode, fuse.Status) // Deletable() should return true if this node may be discarded once // the kernel forgets its reference. // If it returns false, OnForget will never get called for this node. This // is appropriate if the filesystem has no persistent backing store // (in-memory filesystems) where discarding the node loses the stored data. // Deletable will be called from within the treeLock critical section, so you // cannot look at other nodes. Deletable() bool // OnForget is called when the kernel forgets its reference to this node and // sends a FORGET request. It should perform cleanup and free memory as // appropriate for the filesystem. // OnForget is not called if the node is a directory and has children. // This is called from within a treeLock critical section. OnForget() // Misc. Access(mode uint32, context *fuse.Context) (code fuse.Status) Readlink(c *fuse.Context) ([]byte, fuse.Status) // Mknod should create the node, add it to the receiver's // inode, and return it Mknod(name string, mode uint32, dev uint32, context *fuse.Context) (newNode *Inode, code fuse.Status) // Mkdir should create the directory Inode, add it to the // receiver's Inode, and return it Mkdir(name string, mode uint32, context *fuse.Context) (newNode *Inode, code fuse.Status) Unlink(name string, context *fuse.Context) (code fuse.Status) Rmdir(name string, context *fuse.Context) (code fuse.Status) // Symlink should create a child inode to the receiver, and // return it. Symlink(name string, content string, context *fuse.Context) (*Inode, fuse.Status) Rename(oldName string, newParent Node, newName string, context *fuse.Context) (code fuse.Status) // Link should return the Inode of the resulting link. In // a POSIX conformant file system, this should add 'existing' // to the receiver, and return the Inode corresponding to // 'existing'. Link(name string, existing Node, context *fuse.Context) (newNode *Inode, code fuse.Status) // Create should return an open file, and the Inode for that file. Create(name string, flags uint32, mode uint32, context *fuse.Context) (file *FileInfo, child *Inode, code fuse.Status) // Open opens a file, and returns a File which is associated // with a file handle. It is OK to return (nil, OK) here. In // that case, the Node should implement Read or Write // directly. Open(flags uint32, context *fuse.Context) (file *FileInfo, code fuse.Status) OpenDir(context *fuse.Context) ([]fuse.DirEntry, fuse.Status) //指定了fixname?指定了就返回指定文件,没选中就返回所有的 ListDir(fixname string, context *fuse.Context) (map[string]*FileInfo, fuse.Status) Read(file *FileInfo, dest []byte, off int64, size int64, context *fuse.Context) (fuse.ReadResult, fuse.Status) Write(file *FileInfo, data []byte, off int64, context *fuse.Context) (written uint32, code fuse.Status) Release(flags uint32) fuse.Status // XAttrs GetXAttr(attribute string, context *fuse.Context) (data []byte, code fuse.Status) RemoveXAttr(attr string, context *fuse.Context) fuse.Status SetXAttr(attr string, data []byte, flags int, context *fuse.Context) fuse.Status ListXAttr(context *fuse.Context) (attrs []string, code fuse.Status) // Attributes GetAttr(out *fuse.Attr, file *FileInfo, context *fuse.Context) (code fuse.Status) Chmod(file *FileInfo, perms uint32, context *fuse.Context) (code fuse.Status) Chown(file *FileInfo, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) Truncate(file *FileInfo, size uint64, context *fuse.Context) (code fuse.Status) Utimens(file *FileInfo, atime *time.Time, mtime *time.Time, context *fuse.Context) (code fuse.Status) Fallocate(file *FileInfo, off uint64, size uint64, mode uint32, context *fuse.Context) (code fuse.Status) Fsync(openfile *openedFile) (code fuse.Status) StatFs() *fuse.StatfsOut }
具体的操作,会根据Inode信息进行一些初步的整理,主要是路径信息 有缓存和没有缓存的要实现不同的node
type Options ¶
type Options struct { EntryTimeout time.Duration AttrTimeout time.Duration NegativeTimeout time.Duration // If set, replace all uids with given UID. // NewOptions() will set this to the daemon's // uid/gid. *fuse.Owner // This option exists for compatibility and is ignored. PortableInodes bool fuse.MountOptions }
Options contains time out options for a node FileSystem. The default copied from libfuse and set in NewMountOptions() is (1s,1s,0s).
func NewOptions ¶
func NewOptions() *Options
NewOptions generates FUSE options that correspond to libfuse's defaults.
type Ossfs ¶
type Ossfs struct {
// contains filtered or unexported fields
}
PathNodeFs is the file system that can translate an inode back to a path. The path name is then used to call into an object that has the FileSystem interface.
Lookups (ie. FileSystem.GetAttr) may return a inode number in its return value. The inode number ("clientInode") is used to indicate linked files.
type TreeWatcher ¶
type TreeWatcher interface { OnAdd(parent *Inode, name string) OnRemove(parent *Inode, name string) }
TreeWatcher is an additional interface that Nodes can implement. If they do, the OnAdd and OnRemove are called for operations on the file system tree. These functions run under a lock, so they should not do blocking operations.