Merge pull request #45419 from tchaikov/wip-cxx20-fixes-core

osd, common: C++20 related fixes

Reviewed-by: Casey Bodley <cbodley@redhat.com>
Reviewed-by: Adam C. Emerson <aemerson@redhat.com>
This commit is contained in:
Kefu Chai 2022-03-18 11:18:34 +08:00 committed by GitHub
commit e2c1101b69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 117 additions and 98 deletions

View File

@ -145,10 +145,10 @@ struct journal_entry {
}
void dump(ceph::Formatter* f) const;
bool operator ==(const journal_entry& e) {
return (op == e.op &&
part_num == e.part_num &&
part_tag == e.part_tag);
friend bool operator ==(const journal_entry& lhs, const journal_entry& rhs) {
return (lhs.op == rhs.op &&
lhs.part_num == rhs.part_num &&
lhs.part_tag == rhs.part_tag);
}
};
WRITE_CLASS_ENCODER(journal_entry)

View File

@ -26,7 +26,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim_all.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/phoenix.hpp>
#include <boost/spirit/include/support_line_pos_iterator.hpp>
#include "include/buffer.h"

View File

@ -161,7 +161,7 @@ OpTracker::OpTracker(CephContext *cct_, bool tracking, uint32_t num_shards):
tracking_enabled(tracking),
cct(cct_) {
for (uint32_t i = 0; i < num_optracker_shards; i++) {
char lock_name[32] = {0};
char lock_name[34] = {0};
snprintf(lock_name, sizeof(lock_name), "%s:%" PRIu32, "OpTracker::ShardedLock", i);
ShardedTrackingData* one_shard = new ShardedTrackingData(lock_name);
sharded_in_flight_list.push_back(one_shard);

View File

@ -440,7 +440,13 @@ struct error_code;
buffers_iterator(U* const p)
: cur(p) {
}
template <class U>
// copy constructor
buffers_iterator(const buffers_iterator<T>& other)
: cur(other.cur) {
}
// converting constructor, from iterator -> const_iterator only
template <class U, typename std::enable_if<
std::is_const<T>::value && !std::is_const<U>::value, int>::type = 0>
buffers_iterator(const buffers_iterator<U>& other)
: cur(other.cur) {
}
@ -475,11 +481,6 @@ struct error_code;
bool operator!=(const buffers_iterator& rhs) const {
return !(*this==rhs);
}
using citer_t = buffers_iterator<typename std::add_const<T>::type>;
operator citer_t() const {
return citer_t(cur);
}
};
typedef buffers_iterator<const ptr_node> const_iterator;

View File

@ -812,6 +812,12 @@ struct btree_iterator {
bool operator!=(const const_iterator &x) const {
return node != x.node || position != x.position;
}
bool operator==(const iterator& x) const {
return node == x.node && position == x.position;
}
bool operator!=(const iterator& x) const {
return node != x.node || position != x.position;
}
// Accessors for the key/value the iterator is pointing at.
reference operator*() const {

View File

@ -177,21 +177,27 @@ public:
return *this;
}
bool end() const { return cur == 0; }
bool operator==(const iterator& rhs) const {
return cur == rhs.cur;
friend bool operator==(const iterator& lhs, const iterator& rhs) {
return lhs.cur == rhs.cur;
}
bool operator!=(const iterator& rhs) const {
return cur != rhs.cur;
friend bool operator!=(const iterator& lhs, const iterator& rhs) {
return lhs.cur != rhs.cur;
}
};
iterator begin() { return iterator(_front); }
iterator end() { return iterator(NULL); }
class const_iterator: std::iterator<std::forward_iterator_tag, T> {
class const_iterator {
private:
item *cur;
public:
using iterator_category = std::forward_iterator_tag;
using value_type = T;
using difference_type = std::ptrdiff_t;
using pointer = const T*;
using reference = const T&;
const_iterator(item *i = 0) : cur(i) {}
const T operator*() { return static_cast<const T>(cur->_item); }
const_iterator& operator++() {
@ -201,11 +207,13 @@ public:
return *this;
}
bool end() const { return cur == 0; }
bool operator==(const_iterator& rhs) const {
return cur == rhs.cur;
friend bool operator==(const const_iterator& lhs,
const const_iterator& rhs) {
return lhs.cur == rhs.cur;
}
bool operator!=(const_iterator& rhs) const {
return cur != rhs.cur;
friend bool operator!=(const const_iterator& lhs,
const const_iterator& rhs) {
return lhs.cur != rhs.cur;
}
};

View File

@ -92,22 +92,22 @@ int64_t librados::RadosClient::lookup_pool(const char *name)
bool librados::RadosClient::pool_requires_alignment(int64_t pool_id)
{
bool requires;
int r = pool_requires_alignment2(pool_id, &requires);
bool required;
int r = pool_requires_alignment2(pool_id, &required);
if (r < 0) {
// Cast answer to false, this is a little bit problematic
// since we really don't know the answer yet, say.
return false;
}
return requires;
return required;
}
// a safer version of pool_requires_alignment
int librados::RadosClient::pool_requires_alignment2(int64_t pool_id,
bool *requires)
bool *req)
{
if (!requires)
if (!req)
return -EINVAL;
int r = wait_for_osdmap();
@ -115,11 +115,11 @@ int librados::RadosClient::pool_requires_alignment2(int64_t pool_id,
return r;
}
return objecter->with_osdmap([requires, pool_id](const OSDMap& o) {
return objecter->with_osdmap([req, pool_id](const OSDMap& o) {
if (!o.have_pg_pool(pool_id)) {
return -ENOENT;
}
*requires = o.get_pg_pool(pool_id)->requires_aligned_append();
*req = o.get_pg_pool(pool_id)->requires_aligned_append();
return 0;
});
}

View File

@ -121,7 +121,7 @@ public:
int get_fsid(std::string *s);
int64_t lookup_pool(const char *name);
bool pool_requires_alignment(int64_t pool_id);
int pool_requires_alignment2(int64_t pool_id, bool *requires);
int pool_requires_alignment2(int64_t pool_id, bool *req);
uint64_t pool_required_alignment(int64_t pool_id);
int pool_required_alignment2(int64_t pool_id, uint64_t *alignment);
int pool_get_name(uint64_t pool_id, std::string *name,

View File

@ -1607,7 +1607,7 @@ LIBRADOS_C_API_BASE_DEFAULT(rados_ioctx_pool_requires_alignment);
extern "C" int LIBRADOS_C_API_DEFAULT_F(rados_ioctx_pool_requires_alignment2)(
rados_ioctx_t io,
int *requires)
int *req)
{
tracepoint(librados, rados_ioctx_pool_requires_alignment_enter2, io);
librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
@ -1616,8 +1616,8 @@ extern "C" int LIBRADOS_C_API_DEFAULT_F(rados_ioctx_pool_requires_alignment2)(
&requires_alignment);
tracepoint(librados, rados_ioctx_pool_requires_alignment_exit2, retval,
requires_alignment);
if (requires)
*requires = requires_alignment;
if (req)
*req = requires_alignment;
return retval;
}
LIBRADOS_C_API_BASE_DEFAULT(rados_ioctx_pool_requires_alignment2);

View File

@ -1205,9 +1205,9 @@ bool librados::IoCtx::pool_requires_alignment()
return io_ctx_impl->client->pool_requires_alignment(get_id());
}
int librados::IoCtx::pool_requires_alignment2(bool *requires)
int librados::IoCtx::pool_requires_alignment2(bool *req)
{
return io_ctx_impl->client->pool_requires_alignment2(get_id(), requires);
return io_ctx_impl->client->pool_requires_alignment2(get_id(), req);
}
uint64_t librados::IoCtx::pool_required_alignment()

View File

@ -421,7 +421,7 @@ struct StatCompletionData : BasicStatCompletionData {
private:
FRIEND_MAKE_REF(StatCompletionData);
/// constructor
StatCompletionData<TimeType>(libradosstriper::RadosStriperImpl* striper,
StatCompletionData(libradosstriper::RadosStriperImpl* striper,
const std::string& soid,
librados::AioCompletionImpl *userCompletion,
libradosstriper::MultiAioCompletionImpl *multiCompletion,

View File

@ -667,11 +667,13 @@ private:
template<typename Handler, typename T>
static void assoc_delete(const Handler& handler, T* t) {
typename std::allocator_traits<typename ba::associated_allocator<Handler>::type>
::template rebind_alloc<T> a(
ba::get_associated_allocator(handler));
a.destroy(t);
a.deallocate(t, 1);
using Alloc = ba::associated_allocator_t<Handler>;
using Traits = typename std::allocator_traits<Alloc>;
using RebindAlloc = typename Traits::template rebind_alloc<T>;
using RebindTraits = typename std::allocator_traits<RebindAlloc>;
RebindAlloc a(get_associated_allocator(handler));
RebindTraits::destroy(a, t);
RebindTraits::deallocate(a, t, 1);
}
FIFO(RADOS& r,

View File

@ -3256,7 +3256,7 @@ int OSD::run_osd_bench_test(
utime_t start = ceph_clock_now();
for (int64_t pos = 0; pos < count; pos += bsize) {
char nm[30];
char nm[34];
unsigned offset = 0;
if (onum && osize) {
snprintf(nm, sizeof(nm), "disk_bw_test_%d", (int)(rand() % onum));

View File

@ -14,8 +14,8 @@
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include "OSDCap.h"

View File

@ -1212,7 +1212,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
if (auth.digest_present && candidate.digest_present &&
auth.digest != candidate.digest) {
format_to(out,
format_to(std::back_inserter(out),
"data_digest {:#x} != data_digest {:#x} from shard {}",
candidate.digest,
auth.digest,
@ -1223,7 +1223,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
if (auth.omap_digest_present && candidate.omap_digest_present &&
auth.omap_digest != candidate.omap_digest) {
format_to(out,
format_to(std::back_inserter(out),
"{}omap_digest {:#x} != omap_digest {:#x} from shard {}",
sep(error),
candidate.omap_digest,
@ -1236,7 +1236,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
if (m_is_replicated) {
if (auth_oi.is_data_digest() && candidate.digest_present &&
auth_oi.data_digest != candidate.digest) {
format_to(out,
format_to(std::back_inserter(out),
"{}data_digest {:#x} != data_digest {:#x} from auth oi {}",
sep(error),
candidate.digest,
@ -1248,7 +1248,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
// for replicated:
if (auth_oi.is_omap_digest() && candidate.omap_digest_present &&
auth_oi.omap_digest != candidate.omap_digest) {
format_to(out,
format_to(std::back_inserter(out),
"{}omap_digest {:#x} != omap_digest {:#x} from auth oi {}",
sep(error),
candidate.omap_digest,
@ -1282,7 +1282,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
auth_bl.push_back(auth_attr->second);
if (!can_bl.contents_equal(auth_bl)) {
format_to(out, "{}object info inconsistent ", sep(error));
format_to(std::back_inserter(out), "{}object info inconsistent ", sep(error));
obj_result.set_object_info_inconsistency();
}
}
@ -1302,7 +1302,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
auth_bl.push_back(auth_attr->second);
if (!can_bl.contents_equal(auth_bl)) {
format_to(out, "{}snapset inconsistent ", sep(error));
format_to(std::back_inserter(out), "{}snapset inconsistent ", sep(error));
obj_result.set_snapset_inconsistency();
}
}
@ -1325,7 +1325,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
auth_bl.push_back(auth_hi->second);
if (!can_bl.contents_equal(auth_bl)) {
format_to(out, "{}hinfo inconsistent ", sep(error));
format_to(std::back_inserter(out), "{}hinfo inconsistent ", sep(error));
obj_result.set_hinfo_inconsistency();
}
}
@ -1337,7 +1337,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
uint64_t oi_size = logical_to_ondisk_size(auth_oi.size);
if (oi_size != candidate.size) {
format_to(out,
format_to(std::back_inserter(out),
"{}size {} != size {} from auth oi {}",
sep(error),
candidate.size,
@ -1347,7 +1347,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
}
if (auth.size != candidate.size) {
format_to(out,
format_to(std::back_inserter(out),
"{}size {} != size {} from shard {}",
sep(error),
candidate.size,
@ -1361,7 +1361,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
if (candidate.size > m_conf->osd_max_object_size &&
!obj_result.has_size_too_large()) {
format_to(out,
format_to(std::back_inserter(out),
"{}size {} > {} is too large",
sep(error),
candidate.size,
@ -1381,10 +1381,10 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
auto cand = candidate.attrs.find(k);
if (cand == candidate.attrs.end()) {
format_to(out, "{}attr name mismatch '{}'", sep(error), k);
format_to(std::back_inserter(out), "{}attr name mismatch '{}'", sep(error), k);
obj_result.set_attr_name_mismatch();
} else if (cand->second.cmp(v)) {
format_to(out, "{}attr value mismatch '{}'", sep(error), k);
format_to(std::back_inserter(out), "{}attr value mismatch '{}'", sep(error), k);
obj_result.set_attr_value_mismatch();
}
}
@ -1397,7 +1397,7 @@ bool ScrubBackend::compare_obj_details(pg_shard_t auth_shard,
auto in_auth = auth.attrs.find(k);
if (in_auth == auth.attrs.end()) {
format_to(out, "{}attr name mismatch '{}'", sep(error), k);
format_to(std::back_inserter(out), "{}attr name mismatch '{}'", sep(error), k);
obj_result.set_attr_name_mismatch();
}
}

View File

@ -22,6 +22,7 @@
extern "C" {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wextern-c-compat"
#pragma clang diagnostic ignored "-Wdeprecated-anon-enum-enum-conversion"
#include "motr/config.h"
#include "lib/types.h"
#include "lib/trace.h" // m0_trace_set_mmapped_buffer

View File

@ -20,6 +20,7 @@
extern "C" {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wextern-c-compat"
#pragma clang diagnostic ignored "-Wdeprecated-anon-enum-enum-conversion"
#include "motr/config.h"
#include "motr/client.h"
#pragma clang diagnostic pop

@ -1 +1 @@
Subproject commit 1609bb2ab5441d2314f56858f4f98fc2be509f89
Subproject commit 825598ac92dfb889a2107b85d461e9e673838450

View File

@ -26,9 +26,9 @@ void RadosTestNS::SetUp()
{
cluster = RadosTestNS::s_cluster;
ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx));
int requires;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &requires));
ASSERT_FALSE(requires);
int req;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &req));
ASSERT_FALSE(req);
}
void RadosTestNS::TearDown()
@ -78,9 +78,9 @@ void RadosTestECNS::SetUp()
{
cluster = RadosTestECNS::s_cluster;
ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx));
int requires;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &requires));
ASSERT_TRUE(requires);
int req;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &req));
ASSERT_TRUE(req);
ASSERT_EQ(0, rados_ioctx_pool_required_alignment2(ioctx, &alignment));
ASSERT_NE(0U, alignment);
}
@ -112,9 +112,9 @@ void RadosTest::SetUp()
ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx));
nspace = get_temp_pool_name();
rados_ioctx_set_namespace(ioctx, nspace.c_str());
int requires;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &requires));
ASSERT_FALSE(requires);
int req;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &req));
ASSERT_FALSE(req);
}
void RadosTest::TearDown()
@ -172,9 +172,9 @@ void RadosTestEC::SetUp()
ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx));
nspace = get_temp_pool_name();
rados_ioctx_set_namespace(ioctx, nspace.c_str());
int requires;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &requires));
ASSERT_TRUE(requires);
int req;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(ioctx, &req));
ASSERT_TRUE(req);
ASSERT_EQ(0, rados_ioctx_pool_required_alignment2(ioctx, &alignment));
ASSERT_NE(0U, alignment);
}

View File

@ -1147,9 +1147,9 @@ TEST(LibRadosAioEC, RoundTripAppend) {
ASSERT_EQ("", test_data.init());
ASSERT_EQ(0, rados_aio_create_completion2(nullptr,
nullptr, &my_completion));
int requires;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(test_data.m_ioctx, &requires));
ASSERT_NE(0, requires);
int req;
ASSERT_EQ(0, rados_ioctx_pool_requires_alignment2(test_data.m_ioctx, &req));
ASSERT_NE(0, req);
uint64_t alignment;
ASSERT_EQ(0, rados_ioctx_pool_required_alignment2(test_data.m_ioctx, &alignment));
ASSERT_NE(0U, alignment);

View File

@ -1560,9 +1560,9 @@ TEST(LibRadosAioEC, RoundTripAppendPP) {
ASSERT_EQ("", test_data.init());
auto my_completion = std::unique_ptr<AioCompletion>{Rados::aio_create_completion()};
ASSERT_TRUE(my_completion);
bool requires;
ASSERT_EQ(0, test_data.m_ioctx.pool_requires_alignment2(&requires));
ASSERT_TRUE(requires);
bool req;
ASSERT_EQ(0, test_data.m_ioctx.pool_requires_alignment2(&req));
ASSERT_TRUE(req);
uint64_t alignment;
ASSERT_EQ(0, test_data.m_ioctx.pool_required_alignment2(&alignment));
ASSERT_NE((unsigned)0, alignment);

View File

@ -41,9 +41,9 @@ void RadosTestPPNS::TearDownTestCase()
void RadosTestPPNS::SetUp()
{
ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
bool requires;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires));
ASSERT_FALSE(requires);
bool req;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&req));
ASSERT_FALSE(req);
}
void RadosTestPPNS::TearDown()
@ -124,9 +124,9 @@ void RadosTestParamPPNS::SetUp()
}
ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
bool requires;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires));
ASSERT_FALSE(requires);
bool req;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&req));
ASSERT_FALSE(req);
}
void RadosTestParamPPNS::TearDown()
@ -166,9 +166,9 @@ void RadosTestECPPNS::TearDownTestCase()
void RadosTestECPPNS::SetUp()
{
ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
bool requires;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires));
ASSERT_TRUE(requires);
bool req;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&req));
ASSERT_TRUE(req);
ASSERT_EQ(0, ioctx.pool_required_alignment2(&alignment));
ASSERT_NE(0U, alignment);
}
@ -201,9 +201,9 @@ void RadosTestPP::SetUp()
ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
nspace = get_temp_pool_name();
ioctx.set_namespace(nspace);
bool requires;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires));
ASSERT_FALSE(requires);
bool req;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&req));
ASSERT_FALSE(req);
}
void RadosTestPP::TearDown()
@ -322,9 +322,9 @@ void RadosTestParamPP::SetUp()
ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
nspace = get_temp_pool_name();
ioctx.set_namespace(nspace);
bool requires;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires));
ASSERT_FALSE(requires);
bool req;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&req));
ASSERT_FALSE(req);
}
void RadosTestParamPP::TearDown()
@ -373,9 +373,9 @@ void RadosTestECPP::SetUp()
ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx));
nspace = get_temp_pool_name();
ioctx.set_namespace(nspace);
bool requires;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&requires));
ASSERT_TRUE(requires);
bool req;
ASSERT_EQ(0, ioctx.pool_requires_alignment2(&req));
ASSERT_TRUE(req);
ASSERT_EQ(0, ioctx.pool_required_alignment2(&alignment));
ASSERT_NE(0U, alignment);
}

View File

@ -2202,15 +2202,15 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
// align op_size
{
bool requires;
ret = io_ctx.pool_requires_alignment2(&requires);
bool req;
ret = io_ctx.pool_requires_alignment2(&req);
if (ret < 0) {
cerr << "error checking pool alignment requirement"
<< cpp_strerror(ret) << std::endl;
return 1;
}
if (requires) {
if (req) {
uint64_t align = 0;
ret = io_ctx.pool_required_alignment2(&align);
if (ret < 0) {

View File

@ -1230,10 +1230,10 @@ TRACEPOINT_EVENT(librados, rados_ioctx_pool_requires_alignment_enter2,
TRACEPOINT_EVENT(librados, rados_ioctx_pool_requires_alignment_exit2,
TP_ARGS(
int, retval,
int, requires),
int, req),
TP_FIELDS(
ctf_integer(int, retval, retval)
ctf_integer(int, requires, requires)
ctf_integer(int, requires, req)
)
)