lvm2

package
v3.0.0-rc67 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExist = errors.New("does not exist")
)

Functions

func DMDevPath

func DMDevPath(vg, lv string) string

func DMName

func DMName(vg, lv string) string

func IsCapable

func IsCapable() bool

func PVScan

func PVScan(log *plog.Logger) error

func WithLogger

func WithLogger(log *plog.Logger) funcopt.O

Types

type LV

type LV struct {
	LVName string
	VGName string
	// contains filtered or unexported fields
}

func LVOfDevice

func LVOfDevice(ctx context.Context, dev string, opts ...funcopt.O) (*LV, error)

LVOfDevice returns the logical volume dev is, and nil when it is none, or when lvm is not installed.

func NewLV

func NewLV(vg string, lv string, opts ...funcopt.O) *LV

func (*LV) Activate

func (t *LV) Activate(ctx context.Context) error

func (*LV) Attrs

func (t *LV) Attrs(ctx context.Context) (LVAttrs, error)

func (*LV) Create

func (t *LV) Create(ctx context.Context, size string, args []string) error

Create makes the logical volume, of the size given as the configuration spells it.

A share of the volume group is what lvm2 computes, from an extent count, so it is handed over as written. Everything else is a count of bytes, and the unit is spelled out because lvcreate does not default to bytes.

func (*LV) CreateSnapshot

func (t *LV) CreateSnapshot(ctx context.Context, name string, size int64) (*LV, error)

CreateSnapshot creates the snapshot name of the volume, and returns it. A thin volume is snapshotted in its pool, and size is ignored. A thick one is given size bytes to hold what is written to the volume while the snapshot lives: lvm drops a snapshot running out of it.

Taking the snapshot suspends the volume, which freezes the filesystem on it first, so the snapshot holds a clean filesystem.

func (*LV) CreateThin

func (t *LV) CreateThin(ctx context.Context, size string, pool string, args []string) error

CreateThin makes the logical volume a thin volume of the thin pool named pool, in the same volume group, of the size it is seen with. A share of the volume group is no size a thin volume is made with.

func (*LV) Deactivate

func (t *LV) Deactivate(ctx context.Context) error

func (LV) DevPath

func (t LV) DevPath() string

func (*LV) Devices

func (t *LV) Devices(ctx context.Context) (device.L, error)

func (LV) DriverName

func (t LV) DriverName() string

func (*LV) Exists

func (t *LV) Exists(ctx context.Context) (bool, error)

func (LV) FQN

func (t LV) FQN() string

func (*LV) IsActive

func (t *LV) IsActive(ctx context.Context) (bool, error)

func (*LV) Log

func (t *LV) Log() *plog.Logger

func (*LV) Remove

func (t *LV) Remove(ctx context.Context, args []string) error

func (*LV) Resize

func (t *LV) Resize(ctx context.Context, size int64) error

Resize sets the size of the logical volume, in bytes.

The filesystem on it is not touched. Which of the things stacked on a volume to resize, and in which order, is the caller's to decide, where lvresize --resizefs would decide it here.

func (*LV) SetLog

func (t *LV) SetLog(log *plog.Logger)

func (*LV) Show

func (t *LV) Show(ctx context.Context) (*LVInfo, error)

func (*LV) Size

func (t *LV) Size(ctx context.Context) (int64, error)

Size is the bytes the logical volume holds.

func (*LV) Wipe

func (t *LV) Wipe(ctx context.Context) error

Wipe erases the signatures of the volume, and zeroes its end, so the extents it frees hand nothing of what it held to the next volume made on them.

func (*LV) ZeroTail

func (t *LV) ZeroTail(_ context.Context) error

ZeroTail zeroes the last device.TailWipeSize bytes of the volume. lvcreate wipes the signatures its libblkid knows, and zeroes the first 4 KiB: on an older distribution, the drbd metadata a volume left at the end of its extents is found by the next volume made on them, and taken for its own.

type LVAttr

type LVAttr rune
const (
	LVAttrStateActive                               LVAttr = 'a'
	LVAttrStateHistorical                           LVAttr = 'h'
	LVAttrStateSuspended                            LVAttr = 's'
	LVAttrStateInvalidSnapshot                      LVAttr = 'I'
	LVAttrStateSuspendedSnapshot                    LVAttr = 'S'
	LVAttrStateSnapshotMergeFailed                  LVAttr = 'm'
	LVAttrStateSuspendedSnapshotMergeFailed         LVAttr = 'M'
	LVAttrStateMappedDevicePresentWithoutTable      LVAttr = 'd'
	LVAttrStateMappedDevicePresentWithInactiveTable LVAttr = 'i'
	LVAttrStateThinPoolCheckNeeded                  LVAttr = 'c'
	LVAttrStateSuspendedThinPoolCheckNeeded         LVAttr = 'C'
	LVAttrStateUnknown                              LVAttr = 'X'
)

type LVAttrIndex

