From 1bb8960997d373b0afc36092098a67214752fa46 Mon Sep 17 00:00:00 2001 From: Seb Patane Date: Wed, 24 Feb 2021 02:57:37 +1100 Subject: [PATCH] Add btrfs support to the automatic volume resizer --- staging/src/k8s.io/mount-utils/resizefs_linux.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/staging/src/k8s.io/mount-utils/resizefs_linux.go b/staging/src/k8s.io/mount-utils/resizefs_linux.go index e2bfe441727..3b2ffa31366 100644 --- a/staging/src/k8s.io/mount-utils/resizefs_linux.go +++ b/staging/src/k8s.io/mount-utils/resizefs_linux.go @@ -56,6 +56,8 @@ func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (boo return resizefs.extResize(devicePath) case "xfs": return resizefs.xfsResize(deviceMountPath) + case "btrfs": + return resizefs.btrfsResize(deviceMountPath) } return false, fmt.Errorf("ResizeFS.Resize - resize of format %s is not supported for device %s mounted at %s", format, devicePath, deviceMountPath) } @@ -84,3 +86,16 @@ func (resizefs *ResizeFs) xfsResize(deviceMountPath string) (bool, error) { resizeError := fmt.Errorf("resize of device %s failed: %v. xfs_growfs output: %s", deviceMountPath, err, string(output)) return false, resizeError } + +func (resizefs *ResizeFs) btrfsResize(deviceMountPath string) (bool, error) { + args := []string{"filesystem", "resize", "max", deviceMountPath} + output, err := resizefs.exec.Command("btrfs", args...).CombinedOutput() + + if err == nil { + klog.V(2).Infof("Device %s resized successfully", deviceMountPath) + return true, nil + } + + resizeError := fmt.Errorf("resize of device %s failed: %v. btrfs output: %s", deviceMountPath, err, string(output)) + return false, resizeError +}