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