Documentation
¶
Index ¶
- Constants
- Variables
- func All(Pool) bool
- func BindMount(src Volume, target string) error
- func FilesUsage(path string) (uint64, error)
- func GetMountTarget(device string) (string, bool)
- func IsMountPoint(path string) bool
- func Partprobe(ctx context.Context) error
- type Btrfs
- type BtrfsDevice
- type BtrfsDiskUsage
- type BtrfsQGroup
- type BtrfsUtil
- func (u *BtrfsUtil) DeviceAdd(ctx context.Context, dev string, root string) error
- func (u *BtrfsUtil) DeviceRemove(ctx context.Context, dev string, root string) error
- func (u *BtrfsUtil) GetDiskUsage(ctx context.Context, path string) (usage BtrfsDiskUsage, err error)
- func (u *BtrfsUtil) List(ctx context.Context, label string, mounted bool) ([]Btrfs, error)
- func (u *BtrfsUtil) QGroupDestroy(ctx context.Context, id, path string) error
- func (u *BtrfsUtil) QGroupEnable(ctx context.Context, root string) error
- func (u *BtrfsUtil) QGroupLimit(ctx context.Context, size uint64, path string) error
- func (u *BtrfsUtil) QGroupList(ctx context.Context, path string) (map[string]BtrfsQGroup, error)
- func (u *BtrfsUtil) SubvolumeAdd(ctx context.Context, root string) error
- func (u *BtrfsUtil) SubvolumeInfo(ctx context.Context, path string) (volume BtrfsVolume, err error)
- func (u *BtrfsUtil) SubvolumeList(ctx context.Context, root string) ([]BtrfsVolume, error)
- func (u *BtrfsUtil) SubvolumeRemove(ctx context.Context, root string) error
- type BtrfsVolume
- type DeviceInfo
- func (d *DeviceInfo) AllocateEmptySpace(ctx context.Context, space DiskSpace) error
- func (d *DeviceInfo) DetectType() (zos.DeviceType, error)
- func (d *DeviceInfo) GetUnallocatedSpaces(ctx context.Context) ([]DiskSpace, error)
- func (d *DeviceInfo) IsPXEPartition() bool
- func (d *DeviceInfo) IsPartitioned() bool
- func (d *DeviceInfo) Mountpoint(ctx context.Context) (string, error)
- func (i *DeviceInfo) Name() string
- func (d *DeviceInfo) RefreshDeviceInfo(ctx context.Context) (DeviceInfo, error)
- func (i *DeviceInfo) Used() bool
- type DeviceManager
- type Devices
- type DiskSpace
- type DiskUsage
- type FSType
- type Filter
- type Pool
- type Usage
- type Volume
Constants ¶
const (
ZdbVolume = "zdb"
)
Variables ¶
var ( // ErrDeviceAlreadyMounted indicates that a mounted device is attempted // to be mounted again (without MS_BIND flag). ErrDeviceAlreadyMounted = fmt.Errorf("device is already mounted") // ErrDeviceNotMounted is returned when an action is performed on a device // which requires the device to be mounted, while it is not. ErrDeviceNotMounted = fmt.Errorf("device is not mounted") )
Functions ¶
func BindMount ¶
BindMount remounts an existing directory in a given target using the mount syscall with the BIND flag set
func FilesUsage ¶
FilesUsage return the total size of files under path (recursively) in bytes
func GetMountTarget ¶
GetMountTarget returns the mount target of a device or false if the device is not mounted. panic, it panics if it can't read /proc/mounts
func IsMountPoint ¶
IsMountPoint checks if a path is a mount point
Types ¶
type Btrfs ¶
type Btrfs struct {
Label string `json:"label"`
UUID string `json:"uuid"`
TotalDevices int `json:"total_devices"`
Used int64 `json:"used"`
Devices []BtrfsDevice `json:"devices"`
Warnings string `json:"warnings"`
}
Btrfs holds metadata of underlying btrfs filesystem
type BtrfsDevice ¶
type BtrfsDevice struct {
Missing bool `json:"missing,omitempty"`
DevID int `json:"dev_id"`
Size int64 `json:"size"`
Used int64 `json:"used"`
Path string `json:"path"`
}
BtrfsDevice holds metadata about a single device in a btrfs filesystem
type BtrfsDiskUsage ¶
type BtrfsDiskUsage struct {
Data DiskUsage `json:"data"`
System DiskUsage `json:"system"`
Metadata DiskUsage `json:"metadata"`
GlobalReserve DiskUsage `json:"globalreserve"`
}
BtrfsDiskUsage is parsed information form btrfs fi df
type BtrfsQGroup ¶
BtrfsQGroup is parsed btrfs qgroup information
type BtrfsUtil ¶
type BtrfsUtil struct {
// contains filtered or unexported fields
}
BtrfsUtil utils for btrfs
func (*BtrfsUtil) DeviceRemove ¶
DeviceRemove removes a device from a btrfs pool
func (*BtrfsUtil) GetDiskUsage ¶
func (u *BtrfsUtil) GetDiskUsage(ctx context.Context, path string) (usage BtrfsDiskUsage, err error)
GetDiskUsage get btrfs usage
func (*BtrfsUtil) List ¶
List lists all availabel btrfs pools if label is provided, only get fs of that label, if mounted = True, only return mounted filesystems, otherwise any.
func (*BtrfsUtil) QGroupDestroy ¶
QGroupDestroy deletes a qgroup on a subvol
func (*BtrfsUtil) QGroupEnable ¶
QGroupEnable enable quota
func (*BtrfsUtil) QGroupLimit ¶
QGroupLimit limit size on subvol
func (*BtrfsUtil) QGroupList ¶
QGroupList list available qgroups
func (*BtrfsUtil) SubvolumeAdd ¶
SubvolumeAdd adds a new subvolume at path
func (*BtrfsUtil) SubvolumeInfo ¶
SubvolumeInfo get info of a subvolume giving its path
func (*BtrfsUtil) SubvolumeList ¶
SubvolumeList list direct subvolumes of this location
type BtrfsVolume ¶
BtrfsVolume holds metadata about a single subvolume
type DeviceInfo ¶
type DeviceInfo struct {
Path string `json:"path"`
Label string `json:"label"`
Size uint64 `json:"size"`
Filesystem FSType `json:"fstype"`
Rota bool `json:"rota"`
Subsystems string `json:"subsystems"`
UUID string `json:"uuid"`
Children []DeviceInfo `json:"children,omitempty"`
// contains filtered or unexported fields
}
DeviceInfo contains information about the device
func (*DeviceInfo) AllocateEmptySpace ¶
func (d *DeviceInfo) AllocateEmptySpace(ctx context.Context, space DiskSpace) error
func (*DeviceInfo) DetectType ¶
func (d *DeviceInfo) DetectType() (zos.DeviceType, error)
DetectType returns the device type according to seektime
func (*DeviceInfo) GetUnallocatedSpaces ¶
func (d *DeviceInfo) GetUnallocatedSpaces(ctx context.Context) ([]DiskSpace, error)
func (*DeviceInfo) IsPXEPartition ¶
func (d *DeviceInfo) IsPXEPartition() bool
func (*DeviceInfo) IsPartitioned ¶
func (d *DeviceInfo) IsPartitioned() bool
func (*DeviceInfo) Mountpoint ¶
func (d *DeviceInfo) Mountpoint(ctx context.Context) (string, error)
func (*DeviceInfo) Name ¶
func (i *DeviceInfo) Name() string
func (*DeviceInfo) RefreshDeviceInfo ¶
func (d *DeviceInfo) RefreshDeviceInfo(ctx context.Context) (DeviceInfo, error)
func (*DeviceInfo) Used ¶
func (i *DeviceInfo) Used() bool
Used assumes that the device is used if it has custom label or fstype or children
type DeviceManager ¶
type DeviceManager interface {
// Device returns the device at the specified path
Device(ctx context.Context, device string) (DeviceInfo, error)
// Devices finds all devices on a system
Devices(ctx context.Context) (Devices, error)
// ByLabel finds all devices with the specified label
ByLabel(ctx context.Context, label string) (Devices, error)
// Mountpoint returns mount point of a device
Mountpoint(ctx context.Context, device string) (string, error)
// Seektime checks device seektime
Seektime(ctx context.Context, device string) (zos.DeviceType, error)
// ClearCache clears the cached devices to refresh
ClearCache()
}
DeviceManager is able to list all/specific devices on a system
func DefaultDeviceManager ¶
func DefaultDeviceManager() DeviceManager
DefaultDeviceManager returns a default device manager implementation
type FSType ¶
type FSType string
FSType type of filesystem on device
const ( // BtrfsFSType btrfs filesystem type BtrfsFSType FSType = "btrfs" )
type Pool ¶
type Pool interface {
Volume
// Mounted returns whether the pool is mounted or not. If it is mounted,
// the mountpoint is returned
Mounted() (string, error)
// Mount the pool, the mountpoint is returned
Mount() (string, error)
// UnMount the pool
UnMount() error
// Volumes are all subvolumes of this volume
Volumes() ([]Volume, error)
// AddVolume adds a new subvolume with the given name
AddVolume(name string) (Volume, error)
// RemoveVolume removes a subvolume with the given name
RemoveVolume(name string) error
// Shutdown spins down the device where the pool is mounted
Shutdown() error
// Device return device associated with pool
Device() DeviceInfo
// SetType sets a device type on the pool. this will make
// sure that the detected device type is reported
// correctly by calling the Type() method.
SetType(typ zos.DeviceType) error
// Type returns the device type set by a previous call
// to SetType.
Type() (zos.DeviceType, bool, error)
}
Pool represents a created filesystem
func NewBtrfsPool ¶
func NewBtrfsPool(device DeviceInfo) (Pool, error)
NewBtrfsPool creates a btrfs pool associated with device. if device does not have a filesystem one is created
type Usage ¶
type Usage struct {
// Size is allocated space for this Volume
// if 0 it means it has no limit.
// if it has no-limit, the Used attribute
// will be the total size of actual files
// inside the volume. It also means the Used
// can keep growing to the max possible which
// is the size of the pool
Size uint64
// Used can be one of 2 things:
// - If Size is not zero (so size is limited), Used will always equal to size
// because that's the total reserved space for that volume.
// - If Size is zero, (no limit) Used will be the total actual size of all
// files in that volume.
// The reason Used is done this way, it will make it easier to compute
// all allocated space in a pool by going over all volumes and add the
// used on each. It does not matter if this space is reserved but not used
// because it means we can't allocate over that.
//
// NOTE: Special case, if this is a `zdb` volume the Used is instead
// have the total size of reserved namespaces in that volume
Used uint64
// In case of `limited` volume (with quota) Excl will have a "guessed"
// value of the total used space by files. This value is not accurate
// and Used should be used instead for all capacity planning.
Excl uint64
}
Usage struct (in bytes)
type Volume ¶
type Volume interface {
// Volume ID
ID() int
// Path of the volume
Path() string
// Usage reports the current usage of the volume
Usage() (Usage, error)
// Limit the maximum size of the volume
Limit(size uint64) error
// Name of the volume
Name() string
// FsType of the volume
FsType() string
}
Volume represents a logical volume in the pool. Volumes can be nested