aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandan Babu R <chandanbabu@kernel.org>2023-11-06 18:40:51 +0530
committerCarlos Maiolino <cem@kernel.org>2023-11-21 14:09:36 +0100
commit0f47a5004c6fafcde538d3d17eb69b2bb7d8b6e8 (patch)
treead4883c2791ad80c4841f2c5a6f03ec69d2f23f2
parentbb78872ffbd596658ba30d5c976fad5013494aee (diff)
downloadxfsprogs-dev-0f47a5004c6fafcde538d3d17eb69b2bb7d8b6e8.tar.gz
mdrestore: Introduce mdrestore v1 operations
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>
-rw-r--r--mdrestore/xfs_mdrestore.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c
index 40de0d1e3a..b247a4bfb1 100644
--- a/mdrestore/xfs_mdrestore.c
+++ b/mdrestore/xfs_mdrestore.c
@@ -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)