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

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) ===
Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 7f76b0110674a7207f7f5cf5e9316e327278fcd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@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 <stgra...@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.
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to