mcfs

package
v0.0.0-...-ec95f82 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBaseFileHandle

func NewBaseFileHandle(fd, flags int) fs.FileHandle

NewBaseFileHandle creates a FileHandle out of a file descriptor. All operations are implemented. When using the Fd from a *os.File, call syscall.Dup() on the Fd, to avoid os.File's finalizer from closing the file descriptor.

Types

type BaseFileHandle

type BaseFileHandle struct {
	// Mu is used to lock operations on the file
	Mu sync.Mutex

	// The file descriptor to the file the BaseFileHandle is connected to
	Fd int

	// The flags used to open the file.
	Flags int
}

BaseFileHandle implements the basic operations to a file. It is heavily copied from github.com/hanwen/go-fuse/fs/files.go. It implements an interface to an existing file in a linux file system.

func (*BaseFileHandle) Allocate

func (f *BaseFileHandle) Allocate(ctx context.Context, off uint64, sz uint64, mode uint32) syscall.Errno

Allocate implements pre-allocating blocks for a file

func (*BaseFileHandle) Flush

func (f *BaseFileHandle) Flush(ctx context.Context) syscall.Errno

Flush handles flushing the file buffer.

func (*BaseFileHandle) Fsync

func (f *BaseFileHandle) Fsync(ctx context.Context, flags uint32) (errno syscall.Errno)

Fsync handles the fsync call to flush to disk.

func (*BaseFileHandle) Getattr

func (f *BaseFileHandle) Getattr(ctx context.Context, a *fuse.AttrOut) syscall.Errno

Getattr implements getting attributes about a file (different from stat)

func (*BaseFileHandle) Getlk

func (f *BaseFileHandle) Getlk(ctx context.Context, owner uint64, lk *fuse.FileLock, flags uint32, out *fuse.FileLock) (errno syscall.Errno)

Getlk implements getting file lock status

func (*BaseFileHandle) Lseek

func (f *BaseFileHandle) Lseek(ctx context.Context, off uint64, whence uint32) (uint64, syscall.Errno)

Lseek implements file seeking

func (*BaseFileHandle) Read

func (f *BaseFileHandle) Read(ctx context.Context, buf []byte, off int64) (res fuse.ReadResult, errno syscall.Errno)

Read reads a from the file descriptor.

func (*BaseFileHandle) Release

func (f *BaseFileHandle) Release(ctx context.Context) syscall.Errno

Release handles the close operation.

func (*BaseFileHandle) Setattr

func (f *BaseFileHandle) Setattr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) syscall.Errno

Setattr implements the FUSE Setattr call for setting attributes on a file

func (*BaseFileHandle) Setlk

func (f *BaseFileHandle) Setlk(ctx context.Context, owner uint64, lk *fuse.FileLock, flags uint32) (errno syscall.Errno)

Setlk implements file locking

func (*BaseFileHandle) Setlkw

func (f *BaseFileHandle) Setlkw(ctx context.Context, owner uint64, lk *fuse.FileLock, flags uint32) (errno syscall.Errno)

Setlkw implements file locking with waiting

func (*BaseFileHandle) Write

func (f *BaseFileHandle) Write(ctx context.Context, data []byte, off int64) (uint32, syscall.Errno)

Write writes to the file descriptor.

type FileHandleFactory

type FileHandleFactory interface {
	NewFileHandle(fd, flags int, path string, file *mcmodel.File) fs.FileHandle
}

FileHandleFactory is an interface that wraps the method for getting a new file handle. This allows for file handles implementing different feature sets. A factory is used to create a file handle for the case where elements of the file handle need to share state, such as a common interface to the database.

type LocalMCFSApi

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

LocalMCFSApi is the file system interface into Materials Commons. It has little knowledge of FUSE. It understands the Materials Commons calls to make to achieve FUSE file system operations, and returns the results in a way that the node can pass back.

func NewLocalMCFSApi

func NewLocalMCFSApi(stors *stor.Stors, tracker *fsstate.TransferStateTracker, pathParser mcpath.Parser, mcfsRoot string) *LocalMCFSApi

func (*LocalMCFSApi) Create

