Skip to content

Commit 2943868

Browse files
adam900710kdave
authored andcommitted
btrfs: ioctl: return device fsid from DEV_INFO ioctl
Currently user space utilizes dev info ioctl to grab the info of a certain devid, this includes its device uuid. But the returned info is not enough to determine if a device is a seed. Commit a26d60d ("btrfs: sysfs: add devinfo/fsid to retrieve actual fsid from the device") exports the same value in sysfs so this is for parity with ioctl. Add a new member, fsid, into btrfs_ioctl_dev_info_args, and populate the member with fsid value. This should not cause any compatibility problem, following the combinations: - Old user space, old kernel - Old user space, new kernel User space tool won't even check the new member. - New user space, old kernel The kernel won't touch the new member, and user space tool should zero out its argument, thus the new member is all zero. User space tool can then know the kernel doesn't support this fsid reporting, and falls back to whatever they can. - New user space, new kernel Go as planned. Would find the fsid member is no longer zero, and trust its value. Reviewed-by: Anand Jain <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 1214836 commit 2943868

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

fs/btrfs/ioctl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,6 +2859,7 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
28592859
di_args->bytes_used = btrfs_device_get_bytes_used(dev);
28602860
di_args->total_bytes = btrfs_device_get_total_bytes(dev);
28612861
memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid));
2862+
memcpy(di_args->fsid, dev->fs_devices->fsid, BTRFS_UUID_SIZE);
28622863
if (dev->name)
28632864
strscpy(di_args->path, btrfs_dev_name(dev), sizeof(di_args->path));
28642865
else

include/uapi/linux/btrfs.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,17 @@ struct btrfs_ioctl_dev_info_args {
245245
__u8 uuid[BTRFS_UUID_SIZE]; /* in/out */
246246
__u64 bytes_used; /* out */
247247
__u64 total_bytes; /* out */
248-
__u64 unused[379]; /* pad to 4k */
248+
/*
249+
* Optional, out.
250+
*
251+
* Showing the fsid of the device, allowing user space to check if this
252+
* device is a seeding one.
253+
*
254+
* Introduced in v6.3, thus user space still needs to check if kernel
255+
* changed this value. Older kernel will not touch the values here.
256+
*/
257+
__u8 fsid[BTRFS_UUID_SIZE];
258+
__u64 unused[377]; /* pad to 4k */
249259
__u8 path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */
250260
};
251261

0 commit comments

Comments
 (0)