]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add support for metadata upload during PUT on Swift container.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 9 Mar 2016 16:12:37 +0000 (17:12 +0100)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Sun, 13 Mar 2016 02:46:02 +0000 (03:46 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_rest_swift.h

index b1e943fdbd01f157d5037091d961c32182072caa..6475f4bbdcd4298de75ee3ec2b1c5e1668c4d11f 100644 (file)
@@ -1970,8 +1970,13 @@ void RGWCreateBucket::execute()
     }
   }
 
-  policy.encode(aclbl);
+  if (need_metadata_upload()) {
+    rgw_get_request_metadata(s->cct, s->info, attrs, false);
+    prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs, rmattrs);
+    populate_with_generic_attrs(s, attrs);
+  }
 
+  policy.encode(aclbl);
   attrs[RGW_ATTR_ACL] = aclbl;
 
   if (has_cors) {
@@ -2020,6 +2025,47 @@ void RGWCreateBucket::execute()
   } else if (op_ret == -EEXIST || (op_ret == 0 && existed)) {
     op_ret = -ERR_BUCKET_EXISTS;
   }
+
+  if (need_metadata_upload() && existed) {
+    /* OK, it looks we lost race with another request. As it's required to
+     * handle metadata fusion and upload, the whole operation becomes very
+     * similar in nature to PutMetadataBucket. However, as the attrs may
+     * changed in the meantime, we have to refresh. */
+    short tries = 0;
+    do {
+      RGWObjectCtx& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx);
+      RGWBucketInfo binfo;
+      map<string, bufferlist> battrs;
+
+      op_ret = store->get_bucket_info(obj_ctx, s->bucket_tenant, s->bucket_name,
+                                      binfo, nullptr, &battrs);
+      if (op_ret < 0) {
+        return;
+      } else if (binfo.owner.compare(s->user->user_id) != 0) {
+        /* New bucket doesn't belong to the account we're operating on. */
+        op_ret = -EEXIST;
+        return;
+      } else {
+        s->bucket_info = binfo;
+        s->bucket_attrs = battrs;
+      }
+
+      attrs.clear();
+      rmattrs.clear();
+
+      rgw_get_request_metadata(s->cct, s->info, attrs, false);
+      prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs, rmattrs);
+      populate_with_generic_attrs(s, attrs);
+
+      op_ret = rgw_bucket_set_attrs(store, s->bucket_info, attrs,
+                                    &s->bucket_info.objv_tracker);
+    } while (op_ret == -ECANCELED && tries++ < 20);
+
+    /* Restore the proper return code. */
+    if (op_ret >= 0) {
+      op_ret = -ERR_BUCKET_EXISTS;
+    }
+  }
 }
 
 int RGWDeleteBucket::verify_permission()
index 9849b431d3c75a2c7cd16d182a877fb01f854adf..61004aee281fd06055cb7b4d2e27ab35bc54ac71 100644 (file)
@@ -538,9 +538,12 @@ protected:
   bool has_cors;
   RGWCORSConfiguration cors_config;
   string swift_ver_location;
+  set<string> rmattr_names;
 
   bufferlist in_data;
 
+  virtual bool need_metadata_upload() const { return false; }
+
 public:
   RGWCreateBucket() : has_cors(false) {}
 
index 0b993114f4b8f448382c620e92d5271c9e48738a..76e01e4999acd23fce12e4b5f84d0db02e2fefe6 100644 (file)
@@ -517,6 +517,8 @@ int RGWCreateBucket_ObjStore_SWIFT::get_params()
   }
 
   location_constraint = store->get_zonegroup().api_name;
+  get_rmattrs_from_headers(s, CONT_PUT_ATTR_PREFIX,
+                           CONT_REMOVE_ATTR_PREFIX, rmattr_names);
   placement_rule = s->info.env->get("HTTP_X_STORAGE_POLICY", "");
 
   if (s->cct->_conf->rgw_swift_versioning_enabled) {
index 5c45d26950e361b42c4e4ff53d9f71ba0005db08..bbef15bf9b4953d203838f32e79aa9e8ae6b59d1 100644 (file)
@@ -71,6 +71,8 @@ public:
 };
 
 class RGWCreateBucket_ObjStore_SWIFT : public RGWCreateBucket_ObjStore {
+protected:
+  bool need_metadata_upload() const override { return true; }
 public:
   RGWCreateBucket_ObjStore_SWIFT() {}
   ~RGWCreateBucket_ObjStore_SWIFT() {}