diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2017-12-23 00:50:55 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2017-12-23 00:51:19 -0500 |
commit | 30caf69540dfb3913e8b5c0359f7714dd52a08cb (patch) | |
tree | 03234fa5cae288231f7ae1ca44adf852cd330175 /cmd_fs.c | |
parent | 14117dcdfb3942d08f8c6446aae9df9f8d2e42db (diff) |
Add bcachefs fs usage
Diffstat (limited to 'cmd_fs.c')
-rw-r--r-- | cmd_fs.c | 132 |
1 files changed, 107 insertions, 25 deletions
@@ -1,43 +1,125 @@ -#include "cmds.h" +#include <stdio.h> +#include <sys/ioctl.h> -struct bcache_fs { - /* options... */ +#include <uuid/uuid.h> - u64 capacity; +#include "libbcachefs/bcachefs_ioctl.h" +#include "libbcachefs/opts.h" - /* XXX: dirty != used, it doesn't count metadata */ - u64 bytes_dirty; -}; +#include "cmds.h" -#if 0 -static struct bcache_fs fill_fs(struct bcache_handle fs) +static inline int printf_pad(unsigned pad, const char * fmt, ...) { - return (struct bcache_fs) { - }; + va_list args; + int ret; + + va_start(args, fmt); + ret = vprintf(fmt, args); + va_end(args); + + while (ret++ < pad) + putchar(' '); + + return ret; } -#endif -int cmd_fs_show(int argc, char *argv[]) +static void print_fs_usage(const char *path, enum units units) { - if (argc != 2) - die("Please supply a filesystem"); + unsigned i, j, nr_devices = 4; + struct bcache_handle fs = bcache_fs_open(path); + struct bch_ioctl_usage *u = NULL; + char uuid[40]; -#if 0 - struct bcache_handle fs = bcache_fs_open(argv[1]); -#endif + while (1) { + u = xrealloc(u, sizeof(*u) + sizeof(u->devs[0]) * nr_devices); + u->nr_devices = nr_devices; - return 0; + if (!ioctl(fs.ioctl_fd, BCH_IOCTL_USAGE, u)) + break; + if (errno != ENOSPC) + die("BCH_IOCTL_USAGE error: %m"); + nr_devices *= 2; + } + + uuid_unparse(fs.uuid.b, uuid); + printf("Filesystem %s:\n", uuid); + + printf("%-20s%12s\n", "Size:", pr_units(u->fs.capacity, units)); + printf("%-20s%12s\n", "Used:", pr_units(u->fs.used, units)); + + printf("%-20s%12s%12s%12s%12s\n", + "By replicas:", "1x", "2x", "3x", "4x"); + + for (j = BCH_DATA_BTREE; j < BCH_DATA_NR; j++) { + printf_pad(20, " %s:", bch2_data_types[j]); + + for (i = 0; i < BCH_REPLICAS_MAX; i++) + printf("%12s", pr_units(u->fs.sectors[j][i], units)); + printf("\n"); + } + + printf_pad(20, " %s:", "reserved"); + for (i = 0; i < BCH_REPLICAS_MAX; i++) + printf("%12s", pr_units(u->fs.persistent_reserved[i], units)); + printf("\n"); + + printf("%-20s%12s\n", " online reserved:", pr_units(u->fs.online_reserved, units)); + + for (i = 0; i < u->nr_devices; i++) { + struct bch_ioctl_dev_usage *d = u->devs + i; + char *name = NULL; + + if (!d->alive) + continue; + + printf("\n"); + printf_pad(20, "Device %u usage:", i); + name = !d->dev ? strdup("(offline)") + : dev_to_path(d->dev) + ?: strdup("(device not found)"); + + printf("%24s%12s\n", name, bch2_dev_state[d->state]); + free(name); + + printf("%-20s%12s%12s%12s\n", + "", "data", "buckets", "fragmented"); + + for (j = BCH_DATA_SB; j < BCH_DATA_NR; j++) { + u64 frag = max((s64) d->buckets[j] * d->bucket_size - + (s64) d->sectors[j], 0LL); + + printf_pad(20, " %s:", bch2_data_types[j]); + printf("%12s%12llu%12s\n", + pr_units(d->sectors[j], units), + d->buckets[j], + pr_units(frag, units)); + } + } + + free(u); + bcache_fs_close(fs); } -int cmd_fs_set(int argc, char *argv[]) +int cmd_fs_usage(int argc, char *argv[]) { - if (argc != 2) - die("Please supply a filesystem"); + enum units units = BYTES; + unsigned i; + int opt; + + while ((opt = getopt(argc, argv, "h")) != -1) + switch (opt) { + case 'h': + units = HUMAN_READABLE; + break; + } -#if 0 - struct bcache_handle fs = bcache_fs_open(argv[1]); -#endif + if (argc - optind < 1) { + print_fs_usage(".", units); + } else { + for (i = optind; i < argc; i++) + print_fs_usage(argv[i], units); + } return 0; } |