aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandan Babu R <chandan.babu@oracle.com>2023-11-06 18:40:47 +0530
committerCarlos Maiolino <cem@kernel.org>2023-11-21 14:09:36 +0100
commit1fb3dccce21331633069f8b87b740e46f6fb91c7 (patch)
tree64724366d5fe7eed39e5d90985ed39b2662f2acb
parent50f2031ac6f80f5a554b361cffa29486f98924ae (diff)
downloadxfsprogs-dev-1fb3dccce21331633069f8b87b740e46f6fb91c7.tar.gz
mdrestore: Define and use struct mdrestore
This commit collects all state tracking variables in a new "struct mdrestore" structure. This is done to collect all the global variables in one place rather than having them spread across the file. A new structure member of type "struct mdrestore_ops *" will be added by a future commit to support the two versions of metadump. Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandan.babu@oracle.com> Signed-off-by: Carlos Maiolino <cem@kernel.org>
-rw-r--r--mdrestore/xfs_mdrestore.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c
index ca28c48e0e..97cb4e35c4 100644
--- a/mdrestore/xfs_mdrestore.c
+++ b/mdrestore/xfs_mdrestore.c
@@ -7,9 +7,11 @@
#include "libxfs.h"
#include "xfs_metadump.h"
-static bool show_progress = false;
-static bool show_info = false;
-static bool progress_since_warning = false;
+static struct mdrestore {
+ bool show_progress;
+ bool show_info;
+ bool progress_since_warning;
+} mdrestore;
static void
fatal(const char *msg, ...)
@@ -35,7 +37,7 @@ print_progress(const char *fmt, ...)
printf("\r%-59s", buf);
fflush(stdout);
- progress_since_warning = true;
+ mdrestore.progress_since_warning = true;
}
/*
@@ -127,7 +129,8 @@ perform_restore(
bytes_read = 0;
for (;;) {
- if (show_progress && (bytes_read & ((1 << 20) - 1)) == 0)
+ if (mdrestore.show_progress &&
+ (bytes_read & ((1 << 20) - 1)) == 0)
print_progress("%lld MB read", bytes_read >> 20);
for (cur_index = 0; cur_index < mb_count; cur_index++) {
@@ -158,7 +161,7 @@ perform_restore(
bytes_read += block_size + (mb_count << mbp->mb_blocklog);
}
- if (progress_since_warning)
+ if (mdrestore.progress_since_warning)
putchar('\n');
memset(block_buffer, 0, sb.sb_sectsize);
@@ -197,15 +200,19 @@ main(
int is_target_file;
struct xfs_metablock mb;
+ mdrestore.show_progress = false;
+ mdrestore.show_info = false;
+ mdrestore.progress_since_warning = false;
+
progname = basename(argv[0]);
while ((c = getopt(argc, argv, "giV")) != EOF) {
switch (c) {
case 'g':
- show_progress = true;
+ mdrestore.show_progress = true;
break;
case 'i':
- show_info = true;
+ mdrestore.show_info = true;
break;
case 'V':
printf("%s version %s\n", progname, VERSION);
@@ -219,7 +226,7 @@ main(
usage();
/* show_info without a target is ok */
- if (!show_info && argc - optind != 2)
+ if (!mdrestore.show_info && argc - optind != 2)
usage();
/*
@@ -243,7 +250,7 @@ main(
if (mb.mb_magic != cpu_to_be32(XFS_MD_MAGIC_V1))
fatal("specified file is not a metadata dump\n");
- if (show_info) {
+ if (mdrestore.show_info) {
if (mb.mb_info & XFS_METADUMP_INFO_FLAGS) {
printf("%s: %sobfuscated, %s log, %s metadata blocks\n",
argv[optind],