[lxc-devel] [lxd/master] Instance: Mount instance volume before devices start

tomponline on Github lxc-bot at linuxcontainers.org
Wed Oct 21 10:28:48 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 417 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201021/d293cdb7/attachment-0001.bin>
-------------- next part --------------
From 6b3d569c493e7cc5e0367fb45d4f6a54c60fe636 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:14:56 +0100
Subject: [PATCH 01/18] lxd/storage/backend/lxd: b.driver.UnmountVolume usage

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/backend_lxd.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 20ddfc145c..e14f911692 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -1652,7 +1652,7 @@ func (b *lxdBackend) UnmountInstance(inst instance.Instance, op *operations.Oper
 	// Get the volume.
 	vol := b.newVolume(volType, contentType, volStorageName, rootDiskConf)
 
-	return b.driver.UnmountVolume(vol, op)
+	return b.driver.UnmountVolume(vol, false, op)
 }
 
 // GetInstanceDisk returns the location of the disk.
@@ -2976,7 +2976,7 @@ func (b *lxdBackend) UnmountCustomVolume(projectName, volName string, op *operat
 	volStorageName := project.StorageVolume(projectName, volName)
 	vol := b.newVolume(drivers.VolumeTypeCustom, drivers.ContentTypeFS, volStorageName, volume.Config)
 
-	return b.driver.UnmountVolume(vol, op)
+	return b.driver.UnmountVolume(vol, false, op)
 }
 
 // CreateCustomVolumeSnapshot creates a snapshot of a custom volume.

From 4c1aa33f61f9a4bb6bc757629d6f99c3eea61b92 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:15:26 +0100
Subject: [PATCH 02/18] lxd/instance/drivers/driver/lxc: Moves log rotate and
 mount before devices start in startCommon

This is to accomodate TPM devices that need to write their state to the instance's volume during start.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/instance/drivers/driver_lxc.go | 32 +++++++++++++++---------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 03170057c3..aa3228cdb0 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -2077,6 +2077,22 @@ func (c *lxc) startCommon() (string, []func() error, error) {
 		return "", postStartHooks, err
 	}
 
+	// Rotate the log file.
+	logfile := c.LogFilePath()
+	if shared.PathExists(logfile) {
+		os.Remove(logfile + ".old")
+		err := os.Rename(logfile, logfile+".old")
+		if err != nil {
+			return "", postStartHooks, err
+		}
+	}
+
+	// Mount instance root volume.
+	ourStart, err = c.mount()
+	if err != nil {
+		return "", postStartHooks, err
+	}
+
 	// Create the devices
 	nicID := -1
 
@@ -2224,22 +2240,6 @@ func (c *lxc) startCommon() (string, []func() error, error) {
 		}
 	}
 
-	// Rotate the log file
-	logfile := c.LogFilePath()
-	if shared.PathExists(logfile) {
-		os.Remove(logfile + ".old")
-		err := os.Rename(logfile, logfile+".old")
-		if err != nil {
-			return "", postStartHooks, err
-		}
-	}
-
-	// Storage is guaranteed to be mountable now (must be called after devices setup).
-	ourStart, err = c.mount()
-	if err != nil {
-		return "", postStartHooks, err
-	}
-
 	// Generate the LXC config
 	configPath := filepath.Join(c.LogPath(), "lxc.conf")
 	err = c.c.SaveConfigFile(configPath)

