]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/user: a new op to retrieve user header
authorYehuda Sadeh <yehuda@inktank.com>
Tue, 7 Jan 2014 22:42:03 +0000 (14:42 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 24 Jan 2014 18:28:47 +0000 (10:28 -0800)
user header holds user total stats

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/cls/user/cls_user.cc
src/cls/user/cls_user_client.cc
src/cls/user/cls_user_ops.h

index 77eb58d82bef496fd77609e1fde2d6ee25d27d62..b460d6283eafad0d467760803ce871c3bc8f0adb 100644 (file)
@@ -21,6 +21,7 @@ cls_handle_t h_class;
 cls_method_handle_t h_user_set_buckets_info;
 cls_method_handle_t h_user_remove_bucket;
 cls_method_handle_t h_user_list_buckets;
+cls_method_handle_t h_user_get_header;
 
 static int write_entry(cls_method_context_t hctx, const string& key, const cls_user_bucket_entry& entry)
 {
@@ -272,6 +273,29 @@ static int cls_user_list_buckets(cls_method_context_t hctx, bufferlist *in, buff
   return 0;
 }
 
+static int cls_user_get_header(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
+{
+  bufferlist::iterator in_iter = in->begin();
+
+  cls_user_get_header_op op;
+  try {
+    ::decode(op, in_iter);
+  } catch (buffer::error& err) {
+    CLS_LOG(1, "ERROR: cls_user_get_header_op(): failed to decode op");
+    return -EINVAL;
+  }
+
+  cls_user_get_header_ret op_ret;
+
+  int ret = read_header(hctx, &op_ret.header);
+  if (ret < 0)
+    return ret;
+
+  ::encode(op_ret, *out);
+
+  return 0;
+}
+
 void __cls_init()
 {
   CLS_LOG(1, "Loaded user class!");
@@ -283,6 +307,7 @@ void __cls_init()
                           cls_user_set_buckets_info, &h_user_set_buckets_info);
   cls_register_cxx_method(h_class, "remove_bucket", CLS_METHOD_RD | CLS_METHOD_WR, cls_user_remove_bucket, &h_user_remove_bucket);
   cls_register_cxx_method(h_class, "list_buckets", CLS_METHOD_RD, cls_user_list_buckets, &h_user_list_buckets);
+  cls_register_cxx_method(h_class, "get_header", CLS_METHOD_RD, cls_user_get_header, &h_user_get_header);
 
   return;
 }
index 2b1c1347fc08273a03e9b74b7622357cff4539dd..e163931172bdc0848ecd6e2f0160861419c83edd 100644 (file)
@@ -69,4 +69,33 @@ void cls_user_bucket_list(librados::ObjectReadOperation& op,
   op.exec("user", "list_buckets", inbl, new ClsUserListCtx(&entries, out_marker, truncated));
 }
 
+class ClsUserGetHeaderCtx : public ObjectOperationCompletion {
+  cls_user_header *header;
+public:
+  ClsUserGetHeaderCtx(cls_user_header *_h) : header(_h) {}
+  void handle_completion(int r, bufferlist& outbl) {
+    if (r >= 0) {
+      cls_user_get_header_ret ret;
+      try {
+        bufferlist::iterator iter = outbl.begin();
+        ::decode(ret, iter);
+        if (header)
+         *header = ret.header;
+      } catch (buffer::error& err) {
+        // nothing we can do about it atm
+      }
+    }
+  }
+};
+
 
+void cls_user_get_header(librados::ObjectReadOperation& op,
+                       cls_user_header *header)
+{
+  bufferlist inbl;
+  cls_user_get_header_op call;
+
+  ::encode(call, inbl);
+
+  op.exec("user", "get_header", inbl, new ClsUserGetHeaderCtx(header));
+}
index a142d4de7ef49087e37e4eb17641ca202fc4daee..4d9843b489324fda5c3f73ef9810451cd9bf2924 100644 (file)
@@ -94,4 +94,39 @@ struct cls_user_list_buckets_ret {
 WRITE_CLASS_ENCODER(cls_user_list_buckets_ret)
 
 
+struct cls_user_get_header_op {
+  cls_user_get_header_op() {}
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::iterator& bl) {
+    DECODE_START(1, bl);
+    DECODE_FINISH(bl);
+  }
+};
+WRITE_CLASS_ENCODER(cls_user_get_header_op)
+
+struct cls_user_get_header_ret {
+  cls_user_header header;
+
+  cls_user_get_header_ret() {}
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    ::encode(header, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::iterator& bl) {
+    DECODE_START(1, bl);
+    ::decode(header, bl);
+    DECODE_FINISH(bl);
+  }
+};
+WRITE_CLASS_ENCODER(cls_user_get_header_ret)
+
+
 #endif