Documentation ¶
Overview ¶
Package gfapi provides a wrapper around gfapi, the GlusterFS api, which is used to access files/directories on a Gluster volume. The design tries to follow the default go file handling functions provided by the os package as much as possible.
To use gfapi, a virtual volume must be initialized and mounted first.
vol := &gfapi.Volume{} e := vol.Init("hostname", "volume") e := vol.Mount()
Once the virtual volume is mounted, the vol object can be used like the os package to perform file operations.
f, e := vol.Create("testfile") defer f.Close() e := vol.Unlink("somefile")
The gfapi.File implements the same interfaces as os.File, and can be used wherever os.File is used. XXX: Acutally verify this.
Index ¶
- type Fd
- func (fd *Fd) Fallocate(mode int, offset int64, len int64) error
- func (fd *Fd) Fchmod(mode uint32) error
- func (fd *Fd) Fgetxattr(attr string, dest []byte) (int64, error)
- func (fd *Fd) Fremovexattr(attr string) error
- func (fd *Fd) Fsetxattr(attr string, data []byte, flags int) error
- func (fd *Fd) Fstat(stat *syscall.Stat_t) error
- func (fd *Fd) Fsync() error
- func (fd *Fd) Ftruncate(size int64) error
- func (fd *Fd) Pread(b []byte, off int64) (int, error)
- func (fd *Fd) Pwrite(b []byte, off int64) (int, error)
- func (fd *Fd) Read(b []byte) (n int, err error)
- func (fd *Fd) Readdir(n int) ([]os.FileInfo, error)
- func (fd *Fd) Readdirnames(n int) ([]string, error)
- func (fd *Fd) Write(b []byte) (n int, err error)
- type File
- func (f *File) Chdir() error
- func (f *File) Chmod(mode os.FileMode) error
- func (f *File) Chown(uid, gid int) error
- func (f *File) Close() error
- func (f *File) Fallocate(mode int, offset int64, len int64) error
- func (f *File) Getxattr(attr string, dest []byte) (int64, error)
- func (f *File) Name() string
- func (f *File) Read(b []byte) (n int, err error)
- func (f *File) ReadAt(b []byte, off int64) (int, error)
- func (f *File) Readdir(n int) ([]os.FileInfo, error)
- func (f *File) Readdirnames(n int) ([]string, error)
- func (f *File) Removexattr(attr string) error
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Setxattr(attr string, data []byte, flags int) error
- func (f *File) Stat() (os.FileInfo, error)
- func (f *File) Sync() error
- func (f *File) Truncate(size int64) error
- func (f *File) Write(b []byte) (n int, err error)
- func (f *File) WriteAt(b []byte, off int64) (int, error)
- func (f *File) WriteString(s string) (int, error)
- type LogLevel
- type Statvfs_t
- type Volume
- func (v *Volume) Chmod(name string, mode os.FileMode) error
- func (v *Volume) Create(name string) (*File, error)
- func (v *Volume) Getxattr(path string, attr string, dest []byte) (int64, error)
- func (v *Volume) Init(volname string, hosts ...string) error
- func (v *Volume) InitWithVolfile(volname, volfile string) int
- func (v *Volume) Lstat(name string) (os.FileInfo, error)
- func (v *Volume) Mkdir(name string, perm os.FileMode) error
- func (v *Volume) MkdirAll(path string, perm os.FileMode) error
- func (v *Volume) Mount() error
- func (v *Volume) Open(name string) (*File, error)
- func (v *Volume) OpenFile(name string, flags int, perm os.FileMode) (*File, error)
- func (v *Volume) Removexattr(path string, attr string) error
- func (v *Volume) Rename(oldpath string, newpath string) error
- func (v *Volume) Rmdir(path string) error
- func (v *Volume) SetLogging(name string, logLevel LogLevel) error
- func (v *Volume) Setxattr(path string, attr string, data []byte, flags int) error
- func (v *Volume) Stat(name string) (os.FileInfo, error)
- func (v *Volume) Statvfs(path string, buf *Statvfs_t) error
- func (v *Volume) Truncate(name string, size int64) error
- func (v *Volume) Unlink(path string) error
- func (v *Volume) Unmount() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fd ¶
type Fd struct {
// contains filtered or unexported fields
}
Fd is the glusterfs fd type
func (*Fd) Fremovexattr ¶
func (*Fd) Fstat ¶
Fstat performs an fstat call on the Fd and saves stat details in the passed stat structure
Returns error on failure
func (*Fd) Ftruncate ¶
Ftruncate truncates the size of the Fd to the given size
Returns error on failure
func (*Fd) Pread ¶
Pread reads at most len(b) bytes into b from offset off in Fd
Returns number of bytes read on success and error on failure
func (*Fd) Pwrite ¶
Pwrite writes len(b) bytes from b into the Fd from offset off
Returns number of bytes written on success and error on failure
func (*Fd) Read ¶
Read reads at most len(b) bytes into b from Fd
Returns number of bytes read on success and error on failure
func (*Fd) Readdir ¶
Readdir returns the information of files in a directory.
n is the maximum number of items to return. If there are more items than the maximum they can be obtained in successive calls. If maximum is 0 then all the items will be returned.
func (*Fd) Readdirnames ¶
Readdirnames returns the names of files in a directory.
n is the maximum number of items to return and works the same way as Readdir.
type File ¶
type File struct { Fd // contains filtered or unexported fields }
File is the gluster file object.
func (*File) Chmod ¶
Chmod changes the mode of the file to the given mode
Returns an error on failure
func (*File) Close ¶
Close closes an open File. Close is similar to os.Close in its functioning.
Returns an Error on failure.
func (*File) Getxattr ¶
Get value of the extended attribute 'attr' and place it in 'dest'
Returns number of bytes placed in 'dest' and error if any
func (*File) Read ¶
Read reads atmost len(b) bytes into b
Returns number of bytes read and an error if any
func (*File) ReadAt ¶
ReadAt reads atmost len(b) bytes into b starting from offset off
Returns number of bytes read and an error if any
func (*File) Readdir ¶
Readdir returns the information of files in a directory.
n is the maximum number of items to return. If there are more items than the maximum they can be obtained in successive calls. If maximum is 0 then all the items will be returned.
func (*File) Readdirnames ¶
Readdirnames returns the names of files in a directory.
n is the maximum number of items to return and works the same way as Readdir.
func (*File) Seek ¶
Seek sets the offset for the next read or write on the file based on whence, 0 - relative to beginning of file, 1 - relative to current offset, 2 - relative to end
Returns new offset and an error if any
func (*File) Setxattr ¶
Set extended attribute with key 'attr' and value 'data'
Returns error on failure
func (*File) Stat ¶
Stat returns an os.FileInfo object describing the file
Returns an error on failure
func (*File) Write ¶
Write writes len(b) bytes to the file
Returns number of bytes written and an error if any
type Volume ¶
type Volume struct {
// contains filtered or unexported fields
}
Volume is the gluster filesystem object, which represents the virtual filesystem.
func (*Volume) Chmod ¶
Chmod changes the mode of the named file to given mode
Returns an error on failure
func (*Volume) Create ¶
Create creates a file with given name on the the Volume v. The Volume must be mounted before calling Create. Create is similar to os.Create in its functioning.
name is the name of the file to be create.
Returns a File object on success and a os.PathError on failure.
func (*Volume) Getxattr ¶
Get value of the extended attribute 'attr' and place it in 'dest'
Returns number of bytes placed in 'dest' and error if any
func (*Volume) Init ¶
Init creates a new glfs object "Volume". Volname is the name of the Gluster Volume and also the "volfile-id". Hosts accepts one or more hostname(s) and/or IP(s) of volname's constitute volfile servers (management server/glusterd).
Limitations: * Assumes tcp transport and glusterd is listening on 24007
func (*Volume) InitWithVolfile ¶
InitWithVolfile initializes the Volume using the given volfile. This must be done before calling Mount.
volfile is the path to the locally available volfile
Return value is 0 for success and non 0 for failure
func (*Volume) Lstat ¶
Lstat returns an os.FileInfo object describing the named file. It doesn't follow the link if the file is a symlink.
Returns an error on failure
func (*Volume) Mkdir ¶
Mkdir creates a new directory with given name and permission bits
Returns an error on failure
func (*Volume) MkdirAll ¶
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func (*Volume) Mount ¶
Mount establishes a 'virtual mount.' Mount must be called after Init and before storage operations. Steps taken:
- Spawn a poll-loop thread.
- Establish connection to management daemon (volfile server) and receive volume specification (volfile).
- Construct translator graph and initialize graph.
- Wait for initialization (connecting to all bricks) to complete.
Source: glfs.h
func (*Volume) Open ¶
Open opens the named file on the the Volume v. The Volume must be mounted before calling Open. Open is similar to os.Open in its functioning.
name is the name of the file to be open.
Returns a File object on success and a os.PathError on failure.
func (*Volume) OpenFile ¶
OpenFile opens the named file on the the Volume v. The Volume must be mounted before calling OpenFile. OpenFile is similar to os.OpenFile in its functioning.
name is the name of the file to be open. flags is the access mode of the file. perm is the permissions for the opened file.
Returns a File object on success and a os.PathError on failure.
BUG : perm is not used for opening the file. NOTE: It is better to use Open, Create etc. instead of using OpenFile directly
func (*Volume) SetLogging ¶
SetLogging sets the gfapi log file path and LogLevel. The Volume must be initialized before calling. An empty string "" is passed as 'name' sets the default log directory (/var/log/glusterfs).
func (*Volume) Setxattr ¶
Set extended attribute with key 'attr' and value 'data'
Returns error on failure
func (*Volume) Stat ¶
Stat returns an os.FileInfo object describing the named file
Returns an error on failure
func (*Volume) Truncate ¶
Truncate changes the size of the named file
Returns an error on failure ¶
TODO: gfapi currently (20131120) has not implement glfs_truncate.
Once it has been implemented, renable the commented out code or write own function to implement the functionality of glfs_truncate