Skip to contentSkip to conversation

xfs_repair: open filesystem device exclusively

PATCH In review Nathaniel W. Turner 3 participants 6 messages Mar 9, 2009 – May 10, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_repair: open filesystem device exclusively

Hi folks,

I'm sure there is a better way to fix this, but without this patch, 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 seems like it's probably not ideal, so this patch just modifies xfs_repair to open the filesystem device 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 should at least make things a bit safer.)

---
 repair/init.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
repair/init.c +2 -0
index 8e508c4..3d88b8b 100644
@@ -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"));
Signature · 10 lines
1.5.6.3

-- 
Nathaniel W. Turner
http://houseofnate.net/

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw

I forgot to mention that this is against xfsprogs 3.0.0. Also, the indentation was a bit messed up on that last post, so here's the patch again (all 2 lines of it):

----

I'm sure there is a better way to fix this, but without this patch, 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 seems like it's probably not ideal, so this patch just modifies xfs_repair to open the filesystem device 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.)

---
 repair/init.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
repair/init.c +2 -0
index 8e508c4..7e5052c 100644
@@ -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"));
Signature · 7 lines
Nathaniel W. Turner
http://houseofnate.net/

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw
Quoted 15 lines · Nathaniel W. Turner

(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.)

---
 repair/init.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
repair/init.c +0 -0
index 8e508c4..7e5052c 100644

repair/init.c xfs_init(libxfs_init_t *args) · line 146

Quoted 5 lines
repair/init.c +2 -0
@@ -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;

Given that we skip it for -d and -n this is fine with me.

I think we might want to delay this change in the way xfs_repair operates until after we get a 3.0.1 release out with all the build system fixes (hopefully really soon)

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw

...just a friendly reminder to look at this again now that 3.0.1 is out.

Quoted 35 lines · Christoph Hellwig
Quoted 15 lines · Nathaniel W. Turner

(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.)

---
 repair/init.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
repair/init.c +0 -0
index 8e508c4..7e5052c 100644

repair/init.c xfs_init(libxfs_init_t *args) · line 147

Quoted 6 lines
repair/init.c +2 -0
@@ -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;
 

Given that we skip it for -d and -n this is fine with me.

I think we might want to delay this change in the way xfs_repair operates until after we get a 3.0.1 release out with all the build system fixes (hopefully really soon)

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Signature · 2 lines
Nathaniel W. Turner
http://houseofnate.net/

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw
In reply to Nathaniel W. Turner
Quoted 14 lines · Nathaniel W. Turner

I forgot to mention that this is against xfsprogs 3.0.0. Also, the indentation was a bit messed up on that last post, so here's the patch again (all 2 lines of it):

----

I'm sure there is a better way to fix this, but without this patch, 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 seems like it's probably not ideal, so this patch just modifies xfs_repair to open the filesystem device with O_EXCL unless it was invoked in "no modify" or "dangerous" mode.

...

Quoted 1 line

Christoph already looked I guess, but I'll give this my thumbs-up too :)

-Eric

Quoted 10 lines
---
 repair/init.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
repair/init.c +0 -0
index 8e508c4..7e5052c 100644

repair/init.c xfs_init(libxfs_init_t *args) · line 149

Quoted 8 lines
repair/init.c +2 -0
@@ -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"));

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs