bool pol_ret;
rgw_obj obj(rgw_root_bucket, s->bucket_name_str);
-
s->bucket_owner = s->user.user_id;
int r = get_policy_from_attr(s->obj_ctx, &old_policy, obj);
bool system_bucket,
bool exclusive, uint64_t auid)
{
- librados::ObjectWriteOperation op;
- op.create(exclusive);
+ int ret = 0;
- for (map<string, bufferlist>::iterator iter = attrs.begin(); iter != attrs.end(); ++iter)
- op.setxattr(iter->first.c_str(), iter->second);
+ if (system_bucket) {
+ librados::ObjectWriteOperation op;
+ op.create(exclusive);
- bufferlist outbl;
- int ret = root_pool_ctx.operate(bucket.name, &op);
- if (ret < 0)
- return ret;
+ for (map<string, bufferlist>::iterator iter = attrs.begin(); iter != attrs.end(); ++iter)
+ op.setxattr(iter->first.c_str(), iter->second);
+
+ bufferlist outbl;
+ ret = root_pool_ctx.operate(bucket.name, &op);
+ if (ret < 0)
+ return ret;
- if (system_bucket) {
ret = rados->pool_create(bucket.pool.c_str(), auid);
if (ret == -EEXIST)
ret = 0;
bucket.pool = bucket.name;
}
} else {
+ if (ret < 0) {
+ dout(0) << "failed to store bucket info" << dendl;
+ return ret;
+ }
+
ret = select_bucket_placement(bucket.name, bucket);
if (ret < 0)
return ret;
if (r < 0 && r != -EEXIST)
return r;
+ RGWBucketInfo info;
+ info.bucket = bucket;
+ info.owner = owner;
+ ret = store_bucket_info(info, &attrs, exclusive);
+ if (ret == -EEXIST)
+ return ret;
+
if (r != -EEXIST) {
r = cls_rgw_init_index(bucket, dir_oid);
if (r < 0)
return r;
-
- RGWBucketInfo info;
- info.bucket = bucket;
- info.owner = owner;
- ret = store_bucket_info(info, exclusive);
- if (ret < 0) {
- dout(0) << "failed to store bucket info, removing bucket" << dendl;
- delete_bucket(bucket);
- return ret;
- }
}
}
return ret;
}
-int RGWRados::store_bucket_info(RGWBucketInfo& info, bool exclusive)
+int RGWRados::store_bucket_info(RGWBucketInfo& info, map<string, bufferlist> *pattrs, bool exclusive)
{
bufferlist bl;
::encode(info, bl);
- int ret = rgw_put_obj(info.owner, pi_buckets_rados, info.bucket.name, bl.c_str(), bl.length(), exclusive);
+ int ret = rgw_put_obj(info.owner, pi_buckets_rados, info.bucket.name, bl.c_str(), bl.length(), exclusive, pattrs);
if (ret < 0)
return ret;
char bucket_char[16];
snprintf(bucket_char, sizeof(bucket_char), ".%lld", (long long unsigned)info.bucket.bucket_id);
string bucket_id_string(bucket_char);
- ret = rgw_put_obj(info.owner, pi_buckets_rados, bucket_id_string, bl.c_str(), bl.length(), false);
+ ret = rgw_put_obj(info.owner, pi_buckets_rados, bucket_id_string, bl.c_str(), bl.length(), false, pattrs);
if (ret < 0) {
dout(0) << "ERROR: failed to store " << pi_buckets_rados << ":" << bucket_id_string << " ret=" << ret << dendl;
return ret;
int delete_obj_impl(void *ctx, rgw_obj& src_obj, bool sync);
int select_bucket_placement(std::string& bucket_name, rgw_bucket& bucket);
- int store_bucket_info(RGWBucketInfo& info, bool exclusive);
+ int store_bucket_info(RGWBucketInfo& info, map<string, bufferlist> *pattrs, bool exclusive);
public:
RGWRados() : lock("rados_timer_lock"), timer(NULL), watcher(NULL), watch_handle(0) {}
static map<string, string> ext_mime_map;
-int rgw_put_obj(string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size, bool exclusive)
+int rgw_put_obj(string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size, bool exclusive, map<string, bufferlist> *pattrs)
{
- map<string,bufferlist> attrs;
+ map<string,bufferlist> no_attrs;
+ if (!pattrs)
+ pattrs = &no_attrs;
rgw_obj obj(bucket, oid);
- int ret = rgwstore->put_obj(NULL, obj, data, size, exclusive, NULL, attrs);
+ int ret = rgwstore->put_obj(NULL, obj, data, size, exclusive, NULL, *pattrs);
if (ret == -ENOENT) {
- ret = rgwstore->create_bucket(uid, bucket, attrs, true); //all callers are using system buckets
+ ret = rgwstore->create_bucket(uid, bucket, no_attrs, true); //all callers are using system buckets
if (ret >= 0)
- ret = rgwstore->put_obj(NULL, obj, data, size, exclusive, NULL, attrs);
+ ret = rgwstore->put_obj(NULL, obj, data, size, exclusive, NULL, *pattrs);
}
return ret;
#include "rgw_common.h"
-int rgw_put_obj(string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size, bool exclusive);
+int rgw_put_obj(string& uid, rgw_bucket& bucket, string& oid, const char *data, size_t size, bool exclusive, map<string, bufferlist> *pattrs = NULL);
int rgw_get_obj(void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl);
int rgw_tools_init(CephContext *cct);