type LVAttrIndex uint8
const (
	LVAttrIndexType        LVAttrIndex = 0
	LVAttrIndexPermissions LVAttrIndex = iota
	LVAttrIndexAllocationPolicy
	LVAttrIndexAllocationFixedMinor
	LVAttrIndexState
	LVAttrIndexDeviceOpen
	LVAttrIndexTargetType
	LVAttrIndexZeroDataBlocks
	LVAttrIndexVolumeHealth
	LVAttrIndexSkipActivation
)

type LVAttrs

type LVAttrs string

func (LVAttrs) Attr

func (t LVAttrs) Attr(index LVAttrIndex) LVAttr

type LVInfo

type LVInfo struct {
	LVName          string `json:"lv_name"`
	VGName          string `json:"vg_name"`
	LVAttr          string `json:"lv_attr"`
	LVSize          string `json:"lv_size"`
	Origin          string `json:"origin"`
	DataPercent     string `json:"data_percent"`
	CopyPercent     string `json:"copy_percent"`
	MetadataPercent string `json:"metadata_percent"`
	MetadataDevices string `json:"metadata_devices"`
	MovePV          string `json:"move_pv"`
	ConvertPV       string `json:"convert_pv"`
	MirrorLog       string `json:"mirror_log"`
	Devices         string `json:"devices"`

	// SegType is the type of the volume, as thin, which is not
	// snapshotted as a linear one is.
	SegType string `json:"segtype"`

	// PoolLV is the thin pool a thin volume is in, empty for
	// another volume.
	PoolLV string `json:"pool_lv"`
}

type LVReport

type LVReport struct {
	LV []LVInfo `json:"lv"`
	VG []VGInfo `json:"vg"`
}

type LVSummary

type LVSummary struct {
	Activated int
	Total     int
}

LVSummary represents a summary of logical volumes

type ShowData

type ShowData struct {
	Report []LVReport `json:"report"`
}

type VG

type VG struct {
	VGName string
	// contains filtered or unexported fields
}

func NewVG

func NewVG(vg string, opts ...funcopt.O) *VG

func (*VG) Activate

func (t *VG) Activate(ctx context.Context) error

func (*VG) ActiveLVDevices

func (t *VG) ActiveLVDevices() (device.L, error)

func (*VG) AddNodeTag

func (t *VG) AddNodeTag(ctx context.Context) error

func (*VG) AddTag

func (t *VG) AddTag(ctx context.Context, s string) error

func (*VG) Attrs

func (t *VG) Attrs(ctx context.Context) (VGAttrs, error)

func (*VG) CachedDevicesShow

func (t *VG) CachedDevicesShow(ctx context.Context) (*VGInfo, error)

func (*VG) CachedNormalShow

func (t *VG) CachedNormalShow(ctx context.Context) (l []VGInfo, err error)

CachedNormalShow retrieves cached volume group information, unmarshals the output data, and filters by the specified VGName.

It uses the command: vgs --reportformat json -o "+tags,pv_name". => The following cmd output will return 2 entries when t.VGName == "data"

{
  "report": [
    {"vg": [
       {"vg_name": "data", "pv_count": "1", "lv_count": "0", "snap_count": "0", "vg_attr": "wz--n-","vg_size": "<5.00g", "vg_free": "<5.00g", "vg_tags": "local", "pv_name": "/dev/vdb"},
       {"vg_name": "data", "pv_count": "1", "lv_count": "0", "snap_count": "0", "vg_attr": "wz--n-","vg_size": "<5.00g", "vg_free": "<5.00g", "vg_tags": "local", "pv_name": "/dev/vdc"},
       {"vg_name": "root", "pv_count": "1", "lv_count": "2", "snap_count": "0", "vg_attr": "wz--n-","vg_size": "<38.75g", "vg_free": "0 ", "vg_tags": "local", "pv_name": "/dev/vda3"}
   ]}
  ]
}

func (*VG) Create

func (t *VG) Create(ctx context.Context, size string, pvs []string, options []string) error

func (*VG) Deactivate

func (t *VG) Deactivate(ctx context.Context) error

func (*VG) DelNodeTag

func (t *VG) DelNodeTag(ctx context.Context) error

func (*VG) DelTag

func (t *VG) DelTag(ctx context.Context, s string) error

func (*VG) Devices

func (t *VG) Devices(ctx context.Context) (device.L, error)

func (VG) DriverName

func (t VG) DriverName() string

func (*VG) Exists

func (t *VG) Exists(ctx context.Context) (bool, error)

func (*VG) ExtentSize

func (t *VG) ExtentSize(ctx context.Context) (int64, error)

ExtentSize is the bytes of the unit a volume group hands out. A logical volume is a whole number of them, so a group asked for a size that is not has to round up or the volume does not fit.

func (*VG) FQN

func (t *VG) FQN() string

func (*VG) Free

func (t *VG) Free(ctx context.Context) (int64, error)

Free is the bytes of the group nothing has taken yet, rounded down to a whole number of extents.

Rounded down, where every other size om asks for is rounded up: this is what is there, not what is wanted, and a caller asking for all of it must ask for a size that fits. lvcreate rounds a size up to the next extent, so a byte count that is not a whole number of them is one extent more than the group has.

