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 65bcca2
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 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 @@ -119,18 +120,17 @@ static struct dev_name *dev_idx_to_name(dev_names *dev_names, unsigned idx)
}

static void replicas_usage_to_text(struct printbuf *out,
struct bch_sb *sb,
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++) {
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);

Expand All @@ -150,6 +150,15 @@ 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);

unsigned durability = 0;
for (unsigned i = 0; i < r->r.nr_devs; i++) {
struct bch_member m = bch2_sb_member_get(sb, r->r.devs[i]);
durability += BCH_MEMBER_DURABILITY(&m);
}

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

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

Expand Down Expand Up @@ -215,6 +224,9 @@ static void fs_usage_to_text(struct printbuf *out, const char *path)
prt_str(out, "Required/total");
prt_tab(out);

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

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

Expand All @@ -232,26 +244,28 @@ static void fs_usage_to_text(struct printbuf *out, const char *path)
prt_newline(out);
}

struct bch_sb *sb = bchu_read_super(fs, -1);
struct bch_replicas_usage *r;

for_each_usage_replica(u, r)
if (r->r.data_type < BCH_DATA_user)
replicas_usage_to_text(out, r, &dev_names);
replicas_usage_to_text(out, sb, r, &dev_names);

for_each_usage_replica(u, r)
if (r->r.data_type == BCH_DATA_user &&
r->r.nr_required <= 1)
replicas_usage_to_text(out, r, &dev_names);
replicas_usage_to_text(out, sb, r, &dev_names);

for_each_usage_replica(u, r)
if (r->r.data_type == BCH_DATA_user &&
r->r.nr_required > 1)
replicas_usage_to_text(out, r, &dev_names);
replicas_usage_to_text(out, sb, r, &dev_names);

for_each_usage_replica(u, r)
if (r->r.data_type > BCH_DATA_user)
replicas_usage_to_text(out, r, &dev_names);
replicas_usage_to_text(out, sb, r, &dev_names);

free(sb);
free(u);

sort(dev_names.data, dev_names.nr,
Expand Down

0 comments on commit 65bcca2

Please sign in to comment.