Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcachefs: bch2_disk_path_to_text() no longer takes sb_lock

We're going to be using bch2_target_to_text() ->
bch2_disk_path_to_text() from bch2_bkey_ptrs_to_text() and
bch2_bkey_ptrs_invalid(), which can be called in any context.

This patch adds the actual label to bch_disk_group_cpu so that it can be
used by bch2_disk_path_to_text, and splits out bch2_disk_path_to_text()
into two variants - like the previous patch, one for when we have a
running filesystem and another for when we only have a superblock.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

+61 -14
+54 -5
fs/bcachefs/disk_groups.c
··· 175 175 176 176 dst->deleted = BCH_GROUP_DELETED(src); 177 177 dst->parent = BCH_GROUP_PARENT(src); 178 + memcpy(dst->label, src->label, sizeof(dst->label)); 178 179 } 179 180 180 181 for (i = 0; i < c->disk_sb.sb->nr_devices; i++) { ··· 383 382 return v; 384 383 } 385 384 386 - void bch2_disk_path_to_text(struct printbuf *out, struct bch_sb *sb, unsigned v) 385 + void bch2_disk_path_to_text(struct printbuf *out, struct bch_fs *c, unsigned v) 386 + { 387 + struct bch_disk_groups_cpu *groups; 388 + struct bch_disk_group_cpu *g; 389 + unsigned nr = 0; 390 + u16 path[32]; 391 + 392 + out->atomic++; 393 + rcu_read_lock(); 394 + groups = rcu_dereference(c->disk_groups); 395 + if (!groups) 396 + goto invalid; 397 + 398 + while (1) { 399 + if (nr == ARRAY_SIZE(path)) 400 + goto invalid; 401 + 402 + if (v >= groups->nr) 403 + goto invalid; 404 + 405 + g = groups->entries + v; 406 + 407 + if (g->deleted) 408 + goto invalid; 409 + 410 + path[nr++] = v; 411 + 412 + if (!g->parent) 413 + break; 414 + 415 + v = g->parent - 1; 416 + } 417 + 418 + while (nr) { 419 + v = path[--nr]; 420 + g = groups->entries + v; 421 + 422 + prt_printf(out, "%.*s", (int) sizeof(g->label), g->label); 423 + if (nr) 424 + prt_printf(out, "."); 425 + } 426 + out: 427 + rcu_read_unlock(); 428 + out->atomic--; 429 + return; 430 + invalid: 431 + prt_printf(out, "invalid label %u", v); 432 + goto out; 433 + } 434 + 435 + void bch2_disk_path_to_text_sb(struct printbuf *out, struct bch_sb *sb, unsigned v) 387 436 { 388 437 struct bch_sb_field_disk_groups *groups = 389 438 bch2_sb_field_get(sb, disk_groups); ··· 573 522 break; 574 523 } 575 524 case TARGET_GROUP: 576 - mutex_lock(&c->sb_lock); 577 - bch2_disk_path_to_text(out, c->disk_sb.sb, t.group); 578 - mutex_unlock(&c->sb_lock); 525 + bch2_disk_path_to_text(out, c, t.group); 579 526 break; 580 527 default: 581 528 BUG(); ··· 601 552 break; 602 553 } 603 554 case TARGET_GROUP: 604 - bch2_disk_path_to_text(out, sb, t.group); 555 + bch2_disk_path_to_text_sb(out, sb, t.group); 605 556 break; 606 557 default: 607 558 BUG();
+3 -1
fs/bcachefs/disk_groups.h
··· 85 85 /* Exported for userspace bcachefs-tools: */ 86 86 int bch2_disk_path_find_or_create(struct bch_sb_handle *, const char *); 87 87 88 - void bch2_disk_path_to_text(struct printbuf *, struct bch_sb *, unsigned); 88 + void bch2_disk_path_to_text(struct printbuf *, struct bch_fs *, unsigned); 89 + void bch2_disk_path_to_text_sb(struct printbuf *, struct bch_sb *, unsigned); 90 + 89 91 void bch2_target_to_text(struct printbuf *out, struct bch_fs *, unsigned); 90 92 91 93 int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *, struct printbuf *);
+1
fs/bcachefs/disk_groups_types.h
··· 5 5 struct bch_disk_group_cpu { 6 6 bool deleted; 7 7 u16 parent; 8 + u8 label[BCH_SB_LABEL_SIZE]; 8 9 struct bch_devs_mask devs; 9 10 }; 10 11
+1 -1
fs/bcachefs/super.c
··· 1582 1582 dev_mi = bch2_sb_member_get(sb.sb, sb.sb->dev_idx); 1583 1583 1584 1584 if (BCH_MEMBER_GROUP(&dev_mi)) { 1585 - bch2_disk_path_to_text(&label, sb.sb, BCH_MEMBER_GROUP(&dev_mi) - 1); 1585 + bch2_disk_path_to_text_sb(&label, sb.sb, BCH_MEMBER_GROUP(&dev_mi) - 1); 1586 1586 if (label.allocation_failure) { 1587 1587 ret = -ENOMEM; 1588 1588 goto err;
+2 -7
fs/bcachefs/sysfs.c
··· 910 910 sysfs_print(discard, ca->mi.discard); 911 911 912 912 if (attr == &sysfs_label) { 913 - if (ca->mi.group) { 914 - mutex_lock(&c->sb_lock); 915 - bch2_disk_path_to_text(out, c->disk_sb.sb, 916 - ca->mi.group - 1); 917 - mutex_unlock(&c->sb_lock); 918 - } 919 - 913 + if (ca->mi.group) 914 + bch2_disk_path_to_text(out, c, ca->mi.group - 1); 920 915 prt_char(out, '\n'); 921 916 } 922 917