volume

package
v0.0.0-...-1c5d739 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const FlagFileName = ".initialized"

Variables

View Source
var (
	ErrNotADirectory = errors.New("not a directory")
	ErrBtrfsCommand  = errors.New("error running btrfs command")
)
View Source
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")
)
View Source
var DeviceMapperStatusTemplate = `` /* 1138-byte string literal not displayed */
View Source
var ErrWrongDataType = errors.New("Wrong data type for Usage Value")

Functions

func BlocksToBytes

func BlocksToBytes(blocks uint64) string

func BytesToBlocks

func BytesToBlocks(bytes uint64) uint64

func DefaultSnapshotLabel

func DefaultSnapshotLabel(tenant, label string) string

func ExportDirectory

func ExportDirectory(tarfile *tar.Writer, path, name string) error

ExportDirectory recursively writes its contents into a tar Writer.

func ExportFile

func ExportFile(tarfile *tar.Writer, path, name string) error

ExportFile writes a file into a tar Writer.

func FilesystemBytesAvailable

func FilesystemBytesAvailable(path string) uint64

func FilesystemBytesSize

func FilesystemBytesSize(path string) uint64

func FilesystemBytesUsed

func FilesystemBytesUsed(path string) uint64

func FlagFilePath

func FlagFilePath(root string) string

func GetLastIOStat

func GetLastIOStat() (map[string]iostat.DeviceUtilizationReport, bool)

GetLastIOStat returns the iostat device utilization reports

func ImportArchive

func ImportArchive(tarfile *tar.Reader, path string) error

ImportArchive reads from a tar Reader and writes the contents into a path preserving file permissions and ownership.

func ImportArchiveHeader

func ImportArchiveHeader(header *tar.Header, reader io.Reader, path string) error

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

func InitIOStat(getter iostat.Getter, closeChannel <-chan interface{})

InitIOStat starts the iostat call and passes the close signal when sent

func IsBtrfsFilesystem

func IsBtrfsFilesystem(path string) bool

IsBtrfsFilesystem determines whether the path is a btrfs filesystem

func IsDir

func IsDir(dirName string) (dir bool, err error)

IsDir() checks if the given dir is a directory. If any error is encoutered it is returned and directory is set to false.

func IsRoot

func IsRoot() bool

func IsSudoer

func IsSudoer() bool

func Noescape

func Noescape(s string) template.HTML

func Percent

func Percent(amt, total uint64) string

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

func RunBtrFSCmd(sudoer bool, args ...string) ([]byte, error)

RunBtrFSCmd runs a btrfs command, optionally using sudo

func ShutdownAll

func ShutdownAll() error

ShutdownAll shuts down all drivers that have been initialized

func ShutdownDriver

func ShutdownDriver(rootDir string) error

ShutdownDriver shuts down an existing driver and removes it from our internal map.

func SplitPath

func SplitPath(volumePath string) (string, string, error)

SplitPath splits a path by its driver and respective volume. Returns error if the driver is not initialized.

func ToBytes

func ToBytes(from uint64) string

func TouchFlagFile

func TouchFlagFile(root string) error

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.

func GetDriver

func GetDriver(root string) (Driver, error)

GetDriver returns the driver from path <root>.

type DriverInit

type DriverInit func(root string, args []string) (Driver, error)

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

type FileInfoSlice []os.FileInfo

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 SnapshotInfo struct {
	Name     string
	TenantID string
	Label    string
	Tags     []string
	Message  string
	Created  time.Time
}

type Status

type Status interface {
	String() string
	GetUsageData() UsageData
}

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

func (s *Statuses) GetAllStatuses() map[string]Status

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 Usage

type Usage interface {
	GetMetricName() string
	GetLabel() string
	GetType() string
	GetValueUInt64() (uint64, error)
	GetValueFloat64() (float64, error)
}

type UsageData

type UsageData []Usage

UsageData implements Unmarshaler allowing us to unmarshal a []Usage indirectly

func (*UsageData) UnmarshalJSON

func (u *UsageData) UnmarshalJSON(data []byte) error

UnmarshalJSON satisfies Unmarshaler interface

type UsageFloat

type UsageFloat struct {
	MetricName string
	Label      string
	Type       string
	Value      float64
}

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

type UsageInt struct {
	MetricName string
	Label      string
	Type       string
	Value      uint64
}

func (UsageInt) GetLabel

func (u UsageInt) GetLabel() string

func (UsageInt) GetMetricName

func (u UsageInt) GetMetricName() string

func (UsageInt) GetType

func (u UsageInt) GetType() string

func (UsageInt) GetValueFloat64

func (u UsageInt) GetValueFloat64() (float64, error)

func (UsageInt) GetValueUInt64

func (u UsageInt) GetValueUInt64() (uint64, error)

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.

func FindMount

func FindMount(volumePath string) (Volume, error)

FindMount mounts a path based on the relative location of the nearest driver.

func Mount

func Mount(volumeName, rootDir string) (volume Volume, err error)

Mount loads, mounting if necessary, a volume under a path using a specific driver path at <root>.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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