[lxc-devel] [lxd/master] Storage resize and UUID regeneration
tomponline on Github
lxc-bot at linuxcontainers.org
Thu Jan 9 19:42:14 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 382 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200109/6845e8dd/attachment-0001.bin>
-------------- next part --------------
From 529a839a949a3cadd1d8c33e1909ba9729f3262b Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 9 Jan 2020 12:03:00 +0000
Subject: [PATCH 1/3] lxd/storage/drivers/utils: Comment on shrinkFileSystem
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/utils.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/lxd/storage/drivers/utils.go b/lxd/storage/drivers/utils.go
index 91c5e939e4..6797096f7f 100644
--- a/lxd/storage/drivers/utils.go
+++ b/lxd/storage/drivers/utils.go
@@ -406,6 +406,7 @@ func resolveMountOptions(options string) (uintptr, string) {
// shrinkFileSystem shrinks a filesystem if it is supported. Ext4 volumes will be unmounted temporarily if needed.
func shrinkFileSystem(fsType string, devPath string, vol Volume, byteSize int64) error {
+ // The smallest unit that resize2fs accepts in byte size (rather than blocks) is kilobytes.
strSize := fmt.Sprintf("%dK", byteSize/1024)
switch fsType {
From e1fbb4ca5156b23a8f288c3f5a922b2892528def Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 9 Jan 2020 13:35:55 +0000
Subject: [PATCH 2/3] lxd/storage/drivers/utils: Mounts btrfs filesystems
during shrinkFileSystem
This is required to resize the filesystem.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/utils.go | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/lxd/storage/drivers/utils.go b/lxd/storage/drivers/utils.go
index 6797096f7f..32ecbcdf38 100644
--- a/lxd/storage/drivers/utils.go
+++ b/lxd/storage/drivers/utils.go
@@ -429,15 +429,17 @@ func shrinkFileSystem(fsType string, devPath string, vol Volume, byteSize int64)
return nil
}, nil)
case "btrfs":
- _, err := shared.TryRunCommand("btrfs", "filesystem", "resize", strSize, vol.MountPath())
- if err != nil {
- return err
- }
+ return vol.MountTask(func(mountPath string, op *operations.Operation) error {
+ _, err := shared.TryRunCommand("btrfs", "filesystem", "resize", strSize, mountPath)
+ if err != nil {
+ return err
+ }
+
+ return nil
+ }, nil)
default:
return fmt.Errorf(`Shrinking not supported for filesystem type "%s"`, fsType)
}
-
- return nil
}
// growFileSystem grows a filesystem if it is supported. The volume will be mounted temporarily if needed.
From 860e2383bbacffa30d5e8f8c4f14943c6c3f6add Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 9 Jan 2020 15:05:08 +0000
Subject: [PATCH 3/3] lxd/storage/drivers/utils: Adds regenerateFilesystemUUID
functions
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/drivers/utils.go | 48 ++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/lxd/storage/drivers/utils.go b/lxd/storage/drivers/utils.go
index 32ecbcdf38..19a877d1c1 100644
--- a/lxd/storage/drivers/utils.go
+++ b/lxd/storage/drivers/utils.go
@@ -468,3 +468,51 @@ func growFileSystem(fsType string, devPath string, vol Volume) error {
return nil
}, nil)
}
+
+// regenerateFilesystemUUID changes the filesystem UUID to a new randomly generated one if the fsType requires it.
+// Otherwise this function does nothing.
+func regenerateFilesystemUUID(fsType, devPath string) error {
+ switch fsType {
+ case "btrfs":
+ return regenerateFilesystemBTRFSUUID(devPath)
+ case "xfs":
+ return regenerateFilesystemXFSUUID(devPath)
+ }
+
+ return nil
+}
+
+// regenerateFilesystemBTRFSUUID changes the BTRFS filesystem UUID to a new randomly generated one.
+func regenerateFilesystemBTRFSUUID(devPath string) error {
+ _, err := shared.RunCommand("btrfstune", "-f", "-u", devPath)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// regenerateFilesystemXFSUUID changes the XFS filesystem UUID to a new randomly generated one.
+func regenerateFilesystemXFSUUID(devPath string) error {
+ // Attempt to generate a new UUID.
+ msg, err := shared.RunCommand("xfs_admin", "-U", "generate", devPath)
+ if err != nil {
+ return err
+ }
+
+ if msg != "" {
+ // Exit 0 with a msg usually means some log entry getting in the way.
+ _, err = shared.RunCommand("xfs_repair", "-o", "force_geometry", "-L", devPath)
+ if err != nil {
+ return err
+ }
+
+ // Attempt to generate a new UUID again.
+ _, err = shared.RunCommand("xfs_admin", "-U", "generate", devPath)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
More information about the lxc-devel
mailing list