lvm

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

lvm

LVM library in Go

Documentation

Index

Constants

View Source
const ErrInvalidLVName = simpleError("lvm: Name contains invalid character, valid set includes: [A-Za-z0-9_+.-]")
View Source
const ErrInvalidVGName = simpleError("lvm: Name contains invalid character, valid set includes: [A-Za-z0-9_+.-]")
View Source
const ErrLogicalVolumeNotFound = simpleError("lvm: logical volume not found")
View Source
const ErrNoSpace = simpleError("lvm: not enough free space")
View Source
const ErrPhysicalVolumeNotFound = simpleError("lvm: physical volume not found")
View Source
const ErrTagHasInvalidChars = simpleError("lvm: Tag must consist of only [A-Za-z0-9_+.-] and cannot start with a '-'")
View Source
const ErrTagInvalidLength = simpleError("lvm: Tag length must be between 1 and 1024 characters")
View Source
const ErrTooFewDisks = simpleError("lvm: not enough underlying devices")
View Source
const ErrVolumeGroupNotFound = simpleError("lvm: volume group not found")
View Source
const MaxSize uint64 = 0

MaxSize states that all available space should be used by the create operation.

Variables

View Source
var (
	// VolumeTypeDefault is the zero-value of VolumeType and is used to
	// specify no --type= flag if an empty VolumeLayout is provided.
	VolumeTypeDefault VolumeType
	VolumeTypeLinear  = VolumeType{"linear"}
	VolumeTypeRAID1   = VolumeType{"raid1"}
)
View Source
var Verbose bool

Control verbose output of all LVM CLI commands

Functions

func IsLogicalVolumeNotFound

func IsLogicalVolumeNotFound(err error) bool

func IsPhysicalVolumeNotFound

func IsPhysicalVolumeNotFound(err error) bool

func IsVolumeGroupNotFound

func IsVolumeGroupNotFound(err error) bool

func LVMatchTag

func LVMatchTag(tag string) func(lvsItem) bool

func ListVolumeGroupNames

func ListVolumeGroupNames() ([]string, error)

ListVolumeGroupNames returns the names of the list of volume groups. This does not normally scan for devices. To scan for devices, use the `Scan()` function.

func ListVolumeGroupUUIDs

func ListVolumeGroupUUIDs() ([]string, error)

ListVolumeGroupUUIDs returns the UUIDs of the list of volume groups. This does not normally scan for devices. To scan for devices, use the `Scan()` function.

func PVScan

func PVScan(dev string) error

PVScan runs the `pvscan --cache <dev>` command. It scans for the device at `dev` and adds it to the LVM metadata cache if `lvmetad` is running. If `dev` is an empty string, it scans all devices.

func SetLockFilePath

func SetLockFilePath(filepath string)

SetLockFilePath sets the path to the LOCK file to use for preventing concurrent invocations of LVM command-line utilities.

See - https://jira.mesosphere.com/browse/DCOS_OSS-5434 - https://github.com/lvmteam/lvm2/issues/23

func SetLogger

func SetLogger(l logger)

func VGScan

func VGScan(name string) error

VGScan runs the `vgscan --cache <name>` command. It scans for the volume group and adds it to the LVM metadata cache if `lvmetad` is running. If `name` is an empty string, it scans all volume groups.

func ValidateLogicalVolumeName

func ValidateLogicalVolumeName(name string) error

ValidateLogicalVolumeName validates a volume group name. A valid volume group name can consist of a limited range of characters only. The allowed characters are [A-Za-z0-9_+.-].

func ValidateTag

func ValidateTag(tag string) error

ValidateTag validates a tag. LVM tags are strings of up to 1024 characters. LVM tags cannot start with a hyphen. A valid tag can consist of a limited range of characters only. The allowed characters are [A-Za-z0-9_+.-]. As of the Red Hat Enterprise Linux 6.1 release, the list of allowed characters was extended, and tags can contain the /, =, !, :, #, and & characters. See https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/lvm_tags

