]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs, tools/cephfs_mirror: migrate from boost::variant to std::variant 63179/head
authorKefu Chai <tchaikov@gmail.com>
Mon, 12 May 2025 02:36:29 +0000 (10:36 +0800)
committerKefu Chai <tchaikov@gmail.com>
Fri, 13 Jun 2025 22:14:10 +0000 (06:14 +0800)
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 <tchaikov@gmail.com>
src/rgw/rgw_cksum_digest.h
src/rgw/rgw_file.cc
src/rgw/rgw_file_int.h
src/rgw/rgw_lc.cc

index 33f9a629519ad491593c9861d6cd91c4c890a452..51bb5408ec24aa4e9448d7b824ff2dc105af5b9b 100644 (file)
@@ -13,8 +13,7 @@
 
 #pragma once
 
-#include <boost/variant.hpp>
-#include <boost/blank.hpp>
+#include <variant>
 #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<ceph::crypto::SHA512> SHA512;
   typedef TDigest<rgw::digest::Crc64Nvme> Crc64Nvme;
 
-  typedef boost::variant<boost::blank,
-                        Blake3,
-                        Crc32,
-                        Crc32c,
-                        XXH3,
-                        SHA1,
-                        SHA256,
-                        SHA512,
-                        Crc64Nvme> DigestVariant;
+  typedef std::variant<std::monostate,
+                      Blake3,
+                      Crc32,
+                      Crc32c,
+                      XXH3,
+                      SHA1,
+                      SHA256,
+                      SHA512,
+                      Crc64Nvme> DigestVariant;
 
-  struct get_digest_ptr : public boost::static_visitor<Digest*>
+  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)
index 85c54f8c04ccd01841a494914404856b4e1b135f..f40040cdba2ec00718e8cedc35f16e71314b2b54 100644 (file)
@@ -1348,7 +1348,7 @@ namespace rgw {
              goto rele;
            }
            /* maybe clear state */
-           d = get<directory>(&rgw_fh->variant_type);
+           d = std::get_if<directory>(&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<uint64_t*>(&offset))) {
+    if (unlikely(!!std::get_if<uint64_t*>(&offset))) {
       uint64_t* ioff = get<uint64_t*>(offset);
       os << *ioff;
     }
@@ -1568,7 +1567,7 @@ namespace rgw {
       << object_name()
       << dendl;
 
-    directory* d = get<directory>(&variant_type);
+    directory* d = std::get_if<directory>(&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<const char*>(&offset))) {
+    if (likely(!!std::get_if<const char*>(&offset))) {
       mk = const_cast<char*>(get<const char*>(offset));
       initial_off = !mk;
     } else {
@@ -1635,7 +1634,7 @@ namespace rgw {
 
     int rc = 0;
 
-    file* f = get<file>(&variant_type);
+    file* f = std::get_if<file>(&variant_type);
     if (! f)
       return -EISDIR;
 
@@ -1754,7 +1753,7 @@ namespace rgw {
       guard.lock();
     }
 
-    file* f = get<file>(&variant_type);
+    file* f = std::get_if<file>(&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<directory>(&variant_type);
+    directory* d = std::get_if<directory>(&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<const char*>(&offset)) ||
+       unlikely(!std::get_if<const char*>(&offset)) ||
        !! get<const char*>(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<const char*>(&offset)) ||
+       unlikely(!std::get_if<const char*>(&offset)) ||
        !! get<const char*>(offset);
       lsubdout(cct, rgw, 15) << "READDIR offset: " <<
        ((is_offset) ? offset : "(nil)")
index d9c350e6ca93bad5b40c19b6f8cc0338ed79391e..cd86a4aa474563427e39d0cdd84d9006dee79f6d 100644 (file)
@@ -22,7 +22,6 @@
 #include <boost/intrusive_ptr.hpp>
 #include <boost/range/adaptor/reversed.hpp>
 #include <boost/container/flat_map.hpp>
-#include <boost/variant.hpp>
 #include <boost/optional.hpp>
 #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<bool, bool> DecodeAttrsResult;
@@ -243,7 +241,7 @@ namespace rgw {
     void clear_state();
     void advance_mtime(uint32_t flags = FLAG_NONE);
 
-    boost::variant<file, directory> variant_type;
+    std::variant<file, directory> variant_type;
 
     uint16_t depth;
     uint32_t flags;
@@ -434,7 +432,7 @@ namespace rgw {
     }
 
     directory* get_directory() {
-      return boost::get<directory>(&variant_type);
+      return std::get_if<directory>(&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<directory>(&variant_type);
+      directory* d = std::get_if<directory>(&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<directory>(&variant_type);
-       if (d ) {
+       const directory* d = std::get_if<directory>(&variant_type);
+       if (d) {
          return &d->last_marker;
        }
       }
@@ -667,7 +664,7 @@ namespace rgw {
       return -EPERM;
     }
 
-    typedef boost::variant<uint64_t*, const char*> readdir_offset;
+    typedef std::variant<uint64_t*, const char*> 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<uint64_t*>(&offset))) {
+    if (unlikely(!! std::get_if<uint64_t*>(&offset))) {
       ioff = get<uint64_t*>(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<uint64_t*>(&offset))) {
+    if (unlikely(!! std::get_if<uint64_t*>(&offset))) {
       ioff = get<uint64_t*>(offset);
       const auto& mk = rgw_fh->find_marker(*ioff);
       if (mk) {
index a18fbc0e5f0c6eaa9218e79b528b03f1918a3704..006b8225ba8dfd677760027059965a00ca8337e2 100644 (file)
@@ -732,19 +732,19 @@ public:
 }; /* LCOpRule */
 
 using WorkItem =
-  boost::variant<void*,
-                /* out-of-line delete */
-                std::tuple<LCOpRule, rgw_bucket_dir_entry>,
-                /* uncompleted MPU expiration */
-                std::tuple<lc_op, rgw_bucket_dir_entry>,
-                rgw_bucket_dir_entry>;
+  std::variant<void*,
+              /* out-of-line delete */
+              std::tuple<LCOpRule, rgw_bucket_dir_entry>,
+              /* uncompleted MPU expiration */
+              std::tuple<lc_op, rgw_bucket_dir_entry>,
+              rgw_bucket_dir_entry>;
 
 class WorkQ : public Thread
 {
 public:
   using unique_lock = std::unique_lock<std::mutex>;
   using work_f = std::function<void(RGWLC::LCWorker*, WorkQ*, WorkItem&)>;
-  using dequeue_result = boost::variant<void*, WorkItem>;
+  using dequeue_result = std::variant<void*, WorkItem>;
 
   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<WorkItem>(item));
+      f(wk, this, std::get<WorkItem>(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<std::tuple<lc_op, rgw_bucket_dir_entry>>(wi);
+    auto wt = std::get<std::tuple<lc_op, rgw_bucket_dir_entry>>(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<std::tuple<LCOpRule, rgw_bucket_dir_entry>>(wi);
+      std::get<std::tuple<LCOpRule, rgw_bucket_dir_entry>>(wi);
     auto& [op_rule, o] = wt;
 
     ldpp_dout(wk->get_lc(), 20)