From: Kefu Chai Date: Tue, 29 Jun 2021 06:39:35 +0000 (+0800) Subject: osd/PrimaryLogPG: use std::from_chars() to convert str to integer X-Git-Tag: v17.1.0~1517^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8fe0305992efc4516f22066818ef6c5a037f7a8c;p=ceph.git osd/PrimaryLogPG: use std::from_chars() to convert str to integer * no need to create a temporary string for using strtoull() * use std::from_chars() so it's consistent with its counterpart in in crimson. Signed-off-by: Kefu Chai --- diff --git a/src/crimson/osd/pg_backend.cc b/src/crimson/osd/pg_backend.cc index 4fd9cf994a91..62f7341c7363 100644 --- a/src/crimson/osd/pg_backend.cc +++ b/src/crimson/osd/pg_backend.cc @@ -901,15 +901,15 @@ PGBackend::cmp_xattr_ierrorator::future<> PGBackend::cmp_xattr( break; case CEPH_OSD_CMPXATTR_MODE_U64: { - uint64_t val; + uint64_t lhs; try { - decode(val, bp); + decode(lhs, bp); } catch (ceph::buffer::error& e) { logger().info("cmp_xattr: buffer error expection"); result = -EINVAL; break; } - result = do_xattr_cmp_u64(osd_op.op.xattr.cmp_op, val, xattr); + result = do_xattr_cmp_u64(osd_op.op.xattr.cmp_op, lhs, xattr); } break; default: diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index 8a09683504c0..75e070115e1f 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -15,6 +15,8 @@ * */ +#include + #include "boost/tuple/tuple.hpp" #include "boost/intrusive_ptr.hpp" #include "PG.h" @@ -4925,16 +4927,19 @@ int do_cmp_xattr(int op, const U& lhs, const V& rhs) } // anonymous namespace -int PrimaryLogPG::do_xattr_cmp_u64(int op, __u64 v1, bufferlist& xattr) +int PrimaryLogPG::do_xattr_cmp_u64(int op, uint64_t v1, bufferlist& xattr) { - __u64 v2; + uint64_t v2; - string v2s(xattr.c_str(), xattr.length()); - if (v2s.length()) - v2 = strtoull(v2s.c_str(), NULL, 10); - else + if (xattr.length()) { + const char* first = xattr.c_str(); + if (auto [p, ec] = std::from_chars(first, first + xattr.length(), v2); + ec != std::errc()) { + return -EINVAL; + } + } else { v2 = 0; - + } dout(20) << "do_xattr_cmp_u64 '" << v1 << "' vs '" << v2 << "' op " << op << dendl; return do_cmp_xattr(op, v1, v2); } diff --git a/src/osd/PrimaryLogPG.h b/src/osd/PrimaryLogPG.h index 6018f366ca28..a757b8ec9507 100644 --- a/src/osd/PrimaryLogPG.h +++ b/src/osd/PrimaryLogPG.h @@ -1379,7 +1379,7 @@ protected: unsigned split_bits) override; void apply_and_flush_repops(bool requeue); - int do_xattr_cmp_u64(int op, __u64 v1, ceph::buffer::list& xattr); + int do_xattr_cmp_u64(int op, uint64_t v1, ceph::buffer::list& xattr); int do_xattr_cmp_str(int op, std::string& v1s, ceph::buffer::list& xattr); // -- checksum --