func ValidateVolumeGroupName

func ValidateVolumeGroupName(name string) error

ValidateVolumeGroupName validates a volume group name. A valid volume group name can consist of a limited range of characters only. The allowed characters are [A-Za-z0-9_+.-].

Types

type CleanupSteps

type CleanupSteps []func() error

CleanupSteps performs deferred cleanup on condition that an error was returned in the caller. This simplifies code where earlier steps need to be undone if a later step fails. It is not currently resilient to panics as this library is not expected to panic.

func (*CleanupSteps) Add

func (fns *CleanupSteps) Add(fn func() error)

Add appends the given cleanup function to those that will be called if an error occurs.

func (*CleanupSteps) Unwind

func (fns *CleanupSteps) Unwind()

Unwind calls the cleanup funcions in LIFO order. It panics if any of them return an error as failure during recovery is itself unrecoverable.

type CreateLogicalVolumeOpt

type CreateLogicalVolumeOpt func(opts *LVOpts)

func VolumeLayoutOpt

func VolumeLayoutOpt(r VolumeLayout) CreateLogicalVolumeOpt

type LVOpts

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

func (LVOpts) Flags

func (o LVOpts) Flags() (opts []string)

type LinearConfig

type LinearConfig struct{}

func (LinearConfig) Flags

func (c LinearConfig) Flags() (fs []string)

type LogicalVolume

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

func (*LogicalVolume) Extend

func (lv *LogicalVolume) Extend(size string, resizeFS bool) error

func (*LogicalVolume) ExtendWithLogicalExtents

func (lv *LogicalVolume) ExtendWithLogicalExtents(extend string, resizeFS bool) error

func (*LogicalVolume) Name

func (lv *LogicalVolume) Name() string

func (*LogicalVolume) Path

func (lv *LogicalVolume) Path() (string, error)

Path returns the device path for the logical volume.

func (*LogicalVolume) Remove

func (lv *LogicalVolume) Remove() error

func (*LogicalVolume) SizeInBytes

func (lv *LogicalVolume) SizeInBytes() uint64

func (*LogicalVolume) Tags

func (lv *LogicalVolume) Tags() ([]string, error)

Tags returns the volume group tags.

type LoopDevice

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

LoopDevice represents a loop device such as `/dev/loop0` backed by a file.

func CreateLoopDevice

func CreateLoopDevice(size uint64) (device *LoopDevice, err error)

CreateLoopDevice returns a file-backed loop device. The caller is responsible for calling `Close()` on the `*LoopDevice` when done with it.

CreateLoopDevice may panic if an error occurs during error recovery.

func (*LoopDevice) Close

func (d *LoopDevice) Close() error

Close detaches the loop device and removes the backing file.

func (*LoopDevice) Path

func (d *LoopDevice) Path() string

func (*LoopDevice) String

func (d *LoopDevice) String() string

type PhysicalVolume

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

func CreatePhysicalVolume

func CreatePhysicalVolume(dev string) (*PhysicalVolume, error)

CreatePhysicalVolume creates a physical volume of the given device.

func ListPhysicalVolumes

func ListPhysicalVolumes() ([]*PhysicalVolume, error)

ListPhysicalVolumes lists all physical volumes.

func LookupPhysicalVolume

func LookupPhysicalVolume(name string) (*PhysicalVolume, error)

LookupPhysicalVolume returns a physical volume with the given name.

func (*PhysicalVolume) Check

func (pv *PhysicalVolume) Check() error

Check runs the pvck command on the physical volume.

func (*PhysicalVolume) Remove

func (pv *PhysicalVolume) Remove() error

Remove removes the physical volume.

type VolumeGroup

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

func CreateVolumeGroup

func CreateVolumeGroup(
	name string,
	pvs []*PhysicalVolume,
	tags []string) (*VolumeGroup, error)

CreateVolumeGroup creates a new volume group.

