The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6832

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Related to https://github.com/lxc/lxd/issues/6828

Restores old driver behaviour of using storage pool name as LVM volume group name if `lvm.vg_name` is not set in storage pool config.
From 80a8e44776c9ea2ed883cd41605b79e59a66b147 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Tue, 4 Feb 2020 09:46:10 +0000
Subject: [PATCH 1/2] lxd/storage/drivers/driver/lvm/utils: Adds
 volumeGroupName function

It appears that some older LVM storage pools do not have the lvm.vg_name 
property in their config, and instead rely on the old driver behavior of using 
the storage pool name if it is mising.

This adds back the old behavior.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/driver_lvm_utils.go | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lxd/storage/drivers/driver_lvm_utils.go 
b/lxd/storage/drivers/driver_lvm_utils.go
index ea1999c18a..a19e136af3 100644
--- a/lxd/storage/drivers/driver_lvm_utils.go
+++ b/lxd/storage/drivers/driver_lvm_utils.go
@@ -24,6 +24,15 @@ const lvmBlockVolSuffix = ".block"
 
 var errLVMNotFound = fmt.Errorf("Not found")
 
+// volumeGroupName returns the volume group name the pool is hosted on.
+func (d *lvm) volumeGroupName() string {
+       if d.config["lvm.vg_name"] != "" {
+               return d.config["lvm.vg_name"]
+       }
+
+       return d.name
+}
+
 // usesThinpool indicates whether the config specifies to use a thin pool or 
