lvmd

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright @ 2021 fushaosong <fushaosong@beyondlet.com>.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright @ 2021 fushaosong <fushaosong@beyondlet.com>.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright @ 2021 fushaosong <fushaosong@beyondlet.com>.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lvm2

type Lvm2 interface {
	// 检查pv是否存在
	PVCheck(dev string) (string, error)
	PVCreate(dev string) error
	PVRemove(dev string) error
	PVResize(dev string) error
	// 列出pv列表
	PVS() ([]types.PVInfo, error)
	// 扫盲pv加入cache,在服务启动时执行
	PVScan(dev string) error
	PVDisplay(dev string) (*types.PVInfo, error)

	VGCheck(vg string) error
	VGCreate(vg string, tags, pvs []string) error
	VGRemove(vg string) error
	VGS() ([]types.VgGroup, error)
	VGDisplay(vg string) (*types.VgGroup, error)
	VGScan(vg string) error
	// vg卷组增加新的pv
	VGExtend(vg, pv string) error
	// vg卷组安全移除pv
	VGReduce(vg, pv string) error

	// 每一个Volume对应的是一个thin pool下一个lvm卷
	// 若是要扩容卷,则必须先扩容池子
	// 快照占用的是池子剩余的容量
	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(lvName string) ([]types.LvInfo, error)

	// 快照占用Pool空间,要有足够对池空间才能创建快照,不然会导致数据损坏
	CreateSnapshot(snap, lv, vg string) error
	DeleteSnapshot(snap, vg string) error
	// 恢复快照会导致此快照消失
	RestoreSnapshot(snap, vg string) error

	// 启动必要的lvm2服务
	StartLvm2() error
	// 清理unknown设备
	RemoveUnknownDevice(vg string) error
}

type Lvm2Implement

type Lvm2Implement struct {
	Executor exec.Executor
}

func (*Lvm2Implement) CreateSnapshot

func (lv2 *Lvm2Implement) CreateSnapshot(snap, lv, vg string) error

lvcreate -s v1/m2 -n snaph-m1 -ay -Ky

func (*Lvm2Implement) CreateThinPool

func (lv2 *Lvm2Implement) CreateThinPool(lv, vg string, size uint64) error

lvcreate -T v1/t5 --size 2g

func (*Lvm2Implement) DeleteSnapshot

func (lv2 *Lvm2Implement) DeleteSnapshot(snap, vg string) error

func (*Lvm2Implement) DeleteThinPool

func (lv2 *Lvm2Implement) DeleteThinPool(lv, vg string) error

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

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 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 -L 2g v1/m2

func (*Lvm2Implement) LVS

func (lv2 *Lvm2Implement) LVS(lvName string) ([]types.LvInfo, error)

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) PVCheck

func (lv2 *Lvm2Implement) PVCheck(dev string) (string, error)

func (*Lvm2Implement) PVCreate

func (lv2 *Lvm2Implement) PVCreate(dev string) error

func (*Lvm2Implement) PVDisplay

func (lv2 *Lvm2Implement) PVDisplay(dev string) (*types.PVInfo, error)

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() ([]types.PVInfo, error)

示例输出 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) RemoveUnknownDevice

func (lv2 *Lvm2Implement) RemoveUnknownDevice(vg string) error

func (*Lvm2Implement) ResizeThinPool

func (lv2 *Lvm2Implement) ResizeThinPool(lv, vg string, size uint64) error

lvresize -f -L 6g v1/t5

func (*Lvm2Implement) RestoreSnapshot

func (lv2 *Lvm2Implement) RestoreSnapshot(snap, vg string) error

测试 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 --add-tag=v1 v1 /dev/loop4

func (*Lvm2Implement) VGDisplay

func (lv2 *Lvm2Implement) VGDisplay(vg string) (*types.VgGroup, error)

func (*Lvm2Implement) VGExtend

func (lv2 *Lvm2Implement) VGExtend(vg, pv string) error

func (*Lvm2Implement) VGReduce

func (lv2 *Lvm2Implement) VGReduce(vg, pv string) error

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() ([]types.VgGroup, error)

示例 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.

Jump to

Keyboard shortcuts

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