From: Casey Bodley Date: Tue, 6 Aug 2019 14:21:48 +0000 (-0400) Subject: rgw: simplify bucket chown X-Git-Tag: v15.1.0~1913^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4375204a4a2b8627c5a2f3850632544b62aebfc9;p=ceph.git rgw: simplify bucket chown removes unused 'attrs' argument, and takes uid + display name instead of RGWUserInfo Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 0488e7af246c..b67617b5708a 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -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& 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 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 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& 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); } diff --git a/src/rgw/rgw_bucket.h b/src/rgw/rgw_bucket.h index 2f27674a3040..3bde36dda15c 100644 --- a/src/rgw/rgw_bucket.h +++ b/src/rgw/rgw_bucket.h @@ -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& 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& attrs, std::string *err_msg = NULL); - int chown(RGWBucketAdminOpState& op_state, map& 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); diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 59664fb80611..4c98b8174183 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -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;