mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-22 00:00:03 +03:00
New data job command
This adds a new subcommand, bcachefs data job, that gives more direct access to the data job/ioctl functionality, and hooks up the new rewrite old nodes data job.
This commit is contained in:
parent
aa0ddf3cf9
commit
cc92b0f5a2
@ -59,6 +59,7 @@ static void usage(void)
|
||||
"\n"
|
||||
"Commands for managing filesystem data:\n"
|
||||
" data rereplicate Rereplicate degraded data\n"
|
||||
" data job Kick off low level data jobs\n"
|
||||
"\n"
|
||||
"Encryption:\n"
|
||||
" unlock Unlock an encrypted filesystem prior to running/mounting\n"
|
||||
@ -141,6 +142,8 @@ static int data_cmds(int argc, char *argv[])
|
||||
|
||||
if (!strcmp(cmd, "rereplicate"))
|
||||
return cmd_data_rereplicate(argc, argv);
|
||||
if (!strcmp(cmd, "job"))
|
||||
return cmd_data_job(argc, argv);
|
||||
|
||||
usage();
|
||||
return 0;
|
||||
|
74
cmd_data.c
74
cmd_data.c
@ -4,6 +4,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "libbcachefs/bcachefs_ioctl.h"
|
||||
#include "libbcachefs/btree_cache.h"
|
||||
|
||||
#include "cmds.h"
|
||||
#include "libbcachefs.h"
|
||||
@ -48,3 +49,76 @@ int cmd_data_rereplicate(int argc, char *argv[])
|
||||
.end_pos = POS_MAX,
|
||||
});
|
||||
}
|
||||
|
||||
static void data_job_usage(void)
|
||||
{
|
||||
puts("bcachefs data job\n"
|
||||
"Usage: bcachefs data job [job} filesystem\n"
|
||||
"\n"
|
||||
"Kick off a data job and report progress\n"
|
||||
"\n"
|
||||
"job: one of scrub, rereplicate, migrate, or rewrite_old_nodes\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -b btree btree to operate on\n"
|
||||
" -s inode:offset start position\n"
|
||||
" -e inode:offset end position\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
"Report bugs to <linux-bcache@vger.kernel.org>");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
const char * const data_jobs[] = {
|
||||
"scrub",
|
||||
"rereplicate",
|
||||
"migrate",
|
||||
"rewrite_old_nodes",
|
||||
NULL
|
||||
};
|
||||
|
||||
int cmd_data_job(int argc, char *argv[])
|
||||
{
|
||||
struct bch_ioctl_data op = {
|
||||
.start_btree = 0,
|
||||
.start_pos = POS_MIN,
|
||||
.end_btree = BTREE_ID_NR,
|
||||
.end_pos = POS_MAX,
|
||||
};
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "s:e:h")) != -1)
|
||||
switch (opt) {
|
||||
case 'b':
|
||||
op.start_btree = read_string_list_or_die(optarg,
|
||||
bch2_btree_ids, "btree id");
|
||||
op.end_btree = op.start_btree;
|
||||
break;
|
||||
case 's':
|
||||
op.start_pos = bpos_parse(optarg);
|
||||
break;
|
||||
op.end_pos = bpos_parse(optarg);
|
||||
case 'e':
|
||||
break;
|
||||
case 'h':
|
||||
data_job_usage();
|
||||
}
|
||||
args_shift(optind);
|
||||
|
||||
char *job = arg_pop();
|
||||
if (!job)
|
||||
die("please specify which type of job");
|
||||
|
||||
op.op = read_string_list_or_die(job, data_jobs, "bad job type");
|
||||
|
||||
if (op.op == BCH_DATA_OP_SCRUB)
|
||||
die("scrub not implemented yet");
|
||||
|
||||
char *fs_path = arg_pop();
|
||||
if (!fs_path)
|
||||
fs_path = ".";
|
||||
|
||||
if (argc)
|
||||
die("too many arguments");
|
||||
|
||||
return bchu_data(bcache_fs_open(fs_path), op);
|
||||
}
|
||||
|
23
cmd_debug.c
23
cmd_debug.c
@ -389,25 +389,6 @@ static void list_nodes_keys(struct bch_fs *c, enum btree_id btree_id,
|
||||
bch2_trans_exit(&trans);
|
||||
}
|
||||
|
||||
static struct bpos parse_pos(char *buf)
|
||||
{
|
||||
char *s = buf, *field;
|
||||
u64 inode_v = 0, offset_v = 0;
|
||||
|
||||
if (!(field = strsep(&s, ":")) ||
|
||||
kstrtoull(field, 10, &inode_v))
|
||||
die("invalid bpos %s", buf);
|
||||
|
||||
if ((field = strsep(&s, ":")) &&
|
||||
kstrtoull(field, 10, &offset_v))
|
||||
die("invalid bpos %s", buf);
|
||||
|
||||
if (s)
|
||||
die("invalid bpos %s", buf);
|
||||
|
||||
return (struct bpos) { .inode = inode_v, .offset = offset_v };
|
||||
}
|
||||
|
||||
static void list_keys_usage(void)
|
||||
{
|
||||
puts("bcachefs list - list filesystem metadata to stdout\n"
|
||||
@ -457,10 +438,10 @@ int cmd_list(int argc, char *argv[])
|
||||
btree_id_end = btree_id_start + 1;
|
||||
break;
|
||||
case 's':
|
||||
start = parse_pos(optarg);
|
||||
start = bpos_parse(optarg);
|
||||
break;
|
||||
case 'e':
|
||||
end = parse_pos(optarg);
|
||||
end = bpos_parse(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
if (kstrtoull(optarg, 10, &inum))
|
||||
|
1
cmds.h
1
cmds.h
@ -31,6 +31,7 @@ int cmd_device_resize(int argc, char *argv[]);
|
||||
int cmd_device_resize_journal(int argc, char *argv[]);
|
||||
|
||||
int cmd_data_rereplicate(int argc, char *argv[]);
|
||||
int cmd_data_job(int argc, char *argv[]);
|
||||
|
||||
int cmd_unlock(int argc, char *argv[]);
|
||||
int cmd_set_passphrase(int argc, char *argv[]);
|
||||
|
19
tools-util.c
19
tools-util.c
@ -663,3 +663,22 @@ int dev_mounted(char *dev)
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
struct bpos bpos_parse(char *buf)
|
||||
{
|
||||
char *s = buf, *field;
|
||||
u64 inode_v = 0, offset_v = 0;
|
||||
|
||||
if (!(field = strsep(&s, ":")) ||
|
||||
kstrtoull(field, 10, &inode_v))
|
||||
die("invalid bpos %s", buf);
|
||||
|
||||
if ((field = strsep(&s, ":")) &&
|
||||
kstrtoull(field, 10, &offset_v))
|
||||
die("invalid bpos %s", buf);
|
||||
|
||||
if (s)
|
||||
die("invalid bpos %s", buf);
|
||||
|
||||
return (struct bpos) { .inode = inode_v, .offset = offset_v };
|
||||
}
|
||||
|
@ -172,4 +172,6 @@ do { \
|
||||
_ret; \
|
||||
})
|
||||
|
||||
struct bpos bpos_parse(char *);
|
||||
|
||||
#endif /* _TOOLS_UTIL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user