From 180bb60cde72cab20acac742c541a8081bf1c815 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Mon, 26 Oct 2020 22:50:14 -0400 Subject: [PATCH] fs: add support and workarounds for btrfs fs_info v2 Define a local copy of the header that has fields for the csum type and length, so we can build in places that haven't caught up to kernel 5.5 headers yet. The reason why the csum type and length are not unconditionally filled in eludes me. csum_length is necessarily non-zero, and the cost of the conditional is worse than the cost of the copy, so the whole flags dance is a WTF...but it's part of the kernel API now, so it's too late to NAK it. Signed-off-by: Zygo Blaxell --- include/crucible/btrfs.h | 23 +++++++++++++++++++++-- include/crucible/fs.h | 4 +++- lib/fs.cc | 17 +++++++++++++++-- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/include/crucible/btrfs.h b/include/crucible/btrfs.h index 2792679..568ead4 100644 --- a/include/crucible/btrfs.h +++ b/include/crucible/btrfs.h @@ -205,8 +205,27 @@ #endif #ifndef BTRFS_IOC_LOGICAL_INO_V2 -#define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, struct btrfs_ioctl_logical_ino_args) -#define BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET (1ULL << 0) + #define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, struct btrfs_ioctl_logical_ino_args) + #define BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET (1ULL << 0) #endif +#ifndef BTRFS_FS_INFO_FLAG_CSUM_INFO + /* Request information about checksum type and size */ + #define BTRFS_FS_INFO_FLAG_CSUM_INFO (1 << 0) +#endif + +struct btrfs_ioctl_fs_info_args_v2 { + __u64 max_id; /* out */ + __u64 num_devices; /* out */ + __u8 fsid[BTRFS_FSID_SIZE]; /* out */ + __u32 nodesize; /* out */ + __u32 sectorsize; /* out */ + __u32 clone_alignment; /* out */ + /* See BTRFS_FS_INFO_FLAG_* */ + __u16 csum_type; /* out */ + __u16 csum_size; /* out */ + __u64 flags; /* in/out */ + __u8 reserved[968]; /* pad to 1k */ +}; + #endif // CRUCIBLE_BTRFS_H diff --git a/include/crucible/fs.h b/include/crucible/fs.h index 05ee5e1..0e7e04d 100644 --- a/include/crucible/fs.h +++ b/include/crucible/fs.h @@ -258,10 +258,12 @@ namespace crucible { ostream &hexdump(ostream &os, const vector &v); - struct BtrfsIoctlFsInfoArgs : public btrfs_ioctl_fs_info_args { + struct BtrfsIoctlFsInfoArgs : public btrfs_ioctl_fs_info_args_v2 { BtrfsIoctlFsInfoArgs(); void do_ioctl(int fd); string uuid() const; + uint16_t csum_type() const; + uint16_t csum_size() const; }; ostream & operator<<(ostream &os, const BtrfsIoctlFsInfoArgs &a); diff --git a/lib/fs.cc b/lib/fs.cc index e7dd7e7..401d1db 100644 --- a/lib/fs.cc +++ b/lib/fs.cc @@ -1084,13 +1084,14 @@ namespace crucible { BtrfsIoctlFsInfoArgs::BtrfsIoctlFsInfoArgs() { - memset_zero(this); + memset_zero(this); + flags = BTRFS_FS_INFO_FLAG_CSUM_INFO; } void BtrfsIoctlFsInfoArgs::do_ioctl(int fd) { - btrfs_ioctl_fs_info_args *p = static_cast(this); + btrfs_ioctl_fs_info_args_v2 *p = static_cast(this); if (ioctl(fd, BTRFS_IOC_FS_INFO, p)) { THROW_ERRNO("BTRFS_IOC_FS_INFO: fd " << fd); } @@ -1102,4 +1103,16 @@ namespace crucible { return uuid_unparse(fsid); } + uint16_t + BtrfsIoctlFsInfoArgs::csum_type() const + { + return this->btrfs_ioctl_fs_info_args_v2::csum_type; + } + + uint16_t + BtrfsIoctlFsInfoArgs::csum_size() const + { + return this->btrfs_ioctl_fs_info_args_v2::csum_size; + } + };