Skip to content

Commit a26d60d

Browse files
asjkdave
authored andcommitted
btrfs: sysfs: add devinfo/fsid to retrieve actual fsid from the device
In the case of the seed device, the fsid can be different from the mounted sprout fsid. The userland has to read the device superblock to know the fsid but, that idea fails if the device is missing. So add a sysfs interface devinfo/<devid>/fsid to show the fsid of the device. For example: $ cd /sys/fs/btrfs/b10b02a5-f9de-4276-b9e8-2bfd09a578a8 $ cat devinfo/1/fsid c44d771f-639d-4df3-99ec-5bc7ad2af93b $ cat devinfo/3/fsid b10b02a5-f9de-4276-b9e8-2bfd09a578a8 Though it's related to seeding, the name of the sysfs file is plain fsid as it matches what blkid says. A path to the device's fsid will aid scripting. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Anand Jain <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c18e323 commit a26d60d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fs/btrfs/sysfs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,16 @@ static ssize_t btrfs_devinfo_writeable_show(struct kobject *kobj,
15371537
}
15381538
BTRFS_ATTR(devid, writeable, btrfs_devinfo_writeable_show);
15391539

1540+
static ssize_t btrfs_devinfo_fsid_show(struct kobject *kobj,
1541+
struct kobj_attribute *a, char *buf)
1542+
{
1543+
struct btrfs_device *device = container_of(kobj, struct btrfs_device,
1544+
devid_kobj);
1545+
1546+
return sysfs_emit(buf, "%pU\n", device->fs_devices->fsid);
1547+
}
1548+
BTRFS_ATTR(devid, fsid, btrfs_devinfo_fsid_show);
1549+
15401550
static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj,
15411551
struct kobj_attribute *a, char *buf)
15421552
{
@@ -1572,6 +1582,7 @@ BTRFS_ATTR(devid, error_stats, btrfs_devinfo_error_stats_show);
15721582
*/
15731583
static struct attribute *devid_attrs[] = {
15741584
BTRFS_ATTR_PTR(devid, error_stats),
1585+
BTRFS_ATTR_PTR(devid, fsid),
15751586
BTRFS_ATTR_PTR(devid, in_fs_metadata),
15761587
BTRFS_ATTR_PTR(devid, missing),
15771588
BTRFS_ATTR_PTR(devid, replace_target),

0 commit comments

Comments
 (0)