xfs_repair: improved secondary sb search
cover xfs_repair: improved secondary sb search
Hello -
Current xfs_repair uses a brute force approach to find a valid secondary sb. This series optimizes the secondary sb search, using similar method to determine geometry as that of xfs_mkfs. If the faster method fails in its search, fall back to original brute force slower search.
patch 1 has some general infrastructure adjustments, moving general topology functions from mkfs to libxcmd.
patch 2 adds the new secondary superblock search method.
Questions, comments are welcome.
Thanks-
Bill
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 1/2 libxcmd: generalize topology functions
Move general topology functions from xfs_mkfs to new topology collection in libxcmd.
--- include/Makefile | 1 + include/libxcmd.h | 55 +++++++++ libxcmd/Makefile | 2 +- libxcmd/topology.c | 348 +++++++++++++++++++++++++++++++++++++++++++++++++++++ mkfs/Makefile | 2 +- mkfs/xfs_mkfs.c | 321 +----------------------------------------------- 6 files changed, 407 insertions(+), 322 deletions(-) create mode 100644 include/libxcmd.h create mode 100644 libxcmd/topology.c
include/Makefile +1 -0
@@ -20,6 +20,7 @@ include $(TOPDIR)/include/builddefs LIBHFILES = libxfs.h \ libxlog.h \ + libxcmd.h \ atomic.h \ bitops.h \ cache.h \
include/libxcmd.h new file +55 -0
55 lines not on this page · raw message
libxcmd/Makefile +1 -1
@@ -10,7 +10,7 @@ LT_CURRENT = 0 LT_REVISION = 0 LT_AGE = 0 -CFILES = command.c input.c paths.c projects.c help.c quit.c +CFILES = command.c input.c paths.c projects.c help.c quit.c topology.c ifeq ($(HAVE_GETMNTENT),yes) LCFLAGS += -DHAVE_GETMNTENT
libxcmd/topology.c new file +348 -0
348 lines not on this page · raw message
mkfs/Makefile +1 -1
@@ -10,7 +10,7 @@ LTCOMMAND = mkfs.xfs HFILES = xfs_mkfs.h CFILES = maxtrres.c proto.c xfs_mkfs.c -LLDLIBS += $(LIBBLKID) $(LIBXFS) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) +LLDLIBS += $(LIBBLKID) $(LIBXFS) $(LIBUUID) $(LIBRT) $(LIBPTHREAD) $(LIBXCMD) LTDEPENDENCIES += $(LIBXFS) LLDFLAGS = -static-libtool-libs
mkfs/xfs_mkfs.c +1 -320
339 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
PATCH 2/2 xfs_repair: new secondary superblock search method
In reply to Bill O'DonnellOptimize 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 | 28 +++++++++++++++++++++++++++- repair/Makefile | 4 ++-- repair/phase1.c | 25 +++++++++++++++++++++++-- repair/protos.h | 2 +- repair/sb.c | 27 +++++++++++++++++++++------ 7 files changed, 78 insertions(+), 14 deletions(-)
Makefile +1 -1
@@ -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
@@ -50,6 +50,8 @@ extern intcheck_overwrite ( char *device); - +extern int guess_default_geometry (__uint64_t *agsize, +__uint64_t *agcount, +libxfs_init_t x);#endif /* __LIBXCMD_H__ */
libxcmd/topology.c +27 -1
@@ -302,7 +302,6 @@ static void blkid_get_topology(#endif /* ENABLE_BLKID */ - void get_topology( libxfs_init_t *xi, struct fs_topology *ft,
@@ -346,3 +345,30 @@ void get_topology( &lsectorsize, &psectorsize, force_overwrite); } } + +/* +* Use this macro before we have superblock and mount structure +*/ +#define DTOBT (d) ((xfs_rfsblock_t)((d) >> (blocklog - BBSHIFT))) + +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; +printf ("x.dsize = %lu\n" ,(long unsigned int )x.dsize); + dblocks =DTOBT (x.dsize); +calc_default_ag_geometry (blocklog, dblocks, multidisk, + agsize, agcount); + +return (blocklog); +}
repair/Makefile +2 -2
@@ -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/phase1.c +23 -2
@@ -21,6 +21,7 @@#include "agheader.h" #include "protos.h" #include "err_protos.h" +#include "libxcmd.h" static void no_sb (void )
@@ -47,6 +48,9 @@ alloc_ag_buf(int size)*/ #define MAX_SECTSIZE (512 * 1024) +extern libxfs_init_t x; + +/* ARGSUSED */ void phase1 (xfs_mount_t *mp)
@@ -54,6 +58,10 @@ phase1(xfs_mount_t *mp)xfs_sb_t *sb;char *ag_bp;int rval; +int blocklog; +__uint64_t agcount; +__uint64_t agsize; +__uint64_t skipsize;do_log (_ ("Phase 1 - find and verify superblock...\n" ));
@@ -65,6 +73,18 @@ phase1(xfs_mount_t *mp) lost_quotas =0 ;/* +* divine the geometry ;) +*/ + blocklog =guess_default_geometry (&agsize, &agcount, x); + +/* +* use found ag geometry to quickly find secondary sb +*/ + skipsize = agsize << blocklog; +do_log ("agsize = %d agcount = %d skipsize = %d\n" , + (int )agsize, (int )agcount, (int )skipsize); + +/* * get AG 0 into ag header buf */ ag_bp =alloc_ag_buf (MAX_SECTSIZE );
@@ -80,14 +100,15 @@ phase1(xfs_mount_t *mp)if (rval !=XR_OK ) {do_warn (_ ("bad primary superblock - %s !!!\n" ),err_string (rval)); -if (!find_secondary_sb (sb)) + +if (!find_secondary_sb (sb, skipsize))no_sb (); primary_sb_modified =1 ; }else if ((rval =verify_set_primary_sb (sb,0 , &primary_sb_modified)) !=XR_OK ) {do_warn (_ ("couldn't verify primary superblock - %s !!!\n" ),err_string (rval)); -if (!find_secondary_sb (sb)) +if (!find_secondary_sb (sb, skipsize))no_sb (); primary_sb_modified =1 ; }
repair/protos.h +1 -1
@@ -31,7 +31,7 @@ int get_sb(xfs_sb_t *sbp,void write_primary_sb (xfs_sb_t *sbp,int size); -int find_secondary_sb (xfs_sb_t *sb); +int find_secondary_sb (xfs_sb_t *sb,__uint64_t skipsize);struct fs_geometry ; void get_sb_geometry(struct fs_geometry *geo,
repair/sb.c +21 -6
@@ -87,8 +87,7 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest)/* * find a secondary superblock, copy it into the sb buffer */ -int -find_secondary_sb (xfs_sb_t *rsb) +static int __find_secondary_sb (xfs_sb_t *rsb,__uint64_t skipsize ) {xfs_off_t off;xfs_sb_t *sb;
@@ -101,7 +100,6 @@ find_secondary_sb(xfs_sb_t *rsb)int bsize;do_warn (_ ("\nattempting to find secondary superblock...\n" )); - sb = (xfs_sb_t *)memalign (libxfs_device_alignment (),BSIZE );if (!sb) { do_error(
@@ -117,7 +115,7 @@ find_secondary_sb(xfs_sb_t *rsb)/* * 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 += bsize) {/* * read disk 1 MByte at a time. */
@@ -130,7 +128,6 @@ find_secondary_sb(xfs_sb_t *rsb) }do_warn ("." ); -/* * check the buffer 512 bytes at a time since * we don't know how big the sectors really are.
@@ -164,11 +161,29 @@ find_secondary_sb(xfs_sb_t *rsb) } } } -free (sb);return (retval); } +int +find_secondary_sb (xfs_sb_t *rsb,__uint64_t skipsize) +{ +int retval; + +/* +* 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. +*/ + 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); +} +/* * Calculate what the inode alignment field ought to be based on internal * superblock info and determine if it is valid.
Signature · 6 lines
2.5.0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 2/2] xfs_repair: new secondary superblock search method
Quoted 56 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.Signed-off-by Bill O'Donnell <[email protected]>--- Makefile | 2 +- include/libxcmd.h | 4 +++- libxcmd/topology.c | 28 +++++++++++++++++++++++++++- repair/Makefile | 4 ++-- repair/phase1.c | 25 +++++++++++++++++++++++-- repair/protos.h | 2 +- repair/sb.c | 27 +++++++++++++++++++++------ 7 files changed, 78 insertions(+), 14 deletions(-)Makefile +1
-1@@ -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@@ -50,6 +50,8 @@ extern intcheck_overwrite ( char *device); - +extern int guess_default_geometry (__uint64_t *agsize, +__uint64_t *agcount, +libxfs_init_t x);#endif /* __LIBXCMD_H__ */ libxcmd/topology.c +0
-1@@ -302,7 +302,6 @@ static void blkid_get_topology(#endif /* ENABLE_BLKID */ - void get_topology( libxfs_init_t *xi, struct fs_topology *ft,
libxcmd/topology.c void get_topology( · line 352
Quoted 8 lines
libxcmd/topology.c +5
-0@@ -346,3 +345,30 @@ void get_topology( &lsectorsize, &psectorsize, force_overwrite); } } + +/* +* Use this macro before we have superblock and mount structure +*/ +#define DTOBT (d) ((xfs_rfsblock_t)((d) >> (blocklog - BBSHIFT)))
Hm, I hate this macro. ;) I know it lives in xfs_mkfs.c too... depending on a local variable is ick. Since you only use it once below, it might be best to just open-code it, see below.
libxcmd/topology.c void get_topology( · line 354
Quoted 2 lines
libxcmd/topology.c +2
-0+ +int guess_default_geometry (__uint64_t *agsize,__uint64_t *agcount,libxfs_init_t x) {
Move the "{" down to this line, please, and wrap the args so it doesn't go over 80 chars.
libxcmd/topology.c void get_topology( · line 357
Quoted 3 lines
libxcmd/topology.c +3
-0+struct fs_topology ft; +int blocklog; +__uint64_t dblocks;
^tab here please
libxcmd/topology.c void get_topology( · line 358
Quoted 1 line
libxcmd/topology.c +1
-0+int multidisk;
^tabs here please
... and a newline here to separate variable declarations...
libxcmd/topology.c void get_topology( · line 359
Quoted 1 line
libxcmd/topology.c +1
-0+memset (&ft,0 ,sizeof (ft));
... from this call. Tab this call in...
libxcmd/topology.c void get_topology( · line 360
Quoted 1 line
libxcmd/topology.c +1
-0+get_topology (&x, &ft,1 );
^^^^ as well as this one.
libxcmd/topology.c void get_topology( · line 362
Quoted 2 lines
libxcmd/topology.c +2
-0+ +/*
^ tab here too
libxcmd/topology.c void get_topology( · line 368
Quoted 6 lines
libxcmd/topology.c +6
-0+* get geometry from get_topology result. +* Use default block size (2^12) +*/ + blocklog =12 ; + multidisk = ft.dswidth | ft.dsunit; +printf ("x.dsize = %lu\n" ,(long unsigned int )x.dsize);
drop the debug printf
libxcmd/topology.c void get_topology( · line 369
Quoted 1 line
libxcmd/topology.c +1
-0+ dblocks =DTOBT (x.dsize);
maybe best to just:
dblocks = x.dsize >> (blocklog - BBSHIFT);
libxcmd/topology.c void get_topology( · line 371
Quoted 2 lines
libxcmd/topology.c +2
-0+calc_default_ag_geometry (blocklog, dblocks, multidisk, + agsize, agcount);
general whitespace problems above; use tabs not spaces please, as appropriate.
libxcmd/topology.c void get_topology( · line 373
Quoted 2 lines
libxcmd/topology.c +2
-0+ +return (blocklog);
while we're at it it'd be nice to make return not a function; just "return blocklog;"
Quoted 29 lines
libxcmd/topology.c +1
-0+}repair/Makefile +2
-2@@ -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/phase1.c +1
-0@@ -21,6 +21,7 @@#include "agheader.h" #include "protos.h" #include "err_protos.h" +#include "libxcmd.h" static void no_sb (void )
repair/phase1.c alloc_ag_buf(int size) · line 51
Quoted 4 lines
repair/phase1.c +1
-0@@ -47,6 +48,9 @@ alloc_ag_buf(int size)*/ #define MAX_SECTSIZE (512 * 1024) +extern libxfs_init_t x;
It would be better to
#include "libxlog.h"
after the inclusion of libxfs.h at the top of this file, and you won't need this extern. That's how the main file/function gets "x" for xfs_repair. but actually, see more below.
Quoted 20 lines
repair/phase1.c +6
-0+ +/* ARGSUSED */ void phase1 (xfs_mount_t *mp)@@ -54,6 +58,10 @@ phase1(xfs_mount_t *mp)xfs_sb_t *sb;char *ag_bp;int rval; +int blocklog; +__uint64_t agcount; +__uint64_t agsize; +__uint64_t skipsize;do_log (_ ("Phase 1 - find and verify superblock...\n" ));@@ -65,6 +73,18 @@ phase1(xfs_mount_t *mp) lost_quotas =0 ;/*
repair/phase1.c phase1(xfs_mount_t *mp) · line 85
Quoted 10 lines
repair/phase1.c +10
-0+* divine the geometry +*/ + blocklog =guess_default_geometry (&agsize, &agcount, x); + +/* +* use found ag geometry to quickly find secondary sb +*/ + skipsize = agsize << blocklog; +do_log ("agsize = %d agcount = %d skipsize = %d\n" , + (int )agsize, (int )agcount, (int )skipsize);
Since this is just a guess, I wouldn't log. It may well print out geometry that is not correct, and that would be confusing.
And actually - looking at how you have refactored find_secondary_sb(), you can move the above 12 or so lines into find_secondary_sb(), and you don't need to pre-compute skipsize etc here. You can do it all in find_secondary_sb() when it gets called.
Then this file (phase1.c) can be completely unchanged, and all the magic happens in repair/sb.c.
Quoted 28 lines
repair/phase1.c +5
-2+ +/* * get AG 0 into ag header buf */ ag_bp =alloc_ag_buf (MAX_SECTSIZE );@@ -80,14 +100,15 @@ phase1(xfs_mount_t *mp)if (rval !=XR_OK ) {do_warn (_ ("bad primary superblock - %s !!!\n" ),err_string (rval)); -if (!find_secondary_sb (sb)) + +if (!find_secondary_sb (sb, skipsize))no_sb (); primary_sb_modified =1 ; }else if ((rval =verify_set_primary_sb (sb,0 , &primary_sb_modified)) !=XR_OK ) {do_warn (_ ("couldn't verify primary superblock - %s !!!\n" ),err_string (rval)); -if (!find_secondary_sb (sb)) +if (!find_secondary_sb (sb, skipsize))no_sb (); primary_sb_modified =1 ; }repair/protos.h +0
-0
repair/protos.h int get_sb(xfs_sb_t *sbp, · line 34
Quoted 5 lines
repair/protos.h +1
-1@@ -31,7 +31,7 @@ int get_sb(xfs_sb_t *sbp,void write_primary_sb (xfs_sb_t *sbp,int size); -int find_secondary_sb (xfs_sb_t *sb); +int find_secondary_sb (xfs_sb_t *sb,__uint64_t skipsize);
this would be unchanged as well.
repair/sb.c copy_sb(xfs_sb_t *source, xfs_sb_t *dest) · line 88
Quoted 10 lines
repair/protos.h +0
-0struct fs_geometry ; void get_sb_geometry(struct fs_geometry *geo,repair/sb.c renamed from repair/sb.c/d +0
-0@@ -87,8 +87,7 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest)/* * find a secondary superblock, copy it into the sb buffer
It'd be good to document "skipsize" here - units, and purpose.
repair/sb.c copy_sb(xfs_sb_t *source, xfs_sb_t *dest) · line 90
Quoted 4 lines
repair/sb.c renamed from repair/sb.c/d +1
-2*/ -int -find_secondary_sb (xfs_sb_t *rsb) +static int __find_secondary_sb (xfs_sb_t *rsb,__uint64_t skipsize )
no space between skipsize and ")" please.
Quoted 12 lines
repair/sb.c renamed from repair/sb.c/d +0
-1{xfs_off_t off;xfs_sb_t *sb;@@ -101,7 +100,6 @@ find_secondary_sb(xfs_sb_t *rsb)int bsize;do_warn (_ ("\nattempting to find secondary superblock...\n" )); - sb = (xfs_sb_t *)memalign (libxfs_device_alignment (),BSIZE );if (!sb) { do_error(
repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 118
Quoted 5 lines
repair/sb.c renamed from repair/sb.c/d +1
-1@@ -117,7 +115,7 @@ find_secondary_sb(xfs_sb_t *rsb)/* * 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 += bsize) {
Ok, so you jump out "skipsize" for the first read, but after that you only move the offset by bsize, which is BSIZE (or 1MB).
That works OK if the 2nd superblock (at skipsize) is OK, but if it's not, you'll start from there doing smaller reads like before, and then this loop isn't really any more efficient than it was.
If skipsize is set, you need to start out 1x skipsize, then read at 2x skipsize, 3x skipsize, etc. So you need to change the loop increment as well.
i.e. fast path: start at skipsize, advance by skipsize each loop
slow path: start at XFS_AG_MIN_BYTES, advance by BSIZE each loop
If you make a 4t sparse file, mkfs it, and corrupt the first *2* superblocks, then point repair at it you'll see what I mean.
Quoted 22 lines
repair/sb.c renamed from repair/sb.c/d +2
-2/* * read disk 1 MByte at a time. */ @@ -130,7 +128,6 @@ find_secondary_sb(xfs_sb_t *rsb) }do_warn ("." ); -/* * check the buffer 512 bytes at a time since * we don't know how big the sectors really are. @@ -164,11 +161,29 @@ find_secondary_sb(xfs_sb_t *rsb) } } } -free (sb);return (retval); } +int +find_secondary_sb (xfs_sb_t *rsb,__uint64_t skipsize)
repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 179
Quoted 10 lines
repair/sb.c renamed from repair/sb.c/d +10
-0+{ +int retval; + +/* +* 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. +*/ + retval =__find_secondary_sb (rsb, skipsize); +if (!retval)
With the comment below, it's safest to wrap these multiple lines after the conditional in { .... }
repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 184
Quoted 5 lines
repair/sb.c renamed from repair/sb.c/d +5
-0+/* +* fallback: use minimum agsize for skipsize +*/ + retval =__find_secondary_sb (rsb,XFS_AG_MIN_BYTES ); +return (retval);
again drop the () on the return, please.
repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 189
Quoted 6 lines
repair/sb.c renamed from repair/sb.c/d +2
-0+} +/* * Calculate what the inode alignment field ought to be based on internal * superblock info and determine if it is valid.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 2/2] xfs_repair: new secondary superblock search method
Quoted 70 lines · Eric Sandeen
Quoted 56 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.Signed-off-by Bill O'Donnell <[email protected]>--- Makefile | 2 +- include/libxcmd.h | 4 +++- libxcmd/topology.c | 28 +++++++++++++++++++++++++++- repair/Makefile | 4 ++-- repair/phase1.c | 25 +++++++++++++++++++++++-- repair/protos.h | 2 +- repair/sb.c | 27 +++++++++++++++++++++------ 7 files changed, 78 insertions(+), 14 deletions(-)Makefile +1
-1@@ -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@@ -50,6 +50,8 @@ extern intcheck_overwrite ( char *device); - +extern int guess_default_geometry (__uint64_t *agsize, +__uint64_t *agcount, +libxfs_init_t x);#endif /* __LIBXCMD_H__ */ libxcmd/topology.c +0
-1@@ -302,7 +302,6 @@ static void blkid_get_topology(#endif /* ENABLE_BLKID */ - void get_topology( libxfs_init_t *xi, struct fs_topology *ft,libxcmd/topology.c void get_topology( · line 352
Quoted 8 lines
libxcmd/topology.c +5
-0@@ -346,3 +345,30 @@ void get_topology( &lsectorsize, &psectorsize, force_overwrite); } } + +/* +* Use this macro before we have superblock and mount structure +*/ +#define DTOBT (d) ((xfs_rfsblock_t)((d) >> (blocklog - BBSHIFT)))Hm, I hate this macro. ;) I know it lives in
xfs_mkfs.ctoo... depending on a local variable is ick. Since you only use it once below, it might be best to just open-code it, see below.
Quoted 5 lines
libxcmd/topology.c void get_topology( · line 354
Quoted 2 lines
libxcmd/topology.c +2
-0+ +int guess_default_geometry (__uint64_t *agsize,__uint64_t *agcount,libxfs_init_t x) {Move the "{" down to this line, please, and wrap the args so it doesn't go over 80 chars.
Also, please put the function name at the start of a line like most of the other XFS code:
int
guess_default_geometry(
__uint64_t *agsize,
__uint64_t *agcount,
libxfs_init_t x)
{
/* ... */
}This makes it wayyyy easier to grep-hunt for function definitions.
(Try wading through the mishmash of ext4/e2fsprogs until your brain fades...)
--D
Quoted 268 lines
libxcmd/topology.c void get_topology( · line 357
Quoted 4 lines
libxcmd/topology.c +3
-0+struct fs_topology ft; +int blocklog; +__uint64_t dblocks;^tab here please
libxcmd/topology.c void get_topology( · line 358
Quoted 1 line
libxcmd/topology.c +1
-0+int multidisk;^tabs here please
... and a newline here to separate variable declarations...
libxcmd/topology.c void get_topology( · line 359
Quoted 1 line
libxcmd/topology.c +1
-0+memset (&ft,0 ,sizeof (ft));... from this call. Tab this call in...
libxcmd/topology.c void get_topology( · line 360
Quoted 1 line
libxcmd/topology.c +1
-0+get_topology (&x, &ft,1 );^^^^ as well as this one.
libxcmd/topology.c void get_topology( · line 362
Quoted 2 lines
libxcmd/topology.c +2
-0+ +/* ^ tab here too
libxcmd/topology.c void get_topology( · line 368
Quoted 6 lines
libxcmd/topology.c +6
-0+* get geometry from get_topology result. +* Use default block size (2^12) +*/ + blocklog =12 ; + multidisk = ft.dswidth | ft.dsunit; +printf ("x.dsize = %lu\n" ,(long unsigned int )x.dsize);drop the debug printf
libxcmd/topology.c void get_topology( · line 369
Quoted 1 line
libxcmd/topology.c +1
-0+ dblocks =DTOBT (x.dsize);maybe best to just:
dblocks = x.dsize >> (blocklog - BBSHIFT);libxcmd/topology.c void get_topology( · line 371
Quoted 2 lines
libxcmd/topology.c +2
-0+calc_default_ag_geometry (blocklog, dblocks, multidisk, + agsize, agcount);general whitespace problems above; use tabs not spaces please, as appropriate.
libxcmd/topology.c void get_topology( · line 373
Quoted 2 lines
libxcmd/topology.c +2
-0+ +return (blocklog);while we're at it it'd be nice to make return not a function; just "return blocklog;"
Quoted 29 lines
libxcmd/topology.c +1
-0+}repair/Makefile +2
-2@@ -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/phase1.c +1
-0@@ -21,6 +21,7 @@#include "agheader.h" #include "protos.h" #include "err_protos.h" +#include "libxcmd.h" static void no_sb (void )repair/phase1.c alloc_ag_buf(int size) · line 51
Quoted 4 lines
repair/phase1.c +1
-0@@ -47,6 +48,9 @@ alloc_ag_buf(int size)*/ #define MAX_SECTSIZE (512 * 1024) +extern libxfs_init_t x;It would be better to
#include "
libxlog.h"after the inclusion of
libxfs.hat the top of this file, and you won't need this extern. That's how the main file/function gets "x" forxfs_repair. but actually, see more below.Quoted 20 lines
repair/phase1.c +6
-0+ +/* ARGSUSED */ void phase1 (xfs_mount_t *mp)@@ -54,6 +58,10 @@ phase1(xfs_mount_t *mp)xfs_sb_t *sb;char *ag_bp;int rval; +int blocklog; +__uint64_t agcount; +__uint64_t agsize; +__uint64_t skipsize;do_log (_ ("Phase 1 - find and verify superblock...\n" ));@@ -65,6 +73,18 @@ phase1(xfs_mount_t *mp) lost_quotas =0 ;/* repair/phase1.c phase1(xfs_mount_t *mp) · line 85
Quoted 10 lines
repair/phase1.c +10
-0+* divine the geometry +*/ + blocklog =guess_default_geometry (&agsize, &agcount, x); + +/* +* use found ag geometry to quickly find secondary sb +*/ + skipsize = agsize << blocklog; +do_log ("agsize = %d agcount = %d skipsize = %d\n" , + (int )agsize, (int )agcount, (int )skipsize);Since this is just a guess, I wouldn't log. It may well print out geometry that is not correct, and that would be confusing.
And actually - looking at how you have refactored
find_secondary_sb(), you can move the above 12 or so lines intofind_secondary_sb(), and you don't need to pre-compute skipsize etc here. You can do it all infind_secondary_sb()when it gets called.Then this file (
phase1.c) can be completely unchanged, and all the magic happens inrepair/sb.c.Quoted 28 lines
repair/phase1.c +5
-2+ +/* * get AG 0 into ag header buf */ ag_bp =alloc_ag_buf (MAX_SECTSIZE );@@ -80,14 +100,15 @@ phase1(xfs_mount_t *mp)if (rval !=XR_OK ) {do_warn (_ ("bad primary superblock - %s !!!\n" ),err_string (rval)); -if (!find_secondary_sb (sb)) + +if (!find_secondary_sb (sb, skipsize))no_sb (); primary_sb_modified =1 ; }else if ((rval =verify_set_primary_sb (sb,0 , &primary_sb_modified)) !=XR_OK ) {do_warn (_ ("couldn't verify primary superblock - %s !!!\n" ),err_string (rval)); -if (!find_secondary_sb (sb)) +if (!find_secondary_sb (sb, skipsize))no_sb (); primary_sb_modified =1 ; }repair/protos.h +0
-0repair/protos.h int get_sb(xfs_sb_t *sbp, · line 34
Quoted 5 lines
repair/protos.h +1
-1@@ -31,7 +31,7 @@ int get_sb(xfs_sb_t *sbp,void write_primary_sb (xfs_sb_t *sbp,int size); -int find_secondary_sb (xfs_sb_t *sb); +int find_secondary_sb (xfs_sb_t *sb,__uint64_t skipsize);this would be unchanged as well.
repair/sb.c copy_sb(xfs_sb_t *source, xfs_sb_t *dest) · line 88
Quoted 10 lines
repair/protos.h +0
-0struct fs_geometry ; void get_sb_geometry(struct fs_geometry *geo,repair/sb.c renamed from repair/sb.c/d +0
-0@@ -87,8 +87,7 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest)/* * find a secondary superblock, copy it into the sb buffer It'd be good to document "skipsize" here - units, and purpose.
repair/sb.c copy_sb(xfs_sb_t *source, xfs_sb_t *dest) · line 90
Quoted 4 lines
repair/sb.c renamed from repair/sb.c/d +1
-2*/ -int -find_secondary_sb (xfs_sb_t *rsb) +static int __find_secondary_sb (xfs_sb_t *rsb,__uint64_t skipsize )no space between skipsize and ")" please.
Quoted 12 lines
repair/sb.c renamed from repair/sb.c/d +0
-1{xfs_off_t off;xfs_sb_t *sb;@@ -101,7 +100,6 @@ find_secondary_sb(xfs_sb_t *rsb)int bsize;do_warn (_ ("\nattempting to find secondary superblock...\n" )); - sb = (xfs_sb_t *)memalign (libxfs_device_alignment (),BSIZE );if (!sb) { do_error(repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 118
Quoted 5 lines
repair/sb.c renamed from repair/sb.c/d +1
-1@@ -117,7 +115,7 @@ find_secondary_sb(xfs_sb_t *rsb)/* * 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 += bsize) {Ok, so you jump out "skipsize" for the first read, but after that you only move the offset by bsize, which is BSIZE (or 1MB).
That works OK if the 2nd superblock (at skipsize) is OK, but if it's not, you'll start from there doing smaller reads like before, and then this loop isn't really any more efficient than it was.
If skipsize is set, you need to start out 1x skipsize, then read at 2x skipsize, 3x skipsize, etc. So you need to change the loop increment as well.
i.e. fast path: start at skipsize, advance by skipsize each loop
slow path: start at
XFS_AG_MIN_BYTES, advance by BSIZE each loopIf you make a 4t sparse file, mkfs it, and corrupt the first *2* superblocks, then point repair at it you'll see what I mean.
Quoted 22 lines
repair/sb.c renamed from repair/sb.c/d +2
-2/* * read disk 1 MByte at a time. */ @@ -130,7 +128,6 @@ find_secondary_sb(xfs_sb_t *rsb) }do_warn ("." ); -/* * check the buffer 512 bytes at a time since * we don't know how big the sectors really are. @@ -164,11 +161,29 @@ find_secondary_sb(xfs_sb_t *rsb) } } } -free (sb);return (retval); } +int +find_secondary_sb (xfs_sb_t *rsb,__uint64_t skipsize)repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 179
Quoted 10 lines
repair/sb.c renamed from repair/sb.c/d +10
-0+{ +int retval; + +/* +* 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. +*/ + retval =__find_secondary_sb (rsb, skipsize); +if (!retval)With the comment below, it's safest to wrap these multiple lines after the conditional in { .... }
repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 184
Quoted 5 lines
repair/sb.c renamed from repair/sb.c/d +5
-0+/* +* fallback: use minimum agsize for skipsize +*/ + retval =__find_secondary_sb (rsb,XFS_AG_MIN_BYTES ); +return (retval);again drop the () on the return, please.
Quoted 11 lines
repair/sb.c find_secondary_sb(xfs_sb_t *rsb) · line 189
Quoted 6 lines
repair/sb.c renamed from repair/sb.c/d +2
-0+} +/* * Calculate what the inode alignment field ought to be based on internal * superblock info and determine if it is valid. _______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs