Skip to contentSkip to conversation

xfs_repair: new secondary superblock search method] xfs_repair: new secondary superblock search method

PATCH Superseded Bill O'Donnell 2 participants 4 messages Feb 10, 2016 Kbuild

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 xfs_repair: new secondary superblock search method] xfs_repair: new secondary superblock search method

Optimize secondary sb search, using similar method to find fs geometry as that of xfs_mkfs. If this faster method fails in finding a secondary sb, fall back to original brute force slower search.

---
 Makefile           |  2 +-
 include/libxcmd.h  |  4 +++-
 libxcmd/topology.c | 35 ++++++++++++++++++++++++++++----
 repair/Makefile    |  4 ++--
 repair/sb.c        | 58 ++++++++++++++++++++++++++++++++++++++++++++----------
 5 files changed, 85 insertions(+), 18 deletions(-)
Makefile +1 -1
index fca0a42..1d60d9c 100644
@@ -80,7 +80,7 @@ fsr: libhandle
 growfs: libxcmd
 io: libxcmd libhandle
 quota: libxcmd
-repair: libxlog
+repair: libxlog libxcmd
 copy: libxlog
 
 ifeq ($(HAVE_BUILDDEFS), yes)
include/libxcmd.h +3 -1
index df7046e..b140adb 100644
@@ -50,6 +50,8 @@ extern int
 check_overwrite(
 	char		*device);
 
-
+extern int guess_default_geometry(__uint64_t *agsize,
+				  __uint64_t *agcount,
+				  libxfs_init_t x);
 
 #endif	/* __LIBXCMD_H__ */
libxcmd/topology.c +31 -4
index 0eeea28..b98d9b9 100644
@@ -192,7 +192,8 @@ out:
 	return ret;
 }
 
-static void blkid_get_topology(
+static void
+blkid_get_topology(
 	const char	*device,
 	int		*sunit,
 	int		*swidth,
@@ -284,7 +285,8 @@ check_overwrite(
 	return 1;
 }
 
-static void blkid_get_topology(
+static void
+blkid_get_topology(
 	const char	*device,
 	int		*sunit,
 	int		*swidth,
@@ -302,8 +304,8 @@ static void blkid_get_topology(
 
 #endif /* ENABLE_BLKID */
 
-
-void get_topology(
+void
+get_topology(
 	libxfs_init_t		*xi,
 	struct fs_topology	*ft,
 	int			force_overwrite)
@@ -346,3 +348,28 @@ void get_topology(
 				   &lsectorsize, &psectorsize, force_overwrite);
 	}
 }
+
+int
+guess_default_geometry(__uint64_t *agsize, __uint64_t *agcount,
+		       libxfs_init_t x)
+{
+	struct fs_topology ft;
+	int blocklog;
+	__uint64_t	dblocks;
+	int		multidisk;
+
+	memset(&ft, 0, sizeof(ft));
+	get_topology(&x, &ft, 1);
+
+	/*
+	 * get geometry from get_topology result.
+	 * Use default block size (2^12)
+	 */
+	blocklog = 12;
+	multidisk = ft.dswidth | ft.dsunit;
+	dblocks = x.dsize >> (blocklog - BBSHIFT);
+	calc_default_ag_geometry(blocklog, dblocks, multidisk,
+				 agsize, agcount);
+
+	return blocklog;
+}
repair/Makefile +2 -2
index 251722b..d24ab1f 100644
@@ -20,8 +20,8 @@ CFILES = agheader.c attr_repair.c avl.c avl64.c bmap.c btree.c \
 	progress.c prefetch.c rt.c sb.c scan.c threads.c \
 	versions.c xfs_repair.c
 
-LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
-LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG)
+LLDLIBS = $(LIBBLKID) $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) $(LIBXCMD)
+LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBXCMD)
 LLDFLAGS = -static-libtool-libs
 
 default: depend $(LTCOMMAND)
repair/sb.c +48 -10

104 lines not on this page · raw message

Signature · 6 lines
2.5.0

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 77 lines · Bill O'Donnell

Optimize secondary sb search, using similar method to find fs geometry as that of xfs_mkfs. If this faster method fails in finding a secondary sb, fall back to original brute force slower search.

---
 Makefile           |  2 +-
 include/libxcmd.h  |  4 +++-
 libxcmd/topology.c | 35 ++++++++++++++++++++++++++++----
 repair/Makefile    |  4 ++--
 repair/sb.c        | 58 ++++++++++++++++++++++++++++++++++++++++++++----------
 5 files changed, 85 insertions(+), 18 deletions(-)
Makefile +1 -1
index fca0a42..1d60d9c 100644
@@ -80,7 +80,7 @@ fsr: libhandle
 growfs: libxcmd
 io: libxcmd libhandle
 quota: libxcmd
-repair: libxlog
+repair: libxlog libxcmd
 copy: libxlog
 
 ifeq ($(HAVE_BUILDDEFS), yes)
include/libxcmd.h +3 -1
index df7046e..b140adb 100644
@@ -50,6 +50,8 @@ extern int
 check_overwrite(
 	char		*device);
 
-
+extern int guess_default_geometry(__uint64_t *agsize,
+				  __uint64_t *agcount,
+				  libxfs_init_t x);
 
 #endif	/* __LIBXCMD_H__ */
libxcmd/topology.c +6 -4
index 0eeea28..b98d9b9 100644
@@ -192,7 +192,8 @@ out:
 	return ret;
 }
 
