public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_repair: further improvement on secondary superblock search method
@ 2016-05-12 20:38 Bill O'Donnell
  2016-05-23 14:51 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Bill O'Donnell @ 2016-05-12 20:38 UTC (permalink / raw)
  To: xfs

This patch is a further optimization of secondary sb search, in order to
handle non-default geometries. Once again, use a similar method to find
fs geometry as that of xfs_mkfs. Refactor verify_sb(), creating new
sub-function that checks sanity of agblocks and agcount: verify_sb_blocksize().

If verify_sb_blocksize verifies sane paramters, use found values for the sb
search. Otherwise, try search with default values. If these faster methods
both fail, fall back to original brute force slower search.

NOTE: patch series "xfs_repair: improved secondary sb search" must be
applied before applying this patch.
(http://oss.sgi.com/archives/xfs/2016-05/msg00269.html)

Signed-off-by: Bill O'Donnell <billodo@redhat.com>
---
 repair/sb.c | 87 ++++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 52 insertions(+), 35 deletions(-)

diff --git a/repair/sb.c b/repair/sb.c
index 7e4708c..ebe0c60 100644
--- a/repair/sb.c
+++ b/repair/sb.c
@@ -23,12 +23,10 @@
 #include "globals.h"
 #include "protos.h"
 #include "err_protos.h"
+#include "xfs_multidisk.h"
 
 #define BSIZE	(1024 * 1024)
 
-#define XFS_AG_BYTES(bblog)	((long long)BBSIZE << (bblog))
-#define	XFS_AG_MIN_BYTES	((XFS_AG_BYTES(15)))	/* 16 MB */
-
 /*
  * copy the fields of a superblock that are present in primary and
  * secondaries -- preserve fields that are different in the primary.
@@ -85,6 +83,32 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest)
 	memset(source->sb_fname, 0, 12);
 }
 
+int
+verify_sb_blocksize(xfs_sb_t *sb)
+{
+	__uint32_t	bsize;
+	int		i;
+
+	/* check to make sure blocksize is legal 2^N, 9 <= N <= 16 */
+	if (sb->sb_blocksize == 0)
+		return(XR_BAD_BLOCKSIZE);
+
+	bsize = 1;
+
+	for (i = 0; bsize < sb->sb_blocksize &&
+		i < sizeof(sb->sb_blocksize) * NBBY; i++)
+		bsize <<= 1;
+
+	if (i < XFS_MIN_BLOCKSIZE_LOG || i > XFS_MAX_BLOCKSIZE_LOG)
+		return(XR_BAD_BLOCKSIZE);
+
+	/* check sb blocksize field against sb blocklog field */
+	if (i != sb->sb_blocklog)
+		return(XR_BAD_BLOCKLOG);
+
+	return 0;
+}
+
 /*
  * find a secondary superblock, copy it into the sb buffer.
  * start is the point to begin reading BSIZE bytes.
@@ -205,29 +229,34 @@ guess_default_geometry(
 int
 find_secondary_sb(xfs_sb_t *rsb)
 {
-	int		retval;
+	int		retval = 0;
 	__uint64_t	agcount;
 	__uint64_t	agsize;
 	__uint64_t	skip;
 	int		blocklog;
 
 	/*
-	 * Attempt to find secondary sb with a coarse approach.
-	 * Failing that, fallback to a fine-grained approach.
+	 * Attempt to find secondary sb with a coarse approach,
+	 * first trying agblocks and blocksize read from sb, providing
+	 * they're sane.
 	 */
