filesystem

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 26, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ZdbVolume = "zdb"
)

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

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

DeviceInfo contains information about the device

func (*DeviceInfo) DetectType

func (d *DeviceInfo) DetectType() (zos.DeviceType, error)

DetectType returns the device type according to seektime

func (*DeviceInfo) Mountpoint

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

func (*DeviceInfo) Name

func (i *DeviceInfo) Name() string

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

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

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
	// 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

Jump to

Keyboard shortcuts

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