-static void blkid_get_topology(
+static void
+blkid_get_topology(
 	const char	*device,
 	int		*sunit,
 	int		*swidth,
@@ -284,7 +285,8 @@ check_overwrite(
 	return 1;
 }
 
-static void blkid_get_topology(
+static void
+blkid_get_topology(
 	const char	*device,
 	int		*sunit,
 	int		*swidth,
@@ -302,8 +304,8 @@ static void blkid_get_topology(
 
 #endif /* ENABLE_BLKID */
 
-
-void get_topology(
+void
+get_topology(
 	libxfs_init_t		*xi,
 	struct fs_topology	*ft,
 	int			force_overwrite)

libxcmd/topology.c void get_topology( · line 357

Quoted 10 lines
libxcmd/topology.c +7 -0
@@ -346,3 +348,28 @@ void get_topology(
 				   &lsectorsize, &psectorsize, force_overwrite);
 	}
 }
+
+int
+guess_default_geometry(__uint64_t *agsize, __uint64_t *agcount,
+		       libxfs_init_t x)
+{
+	struct fs_topology ft;
+	int blocklog;

When in Rome: :)

int
guess_default_geometry(

	__uint64_t	*agsize,
	__uint64_t	*agcount,
	libxfs_init_t	x)

{
...

(sorry, forgot to mention that last time, but other functions in the file are laid out this way; it is easier to read)

Quoted 38 lines
libxcmd/topology.c +18 -0
+	__uint64_t	dblocks;
+	int		multidisk;
+
+	memset(&ft, 0, sizeof(ft));
+	get_topology(&x, &ft, 1);
+
+	/*
+	 * get geometry from get_topology result.
+	 * Use default block size (2^12)
+	 */
+	blocklog = 12;
+	multidisk = ft.dswidth | ft.dsunit;
+	dblocks = x.dsize >> (blocklog - BBSHIFT);
+	calc_default_ag_geometry(blocklog, dblocks, multidisk,
+				 agsize, agcount);
+
+	return blocklog;
+}
repair/Makefile +2 -2
index 251722b..d24ab1f 100644
@@ -20,8 +20,8 @@ CFILES = agheader.c attr_repair.c avl.c avl64.c bmap.c btree.c \
 	progress.c prefetch.c rt.c sb.c scan.c threads.c \
 	versions.c xfs_repair.c
 
-LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
-LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG)
+LLDLIBS = $(LIBBLKID) $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) $(LIBXCMD)
+LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBXCMD)
 LLDFLAGS = -static-libtool-libs
 
 default: depend $(LTCOMMAND)
repair/sb.c +0 -0
index 4eef14a..8bc246e 100644

repair/sb.c line 25

Quoted 4 lines
repair/sb.c +1 -0
@@ -22,6 +22,7 @@
 #include "globals.h"
 #include "protos.h"
 #include "err_protos.h"
+#include "libxcmd.h"

Nitpick, we usually include that right after libxfs.h.

repair/sb.c copy_sb(xfs_sb_t *source, xfs_sb_t *dest) · line 92

Quoted 11 lines
repair/sb.c +3 -1
 #define BSIZE	(1024 * 1024)
 
@@ -85,10 +86,11 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest)
 }
 
 /*
- * find a secondary superblock, copy it into the sb buffer
+ * find a secondary superblock, copy it into the sb buffer.
+ * skipsize units is bytes, it contains either the agsize in bytes
+ * (if known), or the minimum agsize in bytes if agsize unknown.
  */