-	blocklog = guess_default_geometry(&agsize, &agcount, &x);
-
-	/*
-	 * use found ag geometry to quickly find secondary sb
-	 */
-	skip = agsize << blocklog;
-	retval = __find_secondary_sb(rsb, skip, skip);
-	if (!retval)  {
-		/*
-		 * fallback: Start at min agsize and scan all blocks
-		 */
-		retval = __find_secondary_sb(rsb, XFS_AG_MIN_BYTES, BSIZE);
+	if (verify_sb_blocksize(rsb) == 0) {
+		skip = rsb->sb_agblocks * rsb->sb_blocksize;
+		if ((skip >= XFS_AG_MIN_BYTES) && (skip <= XFS_AG_MAX_BYTES))
+			retval = __find_secondary_sb(rsb, skip, skip);
 	}
+
+        /* If that failed, retry coarse approach, using default geometry */
+        if (!retval) {
+                blocklog = guess_default_geometry(&agsize, &agcount, &x);
+                skip = agsize << blocklog;
+                retval = __find_secondary_sb(rsb, skip, skip);
+        }
+
+        /* If that failed, fall back to the brute force method */
+        if (!retval)
+                retval = __find_secondary_sb(rsb, XFS_AG_MIN_BYTES, BSIZE);
+
 	return retval;
 }
 
@@ -328,6 +357,7 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb)
 {
 	__uint32_t	bsize;
 	int		i;
+	int		ret;
 
 	/* check magic number and version number */
 
@@ -369,23 +399,10 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb)
 	    !xfs_verify_cksum(sb_buf, sb->sb_sectsize, XFS_SB_CRC_OFF))
 		return XR_BAD_CRC;
 
-	/* check to make sure blocksize is legal 2^N, 9 <= N <= 16 */
-	if (sb->sb_blocksize == 0)
-		return(XR_BAD_BLOCKSIZE);
-
-	bsize = 1;
-
-	for (i = 0; bsize < sb->sb_blocksize &&
-		i < sizeof(sb->sb_blocksize) * NBBY; i++)
-		bsize <<= 1;
-
-	if (i < XFS_MIN_BLOCKSIZE_LOG || i > XFS_MAX_BLOCKSIZE_LOG)
-		return(XR_BAD_BLOCKSIZE);
-
-	/* check sb blocksize field against sb blocklog field */
-
-	if (i != sb->sb_blocklog)
-		return(XR_BAD_BLOCKLOG);
+	/* check to ensure blocksize and blocklog are legal */
+	ret = verify_sb_blocksize(sb);
+	if (ret != 0)
+		return ret;
 
 	/* sanity check ag count, size fields against data size field */
 
-- 
2.5.5

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

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

* Re: [PATCH] xfs_repair: further improvement on secondary superblock search method
  2016-05-12 20:38 [PATCH] xfs_repair: further improvement on secondary superblock search method Bill O'Donnell
@ 2016-05-23 14:51 ` Christoph Hellwig
  2016-05-23 15:27   ` Bill O'Donnell
  2016-05-30  5:37 ` Dave Chinner
  2016-05-31 17:37 ` [PATCH V2] " Bill O'Donnell
  2 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2016-05-23 14:51 UTC (permalink / raw)
  To: Bill O'Donnell; +Cc: xfs

