]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/PrimaryLogPG: use std::from_chars() to convert str to integer
authorKefu Chai <kchai@redhat.com>
Tue, 29 Jun 2021 06:39:35 +0000 (14:39 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 29 Jun 2021 06:54:08 +0000 (14:54 +0800)
* 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 <kchai@redhat.com>
src/crimson/osd/pg_backend.cc
src/osd/PrimaryLogPG.cc
src/osd/PrimaryLogPG.h

index 4fd9cf994a914d27754c614f6e63e8d1f9a6be0d..62f7341c73633aee3b558679801022ee2dad4ca2 100644 (file)
@@ -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:
index 8a09683504c01c88e039946831f412895c2c0a05..75e070115e1fe878ea325021fd1ae5652a151ea1 100644 (file)
@@ -15,6 +15,8 @@
  *
  */
 
+#include <charconv>
+
 #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);
 }
index 6018f366ca285f483b34cf46ce8c8581d2f00f0a..a757b8ec950765f9d72625007059b6915188ac79 100644 (file)
@@ -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 --