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