devmapper

package module
v0.0.0-...-48f6140 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2018 License: GPL-3.0 Imports: 4 Imported by: 0

README

devmapper

Devmapper is a Go library for the Linux devicemapper subsystem, a.k.a. LVM2.

This project is a work in progress, in the early stages of development.

Documentation

Overview

Package devicemapper is a collection of wrappers around libdevmapper / liblvm2.

Index

Constants

View Source
const (
	LVM_VG_READ_ONLY  = "r"
	LVM_VG_READ_WRITE = "w"
)
View Source
const (
	// Defined in <linux/loop.h>
	LOOP_SET_FD       = 0x4c00
	LOOP_CLR_FD       = 0x4c01
	LOOP_CTL_GET_FREE = 0x4c82
)

Variables

This section is empty.

Functions

func GetDeviceList

func GetDeviceList() (devices []dmDevice, err error)

GetDeviceList returns a list of devmapper devices, including device number and name

func GetDeviceTable

func GetDeviceTable(name string) (targets []dmTarget, err error)

Types

type LVMError

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

LVMError represents an error from liblvm2.

func (*LVMError) Error

func (e *LVMError) Error() string

type LVMHandle

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

An LVMHandle is the base handle for interacting with liblvm2.

func InitLVM

func InitLVM() (*LVMHandle, error)

InitLVM returns an LVMHandle which can subsequently be used to open and create objects such as phsical volumes, volume groups, and logical volumes. Once all LVM operations have been completed, call Close() to release the handle and any associated resources.

func (*LVMHandle) Close

func (lvm *LVMHandle) Close()

Close destroys an LVM handle that was created by InitLVM(). This method should be called after all volume groups have been closed, and the LVM handle should not be used again after it has been closed.

func (*LVMHandle) CreatePV

func (lvm *LVMHandle) CreatePV(device string, size uint64) error

CreatePV creates a physical volume on the specified absolute device name (e.g., /dev/sda1), with size `size` bytes. Size should be a multiple of 512 bytes. A size of zero bytes will use the entire device.

func (*LVMHandle) CreateVG

func (lvm *LVMHandle) CreateVG(name string) (*VolumeGroup, error)

CreateVG creates a volume group object with default parameters. Upon success, other methods may be used to set non-default parameters, such as extent size. Once all parameters have been set, call Write() to commit the new VG to disk, and Close() to release the handle.

func (*LVMHandle) GetVGNames

func (lvm *LVMHandle) GetVGNames() (names []string)

GetVGNames returns a list of names of all volume groups in the system.

func (*LVMHandle) GetVGUUIDs

func (lvm *LVMHandle) GetVGUUIDs() (uuids []string)

GetVGUUIDs returns a list of UUIDs of all volume groups in the system.

func (*LVMHandle) OpenVG

func (lvm *LVMHandle) OpenVG(name, mode string) (*VolumeGroup, error)

OpenVG returns a VolumeGroup object for specified volume group name. The volume group can be opened in read-only or read-write mode, specified by a string of "r" or "w" respectively.

func (*LVMHandle) RemovePV

func (lvm *LVMHandle) RemovePV(name string) error

RemovePV removes a physical volume from the LVM subsystem.

type LogicalVolume

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

A LogicalVolume represents an LVM logical volume object, and belongs to a parent volume group.

func (*LogicalVolume) Activate

func (lv *LogicalVolume) Activate() error

Activate activates a logical volume, and is equivalent to the lvm command "lvchange -ay".

func (*LogicalVolume) Deactivate

func (lv *LogicalVolume) Deactivate() error

Deactivate deactivates a logical volume, and is equivalent to the lvm command "lvchange -an".

func (*LogicalVolume) GetAttrs

func (lv *LogicalVolume) GetAttrs() []byte

GetAttrs returns the current attributes of a logical volume, e.g.: "-wi-a-----".

func (*LogicalVolume) GetName

func (lv *LogicalVolume) GetName() string

GetName returns the current name of a logical volume.

func (*LogicalVolume) GetSize

func (lv *LogicalVolume) GetSize() uint64

GetSize returns the current size of a logical volume in bytes.

func (*LogicalVolume) GetUUID

func (lv *LogicalVolume) GetUUID() string

GetUUID returns the current LVM UUID of a logical volume.

func (*LogicalVolume) IsActive

func (lv *LogicalVolume) IsActive() bool

IsActive returns the current activation state of a logical volume.

func (*LogicalVolume) Remove

func (lv *LogicalVolume) Remove() error

Remove removes a logical volume from its volume group. This function commits the change to disk and does not require calling Write().

type PhysicalVolume

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

A PhysicalVolume represents an LVM physical volume object.

