]> git-server-git.apps.pok.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, 7 Dec 2023 21:23:08 +0000 (16:23 -0500)
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 e890d7a936195e8efaa2b897bdf3976de0c7d97a..6268f0219f33f8771b73281abf64a26265667a15 100644 (file)
@@ -194,7 +194,7 @@ private:
 
 inline const std::string all_nspaces("\001");
 
-enum class cmpxattr_op : std::uint8_t {
+enum class cmp_op : std::uint8_t {
   eq  = 1,
   ne  = 2,
   gt  = 3,
@@ -304,14 +304,14 @@ public:
 
   void cmpext(uint64_t off, ceph::buffer::list&& cmp_bl,
              uint64_t* 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,
@@ -548,22 +548,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);
   }
@@ -588,13 +588,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);
   }
@@ -932,22 +932,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);
   }
@@ -972,13 +972,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 47b1c0d48824d88fde26246a7a587017d94546e2..84cc200929f50a669a7b1e47eae1adc248d464dc 100644 (file)
@@ -424,11 +424,11 @@ void Op::cmpext(uint64_t off, bufferlist&& cmp_bl, uint64_t* unmatch) {
   reinterpret_cast<OpImpl*>(&impl)->op.cmpext(off, std::move(cmp_bl), nullptr,
                                              unmatch);
 }
-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)->
@@ -446,8 +446,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 512a4435eccb126e35470122bf2a17b471fe3645..0dcdca7982c0ca0a2ce16373db68489f69f2aa1c 100644 (file)
@@ -1046,18 +1046,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;