From: Andrew Price Date: Wed, 8 Jun 2016 11:55:11 +0100 Subject: [Cluster-devel] [gfs2_edit PATCH] gfs2_edit: Add destroy_all_meta for fsck testing In-Reply-To: <183055177.15137093.1465227165556.JavaMail.zimbra@redhat.com> References: <183055177.15137093.1465227165556.JavaMail.zimbra@redhat.com> Message-ID: List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi Bob, On 06/06/16 16:32, Bob Peterson wrote: > Hi, > > This patch adds a new option to gfs2_edit that destroys all the > metadata in a file system. Its sole purpose is for fsck testing > where multiple sets of metadata are restored to the same device, > to prevent accidental bleed-through from one to the next. > I deliberately left it off the tool "usage" so people aren't > tempted to try to misuse it (but that's open to negotiation). So my first reaction to this was uneasiness as it's adding a fairly destructive subcommand, and it's implemented amongst code which needs to avoid being destructive. I can see how it would be useful for testing though, and it's no more destructive than some existing gfs2_edit features, so I'm not going to nix it. That said, to reduce the possibility of future confusion/bugs I'd like to see the possible values of saveoption #defined as SAVEOPT_{DESTROY,SAVE,RGRPS,SLOW} or similar. Longer term, I'd also like gfs2_edit to only open the device O_RDWR if it absolutely needs to and O_RDONLY otherwise. (Tentative ACK) Thanks, Andy > > Regards, > > Bob Peterson > Red Hat File Systems > --- > Signed-off-by: Bob Peterson > > diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c > index 40a719e..adc6071 100644 > --- a/gfs2/edit/hexedit.c > +++ b/gfs2/edit/hexedit.c > @@ -2291,6 +2291,8 @@ static void parameterpass1(int argc, char *argv[], int i) > details = 1; > else if (!strcasecmp(argv[i], "savemeta")) > termlines = 0; > + else if (!strcasecmp(argv[i], "destroy_all_meta")) > + termlines = 0; > else if (!strcasecmp(argv[i], "savemetaslow")) > termlines = 0; > else if (!strcasecmp(argv[i], "savergs")) > @@ -2486,6 +2488,8 @@ static void process_parameters(int argc, char *argv[], int pass) > else if (!strcasecmp(argv[i], "savemeta")) { > getgziplevel(argv, &i); > savemeta(argv[i+2], 0, gziplevel); > + } else if (!strcasecmp(argv[i], "destroy_all_meta")) { > + savemeta(argv[i+1], -1, gziplevel); > } else if (!strcasecmp(argv[i], "savemetaslow")) { > getgziplevel(argv, &i); > savemeta(argv[i+2], 1, gziplevel); > diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c > index db9a947..0b60ba6 100644 > --- a/gfs2/edit/savemeta.c > +++ b/gfs2/edit/savemeta.c > @@ -61,6 +61,7 @@ static uint64_t blks_saved; > static uint64_t journal_blocks[MAX_JOURNALS_SAVED]; > static uint64_t gfs1_journal_size = 0; /* in blocks */ > static int journals_found = 0; > +static int destroy_all_meta = 0; > int print_level = MSG_NOTICE; > extern char *device; > > @@ -432,6 +433,11 @@ static int save_block(int fd, struct metafd *mfd, uint64_t blk, uint64_t owner) > return 0; /* Not metadata, and not system file, so skip it */ > } > > + if (destroy_all_meta) { > + memset(savebh->b_data, 0, blklen); > + bmodified(savebh); > + goto out; > + } > /* No need to save trailing zeroes */ > for (; blklen > 0 && savebh->b_data[blklen - 1] == '\0'; blklen--); > > @@ -459,6 +465,7 @@ static int save_block(int fd, struct metafd *mfd, uint64_t blk, uint64_t owner) > > blks_saved++; > free(savedata); > +out: > brelse(savebh); > return blktype; > } > @@ -795,7 +802,10 @@ void savemeta(char *out_fn, int saveoption, int gziplevel) > > sbd.md.journals = 1; > > - mfd = savemetaopen(out_fn, gziplevel); > + if (saveoption == -1) > + destroy_all_meta = 1; > + else > + mfd = savemetaopen(out_fn, gziplevel); > > blks_saved = 0; > if (sbd.gfs1) > @@ -820,10 +830,12 @@ void savemeta(char *out_fn, int saveoption, int gziplevel) > exit(1); > > /* Write the savemeta file header */ > - err = save_header(&mfd, sbd.fssize * sbd.bsize); > - if (err) { > - perror("Failed to write metadata file header"); > - exit(1); > + if (saveoption != -1) { > + err = save_header(&mfd, sbd.fssize * sbd.bsize); > + if (err) { > + perror("Failed to write metadata file header"); > + exit(1); > + } > } > /* Save off the superblock */ > save_block(sbd.device_fd, &mfd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK / sbd.bsize, 0); > @@ -879,7 +891,8 @@ void savemeta(char *out_fn, int saveoption, int gziplevel) > } else { > printf("(uncompressed).\n"); > } > - savemetaclose(&mfd); > + if (saveoption != -1) > + savemetaclose(&mfd); > close(sbd.device_fd); > destroy_per_node_lookup(); > free(indirect); >