diff --git a/mount/mount_linux.go b/mount/mount_linux.go index 2d24af91..384e92ae 100644 --- a/mount/mount_linux.go +++ b/mount/mount_linux.go @@ -43,6 +43,10 @@ const ( fsckErrorsCorrected = 1 // 'fsck' found errors but exited without correcting them fsckErrorsUncorrected = 4 + // 'xfs_repair' found errors but exited without correcting them + xfsRepairErrorsUncorrected = 1 + // 'xfs_repair' was unable to proceed due to a dirty log + xfsRepairErrorsDirtyLogs = 2 ) // Mounter provides the default implementation of mount.Interface @@ -330,12 +334,25 @@ func (mounter *SafeFormatAndMount) checkAndRepairXfsFilesystem(source string) er } 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 { + if err == nil { klog.Infof("Device %s has errors which were corrected by xfs_repair.", source) return nil } + e, isExitError := err.(utilexec.ExitError) + if !isExitError { + return NewMountError(HasFilesystemErrors, "failed to run 'xfs_repair' on device %s: %v\n", source, err) + + } + switch e.ExitStatus() { + case xfsRepairErrorsUncorrected: + return NewMountError(HasFilesystemErrors, "'xfs_repair' found errors on device %s but could not correct them: %s\n", source, string(out)) + case xfsRepairErrorsDirtyLogs: + // mark the a dirty log issue as a warning, do you replay it by default. + klog.Warningf("A dirty log is detected on this xfs disk.") + return nil + default: + return NewMountError(HasFilesystemErrors, "'xfs_repair' found errors on device %s but could not correct them: %s\n", source, string(out)) + } } } return nil diff --git a/mount/safe_format_and_mount_test.go b/mount/safe_format_and_mount_test.go index 782d3da6..5c2f71a3 100644 --- a/mount/safe_format_and_mount_test.go +++ b/mount/safe_format_and_mount_test.go @@ -240,6 +240,15 @@ func TestSafeFormatAndMount(t *testing.T) { }, expErrorType: HasFilesystemErrors, }, + { + description: "Test that 'xfs_repair' is called twice and report a dirty log (return 2)", + 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: 2}}, + }, + }, { description: "Test that 'blkid' is called and confirms unformatted disk, format fails with sensitive options", fstype: "ext4",