]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add support container and object levels of swift bulkupload 14775/head
authorJing Wenjun <jingwenjun@cmss.chinamobile.com>
Tue, 25 Apr 2017 13:44:01 +0000 (21:44 +0800)
committerJing Wenjun <jingwenjun@cmss.chinamobile.com>
Thu, 27 Apr 2017 14:56:51 +0000 (22:56 +0800)
Signed-off-by: Jing Wenjun <jingwenjun@cmss.chinamobile.com>
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest_swift.cc

index b7ee212ca492af3f20774e1d04791b06afa5ca76..b9db1608ac78d5f478741cd03032c64aa60fd6ba 100644 (file)
@@ -386,7 +386,7 @@ int rgw_build_bucket_policies(RGWRados* store, struct req_state* s)
   int ret = 0;
   rgw_obj_key obj;
   RGWUserInfo bucket_owner_info;
-  RGWObjectCtx& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx);
+  RGWObjectCtx obj_ctx(store);
 
   string bi = s->info.args.get(RGW_SYS_PARAM_PREFIX "bucket-instance");
   if (!bi.empty()) {
@@ -5559,6 +5559,27 @@ RGWBulkUploadOp::parse_path(const boost::string_ref& path)
   return boost::none;
 }
 
+std::pair<std::string, std::string>
+RGWBulkUploadOp::handle_upload_path(struct req_state *s)
+{
+  std::string bucket_path, file_prefix;
+  if (! s->init_state.url_bucket.empty()) {
+    file_prefix = bucket_path = s->init_state.url_bucket + "/";
+    if (! s->object.empty()) {
+      std::string& object_name = s->object.name;
+
+      /* As rgw_obj_key::empty() already verified emptiness of s->object.name,
+       * we can safely examine its last element. */
+      if (object_name.back() == '/') {
+        file_prefix.append(object_name);
+      } else {
+        file_prefix.append(object_name).append("/");
+      }
+    }
+  }
+  return std::make_pair(bucket_path, file_prefix);
+}
+
 int RGWBulkUploadOp::handle_dir_verify_permission()
 {
   if (s->user->max_buckets > 0) {
@@ -5933,6 +5954,11 @@ void RGWBulkUploadOp::execute()
     return;
   }
 
+  /* Handling the $UPLOAD_PATH accordingly to the Swift's Bulk middleware. See: 
+   * https://github.com/openstack/swift/blob/2.13.0/swift/common/middleware/bulk.py#L31-L41 */
+  std::string bucket_path, file_prefix;
+  std::tie(bucket_path, file_prefix) = handle_upload_path(s);
+
   auto status = rgw::tar::StatusIndicator::create();
   do {
     op_ret = stream->get_exactly(rgw::tar::BLOCK_SIZE, buffer);
@@ -5957,25 +5983,28 @@ void RGWBulkUploadOp::execute()
         case rgw::tar::FileType::NORMAL_FILE: {
           ldout(s->cct, 2) << "bulk upload: handling regular file" << dendl;
 
+          boost::string_ref filename = bucket_path.empty() ? header->get_filename() : \
+                            file_prefix + header->get_filename().to_string();
           auto body = AlignedStreamGetter(0, header->get_filesize(),
                                           rgw::tar::BLOCK_SIZE, *stream);
-          op_ret = handle_file(header->get_filename(),
+          op_ret = handle_file(filename,
                                header->get_filesize(),
                                body);
           if (! op_ret) {
             /* Only regular files counts. */
             num_created++;
           } else {
-            failures.emplace_back(op_ret, header->get_filename().to_string());
+            failures.emplace_back(op_ret, filename.to_string());
           }
           break;
         }
         case rgw::tar::FileType::DIRECTORY: {
           ldout(s->cct, 2) << "bulk upload: handling regular directory" << dendl;
 
-          op_ret = handle_dir(header->get_filename());
+          boost::string_ref dirname = bucket_path.empty() ? header->get_filename() : bucket_path;
+          op_ret = handle_dir(dirname);
           if (op_ret < 0 && op_ret != -ERR_BUCKET_EXISTS) {
-            failures.emplace_back(op_ret, header->get_filename().to_string());
+            failures.emplace_back(op_ret, dirname.to_string());
           }
           break;
         }
index 54efe2030e040a814b22952259adc950de8967cb..aa32d5dcb9121bb5015f93ce37b86927f686867b 100644 (file)
@@ -420,6 +420,9 @@ protected:
 
   boost::optional<std::pair<std::string, rgw_obj_key>>
   parse_path(const boost::string_ref& path);
+  
+  std::pair<std::string, std::string>
+  handle_upload_path(struct req_state *s);
 
   bool handle_file_verify_permission(RGWBucketInfo& binfo,
                                      std::map<std::string, ceph::bufferlist>& battrs,
index 3d4a4d5bda858f2b4e31f696a362f2df0cd6ea50..1da22b26bcf6bd029a64943c6be7496204a860c3 100644 (file)
@@ -2103,6 +2103,9 @@ RGWOp *RGWHandler_REST_Bucket_SWIFT::op_put()
   if (is_acl_op()) {
     return new RGWPutACLs_ObjStore_SWIFT;
   }
+  if(s->info.args.exists("extract-archive")) {
+    return new RGWBulkUploadOp_ObjStore_SWIFT;
+  }
   return new RGWCreateBucket_ObjStore_SWIFT;
 }
 
@@ -2148,6 +2151,9 @@ RGWOp *RGWHandler_REST_Obj_SWIFT::op_put()
   if (is_acl_op()) {
     return new RGWPutACLs_ObjStore_SWIFT;
   }
+  if(s->info.args.exists("extract-archive")) {
+    return new RGWBulkUploadOp_ObjStore_SWIFT;
+  }
   if (s->init_state.src_bucket.empty())
     return new RGWPutObj_ObjStore_SWIFT;
   else