func (*PhysicalVolume) GetDevSize

func (pv *PhysicalVolume) GetDevSize() uint64

GetDevSize returns the current size of a device underlying a physical volume, in bytes. This should be larger than the value returned by GetSize(), due to space occupied by metadata.

func (*PhysicalVolume) GetFree

func (pv *PhysicalVolume) GetFree() uint64

GetFree returns the current unallocated space of a physical volume in bytes.

func (*PhysicalVolume) GetMDACount

func (pv *PhysicalVolume) GetMDACount() uint64

GetMDACount returns the current number of metadata areas in a physical volume.

func (*PhysicalVolume) GetName

func (pv *PhysicalVolume) GetName() string

GetName returns the current name of a physical volume, e.g., /dev/sda1.

func (*PhysicalVolume) GetSize

func (pv *PhysicalVolume) GetSize() uint64

GetSize returns the current size of a physical volume in bytes. This should be smaller than the value returned by get GetDevSize(), due to space occupied by metadata.

func (*PhysicalVolume) GetUUID

func (pv *PhysicalVolume) GetUUID() string

GetUUID returns the current LVM UUID of a physical volume.

type VolumeGroup

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

A VolumeGroup represents an LVM volume group object, can contain zero or more logical volumes, and is comprised of one or more physical volumes.

func (*VolumeGroup) Close

func (vg *VolumeGroup) Close() error

Close releases a VG handle and any resources associated with it. Since many underlying liblvm2 functions only release memory when a VG handle is closed, this should be called when a VG object is no longer needed, to avoid leaking memory.

func (*VolumeGroup) CreateLVLinear

func (vg *VolumeGroup) CreateLVLinear(name string, size uint64) (*LogicalVolume, error)

CreateLVLinear creates a linear logical volume. The size, specified in bytes, must be at least one sector (512 bytes), and will be rounded up to the next extent multiple. This method commits the change to disk, and does not require calling Write().

func (*VolumeGroup) Extend

func (vg *VolumeGroup) Extend(device string) error

Extend adds a physical volume to a volume group. After extending a volume group, Write() must be called to commit the change to disk. Upon failure, retry the operation or release the VG handle with Close().

func (*VolumeGroup) GetExtentCount

func (vg *VolumeGroup) GetExtentCount() uint64

GetExtentCount returns the current number of total extents in a volume group.

func (*VolumeGroup) GetExtentSize

func (vg *VolumeGroup) GetExtentSize() uint64

GetExtentSize returns the current extent size of a volume group in bytes.

func (*VolumeGroup) GetFreeExtentCount

func (vg *VolumeGroup) GetFreeExtentCount() uint64

GetFreeExtentCount returns the current number of free extents in a volume group.

func (*VolumeGroup) GetFreeSize

func (vg *VolumeGroup) GetFreeSize() uint64

GetFreeSize returns the current unallocated space of a volume group in bytes.

func (*VolumeGroup) GetMaxLV

func (vg *VolumeGroup) GetMaxLV() uint64

GetMaxLV returns the maximum number of logical volumes allowed in a volume group.

func (*VolumeGroup) GetName

func (vg *VolumeGroup) GetName() string

GetName returns the current name of a volume group.

func (*VolumeGroup) GetPVCount

func (vg *VolumeGroup) GetPVCount() uint64

GetPVCount returns the current number of physical volumes of a volume group.

func (*VolumeGroup) GetSequenceNum

func (vg *VolumeGroup) GetSequenceNum() uint64

GetSequenceNum returns the current metadata sequence number of a volume group. The metadata sequence number is incrented for each metadata change. Applications may use the sequence number to determine if any LVM objects have changed from a prior query.

func (*VolumeGroup) GetSize

func (vg *VolumeGroup) GetSize() uint64

GetSize returns the current size of a volume group in bytes.

func (*VolumeGroup) GetUUID

func (vg *VolumeGroup) GetUUID() string

GetUUID returns the current LVM UUID of a volume group.

func (*VolumeGroup) PVFromName

func (vg *VolumeGroup) PVFromName(device string) (*PhysicalVolume, error)

PVFromName returns an object representing the physical volume specified by name.

func (*VolumeGroup) PVFromUUID

func (vg *VolumeGroup) PVFromUUID(uuid string) (*PhysicalVolume, error)

PVFromUUID returns an object representing the physical volume specified by UUID.

func (*VolumeGroup) Remove

func (vg *VolumeGroup) Remove() error

Remove removes an underlying LVM handle to a volume group in memory, and requires calling Write() to commit the removal to disk.

func (*VolumeGroup) Write

func (vg *VolumeGroup) Write() error

Write commits a volume group to disk. Upon error, retry the operation or release the VG handle with Close().

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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