Documentation
¶
Index ¶
- type Lvm2
- type Lvm2Implement
- func (lv2 *Lvm2Implement) CreateSnapshot(snap, lv, vg string) error
- func (lv2 *Lvm2Implement) CreateThinPool(lv, vg string, size uint64) error
- func (lv2 *Lvm2Implement) DeleteSnapshot(snap, vg string) error
- func (lv2 *Lvm2Implement) DeleteThinPool(lv, vg string) error
- func (lv2 *Lvm2Implement) LVCreateFromPool(lv, thin, vg string, size uint64) error
- func (lv2 *Lvm2Implement) LVCreateFromVG(lv, vg string, size uint64, tags []string, stripe uint, stripeSize string) error
- func (lv2 *Lvm2Implement) LVDisplay(lv, vg string) (*types.LvInfo, error)
- func (lv2 *Lvm2Implement) LVRemove(lv, vg string) error
- func (lv2 *Lvm2Implement) LVResize(lv, vg string, size uint64) error
- func (lv2 *Lvm2Implement) LVS(lvName string) ([]types.LvInfo, error)
- func (lv2 *Lvm2Implement) PVCheck(dev string) (string, error)
- func (lv2 *Lvm2Implement) PVCreate(dev string) error
- func (lv2 *Lvm2Implement) PVDisplay(dev string) (*api.PVInfo, error)
- func (lv2 *Lvm2Implement) PVRemove(dev string) error
- func (lv2 *Lvm2Implement) PVResize(dev string) error
- func (lv2 *Lvm2Implement) PVS() ([]api.PVInfo, error)
- func (lv2 *Lvm2Implement) PVScan(dev string) error
- func (lv2 *Lvm2Implement) PVWipefs(dev string) error
- func (lv2 *Lvm2Implement) RemoveUnknownDevice(vg string) error
- func (lv2 *Lvm2Implement) ResizeThinPool(lv, vg string, size uint64) error
- func (lv2 *Lvm2Implement) RestoreSnapshot(snap, vg string) error
- func (lv2 *Lvm2Implement) StartLvm2() error
- func (lv2 *Lvm2Implement) VGCheck(vg string) error
- func (lv2 *Lvm2Implement) VGCreate(vg string, tags, pvs []string) error
- func (lv2 *Lvm2Implement) VGDisplay(vg string) (*api.VgGroup, error)
- func (lv2 *Lvm2Implement) VGExtend(vg, pv string) error
- func (lv2 *Lvm2Implement) VGReduce(vg, pv string) error
- func (lv2 *Lvm2Implement) VGRemove(vg string) error
- func (lv2 *Lvm2Implement) VGS() ([]api.VgGroup, error)
- func (lv2 *Lvm2Implement) VGScan(vg string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lvm2 ¶
type Lvm2 interface {
// PVCheck 检查pv是否存在
PVCheck(dev string) (string, error)
PVCreate(dev string) error
PVRemove(dev string) error
PVResize(dev string) error
// PVS 列出pv列表
PVS() ([]api.PVInfo, error)
// PVScan 扫描pv加入cache,在服务启动时执行
PVScan(dev string) error
PVDisplay(dev string) (*api.PVInfo, error)
VGCheck(vg string) error
VGCreate(vg string, tags, pvs []string) error
VGRemove(vg string) error
VGS() ([]api.VgGroup, error)
VGDisplay(vg string) (*api.VgGroup, error)
VGScan(vg string) error
// VGExtend vg卷组增加新的pv
VGExtend(vg, pv string) error
// VGReduce vg卷组安全移除pv
VGReduce(vg, pv string) error
// 快照占用的是池子剩余的容量
CreateThinPool(lv, vg string, size uint64) error
ResizeThinPool(lv, vg string, size uint64) error
DeleteThinPool(lv, vg string) error
LVCreateFromPool(lv, thin, vg string, size uint64) error
LVCreateFromVG(lv, vg string, size uint64, tags []string, stripe uint, stripeSize string) error
LVRemove(lv, vg string) error
LVResize(lv, vg string, size uint64) error
LVDisplay(lv, vg string) (*types.LvInfo, error)
// LVS 这个方法会频繁调用
LVS(lvName string) ([]types.LvInfo, error)
// CreateSnapshot 快照占用Pool空间,要有足够对池空间才能创建快照,不然会导致数据损坏
CreateSnapshot(snap, lv, vg string) error
DeleteSnapshot(snap, vg string) error
// RestoreSnapshot 恢复快照会导致此快照消失
RestoreSnapshot(snap, vg string) error
// StartLvm2 启动必要的lvm2服务
StartLvm2() error
// RemoveUnknownDevice 清理unknown设备
RemoveUnknownDevice(vg string) error
}
type Lvm2Implement ¶
func (*Lvm2Implement) CreateSnapshot ¶
func (lv2 *Lvm2Implement) CreateSnapshot(snap, lv, vg string) error
CreateSnapshot lvcreate -s v1/m2 -n snaph-m1 -ay -Ky
func (*Lvm2Implement) CreateThinPool ¶
func (lv2 *Lvm2Implement) CreateThinPool(lv, vg string, size uint64) error
CreateThinPool lvcreate -T v1/t5 --size 2g
func (*Lvm2Implement) DeleteSnapshot ¶
func (lv2 *Lvm2Implement) DeleteSnapshot(snap, vg string) error
DeleteSnapshot
func (*Lvm2Implement) DeleteThinPool ¶
func (lv2 *Lvm2Implement) DeleteThinPool(lv, vg string) error
DeleteThinPool lvremove v1/t3
func (*Lvm2Implement) LVCreateFromPool ¶
func (lv2 *Lvm2Implement) LVCreateFromPool(lv, thin, vg string, size uint64) error
func (*Lvm2Implement) LVCreateFromVG ¶
func (lv2 *Lvm2Implement) LVCreateFromVG(lv, vg string, size uint64, tags []string, stripe uint, stripeSize string) error
LVCreateFromVG LVCreate creates logical volume in this volume group. name is a name of creating volume. size is volume size in bytes. volTags is a list of tags to add to the volume.
func (*Lvm2Implement) LVDisplay ¶
func (lv2 *Lvm2Implement) LVDisplay(lv, vg string) (*types.LvInfo, error)
LVDisplay lvdisplay v1/m2
func (*Lvm2Implement) LVRemove ¶
func (lv2 *Lvm2Implement) LVRemove(lv, vg string) error
func (*Lvm2Implement) LVResize ¶
func (lv2 *Lvm2Implement) LVResize(lv, vg string, size uint64) error
LVResize lvresize -L 2g v1/m2
func (*Lvm2Implement) LVS ¶
func (lv2 *Lvm2Implement) LVS(lvName string) ([]types.LvInfo, error)
LVS
lvs -o lv_name,lv_path,lv_size,lv_kernel_major,lv_kernel_minor,origin,origin_size,pool_lv,thin_count,lv_tags --noheadings --separator=, --units=b --nosuffix --unbuffered --nameprefixes ¶
LVM2_LV_NAME='t1',LVM2_LV_PATH='/dev/v1/t1',LVM2_LV_SIZE='1073741824',LVM2_LV_KERNEL_MAJOR='252',LVM2_LV_KERNEL_MINOR='0',LVM2_ORIGIN='',LVM2_ORIGIN_SIZE='',LVM2_POOL_LV='',LVM2_THIN_COUNT='',LVM2_LV_TAGS='t1' LVM2_LV_NAME='t5',LVM2_LV_PATH='',LVM2_LV_SIZE='6979321856',LVM2_LV_KERNEL_MAJOR='252',LVM2_LV_KERNEL_MINOR='3',LVM2_ORIGIN='',LVM2_ORIGIN_SIZE='',LVM2_POOL_LV='',LVM2_THIN_COUNT='1',LVM2_LV_TAGS='' LVM2_LV_NAME='m2',LVM2_LV_PATH='/dev/v1/m2',LVM2_LV_SIZE='2147483648',LVM2_LV_KERNEL_MAJOR='252',LVM2_LV_KERNEL_MINOR='5',LVM2_ORIGIN='',LVM2_ORIGIN_SIZE='',LVM2_POOL_LV='t5',LVM2_THIN_COUNT='',LVM2_LV_TAGS=''
func (*Lvm2Implement) PVCreate ¶
func (lv2 *Lvm2Implement) PVCreate(dev string) error
func (*Lvm2Implement) PVDisplay ¶
func (lv2 *Lvm2Implement) PVDisplay(dev string) (*api.PVInfo, error)
PVDisplay
pvdisplay /dev/loop4 ¶
--- Physical volume --- PV Name /dev/loop4 VG Name v1 PV Size 15.00 GiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 3839 Free PE 3839 Allocated PE 0 PV UUID OiNoxD-Y1sw-FSzi-mqPN-07EW-C77P-TNdtc6
func (*Lvm2Implement) PVRemove ¶
func (lv2 *Lvm2Implement) PVRemove(dev string) error
func (*Lvm2Implement) PVResize ¶
func (lv2 *Lvm2Implement) PVResize(dev string) error
func (*Lvm2Implement) PVS ¶
func (lv2 *Lvm2Implement) PVS() ([]api.PVInfo, error)
PVS 示例输出 pvs --noheadings --separator=, --units=b --nosuffix --unbuffered --nameprefixes LVM2_PV_NAME='/dev/loop2',LVM2_VG_NAME='lvmvg',LVM2_PV_FMT='lvm2',LVM2_PV_ATTR='a--',LVM2_PV_SIZE='16101933056',LVM2_PV_FREE='16101933056'
func (*Lvm2Implement) PVScan ¶
func (lv2 *Lvm2Implement) 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 (*Lvm2Implement) PVWipefs ¶ added in v0.12.0
func (lv2 *Lvm2Implement) PVWipefs(dev string) error
func (*Lvm2Implement) RemoveUnknownDevice ¶
func (lv2 *Lvm2Implement) RemoveUnknownDevice(vg string) error
func (*Lvm2Implement) ResizeThinPool ¶
func (lv2 *Lvm2Implement) ResizeThinPool(lv, vg string, size uint64) error
ResizeThinPool lvresize -f -L 6g v1/t5
func (*Lvm2Implement) RestoreSnapshot ¶
func (lv2 *Lvm2Implement) RestoreSnapshot(snap, vg string) error
RestoreSnapshot 测试 mkfs -t ext4 /dev/v1/m2 mount /dev/v1/m2 /mnt && touch /mnt/1 && touch /mnt/2 && ls lvcreate -s v1/m2 -n snap-m1 -ay -Ky touch /mnt/3 && touch /mnt/4 umount /mnt lvconvert --merge v1/snap-m1 mount /dev/v1/m2 /mnt && ls /mnt
func (*Lvm2Implement) StartLvm2 ¶
func (lv2 *Lvm2Implement) StartLvm2() error
func (*Lvm2Implement) VGCheck ¶
func (lv2 *Lvm2Implement) VGCheck(vg string) error
func (*Lvm2Implement) VGCreate ¶
func (lv2 *Lvm2Implement) VGCreate(vg string, tags, pvs []string) error
VGCreate vgcreate --add-tag=v1 v1 /dev/loop4
func (*Lvm2Implement) VGDisplay ¶
func (lv2 *Lvm2Implement) VGDisplay(vg string) (*api.VgGroup, error)
func (*Lvm2Implement) VGExtend ¶
func (lv2 *Lvm2Implement) VGExtend(vg, pv string) error
func (*Lvm2Implement) VGReduce ¶
func (lv2 *Lvm2Implement) VGReduce(vg, pv string) error
VGReduce
vgs ¶
VG #PV #lv2.#SN Attr VSize VFree lvmvg 1 0 0 wz--n- 15.00g 15.00g v1 2 0 0 wz--n- 29.99g 29.99g
pvs ¶
PV VG Fmt Attr PSize PFree /dev/loop2 lvmvg lvm2 a-- 15.00g 15.00g /dev/loop4 v1 lvm2 a-- 15.00g 15.00g /dev/loop5 v1 lvm2 a-- 15.00g 15.00g
pvmove /dev/loop5 ¶
No data to move for v1
vgreduce v1 /dev/loop5 ¶
Removed "/dev/loop5" from volume group "v1"
pvremove /dev/loop5 ¶
Labels on physical volume "/dev/loop5" successfully wiped
pvs ¶
PV VG Fmt Attr PSize PFree /dev/loop2 lvmvg lvm2 a-- 15.00g 15.00g /dev/loop4 v1 lvm2 a-- 15.00g 15.00g
func (*Lvm2Implement) VGRemove ¶
func (lv2 *Lvm2Implement) VGRemove(vg string) error
func (*Lvm2Implement) VGS ¶
func (lv2 *Lvm2Implement) VGS() ([]api.VgGroup, error)
VGS 示例 vgs --noheadings --separator=, --units=b --nosuffix --unbuffered --nameprefixes LVM2_VG_NAME='lvmvg',LVM2_PV_COUNT='1',LVM2_LV_COUNT='0',LVM2_SNAP_COUNT='0',LVM2_VG_ATTR='wz--n-',LVM2_VG_SIZE='16101933056',LVM2_VG_FREE='16101933056' LVM2_VG_NAME='v1',LVM2_PV_COUNT='2',LVM2_LV_COUNT='0',LVM2_SNAP_COUNT='0',LVM2_VG_ATTR='wz--n-',LVM2_VG_SIZE='32203866112',LVM2_VG_FREE='32203866112'
func (*Lvm2Implement) VGScan ¶
func (lv2 *Lvm2Implement) VGScan(vg 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.