]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
neorados: Change `cmpxattr_op` to `cmp_op` and use in `Op::cmp_omap`
authorAdam Emerson <aemerson@redhat.com>
Wed, 9 Aug 2023 03:19:24 +0000 (23:19 -0400)
committerAdam Emerson <aemerson@redhat.com>
Thu, 14 Sep 2023 21:48:00 +0000 (17:48 -0400)
Omap and Xattr comparison use the same values, but in the Xattr case
it's eight bits wide.

Rename the enum to `cmp_op` to reflect this, and open-code encoding
the assertions so we don't have to allocate an intermediate structure.

Signed-off-by: Adam Emerson <aemerson@redhat.com>
src/include/neorados/RADOS.hpp
src/neorados/RADOS.cc
src/osdc/Objecter.h

index 6cb11f43d40f116259f8e6e64adea3b8da058e28..4c8251a16661bb40310c816c34711f7393aa30cd 100644 (file)
@@ -193,7 +193,7 @@ private:
 
 inline constexpr std::string_view all_nspaces("\001");
 
-enum class cmpxattr_op : std::uint8_t {
+enum class cmp_op : std::uint8_t {
   eq  = 1,
   ne  = 2,
   gt  = 3,
@@ -303,14 +303,14 @@ public:
 
   void cmpext(uint64_t off, ceph::buffer::list&& cmp_bl,
              int* unmatch = nullptr);
-  void cmpxattr(std::string_view name, cmpxattr_op op,
+  void cmpxattr(std::string_view name, cmp_op op,
                const ceph::buffer::list& val);
-  void cmpxattr(std::string_view name, cmpxattr_op op, std::uint64_t val);
+  void cmpxattr(std::string_view name, cmp_op op, std::uint64_t val);
   void assert_version(uint64_t ver);
   void assert_exists();
   void cmp_omap(const boost::container::flat_map<std::string,
                                                 std::pair<ceph::buffer::list,
-                                                          int>>& assertions);
+                                                          cmp_op>>& assertions);
 
   void exec(std::string_view cls, std::string_view method,
            const ceph::buffer::list& inbl,
@@ -547,22 +547,22 @@ public:
     return std::move(*this);
   }
 
-  ReadOp& cmpxattr(std::string_view name, cmpxattr_op op,
+  ReadOp& cmpxattr(std::string_view name, cmp_op op,
                   const ceph::buffer::list& val) & {
     Op::cmpxattr(name, op, val);
     return *this;
   }
-  ReadOp&& cmpxattr(std::string_view name, cmpxattr_op op,
+  ReadOp&& cmpxattr(std::string_view name, cmp_op op,
                    const ceph::buffer::list& val) && {
     Op::cmpxattr(name, op, val);
     return std::move(*this);
   }
 
-  ReadOp& cmpxattr(std::string_view name, cmpxattr_op op, std::uint64_t val) & {
+  ReadOp& cmpxattr(std::string_view name, cmp_op op, std::uint64_t val) & {
     Op::cmpxattr(name, op, val);
     return *this;
   }
-  ReadOp&& cmpxattr(std::string_view name, cmpxattr_op op, std::uint64_t val) && {
+  ReadOp&& cmpxattr(std::string_view name, cmp_op op, std::uint64_t val) && {
     Op::cmpxattr(name, op, val);
     return std::move(*this);
   }
@@ -587,13 +587,13 @@ public:
 
   ReadOp& cmp_omap(
     const boost::container::flat_map<
-      std::string, std::pair<ceph::buffer::list, int>>& assertions) & {
+      std::string, std::pair<ceph::buffer::list, cmp_op>>& assertions) & {
     Op::cmp_omap(assertions);
     return *this;
   }
   ReadOp&& cmp_omap(
     const boost::container::flat_map<
-      std::string, std::pair<ceph::buffer::list, int>>& assertions) && {
+      std::string, std::pair<ceph::buffer::list, cmp_op>>& assertions) && {
     Op::cmp_omap(assertions);
     return std::move(*this);
   }
@@ -931,22 +931,22 @@ public:
     return std::move(*this);
   }
 
-  WriteOp& cmpxattr(std::string_view name, cmpxattr_op op,
+  WriteOp& cmpxattr(std::string_view name, cmp_op op,
                   const ceph::buffer::list& val) & {
     Op::cmpxattr(name, op, val);
     return *this;
   }
-  WriteOp&& cmpxattr(std::string_view name, cmpxattr_op op,
+  WriteOp&& cmpxattr(std::string_view name, cmp_op op,
                    const ceph::buffer::list& val) && {
     Op::cmpxattr(name, op, val);
     return std::move(*this);
   }
 
-  WriteOp& cmpxattr(std::string_view name, cmpxattr_op op, std::uint64_t val) & {
+  WriteOp& cmpxattr(std::string_view name, cmp_op op, std::uint64_t val) & {
     Op::cmpxattr(name, op, val);
     return *this;
   }
-  WriteOp&& cmpxattr(std::string_view name, cmpxattr_op op, std::uint64_t val) && {
+  WriteOp&& cmpxattr(std::string_view name, cmp_op op, std::uint64_t val) && {
     Op::cmpxattr(name, op, val);
     return std::move(*this);
   }
@@ -971,13 +971,13 @@ public:
 
   WriteOp& cmp_omap(
     const boost::container::flat_map<
-      std::string, std::pair<ceph::buffer::list, int>>& assertions) & {
+      std::string, std::pair<ceph::buffer::list, cmp_op>>& assertions) & {
     Op::cmp_omap(assertions);
     return *this;
   }
   WriteOp&& cmp_omap(
     const boost::container::flat_map<
-      std::string, std::pair<ceph::buffer::list, int>>& assertions) && {
+      std::string, std::pair<ceph::buffer::list, cmp_op>>& assertions) && {
     Op::cmp_omap(assertions);
     return std::move(*this);
   }
index ac3b672b3f6193ac2f43a3727c9f46f95e48e610..082378ff78dff41012d4da4d2dfe8f34e7133e99 100644 (file)
@@ -463,11 +463,11 @@ void Op::cmpext(uint64_t off, bufferlist&& cmp_bl, int* s) {
   reinterpret_cast<OpImpl*>(&impl)->op.cmpext(off, std::move(cmp_bl), nullptr,
                                              s);
 }
-void Op::cmpxattr(std::string_view name, cmpxattr_op op, const bufferlist& val) {
+void Op::cmpxattr(std::string_view name, cmp_op op, const bufferlist& val) {
   reinterpret_cast<OpImpl*>(&impl)->
     op.cmpxattr(name, std::uint8_t(op), CEPH_OSD_CMPXATTR_MODE_STRING, val);
 }
-void Op::cmpxattr(std::string_view name, cmpxattr_op op, std::uint64_t val) {
+void Op::cmpxattr(std::string_view name, cmp_op op, std::uint64_t val) {
   bufferlist bl;
   encode(val, bl);
   reinterpret_cast<OpImpl*>(&impl)->
@@ -485,8 +485,16 @@ void Op::assert_exists() {
 }
 void Op::cmp_omap(const bc::flat_map<
                  std::string, std::pair<cb::list,
-                 int>>& assertions) {
-  reinterpret_cast<OpImpl*>(&impl)->op.omap_cmp(assertions, nullptr);
+                 cmp_op>>& assertions) {
+  buffer::list bl;
+  encode(uint32_t(assertions.size()), bl);
+  for (const auto& [key, assertion] : assertions) {
+    const auto& [value, op] = assertion;
+    encode(key, bl);
+    encode(value, bl);
+    encode(int(op), bl);
+  }
+  reinterpret_cast<OpImpl*>(&impl)->op.omap_cmp(std::move(bl), nullptr);
 }
 
 void Op::exec(std::string_view cls, std::string_view method,
index 5dbc254e3ebfbe1cd186f325a59132e925c782eb..3cfcb2d68800a15e6d6d744ea57614b7aea98df9 100644 (file)
@@ -1026,18 +1026,18 @@ struct ObjectOperation {
     }
   }
 
-  void omap_cmp(const boost::container::flat_map<
-               std::string, std::pair<ceph::buffer::list, int>>& assertions,
-               boost::system::error_code *ec) {
+  void omap_cmp(ceph::buffer::list&& assertions,
+               int *prval) {
+    using ceph::encode;
     OSDOp &op = add_op(CEPH_OSD_OP_OMAP_CMP);
-    ceph::buffer::list bl;
-    encode(assertions, bl);
     op.op.extent.offset = 0;
-    op.op.extent.length = bl.length();
-    op.indata.claim_append(bl);
-    out_ec.back() = ec;
+    op.op.extent.length = assertions.length();
+    op.indata.claim_append(assertions);
+    if (prval) {
+      unsigned p = ops.size() - 1;
+      out_rval[p] = prval;
+    }
   }
-
   struct C_ObjectOperation_copyget : public Context {
     ceph::buffer::list bl;
     object_copy_cursor_t *cursor;