[lxc-devel] [lxd/master] lxd/storage/ceph: Fix ext4 shrinking

stgraber on Github lxc-bot at linuxcontainers.org
Mon Mar 16 21:08:00 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200316/2b6daf0a/attachment.bin>
-------------- next part --------------
From 7f76b0110674a7207f7f5cf5e9316e327278fcd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 16 Mar 2020 17:07:42 -0400
Subject: [PATCH] lxd/storage/ceph: Fix ext4 shrinking
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage/drivers/driver_ceph_volumes.go | 16 +++++++++++++---
 lxd/storage/drivers/volume.go              |  1 +
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/lxd/storage/drivers/driver_ceph_volumes.go b/lxd/storage/drivers/driver_ceph_volumes.go
index 35ec28a066..b3b2e507ca 100644
--- a/lxd/storage/drivers/driver_ceph_volumes.go
+++ b/lxd/storage/drivers/driver_ceph_volumes.go
@@ -675,6 +675,14 @@ 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
+	}()
+
 	RBDSize, err := ioutil.ReadFile(fmt.Sprintf("/sys/class/block/%s/size", filepath.Base(RBDDevPath)))
 	if err != nil {
 		return errors.Wrapf(err, "Error getting current size")
@@ -834,9 +842,11 @@ func (d *ceph) UnmountVolume(vol Volume, op *operations.Operation) (bool, error)
 	}
 
 	// Attempt to unmap.
-	err := d.rbdUnmapVolume(vol, true)
-	if err != nil {
-		return true, err
+	if !vol.keepDevice {
+		err := d.rbdUnmapVolume(vol, true)
+		if err != nil {
+			return true, err
+		}
 	}
 
 	return true, nil
diff --git a/lxd/storage/drivers/volume.go b/lxd/storage/drivers/volume.go
index 71127996b4..f612b5f2e0 100644
--- a/lxd/storage/drivers/volume.go
+++ b/lxd/storage/drivers/volume.go
@@ -68,6 +68,7 @@ type Volume struct {
 	contentType ContentType
 	config      map[string]string
 	driver      Driver
+	keepDevice  bool
 }
 
 // NewVolume instantiates a new Volume struct.


More information about the lxc-devel mailing list