]> git.sesse.net Git - bcachefs-tools-debian/blob - cmd_counters.c
Update bcachefs sources to cbb2e45634dd bcachefs: fix simulateously upgrading & downg...
[bcachefs-tools-debian] / cmd_counters.c
1 #include <getopt.h>
2
3 #include "cmds.h"
4 #include "libbcachefs.h"
5 #include "libbcachefs/super-io.h"
6
7 static void reset_counters_usage(void)
8 {
9         puts("bcachefs reset-counters \n"
10              "Usage: bcachefs reset-counters device\n"
11              "\n"
12              "Options:\n"
13              "  -h, --help                  display this help and exit\n"
14              "Report bugs to <linux-bcachefs@vger.kernel.org>");
15         exit(EXIT_SUCCESS);
16 }
17
18 int cmd_reset_counters(int argc, char *argv[])
19 {
20         static const struct option longopts[] = {
21                 { "help",                       0, NULL, 'h' },
22                 { NULL }
23         };
24         int opt;
25
26         while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1)
27                 switch (opt) {
28                 case 'h':
29                         reset_counters_usage();
30                         break;
31                 }
32         args_shift(optind);
33
34         char *dev = arg_pop();
35         if (!dev)
36                 die("please supply a device");
37         if (argc)
38                 die("too many arguments");
39
40         struct bch_opts opts = bch2_opts_empty();
41         struct bch_sb_handle sb;
42         int ret = bch2_read_super(dev, &opts, &sb);
43         if (ret)
44                 die("Error opening %s: %s", dev, bch2_err_str(ret));
45
46         bch2_sb_field_resize(&sb, counters, 0);
47
48         bch2_super_write(sb.bdev->bd_buffered_fd, sb.sb);
49         bch2_free_super(&sb);
50         return 0;
51 }