Convert to BCH_IOCTL_DEV_USAGE_V2

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2023-11-23 19:42:47 -05:00
parent 3a0cc86e76
commit 7465d1934c
3 changed files with 34 additions and 19 deletions

View File

@ -324,13 +324,15 @@ int cmd_device_evacuate(int argc, char *argv[])
int dev_idx;
struct bchfs_handle fs = bchu_fs_open_by_dev(dev_path, &dev_idx);
struct bch_ioctl_dev_usage u = bchu_dev_usage(fs, dev_idx);
struct bch_ioctl_dev_usage_v2 *u = bchu_dev_usage(fs, dev_idx);
if (u.state == BCH_MEMBER_STATE_rw) {
if (u->state == BCH_MEMBER_STATE_rw) {
printf("Setting %s readonly\n", dev_path);
bchu_disk_set_state(fs, dev_idx, BCH_MEMBER_STATE_ro, 0);
}
free(u);
return bchu_data(fs, (struct bch_ioctl_data) {
.op = BCH_DATA_OP_migrate,
.start_btree = 0,

View File

@ -36,7 +36,7 @@ static void __dev_usage_type_to_text(struct printbuf *out,
}
static void dev_usage_type_to_text(struct printbuf *out,
struct bch_ioctl_dev_usage *u,
struct bch_ioctl_dev_usage_v2 *u,
enum bch_data_type type)
{
__dev_usage_type_to_text(out, bch2_data_types[type],
@ -50,8 +50,7 @@ static void dev_usage_to_text(struct printbuf *out,
struct bchfs_handle fs,
struct dev_name *d)
{
struct bch_ioctl_dev_usage u = bchu_dev_usage(fs, d->idx);
unsigned i;
struct bch_ioctl_dev_usage_v2 *u = bchu_dev_usage(fs, d->idx);
prt_newline(out);
prt_printf(out, "%s (device %u):", d->label ?: "(no label)", d->idx);
@ -59,7 +58,7 @@ static void dev_usage_to_text(struct printbuf *out,
prt_str(out, d->dev ?: "(device not found)");
prt_tab_rjust(out);
prt_str(out, bch2_member_states[u.state]);
prt_str(out, bch2_member_states[u->state]);
prt_tab_rjust(out);
prt_newline(out);
@ -78,23 +77,21 @@ static void dev_usage_to_text(struct printbuf *out,
prt_newline(out);
for (i = 0; i < BCH_DATA_NR; i++)
dev_usage_type_to_text(out, &u, i);
__dev_usage_type_to_text(out, "erasure coded",
u.bucket_size,
u.buckets_ec, u.buckets_ec * u.bucket_size, 0);
for (unsigned i = 0; i < u->nr_data_types; i++)
dev_usage_type_to_text(out, u, i);
prt_str(out, "capacity:");
prt_tab(out);
prt_units_u64(out, (u.nr_buckets * u.bucket_size) << 9);
prt_units_u64(out, (u->nr_buckets * u->bucket_size) << 9);
prt_tab_rjust(out);
prt_printf(out, "%llu", u.nr_buckets);
prt_printf(out, "%llu", u->nr_buckets);
prt_tab_rjust(out);
printbuf_indent_sub(out, 2);
prt_newline(out);
free(u);
}
static int dev_by_label_cmp(const void *_l, const void *_r)

View File

@ -167,14 +167,30 @@ static inline struct bch_ioctl_fs_usage *bchu_fs_usage(struct bchfs_handle fs)
}
}
static inline struct bch_ioctl_dev_usage bchu_dev_usage(struct bchfs_handle fs,
unsigned idx)
static inline struct bch_ioctl_dev_usage_v2 *bchu_dev_usage(struct bchfs_handle fs,
unsigned idx)
{
struct bch_ioctl_dev_usage i = { .dev = idx, .flags = BCH_BY_INDEX};
struct bch_ioctl_dev_usage_v2 *u = xcalloc(sizeof(*u) + sizeof(u->d[0]) * BCH_DATA_NR, 1);
if (xioctl(fs.ioctl_fd, BCH_IOCTL_DEV_USAGE, &i))
die("BCH_IOCTL_DEV_USAGE error: %m");
return i;
u->dev = idx;
u->flags = BCH_BY_INDEX;
u->nr_data_types = BCH_DATA_NR;
if (!ioctl(fs.ioctl_fd, BCH_IOCTL_DEV_USAGE_V2, u))
return u;
struct bch_ioctl_dev_usage u_v1 = { .dev = idx, .flags = BCH_BY_INDEX};
xioctl(fs.ioctl_fd, BCH_IOCTL_DEV_USAGE, &u_v1);
u->state = u_v1.state;
u->nr_data_types = ARRAY_SIZE(u_v1.d);
u->bucket_size = u_v1.bucket_size;
u->nr_buckets = u_v1.nr_buckets;
for (unsigned i = 0; i < ARRAY_SIZE(u_v1.d); i++)
u->d[i] = u_v1.d[i];
return u;
}
static inline struct bch_sb *bchu_read_super(struct bchfs_handle fs, unsigned idx)