]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: recreation of bucket returns success
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 13 Apr 2011 17:38:11 +0000 (10:38 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 13 Apr 2011 17:39:16 +0000 (10:39 -0700)
unless it was owned by a different user, at which case it
returns -EEXIST.

src/rgw/rgw_common.h
src/rgw/rgw_op.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_user.cc

index 711273226bd9576dd490bb29e1f90d295942b115..ec35b6c6074581ae7a35d2533fea2270e0690439 100644 (file)
@@ -28,6 +28,10 @@ using namespace std;
 
 using ceph::crypto::MD5;
 
+extern string rgw_root_bucket;
+
+#define RGW_ROOT_BUCKET ".rgw"
+
 #define RGW_ATTR_PREFIX  "user.rgw."
 
 #define RGW_ATTR_ACL           RGW_ATTR_PREFIX "acl"
index 82b980397e9c189099b9b9fa493595e8720211c4..7167d3f481f714423029048c5785e791665a261a 100644 (file)
@@ -302,11 +302,21 @@ done:
 
 void RGWCreateBucket::execute()
 {
-  RGWAccessControlPolicy policy;
+  RGWAccessControlPolicy policy, old_policy;
   map<string, bufferlist> attrs;
   bufferlist aclbl;
+  bool existed;
+  bool pol_ret;
 
-  bool pol_ret = policy.create_canned(s->user.user_id, s->user.display_name, s->canned_acl);
+  int r = get_policy_from_attr(&old_policy, rgw_root_bucket, s->bucket_str);
+  if (r >= 0)  {
+    if (old_policy.get_owner().get_id().compare(s->user.user_id) != 0) {
+      ret = -EEXIST;
+      goto done;
+    }
+  }
+
+  pol_ret = policy.create_canned(s->user.user_id, s->user.display_name, s->canned_acl);
   if (!pol_ret) {
     ret = -EINVAL;
     goto done;
@@ -321,11 +331,16 @@ void RGWCreateBucket::execute()
   if (ret && ret != -EEXIST)   
     goto done;
 
+  existed = (ret == -EEXIST);
+
   ret = rgwstore->create_bucket(s->user.user_id, s->bucket_str, attrs,
                                s->user.auid);
-  if (ret && ret != -EEXIST)   /* if it exists, don't remove it! */
+  if (ret && !existed && ret != -EEXIST)   /* if it exists (or previously existed), don't remove it! */
     rgw_remove_bucket(s->user.user_id, s->bucket_str);
 
+  if (ret == -EEXIST)
+    ret = 0;
+
 done:
   send_response();
 }
index 0e6b8dbe1e6a478e5a9fd9178cd6172e4e26c578..ea10287f8c09614b253e69be9c6e65b2345b5b97 100644 (file)
@@ -17,9 +17,6 @@ using namespace std;
 
 Rados *rados = NULL;
 
-#define ROOT_BUCKET ".rgw" //keep this synced to rgw_user.cc::root_bucket!
-
-static string root_bucket(ROOT_BUCKET);
 static librados::IoCtx root_pool_ctx;
 
 /** 
@@ -52,13 +49,13 @@ int RGWRados::initialize(md_config_t *conf)
  */
 int RGWRados::open_root_pool_ctx()
 {
-  int r = rados->ioctx_create(root_bucket.c_str(), root_pool_ctx);
+  int r = rados->ioctx_create(RGW_ROOT_BUCKET, root_pool_ctx);
   if (r == -ENOENT) {
-    r = rados->pool_create(root_bucket.c_str());
+    r = rados->pool_create(RGW_ROOT_BUCKET);
     if (r < 0)
       return r;
 
-    r = rados->ioctx_create(root_bucket.c_str(), root_pool_ctx);
+    r = rados->ioctx_create(RGW_ROOT_BUCKET, root_pool_ctx);
   }
 
   return r;
@@ -398,7 +395,7 @@ int RGWRados::delete_bucket(std::string& id, std::string& bucket)
     return r;
 
   librados::IoCtx io_ctx;
-  r = rados->ioctx_create(ROOT_BUCKET, io_ctx);
+  r = rados->ioctx_create(RGW_ROOT_BUCKET, io_ctx);
   if (r < 0) {
     RGW_LOG(0) << "WARNING: failed to create context in delete_bucket, bucket object leaked" << std::endl;
     return r;
@@ -449,7 +446,7 @@ int RGWRados::get_attr(std::string& bucket, std::string& obj,
 
   if (actual_obj.size() == 0) {
     actual_obj = bucket;
-    actual_bucket = root_bucket;
+    actual_bucket = rgw_root_bucket;
   }
 
   int r = rados->ioctx_create(actual_bucket.c_str(), io_ctx);
@@ -480,7 +477,7 @@ int RGWRados::set_attr(std::string& bucket, std::string& oid,
 
   if (actual_obj.size() == 0) {
     actual_obj = bucket;
-    actual_bucket = root_bucket;
+    actual_bucket = rgw_root_bucket;
   }
 
   int r = rados->ioctx_create(actual_bucket.c_str(), io_ctx);
@@ -703,11 +700,15 @@ int RGWRados::tmap_set(std::string& bucket, std::string& obj, std::string& key,
   ::encode(key, cmdbl);
   ::encode(bl, cmdbl);
 
+RGW_LOG(0) << "tmap_set bucket=" << bucket << " obj=" << obj << " key=" << key << std::endl;
+
   librados::IoCtx io_ctx;
   int r = rados->ioctx_create(bucket.c_str(), io_ctx);
   if (r < 0)
     return r;
   r = io_ctx.tmap_update(obj, cmdbl);
+RGW_LOG(0) << "tmap_set done" << std::endl;
+
   return r;
 }
 
index ba2c62b10b3a6e657339b882b6cf66313f6b8e56..f82b23741c84ce8eeaedcebe0dfbf8a89eaea3f9 100644 (file)
@@ -15,7 +15,8 @@ using namespace std;
 static string ui_bucket = USER_INFO_BUCKET_NAME;
 static string ui_email_bucket = USER_INFO_EMAIL_BUCKET_NAME;
 static string ui_openstack_bucket = USER_INFO_OPENSTACK_BUCKET_NAME;
-static string root_bucket = ".rgw"; //keep this synced to rgw_rados.cc::ROOT_BUCKET!
+
+string rgw_root_bucket = RGW_ROOT_BUCKET;
 
 #define READ_CHUNK_LEN (16 * 1024)
 /**
@@ -402,7 +403,7 @@ int rgw_delete_user(RGWUserInfo& info) {
        i != buckets.end();
        ++i) {
     string bucket_name = i->first;
-    rgwstore->delete_obj(info.user_id, root_bucket, bucket_name);
+    rgwstore->delete_obj(info.user_id, rgw_root_bucket, bucket_name);
   }
   rgwstore->delete_obj(info.user_id, ui_bucket, info.user_id);
   rgwstore->delete_obj(info.user_id, ui_email_bucket, info.user_email);