From: Adam Emerson Date: Wed, 9 Aug 2023 03:19:24 +0000 (-0400) Subject: neorados: Change `cmpxattr_op` to `cmp_op` and use in `Op::cmp_omap` X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=36aa8e4973b5da3a5ccd22d6059fccb3706e2b9f;p=ceph.git neorados: Change `cmpxattr_op` to `cmp_op` and use in `Op::cmp_omap` 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 --- diff --git a/src/include/neorados/RADOS.hpp b/src/include/neorados/RADOS.hpp index 6cb11f43d40f1..4c8251a16661b 100644 --- a/src/include/neorados/RADOS.hpp +++ b/src/include/neorados/RADOS.hpp @@ -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>& 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>& assertions) & { + std::string, std::pair>& assertions) & { Op::cmp_omap(assertions); return *this; } ReadOp&& cmp_omap( const boost::container::flat_map< - std::string, std::pair>& assertions) && { + std::string, std::pair>& 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>& assertions) & { + std::string, std::pair>& assertions) & { Op::cmp_omap(assertions); return *this; } WriteOp&& cmp_omap( const boost::container::flat_map< - std::string, std::pair>& assertions) && { + std::string, std::pair>& assertions) && { Op::cmp_omap(assertions); return std::move(*this); } diff --git a/src/neorados/RADOS.cc b/src/neorados/RADOS.cc index ac3b672b3f619..082378ff78dff 100644 --- a/src/neorados/RADOS.cc +++ b/src/neorados/RADOS.cc @@ -463,11 +463,11 @@ void Op::cmpext(uint64_t off, bufferlist&& cmp_bl, int* s) { reinterpret_cast(&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(&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(&impl)-> @@ -485,8 +485,16 @@ void Op::assert_exists() { } void Op::cmp_omap(const bc::flat_map< std::string, std::pair>& assertions) { - reinterpret_cast(&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(&impl)->op.omap_cmp(std::move(bl), nullptr); } void Op::exec(std::string_view cls, std::string_view method, diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 5dbc254e3ebfb..3cfcb2d68800a 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -1026,18 +1026,18 @@ struct ObjectOperation { } } - void omap_cmp(const boost::container::flat_map< - std::string, std::pair>& 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;