]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mdrestore: Introduce mdrestore v1 operations
authorChandan Babu R <chandanbabu@kernel.org>
Mon, 6 Nov 2023 13:10:51 +0000 (18:40 +0530)
committerCarlos Maiolino <cem@kernel.org>
Tue, 21 Nov 2023 13:09:36 +0000 (14:09 +0100)
In order to indicate the version of metadump files that they can work with,
this commit renames read_header(), show_info() and restore() functions to
read_header_v1(), show_info_v1() and restore_v1() respectively.

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 40de0d1e3ac5bc5c76d2e43dd13732e132e1f3f7..b247a4bfb118a42df88f453d03c7afaf60cc4f82 100644 (file)
@@ -13,10 +13,18 @@ union mdrestore_headers {
        struct xfs_metablock    v1;
 };
 
+struct mdrestore_ops {
+       void (*read_header)(union mdrestore_headers *header, FILE *md_fp);
+       void (*show_info)(union mdrestore_headers *header, const char *md_file);
+       void (*restore)(union mdrestore_headers *header, FILE *md_fp,
+                       int ddev_fd, bool is_target_file);
+};
+
 static struct mdrestore {
-       bool    show_progress;
-       bool    show_info;
-       bool    progress_since_warning;
+       struct mdrestore_ops    *mdrops;
+       bool                    show_progress;
+       bool                    show_info;
+       bool                    progress_since_warning;
 } mdrestore;
 
 static void
@@ -82,7 +90,7 @@ open_device(
 }
 
 static void
-read_header(
+read_header_v1(
        union mdrestore_headers *h,
        FILE                    *md_fp)
 {
@@ -92,7 +100,7 @@ read_header(
 }
 
 static void
-show_info(
+show_info_v1(
        union mdrestore_headers *h,
        const char              *md_file)
 {
@@ -107,22 +115,12 @@ show_info(
        }
 }
 
-/*
- * restore() -- do the actual work to restore the metadump
- *
- * @src_f: A FILE pointer to the source metadump
- * @dst_fd: the file descriptor for the target file
- * @is_target_file: designates whether the target is a regular file
- * @mbp: pointer to metadump's first xfs_metablock, read and verified by the caller
- *
- * src_f should be positioned just past a read the previously validated metablock
- */
 static void
-restore(
+restore_v1(
        union mdrestore_headers *h,
        FILE                    *md_fp,
        int                     ddev_fd,
-       int                     is_target_file)
+       bool                    is_target_file)
 {
        struct xfs_metablock    *metablock;     /* header + index + blocks */
        __be64                  *block_index;
@@ -245,6 +243,12 @@ restore(
        free(metablock);
 }
 
+static struct mdrestore_ops mdrestore_ops_v1 = {
+       .read_header    = read_header_v1,
+       .show_info      = show_info_v1,
+       .restore        = restore_v1,
+};
+
 static void
 usage(void)
 {
@@ -294,9 +298,9 @@ main(
 
        /*
         * open source and test if this really is a dump. The first metadump
-        * block will be passed to restore() which will continue to read the
-        * file from this point. This avoids rewind the stream, which causes
-        * restore to fail when source was being read from stdin.
+        * block will be passed to mdrestore_ops->restore() which will continue
+        * to read the file from this point. This avoids rewind the stream,
+        * which causes restore to fail when source was being read from stdin.
         */
        if (strcmp(argv[optind], "-") == 0) {
                src_f = stdin;
@@ -313,16 +317,17 @@ main(
 
        switch (be32_to_cpu(headers.magic)) {
        case XFS_MD_MAGIC_V1:
+               mdrestore.mdrops = &mdrestore_ops_v1;
                break;
        default:
                fatal("specified file is not a metadata dump\n");
                break;
        }
 
-       read_header(&headers, src_f);
+       mdrestore.mdrops->read_header(&headers, src_f);
 
        if (mdrestore.show_info) {
-               show_info(&headers, argv[optind]);
+               mdrestore.mdrops->show_info(&headers, argv[optind]);
 
                if (argc - optind == 1)
                        exit(0);
@@ -333,7 +338,7 @@ main(
        /* check and open target */
        dst_fd = open_device(argv[optind], &is_target_file);
 
-       restore(&headers, src_f, dst_fd, is_target_file);
+       mdrestore.mdrops->restore(&headers, src_f, dst_fd, is_target_file);
 
        close(dst_fd);
        if (src_f != stdin)