From 3db8adc38fde45609a6da38aae0f0d9034dd455d Mon Sep 17 00:00:00 2001 From: rainzm Date: Tue, 6 Jul 2021 16:33:51 +0800 Subject: [PATCH 1/2] feat: update host-deployer-base from 0.6 to 1.0 --- build/docker/Dockerfile.host-deployer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/docker/Dockerfile.host-deployer b/build/docker/Dockerfile.host-deployer index c6d55dd87d..9f9e5b05c2 100644 --- a/build/docker/Dockerfile.host-deployer +++ b/build/docker/Dockerfile.host-deployer @@ -1,4 +1,4 @@ -FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:0.6 +FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:1.0 MAINTAINER "Yaoqi Wan wanyaoqi@yunionyun.com" From de60724ba9ed082cf0867dd13310860a99c15d6e Mon Sep 17 00:00:00 2001 From: rainzm Date: Tue, 6 Jul 2021 16:41:29 +0800 Subject: [PATCH 2/2] feat(hostdeployer): find vg name and id via pv --- pkg/hostman/diskutils/nbd/driver.go | 22 ++++++++++-------- pkg/hostman/diskutils/nbd/lvmutils.go | 33 +++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/pkg/hostman/diskutils/nbd/driver.go b/pkg/hostman/diskutils/nbd/driver.go index 1b67e41f5a..3bd9c66a3b 100644 --- a/pkg/hostman/diskutils/nbd/driver.go +++ b/pkg/hostman/diskutils/nbd/driver.go @@ -162,16 +162,18 @@ func (d *NBDDriver) setupLVMS() (bool, error) { lvmPartitions := []fsdriver.IDiskPartition{} for _, part := range d.partitions { - vgname := d.findLVMPartitions(part.GetPartDev()) - if len(vgname) > 0 { - log.Infof("find vg %s from %s", vgname, part.GetPartDev()) - lvm := NewKVMGuestLVMPartition(part.GetPartDev(), vgname) - d.lvms = append(d.lvms, lvm) - if lvm.SetupDevice() { - if subparts := lvm.FindPartitions(); len(subparts) > 0 { - for i := 0; i < len(subparts); i++ { - lvmPartitions = append(lvmPartitions, subparts[i]) - } + vg, err := findVg(part.GetPartDev()) + if err != nil { + log.Errorf("unable to find vg from %s: %v", part.GetPartDev(), err) + continue + } + log.Infof("find vg %s from %s", vg.Name, part.GetPartDev()) + lvm := NewKVMGuestLVMPartition(part.GetPartDev(), vg) + d.lvms = append(d.lvms, lvm) + if lvm.SetupDevice() { + if subparts := lvm.FindPartitions(); len(subparts) > 0 { + for i := 0; i < len(subparts); i++ { + lvmPartitions = append(lvmPartitions, subparts[i]) } } } diff --git a/pkg/hostman/diskutils/nbd/lvmutils.go b/pkg/hostman/diskutils/nbd/lvmutils.go index 02d61503c7..1b91d842ad 100644 --- a/pkg/hostman/diskutils/nbd/lvmutils.go +++ b/pkg/hostman/diskutils/nbd/lvmutils.go @@ -89,6 +89,7 @@ type SKVMGuestLVMPartition struct { // if need to modify the name when putting down needChangeName bool + vgid string } func findVgname(partDev string) string { @@ -108,11 +109,35 @@ func findVgname(partDev string) string { return "" } -func NewKVMGuestLVMPartition(partDev, originVgname string) *SKVMGuestLVMPartition { +type SVG struct { + Id string + Name string +} + +func findVg(partDev string) (SVG, error) { + command := procutils.NewCommand("vgs", "-v", "--devices", partDev) + output, err := command.Output() + if err != nil { + return SVG{}, errors.Wrapf(err, "unable to exec command %q", command) + } + log.Debugf("command: %s\noutput: %s", command, output) + lines := strings.Split(strings.TrimSpace(string(output)), "\n") + if len(lines) <= 1 { + return SVG{}, fmt.Errorf("unable to find vg, output is %q", output) + } + data := regexp.MustCompile(`\s+`).Split(strings.TrimSpace(lines[len(lines)-1]), -1) + if len(data) < 1 || len(data) < 9 { + return SVG{}, fmt.Errorf("The output is not as expected: %q", output) + } + return SVG{data[8], data[0]}, nil +} + +func NewKVMGuestLVMPartition(partDev string, vg SVG) *SKVMGuestLVMPartition { return &SKVMGuestLVMPartition{ partDev: partDev, - originVgname: originVgname, + originVgname: vg.Name, vgname: uuidWithoutLine(), + vgid: vg.Id, } } @@ -122,10 +147,10 @@ func uuidWithoutLine() string { } func (p *SKVMGuestLVMPartition) SetupDevice() bool { - if len(p.originVgname) == 0 { + if len(p.vgid) == 0 { return false } - if !p.vgRename(p.originVgname, p.vgname) { + if !p.vgRename(p.vgid, p.vgname) { return false } p.needChangeName = true