From 65ee12cf2442b95f998e32b3221bee15706cb6b1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:16:09 +0100
Subject: [PATCH 03/18] lxd/storage/drivers/interface: Adds keepBlockDev arg to
 UnmountVolume

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/interface.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/interface.go b/lxd/storage/drivers/interface.go
index 4aba1a134c..7913b221e1 100644
--- a/lxd/storage/drivers/interface.go
+++ b/lxd/storage/drivers/interface.go
@@ -67,7 +67,7 @@ type Driver interface {
 
 	// UnmountVolume unmounts a storage volume, returns true if unmounted, false if was not
 	// mounted.
-	UnmountVolume(vol Volume, op *operations.Operation) (bool, error)
+	UnmountVolume(vol Volume, keepBlockDev bool, op *operations.Operation) (bool, error)
 
 	// UnmountVolume unmounts a storage volume snapshot, returns true if unmounted, false if was
 	// not mounted.

From 9eb284da66d53e7a73188a6c9c3d66b314df94cb Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:16:45 +0100
Subject: [PATCH 04/18] lxf/storage/drivers/volume: v.driver.UnmountVolume
 usage

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/volume.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/volume.go b/lxd/storage/drivers/volume.go
index d5678e0b2f..47b977496f 100644
--- a/lxd/storage/drivers/volume.go
+++ b/lxd/storage/drivers/volume.go
@@ -218,7 +218,7 @@ func (v Volume) MountTask(task func(mountPath string, op *operations.Operation)
 		if ourMount {
 			defer func() {
 				unlock := locking.Lock(OperationLockName(v.pool, string(v.volType), v.name))
-				v.driver.UnmountVolume(v, op)
+				v.driver.UnmountVolume(v, false, op)
 				unlock()
 			}()
 		}

From ab34fe525fd394e4b3934970b8f949aedfafd863 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:17:05 +0100
Subject: [PATCH 05/18] lxd/storage/drivers/volume: Adds keepBlockDev arg to
 UnmountTask

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/volume.go | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lxd/storage/drivers/volume.go b/lxd/storage/drivers/volume.go
index 47b977496f..9761fc9054 100644
--- a/lxd/storage/drivers/volume.go
+++ b/lxd/storage/drivers/volume.go
@@ -227,9 +227,10 @@ func (v Volume) MountTask(task func(mountPath string, op *operations.Operation)
 	return task(v.MountPath(), op)
 }
 
-// UnmountTask runs the supplied task after unmounting the volume if needed. If the volume was unmounted
-// for this then it is mounted when the task finishes.
-func (v Volume) UnmountTask(task func(op *operations.Operation) error, op *operations.Operation) error {
+// UnmountTask runs the supplied task after unmounting the volume if needed.
+// If the volume was unmounted for this then it is mounted when the task finishes.
+// keepBlockDev indicates if backing block device should be not be deactivated if volume is unmounted.
+func (v Volume) UnmountTask(task func(op *operations.Operation) error, keepBlockDev bool, op *operations.Operation) error {
 	// If the volume is a snapshot then call the snapshot specific mount/unmount functions as
 	// these will mount the snapshot read only.
 	if v.IsSnapshot() {
@@ -253,7 +254,7 @@ func (v Volume) UnmountTask(task func(op *operations.Operation) error, op *opera
 	} else {
 		unlock := locking.Lock(OperationLockName(v.pool, string(v.volType), v.name))
 
-		ourUnmount, err := v.driver.UnmountVolume(v, op)
+		ourUnmount, err := v.driver.UnmountVolume(v, keepBlockDev, op)
 		if err != nil {
 			unlock()
 			return err

From 54472ad66be90990d8a23dfe07c3256ec873dd98 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:17:33 +0100
Subject: [PATCH 06/18] lxd/storage/drivers/utils: Passes true for keepBlockDev
 arg to UnmounTask in shrinkFileSystem

Allows for a block backed storage backend to keep its block device activate to allow shrink of filesystem if filesystem was already mounted.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/utils.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/utils.go b/lxd/storage/drivers/utils.go
index 437efda622..de985134bb 100644
--- a/lxd/storage/drivers/utils.go
+++ b/lxd/storage/drivers/utils.go
@@ -505,7 +505,7 @@ func shrinkFileSystem(fsType string, devPath string, vol Volume, byteSize int64)
 			}
 
 			return nil
-		}, nil)
+		}, true, nil)
 	case "btrfs":
 		return vol.MountTask(func(mountPath string, op *operations.Operation) error {
 			_, err := shared.RunCommand("btrfs", "filesystem", "resize", strSize, mountPath)

From d1144f577bd22587693ebf1c1c6754c15882d863 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:18:47 +0100
Subject: [PATCH 07/18] lxd/storage/drivers/generic/vfs: d.UnmountVolume usage

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

diff --git a/lxd/storage/drivers/generic_vfs.go b/lxd/storage/drivers/generic_vfs.go
index 8e36f6247a..bd7ace84a4 100644
--- a/lxd/storage/drivers/generic_vfs.go
+++ b/lxd/storage/drivers/generic_vfs.go
@@ -816,7 +816,7 @@ func genericVFSBackupUnpack(d Driver, vol Volume, snapshots []string, srcData io
 		// backup restore process to unmount the volume if needed.
 		postHook = func(vol Volume) error {
 			if ourMount {
-				d.UnmountVolume(vol, op)
+				d.UnmountVolume(vol, false, op)
 			}
 
 			return nil
@@ -824,7 +824,7 @@ func genericVFSBackupUnpack(d Driver, vol Volume, snapshots []string, srcData io
 	} else {
 		// For custom volumes unmount now, there is no post hook as there is no backup.yaml to generate.
 		if ourMount {
-			d.UnmountVolume(vol, op)
+			d.UnmountVolume(vol, false, op)
 		}
 	}
 

From ed358c62fc7cdcfa6cbb6ed03f1858cfe6553a48 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:19:03 +0100
Subject: [PATCH 08/18] lxd/storage/drivers/drivers/mock: Adds keepBlockDev arg
 to UnmountVolume

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/drivers_mock.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/drivers_mock.go b/lxd/storage/drivers/drivers_mock.go
index 9d12ac3dee..bc876b075d 100644
--- a/lxd/storage/drivers/drivers_mock.go
+++ b/lxd/storage/drivers/drivers_mock.go
@@ -149,7 +149,7 @@ func (d *mock) MountVolume(vol Volume, op *operations.Operation) (bool, error) {
 
 // UnmountVolume simulates unmounting a volume. As dir driver doesn't have volumes to unmount it
 // returns false indicating the volume was already unmounted.
-func (d *mock) UnmountVolume(vol Volume, op *operations.Operation) (bool, error) {
+func (d *mock) UnmountVolume(vol Volume, keepBlockDev bool, op *operations.Operation) (bool, error) {
 	return false, nil
 }
 

From 0abd8e94fbc22b5a1d5f9a2e899960da90d8ec81 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:19:43 +0100
Subject: [PATCH 09/18] lxd/storage/drivers/driver/btrfs/volumes: Adds
 keepBlockDev arg to UnmountVolume

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

diff --git a/lxd/storage/drivers/driver_btrfs_volumes.go b/lxd/storage/drivers/driver_btrfs_volumes.go
index d2a99e5640..c9bafdef88 100644
--- a/lxd/storage/drivers/driver_btrfs_volumes.go
+++ b/lxd/storage/drivers/driver_btrfs_volumes.go
@@ -771,7 +771,8 @@ func (d *btrfs) MountVolume(vol Volume, op *operations.Operation) (bool, error)
 }
 
 // UnmountVolume simulates unmounting a volume.
-func (d *btrfs) UnmountVolume(vol Volume, op *operations.Operation) (bool, error) {
+// As driver doesn't have volumes to unmount it returns false indicating the volume was already unmounted.
+func (d *btrfs) UnmountVolume(vol Volume, keepBlockDev bool, op *operations.Operation) (bool, error) {
 	return false, nil
 }
 

From 7d150e4898b4137af5d49776b653d15db8322f4a Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:20:02 +0100
Subject: [PATCH 10/18] lxd/storage/drivers/driver/dir/volumes: Adds
 keepBlockDev arg to UnmountVolume

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

diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go
index 2cf3f63c42..a189f908ed 100644
--- a/lxd/storage/drivers/driver_dir_volumes.go
+++ b/lxd/storage/drivers/driver_dir_volumes.go
@@ -322,9 +322,9 @@ func (d *dir) MountVolume(vol Volume, op *operations.Operation) (bool, error) {
 	return false, nil
 }
 
-// UnmountVolume simulates unmounting a volume. As dir driver doesn't have volumes to unmount it
-// returns false indicating the volume was already unmounted.
-func (d *dir) UnmountVolume(vol Volume, op *operations.Operation) (bool, error) {
+// UnmountVolume simulates unmounting a volume.
+// As driver doesn't have volumes to unmount it returns false indicating the volume was already unmounted.
+func (d *dir) UnmountVolume(vol Volume, keepBlockDev bool, op *operations.Operation) (bool, error) {
 	return false, nil
 }
 

From 0049a9745be5ad1b72e6bd24bc3aeb8c1218c451 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:20:18 +0100
Subject: [PATCH 11/18] lxd/storage/drivers/driver/cephfs/volumes: Adds
 keepBlockDev arg to UnmountVolume

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

diff --git a/lxd/storage/drivers/driver_cephfs_volumes.go b/lxd/storage/drivers/driver_cephfs_volumes.go
index bdde9bfad1..af9058d5d8 100644
--- a/lxd/storage/drivers/driver_cephfs_volumes.go
+++ b/lxd/storage/drivers/driver_cephfs_volumes.go
@@ -343,7 +343,8 @@ func (d *cephfs) MountVolume(vol Volume, op *operations.Operation) (bool, error)
 }
 
 // UnmountVolume clears any runtime state for the volume.
-func (d *cephfs) UnmountVolume(vol Volume, op *operations.Operation) (bool, error) {
+// As driver doesn't have volumes to unmount it returns false indicating the volume was already unmounted.
+func (d *cephfs) UnmountVolume(vol Volume, keepBlockDev bool, op *operations.Operation) (bool, error) {
 	return false, nil
 }
 

From 010ec64e97dd9e3d60d99cbe2f21d34277c624a3 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:21:26 +0100
Subject: [PATCH 12/18] lxd/storage/drivers/driver/lvm/volumes: UnmountVolume
 usage

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

diff --git a/lxd/storage/drivers/driver_lvm_volumes.go b/lxd/storage/drivers/driver_lvm_volumes.go
index e761fa2582..3a763f9448 100644
--- a/lxd/storage/drivers/driver_lvm_volumes.go
+++ b/lxd/storage/drivers/driver_lvm_volumes.go
@@ -188,7 +188,7 @@ func (d *lvm) DeleteVolume(vol Volume, op *operations.Operation) error {
 
 	if lvExists {
 		if vol.contentType == ContentTypeFS {
-			_, err = d.UnmountVolume(vol, op)
+			_, err = d.UnmountVolume(vol, false, op)
 			if err != nil {
 				return errors.Wrapf(err, "Error unmounting LVM logical volume")
 			}
@@ -502,7 +502,7 @@ func (d *lvm) UnmountVolume(vol Volume, op *operations.Operation) (bool, error)
 	// For VMs, unmount the filesystem volume.
 	if vol.IsVMBlock() {
 		fsVol := vol.NewVMBlockFilesystemVolume()
-		return d.UnmountVolume(fsVol, op)
+		return d.UnmountVolume(fsVol, false, op)
 	}
 
 	return deactivated, nil
@@ -661,7 +661,7 @@ func (d *lvm) DeleteVolumeSnapshot(snapVol Volume, op *operations.Operation) err
 	}
 
 	if lvExists {
-		_, err = d.UnmountVolume(snapVol, op)
+		_, err = d.UnmountVolume(snapVol, false, op)
 		if err != nil {
 			return errors.Wrapf(err, "Error unmounting LVM logical volume")
 		}
@@ -923,7 +923,7 @@ func (d *lvm) RestoreVolume(vol Volume, snapshotName string, op *operations.Oper
 	// 2. Create a writable snapshot with the original name from the snapshot being restored.
 	// 3. Delete the renamed original volume.
 	if d.usesThinpool() {
-		_, err = d.UnmountVolume(vol, op)
+		_, err = d.UnmountVolume(vol, false, op)
 		if err != nil {
 			return errors.Wrapf(err, "Error unmounting LVM logical volume")
 		}

From 530655d6eb70a61fc6914e84b1431d819f1bebd6 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:21:49 +0100
Subject: [PATCH 13/18] lxd/storage/drivers/driver/lvm/volumes: Adds
 keepBlockDev arg to UnmountVolume

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

diff --git a/lxd/storage/drivers/driver_lvm_volumes.go b/lxd/storage/drivers/driver_lvm_volumes.go
index 3a763f9448..614e3b215b 100644
--- a/lxd/storage/drivers/driver_lvm_volumes.go
+++ b/lxd/storage/drivers/driver_lvm_volumes.go
@@ -468,7 +468,8 @@ func (d *lvm) MountVolume(vol Volume, op *operations.Operation) (bool, error) {
 }
 
 // UnmountVolume unmounts a volume. Returns true if we unmounted.
-func (d *lvm) UnmountVolume(vol Volume, op *operations.Operation) (bool, error) {
+// keepBlockDev indicates if backing block device should be not be deactivated if volume is unmounted.
+func (d *lvm) UnmountVolume(vol Volume, keepBlockDev bool, op *operations.Operation) (bool, error) {
 	var err error
 	volDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, vol.contentType, vol.name)
 	mountPath := vol.MountPath()
@@ -479,20 +480,22 @@ func (d *lvm) UnmountVolume(vol Volume, op *operations.Operation) (bool, error)
 		if err != nil {
 			return false, errors.Wrapf(err, "Failed to unmount LVM logical volume")
 		}
-		d.logger.Debug("Unmounted logical volume", log.Ctx{"path": mountPath})
+		d.logger.Debug("Unmounted logical volume", log.Ctx{"path": mountPath, "keepBlockDev": keepBlockDev})
 
 		// We only deactivate filesystem volumes if an unmount was needed to better align with our
 		// unmount return value indicator.
-		_, err = d.deactivateVolume(volDevPath)
-		if err != nil {
-			return false, err
+		if !keepBlockDev {
+			_, err = d.deactivateVolume(volDevPath)
+			if err != nil {
+				return false, err
+			}
 		}
 
 		return true, nil
 	}
 
 	deactivated := false
-	if vol.contentType == ContentTypeBlock {
+	if vol.contentType == ContentTypeBlock && !keepBlockDev {
 		deactivated, err = d.deactivateVolume(volDevPath)
 		if err != nil {
 			return false, err

From 8ce875a18270d485c04c834009adb137094c02ab Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:22:16 +0100
Subject: [PATCH 14/18] lxd/storage/drivers/driver/lvm/volumes: UnmountTask
 usage

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/driver_lvm_volumes.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/driver_lvm_volumes.go b/lxd/storage/drivers/driver_lvm_volumes.go
index 614e3b215b..518d2686a9 100644
--- a/lxd/storage/drivers/driver_lvm_volumes.go
+++ b/lxd/storage/drivers/driver_lvm_volumes.go
@@ -580,7 +580,7 @@ func (d *lvm) RenameVolume(vol Volume, newVolName string, op *operations.Operati
 
 		revert.Success()
 		return nil
-	}, op)
+	}, false, op)
 }
 
 // MigrateVolume sends a volume for migration.

From a351f11164005d251914628d1439ec60ab08a8fe Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:22:48 +0100
Subject: [PATCH 15/18] lxd/storage/drivers/driver/ceph/volumes:
 d.UnmountVolume usage

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

diff --git a/lxd/storage/drivers/driver_ceph_volumes.go b/lxd/storage/drivers/driver_ceph_volumes.go
index 55ef3825d6..0d3508eb94 100644
--- a/lxd/storage/drivers/driver_ceph_volumes.go
+++ b/lxd/storage/drivers/driver_ceph_volumes.go
@@ -610,7 +610,7 @@ func (d *ceph) DeleteVolume(vol Volume, op *operations.Operation) error {
 
 	if vol.volType == VolumeTypeImage {
 		// Try to umount but don't fail.
-		d.UnmountVolume(vol, op)
+		d.UnmountVolume(vol, false, op)
 
 		// Check if image has dependant snapshots.
 		_, err := d.rbdListSnapshotClones(vol, "readonly")
@@ -658,7 +658,7 @@ func (d *ceph) DeleteVolume(vol Volume, op *operations.Operation) error {
 			return err
 		}
 	} else {
-		_, err := d.UnmountVolume(vol, op)
+		_, err := d.UnmountVolume(vol, false, op)
 		if err != nil {
 			return err
 		}
@@ -980,7 +980,7 @@ func (d *ceph) UnmountVolume(vol Volume, op *operations.Operation) (bool, error)
 	// For VMs, unmount the filesystem volume.
 	if vol.IsVMBlock() {
 		fsVol := vol.NewVMBlockFilesystemVolume()
-		return d.UnmountVolume(fsVol, op)
+		return d.UnmountVolume(fsVol, false, op)
 	}
 
 	return false, nil
@@ -991,7 +991,7 @@ func (d *ceph) RenameVolume(vol Volume, newName string, op *operations.Operation
 	revert := revert.New()
 	defer revert.Fail()
 
-	_, err := d.UnmountVolume(vol, op)
+	_, err := d.UnmountVolume(vol, false, op)
 	if err != nil {
 		return err
 	}
@@ -1419,7 +1419,7 @@ func (d *ceph) VolumeSnapshots(vol Volume, op *operations.Operation) ([]string,
 
 // RestoreVolume restores a volume from a snapshot.
 func (d *ceph) RestoreVolume(vol Volume, snapshotName string, op *operations.Operation) error {
-	ourUmount, err := d.UnmountVolume(vol, op)
+	ourUmount, err := d.UnmountVolume(vol, false, op)
 	if err != nil {
 		return err
 	}

From d6d0f9bf1faa4776b561c36779f3289d43c028b1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:23:11 +0100
Subject: [PATCH 16/18] lxd/storage/drivers/driver/ceph/volumes: Adds
 keepBlockDev arg to UnmountVolume

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/driver_ceph_volumes.go | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lxd/storage/drivers/driver_ceph_volumes.go b/lxd/storage/drivers/driver_ceph_volumes.go
index 0d3508eb94..808d1ea5c6 100644
--- a/lxd/storage/drivers/driver_ceph_volumes.go
+++ b/lxd/storage/drivers/driver_ceph_volumes.go
@@ -950,7 +950,8 @@ func (d *ceph) MountVolume(vol Volume, op *operations.Operation) (bool, error) {
 }
 
 // UnmountVolume simulates unmounting a volume.
-func (d *ceph) UnmountVolume(vol Volume, op *operations.Operation) (bool, error) {
+// keepBlockDev indicates if backing block device should be not be unmapped if volume is unmounted.
+func (d *ceph) UnmountVolume(vol Volume, keepBlockDev bool, op *operations.Operation) (bool, error) {
 	// Attempt to unmount the volume.
 	mountPath := vol.MountPath()
 	if vol.contentType == ContentTypeFS && shared.IsMountPoint(mountPath) {
@@ -958,18 +959,20 @@ func (d *ceph) UnmountVolume(vol Volume, op *operations.Operation) (bool, error)
 		if err != nil {
 			return false, err
 		}
-		d.logger.Debug("Unmounted RBD volume", log.Ctx{"path": mountPath})
+		d.logger.Debug("Unmounted RBD volume", log.Ctx{"path": mountPath, "keepBlockDev": keepBlockDev})
 
 		// Attempt to unmap.
-		err = d.rbdUnmapVolume(vol, true)
-		if err != nil {
-			return false, err
+		if !keepBlockDev {
+			err = d.rbdUnmapVolume(vol, true)
+			if err != nil {
+				return false, err
+			}
 		}
 
 		return true, nil
 	}
 
-	if vol.contentType == ContentTypeBlock {
+	if vol.contentType == ContentTypeBlock && !keepBlockDev {
 		// Attempt to unmap.
 		err := d.rbdUnmapVolume(vol, true)
 		if err != nil {

From 7ef06a6ca186224f8b8b80ec27f1947c40cccf67 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:23:29 +0100
Subject: [PATCH 17/18] lxd/storage/drivers/driver/zfs/volumes: Adds
 keepBlockDev arg to UnmountVolume

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

diff --git a/lxd/storage/drivers/driver_zfs_volumes.go b/lxd/storage/drivers/driver_zfs_volumes.go
index 0f06215306..9e1eeba331 100644
--- a/lxd/storage/drivers/driver_zfs_volumes.go
+++ b/lxd/storage/drivers/driver_zfs_volumes.go
@@ -1073,21 +1073,22 @@ func (d *zfs) MountVolume(vol Volume, op *operations.Operation) (bool, error) {
 }
 
 // UnmountVolume simulates unmounting a volume.
-func (d *zfs) UnmountVolume(vol Volume, op *operations.Operation) (bool, error) {
+// keepBlockDev indicates if backing block device should be not be deactivated if volume is unmounted.
+func (d *zfs) UnmountVolume(vol Volume, keepBlockDev bool, op *operations.Operation) (bool, error) {
 	mountPath := vol.MountPath()
 	dataset := d.dataset(vol, false)
 
 	// For VMs, also mount the filesystem dataset.
 	if vol.IsVMBlock() {
 		fsVol := vol.NewVMBlockFilesystemVolume()
-		_, err := d.UnmountVolume(fsVol, op)
+		_, err := d.UnmountVolume(fsVol, false, op)
 		if err != nil {
 			return false, err
 		}
 	}
 
 	// For block devices, we make them disappear.
-	if vol.contentType == ContentTypeBlock {
+	if vol.contentType == ContentTypeBlock && !keepBlockDev {
 		err := d.setDatasetProperties(dataset, "volmode=none")
 		if err != nil {
 			return false, err

From f74fd527955beb54259d7f5657af687fc4dc29c4 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 21 Oct 2020 11:23:42 +0100
Subject: [PATCH 18/18] lxd/storage/drivers/driver/zfs/volumes: d.UnmountVolume
 usage

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

diff --git a/lxd/storage/drivers/driver_zfs_volumes.go b/lxd/storage/drivers/driver_zfs_volumes.go
index 9e1eeba331..7689718384 100644
--- a/lxd/storage/drivers/driver_zfs_volumes.go
+++ b/lxd/storage/drivers/driver_zfs_volumes.go
@@ -416,7 +416,7 @@ func (d *zfs) CreateVolumeFromBackup(vol Volume, srcBackup backup.Info, srcData
 		}
 
 		postHook = func(vol Volume) error {
-			_, err := d.UnmountVolume(vol, op)
+			_, err := d.UnmountVolume(vol, false, op)
 			return err
 		}
 	}
@@ -1184,7 +1184,7 @@ func (d *zfs) MigrateVolume(vol Volume, conn io.ReadWriteCloser, volSrcArgs *mig
 			return err
 		}
 		if ourMount {
-			defer d.UnmountVolume(parentVol, op)
+			defer d.UnmountVolume(parentVol, false, op)
 		}
 
 		return genericVFSMigrateVolume(d, d.state, vol, conn, volSrcArgs, op)
@@ -1288,7 +1288,7 @@ func (d *zfs) BackupVolume(vol Volume, tarWriter *instancewriter.InstanceTarWrit
 			}
 
 			if ourMount {
-				defer d.UnmountVolume(parentVol, op)
+				defer d.UnmountVolume(parentVol, false, op)
 			}
 		}
 


More information about the lxc-devel mailing list