From 13d480300aff5637dd216624a9913b890c5c1e14 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Tue, 4 Oct 2011 10:52:22 -0700 Subject: [PATCH] rgw: remove rgw_create_bucket. Push all its extra functionality down into RGWRados::create_bucket. Convert callers to the different interface (there's no reason to pass in the bucket name apart from the bucket, and all callers know if they're using a system bucket or not). Signed-off-by: Greg Farnum --- src/rgw/rgw_bucket.cc | 32 -------------------------------- src/rgw/rgw_log.cc | 4 ++-- src/rgw/rgw_op.cc | 9 +++------ src/rgw/rgw_rados.cc | 18 +++++++++++++++++- src/rgw/rgw_tools.cc | 2 +- 5 files changed, 23 insertions(+), 42 deletions(-) diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 2dd069e7c2252..03a8bd0357f1d 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -68,35 +68,3 @@ int rgw_get_bucket_info_id(uint64_t bucket_id, RGWBucketInfo& info) return rgw_get_bucket_info(bucket_string, info); } - -int rgw_create_bucket(std::string& id, string& bucket_name, rgw_bucket& bucket, - map& attrs, bool exclusive, uint64_t auid) -{ - /* system bucket name? */ - if (bucket_name[0] == '.') { - bucket.name = bucket_name; - bucket.pool = bucket_name; - return rgwstore->create_bucket(id, bucket, attrs, true, exclusive, auid); - } - - int ret = rgwstore->select_bucket_placement(bucket_name, bucket); - if (ret < 0) - return ret; - - ret = rgwstore->create_bucket(id, bucket, attrs, false, exclusive, auid); - - if (ret < 0) - return ret; - - RGWBucketInfo info; - info.bucket = bucket; - info.owner = id; - ret = rgw_store_bucket_info(info); - if (ret < 0) { - RGW_LOG(0) << "failed to store bucket info, removing bucket" << dendl; - rgwstore->delete_bucket(id, bucket, true); - return ret; - } - - return 0; -} diff --git a/src/rgw/rgw_log.cc b/src/rgw/rgw_log.cc index 8702733f2e0ef..be03794ef3c3f 100644 --- a/src/rgw/rgw_log.cc +++ b/src/rgw/rgw_log.cc @@ -93,7 +93,7 @@ int rgw_log_op(struct req_state *s) if (ret == -ENOENT) { string id; map attrs; - ret = rgw_create_bucket(id, log_bucket.name, log_bucket, attrs); + ret = rgwstore->create_bucket(id, log_bucket, attrs, true); if (ret < 0) goto done; // retry @@ -132,7 +132,7 @@ int rgw_log_intent(struct req_state *s, rgw_obj& obj, RGWIntentEvent intent) if (ret == -ENOENT) { string id; map attrs; - ret = rgw_create_bucket(id, intent_log_bucket.name, intent_log_bucket, attrs); + ret = rgwstore->create_bucket(id, intent_log_bucket, attrs, true); if (ret < 0) goto done; ret = rgwstore->append_async(log_obj, bl.length(), bl); diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index ea50048eee962..0edd2fc389c46 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -466,12 +466,9 @@ void RGWCreateBucket::execute() attrs[RGW_ATTR_ACL] = aclbl; - ret = rgwstore->select_bucket_placement(s->bucket_name_str, s->bucket); - if (ret < 0) - goto done; - - ret = rgw_create_bucket(s->user.user_id, s->bucket_name_str, s->bucket, attrs, true, - s->user.auid); + s->bucket.name = s->bucket_name_str; + ret = rgwstore->create_bucket(s->user.user_id, s->bucket, attrs, false, + true, s->user.auid); /* continue if EEXIST and create_bucket will fail below. this way we can recover * from a partial create by retrying it. */ RGW_LOG(0) << "rgw_create_bucket returned ret=" << ret << " bucket=" << s->bucket << dendl; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 2cc41bc0e3171..8daf13b35b373 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -335,9 +335,15 @@ int RGWRados::create_bucket(std::string& id, rgw_bucket& bucket, ret = rados->pool_create(bucket.pool.c_str(), auid); if (ret == -EEXIST) ret = 0; - if (ret < 0) + if (ret < 0) { root_pool_ctx.remove(bucket.name.c_str()); + } else { + bucket.pool = bucket.name; + } } else { + ret = select_bucket_placement(bucket.name, bucket); + if (ret < 0) + return ret; librados::IoCtx io_ctx; // context for new bucket int r = open_bucket_ctx(bucket, io_ctx); @@ -375,6 +381,16 @@ int RGWRados::create_bucket(std::string& id, rgw_bucket& bucket, r = cls_rgw_init_index(bucket, dir_oid); if (r < 0) return r; + + RGWBucketInfo info; + info.bucket = bucket; + info.owner = id; + ret = rgw_store_bucket_info(info); + if (ret < 0) { + RGW_LOG(0) << "failed to store bucket info, removing bucket" << dendl; + delete_bucket(id, bucket, true); + return ret; + } } } diff --git a/src/rgw/rgw_tools.cc b/src/rgw/rgw_tools.cc index 639c0a9bf1ec5..5092a36957c24 100644 --- a/src/rgw/rgw_tools.cc +++ b/src/rgw/rgw_tools.cc @@ -20,7 +20,7 @@ int rgw_put_obj(string& uid, rgw_bucket& bucket, string& oid, const char *data, int ret = rgwstore->put_obj(NULL, uid, obj, data, size, NULL, attrs); if (ret == -ENOENT) { - ret = rgw_create_bucket(uid, bucket.name, bucket, attrs); + ret = rgwstore->create_bucket(uid, bucket, attrs, true); //all callers are using system buckets if (ret >= 0) ret = rgwstore->put_obj(NULL, uid, obj, data, size, NULL, attrs); } -- 2.39.5