bcachefs: Update /dev/disk/by-uuid on device add
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 7 Jun 2025 16:01:22 +0000 (12:01 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 12 Jun 2025 03:21:30 +0000 (23:21 -0400)
Invalidate pagecache after we write the new superblock and send a
uevent.

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

index 397a69da5a7589ca48fa0638fbf6dda65ceba052..8648f22411be8c8364cc9cdfba9e9370d2609bce 100644 (file)
@@ -1995,6 +1995,22 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
                        goto err_late;
        }
 
+       /*
+        * We just changed the superblock UUID, invalidate cache and send a
+        * uevent to update /dev/disk/by-uuid
+        */
+       invalidate_bdev(ca->disk_sb.bdev);
+
+       char uuid_str[37];
+       snprintf(uuid_str, sizeof(uuid_str), "UUID=%pUb", &c->sb.uuid);
+
+       char *envp[] = {
+               "CHANGE=uuid",
+               uuid_str,
+               NULL,
+       };
+       kobject_uevent_env(&ca->disk_sb.bdev->bd_device.kobj, KOBJ_CHANGE, envp);
+
        up_write(&c->state_lock);
 out:
        printbuf_exit(&label);