]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: simplify bucket chown
authorCasey Bodley <cbodley@redhat.com>
Tue, 6 Aug 2019 14:21:48 +0000 (10:21 -0400)
committerCasey Bodley <cbodley@redhat.com>
Wed, 7 Aug 2019 20:25:12 +0000 (16:25 -0400)
removes unused 'attrs' argument, and takes uid + display name instead
of RGWUserInfo

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_user.cc

index 0488e7af246c1a12b875865a33c1b11f4b7a8000..b67617b5708a6d3ec0e873808eb934dab41afeaf 100644 (file)
@@ -222,7 +222,9 @@ int rgw_set_bucket_acl(RGWRados* store, ACLOwner& owner, rgw_bucket& bucket, RGW
   return 0;
 }
 
-int rgw_bucket_chown(RGWRados* const store, RGWUserInfo& user_info, RGWBucketInfo& bucket_info, const string& marker, map<string, bufferlist>& attrs)
+int rgw_bucket_chown(RGWRados* const store, RGWBucketInfo& bucket_info,
+                     const rgw_user& uid, const std::string& display_name,
+                     const string& marker)
 {
   RGWObjectCtx obj_ctx(store);
   std::vector<rgw_bucket_dir_entry> objs;
@@ -258,6 +260,7 @@ int rgw_bucket_chown(RGWRados* const store, RGWUserInfo& user_info, RGWBucketInf
         RGWRados::Object op_target(store, bucket_info, obj_ctx, r_obj);
         RGWRados::Object::Read read_op(&op_target);
 
+        map<string, bufferlist> attrs;
         read_op.params.attrs = &attrs;
         ret = read_op.prepare(null_yield);
         if (ret < 0){
@@ -288,12 +291,12 @@ int rgw_bucket_chown(RGWRados* const store, RGWUserInfo& user_info, RGWBucketInf
 
           //Create a grant and add grant
           ACLGrant grant;
-          grant.set_canon(bucket_info.owner, user_info.display_name, RGW_PERM_FULL_CONTROL);
+          grant.set_canon(bucket_info.owner, display_name, RGW_PERM_FULL_CONTROL);
           acl.add_grant(&grant);
 
           //Update the ACL owner to the new user
-          owner.set_id(bucket_info.owner);
-          owner.set_name(user_info.display_name);
+          owner.set_id(uid);
+          owner.set_name(display_name);
           policy.set_owner(owner);
 
           bl.clear();
@@ -1099,31 +1102,17 @@ int RGWBucket::link(RGWBucketAdminOpState& op_state,
   return 0;
 }
 
-int RGWBucket::chown(RGWBucketAdminOpState& op_state,
-       map<string, bufferlist>& attrs, const string& marker, std::string *err_msg)
+int RGWBucket::chown(RGWBucketAdminOpState& op_state, const string& marker, std::string *err_msg)
 {
-  //after bucket link
-  rgw_bucket& bucket = op_state.get_bucket();
-  tenant = bucket.tenant;
-  bucket_name = bucket.name;
-
-  RGWBucketInfo bucket_info;
-  RGWSysObjectCtx sys_ctx = store->svc.sysobj->init_obj_ctx();
-
-  int ret = store->get_bucket_info(sys_ctx, tenant, bucket_name, bucket_info, NULL, null_yield, &attrs);
-  if (ret < 0) {
-    set_err_msg(err_msg, "bucket info failed: tenant: " + tenant + "bucket_name: " + bucket_name + " " + cpp_strerror(-ret));
-    return ret;
-  }
-
   RGWUserInfo user_info;
-  ret = rgw_get_user_info_by_uid(store, bucket_info.owner, user_info);
+  int ret = rgw_get_user_info_by_uid(store, bucket_info.owner, user_info);
   if (ret < 0) {
     set_err_msg(err_msg, "user info failed: " + cpp_strerror(-ret));
     return ret;
   }
 
-  ret = rgw_bucket_chown(store, user_info, bucket_info, marker, attrs);
+  ret = rgw_bucket_chown(store, bucket_info, user_info.user_id,
+                         user_info.display_name, marker);
   if (ret < 0) {
     set_err_msg(err_msg, "Failed to change object ownership" + cpp_strerror(-ret));
   }
@@ -1584,7 +1573,7 @@ int RGWBucketAdminOp::chown(RGWRados *store, RGWBucketAdminOpState& op_state, co
   if (ret < 0)
     return ret;
 
-  return bucket.chown(op_state, attrs, marker, err);
+  return bucket.chown(op_state, marker, err);
 
 }
 
index 2f27674a3040772f4da6614551c4e3b3958ffdf4..3bde36dda15cde5b4db546feb4bc20ee88fdc79a 100644 (file)
@@ -215,8 +215,9 @@ extern int rgw_link_bucket(RGWRados* store,
                            rgw_ep_info *pinfo = nullptr);
 extern int rgw_unlink_bucket(RGWRados *store, const rgw_user& user_id,
                              const string& tenant_name, const string& bucket_name, bool update_entrypoint = true);
-extern int rgw_bucket_chown(RGWRados* const store, RGWUserInfo& user_info, RGWBucketInfo& bucket_info,
-                             const string& marker, map<string, bufferlist>& attrs);
+extern int rgw_bucket_chown(RGWRados* const store, RGWBucketInfo& bucket_info,
+                            const rgw_user& uid, const std::string& display_name,
+                            const string& marker);
 extern int rgw_set_bucket_acl(RGWRados* store, ACLOwner& owner, rgw_bucket& bucket,
                               RGWBucketInfo& bucket_info, bufferlist& bl);
 extern int rgw_remove_object(RGWRados *store, const RGWBucketInfo& bucket_info, const rgw_bucket& bucket, rgw_obj_key& key);
@@ -346,7 +347,7 @@ public:
   int remove(RGWBucketAdminOpState& op_state, optional_yield y, bool bypass_gc = false, bool keep_index_consistent = true, std::string *err_msg = NULL);
   int link(RGWBucketAdminOpState& op_state, map<string, bufferlist>& attrs,
        std::string *err_msg = NULL);
-  int chown(RGWBucketAdminOpState& op_state,  map<string, bufferlist>& attrs, const string& marker, std::string *err_msg = NULL);
+  int chown(RGWBucketAdminOpState& op_state, const string& marker, std::string *err_msg = NULL);
   int unlink(RGWBucketAdminOpState& op_state, std::string *err_msg = NULL);
   int set_quota(RGWBucketAdminOpState& op_state, std::string *err_msg = NULL);
 
index 59664fb80611652b5c3444a031857acc65177f6f..4c98b81741837d58885912749d662bc40f1bc963 100644 (file)
@@ -2071,7 +2071,8 @@ int RGWUser::execute_user_rename(RGWUserAdminOpState& op_state, std::string *err
         return ret;
       }
 
-      ret = rgw_bucket_chown(store, user_info, new_bucket_info, obj_marker, attrs);
+      ret = rgw_bucket_chown(store, new_bucket_info, uid,
+                             old_user_info.display_name, obj_marker);
       if (ret < 0) {
         set_err_msg(err_msg, "failed to run bucket chown" + cpp_strerror(-ret));
         return ret;