]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: bch2_alloc_v4_to_text()
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 26 May 2025 18:24:19 +0000 (14:24 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 30 May 2025 05:21:13 +0000 (01:21 -0400)
Specialize the .to_text() for alloc_v4, to avoid the temporary on the
stack for conversion from old versions.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/alloc_background.h

index 173e81c2bbcbc227516b5d9cbf9375c93f3c7702..271d4a2eb15fae42c41140895b1f1e626d51dc14 100644 (file)
@@ -337,11 +337,10 @@ void bch2_alloc_v4_swab(struct bkey_s k)
        a->stripe_sectors       = swab32(a->stripe_sectors);
 }
 
-void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
+static inline void __bch2_alloc_v4_to_text(struct printbuf *out, struct bch_fs *c,
+                                          unsigned dev, const struct bch_alloc_v4 *a)
 {
-       struct bch_alloc_v4 _a;
-       const struct bch_alloc_v4 *a = bch2_alloc_to_v4(k, &_a);
-       struct bch_dev *ca = c ? bch2_dev_bucket_tryget_noerror(c, k.k->p) : NULL;
+       struct bch_dev *ca = c ? bch2_dev_tryget_noerror(c, dev) : NULL;
 
        prt_newline(out);
        printbuf_indent_add(out, 2);
@@ -369,6 +368,19 @@ void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c
        bch2_dev_put(ca);
 }
 
+void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
+{
+       struct bch_alloc_v4 _a;
+       const struct bch_alloc_v4 *a = bch2_alloc_to_v4(k, &_a);
+
+       __bch2_alloc_v4_to_text(out, c, k.k->p.inode, a);
+}
+
+void bch2_alloc_v4_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
+{
+       __bch2_alloc_v4_to_text(out, c, k.k->p.inode, bkey_s_c_to_alloc_v4(k).v);
+}
+
 void __bch2_alloc_to_v4(struct bkey_s_c k, struct bch_alloc_v4 *out)
 {
        if (k.k->type == KEY_TYPE_alloc_v4) {
index 4f94c6a661bf2949b43666711b1d5553d74fecac..b97ae710219f3b7c07e6706065e476c8c9e2a17e 100644 (file)
@@ -253,6 +253,7 @@ int bch2_alloc_v4_validate(struct bch_fs *, struct bkey_s_c,
                           struct bkey_validate_context);
 void bch2_alloc_v4_swab(struct bkey_s);
 void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
+void bch2_alloc_v4_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 
 #define bch2_bkey_ops_alloc ((struct bkey_ops) {       \
        .key_validate   = bch2_alloc_v1_validate,       \
@@ -277,7 +278,7 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 
 #define bch2_bkey_ops_alloc_v4 ((struct bkey_ops) {    \
        .key_validate   = bch2_alloc_v4_validate,       \
-       .val_to_text    = bch2_alloc_to_text,           \
+       .val_to_text    = bch2_alloc_v4_to_text,        \
        .swab           = bch2_alloc_v4_swab,           \
        .trigger        = bch2_trigger_alloc,           \
        .min_val_size   = 48,                           \