Skip to content

Commit 0225e67

Browse files
authored
Merge pull request ceph#63179 from tchaikov/rgw-std-variant
rgw: migrate from boost::variant to std::variant Reviewed-by: Matt Benjamin <[email protected]> Reviewed-by: Alex Wojno <[email protected]>
2 parents 60bf547 + ad71a82 commit 0225e67

File tree

4 files changed

+69
-80
lines changed

4 files changed

+69
-80
lines changed

src/rgw/rgw_cksum_digest.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
#pragma once
1515

16-
#include <boost/variant.hpp>
17-
#include <boost/blank.hpp>
16+
#include <variant>
1817
#include "common/ceph_crypto.h"
1918
#include "rgw_blake3_digest.h"
2019
#include "rgw_crc_digest.h"
@@ -65,20 +64,20 @@ namespace rgw { namespace cksum {
6564
typedef TDigest<ceph::crypto::SHA512> SHA512;
6665
typedef TDigest<rgw::digest::Crc64Nvme> Crc64Nvme;
6766

68-
typedef boost::variant<boost::blank,
69-
Blake3,
70-
Crc32,
71-
Crc32c,
72-
XXH3,
73-
SHA1,
74-
SHA256,
75-
SHA512,
76-
Crc64Nvme> DigestVariant;
67+
typedef std::variant<std::monostate,
68+
Blake3,
69+
Crc32,
70+
Crc32c,
71+
XXH3,
72+
SHA1,
73+
SHA256,
74+
SHA512,
75+
Crc64Nvme> DigestVariant;
7776

78-
struct get_digest_ptr : public boost::static_visitor<Digest*>
77+
struct get_digest_ptr
7978
{
8079
get_digest_ptr() {};
81-
Digest* operator()(const boost::blank& b) const { return nullptr; }
80+
Digest* operator()(const std::monostate& b) const { return nullptr; }
8281
Digest* operator()(Blake3& digest) const { return &digest; }
8382
Digest* operator()(Crc32& digest) const { return &digest; }
8483
Digest* operator()(Crc32c& digest) const { return &digest; }
@@ -91,7 +90,7 @@ namespace rgw { namespace cksum {
9190

9291
static inline Digest* get_digest(DigestVariant& ev)
9392
{
94-
return boost::apply_visitor(get_digest_ptr{}, ev);
93+
return std::visit(get_digest_ptr{}, ev);
9594
}
9695

9796
static inline DigestVariant digest_factory(const Type cksum_type)
@@ -124,7 +123,7 @@ namespace rgw { namespace cksum {
124123
case Type::none:
125124
break;
126125
};
127-
return boost::blank();
126+
return std::monostate();
128127
} /* digest_factory */
129128

130129
static inline Cksum finalize_digest(Digest* digest, Type type)

src/rgw/rgw_file.cc

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ namespace rgw {
13481348
goto rele;
13491349
}
13501350
/* maybe clear state */
1351-
d = get<directory>(&rgw_fh->variant_type);
1351+
d = std::get_if<directory>(&rgw_fh->variant_type);
13521352
if (d) {
13531353
struct timespec ev_ts = ev.ts;
13541354
lock_guard guard(rgw_fh->mtx);
@@ -1543,8 +1543,7 @@ namespace rgw {
15431543
std::ostream& operator<<(std::ostream &os,
15441544
RGWFileHandle::readdir_offset const &offset)
15451545
{
1546-
using boost::get;
1547-
if (unlikely(!! get<uint64_t*>(&offset))) {
1546+
if (unlikely(!!std::get_if<uint64_t*>(&offset))) {
15481547
uint64_t* ioff = get<uint64_t*>(offset);
15491548
os << *ioff;
15501549
}
@@ -1568,7 +1567,7 @@ namespace rgw {
15681567
<< object_name()
15691568
<< dendl;
15701569

1571-
directory* d = get<directory>(&variant_type);
1570+
directory* d = std::get_if<directory>(&variant_type);
15721571
if (d) {
15731572
(void) clock_gettime(CLOCK_MONOTONIC_COARSE, &now); /* !LOCKED */
15741573
lock_guard guard(mtx);
@@ -1578,7 +1577,7 @@ namespace rgw {
15781577
bool initial_off;
15791578
char* mk{nullptr};
15801579

1581-
if (likely(!! get<const char*>(&offset))) {
1580+
if (likely(!!std::get_if<const char*>(&offset))) {
15821581
mk = const_cast<char*>(get<const char*>(offset));
15831582
initial_off = !mk;
15841583
} else {
@@ -1635,7 +1634,7 @@ namespace rgw {
16351634

16361635
int rc = 0;
16371636

1638-
file* f = get<file>(&variant_type);
1637+
file* f = std::get_if<file>(&variant_type);
16391638
if (! f)
16401639
return -EISDIR;
16411640

@@ -1754,7 +1753,7 @@ namespace rgw {
17541753
guard.lock();
17551754
}
17561755

1757-
file* f = get<file>(&variant_type);
1756+
file* f = std::get_if<file>(&variant_type);
17581757
if (f && (f->write_req)) {
17591758
lsubdout(fs->get_context(), rgw, 10)
17601759
<< __func__
@@ -1790,7 +1789,7 @@ namespace rgw {
17901789

17911790
void RGWFileHandle::clear_state()
17921791
{
1793-
directory* d = get<directory>(&variant_type);
1792+
directory* d = std::get_if<directory>(&variant_type);
17941793
if (d) {
17951794
state.nlink = 2;
17961795
d->last_marker = rgw_obj_key{};
@@ -1825,6 +1824,33 @@ namespace rgw {
18251824
}
18261825
}
18271826

1827+
bool RGWListBucketsRequest::eof() {
1828+
if (unlikely(cct->_conf->subsys.should_gather(ceph_subsys_rgw, 15))) {
1829+
bool is_offset =
1830+
unlikely(!std::get_if<const char*>(&offset)) ||
1831+
!! get<const char*>(offset);
1832+
lsubdout(cct, rgw, 15) << "READDIR offset: " <<
1833+
((is_offset) ? offset : "(nil)")
1834+
<< " is_truncated: " << is_truncated
1835+
<< dendl;
1836+
}
1837+
return !is_truncated && !rcb_eof;
1838+
}
1839+
1840+
bool RGWReaddirRequest::eof() {
1841+
if (unlikely(cct->_conf->subsys.should_gather(ceph_subsys_rgw, 15))) {
1842+
bool is_offset =
1843+
unlikely(!std::get_if<const char*>(&offset)) ||
1844+
!! get<const char*>(offset);
1845+
lsubdout(cct, rgw, 15) << "READDIR offset: " <<
1846+
((is_offset) ? offset : "(nil)")
1847+
<< " next marker: " << next_marker
1848+
<< " is_truncated: " << is_truncated
1849+
<< dendl;
1850+
}
1851+
return !is_truncated && !rcb_eof;
1852+
}
1853+
18281854
int RGWWriteRequest::exec_start() {
18291855
req_state* state = get_state();
18301856

src/rgw/rgw_file_int.h

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <boost/intrusive_ptr.hpp>
2323
#include <boost/range/adaptor/reversed.hpp>
2424
#include <boost/container/flat_map.hpp>
25-
#include <boost/variant.hpp>
2625
#include <boost/optional.hpp>
2726
#include "xxhash.h"
2827
#include "include/buffer.h"
@@ -180,7 +179,6 @@ namespace rgw {
180179
return (lhs < rhs) || (lhs == rhs);
181180
}
182181

183-
using boost::variant;
184182
using boost::container::flat_map;
185183

186184
typedef std::tuple<bool, bool> DecodeAttrsResult;
@@ -243,7 +241,7 @@ namespace rgw {
243241
void clear_state();
244242
void advance_mtime(uint32_t flags = FLAG_NONE);
245243

246-
boost::variant<file, directory> variant_type;
244+
std::variant<file, directory> variant_type;
247245

248246
uint16_t depth;
249247
uint32_t flags;
@@ -434,7 +432,7 @@ namespace rgw {
434432
}
435433

436434
directory* get_directory() {
437-
return boost::get<directory>(&variant_type);
435+
return std::get_if<directory>(&variant_type);
438436
}
439437

440438
size_t get_size() const { return state.size; }
@@ -615,8 +613,7 @@ namespace rgw {
615613

616614
void add_marker(uint64_t off, const rgw_obj_key& marker,
617615
uint8_t obj_type) {
618-
using std::get;
619-
directory* d = get<directory>(&variant_type);
616+
directory* d = std::get_if<directory>(&variant_type);
620617
if (d) {
621618
unique_lock guard(mtx);
622619
d->last_marker = marker;
@@ -626,8 +623,8 @@ namespace rgw {
626623
const rgw_obj_key* find_marker(uint64_t off) const {
627624
using std::get;
628625
if (off > 0) {
629-
const directory* d = get<directory>(&variant_type);
630-
if (d ) {
626+
const directory* d = std::get_if<directory>(&variant_type);
627+
if (d) {
631628
return &d->last_marker;
632629
}
633630
}
@@ -667,7 +664,7 @@ namespace rgw {
667664
return -EPERM;
668665
}
669666

670-
typedef boost::variant<uint64_t*, const char*> readdir_offset;
667+
typedef std::variant<uint64_t*, const char*> readdir_offset;
671668

672669
int readdir(rgw_readdir_cb rcb, void *cb_arg, readdir_offset offset,
673670
bool *eof, uint32_t flags);
@@ -1357,9 +1354,7 @@ class RGWListBucketsRequest : public RGWLibRequest,
13571354
cb_arg(_cb_arg), rcb(_rcb), ioff(nullptr), ix(0), d_count(0),
13581355
rcb_eof(false) {
13591356

1360-
using boost::get;
1361-
1362-
if (unlikely(!! get<uint64_t*>(&offset))) {
1357+
if (unlikely(!! std::get_if<uint64_t*>(&offset))) {
13631358
ioff = get<uint64_t*>(offset);
13641359
const auto& mk = rgw_fh->find_marker(*ioff);
13651360
if (mk) {
@@ -1442,21 +1437,7 @@ class RGWListBucketsRequest : public RGWLibRequest,
14421437
return rcb(name.data(), cb_arg, off, nullptr, 0, RGW_LOOKUP_FLAG_DIR);
14431438
}
14441439

1445-
bool eof() {
1446-
using boost::get;
1447-
1448-
if (unlikely(cct->_conf->subsys.should_gather(ceph_subsys_rgw, 15))) {
1449-
bool is_offset =
1450-
unlikely(! get<const char*>(&offset)) ||
1451-
!! get<const char*>(offset);
1452-
lsubdout(cct, rgw, 15) << "READDIR offset: " <<
1453-
((is_offset) ? offset : "(nil)")
1454-
<< " is_truncated: " << is_truncated
1455-
<< dendl;
1456-
}
1457-
return !is_truncated && !rcb_eof;
1458-
}
1459-
1440+
inline bool eof();
14601441
}; /* RGWListBucketsRequest */
14611442

14621443
/*
@@ -1483,9 +1464,7 @@ class RGWReaddirRequest : public RGWLibRequest,
14831464
cb_arg(_cb_arg), rcb(_rcb), ioff(nullptr), ix(0), d_count(0),
14841465
rcb_eof(false) {
14851466

1486-
using boost::get;
1487-
1488-
if (unlikely(!! get<uint64_t*>(&offset))) {
1467+
if (unlikely(!! std::get_if<uint64_t*>(&offset))) {
14891468
ioff = get<uint64_t*>(offset);
14901469
const auto& mk = rgw_fh->find_marker(*ioff);
14911470
if (mk) {
@@ -1769,22 +1748,7 @@ class RGWReaddirRequest : public RGWLibRequest,
17691748
send_response();
17701749
}
17711750

1772-
bool eof() {
1773-
using boost::get;
1774-
1775-
if (unlikely(cct->_conf->subsys.should_gather(ceph_subsys_rgw, 15))) {
1776-
bool is_offset =
1777-
unlikely(! get<const char*>(&offset)) ||
1778-
!! get<const char*>(offset);
1779-
lsubdout(cct, rgw, 15) << "READDIR offset: " <<
1780-
((is_offset) ? offset : "(nil)")
1781-
<< " next marker: " << next_marker
1782-
<< " is_truncated: " << is_truncated
1783-
<< dendl;
1784-
}
1785-
return !is_truncated && !rcb_eof;
1786-
}
1787-
1751+
inline bool eof();
17881752
}; /* RGWReaddirRequest */
17891753

17901754
/*

src/rgw/rgw_lc.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -732,19 +732,19 @@ class LCOpRule {
732732
}; /* LCOpRule */
733733

734734
using WorkItem =
735-
boost::variant<void*,
736-
/* out-of-line delete */
737-
std::tuple<LCOpRule, rgw_bucket_dir_entry>,
738-
/* uncompleted MPU expiration */
739-
std::tuple<lc_op, rgw_bucket_dir_entry>,
740-
rgw_bucket_dir_entry>;
735+
std::variant<void*,
736+
/* out-of-line delete */
737+
std::tuple<LCOpRule, rgw_bucket_dir_entry>,
738+
/* uncompleted MPU expiration */
739+
std::tuple<lc_op, rgw_bucket_dir_entry>,
740+
rgw_bucket_dir_entry>;
741741

742742
class WorkQ : public Thread
743743
{
744744
public:
745745
using unique_lock = std::unique_lock<std::mutex>;
746746
using work_f = std::function<void(RGWLC::LCWorker*, WorkQ*, WorkItem&)>;
747-
using dequeue_result = boost::variant<void*, WorkItem>;
747+
using dequeue_result = std::variant<void*, WorkItem>;
748748

749749
static constexpr uint32_t FLAG_NONE = 0x0000;
750750
static constexpr uint32_t FLAG_EWAIT_SYNC = 0x0001;
@@ -827,11 +827,11 @@ class WorkQ : public Thread
827827
void* entry() override {
828828
while (!wk->get_lc()->going_down()) {
829829
auto item = dequeue();
830-
if (item.which() == 0) {
830+
if (item.index() == 0) {
831831
/* going down */
832832
break;
833833
}
834-
f(wk, this, boost::get<WorkItem>(item));
834+
f(wk, this, std::get<WorkItem>(item));
835835
}
836836
return nullptr;
837837
}
@@ -909,7 +909,7 @@ int RGWLC::handle_multipart_expiration(rgw::sal::Bucket* target,
909909

910910
auto pf = [&](RGWLC::LCWorker *wk, WorkQ *wq, WorkItem &wi) {
911911
int ret{0};
912-
auto wt = boost::get<std::tuple<lc_op, rgw_bucket_dir_entry>>(wi);
912+
auto wt = std::get<std::tuple<lc_op, rgw_bucket_dir_entry>>(wi);
913913
auto& [rule, obj] = wt;
914914

915915
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,
17821782

17831783
auto pf = [&bucket_name](RGWLC::LCWorker* wk, WorkQ* wq, WorkItem& wi) {
17841784
auto wt =
1785-
boost::get<std::tuple<LCOpRule, rgw_bucket_dir_entry>>(wi);
1785+
std::get<std::tuple<LCOpRule, rgw_bucket_dir_entry>>(wi);
17861786
auto& [op_rule, o] = wt;
17871787

17881788
ldpp_dout(wk->get_lc(), 20)

0 commit comments

Comments
 (0)