func LookupVolumeGroup

func LookupVolumeGroup(name string) (*VolumeGroup, error)

LookupVolumeGroup returns the volume group with the given name.

func (*VolumeGroup) BytesFree

func (vg *VolumeGroup) BytesFree(raid VolumeLayout) (uint64, error)

BytesFree returns the unallocated space in bytes of the volume group.

func (*VolumeGroup) BytesTotal

func (vg *VolumeGroup) BytesTotal() (uint64, error)

BytesTotal returns the current size in bytes of the volume group.

func (*VolumeGroup) Check

func (vg *VolumeGroup) Check() error

Check runs the vgck command on the volume group.

func (*VolumeGroup) CreateLogicalVolume

func (vg *VolumeGroup) CreateLogicalVolume(name string, sizeInBytes uint64, tags []string, defaultYes bool, optFns ...CreateLogicalVolumeOpt) (*LogicalVolume, error)

CreateLogicalVolume creates a logical volume of the given device and size.

The actual size may be larger than asked for as the smallest increment is the size of an extent on the volume group in question.

If sizeInBytes is zero the entire available space is allocated.

Additional optional config items can be specified using CreateLogicalVolumeOpt

func (*VolumeGroup) ExtentCount

func (vg *VolumeGroup) ExtentCount() (uint64, error)

ExtentCount returns the number of extents.

func (*VolumeGroup) ExtentFreeCount

func (vg *VolumeGroup) ExtentFreeCount(raid VolumeLayout) (uint64, error)

ExtentFreeCount returns the number of free extents.

func (*VolumeGroup) ExtentSize

func (vg *VolumeGroup) ExtentSize() (uint64, error)

ExtentSize returns the size in bytes of a single extent.

func (*VolumeGroup) FindLogicalVolume

func (vg *VolumeGroup) FindLogicalVolume(matchFirst func(lvsItem) bool) (*LogicalVolume, error)

FindLogicalVolume looks up the logical volume in the volume group with the given name.

func (*VolumeGroup) ListLogicalVolumeNames

func (vg *VolumeGroup) ListLogicalVolumeNames() ([]string, error)

ListLogicalVolumes returns the names of the logical volumes in this volume group.

func (*VolumeGroup) ListPhysicalVolumeNames

func (vg *VolumeGroup) ListPhysicalVolumeNames() ([]string, error)

ListPhysicalVolumeNames returns the names of the physical volumes in this volume group.

func (*VolumeGroup) LookupLogicalVolume

func (vg *VolumeGroup) LookupLogicalVolume(name string) (*LogicalVolume, error)

LookupLogicalVolume looks up the logical volume in the volume group with the given name.

func (*VolumeGroup) Name

func (vg *VolumeGroup) Name() string

func (*VolumeGroup) Remove

func (vg *VolumeGroup) Remove() error

Remove removes the volume group from disk.

func (*VolumeGroup) Tags

func (vg *VolumeGroup) Tags() ([]string, error)

Tags returns the volume group tags.

type VolumeLayout

type VolumeLayout struct {
	// Type corresponds to the --type= option to lvcreate.
	Type VolumeType
	// Type corresponds to the --mirrors= option to lvcreate.
	Mirrors uint64
	// Type corresponds to the --stripes= option to lvcreate.
	Stripes uint64
	// Type corresponds to the --stripesize= option to lvcreate.
	StripeSize uint64
}

VolumeLayout controls the RAID-related CLI options passed to lvcreate. See the lvmraid or lvcreate man pages for more details on what these options mean and how they may be used.

func (VolumeLayout) Flags

func (c VolumeLayout) Flags() (fs []string)

func (VolumeLayout) MinNumberOfDevices

func (c VolumeLayout) MinNumberOfDevices() uint64

type VolumeType

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

VolumeType controls the value of the --type= flag when logical volumes are created. Its constructor is not exported to ensure that the user cannot specify unexpected values.

Jump to

Keyboard shortcuts

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