]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix bucket creation
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 28 Dec 2011 23:10:10 +0000 (15:10 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 28 Dec 2011 23:10:10 +0000 (15:10 -0800)
src/rgw/rgw_op.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_tools.cc
src/rgw/rgw_tools.h

index fd18d0933305c6438bb77c7921bb7f43934f1a52..020e2998ab3d08ec7c8d1af182cf47963c061351 100644 (file)
@@ -520,7 +520,6 @@ void RGWCreateBucket::execute()
   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);
index 69057456cf4ffe1fac46cf52547a8c23f245c877..2fa01c4480aa2f692ef7f1bc13edb4c65947e536 100644 (file)
@@ -409,18 +409,20 @@ int RGWRados::create_bucket(string& owner, rgw_bucket& bucket,
                            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;
@@ -430,6 +432,11 @@ int RGWRados::create_bucket(string& owner, rgw_bucket& bucket,
       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;
@@ -466,39 +473,36 @@ int RGWRados::create_bucket(string& owner, rgw_bucket& bucket,
     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;
index e33dcdf3e517cf090ee462dfcfc983c95a6748d5..daa1e07303105d6e53b0cbcc26c0fa3b5824d012 100644 (file)
@@ -134,7 +134,7 @@ class RGWRados  : public RGWAccess
   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) {}
index 81f89eb2eec5952e9a4058be4d2bd6563230745e..d1ae0c6dc05b42b9a0b32de7af0c51d8fb3247f8 100644 (file)
 
 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;
index c3230f859faf55220ec951904421cb5446d821af..c7c6e907d4a0a519fac9d1316aa40de1f86d5838 100644 (file)
@@ -7,7 +7,7 @@
 #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);