Ok, so this is a little confused. There are actually 3 relevant parameters here:

1) The place to start reading
2) The number of bytes to read at that point
3) How far to seek forward for the next read

In the old world, it's:

1) XFS_MIN_AG_BYTES
2) BSIZE (1MB)
3) BSIZE (i.e. it does sequential reads)

In the new world, it's:

1) the guessed AG size (skipsize?)
2) BSIZE (more than we need, but not expensive, so leave it)
3) the guessed AG size (skipsize)

You really have 2 different pieces of info: Where to do the first read, and how far forward to skip for the next read. I don't think you can convey that with a single argument, "skipsize."

repair/sb.c copy_sb(xfs_sb_t *source, xfs_sb_t *dest) · line 93

Quoted 3 lines
repair/sb.c +1 -2
-int
-find_secondary_sb(xfs_sb_t *rsb)
+static int __find_secondary_sb(xfs_sb_t *rsb, __uint64_t skipsize)

better to format as:

static int
__find_secondary_sb(

	xfs_sb_t	*rsb,
	__uint64_t	skipsize)

{

but ...

Quoted 17 lines
repair/sb.c +1 -1
 {
 	xfs_off_t	off;
 	xfs_sb_t	*sb;
@@ -99,9 +101,9 @@ find_secondary_sb(xfs_sb_t *rsb)
 	int		dirty;
 	int		retval;
 	int		bsize;
+	int		readsize;
 
 	do_warn(_("\nattempting to find secondary superblock...\n"));
-
 	sb = (xfs_sb_t *)memalign(libxfs_device_alignment(), BSIZE);
 	if (!sb) {
 		do_error(
@@ -113,13 +115,16 @@ find_secondary_sb(xfs_sb_t *rsb)
 	retval = 0;
 	dirty = 0;

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 122

Quoted 10 lines
repair/sb.c +2 -2
 	bsize = 0;
+	readsize = 0;
 
 	/*
 	 * skip first sector since we know that's bad
 	 */
-	for (done = 0, off = XFS_AG_MIN_BYTES; !done ; off += bsize)  {
+	for (done = 0, off = skipsize; !done ; off += readsize)  {
 		/*
-		 * read disk 1 MByte at a time.

we are actually still doing that, read(x.dfd, sb, BSIZE), so I'd leave the comment...

Quoted 9 lines
repair/sb.c +3 -0
+		 * read disk using readsize interval
+		 * (either the bytecount of actual agsize or bsize if
+		 * agsize undetermined.)
 
 
 		 */
repair/sb.c +0 -0
 		if (lseek64(x.dfd, off, SEEK_SET) != off)  {
 			done = 1;

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 139

Quoted 8 lines
repair/sb.c +4 -1
@@ -128,9 +133,13 @@ find_secondary_sb(xfs_sb_t *rsb)
 		if (!done && (bsize = read(x.dfd, sb, BSIZE)) <= 0)  {
 			done = 1;
 		}
-
+		if (skipsize == XFS_AG_MIN_BYTES)  {
+			readsize = bsize;
+		}
+		else  {

better as:

		} else {

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 141

Quoted 2 lines
repair/sb.c +2 -0
+			readsize = skipsize;
+		}

I wouldn't call this "readsize" - we are only ever reading BSIZE at a time. This is how much we advance each loop, so skipsize is a bit better.

But the _functional_ problem here is that it is possible and permissible to have a filesystem with an AG size of XFS_AG_MIN_BYTES (16MB).

So if you guessed a default geometry with an agsize of XFS_AG_MIN_BYTES, you've gone back to the fine-grained scanning. The fs probably isn't very big as a result, so it's not the end of the world, but ... see below.

Quoted 34 lines
repair/sb.c +22 -3
 		do_warn(".");
-
 		/*
 		 * check the buffer 512 bytes at a time since
 		 * we don't know how big the sectors really are.
@@ -164,9 +173,38 @@ find_secondary_sb(xfs_sb_t *rsb)
 			}
 		}
 	}
-
 	free(sb);
-	return(retval);
+	return retval;
+}
+
+int
+find_secondary_sb(xfs_sb_t *rsb)
+{
+	int		retval;
+	__uint64_t	skipsize;
+	__uint64_t	agcount;
+	__uint64_t	agsize;
+	int		blocklog;
+
+	/*
+	 * Attempt to find secondary sb with a coarse approach,
+	 * using a large skipsize (agsize in bytes). Failing that,
+	 * fallback to the fine-grained approach using min agsize.
+	 */
+	blocklog = guess_default_geometry(&agsize, &agcount, x);
+
+	/*
+	 * use found ag geometry to quickly find secondary sb
+	 */

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 208

Quoted 10 lines
repair/sb.c +9 -0
+	skipsize = agsize << blocklog;
+	retval = __find_secondary_sb(rsb, skipsize);
+	if (!retval)  {
+		/*
+		 * fallback: use minimum agsize for skipsize
+		 */
+		retval = __find_secondary_sb(rsb, XFS_AG_MIN_BYTES);
+	}
+	return retval;
 }

I'd make __find_secondary_sb() take (sb, start, skip) i.e. send in this:

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 206

Quoted 7 lines
repair/sb.c +7 -0
+	retval = __find_secondary_sb(rsb, agsize, agsize);
+	if (!retval)  {
+		/*
+		 * fallback: use minimum agsize for skipsize
+		 */
+		retval = __find_secondary_sb(rsb, XFS_AG_MIN_BYTES, BSIZE);
+	}

and the function is something like:

static int
__find_secondary_sb(

        xfs_sb_t	*rsb,
	xfs_off_t	start,
        xfs_off_t	skip)

{

...

        for (done = 0, off = start; !done ; off += skip)  {
...
               if (lseek64(x.dfd, off, SEEK_SET) != off)
                        done = 1;

               if (!done && (read(x.dfd, sb, BSIZE)) <= 0)
                        done = 1;

because you really can't deduce both the starting point and the skip-ahead size from just one parameter.

-Eric

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

#2 lore raw
Quoted 330 lines · Eric Sandeen
Quoted 77 lines · Bill O'Donnell

Optimize secondary sb search, using similar method to find fs geometry as that of xfs_mkfs. If this faster method fails in finding a secondary sb, fall back to original brute force slower search.

---
 Makefile           |  2 +-
 include/libxcmd.h  |  4 +++-
 libxcmd/topology.c | 35 ++++++++++++++++++++++++++++----
 repair/Makefile    |  4 ++--
 repair/sb.c        | 58 ++++++++++++++++++++++++++++++++++++++++++++----------
 5 files changed, 85 insertions(+), 18 deletions(-)
Makefile +1 -1
index fca0a42..1d60d9c 100644
@@ -80,7 +80,7 @@ fsr: libhandle
 growfs: libxcmd
 io: libxcmd libhandle
 quota: libxcmd
-repair: libxlog
+repair: libxlog libxcmd
 copy: libxlog
 
 ifeq ($(HAVE_BUILDDEFS), yes)
include/libxcmd.h +3 -1
index df7046e..b140adb 100644
@@ -50,6 +50,8 @@ extern int
 check_overwrite(
 	char		*device);
 
-
+extern int guess_default_geometry(__uint64_t *agsize,
+				  __uint64_t *agcount,
+				  libxfs_init_t x);
 
 #endif	/* __LIBXCMD_H__ */
libxcmd/topology.c +6 -4
index 0eeea28..b98d9b9 100644
@@ -192,7 +192,8 @@ out:
 	return ret;
 }
 
-static void blkid_get_topology(
+static void
+blkid_get_topology(
 	const char	*device,
 	int		*sunit,
 	int		*swidth,
@@ -284,7 +285,8 @@ check_overwrite(
 	return 1;
 }
 
-static void blkid_get_topology(
+static void
+blkid_get_topology(
 	const char	*device,
 	int		*sunit,
 	int		*swidth,
@@ -302,8 +304,8 @@ static void blkid_get_topology(
 
 #endif /* ENABLE_BLKID */
 
-
-void get_topology(
+void
+get_topology(
 	libxfs_init_t		*xi,
 	struct fs_topology	*ft,
 	int			force_overwrite)

libxcmd/topology.c void get_topology( · line 357

Quoted 10 lines
libxcmd/topology.c +7 -0
@@ -346,3 +348,28 @@ void get_topology(
 				   &lsectorsize, &psectorsize, force_overwrite);
 	}
 }
+
+int
+guess_default_geometry(__uint64_t *agsize, __uint64_t *agcount,
+		       libxfs_init_t x)
+{
+	struct fs_topology ft;
+	int blocklog;

When in Rome: :)

int
guess_default_geometry(

	__uint64_t	*agsize,
	__uint64_t	*agcount,
	libxfs_init_t	x)

{
...

(sorry, forgot to mention that last time, but other functions in the file are laid out this way; it is easier to read)

Quoted 38 lines
libxcmd/topology.c +18 -0
+	__uint64_t	dblocks;
+	int		multidisk;
+
+	memset(&ft, 0, sizeof(ft));
+	get_topology(&x, &ft, 1);
+
+	/*
+	 * get geometry from get_topology result.
+	 * Use default block size (2^12)
+	 */
+	blocklog = 12;
+	multidisk = ft.dswidth | ft.dsunit;
+	dblocks = x.dsize >> (blocklog - BBSHIFT);
+	calc_default_ag_geometry(blocklog, dblocks, multidisk,
+				 agsize, agcount);
+
+	return blocklog;
+}
repair/Makefile +2 -2
index 251722b..d24ab1f 100644
@@ -20,8 +20,8 @@ CFILES = agheader.c attr_repair.c avl.c avl64.c bmap.c btree.c \
 	progress.c prefetch.c rt.c sb.c scan.c threads.c \
 	versions.c xfs_repair.c
 
-LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
-LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG)
+LLDLIBS = $(LIBBLKID) $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) $(LIBXCMD)
+LTDEPENDENCIES = $(LIBXFS) $(LIBXLOG) $(LIBXCMD)
 LLDFLAGS = -static-libtool-libs
 
 default: depend $(LTCOMMAND)
repair/sb.c +0 -0
index 4eef14a..8bc246e 100644

repair/sb.c line 25

Quoted 4 lines
repair/sb.c +1 -0
@@ -22,6 +22,7 @@
 #include "globals.h"
 #include "protos.h"
 #include "err_protos.h"
+#include "libxcmd.h"

Nitpick, we usually include that right after libxfs.h.

repair/sb.c copy_sb(xfs_sb_t *source, xfs_sb_t *dest) · line 92

Quoted 11 lines
repair/sb.c +3 -1
 #define BSIZE	(1024 * 1024)
 
@@ -85,10 +86,11 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest)
 }
 
 /*
- * find a secondary superblock, copy it into the sb buffer
+ * find a secondary superblock, copy it into the sb buffer.
+ * skipsize units is bytes, it contains either the agsize in bytes
+ * (if known), or the minimum agsize in bytes if agsize unknown.
  */

Ok, so this is a little confused. There are actually 3 relevant parameters here:

1) The place to start reading
2) The number of bytes to read at that point
3) How far to seek forward for the next read

In the old world, it's:

1) XFS_MIN_AG_BYTES
2) BSIZE (1MB)
3) BSIZE (i.e. it does sequential reads)

In the new world, it's:

1) the guessed AG size (skipsize?)
2) BSIZE (more than we need, but not expensive, so leave it)
3) the guessed AG size (skipsize)