On Thu, May 12, 2016 at 03:38:16PM -0500, Bill O'Donnell wrote:
> +verify_sb_blocksize(xfs_sb_t *sb)
> +{
> +	__uint32_t	bsize;
> +	int		i;
> +
> +	/* check to make sure blocksize is legal 2^N, 9 <= N <= 16 */
> +	if (sb->sb_blocksize == 0)
> +		return(XR_BAD_BLOCKSIZE);
> +
> +	bsize = 1;
> +
> +	for (i = 0; bsize < sb->sb_blocksize &&
> +		i < sizeof(sb->sb_blocksize) * NBBY; i++)
> +		bsize <<= 1;
> +
> +	if (i < XFS_MIN_BLOCKSIZE_LOG || i > XFS_MAX_BLOCKSIZE_LOG)
> +		return(XR_BAD_BLOCKSIZE);
> +
> +	/* check sb blocksize field against sb blocklog field */
> +	if (i != sb->sb_blocklog)
> +		return(XR_BAD_BLOCKLOG);

Couldn't we do this much simpler?

	if (sb->sb_blocksize == 0)
		return XR_BAD_BLOCKSIZE;
	if (sb->sb_blocksize != (1 << sb->sb_blocklog))
		return XR_BAD_BLOCKLOG;
	if (sb->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG ||
	    sb->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG)
		return XR_BAD_BLOCKLOG;

>  	/*
> +	 * Attempt to find secondary sb with a coarse approach,
> +	 * first trying agblocks and blocksize read from sb, providing
> +	 * they're sane.
>  	 */
> +	if (verify_sb_blocksize(rsb) == 0) {
> +		skip = rsb->sb_agblocks * rsb->sb_blocksize;
> +		if ((skip >= XFS_AG_MIN_BYTES) && (skip <= XFS_AG_MAX_BYTES))

no need for the inner braces here.

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

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

* Re: [PATCH] xfs_repair: further improvement on secondary superblock search method
  2016-05-23 14:51 ` Christoph Hellwig
@ 2016-05-23 15:27   ` Bill O'Donnell
  0 siblings, 0 replies; 8+ messages in thread
From: Bill O'Donnell @ 2016-05-23 15:27 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: xfs

On Mon, May 23, 2016 at 07:51:16AM -0700, Christoph Hellwig wrote:
> On Thu, May 12, 2016 at 03:38:16PM -0500, Bill O'Donnell wrote:
> > +verify_sb_blocksize(xfs_sb_t *sb)
> > +{
> > +	__uint32_t	bsize;
> > +	int		i;
> > +
> > +	/* check to make sure blocksize is legal 2^N, 9 <= N <= 16 */
> > +	if (sb->sb_blocksize == 0)
> > +		return(XR_BAD_BLOCKSIZE);
> > +
> > +	bsize = 1;
> > +
> > +	for (i = 0; bsize < sb->sb_blocksize &&
> > +		i < sizeof(sb->sb_blocksize) * NBBY; i++)
> > +		bsize <<= 1;
> > +
> > +	if (i < XFS_MIN_BLOCKSIZE_LOG || i > XFS_MAX_BLOCKSIZE_LOG)
> > +		return(XR_BAD_BLOCKSIZE);
> > +
> > +	/* check sb blocksize field against sb blocklog field */
> > +	if (i != sb->sb_blocklog)
> > +		return(XR_BAD_BLOCKLOG);
> 
> Couldn't we do this much simpler?
> 
> 	if (sb->sb_blocksize == 0)
> 		return XR_BAD_BLOCKSIZE;
> 	if (sb->sb_blocksize != (1 << sb->sb_blocklog))
> 		return XR_BAD_BLOCKLOG;
> 	if (sb->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG ||
> 	    sb->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG)
> 		return XR_BAD_BLOCKLOG;

Makes sense, yes.

> 
> >  	/*
> > +	 * Attempt to find secondary sb with a coarse approach,
> > +	 * first trying agblocks and blocksize read from sb, providing
> > +	 * they're sane.
> >  	 */
> > +	if (verify_sb_blocksize(rsb) == 0) {
> > +		skip = rsb->sb_agblocks * rsb->sb_blocksize;
> > +		if ((skip >= XFS_AG_MIN_BYTES) && (skip <= XFS_AG_MAX_BYTES))
> 
> no need for the inner braces here.

Check.

Thanks for the review!
-Bill

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

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

* Re: [PATCH] xfs_repair: further improvement on secondary superblock search method
  2016-05-12 20:38 [PATCH] xfs_repair: further improvement on secondary superblock search method Bill O'Donnell
  2016-05-23 14:51 ` Christoph Hellwig
@ 2016-05-30  5:37 ` Dave Chinner
  2016-05-30 22:06   ` Eric Sandeen
  2016-05-31 12:10   ` Bill O'Donnell
  2016-05-31 17:37 ` [PATCH V2] " Bill O'Donnell
  2 siblings, 2 replies; 8+ messages in thread
From: Dave Chinner @ 2016-05-30  5:37 UTC (permalink / raw)
  To: Bill O'Donnell; +Cc: xfs

On Thu, May 12, 2016 at 03:38:16PM -0500, Bill O'Donnell wrote:
> This patch is a further optimization of secondary sb search, in order to
> handle non-default geometries. Once again, use a similar method to find
> fs geometry as that of xfs_mkfs. Refactor verify_sb(), creating new
> sub-function that checks sanity of agblocks and agcount: verify_sb_blocksize().
> 
> If verify_sb_blocksize verifies sane paramters, use found values for the sb
> search. Otherwise, try search with default values. If these faster methods
> both fail, fall back to original brute force slower search.
> 
> NOTE: patch series "xfs_repair: improved secondary sb search" must be
> applied before applying this patch.
> (http://oss.sgi.com/archives/xfs/2016-05/msg00269.html)

Either this or one of the above patches is causing xfs/030 on
my xfstests runs to fail with extra output:

xfs/030 4s ... - output mismatch (see /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad)
    --- tests/xfs/030.out       2016-04-06 11:30:45.348477421 +1000
    +++ /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad        2016-05-30 13:06:29.955682633 +1000
    @@ -11,6 +11,8 @@
     bad primary superblock - bad magic number !!!
     
     attempting to find secondary superblock...
    +....
    +attempting to find secondary superblock...
     found candidate secondary superblock...
     verified secondary superblock...
    ...
    (Run 'diff -u tests/xfs/030.out /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad'  to see the entire diff)

Bill, can you please work up a filter or equivalent for xfstests
so that this extra output doesn't cause unnecessary failures?
Something like simply filtering all the "attempting to find
secondary superblock..." and "...." lines from the output would work
just fine - all we really care about is that a secondary sb is found
and verified, not how many steps it takes to find it...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

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

* Re: [PATCH] xfs_repair: further improvement on secondary superblock search method
  2016-05-30  5:37 ` Dave Chinner
@ 2016-05-30 22:06   ` Eric Sandeen
  2016-05-31 12:12     ` Bill O'Donnell
  2016-05-31 12:10   ` Bill O'Donnell
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Sandeen @ 2016-05-30 22:06 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Bill O'Donnell, xfs



> On May 30, 2016, at 12:37 AM, Dave Chinner <david@fromorbit.com> wrote:
> 
>> On Thu, May 12, 2016 at 03:38:16PM -0500, Bill O'Donnell wrote:
>> This patch is a further optimization of secondary sb search, in order to
>> handle non-default geometries. Once again, use a similar method to find
>> fs geometry as that of xfs_mkfs. Refactor verify_sb(), creating new
>> sub-function that checks sanity of agblocks and agcount: verify_sb_blocksize().
>> 
>> If verify_sb_blocksize verifies sane paramters, use found values for the sb
>> search. Otherwise, try search with default values. If these faster methods
>> both fail, fall back to original brute force slower search.
>> 
>> NOTE: patch series "xfs_repair: improved secondary sb search" must be
>> applied before applying this patch.
>> (http://oss.sgi.com/archives/xfs/2016-05/msg00269.html)
> 
> Either this or one of the above patches is causing xfs/030 on
> my xfstests runs to fail with extra output:
> 
> xfs/030 4s ... - output mismatch (see /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad)
>    --- tests/xfs/030.out       2016-04-06 11:30:45.348477421 +1000
>    +++ /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad        2016-05-30 13:06:29.955682633 +1000
>    @@ -11,6 +11,8 @@
>     bad primary superblock - bad magic number !!!
> 
>     attempting to find secondary superblock...
>    +....
>    +attempting to find secondary superblock...

Seems like the best fix is to not print that twice in the first place?

-Eric

>     found candidate secondary superblock...
>     verified secondary superblock...
>    ...
>    (Run 'diff -u tests/xfs/030.out /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad'  to see the entire diff)
> 
> Bill, can you please work up a filter or equivalent for xfstests
> so that this extra output doesn't cause unnecessary failures?
> Something like simply filtering all the "attempting to find
> secondary superblock..." and "...." lines from the output would work
> just fine - all we really care about is that a secondary sb is found
> and verified, not how many steps it takes to find it...
> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
> 

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

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

* Re: [PATCH] xfs_repair: further improvement on secondary superblock search method
  2016-05-30  5:37 ` Dave Chinner
  2016-05-30 22:06   ` Eric Sandeen
@ 2016-05-31 12:10   ` Bill O'Donnell
  1 sibling, 0 replies; 8+ messages in thread
From: Bill O'Donnell @ 2016-05-31 12:10 UTC (permalink / raw)
  To: Dave Chinner; +Cc: xfs

On Mon, May 30, 2016 at 03:37:10PM +1000, Dave Chinner wrote:
> On Thu, May 12, 2016 at 03:38:16PM -0500, Bill O'Donnell wrote:
> > This patch is a further optimization of secondary sb search, in order to
> > handle non-default geometries. Once again, use a similar method to find
> > fs geometry as that of xfs_mkfs. Refactor verify_sb(), creating new
> > sub-function that checks sanity of agblocks and agcount: verify_sb_blocksize().
> > 
> > If verify_sb_blocksize verifies sane paramters, use found values for the sb
> > search. Otherwise, try search with default values. If these faster methods
> > both fail, fall back to original brute force slower search.
> > 
> > NOTE: patch series "xfs_repair: improved secondary sb search" must be
> > applied before applying this patch.
> > (http://oss.sgi.com/archives/xfs/2016-05/msg00269.html)
> 
> Either this or one of the above patches is causing xfs/030 on
> my xfstests runs to fail with extra output:
> 
> xfs/030 4s ... - output mismatch (see /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad)
>     --- tests/xfs/030.out       2016-04-06 11:30:45.348477421 +1000
>     +++ /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad        2016-05-30 13:06:29.955682633 +1000
>     @@ -11,6 +11,8 @@
>      bad primary superblock - bad magic number !!!
>      
>      attempting to find secondary superblock...
>     +....
>     +attempting to find secondary superblock...
>      found candidate secondary superblock...
>      verified secondary superblock...
>     ...
>     (Run 'diff -u tests/xfs/030.out /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad'  to see the entire diff)
> 
> Bill, can you please work up a filter or equivalent for xfstests
> so that this extra output doesn't cause unnecessary failures?
> Something like simply filtering all the "attempting to find
> secondary superblock..." and "...." lines from the output would work
> just fine - all we really care about is that a secondary sb is found
> and verified, not how many steps it takes to find it...

Yep. Will do.
Thanks-
Bill

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

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

* Re: [PATCH] xfs_repair: further improvement on secondary superblock search method
  2016-05-30 22:06   ` Eric Sandeen
@ 2016-05-31 12:12     ` Bill O'Donnell
  0 siblings, 0 replies; 8+ messages in thread
From: Bill O'Donnell @ 2016-05-31 12:12 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: xfs

On Mon, May 30, 2016 at 05:06:25PM -0500, Eric Sandeen wrote:
> 
> 
> > On May 30, 2016, at 12:37 AM, Dave Chinner <david@fromorbit.com> wrote:
> > 
> >> On Thu, May 12, 2016 at 03:38:16PM -0500, Bill O'Donnell wrote:
> >> This patch is a further optimization of secondary sb search, in order to
> >> handle non-default geometries. Once again, use a similar method to find
> >> fs geometry as that of xfs_mkfs. Refactor verify_sb(), creating new
> >> sub-function that checks sanity of agblocks and agcount: verify_sb_blocksize().
> >> 
> >> If verify_sb_blocksize verifies sane paramters, use found values for the sb
> >> search. Otherwise, try search with default values. If these faster methods
> >> both fail, fall back to original brute force slower search.
> >> 
> >> NOTE: patch series "xfs_repair: improved secondary sb search" must be
> >> applied before applying this patch.
> >> (http://oss.sgi.com/archives/xfs/2016-05/msg00269.html)
> > 
> > Either this or one of the above patches is causing xfs/030 on
> > my xfstests runs to fail with extra output:
> > 
> > xfs/030 4s ... - output mismatch (see /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad)
> >    --- tests/xfs/030.out       2016-04-06 11:30:45.348477421 +1000
> >    +++ /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad        2016-05-30 13:06:29.955682633 +1000
> >    @@ -11,6 +11,8 @@
> >     bad primary superblock - bad magic number !!!
> > 
> >     attempting to find secondary superblock...
> >    +....
> >    +attempting to find secondary superblock...
> 
> Seems like the best fix is to not print that twice in the first place?

The double print of that did make me wonder. I agree we should
only print it once.

Thanks-
Bill

> 
> -Eric
> 
> >     found candidate secondary superblock...
> >     verified secondary superblock...
> >    ...
> >    (Run 'diff -u tests/xfs/030.out /home/dave/src/xfstests-dev/results//xfs/xfs/030.out.bad'  to see the entire diff)
> > 
> > Bill, can you please work up a filter or equivalent for xfstests
> > so that this extra output doesn't cause unnecessary failures?
> > Something like simply filtering all the "attempting to find
> > secondary superblock..." and "...." lines from the output would work
> > just fine - all we really care about is that a secondary sb is found
> > and verified, not how many steps it takes to find it...
> > 
> > Cheers,
> > 
> > Dave.
> > -- 
> > Dave Chinner
> > david@fromorbit.com
> > 
> > _______________________________________________
> > xfs mailing list
> > xfs@oss.sgi.com
> > http://oss.sgi.com/mailman/listinfo/xfs
> > 
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs

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

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

* [PATCH V2] xfs_repair: further improvement on secondary superblock search method
  2016-05-12 20:38 [PATCH] xfs_repair: further improvement on secondary superblock search method Bill O'Donnell
  2016-05-23 14:51 ` Christoph Hellwig
  2016-05-30  5:37 ` Dave Chinner
@ 2016-05-31 17:37 ` Bill O'Donnell
  2 siblings, 0 replies; 8+ messages in thread
From: Bill O'Donnell @ 2016-05-31 17:37 UTC (permalink / raw)
  To: xfs

This patch is a further optimization of secondary sb search, in order to
handle non-default geometries. Once again, use a similar method to find
fs geometry as that of xfs_mkfs. Refactor verify_sb(), creating new
sub-function that checks sanity of agblocks and agcount: verify_sb_blocksize().

If verify_sb_blocksize verifies sane paramters, use found values for the sb
search. Otherwise, try search with default values. If these faster methods
both fail, fall back to original brute force slower search.

NOTE: patch series "xfs_repair: improved secondary sb search" must be
applied before applying this patch.
(http://oss.sgi.com/archives/xfs/2016-05/msg00269.html)

v2: simplify verify_sb_blocksize function.
    remove unneeded parentheses.
    remove redundant warns about attempt to find secondary sb.

Signed-off-by: Bill O'Donnell <billodo@redhat.com>
---
 repair/sb.c | 78 +++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 42 insertions(+), 36 deletions(-)

diff --git a/repair/sb.c b/repair/sb.c
index 7e4708c..3965953 100644
--- a/repair/sb.c
+++ b/repair/sb.c
@@ -23,12 +23,10 @@
 #include "globals.h"
 #include "protos.h"
 #include "err_protos.h"
+#include "xfs_multidisk.h"
 
 #define BSIZE	(1024 * 1024)
 
-#define XFS_AG_BYTES(bblog)	((long long)BBSIZE << (bblog))
-#define	XFS_AG_MIN_BYTES	((XFS_AG_BYTES(15)))	/* 16 MB */
-
 /*
  * copy the fields of a superblock that are present in primary and
  * secondaries -- preserve fields that are different in the primary.
@@ -85,6 +83,21 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest)
 	memset(source->sb_fname, 0, 12);
 }
 
+int
+verify_sb_blocksize(xfs_sb_t *sb)
+{
+	/* check to make sure blocksize is legal 2^N, 9 <= N <= 16 */
+	if (sb->sb_blocksize == 0)
+		return XR_BAD_BLOCKSIZE;
+	if (sb->sb_blocksize != (1 << sb->sb_blocklog))
+		return XR_BAD_BLOCKLOG;
+	if (sb->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG ||
+	    sb->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG)
+		return XR_BAD_BLOCKLOG;
+
+	return 0;
+}
+
 /*
  * find a secondary superblock, copy it into the sb buffer.
  * start is the point to begin reading BSIZE bytes.
@@ -106,8 +119,6 @@ __find_secondary_sb(
 	int		retval;
 	int		bsize;
 
-	do_warn(_("\nattempting to find secondary superblock...\n"));
-
 	sb = (xfs_sb_t *)memalign(libxfs_device_alignment(), BSIZE);
 	if (!sb) {
 		do_error(
@@ -205,29 +216,36 @@ guess_default_geometry(
 int
 find_secondary_sb(xfs_sb_t *rsb)
 {
-	int		retval;
+	int		retval = 0;
 	__uint64_t	agcount;
 	__uint64_t	agsize;
 	__uint64_t	skip;
 	int		blocklog;
 
 	/*
-	 * Attempt to find secondary sb with a coarse approach.
-	 * Failing that, fallback to a fine-grained approach.
+	 * Attempt to find secondary sb with a coarse approach,
+	 * first trying agblocks and blocksize read from sb, providing
+	 * they're sane.
 	 */
-	blocklog = guess_default_geometry(&agsize, &agcount, &x);
+	do_warn(_("\nattempting to find secondary superblock...\n"));
 
-	/*
-	 * use found ag geometry to quickly find secondary sb
-	 */
-	skip = agsize << blocklog;
-	retval = __find_secondary_sb(rsb, skip, skip);
-	if (!retval)  {
-		/*
-		 * fallback: Start at min agsize and scan all blocks
-		 */
-		retval = __find_secondary_sb(rsb, XFS_AG_MIN_BYTES, BSIZE);
+	if (verify_sb_blocksize(rsb) == 0) {
+		skip = rsb->sb_agblocks * rsb->sb_blocksize;
+		if (skip >= XFS_AG_MIN_BYTES && skip <= XFS_AG_MAX_BYTES)
+			retval = __find_secondary_sb(rsb, skip, skip);
 	}
+
+        /* If that failed, retry coarse approach, using default geometry */
+        if (!retval) {
+                blocklog = guess_default_geometry(&agsize, &agcount, &x);
+                skip = agsize << blocklog;
+                retval = __find_secondary_sb(rsb, skip, skip);
+        }
+
+        /* If that failed, fall back to the brute force method */
+        if (!retval)
+                retval = __find_secondary_sb(rsb, XFS_AG_MIN_BYTES, BSIZE);
+
 	return retval;
 }
 
@@ -328,6 +346,7 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb)
 {
 	__uint32_t	bsize;
 	int		i;
+	int		ret;
 
 	/* check magic number and version number */
 
@@ -369,23 +388,10 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb)
 	    !xfs_verify_cksum(sb_buf, sb->sb_sectsize, XFS_SB_CRC_OFF))
 		return XR_BAD_CRC;
 
-	/* check to make sure blocksize is legal 2^N, 9 <= N <= 16 */
-	if (sb->sb_blocksize == 0)
-		return(XR_BAD_BLOCKSIZE);
-
-	bsize = 1;
-
-	for (i = 0; bsize < sb->sb_blocksize &&
-		i < sizeof(sb->sb_blocksize) * NBBY; i++)
-		bsize <<= 1;
-
-	if (i < XFS_MIN_BLOCKSIZE_LOG || i > XFS_MAX_BLOCKSIZE_LOG)
-		return(XR_BAD_BLOCKSIZE);
-
-	/* check sb blocksize field against sb blocklog field */
-
-	if (i != sb->sb_blocklog)
-		return(XR_BAD_BLOCKLOG);
+	/* check to ensure blocksize and blocklog are legal */
+	ret = verify_sb_blocksize(sb);
+	if (ret != 0)
+		return ret;
 
 	/* sanity check ag count, size fields against data size field */
 
-- 
2.5.5

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

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

end of thread, other threads:[~2016-05-31 17:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-12 20:38 [PATCH] xfs_repair: further improvement on secondary superblock search method Bill O'Donnell
2016-05-23 14:51 ` Christoph Hellwig
2016-05-23 15:27   ` Bill O'Donnell
2016-05-30  5:37 ` Dave Chinner
2016-05-30 22:06   ` Eric Sandeen
2016-05-31 12:12     ` Bill O'Donnell
2016-05-31 12:10   ` Bill O'Donnell
2016-05-31 17:37 ` [PATCH V2] " Bill O'Donnell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox