bcachefs: Fix setting ca->name in device add
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 1 May 2025 02:05:49 +0000 (22:05 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:39 +0000 (20:14 -0400)
Device add doesn't get the devide index and attach to the filesystem
until after attaching the block device, and setting the device name from
the block device name - these needs some minor tweaks.

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

index e89b659514b2898d0d97730a8953d1a0681bafaf..9381644cabeea4ec2bc5a72d20e8d78631ad3d8c 100644 (file)
@@ -1488,7 +1488,9 @@ static void bch2_dev_attach(struct bch_fs *c, struct bch_dev *ca,
 {
        ca->dev_idx = dev_idx;
        __set_bit(ca->dev_idx, ca->self.d);
-       scnprintf(ca->name, sizeof(ca->name), "dev-%u", dev_idx);
+
+       if (!ca->name[0])
+               scnprintf(ca->name, sizeof(ca->name), "dev-%u", dev_idx);
 
        ca->fs = c;
        rcu_assign_pointer(c->devs[ca->dev_idx], ca);
@@ -1540,6 +1542,11 @@ static int __bch2_dev_attach_bdev(struct bch_dev *ca, struct bch_sb_handle *sb)
        if (ret)
                return ret;
 
+       struct printbuf name = PRINTBUF;
+       prt_bdevname(&name, sb->bdev);
+       strscpy(ca->name, name.buf, sizeof(ca->name));
+       printbuf_exit(&name);
+
        /* Commit: */
        ca->disk_sb = *sb;
        memset(sb, 0, sizeof(*sb));
@@ -1581,11 +1588,6 @@ static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb)
 
        bch2_dev_sysfs_online(c, ca);
 
-       struct printbuf name = PRINTBUF;
-       prt_bdevname(&name, ca->disk_sb.bdev);
-       strscpy(ca->name, name.buf, sizeof(ca->name));
-       printbuf_exit(&name);
-
        bch2_rebalance_wakeup(c);
        return 0;
 }