You really have 2 different pieces of info: Where to do the first read, and how far forward to skip for the next read. I don't think you can convey that with a single argument, "skipsize."

repair/sb.c copy_sb(xfs_sb_t *source, xfs_sb_t *dest) · line 93

Quoted 3 lines
repair/sb.c +1 -2
-int
-find_secondary_sb(xfs_sb_t *rsb)
+static int __find_secondary_sb(xfs_sb_t *rsb, __uint64_t skipsize)

better to format as:

static int
__find_secondary_sb(

	xfs_sb_t	*rsb,
	__uint64_t	skipsize)

{

but ...

Quoted 17 lines
repair/sb.c +1 -1
 {
 	xfs_off_t	off;
 	xfs_sb_t	*sb;
@@ -99,9 +101,9 @@ find_secondary_sb(xfs_sb_t *rsb)
 	int		dirty;
 	int		retval;
 	int		bsize;
+	int		readsize;
 
 	do_warn(_("\nattempting to find secondary superblock...\n"));
-
 	sb = (xfs_sb_t *)memalign(libxfs_device_alignment(), BSIZE);
 	if (!sb) {
 		do_error(
@@ -113,13 +115,16 @@ find_secondary_sb(xfs_sb_t *rsb)
 	retval = 0;
 	dirty = 0;

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 122

Quoted 10 lines
repair/sb.c +2 -2
 	bsize = 0;
+	readsize = 0;
 
 	/*
 	 * skip first sector since we know that's bad
 	 */
-	for (done = 0, off = XFS_AG_MIN_BYTES; !done ; off += bsize)  {
+	for (done = 0, off = skipsize; !done ; off += readsize)  {
 		/*
-		 * read disk 1 MByte at a time.

we are actually still doing that, read(x.dfd, sb, BSIZE), so I'd leave the comment...

Quoted 9 lines
repair/sb.c +3 -0
+		 * read disk using readsize interval
+		 * (either the bytecount of actual agsize or bsize if
+		 * agsize undetermined.)
 
 
 		 */
repair/sb.c +0 -0
 		if (lseek64(x.dfd, off, SEEK_SET) != off)  {
 			done = 1;

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 139

Quoted 8 lines
repair/sb.c +4 -1
@@ -128,9 +133,13 @@ find_secondary_sb(xfs_sb_t *rsb)
 		if (!done && (bsize = read(x.dfd, sb, BSIZE)) <= 0)  {
 			done = 1;
 		}
-
+		if (skipsize == XFS_AG_MIN_BYTES)  {
+			readsize = bsize;
+		}
+		else  {

better as:

		} else {

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 141

Quoted 2 lines
repair/sb.c +2 -0
+			readsize = skipsize;
+		}

I wouldn't call this "readsize" - we are only ever reading BSIZE at a time. This is how much we advance each loop, so skipsize is a bit better.

But the _functional_ problem here is that it is possible and permissible to have a filesystem with an AG size of XFS_AG_MIN_BYTES (16MB).

So if you guessed a default geometry with an agsize of XFS_AG_MIN_BYTES, you've gone back to the fine-grained scanning. The fs probably isn't very big as a result, so it's not the end of the world, but ... see below.

Quoted 34 lines
repair/sb.c +22 -3
 		do_warn(".");
-
 		/*
 		 * check the buffer 512 bytes at a time since
 		 * we don't know how big the sectors really are.
@@ -164,9 +173,38 @@ find_secondary_sb(xfs_sb_t *rsb)
 			}
 		}
 	}
-
 	free(sb);
-	return(retval);
+	return retval;
+}
+
+int
+find_secondary_sb(xfs_sb_t *rsb)
+{
+	int		retval;
+	__uint64_t	skipsize;
+	__uint64_t	agcount;
+	__uint64_t	agsize;
+	int		blocklog;
+
+	/*
+	 * Attempt to find secondary sb with a coarse approach,
+	 * using a large skipsize (agsize in bytes). Failing that,
+	 * fallback to the fine-grained approach using min agsize.
+	 */
+	blocklog = guess_default_geometry(&agsize, &agcount, x);
+
+	/*
+	 * use found ag geometry to quickly find secondary sb
+	 */

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 208

Quoted 10 lines
repair/sb.c +9 -0
+	skipsize = agsize << blocklog;
+	retval = __find_secondary_sb(rsb, skipsize);
+	if (!retval)  {
+		/*
+		 * fallback: use minimum agsize for skipsize
+		 */
+		retval = __find_secondary_sb(rsb, XFS_AG_MIN_BYTES);
+	}
+	return retval;
 }

I'd make __find_secondary_sb() take (sb, start, skip) i.e. send in this:

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 206

Quoted 7 lines
repair/sb.c +7 -0
+	retval = __find_secondary_sb(rsb, agsize, agsize);
+	if (!retval)  {
+		/*
+		 * fallback: use minimum agsize for skipsize
+		 */
+		retval = __find_secondary_sb(rsb, XFS_AG_MIN_BYTES, BSIZE);
+	}

and the function is something like:

static int
__find_secondary_sb(

        xfs_sb_t	*rsb,
	xfs_off_t	start,
        xfs_off_t	skip)

{

...

Quoted 7 lines
        for (done = 0, off = start; !done ; off += skip)  {
...
               if (lseek64(x.dfd, off, SEEK_SET) != off)
                        done = 1;

               if (!done && (read(x.dfd, sb, BSIZE)) <= 0)
                        done = 1;

But, bsize is used here:
...
* check the buffer 512 bytes at a time since
* we don't know how big the sectors really are. */
for (i = 0; !done && i < bsize; i += BBSIZE) {
...
so, don't we still need to populate bsize? Or does it make more sense to just use BBSIZE in the conditional, ala:

            for (i = 0; !done && i < BBSIZE; i += BBSIZE) 
Quoted 4 lines

because you really can't deduce both the starting point and the skip-ahead size from just one parameter.

Agreed.
Thanks for your thorough reviews :)
Bill

Quoted 5 lines

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

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

#3 lore raw
Quoted 39 lines · Bill O'Donnell
Quoted 30 lines

I'd make __find_secondary_sb() take (sb, start, skip) i.e. send in

Quoted 29 lines

this:

Quoted 7 lines

repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 206

Quoted 7 lines
repair/sb.c +7 -0
+	retval = __find_secondary_sb(rsb, agsize, agsize);
+	if (!retval)  {
+		/*
+		 * fallback: use minimum agsize for skipsize
+		 */
+		retval = __find_secondary_sb(rsb, XFS_AG_MIN_BYTES, BSIZE);
+	}

and the function is something like:

static int
__find_secondary_sb(

        xfs_sb_t	*rsb,
	xfs_off_t	start,
        xfs_off_t	skip)

{

...

        for (done = 0, off = start; !done ; off += skip)  {
...
               if (lseek64(x.dfd, off, SEEK_SET) != off)
                        done = 1;

               if (!done && (read(x.dfd, sb, BSIZE)) <= 0)
                        done = 1;

But, bsize is used here:
...
* check the buffer 512 bytes at a time since
* we don't know how big the sectors really are. */
for (i = 0; !done && i < bsize; i += BBSIZE) {
...
so, don't we still need to populate bsize? Or does it make more sense to just use BBSIZE in the conditional, ala:

Quoted 1 line
            for (i = 0; !done && i < BBSIZE; i += BBSIZE) 

Oh, right, sorry. yes, keep the assignment:

                if (!done && (bsize = read(x.dfd, sb, BSIZE)) <= 0)  {

That handles a short read at the end; we ask for BSIZE, actually read bsize, and then we need to iterate over what actually got read (bsize).

BSIZE, bsize ... clear as mud. :(

-Eric

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

because you really can't deduce both the starting point and the skip-ahead size from just one parameter.

Agreed.
Thanks for your thorough reviews :)
Bill

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