Documentation
¶
Index ¶
- Constants
- Variables
- func BlocksToBytes(blocks uint64) string
- func BytesToBlocks(bytes uint64) uint64
- func DefaultSnapshotLabel(tenant, label string) string
- func ExportDirectory(tarfile *tar.Writer, path, name string) error
- func ExportFile(tarfile *tar.Writer, path, name string) error
- func FilesystemBytesAvailable(path string) uint64
- func FilesystemBytesSize(path string) uint64
- func FilesystemBytesUsed(path string) uint64
- func FlagFilePath(root string) string
- func GetLastIOStat() (map[string]iostat.DeviceUtilizationReport, bool)
- func ImportArchive(tarfile *tar.Reader, path string) error
- func ImportArchiveHeader(header *tar.Header, reader io.Reader, path string) error
- func InitDriver(name DriverType, root string, args []string) error
- func InitIOStat(getter iostat.Getter, closeChannel <-chan interface{})
- func IsBtrfsFilesystem(path string) bool
- func IsDir(dirName string) (dir bool, err error)
- func IsRoot() bool
- func IsSudoer() bool
- func Noescape(s string) template.HTML
- func Percent(amt, total uint64) string
- func Register(name DriverType, driverInit DriverInit) error
- func Registered(name DriverType) bool
- func RunBtrFSCmd(sudoer bool, args ...string) ([]byte, error)
- func ShutdownAll() error
- func ShutdownDriver(rootDir string) error
- func SplitPath(volumePath string) (string, string, error)
- func ToBytes(from uint64) string
- func TouchFlagFile(root string) error
- func Unregister(name DriverType)
- type DeviceMapperStatus
- type Driver
- type DriverInit
- type DriverType
- type FileInfoSlice
- type SimpleStatus
- type SnapshotInfo
- type Status
- type Statuses
- type TenantStorageStats
- type Usage
- type UsageData
- type UsageFloat
- type UsageInt
- type Volume
Constants ¶
const FlagFileName = ".initialized"
Variables ¶
var ( ErrNotADirectory = errors.New("not a directory") ErrBtrfsCommand = errors.New("error running btrfs command") )
var ( ErrInvalidDriverInit = errors.New("invalid driver initializer") ErrDriverNotInit = errors.New("driver not initialized") ErrDriverAlreadyInit = errors.New("different driver already initialized") ErrDriverExists = errors.New("driver exists") ErrDriverNotSupported = errors.New("driver not supported") ErrRemovingVolume = errors.New("could not remove volume") ErrSnapshotExists = errors.New("snapshot exists") ErrSnapshotDoesNotExist = errors.New("snapshot does not exist") ErrRemovingSnapshot = errors.New("could not remove snapshot") ErrBadDriverShutdown = errors.New("unable to shutdown driver") ErrVolumeExists = errors.New("volume exists") ErrVolumeNotExists = errors.New("volume does not exist") ErrPathIsDriver = errors.New("path is initialized as a driver") ErrPathIsNotAbs = errors.New("path is not absolute") ErrBadMount = errors.New("bad mount path") ErrInsufficientPermissions = errors.New("insufficient permissions to run command") ErrTagAlreadyExists = errors.New("a snapshot with the given tag already exists") ErrInvalidSnapshot = errors.New("invalid snapshot") )
var DeviceMapperStatusTemplate = `` /* 1138-byte string literal not displayed */
var ErrWrongDataType = errors.New("Wrong data type for Usage Value")
Functions ¶
func BlocksToBytes ¶
func BytesToBlocks ¶
func DefaultSnapshotLabel ¶
func ExportDirectory ¶
ExportDirectory recursively writes its contents into a tar Writer.
func ExportFile ¶
ExportFile writes a file into a tar Writer.
func FilesystemBytesSize ¶
func FilesystemBytesUsed ¶
func FlagFilePath ¶
func GetLastIOStat ¶
func GetLastIOStat() (map[string]iostat.DeviceUtilizationReport, bool)
GetLastIOStat returns the iostat device utilization reports
func ImportArchive ¶
ImportArchive reads from a tar Reader and writes the contents into a path preserving file permissions and ownership.
func ImportArchiveHeader ¶
ImportArchiveHeader imports a tarfile header to a particular path
func InitDriver ¶
func InitDriver(name DriverType, root string, args []string) error
InitDriver sets up a driver <name> and initializes it to <root>.
func InitIOStat ¶
InitIOStat starts the iostat call and passes the close signal when sent
func IsBtrfsFilesystem ¶
IsBtrfsFilesystem determines whether the path is a btrfs filesystem
func IsDir ¶
IsDir() checks if the given dir is a directory. If any error is encoutered it is returned and directory is set to false.
func Register ¶
func Register(name DriverType, driverInit DriverInit) error
Register registers a driver initializer under <name> so it can be looked up
func Registered ¶
func Registered(name DriverType) bool
Registered returns a boolean indicating whether driver <name> has been registered.
func RunBtrFSCmd ¶
RunBtrFSCmd runs a btrfs command, optionally using sudo
func ShutdownAll ¶
func ShutdownAll() error
ShutdownAll shuts down all drivers that have been initialized
func ShutdownDriver ¶
ShutdownDriver shuts down an existing driver and removes it from our internal map.
func SplitPath ¶
SplitPath splits a path by its driver and respective volume. Returns error if the driver is not initialized.
func TouchFlagFile ¶
func Unregister ¶
func Unregister(name DriverType)
Unregister the driver init func <name>. If it doesn't exist, it's a no-op.
Types ¶
type DeviceMapperStatus ¶
type DeviceMapperStatus struct {
Driver DriverType
DriverType string
DriverPath string
PoolName string
PoolDataTotal uint64
PoolDataAvailable uint64
PoolDataUsed uint64
PoolMetadataTotal uint64
PoolMetadataAvailable uint64
PoolMetadataUsed uint64
DriverData map[string]string
UsageData UsageData
Tenants []TenantStorageStats
Errors []string
}
func (DeviceMapperStatus) GetUsageData ¶
func (s DeviceMapperStatus) GetUsageData() UsageData
func (DeviceMapperStatus) String ¶
func (s DeviceMapperStatus) String() string
type Driver ¶
type Driver interface {
// Root returns the filesystem root this driver acts on
Root() string
// DriverType returns the string describing the driver
DriverType() DriverType
// Create creates a volume with the given name and returns it. The volume
// must not exist already.
Create(volumeName string) (Volume, error)
// Remove removes an existing device. If the device doesn't exist, the
// removal is a no-op
Remove(volumeName string) error
// Resize resizes an existing volume.
Resize(volumeName string, size uint64) error
// GetTenant returns the parent volume or the volume if it is the
// parent.
GetTenant(volumeName string) (Volume, error)
// Get returns the volume with the given name. The volume must exist.
Get(volumeName string) (Volume, error)
// Release releases any runtime resources associated with a volume (e.g.,
// unmounts a device)
Release(volumeName string) error
// List returns the names of all volumes managed by this driver
List() []string
// Exists returns whether or not a volume managed by this driver exists
// with the given name
Exists(volumeName string) bool
// Cleanup releases any runtime resources held by the driver itself.
Cleanup() error
// Status gets the status of the volume
Status() (Status, error)
}
Driver is the basic interface to the filesystem. It is able to create, manage and destroy volumes. It is initialized with and operates beneath a given directory.
type DriverInit ¶
DriverInit represents a function that can initialize a driver.
type DriverType ¶
type DriverType string
DriverType represents a driver type.
const ( DriverTypeBtrFS DriverType = "btrfs" DriverTypeRsync DriverType = "rsync" DriverTypeDeviceMapper DriverType = "devicemapper" DriverTypeNFS DriverType = "nfs" )
func DetectDriverType ¶
func DetectDriverType(root string) (DriverType, error)
func StringToDriverType ¶
func StringToDriverType(name string) (DriverType, error)
type FileInfoSlice ¶
FileInfoSlice is a os.FileInfo array sortable by modification time
func (FileInfoSlice) Labels ¶
func (p FileInfoSlice) Labels() []string
Labels will return the names of the files in the slice, sorted by modification time
func (FileInfoSlice) Len ¶
func (p FileInfoSlice) Len() int
func (FileInfoSlice) Less ¶
func (p FileInfoSlice) Less(i, j int) bool
func (FileInfoSlice) Swap ¶
func (p FileInfoSlice) Swap(i, j int)
type SimpleStatus ¶
type SimpleStatus struct {
Driver DriverType
DriverData map[string]string
UsageData UsageData
}
func (SimpleStatus) GetUsageData ¶
func (s SimpleStatus) GetUsageData() UsageData
func (SimpleStatus) String ¶
func (s SimpleStatus) String() string
type SnapshotInfo ¶
type Statuses ¶
type Statuses struct {
DeviceMapperStatusMap map[string]*DeviceMapperStatus
SimpleStatusMap map[string]*SimpleStatus
}
This struct is stupid, for the sake of using interfaces AND RPC ser/deser.
func GetStatus ¶
func GetStatus() *Statuses
GetStatus retrieves the status for the volumeNames passed in. If volumeNames is empty, it gets all statuses.
func (*Statuses) GetAllStatuses ¶
type TenantStorageStats ¶
type TenantStorageStats struct {
TenantID string
VolumePath string
PoolAvailableBlocks uint64
DeviceName string
DeviceTotalBlocks uint64
DeviceAllocatedBlocks uint64
DeviceUnallocatedBlocks uint64
FilesystemTotal uint64
FilesystemUsed uint64
FilesystemAvailable uint64
Errors []string
NumberSnapshots int
SnapshotAllocatedBlocks uint64
}
TenantStorageStats represents tenant-specific storage usage details.
type UsageData ¶
type UsageData []Usage
UsageData implements Unmarshaler allowing us to unmarshal a []Usage indirectly
func (*UsageData) UnmarshalJSON ¶
UnmarshalJSON satisfies Unmarshaler interface
type UsageFloat ¶
func (UsageFloat) GetLabel ¶
func (u UsageFloat) GetLabel() string
func (UsageFloat) GetMetricName ¶
func (u UsageFloat) GetMetricName() string
func (UsageFloat) GetType ¶
func (u UsageFloat) GetType() string
func (UsageFloat) GetValueFloat64 ¶
func (u UsageFloat) GetValueFloat64() (float64, error)
func (UsageFloat) GetValueUInt64 ¶
func (u UsageFloat) GetValueUInt64() (uint64, error)
type UsageInt ¶
func (UsageInt) GetMetricName ¶
func (UsageInt) GetValueFloat64 ¶
func (UsageInt) GetValueUInt64 ¶
type Volume ¶
type Volume interface {
// Name returns the name of this volume
Name() string
// Path returns the filesystem path to this volume
Path() string
// Driver returns the driver managing this volume
Driver() Driver
// Snapshot snapshots the current state of this volume and stores it
// using the name <label>
Snapshot(label, message string, tags []string) (err error)
// SnapshotInfo returns general information about a particular snapshot
SnapshotInfo(label string) (*SnapshotInfo, error)
// WriteMetadata returns a handle to write metadata to a snapshot
WriteMetadata(label, name string) (io.WriteCloser, error)
// ReadMetadata returns a handle to read metadata from a snapshot
ReadMetadata(label, name string) (io.ReadCloser, error)
// Snapshots lists all snapshots of this volume
Snapshots() ([]string, error)
// RemoveSnapshot removes the snapshot with name <label>
RemoveSnapshot(label string) error
// Rollback replaces the current state of the volume with that snapshotted
// as <label>
Rollback(label string) error
// TagSnapshot adds a tagName to the snapshot's tag list
TagSnapshot(label string, tagName string) error
// UntagSnapshot removes a tagName from the snapshot's tag list
UntagSnapshot(tagName string) (string, error)
// GetSnapshotWithTag returns info about the snapshot with the given tag, or nil if there isn't one
GetSnapshotWithTag(tagName string) (*SnapshotInfo, error)
// Export exports the snapshot stored as <label> to <filename>
Export(label, parent string, writer io.Writer, excludes []string) error
// Import imports the exported snapshot at <filename> as <label>
Import(label string, reader io.Reader) error
// Tenant returns the base tenant of this volume
Tenant() string
}
Volume maps, in the end, to a directory on the filesystem available to the application. It can be snapshotted and rolled back to snapshots. It can be exported to a file and restored from a file.