mirror of
https://github.com/ceph/ceph
synced 2025-01-20 01:51:34 +00:00
rgw: move bucket add / remove to new user objclass
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
This commit is contained in:
parent
23aa65f62a
commit
c7b4d00815
@ -83,20 +83,17 @@ int rgw_link_bucket(RGWRados *store, string user_id, rgw_bucket& bucket, time_t
|
||||
int ret;
|
||||
string& bucket_name = bucket.name;
|
||||
|
||||
bufferlist bl;
|
||||
|
||||
RGWBucketEnt new_bucket;
|
||||
cls_user_bucket_entry new_bucket;
|
||||
|
||||
RGWBucketEntryPoint ep;
|
||||
RGWObjVersionTracker ot;
|
||||
|
||||
new_bucket.bucket = bucket;
|
||||
bucket.convert(&new_bucket.bucket);
|
||||
new_bucket.size = 0;
|
||||
if (!creation_time)
|
||||
time(&new_bucket.creation_time);
|
||||
else
|
||||
new_bucket.creation_time = creation_time;
|
||||
::encode(new_bucket, bl);
|
||||
|
||||
map<string, bufferlist> attrs;
|
||||
|
||||
@ -114,7 +111,7 @@ int rgw_link_bucket(RGWRados *store, string user_id, rgw_bucket& bucket, time_t
|
||||
rgw_get_buckets_obj(user_id, buckets_obj_id);
|
||||
|
||||
rgw_obj obj(store->zone.user_uid_pool, buckets_obj_id);
|
||||
ret = store->omap_set(obj, bucket_name, bl);
|
||||
ret = store->cls_user_add_bucket(obj, new_bucket);
|
||||
if (ret < 0) {
|
||||
ldout(store->ctx(), 0) << "ERROR: error adding bucket to directory: "
|
||||
<< cpp_strerror(-ret)<< dendl;
|
||||
@ -148,8 +145,10 @@ int rgw_unlink_bucket(RGWRados *store, string user_id, const string& bucket_name
|
||||
string buckets_obj_id;
|
||||
rgw_get_buckets_obj(user_id, buckets_obj_id);
|
||||
|
||||
cls_user_bucket bucket;
|
||||
bucket.name = bucket_name;
|
||||
rgw_obj obj(store->zone.user_uid_pool, buckets_obj_id);
|
||||
ret = store->omap_del(obj, bucket_name);
|
||||
ret = store->cls_user_remove_bucket(obj, bucket);
|
||||
if (ret < 0) {
|
||||
ldout(store->ctx(), 0) << "ERROR: error removing bucket from directory: "
|
||||
<< cpp_strerror(-ret)<< dendl;
|
||||
|
@ -576,6 +576,14 @@ struct rgw_bucket {
|
||||
rgw_bucket(const char *n, const char *dp, const char *ip, const char *m, const char *id, const char *h) :
|
||||
name(n), data_pool(dp), index_pool(ip), marker(m), bucket_id(id) {}
|
||||
|
||||
void convert(cls_user_bucket *b) {
|
||||
b->name = name;
|
||||
b->data_pool = data_pool;
|
||||
b->index_pool = index_pool;
|
||||
b->marker = marker;
|
||||
b->bucket_id = bucket_id;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
name = "";
|
||||
data_pool = "";
|
||||
@ -917,6 +925,14 @@ struct RGWBucketEnt {
|
||||
count = e.count;
|
||||
}
|
||||
|
||||
void convert(cls_user_bucket_entry *b) {
|
||||
bucket.convert(&b->bucket);
|
||||
b->size = size;
|
||||
b->size_rounded = size_rounded;
|
||||
b->creation_time = creation_time;
|
||||
b->count = count;
|
||||
}
|
||||
|
||||
void encode(bufferlist& bl) const {
|
||||
ENCODE_START(5, 5, bl);
|
||||
uint64_t s = size;
|
||||
|
@ -5611,6 +5611,54 @@ int RGWRados::cls_user_list_buckets(rgw_obj& obj,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RGWRados::cls_user_update_buckets(rgw_obj& obj, list<cls_user_bucket_entry>& entries)
|
||||
{
|
||||
bufferlist bl;
|
||||
librados::IoCtx io_ctx;
|
||||
rgw_bucket bucket;
|
||||
std::string oid, key;
|
||||
get_obj_bucket_and_oid_key(obj, bucket, oid, key);
|
||||
int r = open_bucket_data_ctx(bucket, io_ctx);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
librados::ObjectWriteOperation op;
|
||||
cls_user_set_buckets(op, entries);
|
||||
r = io_ctx.operate(oid, &op);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RGWRados::cls_user_add_bucket(rgw_obj& obj, const cls_user_bucket_entry& entry)
|
||||
{
|
||||
list<cls_user_bucket_entry> l;
|
||||
l.push_back(entry);
|
||||
|
||||
return cls_user_update_buckets(obj, l);
|
||||
}
|
||||
|
||||
int RGWRados::cls_user_remove_bucket(rgw_obj& obj, const cls_user_bucket& bucket)
|
||||
{
|
||||
bufferlist bl;
|
||||
librados::IoCtx io_ctx;
|
||||
rgw_bucket b;
|
||||
std::string oid, key;
|
||||
get_obj_bucket_and_oid_key(obj, b, oid, key);
|
||||
int r = open_bucket_data_ctx(b, io_ctx);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
librados::ObjectWriteOperation op;
|
||||
::cls_user_remove_bucket(op, bucket);
|
||||
r = io_ctx.operate(oid, &op);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RGWRados::check_quota(rgw_bucket& bucket, RGWQuotaInfo& quota_info, uint64_t obj_size)
|
||||
{
|
||||
return quota_handler->check_quota(bucket, quota_info, 1, obj_size);
|
||||
|
@ -1414,6 +1414,10 @@ public:
|
||||
const string& in_marker, int max_entries,
|
||||
list<cls_user_bucket_entry>& entries,
|
||||
string *out_marker, bool *truncated);
|
||||
int cls_user_add_bucket(rgw_obj& obj, const cls_user_bucket_entry& entry);
|
||||
int cls_user_update_buckets(rgw_obj& obj, list<cls_user_bucket_entry>& entries);
|
||||
int cls_user_add_bucket(rgw_obj& obj, list<cls_user_bucket_entry>& entries);
|
||||
int cls_user_remove_bucket(rgw_obj& obj, const cls_user_bucket& bucket);
|
||||
|
||||
int check_quota(rgw_bucket& bucket, RGWQuotaInfo& quota_info, uint64_t obj_size);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user