filesystem

package
v0.2.2-rc7 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: Apache-2.0 Imports: 17 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 IsZDBVolume

func IsZDBVolume(v Volume) bool

IsZDBVolume checks if this is a zdb subvolume

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 (*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 ByReadTime

type ByReadTime DeviceCache

ByReadTime implements sort.Interface for []Device based on the ReadTime field

func (ByReadTime) Len

func (a ByReadTime) Len() int

func (ByReadTime) Less

func (a ByReadTime) Less(i, j int) bool

func (ByReadTime) Swap

func (a ByReadTime) Swap(i, j int)

type Device

type Device struct {
	Type       string         `json:"type"`
	Path       string         `json:"name"`
	Label      string         `json:"label"`
	Filesystem FSType         `json:"fstype"`
	Children   []Device       `json:"children"`
	DiskType   pkg.DeviceType `json:"-"`
	ReadTime   uint64         `json:"-"`
	//HasPartions is different from children, because once the
	//devices are flattend in the device, cache, the children list is
	//zeroed (since all devices are flat), then has partions is set to
	//make sure the device is not altered.
	HasPartions bool `json:"-"`
}

Device represents a physical device

func (*Device) Used

func (d *Device) Used() bool

Used assumes that the device is used if it has custom label or fstype or children

type DeviceCache

type DeviceCache []Device

DeviceCache represents a list of cached in memory devices

type DeviceManager

type DeviceManager interface {
	// Device returns the device at the specified path
	Device(ctx context.Context, device string) (*Device, error)
	// Devices finds all devices on a system
	Devices(ctx context.Context) (DeviceCache, error)
	// ByLabel finds all devices with the specified label
	ByLabel(ctx context.Context, label string) ([]*Device, error)
	// Raw returns the devices as represented in the kernel
	// without using the internal cache, nor flattened
	Raw(ctx context.Context) (DeviceCache, error)
	// Reset returns a "clean" instace of the device manager
	// The implementation must take care to clean any caching
	// or other in-memory states and starting fresh. It's called
	// by some routines to make sure a listing of devices will
	// always return the real state of the system.
	Reset() DeviceManager
}

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

func DefaultDeviceManager

func DefaultDeviceManager(ctx context.Context) DeviceManager

DefaultDeviceManager returns a default device manager implementation

func Migrate

func Migrate(ctx context.Context, m DeviceManager) (DeviceManager, error)

Migrate is a simple migration routine that makes sure we have fresh disks to use from zos v1, in case you moving away from older version After migration you should alway use the returned Device manager, or create a new one.

type DiskUsage

type DiskUsage struct {
	Profile pkg.RaidProfile `json:"profile"`
	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 Filesystem

type Filesystem interface {
	// Create a new filesystem.
	//
	// name: name of the filesystem
	// devices: list of devices to use in the filesystem
	// profile: Raid profile of the filesystem
	Create(ctx context.Context, name string, profile pkg.RaidProfile, devices ...*Device) (Pool, error)
	// List all existing filesystems on the node
	List(ctx context.Context, filter Filter) ([]Pool, error)
}

Filesystem defines a filesystem interface

func NewBtrfs

func NewBtrfs(manager DeviceManager) Filesystem

NewBtrfs creates a new filesystem that implements 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, bool)
	// Mount the pool, the mountpoint is returned
	Mount() (string, error)
	// UnMount the pool
	UnMount() error
	//AddDevice to the pool
	AddDevice(device *Device) error
	// RemoveDevice from the pool
	RemoveDevice(device *Device) error
	// Type of the physical storage in this pool
	Type() pkg.DeviceType
	// Reserved is reserved size of the devices in bytes
	Reserved() (uint64, error)
	// Maintenance is a routine that is called at boot
	// and that all implementer can use to do some clean up and
	// other maintenance on the pool
	Maintenance() 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
	// Devices list attached devices
	Devices() []*Device
}

Pool represents a created filesystem

type Usage

type Usage struct {
	Size uint64
	Used uint64
}

Usage struct

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