mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-09 00:00:04 +03:00
add a force flag to cmd_migrate
This commit is contained in:
parent
07ddcf0bef
commit
076b4196fc
@ -502,9 +502,12 @@ next:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ranges reserve_new_fs_space(const char *file_path, unsigned block_size,
|
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)
|
if (fd < 0)
|
||||||
die("Error creating %s for bcachefs metadata: %s",
|
die("Error creating %s for bcachefs metadata: %s",
|
||||||
file_path, strerror(errno));
|
file_path, strerror(errno));
|
||||||
@ -625,6 +628,7 @@ static void migrate_usage(void)
|
|||||||
" -f fs Root of filesystem to migrate(s)\n"
|
" -f fs Root of filesystem to migrate(s)\n"
|
||||||
" --encrypted Enable whole filesystem encryption (chacha20/poly1305)\n"
|
" --encrypted Enable whole filesystem encryption (chacha20/poly1305)\n"
|
||||||
" --no_passphrase Don't encrypt master encryption key\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"
|
" -h Display this help and exit\n"
|
||||||
"Report bugs to <linux-bcache@vger.kernel.org>");
|
"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();
|
struct format_opts format_opts = format_opts_default();
|
||||||
char *fs_path = NULL;
|
char *fs_path = NULL;
|
||||||
unsigned block_size;
|
unsigned block_size;
|
||||||
bool no_passphrase = false;
|
bool no_passphrase = false, force = false;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "f:h",
|
while ((opt = getopt_long(argc, argv, "f:Fh",
|
||||||
migrate_opts, NULL)) != -1)
|
migrate_opts, NULL)) != -1)
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -655,6 +659,9 @@ int cmd_migrate(int argc, char *argv[])
|
|||||||
case 'p':
|
case 'p':
|
||||||
no_passphrase = true;
|
no_passphrase = true;
|
||||||
break;
|
break;
|
||||||
|
case 'F':
|
||||||
|
force = true;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
migrate_usage();
|
migrate_usage();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
@ -688,7 +695,7 @@ int cmd_migrate(int argc, char *argv[])
|
|||||||
|
|
||||||
ranges extents = reserve_new_fs_space(file_path,
|
ranges extents = reserve_new_fs_space(file_path,
|
||||||
block_size, get_size(dev.path, dev.fd) / 5,
|
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);
|
find_superblock_space(extents, &dev);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user