]> git.sesse.net Git - bcachefs-tools-debian/blob - cmd_fs.c
New data rereplicate command
[bcachefs-tools-debian] / cmd_fs.c
1
2 #include <stdio.h>
3 #include <sys/ioctl.h>
4
5 #include <uuid/uuid.h>
6
7 #include "libbcachefs/bcachefs_ioctl.h"
8 #include "libbcachefs/opts.h"
9
10 #include "cmds.h"
11 #include "libbcachefs.h"
12
13 static void print_fs_usage(const char *path, enum units units)
14 {
15         unsigned i, j;
16         char uuid[40];
17
18         struct bchfs_handle fs = bcache_fs_open(path);
19         struct bch_ioctl_usage *u = bchu_usage(fs);
20
21         uuid_unparse(fs.uuid.b, uuid);
22         printf("Filesystem %s:\n", uuid);
23
24         printf("%-20s%12s\n", "Size:", pr_units(u->fs.capacity, units));
25         printf("%-20s%12s\n", "Used:", pr_units(u->fs.used, units));
26
27         printf("%-20s%12s%12s%12s%12s\n",
28                "By replicas:", "1x", "2x", "3x", "4x");
29
30         for (j = BCH_DATA_BTREE; j < BCH_DATA_NR; j++) {
31                 printf_pad(20, "  %s:", bch2_data_types[j]);
32
33                 for (i = 0; i < BCH_REPLICAS_MAX; i++)
34                         printf("%12s", pr_units(u->fs.sectors[j][i], units));
35                 printf("\n");
36         }
37
38         printf_pad(20, "  %s:", "reserved");
39         for (i = 0; i < BCH_REPLICAS_MAX; i++)
40                 printf("%12s", pr_units(u->fs.persistent_reserved[i], units));
41         printf("\n");
42
43         printf("%-20s%12s\n", "  online reserved:", pr_units(u->fs.online_reserved, units));
44
45         for (i = 0; i < u->nr_devices; i++) {
46                 struct bch_ioctl_dev_usage *d = u->devs + i;
47                 char *name = NULL;
48
49                 if (!d->alive)
50                         continue;
51
52                 printf("\n");
53                 printf_pad(20, "Device %u usage:", i);
54                 name = !d->dev ? strdup("(offline)")
55                         : dev_to_path(d->dev)
56                         ?: strdup("(device not found)");
57
58                 printf("%24s%12s\n", name, bch2_dev_state[d->state]);
59                 free(name);
60
61                 printf("%-20s%12s%12s%12s\n",
62                        "", "data", "buckets", "fragmented");
63
64                 for (j = BCH_DATA_SB; j < BCH_DATA_NR; j++) {
65                         u64 frag = max((s64) d->buckets[j] * d->bucket_size -
66                                        (s64) d->sectors[j], 0LL);
67
68                         printf_pad(20, "  %s:", bch2_data_types[j]);
69                         printf("%12s%12llu%12s\n",
70                                pr_units(d->sectors[j], units),
71                                d->buckets[j],
72                                pr_units(frag, units));
73                 }
74         }
75
76         free(u);
77         bcache_fs_close(fs);
78 }
79
80 int cmd_fs_usage(int argc, char *argv[])
81 {
82         enum units units = BYTES;
83         char *fs;
84         int opt;
85
86         while ((opt = getopt(argc, argv, "h")) != -1)
87                 switch (opt) {
88                 case 'h':
89                         units = HUMAN_READABLE;
90                         break;
91                 }
92         args_shift(optind);
93
94         if (!argc) {
95                 print_fs_usage(".", units);
96         } else {
97                 while ((fs = arg_pop()))
98                         print_fs_usage(fs, units);
99         }
100
101         return 0;
102 }