@@ -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)