1 // -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include "cls/user/cls_user_client.h"
7 #include "include/rados/librados.hpp"
10 using namespace librados;
13 void cls_user_set_buckets(librados::ObjectWriteOperation& op, list<cls_user_bucket_entry>& entries, bool add)
16 cls_user_set_buckets_op call;
17 call.entries = entries;
19 call.time = real_clock::now();
21 op.exec("user", "set_buckets_info", in);
24 void cls_user_complete_stats_sync(librados::ObjectWriteOperation& op)
27 cls_user_complete_stats_sync_op call;
28 call.time = real_clock::now();
30 op.exec("user", "complete_stats_sync", in);
33 void cls_user_remove_bucket(librados::ObjectWriteOperation& op, const cls_user_bucket& bucket)
36 cls_user_remove_bucket_op call;
39 op.exec("user", "remove_bucket", in);
42 class ClsUserListCtx : public ObjectOperationCompletion {
43 list<cls_user_bucket_entry> *entries;
48 ClsUserListCtx(list<cls_user_bucket_entry> *_entries, string *_marker, bool *_truncated, int *_pret) :
49 entries(_entries), marker(_marker), truncated(_truncated), pret(_pret) {}
50 void handle_completion(int r, bufferlist& outbl) override {
52 cls_user_list_buckets_ret ret;
54 bufferlist::iterator iter = outbl.begin();
57 *entries = ret.entries;
59 *truncated = ret.truncated;
62 } catch (buffer::error& err) {
72 void cls_user_bucket_list(librados::ObjectReadOperation& op,
73 const string& in_marker,
74 const string& end_marker,
76 list<cls_user_bucket_entry>& entries,
82 cls_user_list_buckets_op call;
83 call.marker = in_marker;
84 call.end_marker = end_marker;
85 call.max_entries = max_entries;
89 op.exec("user", "list_buckets", inbl, new ClsUserListCtx(&entries, out_marker, truncated, pret));
92 class ClsUserGetHeaderCtx : public ObjectOperationCompletion {
93 cls_user_header *header;
94 RGWGetUserHeader_CB *ret_ctx;
97 ClsUserGetHeaderCtx(cls_user_header *_h, RGWGetUserHeader_CB *_ctx, int *_pret) : header(_h), ret_ctx(_ctx), pret(_pret) {}
98 ~ClsUserGetHeaderCtx() override {
103 void handle_completion(int r, bufferlist& outbl) override {
105 cls_user_get_header_ret ret;
107 bufferlist::iterator iter = outbl.begin();
110 *header = ret.header;
111 } catch (buffer::error& err) {
115 ret_ctx->handle_response(r, ret.header);
124 void cls_user_get_header(librados::ObjectReadOperation& op,
125 cls_user_header *header, int *pret)
128 cls_user_get_header_op call;
130 ::encode(call, inbl);
132 op.exec("user", "get_header", inbl, new ClsUserGetHeaderCtx(header, NULL, pret));
135 int cls_user_get_header_async(IoCtx& io_ctx, string& oid, RGWGetUserHeader_CB *ctx)
138 cls_user_get_header_op call;
140 ObjectReadOperation op;
141 op.exec("user", "get_header", in, new ClsUserGetHeaderCtx(NULL, ctx, NULL)); /* no need to pass pret, as we'll call ctx->handle_response() with correct error */
142 AioCompletion *c = librados::Rados::aio_create_completion(NULL, NULL, NULL);
143 int r = io_ctx.aio_operate(oid, c, &op, NULL);