]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mdrestore: Define and use struct mdrestore
authorChandan Babu R <chandan.babu@oracle.com>
Mon, 6 Nov 2023 13:10:47 +0000 (18:40 +0530)
committerCarlos Maiolino <cem@kernel.org>
Tue, 21 Nov 2023 13:09:36 +0000 (14:09 +0100)
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>
mdrestore/xfs_mdrestore.c

index ca28c48e0e5b753ccbe29b7b612d56e67913f8f0..97cb4e35c420ce764bad614adcad0e6b986dc327 100644 (file)
@@ -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],