filesystem

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 All

func All(Pool) bool

All is default filter

func BindMount

func BindMount(src Volume, target string) error

BindMount remounts an existing directory in a given target using the mount syscall with the BIND flag set

func FilesUsage

func FilesUsage(path string) (uint64, error)

FilesUsage return the total size of files under path (recursively) in bytes

func GetMountTarget

func GetMountTarget(device string) (string, bool)

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

func IsMountPoint(path string) bool

IsMountPoint checks if a path is a mount point

func Partprobe

func Partprobe(ctx context.Context) error

Partprobe runs partprobe

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

type BtrfsQGroup struct {
	ID      string
	Rfer    uint64
	Excl    uint64
	MaxRfer uint64
	MaxExcl uint64
}

BtrfsQGroup is parsed btrfs qgroup information

type BtrfsUtil

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

BtrfsUtil utils for btrfs

func NewUtils

func NewUtils() BtrfsUtil

NewUtils create a new BtrfsUtil object

func (*BtrfsUtil) DeviceAdd

func (u *BtrfsUtil) DeviceAdd(ctx context.Context, dev string, root string) error

DeviceAdd adds a device to a btrfs pool

func (*BtrfsUtil) DeviceRemove

func (u *BtrfsUtil) DeviceRemove(ctx context.Context, dev string, root string) error

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

func (u *BtrfsUtil) List(ctx context.Context, label string, mounted bool) ([]Btrfs, error)

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

func (u *BtrfsUtil) QGroupDestroy(ctx context.Context, id, path string) error

QGroupDestroy deletes a qgroup on a subvol

func (*BtrfsUtil) QGroupEnable

func (u *BtrfsUtil) QGroupEnable(ctx context.Context, root string) error

QGroupEnable enable quota

func (*BtrfsUtil) QGroupLimit

func (u *BtrfsUtil) QGroupLimit(ctx context.Context, size uint64, path string) error

QGroupLimit limit size on subvol

func (*BtrfsUtil) QGroupList

func (u *BtrfsUtil) QGroupList(ctx context.Context, path string) (map[string]BtrfsQGroup, error)

QGroupList list available qgroups

func (*BtrfsUtil) SubvolumeAdd

func (u *BtrfsUtil) SubvolumeAdd(ctx context.Context, root string) error

SubvolumeAdd adds a new subvolume at path

func (*BtrfsUtil) SubvolumeInfo

func (u *BtrfsUtil) SubvolumeInfo(ctx context.Context, path string) (volume BtrfsVolume, err error)

SubvolumeInfo get info of a subvolume giving its path

func (*BtrfsUtil) SubvolumeList

func (u *BtrfsUtil) SubvolumeList(ctx context.Context, root string) ([]BtrfsVolume, error)

SubvolumeList list direct subvolumes of this location

func (*BtrfsUtil) SubvolumeRemove

func (u *BtrfsUtil) SubvolumeRemove(ctx context.Context, root string) error

SubvolumeRemove removes a subvolume

type BtrfsVolume

type BtrfsVolume struct {
	Path       string
	ID         int
	Generation int
	ParentID   int
}

BtrfsVolume holds metadata about a single subvolume

type DeviceInfo added in v0.5.5

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"`
	Readtime   uint64 `json:"-"`
	// contains filtered or unexported fields
}

DeviceInfo contains information about the device

func (*DeviceInfo) Mountpoint added in v0.5.5

func (d *DeviceInfo) Mountpoint(ctx context.Context) (string, error)

func (*DeviceInfo) Name added in v0.5.5

func (i *DeviceInfo) Name() string

func (*DeviceInfo) Type added in v0.5.5

func (d *DeviceInfo) Type() zos.DeviceType

func (*DeviceInfo) Used added in v0.5.5

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

DeviceManager is able to list all/specific devices on a system

func DefaultDeviceManager

func DefaultDeviceManager() DeviceManager

DefaultDeviceManager returns a default device manager implementation

type Devices added in v0.5.5

type Devices []DeviceInfo

Devices represents a list of cached in memory devices

type DiskUsage

type DiskUsage struct {
	Total uint64 `json:"total"`
	Used  uint64 `json:"used"`
}

DiskUsage is parsed information from a btrfs fi df line

type FSType

type FSType string

FSType type of filesystem on device

const (
	// BtrfsFSType btrfs filesystem type
	BtrfsFSType FSType = "btrfs"
)

type Filter

type Filter func(pool Pool) bool

Filter closure for Filesystem list

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
	//AddDevice to the pool
	// RemoveDevice from the pool
	// Type of the physical storage in this pool
	Type() pkg.DeviceType
	// Reserved is reserved size of the devices in bytes
	Reserved() (uint64, 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
}

Pool represents a created filesystem

func NewBtrfsPool added in v0.5.5

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 uint64
	Used 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

Jump to

Keyboard shortcuts

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