]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: automatically enable -f (file) mode when needed
authorEric Sandeen <sandeen@sandeen.net>
Tue, 23 Jun 2015 01:37:38 +0000 (11:37 +1000)
committerDave Chinner <david@fromorbit.com>
Tue, 23 Jun 2015 01:37:38 +0000 (11:37 +1000)
If we specify "-f" to xfs_repair, it recognizes that it's working
on a file, and if the underlying filesystem sector size differs
such that direct IO won't work, it disables direct IO.

It's odd, though, that we'd need to specify this, and the failure
is non-obvious:

# xfs_repair /mnt/test/foo.img
Phase 1 - find and verify superblock...
xfs_repair: read failed: Invalid argument

I see no advantage to requiring the administrator to jump through
this hoop; why not just detect that it's a file, and move on?

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
repair/xfs_repair.c

index 11a6069aca71af5f7a006023c7f26a35a1994152..8cb06b35a50849b28c12e4bfb587b532a7bcd2d5 100644 (file)
@@ -573,6 +573,18 @@ main(int argc, char **argv)
                exit(1);
        }
 
+       /* -f forces this, but let's be nice and autodetect it, as well. */
+       if (!isa_file) {
+               int             fd = libxfs_device_to_fd(x.ddev);
+               struct stat64   statbuf;
+
+               if (fstat64(fd, &statbuf) < 0)
+                       do_warn(_("%s: couldn't stat \"%s\"\n"),
+                               progname, fs_name);
+               else if (S_ISREG(statbuf.st_mode))
+                       isa_file = 1;
+       }
+
        /*
         * if the sector size of the filesystem we are trying to repair is
         * smaller than that of the underlying filesystem (i.e. we are repairing