From 6f3c8414f4d4746c8d9d9e6f46f7af3eac34f36c Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Thu, 13 Apr 2017 21:48:16 +0300 Subject: [PATCH] sbin/hammer: Make volume count test optional for blkdevs based commands This is basically for feature enhancement of hammer strip command in the next commit. No functional change by this commit. Some blkdevs based commands need to be able to handle broken volume headers by omitting volume verification (to certain extent). It has been that way for the volume header contents, but not for volume count as well as checking existence of root volume. --- sbin/hammer/hammer.c | 50 +++++++++++++++++++++-------------------------- sbin/hammer/hammer_util.h | 2 +- sbin/hammer/ondisk.c | 4 ++-- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/sbin/hammer/hammer.c b/sbin/hammer/hammer.c index f33497782c..aedac791f2 100644 --- a/sbin/hammer/hammer.c +++ b/sbin/hammer/hammer.c @@ -35,7 +35,8 @@ #include "hammer.h" static void hammer_parsedevs(const char *blkdevs, int oflags); -static void hammer_parsedevs_noverify(const char *blkdevs, int oflags); +static void __hammer_parsedevs(const char *blkdevs, int oflags, + int verify_volume, int verify_count); static void sigalrm(int signo); static void sigintr(int signo); static void usage(int exit_code); @@ -554,7 +555,7 @@ main(int ac, char **av) exit(0); } if (strcmp(av[0], "recover") == 0) { - hammer_parsedevs_noverify(blkdevs, O_RDONLY); + __hammer_parsedevs(blkdevs, O_RDONLY, 0, 1); hammer_cmd_recover(av + 1, ac - 1); exit(0); } @@ -569,7 +570,7 @@ main(int ac, char **av) exit(0); } if (strcmp(av[0], "strip") == 0) { - hammer_parsedevs(blkdevs, O_RDWR); + __hammer_parsedevs(blkdevs, O_RDWR, 0, 1); hammer_cmd_strip(); exit(0); } @@ -589,12 +590,13 @@ main(int ac, char **av) */ static void -__hammer_parsedevs(const char *blkdevs, int oflags, int verify) +__hammer_parsedevs(const char *blkdevs, int oflags, int verify_volume, + int verify_count) { volume_info_t volume = NULL; char *copy; char *volname; - int volnum = 0; + int vol_count = 0; if (blkdevs == NULL) { errx(1, "A -f blkdevs specification is required " @@ -608,29 +610,28 @@ __hammer_parsedevs(const char *blkdevs, int oflags, int verify) *copy++ = 0; volname = getdevpath(volname, 0); if (strchr(volname, ':')) { - __hammer_parsedevs(volname, oflags, verify); + __hammer_parsedevs(volname, oflags, verify_volume, + verify_count); } else { - volume = load_volume(volname, oflags, verify); + volume = load_volume(volname, oflags, verify_volume); assert(volume); - ++volnum; + ++vol_count; } free(volname); } free(copy); - /* - * All volumes have the same vol_count. - */ assert(volume); - if (volnum != volume->ondisk->vol_count) { - errx(1, "Volume header says %d volumes, but %d specified.", - volume->ondisk->vol_count, volnum); - /* not reached */ - } - - if (get_root_volume() == NULL) { - errx(1, "No root volume found"); - /* not reached */ + if (verify_count) { + if (vol_count != volume->ondisk->vol_count) { + errx(1, "Volume header says %d volumes, but %d specified.", + volume->ondisk->vol_count, vol_count); + /* not reached */ + } + if (get_root_volume() == NULL) { + errx(1, "No root volume found"); + /* not reached */ + } } } @@ -638,14 +639,7 @@ static __inline void hammer_parsedevs(const char *blkdevs, int oflags) { - __hammer_parsedevs(blkdevs, oflags, 1); -} - -static __inline -void -hammer_parsedevs_noverify(const char *blkdevs, int oflags) -{ - __hammer_parsedevs(blkdevs, oflags, 0); + __hammer_parsedevs(blkdevs, oflags, 1, 1); } static diff --git a/sbin/hammer/hammer_util.h b/sbin/hammer/hammer_util.h index 8607d0e2f5..b26d6ec7bd 100644 --- a/sbin/hammer/hammer_util.h +++ b/sbin/hammer/hammer_util.h @@ -120,7 +120,7 @@ extern uint32_t HammerVersion; extern const char *zone_labels[]; volume_info_t init_volume(const char *filename, int oflags, int32_t vol_no); -volume_info_t load_volume(const char *filename, int oflags, int verify); +volume_info_t load_volume(const char *filename, int oflags, int verify_volume); int is_regfile(const volume_info_t volume); void assert_volume_offset(const volume_info_t volume); volume_info_t get_volume(int32_t vol_no); diff --git a/sbin/hammer/ondisk.c b/sbin/hammer/ondisk.c index 0754ff93a1..d989c784b5 100644 --- a/sbin/hammer/ondisk.c +++ b/sbin/hammer/ondisk.c @@ -188,7 +188,7 @@ init_volume(const char *filename, int oflags, int32_t vol_no) * Initialize a volume structure and read ondisk volume header. */ volume_info_t -load_volume(const char *filename, int oflags, int verify) +load_volume(const char *filename, int oflags, int verify_volume) { volume_info_t volume; int n; @@ -206,7 +206,7 @@ load_volume(const char *filename, int oflags, int verify) if (valid_hammer_volumes++ == 0) Hammer_FSId = volume->ondisk->vol_fsid; - if (verify) + if (verify_volume) __verify_volume(volume); __add_volume(volume); -- 2.11.4.GIT