gfapi

package
v0.0.0-...-cc18ed6 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: BSD-2-Clause Imports: 9 Imported by: 2

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

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) Fallocate

func (fd *Fd) Fallocate(mode int, offset int64, len int64) error

func (*Fd) Fchmod

func (fd *Fd) Fchmod(mode uint32) error

Fchmod changes the mode of the Fd to the given mode

Returns error on failure

func (*Fd) Fgetxattr

func (fd *Fd) Fgetxattr(attr string, dest []byte) (int64, error)

func (*Fd) Fremovexattr

func (fd *Fd) Fremovexattr(attr string) error

func (*Fd) Fsetxattr

func (fd *Fd) Fsetxattr(attr string, data []byte, flags int) error

func (*Fd) Fstat

func (fd *Fd) Fstat(stat *syscall.Stat_t) error

Fstat performs an fstat call on the Fd and saves stat details in the passed stat structure

Returns error on failure

func (*Fd) Fsync

func (fd *Fd) Fsync() error

Fsync performs an fsync on the Fd

Returns error on failure

func (*Fd) Ftruncate

func (fd *Fd) Ftruncate(size int64) error

Ftruncate truncates the size of the Fd to the given size

Returns error on failure

func (*Fd) Pread

func (fd *Fd) Pread(b []byte, off int64) (int, error)

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

func (fd *Fd) Pwrite(b []byte, off int64) (int, error)

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

func (fd *Fd) Read(b []byte) (n int, err error)

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

func (fd *Fd) Readdir(n int) ([]os.FileInfo, error)

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

func (fd *Fd) Readdirnames(n int) ([]string, error)

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 (*Fd) Write

func (fd *Fd) Write(b []byte) (n int, err error)

Write writes len(b) bytes from b into the Fd

Returns number of bytes written on success and error on failure

type File

type File struct {
	Fd
	// contains filtered or unexported fields
}

File is the gluster file object.

func (*File) Chdir

func (f *File) Chdir() error

Chdir has not been implemented yet

func (*File) Chmod

func (f *File) Chmod(mode os.FileMode) error

Chmod changes the mode of the file to the given mode

Returns an error on failure

func (*File) Chown

func (f *File) Chown(uid, gid int) error

Chown has not been implemented yet

func (*File) Close

func (f *File) Close() error

Close closes an open File. Close is similar to os.Close in its functioning.

Returns an Error on failure.

func (*File) Fallocate

func (f *File) Fallocate(mode int, offset int64, len int64) error

Manipulate the allocated disk space for the file

Returns error on failure

func (*File) Getxattr

func (f *File) Getxattr(attr string, dest []byte) (int64, error)

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) Name

func (f *File) Name() string

Name returns the name of the opened file

func (*File) Read

func (f *File) Read(b []byte) (n int, err error)

Read reads atmost len(b) bytes into b

Returns number of bytes read and an error if any

func (*File) ReadAt

func (f *File) ReadAt(b []byte, off int64) (int, error)

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

func (f *File) Readdir(n int) ([]os.FileInfo, error)

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

func (f *File) Readdirnames(n int) ([]string, error)

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) Removexattr

func (f *File) Removexattr(attr string) error

Remove extended attribute named 'attr'

Returns error on failure

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

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

func (f *File) Setxattr(attr string, data []byte, flags int) error

Set extended attribute with key 'attr' and value 'data'

Returns error on failure

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat returns an os.FileInfo object describing the file

Returns an error on failure

func (*File) Sync

func (f *File) Sync() error

Sync commits the file to the storage

Returns error on failure

func (*File) Truncate

func (f *File) Truncate(size int64) error

Truncate changes the size of the file

Returns error on failure

func (*File) Write

func (f *File) Write(b []byte) (n int, err error)

Write writes len(b) bytes to the file

Returns number of bytes written and an error if any

func (*File) WriteAt

func (f *File) WriteAt(b []byte, off int64) (int, error)

WriteAt writes len(b) bytes to the file starting at offset off

Returns number of bytes written and an error if any

func (*File) WriteString

func (f *File) WriteString(s string) (int, error)

WriteString writes the contents of string s to the file

Returns number of bytes written and an error if any

type LogLevel

type LogLevel int

LogLevel is the logging level to be used to logging

const (
	LogNone LogLevel = iota
	LogEmerg
	LogAlert
	LogCritical
	LogError
	LogWarning
	LogNotice
	LogInfo
	LogDebug
	LogTrace
)

LogNone .. LogTrace are LogLevel types which correspond to the equivalent gluster log levels

type Statvfs_t

type Statvfs_t struct {
	Bsize      uint64
	Frsize     uint64
	Blocks     uint64
	Bfree      uint64
	Bavail     uint64
	Files      uint64
	Ffree      uint64
	Favail     uint64
	Fsid       uint64
	Flag       uint64
	Namemax    uint64
	X__f_spare [6]int32
}

type Volume

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

Volume is the gluster filesystem object, which represents the virtual filesystem.

func (*Volume) Chmod

func (v *Volume) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to given mode

Returns an error on failure

func (*Volume) Create

func (v *Volume) Create(name string) (*File, error)

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

func (v *Volume) Getxattr(path string, attr string, dest []byte) (int64, error)

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

func (v *Volume) Init(volname string, hosts ...string) error

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

func (v *Volume) InitWithVolfile(volname, volfile string) int

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

func (v *Volume) Lstat(name string) (os.FileInfo, error)

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

func (v *Volume) Mkdir(name string, perm os.FileMode) error

Mkdir creates a new directory with given name and permission bits

Returns an error on failure

func (*Volume) MkdirAll

func (v *Volume) MkdirAll(path string, perm os.FileMode) error

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

func (v *Volume) Mount() error

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

func (v *Volume) Open(name string) (*File, error)

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

func (v *Volume) OpenFile(name string, flags int, perm os.FileMode) (*File, error)

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) Removexattr

func (v *Volume) Removexattr(path string, attr string) error

Remove extended attribute named 'attr'

Returns error on failure

func (*Volume) Rename

func (v *Volume) Rename(oldpath string, newpath string) error

Rename a file or directory

Returns error on failure

func (*Volume) Rmdir

func (v *Volume) Rmdir(path string) error

Removes an existing directory

Returns error on failure

func (*Volume) SetLogging

func (v *Volume) SetLogging(name string, logLevel LogLevel) error

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

func (v *Volume) Setxattr(path string, attr string, data []byte, flags int) error

Set extended attribute with key 'attr' and value 'data'

Returns error on failure

func (*Volume) Stat

func (v *Volume) Stat(name string) (os.FileInfo, error)

Stat returns an os.FileInfo object describing the named file

Returns an error on failure

func (*Volume) Statvfs

func (v *Volume) Statvfs(path string, buf *Statvfs_t) error

Get filesystem statistics

Returns an error on failure

func (*Volume) Truncate

func (v *Volume) Truncate(name string, size int64) error

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
func (v *Volume) Unlink(path string) error

Unlink attempts to unlink a file a path and returns a non-nil error on failure.

func (*Volume) Unmount

func (v *Volume) Unmount() error

Unmount ends the virtual mount.

Jump to

Keyboard shortcuts

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