The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3852
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) ===
From 1f5d1ed6d2824a14ec0116dd20eeaf33bc86f464 Mon Sep 17 00:00:00 2001 From: Alberto Donato <[email protected]> Date: Tue, 26 Sep 2017 11:33:14 -0400 Subject: [PATCH 1/2] storage/utils: support resizing btrfs-based volumes Signed-off-by: Alberto Donato <[email protected]> --- lxd/storage_ceph_utils.go | 2 +- lxd/storage_lvm_utils.go | 2 +- lxd/storage_utils.go | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lxd/storage_ceph_utils.go b/lxd/storage_ceph_utils.go index a6510e848..142dcabc4 100644 --- a/lxd/storage_ceph_utils.go +++ b/lxd/storage_ceph_utils.go @@ -1556,7 +1556,7 @@ func (s *storageCeph) rbdShrink(path string, size int64, fsType string, `less than 1MB`) } - cleanupFunc, err := shrinkVolumeFilesystem(s, volumeType, fsType, path, size, data) + cleanupFunc, err := shrinkVolumeFilesystem(s, volumeType, fsType, path, fsMntPoint, size, data) if cleanupFunc != nil { defer cleanupFunc() } diff --git a/lxd/storage_lvm_utils.go b/lxd/storage_lvm_utils.go index 62e61d7c6..0b53eb712 100644 --- a/lxd/storage_lvm_utils.go +++ b/lxd/storage_lvm_utils.go @@ -70,7 +70,7 @@ func (s *storageLvm) lvReduce(lvPath string, lvSize int64, fsType string, fsMntP return fmt.Errorf(`The size of the storage volume would be ` + `less than 1MB`) } - cleanupFunc, err := shrinkVolumeFilesystem(s, volumeType, fsType, lvPath, lvSize, data) + cleanupFunc, err := shrinkVolumeFilesystem(s, volumeType, fsType, lvPath, fsMntPoint, lvSize, data) if cleanupFunc != nil { defer cleanupFunc() } diff --git a/lxd/storage_utils.go b/lxd/storage_utils.go index 81171a0fd..c9b438eaf 100644 --- a/lxd/storage_utils.go +++ b/lxd/storage_utils.go @@ -236,6 +236,8 @@ func growFileSystem(fsType string, devPath string, mntpoint string) error { msg, err = shared.TryRunCommand("resize2fs", mntpoint) case "xfs": msg, err = shared.TryRunCommand("xfs_growfs", devPath) + case "btrfs": + msg, err = shared.TryRunCommand("btrfs", "filesystem", "resize", "max", mntpoint) default: return fmt.Errorf(`Growing not supported for filesystem type "%s"`, fsType) } @@ -250,9 +252,10 @@ func growFileSystem(fsType string, devPath string, mntpoint string) error { return nil } -func shrinkFileSystem(fsType string, devPath string, byteSize int64) error { +func shrinkFileSystem(fsType string, devPath string, mntpoint string, byteSize int64) error { var msg string var err error + strSize := fmt.Sprintf("%dK", byteSize/1024) switch fsType { case "": // if not specified, default to ext4 fallthrough @@ -261,9 +264,9 @@ func shrinkFileSystem(fsType string, devPath string, byteSize int64) error { if err != nil { return err } - kbSize := byteSize / 1024 - msg, err = shared.TryRunCommand("resize2fs", devPath, fmt.Sprintf("%dK", kbSize)) - + msg, err = shared.TryRunCommand("resize2fs", devPath, strSize) + case "btrfs": + msg, err = shared.TryRunCommand("btrfs", "filesystem", "resize", strSize, mntpoint) default: return fmt.Errorf(`Shrinking not supported for filesystem type "%s"`, fsType) } @@ -276,12 +279,14 @@ func shrinkFileSystem(fsType string, devPath string, byteSize int64) error { return nil } -func shrinkVolumeFilesystem(s storage, volumeType int, fsType string, devPath string, byteSize int64, data interface{}) (func() (bool, error), error) { +func shrinkVolumeFilesystem(s storage, volumeType int, fsType string, devPath string, mntpoint string, byteSize int64, data interface{}) (func() (bool, error), error) { var cleanupFunc func() (bool, error) switch fsType { case "xfs": logger.Errorf("xfs filesystems cannot be shrunk: dump, mkfs, and restore are required") return nil, fmt.Errorf("xfs filesystems cannot be shrunk: dump, mkfs, and restore are required") + case "btrfs": + fallthrough case "": // if not specified, default to ext4 fallthrough case "ext4": @@ -311,6 +316,6 @@ func shrinkVolumeFilesystem(s storage, volumeType int, fsType string, devPath st return nil, fmt.Errorf(`Shrinking not supported for filesystem type "%s"`, fsType) } - err := shrinkFileSystem(fsType, devPath, byteSize) + err := shrinkFileSystem(fsType, devPath, mntpoint, byteSize) return cleanupFunc, err } From 3bf73e8bdcc98ccaff4d97f60636faa896a1b993 Mon Sep 17 00:00:00 2001 From: Alberto Donato <[email protected]> Date: Tue, 26 Sep 2017 15:01:47 -0400 Subject: [PATCH 2/2] add tests for btrfs resize Signed-off-by: Alberto Donato <[email protected]> --- test/suites/storage.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/suites/storage.sh b/test/suites/storage.sh index e4561dbac..5cccd94cb 100644 --- a/test/suites/storage.sh +++ b/test/suites/storage.sh @@ -30,6 +30,19 @@ test_storage() { lxc storage volume delete "$storage_pool" "$storage_volume" lxc storage delete "$storage_pool" + + # Test btrfs resize + # shellcheck disable=2039 + local btrfs_storage_pool btrfs_storage_volume + btrfs_storage_pool="lxdtest-$(basename "${LXD_DIR}")-pool-btrfs" + btrfs_storage_volume="${storage_pool}-vol" + lxc storage create "$btrfs_storage_pool" "$lxd_backend" volume.block.filesystem=btrfs + lxc storage volume create "$btrfs_storage_pool" "$btrfs_storage_volume" + if [ "$lxd_backend" != "dir" ] && [ "$lxd_backend" != "ceph" ]; then + lxc storage volume set "$btrfs_storage_pool" "$btrfs_storage_volume" size 200MB + lxc storage volume unset "$btrfs_storage_pool" "$btrfs_storage_volume" size 150MB + fi + ( set -e # shellcheck disable=2030
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
