summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2017-03-09 16:12:51 -0900
committerKent Overstreet <kent.overstreet@gmail.com>2017-03-09 16:12:51 -0900
commit076b4196fc340f840e83072e8ea3986a19dcb321 (patch)
treec0280dede056c3c42d7ab65b6d2715f7bb23e680
parent07ddcf0bef7ea7dfe4885b29d1c727ae32a29dcf (diff)
add a force flag to cmd_migrate
-rw-r--r--cmd_migrate.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/cmd_migrate.c b/cmd_migrate.c
index 9a02cb9..a2c4029 100644
--- a/cmd_migrate.c
+++ b/cmd_migrate.c
@@ -502,9 +502,12 @@ next:
}
static ranges reserve_new_fs_space(const char *file_path, unsigned block_size,
- u64 size, u64 *bcachefs_inum, dev_t dev)
+ u64 size, u64 *bcachefs_inum, dev_t dev,
+ bool force)
{
- int fd = open(file_path, O_RDWR|O_CREAT|O_EXCL, 0600);
+ int fd = force
+ ? open(file_path, O_RDWR|O_CREAT, 0600)
+ : open(file_path, O_RDWR|O_CREAT|O_EXCL, 0600);
if (fd < 0)
die("Error creating %s for bcachefs metadata: %s",
file_path, strerror(errno));
@@ -625,6 +628,7 @@ static void migrate_usage(void)
" -f fs Root of filesystem to migrate(s)\n"
" --encrypted Enable whole filesystem encryption (chacha20/poly1305)\n"
" --no_passphrase Don't encrypt master encryption key\n"
+ " -F Force, even if metadata file already exists\n"
" -h Display this help and exit\n"
"Report bugs to <linux-bcache@vger.kernel.org>");
}
@@ -640,10 +644,10 @@ int cmd_migrate(int argc, char *argv[])
struct format_opts format_opts = format_opts_default();
char *fs_path = NULL;
unsigned block_size;
- bool no_passphrase = false;
+ bool no_passphrase = false, force = false;
int opt;
- while ((opt = getopt_long(argc, argv, "f:h",
+ while ((opt = getopt_long(argc, argv, "f:Fh",
migrate_opts, NULL)) != -1)
switch (opt) {
case 'f':
@@ -655,6 +659,9 @@ int cmd_migrate(int argc, char *argv[])
case 'p':
no_passphrase = true;
break;
+ case 'F':
+ force = true;
+ break;
case 'h':
migrate_usage();
exit(EXIT_SUCCESS);
@@ -688,7 +695,7 @@ int cmd_migrate(int argc, char *argv[])
ranges extents = reserve_new_fs_space(file_path,
block_size, get_size(dev.path, dev.fd) / 5,
- &bcachefs_inum, stat.st_dev);
+ &bcachefs_inum, stat.st_dev, force);
find_superblock_space(extents, &dev);