func (fsapi *LocalMCFSApi) Create(path string) (*mcmodel.File, error)

func (*LocalMCFSApi) FTruncate

func (fsapi *LocalMCFSApi) FTruncate(path string, size uint64) (error, *syscall.Stat_t)

func (*LocalMCFSApi) GetKnownFileRealPath

func (fsapi *LocalMCFSApi) GetKnownFileRealPath(path string) (string, error)

func (*LocalMCFSApi) GetRealPath

func (fsapi *LocalMCFSApi) GetRealPath(path string) (realpath string, err error)

func (*LocalMCFSApi) Lookup

func (fsapi *LocalMCFSApi) Lookup(path string) (*mcmodel.File, error)

func (*LocalMCFSApi) Mkdir

func (fsapi *LocalMCFSApi) Mkdir(path string) (*mcmodel.File, error)

func (*LocalMCFSApi) Open

func (fsapi *LocalMCFSApi) Open(path string, flags int) (f *mcmodel.File, isNewFile bool, err error)

Open will open a file. It will create a new version if opening a new file for write. An open in Append mode should only happen after a new file has been created (ie, a TransferRequestFile created in the database).

func (*LocalMCFSApi) Readdir

func (fsapi *LocalMCFSApi) Readdir(path string) ([]mcmodel.File, error)

func (*LocalMCFSApi) Release

func (fsapi *LocalMCFSApi) Release(path string, size uint64) error

type MCFSApi

type MCFSApi interface {
	// Create creates a new file database entry.
	Create(path string) (*mcmodel.File, error)

	// Open will create a new mcmodel.File or return an existing one depending on
	// the flags passed in.
	Open(path string, flags int) (f *mcmodel.File, isNewFile bool, err error)

	// Release releases (closes) a file and updates metadata about the file in MC.
	Release(path string, size uint64) error

	// Lookup returns a file entry if it exists.
	Lookup(path string) (*mcmodel.File, error)

	// Readdir returns a list of mcmodel.File entries for a directory.
	Readdir(path string) ([]mcmodel.File, error)

	// Mkdir creates a new directory in MC.
	Mkdir(path string) (*mcmodel.File, error)

	// GetRealPath will take a MCFS path and return the path to the real underlying file (the UUID based path).
	GetRealPath(path string) (realpath string, err error)

	// GetKnownFileRealPath will return the real underlying file path (the UUID based path) only for files
	// that are in the AccessedFileState tracker.
	GetKnownFileRealPath(path string) (string, error)

	// FTruncate will truncate the real underlying file (the UUID based one) and return
	// Stat info on it.
	FTruncate(path string, size uint64) (error, *syscall.Stat_t)
}

MCFSApi is the interface into Materials Commons that supports the file system. It follows a naming convention that mostly matches the FUSE call. So for example Create, Open, Release, Lookup, Readdir, Mkdir, FTruncate correspond to the FUSE calls.

type MCFileHandle

type MCFileHandle struct {
	*BaseFileHandle

	Path string
	File *mcmodel.File
	// contains filtered or unexported fields
}

func NewMCFileHandle

func NewMCFileHandle(fd, flags int) *MCFileHandle

func (*MCFileHandle) Flush

func (*MCFileHandle) Read

func (h *MCFileHandle) Read(_ context.Context, buf []byte, off int64) (res fuse.ReadResult, errno syscall.Errno)

func (*MCFileHandle) Release

func (h *MCFileHandle) Release(ctx context.Context) (errno syscall.Errno)

func (*MCFileHandle) Setattr

func (h *MCFileHandle) Setattr(_ context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) (errno syscall.Errno)

func (*MCFileHandle) WithActivityCounter

func (h *MCFileHandle) WithActivityCounter(activityCounter *fsstate.ActivityCounter) *MCFileHandle

func (*MCFileHandle) WithFile

func (h *MCFileHandle) WithFile(f *mcmodel.File) *MCFileHandle

func (*MCFileHandle) WithMCFSApi

func (h *MCFileHandle) WithMCFSApi(mcfsapi MCFSApi) *MCFileHandle

func (*MCFileHandle) WithPath

func (h *MCFileHandle) WithPath(path string) *MCFileHandle

