From eb721ed44dbe622aaf2883a359b2ffb33c98931f Mon Sep 17 00:00:00 2001 From: tblanchard Date: Tue, 21 Sep 2021 12:32:28 +0200 Subject: [PATCH 1/2] Preliminary commit for xfs support. --- src/connector/nfs/nfs_helper.go | 29 +++++++++++++++++------------ src/utils/utils.go | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/connector/nfs/nfs_helper.go b/src/connector/nfs/nfs_helper.go index e2465d7c..4eedacd4 100644 --- a/src/connector/nfs/nfs_helper.go +++ b/src/connector/nfs/nfs_helper.go @@ -245,18 +245,22 @@ func getFSType(sourcePath string) (string, error) { func formatDisk(sourcePath, fsType, diskSizeType string) error { var cmd string - switch diskSizeType { - case "default": - cmd = fmt.Sprintf("mkfs -t %s -F %s", fsType, sourcePath) - case "big": - cmd = fmt.Sprintf("mkfs -t %s -T big -F %s", fsType, sourcePath) - case "huge": - cmd = fmt.Sprintf("mkfs -t %s -T huge -F %s", fsType, sourcePath) - case "large": - cmd = fmt.Sprintf("mkfs -t %s -T largefile -F %s", fsType, sourcePath) - case "veryLarge": - cmd = fmt.Sprintf("mkfs -t %s -T largefile4 -F %s", fsType, sourcePath) - } + switch fsType { + case "xfs": + cmd = fmt.Sprintf("mkfs.xfs -f %s", sourcePath) + default: + switch diskSizeType { + case "default": + cmd = fmt.Sprintf("mkfs -t %s -F %s", fsType, sourcePath) + case "big": + cmd = fmt.Sprintf("mkfs -t %s -T big -F %s", fsType, sourcePath) + case "huge": + cmd = fmt.Sprintf("mkfs -t %s -T huge -F %s", fsType, sourcePath) + case "large": + cmd = fmt.Sprintf("mkfs -t %s -T largefile -F %s", fsType, sourcePath) + case "veryLarge": + cmd = fmt.Sprintf("mkfs -t %s -T largefile4 -F %s", fsType, sourcePath) + } output, err := utils.ExecShellCmd(cmd) if err != nil { if strings.Contains(output, "in use by the system") { @@ -267,6 +271,7 @@ func formatDisk(sourcePath, fsType, diskSizeType string) error { log.Errorf("Couldn't mkfs %s to %s: %s", sourcePath, fsType, output) return err } + return nil } diff --git a/src/utils/utils.go b/src/utils/utils.go index c981ff89..38f3cfbb 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -127,7 +127,7 @@ func execShellCmd(format string, logFilter bool, args ...interface{}) (string, b execCmd := []string{"-i/proc/1/ns/ipc", "-m/proc/1/ns/mnt", "-n/proc/1/ns/net", "/bin/sh", "-c", cmd} shCmd := exec.Command("nsenter", execCmd...) var timeOut bool - if strings.Contains(cmd, "mkfs") || strings.Contains(cmd, "resize2fs") { + if strings.Contains(cmd, "mkfs") || strings.Contains(cmd, "resize2fs" || strings.Contains(cmd, "xfs_growfs" ) { time.AfterFunc(longTimeout*time.Second, func() { timeOut = true }) From a1fdcdec318066f6cd3fbbb93248b802b67cf036 Mon Sep 17 00:00:00 2001 From: tblanchard Date: Mon, 20 Sep 2021 15:32:07 +0200 Subject: [PATCH 2/2] Add xfs resize support to huawei csi driver. --- src/connector/connector_utils.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/connector/connector_utils.go b/src/connector/connector_utils.go index de964929..49fd9faa 100644 --- a/src/connector/connector_utils.go +++ b/src/connector/connector_utils.go @@ -723,8 +723,11 @@ func ResizeMountPath(volumePath string) error { switch fsType { case "ext2", "ext3", "ext4": return extResize(devicePath) + case "xfs": + return xfsResize(devicePath) } + return fmt.Errorf("resize of format %s is not supported for device %s", fsType, devicePath) } @@ -739,6 +742,17 @@ func extResize(devicePath string) error { return nil } +func xfsResize(devicePath string) error { + output, err := utils.ExecShellCmd("xfs_growfs %s", devicePath) + if err != nil { + log.Errorf("xfs Resize %s error: %s", devicePath, output) + return err + } + + log.Infof("xfs Resize success for device path : %v", devicePath) + return nil +} + func findMultiPathWWN(mPath string) (string, error) { output, err := utils.ExecShellCmd("multipathd show maps") if err != nil {