From bd336e81a6b51e54c57f1f59d917234eb94455ad Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sun, 23 Oct 2022 14:01:38 -0400 Subject: [PATCH] fs: get rid of base class btrfs_ioctl_logical_ino_args Another instance of the pattern where we derived a crucible class from a btrfs struct. Make it an automatic variable instead. Signed-off-by: Zygo Blaxell --- include/crucible/fs.h | 9 ++++++--- lib/fs.cc | 38 +++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/include/crucible/fs.h b/include/crucible/fs.h index 695f4a3..df7b936 100644 --- a/include/crucible/fs.h +++ b/include/crucible/fs.h @@ -64,7 +64,7 @@ namespace crucible { ByteVector m_data; }; - struct BtrfsIoctlLogicalInoArgs : public btrfs_ioctl_logical_ino_args { + struct BtrfsIoctlLogicalInoArgs { BtrfsIoctlLogicalInoArgs(uint64_t logical, size_t buf_size = 16 * 1024 * 1024); uint64_t get_flags() const; @@ -73,7 +73,6 @@ namespace crucible { virtual void do_ioctl(int fd); virtual bool do_ioctl_nothrow(int fd); - size_t m_container_size; struct BtrfsInodeOffsetRootSpan { using iterator = BtrfsInodeOffsetRoot*; using const_iterator = const BtrfsInodeOffsetRoot*; @@ -84,13 +83,17 @@ namespace crucible { const_iterator cend() const; iterator data() const; void clear(); - operator vector() const; private: iterator m_begin = nullptr; iterator m_end = nullptr; friend struct BtrfsIoctlLogicalInoArgs; } m_iors; + private: + size_t m_container_size; BtrfsDataContainer m_container; + uint64_t m_logical; + uint64_t m_flags = 0; + friend ostream & operator<<(ostream &os, const BtrfsIoctlLogicalInoArgs *p); }; ostream & operator<<(ostream &os, const BtrfsIoctlLogicalInoArgs &p); diff --git a/lib/fs.cc b/lib/fs.cc index 90a0bab..002c7a7 100644 --- a/lib/fs.cc +++ b/lib/fs.cc @@ -243,7 +243,7 @@ namespace crucible { return os << "BtrfsIoctlLogicalInoArgs NULL"; } os << "BtrfsIoctlLogicalInoArgs {"; - os << " .logical = " << to_hex(p->logical); + os << " .m_logical = " << to_hex(p->m_logical); os << " .inodes[] = {\n"; unsigned count = 0; for (auto i = p->m_iors.cbegin(); i != p->m_iors.cend(); ++i) { @@ -254,14 +254,10 @@ namespace crucible { } BtrfsIoctlLogicalInoArgs::BtrfsIoctlLogicalInoArgs(uint64_t new_logical, size_t new_size) : - btrfs_ioctl_logical_ino_args( (btrfs_ioctl_logical_ino_args) { } ), m_container_size(new_size), - m_container(new_size) + m_container(new_size), + m_logical(new_logical) { - assert(logical == 0); - assert(size == 0); - assert(flags == 0); - logical = new_logical; } size_t @@ -300,11 +296,6 @@ namespace crucible { return m_begin; } - BtrfsIoctlLogicalInoArgs::BtrfsInodeOffsetRootSpan::operator vector() const - { - return vector(m_begin, m_end); - } - void BtrfsIoctlLogicalInoArgs::BtrfsInodeOffsetRootSpan::clear() { @@ -314,23 +305,28 @@ namespace crucible { void BtrfsIoctlLogicalInoArgs::set_flags(uint64_t new_flags) { - // We are still supporting building with old headers that don't have .flags yet - *(&reserved[0] + 3) = new_flags; + m_flags = new_flags; } uint64_t BtrfsIoctlLogicalInoArgs::get_flags() const { // We are still supporting building with old headers that don't have .flags yet - return *(&reserved[0] + 3); + return m_flags; } bool BtrfsIoctlLogicalInoArgs::do_ioctl_nothrow(int fd) { - btrfs_ioctl_logical_ino_args *const p = static_cast(this); - inodes = reinterpret_cast(m_container.prepare(m_container_size)); - size = m_container.get_size(); + btrfs_ioctl_logical_ino_args args = (btrfs_ioctl_logical_ino_args) { + .logical = m_logical, + .size = m_container_size, + .inodes = reinterpret_cast(m_container.prepare(m_container_size)), + }; + // We are still supporting building with old headers that don't have .flags yet + *(&args.reserved[0] + 3) = m_flags; + + btrfs_ioctl_logical_ino_args *const p = &args; m_iors.clear(); @@ -368,12 +364,12 @@ namespace crucible { } btrfs_data_container *const bdc = reinterpret_cast(p->inodes); - BtrfsInodeOffsetRoot *const input_iter = reinterpret_cast(bdc->val); + BtrfsInodeOffsetRoot *const ior_iter = reinterpret_cast(bdc->val); // elem_cnt counts uint64_t, but BtrfsInodeOffsetRoot is 3x uint64_t THROW_CHECK1(runtime_error, bdc->elem_cnt, bdc->elem_cnt % 3 == 0); - m_iors.m_begin = input_iter; - m_iors.m_end = input_iter + bdc->elem_cnt / 3; + m_iors.m_begin = ior_iter; + m_iors.m_end = ior_iter + bdc->elem_cnt / 3; return true; }