summaryrefslogtreecommitdiffstats
path: root/src/cls/version/cls_version_client.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/cls/version/cls_version_client.cc
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/cls/version/cls_version_client.cc')
-rw-r--r--src/cls/version/cls_version_client.cc101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/cls/version/cls_version_client.cc b/src/cls/version/cls_version_client.cc
new file mode 100644
index 00000000..3c1792aa
--- /dev/null
+++ b/src/cls/version/cls_version_client.cc
@@ -0,0 +1,101 @@
+#include <errno.h>
+
+#include "cls/version/cls_version_client.h"
+#include "include/rados/librados.hpp"
+
+
+using namespace librados;
+
+
+void cls_version_set(librados::ObjectWriteOperation& op, obj_version& objv)
+{
+ bufferlist in;
+ cls_version_set_op call;
+ call.objv = objv;
+ encode(call, in);
+ op.exec("version", "set", in);
+}
+
+void cls_version_inc(librados::ObjectWriteOperation& op)
+{
+ bufferlist in;
+ cls_version_inc_op call;
+ encode(call, in);
+ op.exec("version", "inc", in);
+}
+
+void cls_version_inc(librados::ObjectWriteOperation& op, obj_version& objv, VersionCond cond)
+{
+ bufferlist in;
+ cls_version_inc_op call;
+ call.objv = objv;
+
+ obj_version_cond c;
+ c.cond = cond;
+ c.ver = objv;
+
+ call.conds.push_back(c);
+
+ encode(call, in);
+ op.exec("version", "inc_conds", in);
+}
+
+void cls_version_check(librados::ObjectOperation& op, obj_version& objv, VersionCond cond)
+{
+ bufferlist in;
+ cls_version_check_op call;
+ call.objv = objv;
+
+ obj_version_cond c;
+ c.cond = cond;
+ c.ver = objv;
+
+ call.conds.push_back(c);
+
+ encode(call, in);
+ op.exec("version", "check_conds", in);
+}
+
+class VersionReadCtx : public ObjectOperationCompletion {
+ obj_version *objv;
+public:
+ explicit VersionReadCtx(obj_version *_objv) : objv(_objv) {}
+ void handle_completion(int r, bufferlist& outbl) override {
+ if (r >= 0) {
+ cls_version_read_ret ret;
+ try {
+ auto iter = outbl.cbegin();
+ decode(ret, iter);
+ *objv = ret.objv;
+ } catch (buffer::error& err) {
+ // nothing we can do about it atm
+ }
+ }
+ }
+};
+
+void cls_version_read(librados::ObjectReadOperation& op, obj_version *objv)
+{
+ bufferlist inbl;
+ op.exec("version", "read", inbl, new VersionReadCtx(objv));
+}
+
+int cls_version_read(librados::IoCtx& io_ctx, string& oid, obj_version *ver)
+{
+ bufferlist in, out;
+ int r = io_ctx.exec(oid, "version", "read", in, out);
+ if (r < 0)
+ return r;
+
+ cls_version_read_ret ret;
+ try {
+ auto iter = out.cbegin();
+ decode(ret, iter);
+ } catch (buffer::error& err) {
+ return -EIO;
+ }
+
+ *ver = ret.objv;
+
+ return r;
+}