From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Price Date: Thu, 23 Jan 2020 15:55:47 +0000 Subject: [Cluster-devel] [PATCH 08/13] restoremeta: Remove find_highest_block() In-Reply-To: <20200123155552.1080247-1-anprice@redhat.com> References: <20200123155552.1080247-1-anprice@redhat.com> Message-ID: <20200123155552.1080247-9-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Doing a first pass through the metadata file just to find the highest saved block and report it is a bit excessive, so remove find_highest_block() and simply use the value from the metadata file header if present. For ancient files that don't have the header, we just don't report the size, which is a reasonable tradeoff as old files are really only encountered during testing. Signed-off-by: Andrew Price --- gfs2/edit/savemeta.c | 41 ++++++----------------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c index f73cb0e0..dd203974 100644 --- a/gfs2/edit/savemeta.c +++ b/gfs2/edit/savemeta.c @@ -1066,37 +1066,6 @@ err: return -1; } -static int find_highest_block(struct metafd *mfd, off_t pos, uint64_t fssize) -{ - int err = 0; - uint64_t highest = 0; - struct saved_metablock svb = {0}; - - while (1) { - mfd->seek(mfd, pos, SEEK_SET); - err = restore_block(mfd, &svb, NULL, 0); - if (err == 1) - break; - if (err != 0) - return -1; - - if (svb.blk > highest) - highest = svb.blk; - pos += sizeof(svb) + svb.siglen; - } - - if (fssize > 0) { - printf("Saved file system size is %"PRIu64" blocks, %.2fGB\n", - fssize, (fssize * sbd.bsize) / ((float)(1 << 30))); - 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, struct metafd *mfd, off_t pos, int printonly) { struct saved_metablock savedata = {0}; @@ -1248,6 +1217,12 @@ void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly) if (error) exit(1); + if (smh.sh_fs_bytes > 0) { + sbd.fssize = smh.sh_fs_bytes / sbd.bsize; + printf("Saved file system size is %"PRIu64" blocks, %.2fGB\n", + sbd.fssize, smh.sh_fs_bytes / ((float)(1 << 30))); + } + printf("This is gfs%c metadata.\n", sbd.gfs1 ? '1': '2'); if (!printonly) { @@ -1255,10 +1230,6 @@ void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly) printf("There are %"PRIu64" free blocks on the destination device.\n", space); } - error = find_highest_block(&mfd, pos, sbd.fssize); - if (error) - exit(1); - error = restore_data(sbd.device_fd, &mfd, pos, printonly); printf("File %s %s %s.\n", in_fn, (printonly ? "print" : "restore"), -- 2.24.1