Skip to content

Commit eabef52

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_alloc_v4_to_text()
Specialize the .to_text() for alloc_v4, to avoid the temporary on the stack for conversion from old versions. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 0c34e7f commit eabef52

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,10 @@ void bch2_alloc_v4_swab(struct bkey_s k)
337337
a->stripe_sectors = swab32(a->stripe_sectors);
338338
}
339339

340-
void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
340+
static inline void __bch2_alloc_v4_to_text(struct printbuf *out, struct bch_fs *c,
341+
unsigned dev, const struct bch_alloc_v4 *a)
341342
{
342-
struct bch_alloc_v4 _a;
343-
const struct bch_alloc_v4 *a = bch2_alloc_to_v4(k, &_a);
344-
struct bch_dev *ca = c ? bch2_dev_bucket_tryget_noerror(c, k.k->p) : NULL;
343+
struct bch_dev *ca = c ? bch2_dev_tryget_noerror(c, dev) : NULL;
345344

346345
prt_newline(out);
347346
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
369368
bch2_dev_put(ca);
370369
}
371370

371+
void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
372+
{
373+
struct bch_alloc_v4 _a;
374+
const struct bch_alloc_v4 *a = bch2_alloc_to_v4(k, &_a);
375+
376+
__bch2_alloc_v4_to_text(out, c, k.k->p.inode, a);
377+
}
378+
379+
void bch2_alloc_v4_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
380+
{
381+
__bch2_alloc_v4_to_text(out, c, k.k->p.inode, bkey_s_c_to_alloc_v4(k).v);
382+
}
383+
372384
void __bch2_alloc_to_v4(struct bkey_s_c k, struct bch_alloc_v4 *out)
373385
{
374386
if (k.k->type == KEY_TYPE_alloc_v4) {

fs/bcachefs/alloc_background.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ int bch2_alloc_v4_validate(struct bch_fs *, struct bkey_s_c,
253253
struct bkey_validate_context);
254254
void bch2_alloc_v4_swab(struct bkey_s);
255255
void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
256+
void bch2_alloc_v4_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
256257

257258
#define bch2_bkey_ops_alloc ((struct bkey_ops) { \
258259
.key_validate = bch2_alloc_v1_validate, \
@@ -277,7 +278,7 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
277278

278279
#define bch2_bkey_ops_alloc_v4 ((struct bkey_ops) { \
279280
.key_validate = bch2_alloc_v4_validate, \
280-
.val_to_text = bch2_alloc_to_text, \
281+
.val_to_text = bch2_alloc_v4_to_text, \
281282
.swab = bch2_alloc_v4_swab, \
282283
.trigger = bch2_trigger_alloc, \
283284
.min_val_size = 48, \

0 commit comments

Comments
 (0)