]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: open filesystem device exclusively
authorNathaniel W. Turner <nate@houseofnate.net>
Sun, 10 May 2009 18:02:30 +0000 (20:02 +0200)
committerChristoph Hellwig <hch@brick.lst.de>
Sun, 10 May 2009 18:02:30 +0000 (20:02 +0200)
Currently two xfs_repair processes will happily operate on the same
filesystem device at the same time.  It is also possible to mount a
filesystem that is in the process of being repaired.

This patch modifies xfs_repair to open the filesystem devices with
O_EXCL unless it was invoked in "no modify" or "dangerous" mode.

The net effect is that a 2nd xfs_repair will now safely fail with
"xfs_repair: cannot open /dev/foo: Device or resource busy", and a mount
command will fail with (the slightly cryptic) "mount: /dev/foo already
mounted or /mountpoint busy".

Note that this has no effect if the filesystem is stored in a regular
file instead of on a block device.

(Error messages could probably be improved to be more user-friendly in
this new failure case, and it probably wouldn't hurt to add a BLKROGET
ioctl to check for read-only block devices with read-write permissions,
but this does the job for me.)

Signed-off-by: Nathaniel W. Turner <nate@houseofnate.net>
Signed-off-by: Christoph Hellwig <hch@lst.de>
repair/init.c

index 8e508c4e84a98ec89e0d79d76f7f0cc5b480438d..7e5052c48acdd675b92f8f01b13b5deb0e7d0431 100644 (file)
@@ -142,6 +142,8 @@ xfs_init(libxfs_init_t *args)
                args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE);
        else if (dangerously)
                args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY);
+       else
+               args->isreadonly = LIBXFS_EXCLUSIVELY;
 
        if (!libxfs_init(args))
                do_error(_("couldn't initialize XFS library\n"));