Skip to content

Commit

Permalink
cmd_fs_usage: Print out replica set durability
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Kent Overstreet committed Nov 25, 2023
1 parent 446ec6b commit 138397d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cmd_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "libbcachefs/bcachefs_ioctl.h"
#include "libbcachefs/darray.h"
#include "libbcachefs/opts.h"
#include "libbcachefs/super-io.h"

#include "cmds.h"
#include "libbcachefs.h"
Expand Down Expand Up @@ -122,18 +123,20 @@ static void replicas_usage_to_text(struct printbuf *out,
const struct bch_replicas_usage *r,
dev_names *dev_names)
{
unsigned i;

if (!r->sectors)
return;

char devs[4096], *d = devs;
*d++ = '[';

for (i = 0; i < r->r.nr_devs; i++) {
unsigned durability = 0;

for (unsigned i = 0; i < r->r.nr_devs; i++) {
unsigned dev_idx = r->r.devs[i];
struct dev_name *dev = dev_idx_to_name(dev_names, dev_idx);

durability += dev->durability;

if (i)
*d++ = ' ';

Expand All @@ -150,6 +153,9 @@ static void replicas_usage_to_text(struct printbuf *out,
prt_printf(out, "%u/%u ", r->r.nr_required, r->r.nr_devs);
prt_tab(out);

prt_printf(out, "%u ", durability);
prt_tab(out);

prt_printf(out, "%s ", devs);
prt_tab(out);

Expand Down Expand Up @@ -204,20 +210,25 @@ static void fs_usage_to_text(struct printbuf *out, const char *path)
prt_newline(out);

printbuf_tabstops_reset(out);
printbuf_tabstop_push(out, 16);
printbuf_tabstop_push(out, 16);
printbuf_tabstop_push(out, 18);
printbuf_tabstop_push(out, 18);

printbuf_tabstop_push(out, 16);
prt_str(out, "Data type");
prt_tab(out);

printbuf_tabstop_push(out, 16);
prt_str(out, "Required/total");
prt_tab(out);

printbuf_tabstop_push(out, 14);
prt_str(out, "Durability");
prt_tab(out);

printbuf_tabstop_push(out, 14);
prt_str(out, "Devices");
prt_newline(out);

printbuf_tabstop_push(out, 14);

for (i = 0; i < BCH_REPLICAS_MAX; i++) {
if (!u->persistent_reserved[i])
continue;
Expand Down
4 changes: 4 additions & 0 deletions libbcachefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@ dev_names bchu_fs_get_devices(struct bchfs_handle fs)
n.label = read_file_str(fs.sysfs_fd, label_attr);
free(label_attr);

char *durability_attr = mprintf("dev-%u/durability", n.idx);
n.durability = read_file_u64(fs.sysfs_fd, durability_attr);
free(durability_attr);

darray_push(&devs, n);
}

Expand Down
1 change: 1 addition & 0 deletions libbcachefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ struct dev_name {
char *dev;
char *label;
uuid_t uuid;
unsigned durability;
};
typedef DARRAY(struct dev_name) dev_names;

Expand Down

0 comments on commit 138397d

Please sign in to comment.