[lxc-devel] [lxd/master] Storage: Removes Volume.keepDevice and updates Ceph to support shrink without it
tomponline on Github
lxc-bot at linuxcontainers.org
Wed May 6 09:37:11 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200506/29e0cbb9/attachment.bin>
-------------- next part --------------
From c93bed46f856a1250d274192dc6e5dab298316f3 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 6 May 2020 09:45:44 +0100
Subject: [PATCH 1/4] lxc/storage/drivers/volume: Removes keepDevice from
Volume
No longer needed.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/volume.go | 1 -
1 file changed, 1 deletion(-)
diff --git a/lxd/storage/drivers/volume.go b/lxd/storage/drivers/volume.go
index ac98e6e324..07ff0d433c 100644
--- a/lxd/storage/drivers/volume.go
+++ b/lxd/storage/drivers/volume.go
@@ -69,7 +69,6 @@ type Volume struct {
contentType ContentType
config map[string]string
driver Driver
- keepDevice bool
customMountPath string
allowUnsafeResize bool // Whether to allow potentially destructive unchecked resizing of volume.
}
From 6d69dc3a111832002db8c1b3be8daddb707222eb Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 6 May 2020 09:47:27 +0100
Subject: [PATCH 2/4] lxd/storage/drivers/driver/ceph/volumes: Removes
keepDevice usage
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/driver_ceph_volumes.go | 7 -------
1 file changed, 7 deletions(-)
diff --git a/lxd/storage/drivers/driver_ceph_volumes.go b/lxd/storage/drivers/driver_ceph_volumes.go
index 53521927ff..31b6691cbe 100644
--- a/lxd/storage/drivers/driver_ceph_volumes.go
+++ b/lxd/storage/drivers/driver_ceph_volumes.go
@@ -822,13 +822,6 @@ func (d *ceph) SetVolumeQuota(vol Volume, size string, op *operations.Operation)
return err
}
- // The grow/shrink functions use Mount/Unmount which may cause an unmap, so make sure to keep a reference.
- oldKeepDevice := vol.keepDevice
- vol.keepDevice = true
- defer func() {
- vol.keepDevice = oldKeepDevice
- }()
-
oldSizeBytes, err := BlockDevSizeBytes(RBDDevPath)
if err != nil {
return errors.Wrapf(err, "Error getting current size")
From aa932330f26067d384688a09de24b55631a6a3b2 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 6 May 2020 09:48:40 +0100
Subject: [PATCH 3/4] lxc/storage/drivers/driver/ceph/volumes: Mount changes
Always map the RBD device (so FS and block volumes get a device).
Only try and mount filesystem volumes that are not already mounted.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/driver_ceph_volumes.go | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/lxd/storage/drivers/driver_ceph_volumes.go b/lxd/storage/drivers/driver_ceph_volumes.go
index 31b6691cbe..b3b15043f8 100644
--- a/lxd/storage/drivers/driver_ceph_volumes.go
+++ b/lxd/storage/drivers/driver_ceph_volumes.go
@@ -907,19 +907,19 @@ func (d *ceph) GetVolumeDiskPath(vol Volume) (string, error) {
func (d *ceph) MountVolume(vol Volume, op *operations.Operation) (bool, error) {
mountPath := vol.MountPath()
- if vol.contentType == ContentTypeFS && !shared.IsMountPoint(mountPath) {
- RBDFilesystem := d.getRBDFilesystem(vol)
+ // Activate RBD volume if needed.
+ RBDDevPath, err := d.getRBDMappedDevPath(vol)
+ if err != nil {
+ return false, err
+ }
+ if vol.contentType == ContentTypeFS && !shared.IsMountPoint(mountPath) {
err := vol.EnsureMountPath()
if err != nil {
return false, err
}
- RBDDevPath, err := d.getRBDMappedDevPath(vol)
- if err != nil {
- return false, err
- }
-
+ RBDFilesystem := d.getRBDFilesystem(vol)
mountFlags, mountOptions := resolveMountOptions(d.getRBDMountOptions(vol))
err = TryMount(RBDDevPath, mountPath, RBDFilesystem, mountFlags, mountOptions)
if err != nil {
From 5311eb05cad47cc363765c88550fee23edce483b Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 6 May 2020 09:50:20 +0100
Subject: [PATCH 4/4] lxd/storage/drivers/driver/ceph/volumes: UnmountVolume
modifications
Only unmap filesystem volumes if they have been unmounted too (allows for mapped volumes to remain mapped if already unmounted).
Always unmap block volumes.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/driver_ceph_volumes.go | 34 ++++++++++++----------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/lxd/storage/drivers/driver_ceph_volumes.go b/lxd/storage/drivers/driver_ceph_volumes.go
index b3b15043f8..1b7d5e0a82 100644
--- a/lxd/storage/drivers/driver_ceph_volumes.go
+++ b/lxd/storage/drivers/driver_ceph_volumes.go
@@ -941,35 +941,39 @@ 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) {
- // For VMs, also unmount the filesystem dataset.
- if vol.IsVMBlock() {
- fsVol := vol.NewVMBlockFilesystemVolume()
-
- _, err := d.UnmountVolume(fsVol, op)
- if err != nil {
- return false, err
- }
- }
-
// Attempt to unmount the volume.
mountPath := vol.MountPath()
- if shared.IsMountPoint(mountPath) {
+ if vol.contentType == ContentTypeFS && shared.IsMountPoint(mountPath) {
err := TryUnmount(mountPath, unix.MNT_DETACH)
if err != nil {
return false, err
}
d.logger.Debug("Unmounted RBD volume", log.Ctx{"path": mountPath})
+
+ // Attempt to unmap.
+ err = d.rbdUnmapVolume(vol, true)
+ if err != nil {
+ return false, err
+ }
+
+ return true, nil
}
- // Attempt to unmap.
- if !vol.keepDevice {
+ if vol.contentType == ContentTypeBlock {
+ // Attempt to unmap.
err := d.rbdUnmapVolume(vol, true)
if err != nil {
- return true, err
+ return false, err
}
}
- return true, nil
+ // For VMs, unmount the filesystem volume.
+ if vol.IsVMBlock() {
+ fsVol := vol.NewVMBlockFilesystemVolume()
+ return d.UnmountVolume(fsVol, op)
+ }
+
+ return false, nil
}
// RenameVolume renames a volume and its snapshots.
More information about the lxc-devel
mailing list