From: Yehuda Sadeh Date: Tue, 7 Jan 2014 22:42:03 +0000 (-0800) Subject: cls/user: a new op to retrieve user header X-Git-Tag: v0.78~270^2~32 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=edcf9fed0292d45f30ff24c51f9742d137951213;p=ceph.git cls/user: a new op to retrieve user header user header holds user total stats Signed-off-by: Yehuda Sadeh --- diff --git a/src/cls/user/cls_user.cc b/src/cls/user/cls_user.cc index 77eb58d82be..b460d6283ea 100644 --- a/src/cls/user/cls_user.cc +++ b/src/cls/user/cls_user.cc @@ -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; } diff --git a/src/cls/user/cls_user_client.cc b/src/cls/user/cls_user_client.cc index 2b1c1347fc0..e163931172b 100644 --- a/src/cls/user/cls_user_client.cc +++ b/src/cls/user/cls_user_client.cc @@ -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)); +} diff --git a/src/cls/user/cls_user_ops.h b/src/cls/user/cls_user_ops.h index a142d4de7ef..4d9843b4893 100644 --- a/src/cls/user/cls_user_ops.h +++ b/src/cls/user/cls_user_ops.h @@ -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