summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2025-02-06 10:26:10 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2025-02-06 10:26:10 -0500
commit7d30f895c68e28766387be99ab57d79380e8a4a7 (patch)
tree2e10f567e2afb7f5f7f281b08aaddd43cda2fb5d
parent67c9b378c7e7820b91033004b032e236a8069b4a (diff)
cmd_fs_usage: Handle querying old versions
Fix reading accounting from old kernel versions that had it in little endian. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--c_src/cmd_fs.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/c_src/cmd_fs.c b/c_src/cmd_fs.c
index a6da2515..cda9a755 100644
--- a/c_src/cmd_fs.c
+++ b/c_src/cmd_fs.c
@@ -237,6 +237,17 @@ static void accounting_sort(darray_accounting_p *sorted,
sort(sorted->data, sorted->nr, sizeof(sorted->data[0]), accounting_p_cmp, NULL);
}
+static void accounting_swab_if_old(struct bch_ioctl_query_accounting *in)
+{
+ u64 kernel_version = read_file_u64(AT_FDCWD, "/sys/module/bcachefs/parameters/version");
+
+ if (kernel_version < bcachefs_metadata_version_disk_accounting_big_endian)
+ for (struct bkey_i_accounting *a = in->accounting;
+ a < (struct bkey_i_accounting *) ((u64 *) in->accounting + in->accounting_u64s);
+ a = bkey_i_to_accounting(bkey_next(&a->k_i)))
+ bch2_bpos_swab(&a->k.p);
+}
+
static int fs_usage_v1_to_text(struct printbuf *out,
struct bchfs_handle fs,
dev_names dev_names)
@@ -251,6 +262,8 @@ static int fs_usage_v1_to_text(struct printbuf *out,
if (!a)
return -1;
+ accounting_swab_if_old(a);
+
darray_accounting_p a_sorted = {};
accounting_sort(&a_sorted, a);