not.
 func (d *lvm) usesThinpool() bool {
        // Default is to use a thinpool.

From 9ffbdba9acc61f1440d468057c801947a7cb6aeb Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Tue, 4 Feb 2020 09:47:30 +0000
Subject: [PATCH 2/2] lxd/storage/drivers/driver/lvm: volumeGroupName usage in
 place of d.config["lvm.vg_name"]

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/driver_lvm.go         | 80 +++++++++++------------
 lxd/storage/drivers/driver_lvm_utils.go   | 14 ++--
 lxd/storage/drivers/driver_lvm_volumes.go | 60 ++++++++---------
 3 files changed, 77 insertions(+), 77 deletions(-)

diff --git a/lxd/storage/drivers/driver_lvm.go 
b/lxd/storage/drivers/driver_lvm.go
index 8a614af018..f2ecdd262e 100644
--- a/lxd/storage/drivers/driver_lvm.go
+++ b/lxd/storage/drivers/driver_lvm.go
@@ -146,7 +146,7 @@ func (d *lvm) Create() error {
                }
 
                // Check if the volume group already exists.
-               vgExists, vgTags, err = 
d.volumeGroupExists(d.config["lvm.vg_name"])
+               vgExists, vgTags, err = d.volumeGroupExists(d.volumeGroupName())
                if err != nil {
                        return err
                }
@@ -160,14 +160,14 @@ func (d *lvm) Create() error {
                if d.config["lvm.vg_name"] == "" {
                        d.config["lvm.vg_name"] = d.name
                }
-               d.config["source"] = d.config["lvm.vg_name"]
+               d.config["source"] = d.volumeGroupName()
 
                if !shared.IsBlockdevPath(srcPath) {
                        return fmt.Errorf("Custom loop file locations are not 
supported")
                }
 
                // Check if the volume group already exists.
-               vgExists, vgTags, err = 
d.volumeGroupExists(d.config["lvm.vg_name"])
+               vgExists, vgTags, err = d.volumeGroupExists(d.volumeGroupName())
                if err != nil {
                        return err
                }
@@ -196,13 +196,13 @@ func (d *lvm) Create() error {
                d.config["lvm.vg_name"] = d.config["source"]
 
                // Check the volume group already exists.
-               vgExists, vgTags, err = 
d.volumeGroupExists(d.config["lvm.vg_name"])
+               vgExists, vgTags, err = d.volumeGroupExists(d.volumeGroupName())
                if err != nil {
                        return err
                }
 
                if !vgExists {
-                       return fmt.Errorf("The requested volume group %q does 
not exist", d.config["lvm.vg_name"])
+                       return fmt.Errorf("The requested volume group %q does 
not exist", d.volumeGroupName())
                }
        } else {
                return fmt.Errorf("Invalid source property")
@@ -220,18 +220,18 @@ func (d *lvm) Create() error {
        if vgExists {
                // Check that the volume group is empty. Otherwise we will 
refuse to use it.
                // The LV count returned includes both normal volumes and thin 
volumes.
-               lvCount, err := d.countLogicalVolumes(d.config["lvm.vg_name"])
+               lvCount, err := d.countLogicalVolumes(d.volumeGroupName())
                if err != nil {
-                       return errors.Wrapf(err, "Failed to determine whether 
the volume group %q is empty", d.config["lvm.vg_name"])
+                       return errors.Wrapf(err, "Failed to determine whether 
the volume group %q is empty", d.volumeGroupName())
                }
 
                empty := false
                if lvCount > 0 {
                        if d.usesThinpool() {
                                // Always check if the thin pool exists as we 
may need to create it later.
-                               thinPoolExists, err = 
d.thinpoolExists(d.config["lvm.vg_name"], d.thinpoolName())
+                               thinPoolExists, err = 
d.thinpoolExists(d.volumeGroupName(), d.thinpoolName())
                                if err != nil {
-                                       return errors.Wrapf(err, "Failed to 
determine whether thinpool %q exists in volume group %q", 
d.config["lvm.vg_name"], d.thinpoolName())
+                                       return errors.Wrapf(err, "Failed to 
determine whether thinpool %q exists in volume group %q", d.volumeGroupName(), 
d.thinpoolName())
                                }
 
                                // If the single volume is the storage pool's 
thin pool LV then we still consider
@@ -245,12 +245,12 @@ func (d *lvm) Create() error {
                }
 
                if !empty {
-                       return fmt.Errorf("Volume group %q is not empty", 
d.config["lvm.vg_name"])
+                       return fmt.Errorf("Volume group %q is not empty", 
d.volumeGroupName())
                }
 
                // Check the tags on the volume group to check it is not 
already being used by LXD.
                if shared.StringInSlice(lvmVgPoolMarker, vgTags) {
-                       return fmt.Errorf("Volume group %q is already used by 
LXD", d.config["lvm.vg_name"])
+                       return fmt.Errorf("Volume group %q is already used by 
LXD", d.volumeGroupName())
                }
        } else {
                // Create physical volume if doesn't exist.
@@ -268,33 +268,33 @@ func (d *lvm) Create() error {
                }
 
                // Create volume group.
-               _, err := shared.TryRunCommand("vgcreate", 
d.config["lvm.vg_name"], pvName)
+               _, err := shared.TryRunCommand("vgcreate", d.volumeGroupName(), 
pvName)
                if err != nil {
                        return err
                }
-               d.logger.Debug("Volume group created", log.Ctx{"pv_name": 
pvName, "vg_name": d.config["lvm.vg_name"]})
-               revert.Add(func() { shared.TryRunCommand("vgremove", 
d.config["lvm.vg_name"]) })
+               d.logger.Debug("Volume group created", log.Ctx{"pv_name": 
pvName, "vg_name": d.volumeGroupName()})
+               revert.Add(func() { shared.TryRunCommand("vgremove", 
d.volumeGroupName()) })
        }
 
        // Create thin pool if needed.
        if d.usesThinpool() && !thinPoolExists {
-               err = d.createDefaultThinPool(d.Info().Version, 
d.config["lvm.vg_name"], d.thinpoolName())
+               err = d.createDefaultThinPool(d.Info().Version, 
d.volumeGroupName(), d.thinpoolName())
                if err != nil {
                        return err
                }
-               d.logger.Debug("Thin pool created", log.Ctx{"vg_name": 
d.config["lvm.vg_name"], "thinpool_name": d.thinpoolName()})
+               d.logger.Debug("Thin pool created", log.Ctx{"vg_name": 
d.volumeGroupName(), "thinpool_name": d.thinpoolName()})
 
                revert.Add(func() {
-                       
d.removeLogicalVolume(d.lvmDevPath(d.config["lvm.vg_name"], "", "", 
d.thinpoolName()))
+                       d.removeLogicalVolume(d.lvmDevPath(d.volumeGroupName(), 
"", "", d.thinpoolName()))
                })
        }
 
        // Mark the volume group with the lvmVgPoolMarker tag to indicate it is 
now in use by LXD.
-       _, err = shared.TryRunCommand("vgchange", "--addtag", lvmVgPoolMarker, 
d.config["lvm.vg_name"])
+       _, err = shared.TryRunCommand("vgchange", "--addtag", lvmVgPoolMarker, 
d.volumeGroupName())
        if err != nil {
                return err
        }
-       d.logger.Debug("LXD marker tag added to volume group", 
log.Ctx{"vg_name": d.config["lvm.vg_name"]})
+       d.logger.Debug("LXD marker tag added to volume group", 
log.Ctx{"vg_name": d.volumeGroupName()})
 
        revert.Success()
        return nil
@@ -314,7 +314,7 @@ func (d *lvm) Delete(op *operations.Operation) error {
                defer loopFile.Close()
        }
 
-       vgExists, vgTags, err := d.volumeGroupExists(d.config["lvm.vg_name"])
+       vgExists, vgTags, err := d.volumeGroupExists(d.volumeGroupName())
        if err != nil {
                return err
        }
@@ -322,7 +322,7 @@ func (d *lvm) Delete(op *operations.Operation) error {
        removeVg := false
        if vgExists {
                // Count normal and thin volumes.
-               lvCount, err := d.countLogicalVolumes(d.config["lvm.vg_name"])
+               lvCount, err := d.countLogicalVolumes(d.volumeGroupName())
                if err != nil && err != errLVMNotFound {
                        return err
                }
@@ -336,7 +336,7 @@ func (d *lvm) Delete(op *operations.Operation) error {
                        } else if d.usesThinpool() && lvCount > 0 {
                                // Lets see if the lv count is just our thin 
pool, or whether we can only remove
                                // the thin pool itself and not the volume 
group.
-                               thinVolCount, err := 
d.countThinVolumes(d.config["lvm.vg_name"], d.thinpoolName())
+                               thinVolCount, err := 
d.countThinVolumes(d.volumeGroupName(), d.thinpoolName())
                                if err != nil && err != errLVMNotFound {
                                        return err
                                }
@@ -350,11 +350,11 @@ func (d *lvm) Delete(op *operations.Operation) error {
                                        } else if thinVolCount == 0 && lvCount 
> 1 {
                                                // Otherwise, if the thin pool 
is empty but the volume group has
                                                // other volumes, then just 
remove the thin pool volume.
-                                               err = 
d.removeLogicalVolume(d.lvmDevPath(d.config["lvm.vg_name"], "", "", 
d.thinpoolName()))
+                                               err = 
d.removeLogicalVolume(d.lvmDevPath(d.volumeGroupName(), "", "", 
d.thinpoolName()))
                                                if err != nil {
-                                                       return 
errors.Wrapf(err, "Failed to delete thin pool %q from volume group %q", 
d.thinpoolName(), d.config["lvm.vg_name"])
+                                                       return 
errors.Wrapf(err, "Failed to delete thin pool %q from volume group %q", 
d.thinpoolName(), d.volumeGroupName())
                                                }
-                                               d.logger.Debug("Thin pool 
removed", log.Ctx{"vg_name": d.config["lvm.vg_name"], "thinpool_name": 
d.thinpoolName()})
+                                               d.logger.Debug("Thin pool 
removed", log.Ctx{"vg_name": d.volumeGroupName(), "thinpool_name": 
d.thinpoolName()})
                                        }
                                }
                        }
@@ -362,19 +362,19 @@ func (d *lvm) Delete(op *operations.Operation) error {
 
                // Remove volume group if needed.
                if removeVg {
-                       _, err := shared.TryRunCommand("vgremove", "-f", 
d.config["lvm.vg_name"])
+                       _, err := shared.TryRunCommand("vgremove", "-f", 
d.volumeGroupName())
                        if err != nil {
                                return errors.Wrapf(err, "Failed to delete the 
volume group for the lvm storage pool")
                        }
-                       d.logger.Debug("Volume group removed", 
log.Ctx{"vg_name": d.config["lvm.vg_name"]})
+                       d.logger.Debug("Volume group removed", 
log.Ctx{"vg_name": d.volumeGroupName()})
                } else {
                        // Otherwise just remove the lvmVgPoolMarker tag to 
indicate LXD no longer uses this VG.
                        if shared.StringInSlice(lvmVgPoolMarker, vgTags) {
-                               _, err = shared.TryRunCommand("vgchange", 
"--deltag", lvmVgPoolMarker, d.config["lvm.vg_name"])
+                               _, err = shared.TryRunCommand("vgchange", 
"--deltag", lvmVgPoolMarker, d.volumeGroupName())
                                if err != nil {
                                        return errors.Wrapf(err, "Failed to 
remove marker tag on volume group for the lvm storage pool")
                                }
-                               d.logger.Debug("LXD marker tag removed from 
volume group", log.Ctx{"vg_name": d.config["lvm.vg_name"]})
+                               d.logger.Debug("LXD marker tag removed from 
volume group", log.Ctx{"vg_name": d.volumeGroupName()})
                        }
                }
        }
@@ -457,19 +457,19 @@ func (d *lvm) Update(changedConfig map[string]string) 
error {
        }
 
        if changedConfig["lvm.vg_name"] != "" {
-               _, err := shared.TryRunCommand("vgrename", 
d.config["lvm.vg_name"], changedConfig["lvm.vg_name"])
+               _, err := shared.TryRunCommand("vgrename", d.volumeGroupName(), 
changedConfig["lvm.vg_name"])
                if err != nil {
-                       return errors.Wrapf(err, "Error renaming LVM volume 
group from %q to %q", d.config["lvm.vg_name"], changedConfig["lvm.vg_name"])
+                       return errors.Wrapf(err, "Error renaming LVM volume 
group from %q to %q", d.volumeGroupName(), changedConfig["lvm.vg_name"])
                }
-               d.logger.Debug("Volume group renamed", log.Ctx{"vg_name": 
d.config["lvm.vg_name"], "new_vg_name": changedConfig["lvm.vg_name"]})
+               d.logger.Debug("Volume group renamed", log.Ctx{"vg_name": 
d.volumeGroupName(), "new_vg_name": changedConfig["lvm.vg_name"]})
        }
 
        if changedConfig["lvm.thinpool_name"] != "" {
-               _, err := shared.TryRunCommand("lvrename", 
d.config["lvm.vg_name"], d.config["lvm.thinpool_name"], 
changedConfig["lvm.thinpool_name"])
+               _, err := shared.TryRunCommand("lvrename", d.volumeGroupName(), 
d.config["lvm.thinpool_name"], changedConfig["lvm.thinpool_name"])
                if err != nil {
                        return errors.Wrapf(err, "Error renaming LVM thin pool 
from %q to %q", d.config["lvm.thinpool_name"], 
changedConfig["lvm.thinpool_name"])
                }
-               d.logger.Debug("Thin pool volume renamed", log.Ctx{"vg_name": 
d.config["lvm.vg_name"], "thinpool": d.config["lvm.thinpool_name"], 
"new_thinpool": changedConfig["lvm.thinpool_name"]})
+               d.logger.Debug("Thin pool volume renamed", log.Ctx{"vg_name": 
d.volumeGroupName(), "thinpool": d.config["lvm.thinpool_name"], "new_thinpool": 
changedConfig["lvm.thinpool_name"]})
        }
 
        return nil
@@ -479,7 +479,7 @@ func (d *lvm) Update(changedConfig map[string]string) error 
{
 // LVM pools this creates a loop device).
 func (d *lvm) Mount() (bool, error) {
        // Open the loop file if the LVM device doesn't exist yet and the 
source points to a file.
-       if !shared.IsDir(fmt.Sprintf("/dev/%s", d.config["lvm.vg_name"])) && 
filepath.IsAbs(d.config["source"]) && 
!shared.IsBlockdevPath(d.config["source"]) {
+       if !shared.IsDir(fmt.Sprintf("/dev/%s", d.volumeGroupName())) && 
filepath.IsAbs(d.config["source"]) && 
!shared.IsBlockdevPath(d.config["source"]) {
                loopFile, err := d.openLoopFile(d.config["source"])
                if err != nil {
                        return false, err
@@ -490,7 +490,7 @@ func (d *lvm) Mount() (bool, error) {
        }
 
        // Activate volume group so that it's device is added to /dev.
-       _, err := shared.TryRunCommand("vgchange", "-ay", 
d.config["lvm.vg_name"])
+       _, err := shared.TryRunCommand("vgchange", "-ay", d.volumeGroupName())
        if err != nil {
                return false, err
        }
@@ -503,10 +503,10 @@ func (d *lvm) Mount() (bool, error) {
 func (d *lvm) Unmount() (bool, error) {
        // If loop backed, force release the loop device.
        if filepath.IsAbs(d.config["source"]) && 
!shared.IsBlockdevPath(d.config["source"]) {
-               vgExists, _, _ := d.volumeGroupExists(d.config["lvm.vg_name"])
+               vgExists, _, _ := d.volumeGroupExists(d.volumeGroupName())
                if vgExists {
                        // Deactivate volume group so that it's device is 
removed from /dev.
-                       _, err := shared.TryRunCommand("vgchange", "-an", 
d.config["lvm.vg_name"])
+                       _, err := shared.TryRunCommand("vgchange", "-an", 
d.volumeGroupName())
                        if err != nil {
                                return false, err
                        }
@@ -531,7 +531,7 @@ func (d *lvm) GetResources() (*api.ResourcesStoragePool, 
error) {
        // Thinpools will always report zero free space on the volume group, so 
calculate approx
        // used space using the thinpool logical volume allocated (data and 
meta) percentages.
        if d.usesThinpool() {
-               volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], "", "", 
d.thinpoolName())
+               volDevPath := d.lvmDevPath(d.volumeGroupName(), "", "", 
d.thinpoolName())
                totalSize, usedSize, err := d.thinPoolVolumeUsage(volDevPath)
                if err != nil {
                        return nil, err
@@ -542,7 +542,7 @@ func (d *lvm) GetResources() (*api.ResourcesStoragePool, 
error) {
        } else {
                // If thinpools are not in use, calculate used space in volume 
group.
                args := []string{
-                       d.config["lvm.vg_name"],
+                       d.volumeGroupName(),
                        "--noheadings",
                        "--units", "b",
                        "--nosuffix",
diff --git a/lxd/storage/drivers/driver_lvm_utils.go 
b/lxd/storage/drivers/driver_lvm_utils.go
index a19e136af3..696399793e 100644
--- a/lxd/storage/drivers/driver_lvm_utils.go
+++ b/lxd/storage/drivers/driver_lvm_utils.go
@@ -578,13 +578,13 @@ func (d *lvm) copyThinpoolVolume(vol, srcVol Volume, 
srcSnapshots []Volume, refr
                        // We do not modify the original snapshot so as to 
avoid damaging if it is corrupted for
                        // some reason. If the filesystem needs to have a 
unique UUID generated in order to mount
                        // this will be done at restore time to be safe.
-                       _, err = 
d.createLogicalVolumeSnapshot(d.config["lvm.vg_name"], srcSnapshot, newSnapVol, 
true, d.usesThinpool())
+                       _, err = 
d.createLogicalVolumeSnapshot(d.volumeGroupName(), srcSnapshot, newSnapVol, 
true, d.usesThinpool())
                        if err != nil {
                                return errors.Wrapf(err, "Error creating LVM 
logical volume snapshot")
                        }
 
                        revert.Add(func() {
-                               
d.removeLogicalVolume(d.lvmDevPath(d.config["lvm.vg_name"], newSnapVol.volType, 
newSnapVol.contentType, newSnapVol.name))
+                               
d.removeLogicalVolume(d.lvmDevPath(d.volumeGroupName(), newSnapVol.volType, 
newSnapVol.contentType, newSnapVol.name))
                        })
                }
        }
@@ -592,9 +592,9 @@ func (d *lvm) copyThinpoolVolume(vol, srcVol Volume, 
srcSnapshots []Volume, refr
        // Handle copying the main volume.
        if d.HasVolume(vol) {
                if refresh {
-                       newVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, vol.name)
+                       newVolDevPath := d.lvmDevPath(d.volumeGroupName(), 
vol.volType, vol.contentType, vol.name)
                        tmpVolName := fmt.Sprintf("%s%s", vol.name, 
tmpVolSuffix)
-                       tmpVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, tmpVolName)
+                       tmpVolDevPath := d.lvmDevPath(d.volumeGroupName(), 
vol.volType, vol.contentType, tmpVolName)
 
                        // Rename existing volume to temporary new name so we 
can revert if needed.
                        err := d.renameLogicalVolume(newVolDevPath, 
tmpVolDevPath)
@@ -623,12 +623,12 @@ func (d *lvm) copyThinpoolVolume(vol, srcVol Volume, 
srcSnapshots []Volume, refr
        }
 
        // Create snapshot of source volume as new volume.
-       _, err := d.createLogicalVolumeSnapshot(d.config["lvm.vg_name"], 
srcVol, vol, false, d.usesThinpool())
+       _, err := d.createLogicalVolumeSnapshot(d.volumeGroupName(), srcVol, 
vol, false, d.usesThinpool())
        if err != nil {
                return errors.Wrapf(err, "Error creating LVM logical volume 
snapshot")
        }
 
-       volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, 
vol.contentType, vol.name)
+       volDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, vol.name)
 
        revert.Add(func() {
                d.removeLogicalVolume(volDevPath)
@@ -655,7 +655,7 @@ func (d *lvm) copyThinpoolVolume(vol, srcVol Volume, 
srcSnapshots []Volume, refr
 
        // Finally clean up original volumes left that were renamed with a 
tmpVolSuffix suffix.
        for _, removeVolName := range removeVols {
-               err := 
d.removeLogicalVolume(d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, 
vol.contentType, removeVolName))
+               err := d.removeLogicalVolume(d.lvmDevPath(d.volumeGroupName(), 
vol.volType, vol.contentType, removeVolName))
                if err != nil {
                        return errors.Wrapf(err, "Error removing LVM volume 
%q", vol.name)
                }
diff --git a/lxd/storage/drivers/driver_lvm_volumes.go 
b/lxd/storage/drivers/driver_lvm_volumes.go
index d55449964e..472fb5fa75 100644
--- a/lxd/storage/drivers/driver_lvm_volumes.go
+++ b/lxd/storage/drivers/driver_lvm_volumes.go
@@ -29,7 +29,7 @@ func (d *lvm) CreateVolume(vol Volume, filler *VolumeFiller, 
op *operations.Oper
        }
        revert.Add(func() { os.RemoveAll(volPath) })
 
-       err = d.createLogicalVolume(d.config["lvm.vg_name"], d.thinpoolName(), 
vol, d.usesThinpool())
+       err = d.createLogicalVolume(d.volumeGroupName(), d.thinpoolName(), vol, 
d.usesThinpool())
        if err != nil {
                return errors.Wrapf(err, "Error creating LVM logical volume")
        }
@@ -162,7 +162,7 @@ func (d *lvm) DeleteVolume(vol Volume, op 
*operations.Operation) error {
                return fmt.Errorf("Cannot remove a volume that has snapshots")
        }
 
-       volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, 
vol.contentType, vol.name)
+       volDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, vol.name)
        lvExists, err := d.logicalVolumeExists(volDevPath)
        if err != nil {
                return err
@@ -176,7 +176,7 @@ func (d *lvm) DeleteVolume(vol Volume, op 
*operations.Operation) error {
                        }
                }
 
-               err = 
d.removeLogicalVolume(d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, 
vol.contentType, vol.name))
+               err = d.removeLogicalVolume(d.lvmDevPath(d.volumeGroupName(), 
vol.volType, vol.contentType, vol.name))
                if err != nil {
                        return errors.Wrapf(err, "Error removing LVM logical 
volume")
                }
@@ -212,7 +212,7 @@ func (d *lvm) DeleteVolume(vol Volume, op 
*operations.Operation) error {
 
 // HasVolume indicates whether a specific volume exists on the storage pool.
 func (d *lvm) HasVolume(vol Volume) bool {
-       volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, 
vol.contentType, vol.name)
+       volDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, vol.name)
        volExists, err := d.logicalVolumeExists(volDevPath)
        if err != nil {
                return false
@@ -288,7 +288,7 @@ func (d *lvm) GetVolumeUsage(vol Volume) (int64, error) {
        } else if vol.contentType == ContentTypeBlock && d.usesThinpool() {
                // For thin pool block volumes we can calculate an approximate 
usage using the space allocated to
                // the volume from the thin pool.
-               volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, vol.name)
+               volDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, vol.name)
                _, usedSize, err := d.thinPoolVolumeUsage(volDevPath)
                if err != nil {
                        return -1, err
@@ -313,7 +313,7 @@ func (d *lvm) SetVolumeQuota(vol Volume, size string, op 
*operations.Operation)
        }
 
        // Read actual size of current volume.
-       volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, 
vol.contentType, vol.name)
+       volDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, vol.name)
        oldSizeBytes, err := d.logicalVolumeSize(volDevPath)
        if err != nil {
                return err
@@ -321,7 +321,7 @@ func (d *lvm) SetVolumeQuota(vol Volume, size string, op 
*operations.Operation)
 
        // Get the volume group's physical extent size, as we use this to 
figure out if the new and old sizes are
        // going to change beyond 1 extent size, otherwise there is no point in 
trying to resize as LVM do it.
-       vgExtentSize, err := d.volumeGroupExtentSize(d.config["lvm.vg_name"])
+       vgExtentSize, err := d.volumeGroupExtentSize(d.volumeGroupName())
        if err != nil {
                return err
        }
@@ -383,7 +383,7 @@ func (d *lvm) SetVolumeQuota(vol Volume, size string, op 
*operations.Operation)
 // GetVolumeDiskPath returns the location of a disk volume.
 func (d *lvm) GetVolumeDiskPath(vol Volume) (string, error) {
        if vol.IsVMBlock() {
-               volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, vol.name)
+               volDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, vol.name)
                return volDevPath, nil
        }
 
@@ -397,7 +397,7 @@ func (d *lvm) MountVolume(vol Volume, op 
*operations.Operation) (bool, error) {
 
        // Check if already mounted.
        if vol.contentType == ContentTypeFS && !shared.IsMountPoint(mountPath) {
-               volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, vol.name)
+               volDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, vol.name)
                mountFlags, mountOptions := 
resolveMountOptions(d.volumeMountOptions(vol))
                err := TryMount(volDevPath, mountPath, d.volumeFilesystem(vol), 
mountFlags, mountOptions)
                if err != nil {
@@ -438,7 +438,7 @@ func (d *lvm) UnmountVolume(vol Volume, op 
*operations.Operation) (bool, error)
 
 // RenameVolume renames a volume and its snapshots.
 func (d *lvm) RenameVolume(vol Volume, newVolName string, op 
*operations.Operation) error {
-       volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, 
vol.contentType, vol.name)
+       volDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, vol.name)
 
        return vol.UnmountTask(func(op *operations.Operation) error {
                snapNames, err := d.VolumeSnapshots(vol, op)
@@ -452,9 +452,9 @@ func (d *lvm) RenameVolume(vol Volume, newVolName string, 
op *operations.Operati
                // Rename snapshots (change volume prefix to use new parent 
volume name).
                for _, snapName := range snapNames {
                        snapVolName := GetSnapshotVolumeName(vol.name, snapName)
-                       snapVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, snapVolName)
+                       snapVolDevPath := d.lvmDevPath(d.volumeGroupName(), 
vol.volType, vol.contentType, snapVolName)
                        newSnapVolName := GetSnapshotVolumeName(newVolName, 
snapName)
-                       newSnapVolDevPath := 
d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, vol.contentType, 
newSnapVolName)
+                       newSnapVolDevPath := d.lvmDevPath(d.volumeGroupName(), 
vol.volType, vol.contentType, newSnapVolName)
                        err = d.renameLogicalVolume(snapVolDevPath, 
newSnapVolDevPath)
                        if err != nil {
                                return err
@@ -476,7 +476,7 @@ func (d *lvm) RenameVolume(vol Volume, newVolName string, 
op *operations.Operati
                }
 
                // Rename actual volume.
-               newVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, newVolName)
+               newVolDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, newVolName)
                err = d.renameLogicalVolume(volDevPath, newVolDevPath)
                if err != nil {
                        return err
@@ -549,12 +549,12 @@ func (d *lvm) CreateVolumeSnapshot(snapVol Volume, op 
*operations.Operation) err
        }
        revert.Add(func() { os.RemoveAll(snapPath) })
 
-       _, err = d.createLogicalVolumeSnapshot(d.config["lvm.vg_name"], 
parentVol, snapVol, true, d.usesThinpool())
+       _, err = d.createLogicalVolumeSnapshot(d.volumeGroupName(), parentVol, 
snapVol, true, d.usesThinpool())
        if err != nil {
                return errors.Wrapf(err, "Error creating LVM logical volume 
snapshot")
        }
 
-       volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], snapVol.volType, 
snapVol.contentType, snapVol.name)
+       volDevPath := d.lvmDevPath(d.volumeGroupName(), snapVol.volType, 
snapVol.contentType, snapVol.name)
 
        revert.Add(func() {
                d.removeLogicalVolume(volDevPath)
@@ -564,7 +564,7 @@ func (d *lvm) CreateVolumeSnapshot(snapVol Volume, op 
*operations.Operation) err
        if snapVol.IsVMBlock() {
                parentFSVol := parentVol.NewVMBlockFilesystemVolume()
                fsVol := snapVol.NewVMBlockFilesystemVolume()
-               _, err = d.createLogicalVolumeSnapshot(d.config["lvm.vg_name"], 
parentFSVol, fsVol, true, d.usesThinpool())
+               _, err = d.createLogicalVolumeSnapshot(d.volumeGroupName(), 
parentFSVol, fsVol, true, d.usesThinpool())
                if err != nil {
                        return errors.Wrapf(err, "Error creating LVM logical 
volume snapshot")
                }
@@ -578,7 +578,7 @@ func (d *lvm) CreateVolumeSnapshot(snapVol Volume, op 
*operations.Operation) err
 // must be bare names and should not be in the format "volume/snapshot".
 func (d *lvm) DeleteVolumeSnapshot(snapVol Volume, op *operations.Operation) 
error {
        // Remove the snapshot from the storage device.
-       volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], snapVol.volType, 
snapVol.contentType, snapVol.name)
+       volDevPath := d.lvmDevPath(d.volumeGroupName(), snapVol.volType, 
snapVol.contentType, snapVol.name)
        lvExists, err := d.logicalVolumeExists(volDevPath)
        if err != nil {
                return err
@@ -590,7 +590,7 @@ func (d *lvm) DeleteVolumeSnapshot(snapVol Volume, op 
*operations.Operation) err
                        return errors.Wrapf(err, "Error unmounting LVM logical 
volume")
                }
 
-               err = 
d.removeLogicalVolume(d.lvmDevPath(d.config["lvm.vg_name"], snapVol.volType, 
snapVol.contentType, snapVol.name))
+               err = d.removeLogicalVolume(d.lvmDevPath(d.volumeGroupName(), 
snapVol.volType, snapVol.contentType, snapVol.name))
                if err != nil {
                        return errors.Wrapf(err, "Error removing LVM logical 
volume")
                }
@@ -649,16 +649,16 @@ func (d *lvm) MountVolumeSnapshot(snapVol Volume, op 
*operations.Operation) (boo
                        tmpVol := NewVolume(d, d.name, snapVol.volType, 
snapVol.contentType, tmpVolName, snapVol.config, snapVol.poolConfig)
 
                        // Create writable snapshot from source snapshot named 
with a tmpVolSuffix suffix.
-                       _, err := 
d.createLogicalVolumeSnapshot(d.config["lvm.vg_name"], snapVol, tmpVol, false, 
d.usesThinpool())
+                       _, err := 
d.createLogicalVolumeSnapshot(d.volumeGroupName(), snapVol, tmpVol, false, 
d.usesThinpool())
                        if err != nil {
                                return false, errors.Wrapf(err, "Error creating 
temporary LVM logical volume snapshot")
                        }
 
                        revert.Add(func() {
-                               
d.removeLogicalVolume(d.lvmDevPath(d.config["lvm.vg_name"], tmpVol.volType, 
tmpVol.contentType, tmpVol.name))
+                               
d.removeLogicalVolume(d.lvmDevPath(d.volumeGroupName(), tmpVol.volType, 
tmpVol.contentType, tmpVol.name))
                        })
 
-                       tmpVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
tmpVol.volType, tmpVol.contentType, tmpVol.name)
+                       tmpVolDevPath := d.lvmDevPath(d.volumeGroupName(), 
tmpVol.volType, tmpVol.contentType, tmpVol.name)
 
                        d.logger.Debug("Regenerating filesystem UUID", 
log.Ctx{"dev": tmpVolDevPath, "fs": d.volumeFilesystem(tmpVol)})
                        err = 
regenerateFilesystemUUID(d.volumeFilesystem(tmpVol), tmpVolDevPath)
@@ -671,7 +671,7 @@ func (d *lvm) MountVolumeSnapshot(snapVol Volume, op 
*operations.Operation) (boo
                }
 
                // Finally attempt to mount the volume that needs mounting.
-               volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
mountVol.volType, mountVol.contentType, mountVol.name)
+               volDevPath := d.lvmDevPath(d.volumeGroupName(), 
mountVol.volType, mountVol.contentType, mountVol.name)
                mountFlags, mountOptions := 
resolveMountOptions(d.volumeMountOptions(snapVol))
                err := TryMount(volDevPath, mountPath, 
d.volumeFilesystem(mountVol), mountFlags|unix.MS_RDONLY, mountOptions)
                if err != nil {
@@ -707,7 +707,7 @@ func (d *lvm) UnmountVolumeSnapshot(snapVol Volume, op 
*operations.Operation) (b
 
                // Check if a temporary snapshot exists, and if so remove it.
                tmpVolName := fmt.Sprintf("%s%s", snapVol.name, tmpVolSuffix)
-               tmpVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
snapVol.volType, snapVol.contentType, tmpVolName)
+               tmpVolDevPath := d.lvmDevPath(d.volumeGroupName(), 
snapVol.volType, snapVol.contentType, tmpVolName)
                exists, err := d.logicalVolumeExists(tmpVolDevPath)
                if err != nil {
                        return true, errors.Wrapf(err, "Failed to check 
existence of temporary LVM snapshot volume %q", tmpVolDevPath)
@@ -755,9 +755,9 @@ func (d *lvm) RestoreVolume(vol Volume, snapshotName 
string, op *operations.Oper
                        return errors.Wrapf(err, "Error unmounting LVM logical 
volume")
                }
 
-               originalVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, vol.name)
+               originalVolDevPath := d.lvmDevPath(d.volumeGroupName(), 
vol.volType, vol.contentType, vol.name)
                tmpVolName := fmt.Sprintf("%s%s", vol.name, tmpVolSuffix)
-               tmpVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, tmpVolName)
+               tmpVolDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, tmpVolName)
 
                // Rename original logical volume to temporary new name so we 
can revert if needed.
                err = d.renameLogicalVolume(originalVolDevPath, tmpVolDevPath)
@@ -771,12 +771,12 @@ func (d *lvm) RestoreVolume(vol Volume, snapshotName 
string, op *operations.Oper
                })
 
                // Create writable snapshot from source snapshot named as 
target volume.
-               _, err = d.createLogicalVolumeSnapshot(d.config["lvm.vg_name"], 
snapVol, vol, false, true)
+               _, err = d.createLogicalVolumeSnapshot(d.volumeGroupName(), 
snapVol, vol, false, true)
                if err != nil {
                        return errors.Wrapf(err, "Error restoring LVM logical 
volume snapshot")
                }
 
-               volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], 
vol.volType, vol.contentType, vol.name)
+               volDevPath := d.lvmDevPath(d.volumeGroupName(), vol.volType, 
vol.contentType, vol.name)
 
                revert.Add(func() {
                        d.removeLogicalVolume(volDevPath)
@@ -792,7 +792,7 @@ func (d *lvm) RestoreVolume(vol Volume, snapshotName 
string, op *operations.Oper
                }
 
                // Finally remove the original logical volume. Should always be 
the last step to allow revert.
-               err = 
d.removeLogicalVolume(d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, 
vol.contentType, tmpVolName))
+               err = d.removeLogicalVolume(d.lvmDevPath(d.volumeGroupName(), 
vol.volType, vol.contentType, tmpVolName))
                if err != nil {
                        return errors.Wrapf(err, "Error removing original LVM 
logical volume")
                }
@@ -835,11 +835,11 @@ func (d *lvm) RestoreVolume(vol Volume, snapshotName 
string, op *operations.Oper
 
 // RenameVolumeSnapshot renames a volume snapshot.
 func (d *lvm) RenameVolumeSnapshot(snapVol Volume, newSnapshotName string, op 
*operations.Operation) error {
-       volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], snapVol.volType, 
snapVol.contentType, snapVol.name)
+       volDevPath := d.lvmDevPath(d.volumeGroupName(), snapVol.volType, 
snapVol.contentType, snapVol.name)
 
        parentName, _, _ := 
shared.InstanceGetParentAndSnapshotName(snapVol.name)
        newSnapVolName := GetSnapshotVolumeName(parentName, newSnapshotName)
-       newVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], snapVol.volType, 
snapVol.contentType, newSnapVolName)
+       newVolDevPath := d.lvmDevPath(d.volumeGroupName(), snapVol.volType, 
snapVol.contentType, newSnapVolName)
        err := d.renameLogicalVolume(volDevPath, newVolDevPath)
        if err != nil {
                return errors.Wrapf(err, "Error renaming LVM logical volume")
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to