[lxc-devel] [lxd/master] lxd/storage/drivers/driver/lvm/volumes: Fixes LVM VM snapshot list

tomponline on Github lxc-bot at linuxcontainers.org
Tue Mar 17 17:32:03 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 519 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200317/f4446708/attachment.bin>
-------------- next part --------------
From 55f09230efd264f5b1887788322b91a31a0edaaf Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 17 Mar 2020 17:29:45 +0000
Subject: [PATCH] lxd/storage/drivers/driver/lvm/volumes: Fixes LVM VM snapshot
 list

This bug was introduced in d782daf202cda0de0a88886e21aa056775024139 due to the way that VM snapshot LVs are named differently than container snapshot LVs.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/driver_lvm_volumes.go | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/lxd/storage/drivers/driver_lvm_volumes.go b/lxd/storage/drivers/driver_lvm_volumes.go
index 76d7e93b2c..9eadf49623 100644
--- a/lxd/storage/drivers/driver_lvm_volumes.go
+++ b/lxd/storage/drivers/driver_lvm_volumes.go
@@ -734,8 +734,6 @@ func (d *lvm) UnmountVolumeSnapshot(snapVol Volume, op *operations.Operation) (b
 
 // VolumeSnapshots returns a list of snapshots for the volume.
 func (d *lvm) VolumeSnapshots(vol Volume, op *operations.Operation) ([]string, error) {
-	fullVolName := d.lvmFullVolumeName(vol.volType, vol.contentType, vol.name)
-
 	// We use the volume list rather than inspecting the logical volumes themselves because the origin
 	// property of an LVM snapshot can be removed/changed when restoring snapshots, such that they are no
 	// marked as origin of the parent volume. Instead we use prefix matching on the volume names to find the
@@ -757,10 +755,29 @@ func (d *lvm) VolumeSnapshots(vol Volume, op *operations.Operation) ([]string, e
 	}
 
 	snapshots := []string{}
-	scanner := bufio.NewScanner(stdout)
+	fullVolName := d.lvmFullVolumeName(vol.volType, vol.contentType, vol.name)
+
+	// If block volume, remove the block suffix ready for comparison with LV list.
+	if vol.IsVMBlock() {
+		fullVolName = strings.TrimSuffix(fullVolName, lvmBlockVolSuffix)
+	}
+
 	prefix := fmt.Sprintf("%s-", fullVolName)
+
+	scanner := bufio.NewScanner(stdout)
 	for scanner.Scan() {
 		snapLine := strings.TrimSpace(scanner.Text())
+
+		// If block volume, skip any LVs that don't end with the block suffix, and then for those that do
+		// remove the block suffix so that they can be compared with the fullVolName prefix.
+		if vol.IsVMBlock() {
+			if !strings.HasSuffix(snapLine, lvmBlockVolSuffix) {
+				continue // Ignore non-block volumes.
+			}
+
+			snapLine = strings.TrimSuffix(snapLine, lvmBlockVolSuffix)
+		}
+
 		if strings.HasPrefix(snapLine, prefix) {
 			// Remove volume name prefix (including snapshot delimiter) and unescape snapshot name.
 			snapshots = append(snapshots, strings.Replace(strings.TrimPrefix(snapLine, prefix), "--", "-", -1))


More information about the lxc-devel mailing list