From: Kefu Chai Date: Mon, 12 May 2025 02:36:29 +0000 (+0800) Subject: cephfs, tools/cephfs_mirror: migrate from boost::variant to std::variant X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ad71a82014cbc7eb84d00bbea232f8d324cda9b2;p=ceph.git cephfs, tools/cephfs_mirror: migrate from boost::variant to std::variant Replacing boost::variant with std::variant throughout the cephfs related codebase. This change is part of our ongoing effort to reduce third-party dependencies by leveraging C++ standard library alternatives where possible. Signed-off-by: Kefu Chai --- diff --git a/src/rgw/rgw_cksum_digest.h b/src/rgw/rgw_cksum_digest.h index 33f9a629519..51bb5408ec2 100644 --- a/src/rgw/rgw_cksum_digest.h +++ b/src/rgw/rgw_cksum_digest.h @@ -13,8 +13,7 @@ #pragma once -#include -#include +#include #include "common/ceph_crypto.h" #include "rgw_blake3_digest.h" #include "rgw_crc_digest.h" @@ -65,20 +64,20 @@ namespace rgw { namespace cksum { typedef TDigest SHA512; typedef TDigest Crc64Nvme; - typedef boost::variant DigestVariant; + typedef std::variant DigestVariant; - struct get_digest_ptr : public boost::static_visitor + struct get_digest_ptr { get_digest_ptr() {}; - Digest* operator()(const boost::blank& b) const { return nullptr; } + Digest* operator()(const std::monostate& b) const { return nullptr; } Digest* operator()(Blake3& digest) const { return &digest; } Digest* operator()(Crc32& digest) const { return &digest; } Digest* operator()(Crc32c& digest) const { return &digest; } @@ -91,7 +90,7 @@ namespace rgw { namespace cksum { static inline Digest* get_digest(DigestVariant& ev) { - return boost::apply_visitor(get_digest_ptr{}, ev); + return std::visit(get_digest_ptr{}, ev); } static inline DigestVariant digest_factory(const Type cksum_type) @@ -124,7 +123,7 @@ namespace rgw { namespace cksum { case Type::none: break; }; - return boost::blank(); + return std::monostate(); } /* digest_factory */ static inline Cksum finalize_digest(Digest* digest, Type type) diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 85c54f8c04c..f40040cdba2 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -1348,7 +1348,7 @@ namespace rgw { goto rele; } /* maybe clear state */ - d = get(&rgw_fh->variant_type); + d = std::get_if(&rgw_fh->variant_type); if (d) { struct timespec ev_ts = ev.ts; lock_guard guard(rgw_fh->mtx); @@ -1543,8 +1543,7 @@ namespace rgw { std::ostream& operator<<(std::ostream &os, RGWFileHandle::readdir_offset const &offset) { - using boost::get; - if (unlikely(!! get(&offset))) { + if (unlikely(!!std::get_if(&offset))) { uint64_t* ioff = get(offset); os << *ioff; } @@ -1568,7 +1567,7 @@ namespace rgw { << object_name() << dendl; - directory* d = get(&variant_type); + directory* d = std::get_if(&variant_type); if (d) { (void) clock_gettime(CLOCK_MONOTONIC_COARSE, &now); /* !LOCKED */ lock_guard guard(mtx); @@ -1578,7 +1577,7 @@ namespace rgw { bool initial_off; char* mk{nullptr}; - if (likely(!! get(&offset))) { + if (likely(!!std::get_if(&offset))) { mk = const_cast(get(offset)); initial_off = !mk; } else { @@ -1635,7 +1634,7 @@ namespace rgw { int rc = 0; - file* f = get(&variant_type); + file* f = std::get_if(&variant_type); if (! f) return -EISDIR; @@ -1754,7 +1753,7 @@ namespace rgw { guard.lock(); } - file* f = get(&variant_type); + file* f = std::get_if(&variant_type); if (f && (f->write_req)) { lsubdout(fs->get_context(), rgw, 10) << __func__ @@ -1790,7 +1789,7 @@ namespace rgw { void RGWFileHandle::clear_state() { - directory* d = get(&variant_type); + directory* d = std::get_if(&variant_type); if (d) { state.nlink = 2; d->last_marker = rgw_obj_key{}; @@ -1826,11 +1825,9 @@ namespace rgw { } bool RGWListBucketsRequest::eof() { - using boost::get; - if (unlikely(cct->_conf->subsys.should_gather(ceph_subsys_rgw, 15))) { bool is_offset = - unlikely(! get(&offset)) || + unlikely(!std::get_if(&offset)) || !! get(offset); lsubdout(cct, rgw, 15) << "READDIR offset: " << ((is_offset) ? offset : "(nil)") @@ -1841,11 +1838,9 @@ namespace rgw { } bool RGWReaddirRequest::eof() { - using boost::get; - if (unlikely(cct->_conf->subsys.should_gather(ceph_subsys_rgw, 15))) { bool is_offset = - unlikely(! get(&offset)) || + unlikely(!std::get_if(&offset)) || !! get(offset); lsubdout(cct, rgw, 15) << "READDIR offset: " << ((is_offset) ? offset : "(nil)") diff --git a/src/rgw/rgw_file_int.h b/src/rgw/rgw_file_int.h index d9c350e6ca9..cd86a4aa474 100644 --- a/src/rgw/rgw_file_int.h +++ b/src/rgw/rgw_file_int.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include "xxhash.h" #include "include/buffer.h" @@ -180,7 +179,6 @@ namespace rgw { return (lhs < rhs) || (lhs == rhs); } - using boost::variant; using boost::container::flat_map; typedef std::tuple DecodeAttrsResult; @@ -243,7 +241,7 @@ namespace rgw { void clear_state(); void advance_mtime(uint32_t flags = FLAG_NONE); - boost::variant variant_type; + std::variant variant_type; uint16_t depth; uint32_t flags; @@ -434,7 +432,7 @@ namespace rgw { } directory* get_directory() { - return boost::get(&variant_type); + return std::get_if(&variant_type); } size_t get_size() const { return state.size; } @@ -615,8 +613,7 @@ namespace rgw { void add_marker(uint64_t off, const rgw_obj_key& marker, uint8_t obj_type) { - using std::get; - directory* d = get(&variant_type); + directory* d = std::get_if(&variant_type); if (d) { unique_lock guard(mtx); d->last_marker = marker; @@ -626,8 +623,8 @@ namespace rgw { const rgw_obj_key* find_marker(uint64_t off) const { using std::get; if (off > 0) { - const directory* d = get(&variant_type); - if (d ) { + const directory* d = std::get_if(&variant_type); + if (d) { return &d->last_marker; } } @@ -667,7 +664,7 @@ namespace rgw { return -EPERM; } - typedef boost::variant readdir_offset; + typedef std::variant readdir_offset; int readdir(rgw_readdir_cb rcb, void *cb_arg, readdir_offset offset, bool *eof, uint32_t flags); @@ -1357,9 +1354,7 @@ public: cb_arg(_cb_arg), rcb(_rcb), ioff(nullptr), ix(0), d_count(0), rcb_eof(false) { - using boost::get; - - if (unlikely(!! get(&offset))) { + if (unlikely(!! std::get_if(&offset))) { ioff = get(offset); const auto& mk = rgw_fh->find_marker(*ioff); if (mk) { @@ -1469,9 +1464,7 @@ public: cb_arg(_cb_arg), rcb(_rcb), ioff(nullptr), ix(0), d_count(0), rcb_eof(false) { - using boost::get; - - if (unlikely(!! get(&offset))) { + if (unlikely(!! std::get_if(&offset))) { ioff = get(offset); const auto& mk = rgw_fh->find_marker(*ioff); if (mk) { diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index a18fbc0e5f0..006b8225ba8 100644 --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@ -732,19 +732,19 @@ public: }; /* LCOpRule */ using WorkItem = - boost::variant, - /* uncompleted MPU expiration */ - std::tuple, - rgw_bucket_dir_entry>; + std::variant, + /* uncompleted MPU expiration */ + std::tuple, + rgw_bucket_dir_entry>; class WorkQ : public Thread { public: using unique_lock = std::unique_lock; using work_f = std::function; - using dequeue_result = boost::variant; + using dequeue_result = std::variant; static constexpr uint32_t FLAG_NONE = 0x0000; static constexpr uint32_t FLAG_EWAIT_SYNC = 0x0001; @@ -827,11 +827,11 @@ private: void* entry() override { while (!wk->get_lc()->going_down()) { auto item = dequeue(); - if (item.which() == 0) { + if (item.index() == 0) { /* going down */ break; } - f(wk, this, boost::get(item)); + f(wk, this, std::get(item)); } return nullptr; } @@ -909,7 +909,7 @@ int RGWLC::handle_multipart_expiration(rgw::sal::Bucket* target, auto pf = [&](RGWLC::LCWorker *wk, WorkQ *wq, WorkItem &wi) { int ret{0}; - auto wt = boost::get>(wi); + auto wt = std::get>(wi); auto& [rule, obj] = wt; if (obj_has_expired(this, cct, obj.meta.mtime, rule.mp_expiration)) { @@ -1782,7 +1782,7 @@ int RGWLC::bucket_lc_process(string& shard_id, LCWorker* worker, auto pf = [&bucket_name](RGWLC::LCWorker* wk, WorkQ* wq, WorkItem& wi) { auto wt = - boost::get>(wi); + std::get>(wi); auto& [op_rule, o] = wt; ldpp_dout(wk->get_lc(), 20)