All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_repair: open filesystem device exclusively
@ 2009-03-09  3:22 Nathaniel W. Turner
  2009-03-09  3:50 ` Nathaniel W. Turner
  0 siblings, 1 reply; 6+ messages in thread
From: Nathaniel W. Turner @ 2009-03-09  3:22 UTC (permalink / raw)
  To: xfs

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

Signed-off-by: Nathaniel W. Turner <nate@houseofnate.net>
---
 repair/init.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/repair/init.c b/repair/init.c
index 8e508c4..3d88b8b 100644
--- a/repair/init.c
+++ b/repair/init.c
@@ -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"));
-- 
1.5.6.3

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

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] xfs_repair: open filesystem device exclusively
  2009-03-09  3:22 [PATCH] xfs_repair: open filesystem device exclusively Nathaniel W. Turner
@ 2009-03-09  3:50 ` Nathaniel W. Turner
  2009-03-16 21:23   ` Christoph Hellwig
  2009-05-07  2:55   ` Eric Sandeen
  0 siblings, 2 replies; 6+ messages in thread
From: Nathaniel W. Turner @ 2009-03-09  3:50 UTC (permalink / raw)
  To: xfs

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

Signed-off-by: Nathaniel W. Turner <nate@houseofnate.net>
---
 repair/init.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/repair/init.c b/repair/init.c
index 8e508c4..7e5052c 100644
--- a/repair/init.c
+++ b/repair/init.c
@@ -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"));

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

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] xfs_repair: open filesystem device exclusively
  2009-03-09  3:50 ` Nathaniel W. Turner
@ 2009-03-16 21:23   ` Christoph Hellwig
  2009-05-07  2:46     ` Nathaniel W. Turner
  2009-05-07  2:55   ` Eric Sandeen
  1 sibling, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2009-03-16 21:23 UTC (permalink / raw)
  To: Nathaniel W. Turner; +Cc: xfs

On Sun, Mar 08, 2009 at 11:50:02PM -0400, Nathaniel W. Turner wrote:
> (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>
> ---
>  repair/init.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/repair/init.c b/repair/init.c
> index 8e508c4..7e5052c 100644
> --- a/repair/init.c
> +++ b/repair/init.c
> @@ -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
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] xfs_repair: open filesystem device exclusively
  2009-03-16 21:23   ` Christoph Hellwig
@ 2009-05-07  2:46     ` Nathaniel W. Turner
  2009-05-10 18:03       ` Christoph Hellwig
  0 siblings, 1 reply; 6+ messages in thread
From: Nathaniel W. Turner @ 2009-05-07  2:46 UTC (permalink / raw)
  To: xfs


[-- Attachment #1.1: Type: text/plain, Size: 1437 bytes --]

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

Christoph Hellwig wrote:
> On Sun, Mar 08, 2009 at 11:50:02PM -0400, Nathaniel W. Turner wrote:
>   
>> (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>
>> ---
>>  repair/init.c |    2 ++
>>  1 files changed, 2 insertions(+), 0 deletions(-)
>>
>> diff --git a/repair/init.c b/repair/init.c
>> index 8e508c4..7e5052c 100644
>> --- a/repair/init.c
>> +++ b/repair/init.c
>> @@ -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
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
>   

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


[-- Attachment #1.2: Type: text/html, Size: 2127 bytes --]

[-- Attachment #2: Type: text/plain, Size: 121 bytes --]

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] xfs_repair: open filesystem device exclusively
  2009-03-09  3:50 ` Nathaniel W. Turner
  2009-03-16 21:23   ` Christoph Hellwig
@ 2009-05-07  2:55   ` Eric Sandeen
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Sandeen @ 2009-05-07  2:55 UTC (permalink / raw)
  To: Nathaniel W. Turner; +Cc: xfs

Nathaniel W. Turner wrote:
> 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.

...

> Signed-off-by: Nathaniel W. Turner <nate@houseofnate.net>

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

-Eric

> ---
>  repair/init.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/repair/init.c b/repair/init.c
> index 8e508c4..7e5052c 100644
> --- a/repair/init.c
> +++ b/repair/init.c
> @@ -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
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] xfs_repair: open filesystem device exclusively
  2009-05-07  2:46     ` Nathaniel W. Turner
@ 2009-05-10 18:03       ` Christoph Hellwig
  0 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2009-05-10 18:03 UTC (permalink / raw)
  To: Nathaniel W. Turner; +Cc: xfs

On Wed, May 06, 2009 at 10:46:20PM -0400, Nathaniel W. Turner wrote:
> ...just a friendly reminder to look at this again now that 3.0.1 is out.


Thanks for the heads-up.  I've put the patch in.

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-05-10 18:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-09  3:22 [PATCH] xfs_repair: open filesystem device exclusively Nathaniel W. Turner
2009-03-09  3:50 ` Nathaniel W. Turner
2009-03-16 21:23   ` Christoph Hellwig
2009-05-07  2:46     ` Nathaniel W. Turner
2009-05-10 18:03       ` Christoph Hellwig
2009-05-07  2:55   ` Eric Sandeen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.