func (*MCFileHandle) WithPathParser

func (h *MCFileHandle) WithPathParser(p mcpath.Parser) *MCFileHandle

func (*MCFileHandle) WithTransferStateTracker

func (h *MCFileHandle) WithTransferStateTracker(tracker *fsstate.TransferStateTracker) *MCFileHandle

func (*MCFileHandle) Write

func (h *MCFileHandle) Write(_ context.Context, data []byte, off int64) (bytesWritten uint32, errno syscall.Errno)

type MCFileHandlerFactory

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

MCFileHandlerFactory creates new instances of MCFileHandle. The shared state is the MCFSApi, an activity counter and a tracker for files that are or were opened.

func NewMCFileHandlerFactory

func NewMCFileHandlerFactory(mcfsapi MCFSApi, transferStateTracker *fsstate.TransferStateTracker, pathParser mcpath.Parser,
	activityCounterMonitor *fsstate.ActivityTracker) *MCFileHandlerFactory

NewMCFileHandlerFactory creates a new MCFileHandlerFactory.

func (*MCFileHandlerFactory) NewFileHandle

func (f *MCFileHandlerFactory) NewFileHandle(fd, flags int, path string, file *mcmodel.File) fs.FileHandle

NewFileHandle creates a new MCFileHandle. Handles created this way will share the activity counter, known files tracker and MCFSApi.

type NewFileHandleFN

type NewFileHandleFN func(fd, flags int, path string, file *mcmodel.File) fs.FileHandle

type Node

type Node struct {
	fs.Inode
	RootData *RootData
}

func CreateFS

func CreateFS(fsRoot string, mcfsapi MCFSApi, fn NewFileHandleFN) (*Node, error)

func (*Node) Create

func (n *Node) Create(ctx context.Context, name string, flags uint32, mode uint32, out *fuse.EntryOut) (inode *fs.Inode, fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno)

Create will create a new file. At this point the file shouldn't exist. However, because multiple users could be uploading files, there is a chance it does exist. If that happens then a new version of the file is created instead.

func (*Node) Getattr

func (n *Node) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) (errno syscall.Errno)

Getattr gets attributes about the file

func (*Node) Getxattr

func (n *Node) Getxattr(_ context.Context, _ string, _ []byte) (uint32, syscall.Errno)

Getxattr returns extra attributes. This is used by lstat. There are no extra attributes to return, so we always return a 0 for buffer length and success.

func (*Node) Lookup

func (n *Node) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (inode *fs.Inode, errno syscall.Errno)

Lookup will return information about the current entry.

func (*Node) Mkdir

func (n *Node) Mkdir(ctx context.Context, name string, _ uint32, out *fuse.EntryOut) (inode *fs.Inode, errno syscall.Errno)

Mkdir will create a new directory. If an attempt is made to create an existing directory then it will return the existing directory rather than returning an error.

func (*Node) Open

func (n *Node) Open(_ context.Context, flags uint32) (fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno)

Open will open an existing file. It will create a new file if the underlying mcfsapi.Open indicates a new version was created.

func (*Node) Opendir

func (n *Node) Opendir(_ context.Context) syscall.Errno

Opendir just returns success

func (*Node) Readdir

func (n *Node) Readdir(_ context.Context) (ds fs.DirStream, errno syscall.Errno)

Readdir reads the corresponding directory and returns its files

func (*Node) Rename

func (n *Node) Rename(_ context.Context, _ string, _ fs.InodeEmbedder, _ string, _ uint32) syscall.Errno

func (*Node) Rmdir

func (n *Node) Rmdir(_ context.Context, name string) syscall.Errno

func (*Node) Setattr

func (n *Node) Setattr(ctx context.Context, f fs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) (errno syscall.Errno)

func (*Node) Statfs

func (n *Node) Statfs(_ context.Context, out *fuse.StatfsOut) (errno syscall.Errno)
func (n *Node) Unlink(_ context.Context, name string) syscall.Errno

type NullLogger

type NullLogger struct{}

func (*NullLogger) Printf

func (l *NullLogger) Printf(_ string, _ ...interface{})

type RootData

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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