func (*VG) GetLVSummary

func (t *VG) GetLVSummary(ctx context.Context) (LVSummary, error)

func (*VG) HasNodeTag

func (t *VG) HasNodeTag(ctx context.Context) (bool, error)

func (*VG) HasTag

func (t *VG) HasTag(ctx context.Context, s string) (bool, error)

func (*VG) ImportDevices

func (t *VG) ImportDevices(ctx context.Context) error

func (*VG) IsActive

func (t *VG) IsActive(ctx context.Context) (bool, error)

func (*VG) LVInfos

func (t *VG) LVInfos(ctx context.Context) ([]LVInfo, error)

LVInfos retrieves information about logical volumes (LVs) in the volume group (VG) as a list of LVInfo structures. It runs the "lvs" command with JSON output format and processes the result. Returns an error if the command fails.

func (*VG) Log

func (t *VG) Log() *plog.Logger

func (*VG) NeedActivate

func (t *VG) NeedActivate(s LVSummary) bool

func (*VG) PEStart

func (t *VG) PEStart(ctx context.Context) (int64, error)

PEStart is the offset of the first extent of the physical volume of a group of one: the bytes the group keeps of its device for its metadata, before the extents it hands out.

It is what the group keeps for itself whatever the device holds, where the gap between the device and the group counts, once the device has grown and the group has not been grown onto it, the growth itself. lvm reports the size of the physical volume as its extents, so that gap says nothing either.

func (*VG) PVs

func (t *VG) PVs(ctx context.Context) (device.L, error)

func (*VG) Remove

func (t *VG) Remove(ctx context.Context, args []string) error

func (*VG) RemovePVs

func (t *VG) RemovePVs(ctx context.Context, pvs device.L) error

RemovePVs removes the lvm label of the physical volumes pvs, freed by the removal of their group. A vgcreate labels the devices it is given, so the group removed, the label is all that is left of it on them.

func (*VG) ResizePV

func (t *VG) ResizePV(ctx context.Context, pv string, size int64) error

ResizePV makes the volume group use the current size of one of its physical volumes.

A size of 0 takes the whole device, which is what a group growing onto a device that just grew wants. A size is set explicitly to give space back, which lvm refuses if extents beyond it are in use.

func (*VG) SetLog

func (t *VG) SetLog(log *plog.Logger)

func (*VG) Show

func (t *VG) Show(ctx context.Context, fields string) (*VGInfo, error)

func (*VG) Size

func (t *VG) Size(ctx context.Context) (int64, error)

Size is the bytes the volume group offers to its logical volumes. It is less than what its physical volumes hold, by the metadata lvm keeps and by what does not fill a whole extent.

func (*VG) Tags

func (t *VG) Tags(ctx context.Context) ([]string, error)

func (*VG) Wipe

func (t *VG) Wipe() error

type VGAttr

type VGAttr rune
const (
	VGAttrStateWriteable       VGAttr = 'w'
	VGAttrStateReadOnly        VGAttr = 'r'
	VGAttrStateResizeable      VGAttr = 'z'
	VGAttrStateExported        VGAttr = 'x'
	VGAttrStatePartial         VGAttr = 'p'
	VGAttrStateAllocContiguous VGAttr = 'c'
	VGAttrStateAllocCling      VGAttr = 'l'
	VGAttrStateAllocNormal     VGAttr = 'n'
	VGAttrStateAllocAnywhere   VGAttr = 'a'
	VGAttrStateClustered       VGAttr = 'c'
	VGAttrStateShared          VGAttr = 's'
)

type VGAttrIndex

type VGAttrIndex uint8
const (
	VGAttrIndexPermissions VGAttrIndex = 0
	VGAttrIndexResizeable  VGAttrIndex = iota
	VGAttrIndexExported
	VGAttrIndexPartial
	VGAttrIndexAllocationPolicy
	VGAttrIndexClusteredOrShared
)

type VGAttrs

type VGAttrs string

func (VGAttrs) Attr

func (t VGAttrs) Attr(index VGAttrIndex) VGAttr

type VGInfo

type VGInfo struct {
	VGName    string `json:"vg_name"`
	VGAttr    string `json:"vg_attr"`
	VGSize    string `json:"vg_size"`
	VGFree    string `json:"vg_free"`
	VGExtSize string `json:"vg_extent_size"`
	VGTags    string `json:"vg_tags"`
	SnapCount string `json:"snap_count"`
	PVCount   string `json:"pv_count"`
	LVCount   string `json:"lv_count"`
	PVName    string `json:"pv_name"`
	PEStart   string `json:"pe_start"`
	LVName    string `json:"lv_name"`
	Devices   string `json:"devices"`
}

func (*VGInfo) Free

func (t *VGInfo) Free() (int64, error)

func (*VGInfo) PEStartBytes

func (t *VGInfo) PEStartBytes() (int64, error)

PEStartBytes is the offset of the first extent of the physical volume of the row.

func (*VGInfo) Size

func (t *VGInfo) Size() (int64, error)

Jump to

Keyboard shortcuts

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