Skip to content

Commit

Permalink
New data rereplicate command
Browse files Browse the repository at this point in the history
  • Loading branch information
koverstreet committed Feb 8, 2018
1 parent 6976570 commit 7875b82
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 218 deletions.
17 changes: 17 additions & 0 deletions bcachefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ static void usage(void)
" device set-state Mark a device as failed\n"
" device resize Resize filesystem on a device\n"
"\n"
"Commands for managing filesystem data:\n"
" data rereplicate Rereplicate degraded data\n"
"\n"
"Encryption:\n"
" unlock Unlock an encrypted filesystem prior to running/mounting\n"
" set-passphrase Change passphrase on an existing (unmounted) filesystem\n"
Expand Down Expand Up @@ -120,6 +123,17 @@ static int device_cmds(int argc, char *argv[])
return 0;
}

static int data_cmds(int argc, char *argv[])
{
char *cmd = pop_cmd(&argc, argv);

if (!strcmp(cmd, "rereplicate"))
return cmd_data_rereplicate(argc, argv);

usage();
return 0;
}

int main(int argc, char *argv[])
{
full_cmd = argv[0];
Expand Down Expand Up @@ -151,6 +165,9 @@ int main(int argc, char *argv[])
if (!strcmp(cmd, "device"))
return device_cmds(argc, argv);

if (!strcmp(cmd, "data"))
return data_cmds(argc, argv);

if (!strcmp(cmd, "unlock"))
return cmd_unlock(argc, argv);
if (!strcmp(cmd, "set-passphrase"))
Expand Down
48 changes: 48 additions & 0 deletions cmd_data.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@


#include <stdio.h>
#include <sys/ioctl.h>

#include "libbcachefs/bcachefs_ioctl.h"

#include "cmds.h"
#include "libbcachefs.h"

static void data_rereplicate_usage(void)
{
puts("bcachefs data rereplicate\n"
"Usage: bcachefs data rereplicate filesystem\n"
"\n"
"Walks existing data in a filesystem, writing additional copies\n"
"of any degraded data\n"
"\n"
"Options:\n"
" -h, --help display this help and exit\n"
"Report bugs to <linux-bcache@vger.kernel.org>");
exit(EXIT_SUCCESS);
}

int cmd_data_rereplicate(int argc, char *argv[])
{
int opt;

while ((opt = getopt(argc, argv, "h")) != -1)
switch (opt) {
case 'h':
data_rereplicate_usage();
}
args_shift(optind);

char *fs_path = arg_pop();
if (!fs_path)
die("Please supply a filesystem");

if (argc)
die("too many arguments");

return bchu_data(bcache_fs_open(fs_path), (struct bch_ioctl_data) {
.op = BCH_DATA_OP_REREPLICATE,
.start = POS_MIN,
.end = POS_MAX,
});
}
20 changes: 11 additions & 9 deletions cmd_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,17 @@ int cmd_dump(int argc, char *argv[])
dump_usage();
exit(EXIT_SUCCESS);
}

if (optind >= argc)
die("Please supply device(s) to check");
args_shift(optind);

if (!out)
die("Please supply output filename");

struct bch_fs *c = bch2_fs_open(argv + optind, argc - optind, opts);
if (!argc)
die("Please supply device(s) to check");

struct bch_fs *c = bch2_fs_open(argv, argc, opts);
if (IS_ERR(c))
die("error opening %s: %s", argv[optind], strerror(-PTR_ERR(c)));
die("error opening %s: %s", argv[0], strerror(-PTR_ERR(c)));

down_read(&c->gc_lock);

Expand Down Expand Up @@ -299,13 +300,14 @@ int cmd_list(int argc, char *argv[])
list_keys_usage();
exit(EXIT_SUCCESS);
}
args_shift(optind);

if (optind >= argc)
die("Please supply device(s) to check");
if (!argc)
die("Please supply device(s)");

struct bch_fs *c = bch2_fs_open(argv + optind, argc - optind, opts);
struct bch_fs *c = bch2_fs_open(argv, argc, opts);
if (IS_ERR(c))
die("error opening %s: %s", argv[optind], strerror(-PTR_ERR(c)));
die("error opening %s: %s", argv[0], strerror(-PTR_ERR(c)));

switch (mode) {
case 0:
Expand Down
Loading

0 comments on commit 7875b82

Please sign in to comment.