diff --git a/mount_linux.go b/mount_linux.go index 2d24af913e4..41f69efe3f0 100644 --- a/mount_linux.go +++ b/mount_linux.go @@ -314,33 +314,6 @@ func (mounter *SafeFormatAndMount) checkAndRepairFilesystem(source string) error return nil } -// checkAndRepairXfsFilesystem checks and repairs xfs filesystem using command xfs_repair. -func (mounter *SafeFormatAndMount) checkAndRepairXfsFilesystem(source string) error { - klog.V(4).Infof("Checking for issues with xfs_repair on disk: %s", source) - - args := []string{source} - checkArgs := []string{"-n", source} - - // check-only using "xfs_repair -n", if the exit status is not 0, perform a "xfs_repair" - _, err := mounter.Exec.Command("xfs_repair", checkArgs...).CombinedOutput() - if err != nil { - if err == utilexec.ErrExecutableNotFound { - klog.Warningf("'xfs_repair' not found on system; continuing mount without running 'xfs_repair'.") - return nil - } else { - klog.Warningf("Filesystem corruption was detected for %s, running xfs_repair to repair", source) - out, err := mounter.Exec.Command("xfs_repair", args...).CombinedOutput() - if err != nil { - return NewMountError(HasFilesystemErrors, "'xfs_repair' found errors on device %s but could not correct them: %s\n", source, out) - } else { - klog.Infof("Device %s has errors which were corrected by xfs_repair.", source) - return nil - } - } - } - return nil -} - // formatAndMount uses unix utils to format and mount the given disk func (mounter *SafeFormatAndMount) formatAndMountSensitive(source string, target string, fstype string, options []string, sensitiveOptions []string) error { readOnly := false @@ -410,14 +383,7 @@ func (mounter *SafeFormatAndMount) formatAndMountSensitive(source string, target if !readOnly { // Run check tools on the disk to fix repairable issues, only do this for formatted volumes requested as rw. - var err error - switch existingFormat { - case "xfs": - err = mounter.checkAndRepairXfsFilesystem(source) - default: - err = mounter.checkAndRepairFilesystem(source) - } - + err := mounter.checkAndRepairFilesystem(source) if err != nil { return err } diff --git a/safe_format_and_mount_test.go b/safe_format_and_mount_test.go index 782d3da67e7..38c2c8f5b9f 100644 --- a/safe_format_and_mount_test.go +++ b/safe_format_and_mount_test.go @@ -202,44 +202,6 @@ func TestSafeFormatAndMount(t *testing.T) { }, expErrorType: GetDiskFormatFailed, }, - { - description: "Test that 'xfs_repair' is called only once, no need to repair the filesystem", - fstype: "xfs", - execScripts: []ExecArgs{ - {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "DEVNAME=/dev/foo\nTYPE=xfs\n", nil}, - {"xfs_repair", []string{"-n", "/dev/foo"}, "", nil}, - }, - }, - { - description: "Test that 'xfs_repair' is called twice and repair the filesystem", - fstype: "xfs", - execScripts: []ExecArgs{ - {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "DEVNAME=/dev/foo\nTYPE=xfs\n", nil}, - {"xfs_repair", []string{"-n", "/dev/foo"}, "", &testingexec.FakeExitError{Status: 1}}, - {"xfs_repair", []string{"/dev/foo"}, "\ndone\n", nil}, - }, - }, - { - description: "Test that 'xfs_repair' is called twice and repair the filesystem, but mount failed", - fstype: "xfs", - mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'")}, - execScripts: []ExecArgs{ - {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "DEVNAME=/dev/foo\nTYPE=xfs\n", nil}, - {"xfs_repair", []string{"-n", "/dev/foo"}, "", &testingexec.FakeExitError{Status: 1}}, - {"xfs_repair", []string{"/dev/foo"}, "\ndone\n", nil}, - }, - expErrorType: UnknownMountError, - }, - { - description: "Test that 'xfs_repair' is called twice but could not repair the filesystem", - fstype: "xfs", - execScripts: []ExecArgs{ - {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "DEVNAME=/dev/foo\nTYPE=xfs\n", nil}, - {"xfs_repair", []string{"-n", "/dev/foo"}, "", &testingexec.FakeExitError{Status: 1}}, - {"xfs_repair", []string{"/dev/foo"}, "\nAn error occurred\n", &testingexec.FakeExitError{Status: 1}}, - }, - expErrorType: HasFilesystemErrors, - }, { description: "Test that 'blkid' is called and confirms unformatted disk, format fails with sensitive options", fstype: "ext4",