History

btrfs: pass checksum type via BTRFS_IOC_FS_INFO ioctl

With the recent addition of filesystem checksum types other than CRC32c, it is not anymore hard-coded which checksum type a btrfs filesystem uses. Up to now there is no good way to read the filesystem checksum, apart from reading the filesystem UUID and then query sysfs for the checksum type. Add a new csum_type and csum_size fields to the BTRFS_IOC_FS_INFO ioctl command which usually is used to query filesystem features. Also add a flags member indicating that the kernel responded with a set csum_type and csum_size field. For compatibility reasons, only return the csum_type and csum_size if the BTRFS_FS_INFO_FLAG_CSUM_INFO flag was passed to the kernel. Also clear any unknown flags so we don't pass false positives to user-space newer than the kernel. To simplify further additions to the ioctl, also switch the padding to a u8 array. Pahole was used to verify the result of this switch: The csum members are added before flags, which might look odd, but this is to keep the alignment requirements and not to introduce holes in the structure. $ pahole -C btrfs_ioctl_fs_info_args fs/btrfs/btrfs.ko struct btrfs_ioctl_fs_info_args { __u64 max_id; /* 0 8 */ __u64 num_devices; /* 8 8 */ __u8 fsid[16]; /* 16 16 */ __u32 nodesize; /* 32 4 */ __u32 sectorsize; /* 36 4 */ __u32 clone_alignment; /* 40 4 */ __u16 csum_type; /* 44 2 */ __u16 csum_size; /* 46 2 */ __u64 flags; /* 48 8 */ __u8 reserved[968]; /* 56 968 */ /* size: 1024, cachelines: 16, members: 10 */ };

Johannes Thumshirn committed 6 years ago

Commit 137c5411 parent adca4d92 files · +25 −5Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/btrfs.h+12−2
@@ -243,6 +243,13 @@ struct btrfs_ioctl_dev_info_args { · 242 unmodified lines
243243 __u8 path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */
244244 };
245245
246+/*
247+ * Retrieve information about the filesystem
248+ */
249+
250+/* Request information about checksum type and size */
251+#define BTRFS_FS_INFO_FLAG_CSUM_INFO (1 << 0)
252+
246253 struct btrfs_ioctl_fs_info_args {
247254 __u64 max_id; /* out */
248255 __u64 num_devices; /* out */
@@ -250,8 +257,11 @@ struct btrfs_ioctl_fs_info_args { · 1 unmodified line
250257 __u32 nodesize; /* out */
251258 __u32 sectorsize; /* out */
252259 __u32 clone_alignment; /* out */
253− __u32 reserved32;
254− __u64 reserved[122]; /* pad to 1k */
260+ /* See BTRFS_FS_INFO_FLAG_* */
261+ __u16 csum_type; /* out */
262+ __u16 csum_size; /* out */
263+ __u64 flags; /* in/out */
264+ __u8 reserved[968]; /* pad to 1k */
255265 };
256266
257267 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t