gfs2-utils: RHEL7 - gfs2_edit: print LB (log descriptor continuation blocks) for GFS2
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=674b743c...
Commit: 674b743c39a6582b124634557f9c2850b9b19c63
Parent: 1ba7c543792e524e1a84a8cd6aa365919ee33427
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Tue Jun 10 11:32:29 2014 -0500
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:21:40 2014 +0100
gfs2_edit: print LB (log descriptor continuation blocks) for GFS2
This patch allows gfs2_edit to print metadata blocks of type LB
(log descriptor continuation blocks) for GFS2. Prior to this, only
GFS1's continuation blocks would print.
---
gfs2/edit/journal.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/gfs2/edit/journal.c b/gfs2/edit/journal.c
index e012bc3..bb56649 100644
--- a/gfs2/edit/journal.c
+++ b/gfs2/edit/journal.c
@@ -582,12 +582,15 @@ void dump_journal(const char *journal, int tblk)
" [UNMOUNTED]" : "");
}
eol(0);
- } else if (sbd.gfs1 && ld_blocks > 0) {
- print_gfs2("0x%llx (j+%4llx): GFS log descriptor"
+ } else if ((ld_blocks > 0) &&
+ (sbd.gfs1 || block_type == GFS2_METATYPE_LB)) {
+ print_gfs2("0x%llx (j+%4llx): Log descriptor"
" continuation block", abs_block, jb);
eol(0);
print_gfs2(" ");
- ld_blocks -= print_ld_blks((uint64_t *)dummy_bh.b_data,
+ ld_blocks -= print_ld_blks((uint64_t *)dummy_bh.b_data +
+ (sbd.gfs1 ? 0 :
+ sizeof(struct gfs2_meta_header)),
(dummy_bh.b_data +
sbd.bsize), start_line,
tblk, &tblk_off, 0, rgd,
9 years, 8 months
gfs2-utils: RHEL7 - libgfs2: Zero de_inum.no_addr when deleting dirents
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=1ba7c543...
Commit: 1ba7c543792e524e1a84a8cd6aa365919ee33427
Parent: d3b234ae80910f40a3450c6a9ac852f6d8e2b453
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Jun 5 10:53:07 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:16:23 2014 +0100
libgfs2: Zero de_inum.no_addr when deleting dirents
libgfs2 left deleted dirents in leaf blocks which have been split, which
is fine, but it only zeroed the no_formal_ino field, causing gfs2_edit
to display deleted dirents when printing leaf blocks. Zero the no_addr
field too, as the kernel code does.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/fs_ops.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index fdd4438..015b974 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -826,6 +826,7 @@ void dirent2_del(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
dip->i_di.di_entries--;
}
if (!prev) {
+ cur->de_inum.no_addr = 0;
cur->de_inum.no_formal_ino = 0;
return;
}
9 years, 8 months
gfs2-utils: RHEL7 - gfs2-utils tests: Add small-block savemeta tests
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=d3b234ae...
Commit: d3b234ae80910f40a3450c6a9ac852f6d8e2b453
Parent: 19d15306a16ebc520bf87de711b3a5999f1c24e9
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Jun 5 01:51:21 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:16:23 2014 +0100
gfs2-utils tests: Add small-block savemeta tests
Add some savemeta/restoremeta test scenarios which were used to discover
some recently fixed bugs, to make sure they stay fixed. They mainly cover
scenarios relating to small block sizes.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
tests/edit.at | 32 ++++++++++++++++++++++++++++++--
1 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/tests/edit.at b/tests/edit.at
index e2a702c..49f4a58 100644
--- a/tests/edit.at
+++ b/tests/edit.at
@@ -1,7 +1,7 @@
AT_TESTED([gfs2_edit])
AT_BANNER([gfs2_edit tests])
-AT_SETUP([Savemeta/restoremeta, defaults])
+AT_SETUP([Save/restoremeta, defaults])
GFS_TGT_REGEN
AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT $(($(gfs_max_blocks 4096)/2))], 0, [ignore], [ignore])
AT_CHECK([gfs2_edit savemeta $GFS_TGT test.meta > savemeta.log], 0, [ignore], [ignore])
@@ -13,10 +13,38 @@ AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
AT_CLEANUP
-AT_SETUP([Savemeta/restoremeta, no compression])
+AT_SETUP([Save/restoremeta, no compression])
GFS_TGT_REGEN
AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT $(($(gfs_max_blocks 4096)/2))], 0, [ignore], [ignore])
AT_CHECK([gfs2_edit savemeta -z0 $GFS_TGT test.meta], 0, [ignore], [ignore])
+GFS_TGT_REGEN
+AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
+AT_CLEANUP
+
+AT_SETUP([Save/restoremeta, min. block size])
+GFS_TGT_REGEN
+AT_CHECK([$GFS_MKFS -p lock_nolock -b512 $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit savemeta -z0 $GFS_TGT test.meta], 0, [ignore], [ignore])
+GFS_TGT_REGEN
+AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
+AT_CLEANUP
+
+AT_SETUP([Save/restoremeta, 4 journals])
+GFS_TGT_REGEN
+AT_CHECK([$GFS_MKFS -p lock_nolock -j4 -J8 $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit savemeta -z0 $GFS_TGT test.meta], 0, [ignore], [ignore])
+GFS_TGT_REGEN
+AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
+AT_CLEANUP
+
+AT_SETUP([Save/restoremeta, min. block size, 4 journals])
+GFS_TGT_REGEN
+AT_CHECK([$GFS_MKFS -p lock_nolock -b512 -j4 -J8 $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit savemeta -z0 $GFS_TGT test.meta], 0, [ignore], [ignore])
+GFS_TGT_REGEN
AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
AT_CLEANUP
9 years, 8 months
gfs2-utils: RHEL7 - gfs2_edit: Ensure all leaf blocks in per_node are saved
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=19d15306...
Commit: 19d15306a16ebc520bf87de711b3a5999f1c24e9
Parent: b5beeb415bc9db80c9d6a896c958e9987b9a1e10
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Jun 5 01:41:13 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:16:23 2014 +0100
gfs2_edit: Ensure all leaf blocks in per_node are saved
block_is_in_per_node() only checks the first leaf block when the
per_node directory has been split (when the block size is small and/or
the number of journals is large). This caused savemeta to treat the
files in per_node as user data and so didn't save their metadata. Add an
outer loop to iterate over the indirect blocks.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/savemeta.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index a43045f..360b144 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -75,7 +75,7 @@ static int block_is_a_journal(void)
static int block_is_in_per_node(void)
{
- int d;
+ int i;
struct gfs2_inode *per_node_di;
if (sbd.gfs1)
@@ -90,9 +90,12 @@ static int block_is_in_per_node(void)
do_dinode_extended(&per_node_di->i_di, per_node_di->i_bh);
inode_put(&per_node_di);
- for (d = 0; d < indirect->ii[0].dirents; d++) {
- if (block == indirect->ii[0].dirent[d].block)
- return TRUE;
+ for (i = 0; i < indirect_blocks; i++) {
+ int d;
+ for (d = 0; d < indirect->ii[i].dirents; d++) {
+ if (block == indirect->ii[i].dirent[d].block)
+ return TRUE;
+ }
}
return FALSE;
}
9 years, 8 months
gfs2-utils: RHEL7 - gfs2-utils: Fix two logic errors
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=b5beeb41...
Commit: b5beeb415bc9db80c9d6a896c958e9987b9a1e10
Parent: 3bd4606e134132f1f0d49a1900f4e98b6cb3c2d7
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Jun 5 01:35:44 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:16:22 2014 +0100
gfs2-utils: Fix two logic errors
Two uses of lgfs2_get_leaf_ptr() were still expecting it to return 0 on
failure. Remove the negations.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/savemeta.c | 2 +-
gfs2/fsck/pass2.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index e336100..a43045f 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -542,7 +542,7 @@ static void save_inode_data(struct metafd *mfd)
int li;
for (li = 0; li < (1 << inode->i_di.di_depth); li++) {
- if (!lgfs2_get_leaf_ptr(inode, li, &leaf_no)) {
+ if (lgfs2_get_leaf_ptr(inode, li, &leaf_no)) {
fprintf(stderr, "Could not read leaf index %d in dinode %"PRIu64"\n", li,
(uint64_t)inode->i_di.di_num.no_addr);
exit(-1);
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 2474ccb..2971b8c 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -370,7 +370,7 @@ static int wrong_leaf(struct gfs2_inode *ip, struct gfs2_inum *entry,
de->de_type) == 0) {
log_err(_("The misplaced directory entry was moved to a "
"valid leaf block.\n"));
- if (!lgfs2_get_leaf_ptr(ip, hash_index, &real_leaf)) {
+ if (lgfs2_get_leaf_ptr(ip, hash_index, &real_leaf)) {
log_err(_("Could not read leaf %d in dinode %"PRIu64": %s\n"), hash_index,
(uint64_t)ip->i_di.di_num.no_addr, strerror(errno));
}
9 years, 8 months
gfs2-utils: RHEL7 - gfs2_edit: Fix parsing the savemeta -z option
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=3bd4606e...
Commit: 3bd4606e134132f1f0d49a1900f4e98b6cb3c2d7
Parent: dca58e4a2913daceb1738baa21d99a2d824e75f8
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon May 19 15:40:49 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:15:57 2014 +0100
gfs2_edit: Fix parsing the savemeta -z option
Specifying -z0 instead of -z 0 could confuse gfs2_edit to the point
where it would call ftruncate on the filesystem instead of the output
file. Fix up the -z parsing function to recognise when the space is
omitted and avoid calling ftruncate on the wrong file.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/hexedit.c | 26 ++++++++++++++++----------
tests/edit.at | 7 +++++++
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 53a816d..0982f7b 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -2608,19 +2608,25 @@ static void usage(void)
*/
static void getgziplevel(char *argv[], int *i)
{
+ char *opt, *arg;
char *endptr;
- (*i)++;
- if (!strcasecmp(argv[*i], "-z")) {
- (*i)++;
- errno = 0;
- gziplevel = strtol(argv[*i], &endptr, 10);
- if (errno || endptr == argv[*i] || gziplevel < 0 || gziplevel > 9) {
- fprintf(stderr, "Compression level out of range: %s\n", argv[*i]);
- exit(-1);
- }
+
+ arg = argv[1 + *i];
+ if (strncmp(arg, "-z", 2)) {
+ return;
+ } else if (arg[2] != '\0') {
+ opt = &arg[2];
} else {
- (*i)--;
+ (*i)++;
+ opt = argv[1 + *i];
+ }
+ errno = 0;
+ gziplevel = strtol(opt, &endptr, 10);
+ if (errno || endptr == opt || gziplevel < 0 || gziplevel > 9) {
+ fprintf(stderr, "Compression level out of range: %s\n", opt);
+ exit(-1);
}
+ (*i)++;
}
/* ------------------------------------------------------------------------ */
diff --git a/tests/edit.at b/tests/edit.at
index 3428d64..e2a702c 100644
--- a/tests/edit.at
+++ b/tests/edit.at
@@ -11,5 +11,12 @@ Reading resource groups...Done. File system size: 4.1023GB
GFS_TGT_REGEN
AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
+AT_CLEANUP
+AT_SETUP([Savemeta/restoremeta, no compression])
+GFS_TGT_REGEN
+AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT $(($(gfs_max_blocks 4096)/2))], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit savemeta -z0 $GFS_TGT test.meta], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
AT_CLEANUP
9 years, 8 months
gfs2-utils: RHEL7 - gfs2_edit: savemeta and restoremeta improvements
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=dca58e4a...
Commit: dca58e4a2913daceb1738baa21d99a2d824e75f8
Parent: 39a4a68fe4f462686d488a0e49c368a314c03f5c
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon May 19 11:57:08 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:15:39 2014 +0100
gfs2_edit: savemeta and restoremeta improvements
This adds various improvements to savemeta and restoremeta including:
- Made the saved_metablock buffer a flexible array to make better use of
sizeof() etc.
- Read/write saved_metablock structures with one read/write call instead
of one per field (gives a small perf improvement).
- Factor out the block restore code and split the "find highest block"
code out of restore_data.
- Print more, clearer information relating to the metadata file,
progress made and errors.
- Made global variables static, removed unused ones.
- Improved code clarity, separation of concerns.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/savemeta.c | 474 +++++++++++++++++++++++++++-----------------------
tests/edit.at | 2 +-
2 files changed, 255 insertions(+), 221 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index a10da19..e336100 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -27,7 +27,6 @@
#include "hexedit.h"
#include "libgfs2.h"
-#define BUFSIZE (4096)
#define DFT_SAVE_FILE "/tmp/gfsmeta.XXXXXX"
#define MAX_JOURNALS_SAVED 256
@@ -45,8 +44,11 @@ struct savemeta_header {
struct saved_metablock {
uint64_t blk;
uint16_t siglen; /* significant data length */
- char buf[BUFSIZE];
-};
+ char buf[];
+/* This needs to be packed because old versions of gfs2_edit read and write the
+ individual fields separately, so the hole after siglen must be eradicated
+ before the struct reflects what's on disk. */
+} __attribute__((__packed__));
struct metafd {
int fd;
@@ -55,15 +57,12 @@ struct metafd {
int gziplevel;
};
-struct saved_metablock *savedata;
-uint64_t last_reported_block, blks_saved, total_out, pct;
-uint64_t journal_blocks[MAX_JOURNALS_SAVED];
-uint64_t gfs1_journal_size = 0; /* in blocks */
-int journals_found = 0;
+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;
int print_level = MSG_NOTICE;
-extern void read_superblock(void);
-
static int block_is_a_journal(void)
{
int j;
@@ -121,7 +120,7 @@ static const char *anthropomorphize(unsigned long long inhuman_value)
remainder = val % 1024;
val /= 1024;
}
- sprintf(out_val, "%llu.%llu%c", val, remainder, symbols[i]);
+ sprintf(out_val, "%llu.%llu%cB", val, remainder, symbols[i]);
return out_val;
}
@@ -223,8 +222,7 @@ static void warm_fuzzy_stuff(uint64_t wfsblock, int force)
{
static struct timeval tv;
static uint32_t seconds = 0;
-
- last_reported_block = wfsblock;
+
gettimeofday(&tv, NULL);
if (!seconds)
seconds = tv.tv_sec;
@@ -235,8 +233,7 @@ static void warm_fuzzy_stuff(uint64_t wfsblock, int force)
if (sbd.fssize) {
printf("\r");
percent = (wfsblock * 100) / sbd.fssize;
- printf("%llu inodes processed, %llu blocks saved "
- "(%llu%%) processed, ",
+ printf("%llu blocks processed, %llu saved (%llu%%)",
(unsigned long long)wfsblock,
(unsigned long long)blks_saved,
(unsigned long long)percent);
@@ -339,10 +336,10 @@ static int savemetaclose(struct metafd *mfd)
static int save_block(int fd, struct metafd *mfd, uint64_t blk)
{
- int blktype, blklen, outsz;
- uint16_t trailing0;
- char *p;
+ int blktype, blklen;
+ size_t outsz;
struct gfs2_buffer_head *savebh;
+ struct saved_metablock *savedata;
if (gfs2_check_range(&sbd, blk) && blk != sbd.sb_addr) {
fprintf(stderr, "\nWarning: bad block pointer '0x%llx' "
@@ -351,9 +348,7 @@ static int save_block(int fd, struct metafd *mfd, uint64_t blk)
(unsigned long long)block, (unsigned long long)block);
return 0;
}
- memset(savedata, 0, sizeof(struct saved_metablock));
savebh = bread(&sbd, blk);
- memcpy(&savedata->buf, savebh->b_data, sbd.bsize);
/* If this isn't metadata and isn't a system file, we don't want it.
Note that we're checking "block" here rather than blk. That's
@@ -365,43 +360,34 @@ static int save_block(int fd, struct metafd *mfd, uint64_t blk)
brelse(savebh);
return 0; /* Not metadata, and not system file, so skip it */
}
- trailing0 = 0;
- p = &savedata->buf[blklen - 1];
- while (*p=='\0' && trailing0 < sbd.bsize) {
- trailing0++;
- p--;
+
+ /* No need to save trailing zeroes */
+ for (; blklen > 0 && savebh->b_data[blklen - 1] == '\0'; blklen--);
+
+ if (blklen == 0) /* No significant data; skip. */
+ return 0;
+
+ outsz = sizeof(*savedata) + blklen;
+ savedata = calloc(1, outsz);
+ if (savedata == NULL) {
+ perror("Failed to save block");
+ exit(1);
}
savedata->blk = cpu_to_be64(blk);
- if (savemetawrite(mfd, &savedata->blk, sizeof(savedata->blk)) !=
- sizeof(savedata->blk)) {
- fprintf(stderr, "write error: %s from %s:%d: "
- "block %lld (0x%llx)\n", strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)savedata->blk,
- (unsigned long long)savedata->blk);
- exit(-1);
- }
- outsz = blklen - trailing0;
- savedata->siglen = cpu_to_be16(outsz);
- if (savemetawrite(mfd, &savedata->siglen, sizeof(savedata->siglen)) !=
- sizeof(savedata->siglen)) {
- fprintf(stderr, "write error: %s from %s:%d: "
- "block %lld (0x%llx)\n", strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)savedata->blk,
- (unsigned long long)savedata->blk);
- exit(-1);
- }
- if (savemetawrite(mfd, savedata->buf, outsz) != outsz) {
- fprintf(stderr, "write error: %s from %s:%d: "
- "block %lld (0x%llx)\n", strerror(errno),
- __FUNCTION__, __LINE__,
+ savedata->siglen = cpu_to_be16(blklen);
+ memcpy(savedata->buf, savebh->b_data, blklen);
+
+ if (savemetawrite(mfd, savedata, outsz) != outsz) {
+ fprintf(stderr, "write error: %s from %s:%d: block %lld (0x%llx)\n",
+ strerror(errno), __FUNCTION__, __LINE__,
(unsigned long long)savedata->blk,
(unsigned long long)savedata->blk);
+ free(savedata);
exit(-1);
}
- total_out += sizeof(savedata->blk) + sizeof(savedata->siglen) + outsz;
+
blks_saved++;
+ free(savedata);
brelse(savebh);
return blktype;
}
@@ -701,6 +687,7 @@ static int read_header(gzFile gzin_fd, struct savemeta_header *smh)
size_t rs;
struct savemeta_header smh_be = {0};
+ gzseek(gzin_fd, 0, SEEK_SET);
rs = gzread(gzin_fd, &smh_be, sizeof(smh_be));
if (rs == -1) {
perror("Failed to read savemeta file header");
@@ -721,8 +708,7 @@ static int check_header(struct savemeta_header *smh)
{
if (smh->sh_magic != SAVEMETA_MAGIC || smh->sh_format > SAVEMETA_FORMAT)
return -1;
- printf("Savemeta file format %"PRIu32"\n", smh->sh_format);
- printf("Created %s\n", ctime((time_t *)&smh->sh_time));
+ printf("Metadata saved at %s", ctime((time_t *)&smh->sh_time)); /* ctime() adds \n */
printf("File system size %s\n", anthropomorphize(smh->sh_fs_bytes));
return 0;
}
@@ -741,14 +727,10 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
mfd = savemetaopen(out_fn, gziplevel);
- savedata = malloc(sizeof(struct saved_metablock));
- if (!savedata)
- die("Can't allocate memory for the operation.\n");
-
lseek(sbd.device_fd, 0, SEEK_SET);
- blks_saved = total_out = last_reported_block = 0;
+ blks_saved = 0;
if (!sbd.gfs1)
- sbd.bsize = BUFSIZE;
+ sbd.bsize = GFS2_DEFAULT_BSIZE;
if (lgfs2_get_dev_info(sbd.device_fd, &sbd.dinfo)) {
perror(sbd.device_name);
exit(-1);
@@ -864,7 +846,6 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
} else {
printf("(uncompressed).\n");
}
- free(savedata);
savemetaclose(&mfd);
close(sbd.device_fd);
free(indirect);
@@ -872,174 +853,227 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
exit(0);
}
-static int restore_data(int fd, gzFile gzin_fd, int printblocksonly,
- int find_highblk, const int startpos)
+static off_t restore_init(gzFile gzfd, struct savemeta_header *smh)
{
+ int err;
+ unsigned i;
size_t rs;
- uint64_t buf64, writes = 0, highest_valid_block = 0;
- uint16_t buf16;
- int first = 1, pos, gzerr;
- char rdbuf[256];
- char gfs_superblock_id[8] = {0x01, 0x16, 0x19, 0x70,
- 0x00, 0x00, 0x00, 0x01};
-
- if (!printblocksonly)
- lseek(fd, 0, SEEK_SET);
- gzseek(gzin_fd, startpos, SEEK_SET);
- rs = gzread(gzin_fd, rdbuf, sizeof(rdbuf));
- if (rs != sizeof(rdbuf)) {
+ char buf[256];
+ off_t startpos = 0;
+ struct saved_metablock *svb;
+ struct gfs2_meta_header *sbmh;
+
+ err = read_header(gzfd, smh);
+ if (err < 0) {
+ exit(1);
+ } else if (check_header(smh) != 0) {
+ printf("No valid file header found. Falling back to old format...\n");
+ } else if (err == 0) {
+ startpos = sizeof(*smh);
+ }
+
+ gzseek(gzfd, startpos, SEEK_SET);
+ rs = gzread(gzfd, buf, sizeof(buf));
+ if (rs != sizeof(buf)) {
fprintf(stderr, "Error: File is too small.\n");
- return -1;
+ exit(1);
}
- for (pos = startpos; pos < startpos + sizeof(rdbuf) - sizeof(uint64_t) - sizeof(uint16_t);
- pos++) {
- if (!memcmp(&rdbuf[pos + sizeof(uint64_t) + sizeof(uint16_t)],
- gfs_superblock_id, sizeof(gfs_superblock_id))) {
+ /* Scan for the beginning of the file body. Required to support old formats(?). */
+ for (i = 0; i < (256 - sizeof(*svb) - sizeof(*sbmh)); i++) {
+ svb = (struct saved_metablock *)&buf[i];
+ sbmh = (struct gfs2_meta_header *)svb->buf;
+ if (sbmh->mh_magic == cpu_to_be32(GFS2_MAGIC) &&
+ sbmh->mh_type == cpu_to_be32(GFS2_METATYPE_SB))
break;
+ }
+ if (i == (sizeof(buf) - sizeof(*svb) - sizeof(*sbmh)))
+ i = 0;
+ return startpos + i; /* File offset of saved sb */
+}
+
+
+static int restore_block(gzFile gzfd, struct saved_metablock *svb, uint16_t maxlen)
+{
+ int gzerr;
+ int ret;
+ uint16_t checklen;
+ const char *errstr;
+
+ ret = gzread(gzfd, svb, sizeof(*svb));
+ if (ret < sizeof(*svb)) {
+ goto gzread_err;
+ }
+ svb->blk = be64_to_cpu(svb->blk);
+ svb->siglen = be16_to_cpu(svb->siglen);
+
+ if (sbd.fssize && svb->blk >= sbd.fssize) {
+ fprintf(stderr, "Error: File system is too small to restore this metadata.\n");
+ fprintf(stderr, "File system is %llu blocks. Restore block = %llu\n",
+ (unsigned long long)sbd.fssize, (unsigned long long)svb->blk);
+ return -1;
+ }
+
+ if (maxlen)
+ checklen = maxlen;
+ else
+ checklen = sbd.bsize;
+
+ if (checklen && svb->siglen > checklen) {
+ fprintf(stderr, "Bad record length: %u for block %"PRIu64" (0x%"PRIx64").\n",
+ svb->siglen, svb->blk, svb->blk);
+ return -1;
+ }
+
+ if (maxlen) {
+ ret = gzread(gzfd, svb + 1, svb->siglen);
+ if (ret < svb->siglen) {
+ goto gzread_err;
}
}
- if (pos == startpos + sizeof(rdbuf) - sizeof(uint64_t) - sizeof(uint16_t))
- pos = startpos;
- if (gzseek(gzin_fd, pos, SEEK_SET) != pos) {
- fprintf(stderr, "bad seek: %s from %s:%d: "
- "offset %lld (0x%llx)\n", strerror(errno),
- __FUNCTION__, __LINE__, (unsigned long long)pos,
- (unsigned long long)pos);
- exit(-1);
+
+ return 0;
+
+gzread_err:
+ if (gzeof(gzfd))
+ return 1;
+
+ errstr = gzerror(gzfd, &gzerr);
+ if (gzerr == Z_ERRNO)
+ errstr = strerror(errno);
+ fprintf(stderr, "Failed to restore block: %s\n", errstr);
+ return -1;
+}
+
+static int restore_super(gzFile gzfd, off_t pos)
+{
+ int ret;
+ struct saved_metablock *svb;
+ struct gfs2_buffer_head dummy_bh;
+ size_t len = sizeof(*svb) + sizeof(struct gfs2_sb);
+
+ svb = calloc(1, len);
+ if (svb == NULL) {
+ perror("Failed to restore super block");
+ exit(1);
}
- blks_saved = total_out = 0;
- while (TRUE) {
- struct gfs2_buffer_head dummy_bh;
+ gzseek(gzfd, pos, SEEK_SET);
+ ret = restore_block(gzfd, svb, sizeof(struct gfs2_sb));
+ if (ret == 1) {
+ fprintf(stderr, "Reached end of file while restoring superblock\n");
+ goto err;
+ } else if (ret != 0) {
+ goto err;
+ }
+
+ dummy_bh.b_data = (char *)svb->buf;
+ gfs2_sb_in(&sbd.sd_sb, &dummy_bh);
+ sbd1 = (struct gfs_sb *)&sbd.sd_sb;
+ ret = check_sb(&sbd.sd_sb);
+ if (ret < 0) {
+ fprintf(stderr,"Error: Invalid superblock data.\n");
+ goto err;
+ }
+ if (ret == 1)
+ sbd.gfs1 = 1;
+ sbd.bsize = sbd.sd_sb.sb_bsize;
+ free(svb);
+ printf("Block size is %uB\n", sbd.bsize);
+ return 0;
+err:
+ free(svb);
+ return -1;
+}
+
+static int find_highest_block(gzFile gzfd, off_t pos, uint64_t fssize)
+{
+ int err = 0;
+ uint64_t highest = 0;
+ struct saved_metablock svb = {0};
- memset(savedata, 0, sizeof(struct saved_metablock));
- rs = gzread(gzin_fd, &buf64, sizeof(uint64_t));
- if (!rs)
+ while (1) {
+ gzseek(gzfd, pos, SEEK_SET);
+ err = restore_block(gzfd, &svb, 0);
+ if (err == 1)
break;
- if (rs != sizeof(uint64_t)) {
- fprintf(stderr, "Error reading from file.\n");
- return -1;
- }
- total_out += sbd.bsize;
- savedata->blk = be64_to_cpu(buf64);
- if (!printblocksonly &&
- sbd.fssize && savedata->blk >= sbd.fssize) {
- fprintf(stderr, "Error: File system is too small to "
- "restore this metadata.\n");
- fprintf(stderr, "File system is %llu blocks, ",
- (unsigned long long)sbd.fssize);
- fprintf(stderr, "Restore block = %llu\n",
- (unsigned long long)savedata->blk);
+ if (err != 0)
return -1;
- }
- if (gzread(gzin_fd, &buf16, sizeof(uint16_t)) !=
- sizeof(uint16_t)) {
- fprintf(stderr, "read error: %s from %s:%d: "
- "block %lld (0x%llx)\n",
- gzerror(gzin_fd, &gzerr), __FUNCTION__, __LINE__,
- (unsigned long long)savedata->blk,
- (unsigned long long)savedata->blk);
- exit(-1);
- }
- savedata->siglen = be16_to_cpu(buf16);
- if (savedata->siglen > sizeof(savedata->buf)) {
- fprintf(stderr, "\nBad record length: %d for block #%llu"
- " (0x%llx).\n", savedata->siglen,
- (unsigned long long)savedata->blk,
- (unsigned long long)savedata->blk);
+
+ if (svb.blk > highest)
+ highest = svb.blk;
+ pos += sizeof(svb) + svb.siglen;
+ }
+
+ if (fssize > 0) {
+ printf("Saved file system size is %"PRIu64" (0x%"PRIx64") blocks, %s\n",
+ fssize, fssize, anthropomorphize(fssize * sbd.bsize));
+ sbd.fssize = fssize;
+ } else {
+ sbd.fssize = highest + 1;
+ }
+
+ printf("Highest saved block is %"PRIu64" (0x%"PRIx64")\n", highest, highest);
+ return 0;
+}
+
+static int restore_data(int fd, gzFile gzin_fd, off_t pos, int printonly)
+{
+ struct saved_metablock *savedata;
+ size_t insz = sizeof(*savedata) + sbd.bsize;
+ uint64_t writes = 0;
+
+ savedata = calloc(1, insz);
+ if (savedata == NULL) {
+ perror("Failed to restore data");
+ exit(1);
+ }
+
+ gzseek(gzin_fd, pos, SEEK_SET);
+ blks_saved = 0;
+ while (TRUE) {
+ int err;
+ err = restore_block(gzin_fd, savedata, sbd.bsize);
+ if (err == 1)
+ break;
+ if (err != 0) {
+ free(savedata);
return -1;
}
- if (savedata->siglen &&
- gzread(gzin_fd, savedata->buf, savedata->siglen) !=
- savedata->siglen) {
- fprintf(stderr, "read error: %s from %s:%d: "
- "block %lld (0x%llx)\n",
- gzerror(gzin_fd, &gzerr), __FUNCTION__, __LINE__,
- (unsigned long long)savedata->blk,
- (unsigned long long)savedata->blk);
- exit(-1);
- }
- if (first) {
- struct gfs2_sb bufsb;
- int ret;
-
- dummy_bh.b_data = (char *)&bufsb;
- memcpy(&bufsb, savedata->buf, sizeof(bufsb));
- gfs2_sb_in(&sbd.sd_sb, &dummy_bh);
- sbd1 = (struct gfs_sb *)&sbd.sd_sb;
- ret = check_sb(&sbd.sd_sb);
- if (ret < 0) {
- fprintf(stderr,"Error: Invalid superblock data.\n");
- return -1;
- }
- if (ret == 1)
- sbd.gfs1 = TRUE;
- sbd.bsize = sbd.sd_sb.sb_bsize;
- if (find_highblk)
- ;
- else if (!printblocksonly) {
- sbd.fssize =
- lseek(fd, 0, SEEK_END) / sbd.bsize;
- printf("There are %llu blocks of %u bytes in "
- "the destination device.\n\n",
- (unsigned long long)sbd.fssize, sbd.bsize);
- } else {
- printf("This is %s metadata\n", sbd.gfs1 ?
- "gfs (not gfs2)" : "gfs2");
- }
- first = 0;
- }
- bh = &dummy_bh;
- bh->b_data = savedata->buf;
- if (savedata->blk > highest_valid_block)
- highest_valid_block = savedata->blk;
- if (find_highblk)
- ;
- else if (printblocksonly) {
+
+ if (printonly) {
+ struct gfs2_buffer_head dummy_bh;
+ dummy_bh.b_data = savedata->buf;
+ bh = &dummy_bh;
block = savedata->blk;
- if (printblocksonly > 1 && printblocksonly == block) {
+ if (printonly > 1 && printonly == block) {
block_in_mem = block;
display(0, 0, 0, 0);
bh = NULL;
- return 0;
- } else if (printblocksonly == 1) {
- print_gfs2("%d (l=0x%x): ", blks_saved,
- savedata->siglen);
+ break;
+ } else if (printonly == 1) {
+ print_gfs2("%d (l=0x%x): ", blks_saved, savedata->siglen);
display_block_type(TRUE);
}
+ bh = NULL;
} else {
warm_fuzzy_stuff(savedata->blk, FALSE);
- if (savedata->blk >= sbd.fssize) {
- printf("\nOut of space on the destination "
- "device; quitting.\n");
- bh = NULL;
- break;
- }
+ memset(savedata->buf + savedata->siglen, 0, sbd.bsize - savedata->siglen);
if (pwrite(fd, savedata->buf, sbd.bsize, savedata->blk * sbd.bsize) != sbd.bsize) {
- fprintf(stderr, "write error: %s from "
- "%s:%d: block %lld (0x%llx)\n",
- strerror(errno), __FUNCTION__,
- __LINE__,
+ fprintf(stderr, "write error: %s from %s:%d: block %lld (0x%llx)\n",
+ strerror(errno), __FUNCTION__, __LINE__,
(unsigned long long)savedata->blk,
(unsigned long long)savedata->blk);
- exit(-1);
+ free(savedata);
+ return -1;
}
writes++;
if (writes % 1000 == 0)
fsync(fd);
}
blks_saved++;
- /* Don't leave a dangling reference to our local dummy_bh */
- bh = NULL;
- }
- if (!printblocksonly && !find_highblk)
- warm_fuzzy_stuff(sbd.fssize, TRUE);
- if (find_highblk && startpos == 0) {
- printf("File system size: %lld (0x%llx) blocks, aka %sB\n",
- (unsigned long long)highest_valid_block,
- (unsigned long long)highest_valid_block,
- anthropomorphize(highest_valid_block * sbd.bsize));
- sbd.fssize = highest_valid_block;
}
+ if (!printonly)
+ warm_fuzzy_stuff(sbd.fssize, 1);
+ free(savedata);
return 0;
}
@@ -1050,56 +1084,56 @@ static void complain(const char *complaint)
"<dest file system>\n");
}
-void restoremeta(const char *in_fn, const char *out_device,
- uint64_t printblocksonly)
+void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly)
{
int error;
gzFile gzfd;
- int startpos = 0;
+ off_t pos = 0;
struct savemeta_header smh = {0};
termlines = 0;
if (!in_fn)
complain("No source file specified.");
- if (!printblocksonly && !out_device)
+ if (!printonly && !out_device)
complain("No destination file system specified.");
+
gzfd = gzopen(in_fn, "rb");
if (!gzfd)
die("Can't open source file %s: %s\n",
in_fn, strerror(errno));
- if (!printblocksonly) {
+ if (!printonly) {
sbd.device_fd = open(out_device, O_RDWR);
if (sbd.device_fd < 0)
die("Can't open destination file system %s: %s\n",
out_device, strerror(errno));
} else if (out_device) /* for printsavedmeta, the out_device is an
optional block no */
- printblocksonly = check_keywords(out_device);
- savedata = malloc(sizeof(struct saved_metablock));
- if (!savedata)
- die("Can't allocate memory for the restore operation.\n");
-
- gzseek(gzfd, 0, SEEK_SET);
- error = read_header(gzfd, &smh);
- if (error < 0) {
+ printonly = check_keywords(out_device);
+
+ pos = restore_init(gzfd, &smh);
+ error = restore_super(gzfd, pos);
+ if (error)
exit(1);
- } else if (check_header(&smh) != 0) {
- printf("No valid file header found. Falling back to old format...\n");
- gzseek(gzfd, 0, SEEK_SET);
- } else if (error == 0) {
- startpos = sizeof(smh);
+
+ printf("This is gfs%c metadata.\n", sbd.gfs1 ? '1': '2');
+
+ if (!printonly) {
+ uint64_t space = lseek(sbd.device_fd, 0, SEEK_END) / sbd.bsize;
+ printf("There are %"PRIu64" free blocks on the destination device.\n", space);
}
- blks_saved = 0;
- restore_data(sbd.device_fd, gzfd, printblocksonly, 1, startpos);
- error = restore_data(sbd.device_fd, gzfd, printblocksonly, 0, startpos);
+ error = find_highest_block(gzfd, pos, sbd.fssize);
+ if (error)
+ exit(1);
+
+ error = restore_data(sbd.device_fd, gzfd, pos, printonly);
printf("File %s %s %s.\n", in_fn,
- (printblocksonly ? "print" : "restore"),
+ (printonly ? "print" : "restore"),
(error ? "error" : "successful"));
- free(savedata);
+
gzclose(gzfd);
- if (!printblocksonly)
+ if (!printonly)
close(sbd.device_fd);
free(indirect);
exit(error);
diff --git a/tests/edit.at b/tests/edit.at
index 014d118..3428d64 100644
--- a/tests/edit.at
+++ b/tests/edit.at
@@ -6,7 +6,7 @@ GFS_TGT_REGEN
AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT $(($(gfs_max_blocks 4096)/2))], 0, [ignore], [ignore])
AT_CHECK([gfs2_edit savemeta $GFS_TGT test.meta > savemeta.log], 0, [ignore], [ignore])
AT_CHECK([head -2 savemeta.log], 0, [There are 2621440 blocks of 4096 bytes in the destination device.
-Reading resource groups...Done. File system size: 4.1023G
+Reading resource groups...Done. File system size: 4.1023GB
], [ignore])
GFS_TGT_REGEN
AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore])
9 years, 8 months
gfs2-utils: RHEL7 - gfs2_edit: Add a savemeta file metadata header
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=39a4a68f...
Commit: 39a4a68fe4f462686d488a0e49c368a314c03f5c
Parent: f8aab099da3f8a9b300a85a1fc3247cdb7e15103
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri May 16 23:46:12 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:15:39 2014 +0100
gfs2_edit: Add a savemeta file metadata header
Previously 'gfs2_edit savemeta' just saved blocks into the file and any
characterisation of the contents had to be calculated by reading the
gfs2 structures out of it. Add a metadata header to savemeta output
files which initially holds the original fs size and a file creation
time, leaving some room to spare for future fields to be added.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/savemeta.c | 95 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 86 insertions(+), 9 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index ab7f86f..a10da19 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -19,6 +19,7 @@
#include <sys/time.h>
#include <linux/gfs2_ondisk.h>
#include <zlib.h>
+#include <time.h>
#include <logging.h>
#include "osi_list.h"
@@ -30,6 +31,17 @@
#define DFT_SAVE_FILE "/tmp/gfsmeta.XXXXXX"
#define MAX_JOURNALS_SAVED 256
+/* Header for the savemeta output file */
+struct savemeta_header {
+#define SAVEMETA_MAGIC (0x01171970)
+ uint32_t sh_magic;
+#define SAVEMETA_FORMAT (1)
+ uint32_t sh_format; /* In case we want to change the layout */
+ uint64_t sh_time; /* When savemeta was run */
+ uint64_t sh_fs_bytes; /* Size of the fs */
+ uint8_t __reserved[104];
+};
+
struct saved_metablock {
uint64_t blk;
uint16_t siglen; /* significant data length */
@@ -670,6 +682,51 @@ static void save_allocated(struct rgrp_tree *rgd, struct metafd *mfd)
free(ibuf);
}
+static int save_header(struct metafd *mfd, uint64_t fsbytes)
+{
+ struct savemeta_header smh = {
+ .sh_magic = cpu_to_be32(SAVEMETA_MAGIC),
+ .sh_format = cpu_to_be32(SAVEMETA_FORMAT),
+ .sh_time = cpu_to_be64(time(NULL)),
+ .sh_fs_bytes = cpu_to_be64(fsbytes)
+ };
+
+ if (savemetawrite(mfd, (char *)(&smh), sizeof(smh)) != sizeof(smh))
+ return -1;
+ return 0;
+}
+
+static int read_header(gzFile gzin_fd, struct savemeta_header *smh)
+{
+ size_t rs;
+ struct savemeta_header smh_be = {0};
+
+ rs = gzread(gzin_fd, &smh_be, sizeof(smh_be));
+ if (rs == -1) {
+ perror("Failed to read savemeta file header");
+ return -1;
+ }
+ if (rs != sizeof(smh_be))
+ return 1;
+
+ smh->sh_magic = be32_to_cpu(smh_be.sh_magic);
+ smh->sh_format = be32_to_cpu(smh_be.sh_format);
+ smh->sh_time = be64_to_cpu(smh_be.sh_time);
+ smh->sh_fs_bytes = be64_to_cpu(smh_be.sh_fs_bytes);
+
+ return 0;
+}
+
+static int check_header(struct savemeta_header *smh)
+{
+ if (smh->sh_magic != SAVEMETA_MAGIC || smh->sh_format > SAVEMETA_FORMAT)
+ return -1;
+ printf("Savemeta file format %"PRIu32"\n", smh->sh_format);
+ printf("Created %s\n", ctime((time_t *)&smh->sh_time));
+ printf("File system size %s\n", anthropomorphize(smh->sh_fs_bytes));
+ return 0;
+}
+
void savemeta(char *out_fn, int saveoption, int gziplevel)
{
int rgcount;
@@ -678,6 +735,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
struct metafd mfd;
int sane;
struct osi_node *n, *next = NULL;
+ int err = 0;
sbd.md.journals = 1;
@@ -746,8 +804,14 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
get_journal_inode_blocks();
+ /* Write the savemeta file header */
+ 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, 0x10 * (4096 / sbd.bsize));
+ save_block(sbd.device_fd, &mfd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK / sbd.bsize);
/* If this is gfs1, save off the rindex because it's not
part of the file system as it is in gfs2. */
if (sbd.gfs1) {
@@ -809,7 +873,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
}
static int restore_data(int fd, gzFile gzin_fd, int printblocksonly,
- int find_highblk)
+ int find_highblk, const int startpos)
{
size_t rs;
uint64_t buf64, writes = 0, highest_valid_block = 0;
@@ -821,21 +885,21 @@ static int restore_data(int fd, gzFile gzin_fd, int printblocksonly,
if (!printblocksonly)
lseek(fd, 0, SEEK_SET);
- gzseek(gzin_fd, 0, SEEK_SET);
+ gzseek(gzin_fd, startpos, SEEK_SET);
rs = gzread(gzin_fd, rdbuf, sizeof(rdbuf));
if (rs != sizeof(rdbuf)) {
fprintf(stderr, "Error: File is too small.\n");
return -1;
}
- for (pos = 0; pos < sizeof(rdbuf) - sizeof(uint64_t) - sizeof(uint16_t);
+ for (pos = startpos; pos < startpos + sizeof(rdbuf) - sizeof(uint64_t) - sizeof(uint16_t);
pos++) {
if (!memcmp(&rdbuf[pos + sizeof(uint64_t) + sizeof(uint16_t)],
gfs_superblock_id, sizeof(gfs_superblock_id))) {
break;
}
}
- if (pos == sizeof(rdbuf) - sizeof(uint64_t) - sizeof(uint16_t))
- pos = 0;
+ if (pos == startpos + sizeof(rdbuf) - sizeof(uint64_t) - sizeof(uint16_t))
+ pos = startpos;
if (gzseek(gzin_fd, pos, SEEK_SET) != pos) {
fprintf(stderr, "bad seek: %s from %s:%d: "
"offset %lld (0x%llx)\n", strerror(errno),
@@ -969,7 +1033,7 @@ static int restore_data(int fd, gzFile gzin_fd, int printblocksonly,
}
if (!printblocksonly && !find_highblk)
warm_fuzzy_stuff(sbd.fssize, TRUE);
- if (find_highblk) {
+ if (find_highblk && startpos == 0) {
printf("File system size: %lld (0x%llx) blocks, aka %sB\n",
(unsigned long long)highest_valid_block,
(unsigned long long)highest_valid_block,
@@ -991,6 +1055,8 @@ void restoremeta(const char *in_fn, const char *out_device,
{
int error;
gzFile gzfd;
+ int startpos = 0;
+ struct savemeta_header smh = {0};
termlines = 0;
if (!in_fn)
@@ -1014,9 +1080,20 @@ void restoremeta(const char *in_fn, const char *out_device,
if (!savedata)
die("Can't allocate memory for the restore operation.\n");
+ gzseek(gzfd, 0, SEEK_SET);
+ error = read_header(gzfd, &smh);
+ if (error < 0) {
+ exit(1);
+ } else if (check_header(&smh) != 0) {
+ printf("No valid file header found. Falling back to old format...\n");
+ gzseek(gzfd, 0, SEEK_SET);
+ } else if (error == 0) {
+ startpos = sizeof(smh);
+ }
+
blks_saved = 0;
- restore_data(sbd.device_fd, gzfd, printblocksonly, 1);
- error = restore_data(sbd.device_fd, gzfd, printblocksonly, 0);
+ restore_data(sbd.device_fd, gzfd, printblocksonly, 1, startpos);
+ error = restore_data(sbd.device_fd, gzfd, printblocksonly, 0, startpos);
printf("File %s %s %s.\n", in_fn,
(printblocksonly ? "print" : "restore"),
(error ? "error" : "successful"));
9 years, 8 months
gfs2-utils: RHEL7 - libgfs2: Remove logging API
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=f8aab099...
Commit: f8aab099da3f8a9b300a85a1fc3247cdb7e15103
Parent: 8dfe0251aa7c2ac39784f1a75735fedb353e372b
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed May 7 15:24:22 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:15:39 2014 +0100
libgfs2: Remove logging API
libgfs2 was exposing a logging API (log_info, etc.) but wasn't using it
itself. Remove the logging bits and move them into
gfs2/include/logging.h
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 2 ++
gfs2/edit/savemeta.c | 2 ++
gfs2/fsck/fs_recovery.c | 1 +
gfs2/fsck/initialize.c | 1 +
gfs2/fsck/inode_hash.c | 1 +
gfs2/fsck/link.c | 1 +
gfs2/fsck/lost_n_found.c | 1 +
gfs2/fsck/main.c | 2 ++
gfs2/fsck/metawalk.c | 1 +
gfs2/fsck/pass1.c | 1 +
gfs2/fsck/pass1b.c | 1 +
gfs2/fsck/pass1c.c | 1 +
gfs2/fsck/pass2.c | 1 +
gfs2/fsck/pass3.c | 1 +
gfs2/fsck/pass4.c | 1 +
gfs2/fsck/pass5.c | 1 +
gfs2/fsck/rgrepair.c | 1 +
gfs2/fsck/util.c | 1 +
gfs2/include/Makefile.am | 2 +-
gfs2/include/logging.h | 36 ++++++++++++++++++++++++++++++++++++
gfs2/libgfs2/Makefile.am | 2 +-
gfs2/libgfs2/fs_geometry.c | 8 ++++----
gfs2/libgfs2/gfs2_log.c | 24 ------------------------
gfs2/libgfs2/libgfs2.h | 34 ----------------------------------
gfs2/mkfs/main_grow.c | 2 ++
25 files changed, 65 insertions(+), 64 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 15a16ef..87bec8c 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -30,6 +30,7 @@
#include <linux/types.h>
#include <linux/gfs2_ondisk.h>
+#include <logging.h>
#include "osi_list.h"
#include "copyright.cf"
#include "libgfs2.h"
@@ -112,6 +113,7 @@ uint64_t gfs2_jheightsize[GFS2_MAX_META_HEIGHT];
uint32_t gfs2_max_height;
uint32_t gfs2_max_jheight;
uint64_t jindex_addr = 0, rindex_addr = 0;
+int print_level = MSG_NOTICE;
/* ------------------------------------------------------------------------- */
/* This function is for libgfs's sake. */
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index c9f2d0a..ab7f86f 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -20,6 +20,7 @@
#include <linux/gfs2_ondisk.h>
#include <zlib.h>
+#include <logging.h>
#include "osi_list.h"
#include "gfs2hex.h"
#include "hexedit.h"
@@ -47,6 +48,7 @@ uint64_t last_reported_block, blks_saved, total_out, pct;
uint64_t journal_blocks[MAX_JOURNALS_SAVED];
uint64_t gfs1_journal_size = 0; /* in blocks */
int journals_found = 0;
+int print_level = MSG_NOTICE;
extern void read_superblock(void);
diff --git a/gfs2/fsck/fs_recovery.c b/gfs2/fsck/fs_recovery.c
index 54a8c5f..a052487 100644
--- a/gfs2/fsck/fs_recovery.c
+++ b/gfs2/fsck/fs_recovery.c
@@ -9,6 +9,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "fsck.h"
#include "fs_recovery.h"
#include "libgfs2.h"
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 9ada7d2..f7ea45f 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -15,6 +15,7 @@
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "fsck.h"
#include "util.h"
diff --git a/gfs2/fsck/inode_hash.c b/gfs2/fsck/inode_hash.c
index aca5e61..eeb0a84 100644
--- a/gfs2/fsck/inode_hash.c
+++ b/gfs2/fsck/inode_hash.c
@@ -5,6 +5,7 @@
#include <libintl.h>
#include <string.h>
+#include <logging.h>
#include "libgfs2.h"
#include "osi_list.h"
#include "inode_hash.h"
diff --git a/gfs2/fsck/link.c b/gfs2/fsck/link.c
index 72fe7d5..9a958b4 100644
--- a/gfs2/fsck/link.c
+++ b/gfs2/fsck/link.c
@@ -8,6 +8,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "fsck.h"
#include "inode_hash.h"
diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index 919cb2f..9672c7a 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -10,6 +10,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "fsck.h"
#include "libgfs2.h"
#include "lost_n_found.h"
diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
index 6a6fcd9..b25d802 100644
--- a/gfs2/fsck/main.c
+++ b/gfs2/fsck/main.c
@@ -16,6 +16,7 @@
#define _(String) gettext(String)
#include <syslog.h>
+#include <logging.h>
#include "copyright.cf"
#include "libgfs2.h"
#include "fsck.h"
@@ -41,6 +42,7 @@ struct osi_root inodetree = (struct osi_root) { NULL, };
int dups_found = 0, dups_found_first = 0;
struct gfs_sb *sbd1 = NULL;
int sb_fixed = 0;
+int print_level = MSG_NOTICE;
/* This function is for libgfs2's sake. */
void print_it(const char *label, const char *fmt, const char *fmt2, ...)
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index bc0a7ff..8da17c6 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -12,6 +12,7 @@
#include <fcntl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "osi_tree.h"
#include "fsck.h"
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index ea660cf..90ca357 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -20,6 +20,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "fsck.h"
#include "inode_hash.h"
diff --git a/gfs2/fsck/pass1b.c b/gfs2/fsck/pass1b.c
index e3da20a..f82f43b 100644
--- a/gfs2/fsck/pass1b.c
+++ b/gfs2/fsck/pass1b.c
@@ -8,6 +8,7 @@
#include <sys/stat.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "fsck.h"
#include "osi_list.h"
diff --git a/gfs2/fsck/pass1c.c b/gfs2/fsck/pass1c.c
index b918de1..ce9ca96 100644
--- a/gfs2/fsck/pass1c.c
+++ b/gfs2/fsck/pass1c.c
@@ -7,6 +7,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "fsck.h"
#include "util.h"
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index c8c047e..2474ccb 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -9,6 +9,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "fsck.h"
#include "util.h"
diff --git a/gfs2/fsck/pass3.c b/gfs2/fsck/pass3.c
index 6448da3..9582b5b 100644
--- a/gfs2/fsck/pass3.c
+++ b/gfs2/fsck/pass3.c
@@ -8,6 +8,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "osi_list.h"
#include "fsck.h"
diff --git a/gfs2/fsck/pass4.c b/gfs2/fsck/pass4.c
index 311b96b..7b3cb87 100644
--- a/gfs2/fsck/pass4.c
+++ b/gfs2/fsck/pass4.c
@@ -6,6 +6,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "fsck.h"
#include "lost_n_found.h"
diff --git a/gfs2/fsck/pass5.c b/gfs2/fsck/pass5.c
index 49ab682..68b1373 100644
--- a/gfs2/fsck/pass5.c
+++ b/gfs2/fsck/pass5.c
@@ -7,6 +7,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "fsck.h"
#include "util.h"
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index cb39541..0466dd8 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -10,6 +10,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "osi_list.h"
#include "fsck.h"
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index f8ccb3e..8b439a9 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -12,6 +12,7 @@
#include <ctype.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "metawalk.h"
#include "util.h"
diff --git a/gfs2/include/Makefile.am b/gfs2/include/Makefile.am
index a017cb3..c755181 100644
--- a/gfs2/include/Makefile.am
+++ b/gfs2/include/Makefile.am
@@ -1,3 +1,3 @@
MAINTAINERCLEANFILES = Makefile.in
-noinst_HEADERS = osi_list.h osi_tree.h linux_endian.h
+noinst_HEADERS = osi_list.h osi_tree.h linux_endian.h logging.h
diff --git a/gfs2/include/logging.h b/gfs2/include/logging.h
new file mode 100644
index 0000000..18b5832
--- /dev/null
+++ b/gfs2/include/logging.h
@@ -0,0 +1,36 @@
+#ifndef __LOGGING_H__
+#define __LOGGING_H__
+
+extern int print_level;
+#define increase_verbosity() do { print_level++; } while(0)
+#define decrease_verbosity() do { print_level--; } while(0)
+
+#define MSG_DEBUG 7
+#define MSG_INFO 6
+#define MSG_NOTICE 5
+#define MSG_WARN 4
+#define MSG_ERROR 3
+#define MSG_CRITICAL 2
+#define MSG_NULL 1
+
+#define log_debug(format...) \
+ do { if (print_level >= MSG_DEBUG) { \
+ printf("(%s:%d) ", __FUNCTION__, __LINE__); \
+ printf(format); } } while(0)
+
+#define log_info(format...) \
+ do { if (print_level >= MSG_INFO) printf(format); } while(0)
+
+#define log_notice(format...) \
+ do { if (print_level >= MSG_NOTICE) printf(format); } while(0)
+
+#define log_warn(format...) \
+ do { if (print_level >= MSG_WARN) printf(format); } while(0)
+
+#define log_err(format...) \
+ do { if (print_level >= MSG_ERROR) fprintf(stderr, format); } while(0)
+
+#define log_crit(format...) \
+ do { if (print_level >= MSG_CRITICAL) fprintf(stderr, format); } while(0)
+
+#endif /* __LOGGING_H__ */
diff --git a/gfs2/libgfs2/Makefile.am b/gfs2/libgfs2/Makefile.am
index 2d197f0..4af27be 100644
--- a/gfs2/libgfs2/Makefile.am
+++ b/gfs2/libgfs2/Makefile.am
@@ -13,7 +13,7 @@ noinst_PROGRAMS = gfs2l
libgfs2_la_SOURCES = block_list.c fs_bits.c gfs1.c misc.c rgrp.c super.c \
buf.c fs_geometry.c gfs2_disk_hash.c ondisk.c config.c \
- device_geometry.c fs_ops.c gfs2_log.c recovery.c \
+ device_geometry.c fs_ops.c recovery.c \
structures.c meta.c lang.c parser.y lexer.l
libgfs2_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 \
diff --git a/gfs2/libgfs2/fs_geometry.c b/gfs2/libgfs2/fs_geometry.c
index 9c9085f..587ceb8 100644
--- a/gfs2/libgfs2/fs_geometry.c
+++ b/gfs2/libgfs2/fs_geometry.c
@@ -97,12 +97,12 @@ void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
} else {
uint64_t old_length, new_chunk;
- log_info("Existing resource groups:\n");
+ printf("Existing resource groups:\n");
for (rgrp = 0, n = osi_first(rgtree); n; n = next, rgrp++) {
next = osi_next(n);
rl = (struct rgrp_tree *)n;
- log_info("%d: start: %" PRIu64 " (0x%"
+ printf("%d: start: %" PRIu64 " (0x%"
PRIx64 "), length = %"PRIu64" (0x%"
PRIx64 ")\n", rgrp + 1, rl->start, rl->start,
rl->length, rl->length);
@@ -118,7 +118,7 @@ void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
}
if (rgrp < nrgrp)
- log_info("\nNew resource groups:\n");
+ printf("\nNew resource groups:\n");
for (; rgrp < nrgrp; rgrp++) {
if (rgrp) {
rgaddr = rlast->start + rlast->length;
@@ -131,7 +131,7 @@ void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
(nrgrp - 1) * (dev->length / nrgrp);
}
rl->start = rgaddr;
- log_info("%d: start: %" PRIu64 " (0x%"
+ printf("%d: start: %" PRIu64 " (0x%"
PRIx64 "), length = %"PRIu64" (0x%"
PRIx64 ")\n", rgrp + 1, rl->start, rl->start,
rl->length, rl->length);
diff --git a/gfs2/libgfs2/gfs2_log.c b/gfs2/libgfs2/gfs2_log.c
deleted file mode 100644
index da5f489..0000000
--- a/gfs2/libgfs2/gfs2_log.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "clusterautoconfig.h"
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <sys/select.h>
-#include <signal.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "libgfs2.h"
-
-int print_level = MSG_NOTICE;
-
-void increase_verbosity(void)
-{
- print_level++;
-}
-
-void decrease_verbosity(void)
-{
- print_level--;
-}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index b269357..041e5fd 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -671,40 +671,6 @@ extern void gfs_jindex_in(struct gfs_jindex *jindex, char *buf);
extern void gfs_rgrp_in(struct gfs_rgrp *rg, struct gfs2_buffer_head *bh);
extern void gfs_rgrp_out(struct gfs_rgrp *rg, struct gfs2_buffer_head *bh);
-/* gfs2_log.c */
-
-extern int print_level;
-
-#define MSG_DEBUG 7
-#define MSG_INFO 6
-#define MSG_NOTICE 5
-#define MSG_WARN 4
-#define MSG_ERROR 3
-#define MSG_CRITICAL 2
-#define MSG_NULL 1
-
-#define log_debug(format...) \
- do { if (print_level >= MSG_DEBUG) { \
- printf("(%s:%d) ", __FUNCTION__, __LINE__); \
- printf(format); } } while(0)
-
-#define log_info(format...) \
- do { if (print_level >= MSG_INFO) printf(format); } while(0)
-
-#define log_notice(format...) \
- do { if (print_level >= MSG_NOTICE) printf(format); } while(0)
-
-#define log_warn(format...) \
- do { if (print_level >= MSG_WARN) printf(format); } while(0)
-
-#define log_err(format...) \
- do { if (print_level >= MSG_ERROR) fprintf(stderr, format); } while(0)
-
-#define log_crit(format...) \
- do { if (print_level >= MSG_CRITICAL) fprintf(stderr, format); } while(0)
-
-extern void increase_verbosity(void);
-extern void decrease_verbosity(void);
/* misc.c */
extern int metafs_interrupted;
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 7e005e9..5da809a 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -23,6 +23,7 @@
#include <libintl.h>
#define _(String) gettext(String)
+#include <logging.h>
#include "libgfs2.h"
#include "gfs2_mkfs.h"
@@ -33,6 +34,7 @@ static uint64_t override_device_size = 0;
static int test = 0;
static uint64_t fssize = 0, fsgrowth;
static unsigned int rgsize = 0;
+int print_level = MSG_NOTICE;
extern int create_new_inode(struct gfs2_sbd *sdp);
extern int rename2system(struct gfs2_sbd *sdp, char *new_dir, char *new_name);
9 years, 8 months
gfs2-utils: RHEL7 - libgfs2: Remove debug field from gfs2_sbd
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=8dfe0251...
Commit: 8dfe0251aa7c2ac39784f1a75735fedb353e372b
Parent: 26b7af3357ba6d81fad5096a0e594302502bcd5d
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed May 7 14:25:58 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Jul 24 17:15:39 2014 +0100
libgfs2: Remove debug field from gfs2_sbd
The utils were using the debug field to store their debug printing
options. Hide the debug field in a libgfs2-internal header to allow
switching on libgfs2 debugging output separately and switch the apps to
use their own debug options. In cases where apps were using sdp->debug
but not actually setting it, remove the code which depends on it being
set.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 5 -----
gfs2/fsck/rgrepair.c | 19 -------------------
gfs2/libgfs2/Makefile.am | 4 ++--
gfs2/libgfs2/config.c | 9 +++++++++
gfs2/libgfs2/config.h | 6 ++++++
gfs2/libgfs2/device_geometry.c | 3 ++-
gfs2/libgfs2/fs_geometry.c | 5 +++--
gfs2/libgfs2/libgfs2.h | 5 +++--
gfs2/libgfs2/misc.c | 7 ++++---
gfs2/libgfs2/structures.c | 31 +++++++++++++++----------------
gfs2/mkfs/main_grow.c | 21 ---------------------
gfs2/mkfs/main_jadd.c | 8 +++++---
gfs2/mkfs/main_mkfs.c | 10 +++++-----
13 files changed, 54 insertions(+), 79 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 9f7fa17..15a16ef 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1981,11 +1981,6 @@ static int conv_build_jindex(struct gfs2_sbd *sdp)
}
free(sdp->md.journal);
- if (sdp->debug) {
- printf("\nJindex:\n");
- gfs2_dinode_print(&sdp->md.jiinode->i_di);
- }
-
inode_put(&sdp->md.jiinode);
return 0;
}
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 4fdbcf7..cb39541 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -589,24 +589,6 @@ static int gfs2_rindex_rebuild(struct gfs2_sbd *sdp, int *num_rgs,
return 0;
}
-static void debug_print_rgrps(struct gfs2_sbd *sdp, struct osi_root *rgtree)
-{
- struct osi_node *n, *next;
- struct rgrp_tree *rl;
-
- if (sdp->debug) {
- log_info("\n");
-
- for (n = osi_first(rgtree); n; n = next) {
- next = osi_next(n);
- rl = (struct rgrp_tree *)n;
- log_info("rg_o = %llu, rg_l = %llu\n",
- (unsigned long long)rl->start,
- (unsigned long long)rl->length);
- }
- }
-}
-
/*
* gfs2_rindex_calculate - calculate what the rindex should look like
* in a perfect world (trust_lvl == open_minded)
@@ -649,7 +631,6 @@ static int gfs2_rindex_calculate(struct gfs2_sbd *sdp, int *num_rgs)
}
/* Compute the default resource group layout as mkfs would have done */
compute_rgrp_layout(sdp, &sdp->rgcalc, TRUE);
- debug_print_rgrps(sdp, &sdp->rgcalc);
if (build_rgrps(sdp, FALSE)) { /* FALSE = calc but don't write to disk. */
fprintf(stderr, _("Failed to build resource groups\n"));
exit(-1);
diff --git a/gfs2/libgfs2/Makefile.am b/gfs2/libgfs2/Makefile.am
index c5cb288..2d197f0 100644
--- a/gfs2/libgfs2/Makefile.am
+++ b/gfs2/libgfs2/Makefile.am
@@ -5,14 +5,14 @@ BUILT_SOURCES = parser.h lexer.h
AM_LFLAGS = --header-file=lexer.h
AM_YFLAGS = -d
-noinst_HEADERS = libgfs2.h lang.h
+noinst_HEADERS = libgfs2.h lang.h config.h
noinst_LTLIBRARIES = libgfs2.la
noinst_PROGRAMS = gfs2l
libgfs2_la_SOURCES = block_list.c fs_bits.c gfs1.c misc.c rgrp.c super.c \
- buf.c fs_geometry.c gfs2_disk_hash.c ondisk.c \
+ buf.c fs_geometry.c gfs2_disk_hash.c ondisk.c config.c \
device_geometry.c fs_ops.c gfs2_log.c recovery.c \
structures.c meta.c lang.c parser.y lexer.l
diff --git a/gfs2/libgfs2/config.c b/gfs2/libgfs2/config.c
new file mode 100644
index 0000000..d2431e4
--- /dev/null
+++ b/gfs2/libgfs2/config.c
@@ -0,0 +1,9 @@
+#include "libgfs2.h"
+#include "config.h"
+
+int cfg_debug = 0;
+
+void lgfs2_set_debug(int enable)
+{
+ cfg_debug = enable;
+}
diff --git a/gfs2/libgfs2/config.h b/gfs2/libgfs2/config.h
new file mode 100644
index 0000000..7c1eb3c
--- /dev/null
+++ b/gfs2/libgfs2/config.h
@@ -0,0 +1,6 @@
+#ifndef __LGFS2_CONFIG_H__
+#define __LGFS2_CONFIG_H__
+
+extern int cfg_debug;
+
+#endif /* __LGFS2_CONFIG_H__ */
diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index 1bee9c2..27e846d 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -15,6 +15,7 @@
#include <linux/fs.h>
#include "libgfs2.h"
+#include "config.h"
#ifndef BLKSSZGET
#define BLKSSZGET _IO(0x12,104) /* logical_block_size */
@@ -99,7 +100,7 @@ void fix_device_geometry(struct gfs2_sbd *sdp)
device->length = sdp->dinfo.size / sdp->bsize;
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nDevice Geometry: (in FS blocks)\n");
printf(" length = %"PRIu64"\n", device->length);
printf("\nDevice Size: %"PRIu64"\n", sdp->dinfo.size);
diff --git a/gfs2/libgfs2/fs_geometry.c b/gfs2/libgfs2/fs_geometry.c
index 4bdb64a..9c9085f 100644
--- a/gfs2/libgfs2/fs_geometry.c
+++ b/gfs2/libgfs2/fs_geometry.c
@@ -13,6 +13,7 @@
#include <linux/types.h>
#include "libgfs2.h"
+#include "config.h"
#define DIV_RU(x, y) (((x) + (y) - 1) / (y))
@@ -59,7 +60,7 @@ uint64_t how_many_rgrps(struct gfs2_sbd *sdp, struct device *dev, int rgsize_spe
sdp->rgsize += GFS2_DEFAULT_RGSIZE; /* bigger rgs */
}
- if (sdp->debug)
+ if (cfg_debug)
printf(" rg sz = %"PRIu32"\n nrgrp = %"PRIu64"\n",
sdp->rgsize, nrgrp);
@@ -220,7 +221,7 @@ int build_rgrps(struct gfs2_sbd *sdp, int do_write)
}
}
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\n");
gfs2_rindex_print(ri);
}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 5fdf9af..b269357 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -276,8 +276,6 @@ struct gfs2_sbd {
unsigned int rgsize; /* Size of resource groups (in MB) */
unsigned int qcsize; /* Size of quota change files (in MB) */
- int debug;
-
char device_name[PATH_MAX];
char *path_name;
@@ -401,6 +399,9 @@ extern uint32_t lgfs2_get_block_type(const struct gfs2_buffer_head *lbh);
#define bread(bl, num) __bread(bl, num, __LINE__, __FUNCTION__)
#define breadm(bl, bhs, n, block) __breadm(bl, bhs, n, block, __LINE__, __FUNCTION__)
+/* config.c */
+extern void lgfs2_set_debug(int enable);
+
/* device_geometry.c */
extern int lgfs2_get_dev_info(int fd, struct lgfs2_dev_info *i);
extern void fix_device_geometry(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 4cdd6e0..9eca24c 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -20,6 +20,7 @@
#include <signal.h>
#include "libgfs2.h"
+#include "config.h"
#define PAGE_SIZE (4096)
#define DIV_RU(x, y) (((x) + (y) - 1) / (y))
@@ -198,17 +199,17 @@ static int lock_for_admin(struct gfs2_sbd *sdp)
{
int error;
- if (sdp->debug)
+ if (cfg_debug)
printf("\nTrying to get admin lock...\n");
sdp->metafs_fd = open(sdp->metafs_path, O_RDONLY | O_NOFOLLOW);
if (sdp->metafs_fd < 0)
return -1;
-
+
error = flock(sdp->metafs_fd, LOCK_EX);
if (error)
return -1;
- if (sdp->debug)
+ if (cfg_debug)
printf("Got it.\n");
return 0;
}
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 2cc9a98..ee49dce 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -14,6 +14,7 @@
#include <sys/time.h>
#include "libgfs2.h"
+#include "config.h"
int build_master(struct gfs2_sbd *sdp)
{
@@ -29,12 +30,12 @@ int build_master(struct gfs2_sbd *sdp)
inum.no_addr = bn;
bh = init_dinode(sdp, &inum, S_IFDIR | 0755, GFS2_DIF_SYSTEM, &inum);
-
+
sdp->master_dir = lgfs2_inode_get(sdp, bh);
if (sdp->master_dir == NULL)
return -1;
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nMaster dir:\n");
gfs2_dinode_print(&sdp->master_dir->i_di);
}
@@ -223,7 +224,7 @@ int build_jindex(struct gfs2_sbd *sdp)
return ret;
inode_put(&sdp->md.journal[j]);
}
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nJindex:\n");
gfs2_dinode_print(&jindex->i_di);
}
@@ -235,7 +236,6 @@ int build_jindex(struct gfs2_sbd *sdp)
int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
{
- struct gfs2_sbd *sdp = per_node->i_sbd;
char name[256];
struct gfs2_inode *ip;
@@ -248,7 +248,7 @@ int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
ip->i_di.di_size = sizeof(struct gfs2_inum_range);
gfs2_dinode_out(&ip->i_di, ip->i_bh);
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nInum Range %u:\n", j);
gfs2_dinode_print(&ip->i_di);
}
@@ -259,7 +259,6 @@ int build_inum_range(struct gfs2_inode *per_node, unsigned int j)
int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
{
- struct gfs2_sbd *sdp = per_node->i_sbd;
char name[256];
struct gfs2_inode *ip;
@@ -272,7 +271,7 @@ int build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
ip->i_di.di_size = sizeof(struct gfs2_statfs_change);
gfs2_dinode_out(&ip->i_di, ip->i_bh);
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nStatFS Change %u:\n", j);
gfs2_dinode_print(&ip->i_di);
}
@@ -316,7 +315,7 @@ int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
brelse(bh);
}
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nQuota Change %u:\n", j);
gfs2_dinode_print(&ip->i_di);
}
@@ -352,7 +351,7 @@ int build_per_node(struct gfs2_sbd *sdp)
}
}
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nper_node:\n");
gfs2_dinode_print(&per_node->i_di);
}
@@ -371,7 +370,7 @@ int build_inum(struct gfs2_sbd *sdp)
return errno;
}
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nInum Inode:\n");
gfs2_dinode_print(&ip->i_di);
}
@@ -390,7 +389,7 @@ int build_statfs(struct gfs2_sbd *sdp)
return errno;
}
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nStatFS Inode:\n");
gfs2_dinode_print(&ip->i_di);
}
@@ -432,7 +431,7 @@ int build_rindex(struct gfs2_sbd *sdp)
if (count != sizeof(struct gfs2_rindex))
return -1;
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nResource Index:\n");
gfs2_dinode_print(&ip->i_di);
}
@@ -467,7 +466,7 @@ int build_quota(struct gfs2_sbd *sdp)
if (count != sizeof(struct gfs2_quota))
return -1;
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nRoot quota:\n");
gfs2_quota_print(&qu);
}
@@ -494,7 +493,7 @@ int build_root(struct gfs2_sbd *sdp)
if (sdp->md.rooti == NULL)
return -1;
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nRoot directory:\n");
gfs2_dinode_print(&sdp->md.rooti->i_di);
}
@@ -513,7 +512,7 @@ int do_init_inum(struct gfs2_sbd *sdp)
if (count != sizeof(uint64_t))
return -1;
- if (sdp->debug)
+ if (cfg_debug)
printf("\nNext Inum: %"PRIu64"\n",
sdp->md.next_inum);
return 0;
@@ -535,7 +534,7 @@ int do_init_statfs(struct gfs2_sbd *sdp)
if (count != sizeof(struct gfs2_statfs_change))
return -1;
- if (sdp->debug) {
+ if (cfg_debug) {
printf("\nStatfs:\n");
gfs2_statfs_change_print(&sc);
}
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index adceeef..7e005e9 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -216,9 +216,6 @@ static unsigned initialize_new_portion(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs)
}
if (metafs_interrupted)
return 0;
- if (sdp->debug)
- printf(_("Writing resource group at %llu with size %"PRIu32"\n"),
- ri.ri_addr, ri.ri_length + ri.ri_data);
if (!test)
err = lgfs2_rgrp_write(rgs, sdp->device_fd, rg);
if (err != 0) {
@@ -322,22 +319,6 @@ static void print_info(struct gfs2_sbd *sdp)
(unsigned long long)(fsgrowth * sdp->bsize) / MB);
}
-static void debug_print_rgrps(const char *banner, struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs)
-{
- lgfs2_rgrp_t r;
-
- if (sdp->debug) {
- log_info("%s\n", banner);
-
- for (r = lgfs2_rgrp_first(rgs); r; r = lgfs2_rgrp_next(r)) {
- const struct gfs2_rindex *ri = lgfs2_rgrp_index(r);
- log_info("ri_addr = %llu, size = %llu\n",
- (unsigned long long)ri->ri_addr,
- (unsigned long long)(ri->ri_data0 + ri->ri_data - ri->ri_addr));
- }
- }
-}
-
void main_grow(int argc, char *argv[])
{
struct gfs2_sbd sbd, *sdp = &sbd;
@@ -431,7 +412,6 @@ void main_grow(int argc, char *argv[])
if (metafs_interrupted)
goto out;
fssize = lgfs2_rgrp_align_addr(rgs, filesystem_size(rgs) + 1);
- debug_print_rgrps(_("Existing resource groups"), sdp, rgs);
/* We're done with the old rgs now that we have the fssize and rg count */
lgfs2_rgrps_free(&rgs);
/* Now lets set up the new ones with alignment and all */
@@ -453,7 +433,6 @@ void main_grow(int argc, char *argv[])
rgcount = initialize_new_portion(sdp, rgs);
if (rgcount == 0 || metafs_interrupted)
goto out;
- debug_print_rgrps(_("New resource groups"), sdp, rgs);
fsync(sdp->device_fd);
fix_rindex(rindex_fd, rgs, old_rg_count, rgcount);
out:
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index d01e3b3..4338e8d 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -28,6 +28,7 @@
#define RANDOM(values) ((values) * (random() / (RAND_MAX + 1.0)))
static int quiet = 0;
+static int debug = 0;
static void
make_jdata(int fd, const char *value)
@@ -128,7 +129,8 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
sdp->qcsize = atoi(optarg);
break;
case 'D':
- sdp->debug = TRUE;
+ debug = 1;
+ lgfs2_set_debug(1);
break;
case 'h':
print_usage(argv[0]);
@@ -172,7 +174,7 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
if (optind < argc)
die( _("Unrecognized argument: %s\n"), argv[optind]);
- if (sdp->debug) {
+ if (debug) {
printf( _("Command Line Arguments:\n"));
printf(" qcsize = %u\n", sdp->qcsize);
printf(" jsize = %u\n", sdp->jsize);
@@ -200,7 +202,7 @@ static void verify_arguments(struct gfs2_sbd *sdp)
static void print_results(struct gfs2_sbd *sdp)
{
- if (sdp->debug)
+ if (debug)
printf("\n");
else if (quiet)
return;
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 31b1e62..f778e8d 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -308,6 +308,7 @@ static void opts_get(int argc, char *argv[], struct mkfs_opts *opts)
break;
case 'D':
opts->debug = 1;
+ lgfs2_set_debug(1);
break;
case 'h':
print_usage(argv[0]);
@@ -616,7 +617,7 @@ static lgfs2_rgrps_t rgs_init(struct mkfs_opts *opts, struct gfs2_sbd *sdp)
return rgs;
}
-static int place_rgrp(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct gfs2_rindex *ri)
+static int place_rgrp(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct gfs2_rindex *ri, int debug)
{
int err = 0;
lgfs2_rgrp_t rg = NULL;
@@ -631,7 +632,7 @@ static int place_rgrp(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct gfs2_rinde
perror(_("Failed to write resource group"));
return -1;
}
- if (sdp->debug) {
+ if (debug) {
gfs2_rindex_print(ri);
printf("\n");
}
@@ -665,7 +666,7 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct mkfs_opts
rgaddr = lgfs2_rindex_entry_new(rgs, &ri, rgaddr, jrgsize);
if (rgaddr == 0) /* Reached the end when we still have journals to write */
return 1;
- result = place_rgrp(sdp, rgs, &ri);
+ result = place_rgrp(sdp, rgs, &ri, opts->debug);
if (result != 0)
return result;
}
@@ -678,7 +679,7 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct mkfs_opts
rgaddr = lgfs2_rindex_entry_new(rgs, &ri, rgaddr, 0);
if (rgaddr == 0)
break; /* Done */
- result = place_rgrp(sdp, rgs, &ri);
+ result = place_rgrp(sdp, rgs, &ri, opts->debug);
if (result)
return result;
}
@@ -696,7 +697,6 @@ static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, unsigned bsiz
sdp->md.journals = opts->journals;
sdp->device_fd = opts->dev.fd;
sdp->bsize = bsize;
- sdp->debug = opts->debug;
if (compute_constants(sdp)) {
perror(_("Failed to compute file system constants"));
9 years, 8 months