[Cluster-devel] [gfs2_edit PATCH] gfs2_edit: Add destroy_all_meta for fsck testing
Bob Peterson
rpeterso at redhat.com
Mon Jun 6 15:32:45 UTC 2016
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).
Regards,
Bob Peterson
Red Hat File Systems
---
Signed-off-by: Bob Peterson <rpeterso at redhat.com>
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);
More information about the Cluster-devel
mailing list