From a7ed6bf2423212aed185fb6664c69caf0eacf1ef Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 2 Nov 2023 18:05:51 -0700 Subject: [PATCH] Add force to prepare-empty-data-device Signed-off-by: Zach Brown --- utils/src/prepare_empty_data_device.c | 34 +++++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/utils/src/prepare_empty_data_device.c b/utils/src/prepare_empty_data_device.c index b9732d1a..aaba1ae6 100644 --- a/utils/src/prepare_empty_data_device.c +++ b/utils/src/prepare_empty_data_device.c @@ -38,6 +38,7 @@ struct prepare_empty_data_dev_args { char *meta_device; char *data_device; bool check; + bool force; }; static int do_prepare_empty_data_dev(struct prepare_empty_data_dev_args *args) @@ -77,20 +78,22 @@ static int do_prepare_empty_data_dev(struct prepare_empty_data_dev_args *args) goto out; } - ret = meta_super_in_use(meta_fd, meta_super); - if (ret < 0) { - if (ret == -EBUSY) - fprintf(stderr, "The filesystem must be fully recovered and cleanly unmounted to determine if the data device is empty.\n"); - goto out; - } + if (!args->force) { + ret = meta_super_in_use(meta_fd, meta_super); + if (ret < 0) { + if (ret == -EBUSY) + fprintf(stderr, "The filesystem must be fully recovered and cleanly unmounted to determine if the data device is empty.\n"); + goto out; + } - in_use = (le64_to_cpu(meta_super->total_data_blocks) - SCOUTFS_DATA_DEV_START_BLKNO) - - le64_to_cpu(meta_super->data_alloc.total_len); - if (in_use) { - fprintf(stderr, "Data block allocator metadata shows "SIZE_FMT" data blocks used by files. They must be removed, truncated, or released before a new empty data device can be used.\n", - SIZE_ARGS(in_use, SCOUTFS_BLOCK_SM_SIZE)); - ret = -EINVAL; - goto out; + in_use = (le64_to_cpu(meta_super->total_data_blocks) - SCOUTFS_DATA_DEV_START_BLKNO) - + le64_to_cpu(meta_super->data_alloc.total_len); + if (in_use) { + fprintf(stderr, "Data block allocator metadata shows "SIZE_FMT" data blocks used by files. They must be removed, truncated, or released before a new empty data device can be used.\n", + SIZE_ARGS(in_use, SCOUTFS_BLOCK_SM_SIZE)); + ret = -EINVAL; + goto out; + } } if (args->data_device) { @@ -193,6 +196,9 @@ static int parse_opt(int key, char *arg, struct argp_state *state) case 'c': args->check = true; break; + case 'f': + args->force = true; + break; case ARGP_KEY_ARG: if (!args->meta_device) args->meta_device = strdup_or_error(state, arg); @@ -216,6 +222,7 @@ static int parse_opt(int key, char *arg, struct argp_state *state) static struct argp_option options[] = { { "check", 'c', NULL, 0, "Only check for errors and do not write", }, + { "force", 'f', NULL, 0, "Do not check that super is in use, nor if blocks are in use",}, { NULL } }; @@ -230,6 +237,7 @@ static int prepare_empty_data_dev_cmd(int argc, char *argv[]) { struct prepare_empty_data_dev_args prepare_empty_data_dev_args = { .check = false, + .force = false, }; int ret;