Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / cls / refcount / cls_refcount_client.cc
1 #include <errno.h>
2
3 #include "cls/refcount/cls_refcount_client.h"
4 #include "cls/refcount/cls_refcount_ops.h"
5 #include "include/rados/librados.hpp"
6
7 using namespace librados;
8
9
10 void cls_refcount_get(librados::ObjectWriteOperation& op, const string& tag, bool implicit_ref)
11 {
12   bufferlist in;
13   cls_refcount_get_op call;
14   call.tag = tag;
15   call.implicit_ref = implicit_ref;
16   ::encode(call, in);
17   op.exec("refcount", "get", in);
18 }
19
20 void cls_refcount_put(librados::ObjectWriteOperation& op, const string& tag, bool implicit_ref)
21 {
22   bufferlist in;
23   cls_refcount_put_op call;
24   call.tag = tag;
25   call.implicit_ref = implicit_ref;
26   ::encode(call, in);
27   op.exec("refcount", "put", in);
28 }
29
30 void cls_refcount_set(librados::ObjectWriteOperation& op, list<string>& refs)
31 {
32   bufferlist in;
33   cls_refcount_set_op call;
34   call.refs = refs;
35   ::encode(call, in);
36   op.exec("refcount", "set", in);
37 }
38
39 int cls_refcount_read(librados::IoCtx& io_ctx, string& oid, list<string> *refs, bool implicit_ref)
40 {
41   bufferlist in, out;
42   cls_refcount_read_op call;
43   call.implicit_ref = implicit_ref;
44   ::encode(call, in);
45   int r = io_ctx.exec(oid, "refcount", "read", in, out);
46   if (r < 0)
47     return r;
48
49   cls_refcount_read_ret ret;
50   try {
51     bufferlist::iterator iter = out.begin();
52     ::decode(ret, iter);
53   } catch (buffer::error& err) {
54     return -EIO;
55   }
56
57   *refs = ret.refs;
58
59   return r;
60 }