]> git.sesse.net Git - bcachefs-tools-debian/blob - cmd_data.c
Fix python test_list
[bcachefs-tools-debian] / cmd_data.c
1
2
3 #include <stdio.h>
4 #include <sys/ioctl.h>
5
6 #include "libbcachefs/bcachefs_ioctl.h"
7 #include "libbcachefs/btree_cache.h"
8
9 #include "cmds.h"
10 #include "libbcachefs.h"
11
12 static void data_rereplicate_usage(void)
13 {
14         puts("bcachefs data rereplicate\n"
15              "Usage: bcachefs data rereplicate filesystem\n"
16              "\n"
17              "Walks existing data in a filesystem, writing additional copies\n"
18              "of any degraded data\n"
19              "\n"
20              "Options:\n"
21              "  -h, --help                  display this help and exit\n"
22              "Report bugs to <linux-bcache@vger.kernel.org>");
23         exit(EXIT_SUCCESS);
24 }
25
26 int cmd_data_rereplicate(int argc, char *argv[])
27 {
28         int opt;
29
30         while ((opt = getopt(argc, argv, "h")) != -1)
31                 switch (opt) {
32                 case 'h':
33                         data_rereplicate_usage();
34                 }
35         args_shift(optind);
36
37         char *fs_path = arg_pop();
38         if (!fs_path)
39                 die("Please supply a filesystem");
40
41         if (argc)
42                 die("too many arguments");
43
44         return bchu_data(bcache_fs_open(fs_path), (struct bch_ioctl_data) {
45                 .op             = BCH_DATA_OP_REREPLICATE,
46                 .start_btree    = 0,
47                 .start_pos      = POS_MIN,
48                 .end_btree      = BTREE_ID_NR,
49                 .end_pos        = POS_MAX,
50         });
51 }
52
53 static void data_job_usage(void)
54 {
55         puts("bcachefs data job\n"
56              "Usage: bcachefs data job [job} filesystem\n"
57              "\n"
58              "Kick off a data job and report progress\n"
59              "\n"
60              "job: one of scrub, rereplicate, migrate, or rewrite_old_nodes\n"
61              "\n"
62              "Options:\n"
63              "  -b btree                    btree to operate on\n"
64              "  -s inode:offset       start position\n"
65              "  -e inode:offset       end position\n"
66              "  -h, --help                  display this help and exit\n"
67              "Report bugs to <linux-bcache@vger.kernel.org>");
68         exit(EXIT_SUCCESS);
69 }
70
71 const char * const data_jobs[] = {
72         "scrub",
73         "rereplicate",
74         "migrate",
75         "rewrite_old_nodes",
76         NULL
77 };
78
79 int cmd_data_job(int argc, char *argv[])
80 {
81         struct bch_ioctl_data op = {
82                 .start_btree    = 0,
83                 .start_pos      = POS_MIN,
84                 .end_btree      = BTREE_ID_NR,
85                 .end_pos        = POS_MAX,
86         };
87         int opt;
88
89         while ((opt = getopt(argc, argv, "s:e:h")) != -1)
90                 switch (opt) {
91                 case 'b':
92                         op.start_btree = read_string_list_or_die(optarg,
93                                                 bch2_btree_ids, "btree id");
94                         op.end_btree = op.start_btree;
95                         break;
96                 case 's':
97                         op.start_pos    = bpos_parse(optarg);
98                         break;
99                         op.end_pos      = bpos_parse(optarg);
100                 case 'e':
101                         break;
102                 case 'h':
103                         data_job_usage();
104                 }
105         args_shift(optind);
106
107         char *job = arg_pop();
108         if (!job)
109                 die("please specify which type of job");
110
111         op.op = read_string_list_or_die(job, data_jobs, "bad job type");
112
113         if (op.op == BCH_DATA_OP_SCRUB)
114                 die("scrub not implemented yet");
115
116         char *fs_path = arg_pop();
117         if (!fs_path)
118                 fs_path = ".";
119
120         if (argc)
121                 die("too many arguments");
122
123         return bchu_data(bcache_fs_open(fs_path), op);
124 }