From patchwork Wed Jul 26 14:10:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 126440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp476266vqo; Wed, 26 Jul 2023 08:21:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlFzLFoL9pcKg48HKONru2ccnrG7dKHqACbG8FcW4jKwE5ezDq3WC9eZqvzp5Xb8VwssN1m8 X-Received: by 2002:a05:6a21:9986:b0:133:bbe0:312f with SMTP id ve6-20020a056a21998600b00133bbe0312fmr2530270pzb.50.1690384895983; Wed, 26 Jul 2023 08:21:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690384895; cv=none; d=google.com; s=arc-20160816; b=EOcPK0DNc6HaCaqLBW5xT+gW3qmMSaFLvXPJ1vJt2S2eegcopn5NPmJjIzgGLw19rA DK55W5FSFKpMh3mnmqwB9zJuDNysmuVk7TDr1daGsrT+jLQrtTvs6m6ca9lQTIyG+xfa RJD0cJ898w7hgE5sky8kbtMxFm42G1K9l2yuVzFamZLn08v152kMc2hQ3JOBiKZOTlhQ iaTtH5XSILpRVpwT6lwG8kmiMbAl7f+XQUBoHz9GQoz2J/A9d6gkVlaFBNruGj+4Od4m GqTK4MBzICalneqHJKu1RNznK4rlJzXY7VgRIenieTyc/I6jSk6rrqt8ykbqVYu5uTi1 hswQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5Jek2ao2Gg23mz8Y2ufU3Ts9QQq34R72Sad2dO2kfLI=; fh=4TkUEkUtkmMzuUVnw4jjBfLQ2m58OJnBJO1eZJpOGII=; b=RdnktdhhFhY0WXcJj3qUUis3V1atSVlDwPqCbXtlmJDUCNMgc2pdWuF0alvNhXTLkw ssj4Jg5gZw/nwrrG0aPAlopjBLG6/E9U8Rc41lQgX/LjTEE6x2GLo7xIdMBJuRSuXFUK fylqets69K4iLPJ49G56wbV7i8k5uN4BdKCYWiUym0xcM05wbHEelVH/3Ma+8OyjzEN0 Ob6M9JUxlQE2e+mPb/qaKt87qN7gEzJlgsY8Ldx6ykOsnazojTzTw3o7eidjAAVMLQQX jOEh/nSLyprv4ecHqt5wVHbACxEeJeUdVEhSTBG//9GWhaJNFijsjK/AA2zjI1CcACpn Nl6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=Huw+yv96; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bw16-20020a056a00409000b00686b62a6dc4si2213378pfb.145.2023.07.26.08.21.21; Wed, 26 Jul 2023 08:21:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=Huw+yv96; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234500AbjGZOMy (ORCPT + 99 others); Wed, 26 Jul 2023 10:12:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232756AbjGZOL6 (ORCPT ); Wed, 26 Jul 2023 10:11:58 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC06D19BE for ; Wed, 26 Jul 2023 07:11:25 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 49F7542483 for ; Wed, 26 Jul 2023 14:10:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1690380655; bh=5Jek2ao2Gg23mz8Y2ufU3Ts9QQq34R72Sad2dO2kfLI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Huw+yv96Q6JnUXQUHGSgOuuUwJu0mXq2UHfgU2SpUvA+5QrXdUHTwtzhTJ8wZsdRq t6FE4aa8kil3d5Clce6Cwpljm6fncxn+4CdZ/ci2YeMrPZLYdP2aiIQJ9djntqZjZl s6JXA/9FyJeTO0ORIBTI3As4eVpvamYCNt27JPVAWZ+ac2Qm+L020757LvbThTc2tt uXeSJcR4VT783Zde79w3RHiJluz3iPgezRIAfLkMv+U1bpAaph8RWUWbCkV87A5BRP t7vPkl6jU683jNz61vtdudloWbbtepHJKDVeI2PBEEs/et1UQ5f5ANYFEnRO6RIfwS E2rgmaJHac1Xw== Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3fc00d7d62cso40675215e9.2 for ; Wed, 26 Jul 2023 07:10:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690380652; x=1690985452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Jek2ao2Gg23mz8Y2ufU3Ts9QQq34R72Sad2dO2kfLI=; b=jQRnW30kqLpL5a9d8LVVgr7rAq21ZozV4CfngGFtivVLiBXbNlevFgOx7KxrZDJvvs gab+QM7DWVFW6m8nEvTKcxqwaovT3TEsxNp+WSc5FWXnmi9VcUrpmsZgV00nOQDeaXdo 7RYBWunFPLgqO2MRwkT8p6ufPiE4BLOZ99+hpIVOtNxDairsEA2OnEgGXaS+/nMhLOSU wtO+3hXAEnXxteHOk3d//yxwGgsuscGC3HTe2SgOCJpSjkVZxcAFTlcRfMijEhoVfvMx CzTHqlvTuCMIdgD+0S1Mr5zNn/M1syVF6h6o823J8xubvlXg4/ZQ2yzphIrCSShB2OJX azTA== X-Gm-Message-State: ABy/qLY0/sRyM3xG0jW/ivD8vKBGUBQeQx8/dH+YfO4bKTlcNOv2siif AvnZdlMla49HpGonVfaeTXQnlYEkG4gisVNo1DIv+qar4WX1a09m5FS5g56QwCn261/gLNqCa/u TgGXhv9KPTt0HO/NLxbUrTUmjpemOccMKzZaaJMrmrw== X-Received: by 2002:a7b:c319:0:b0:3fb:e206:ca5f with SMTP id k25-20020a7bc319000000b003fbe206ca5fmr1487597wmj.31.1690380652184; Wed, 26 Jul 2023 07:10:52 -0700 (PDT) X-Received: by 2002:a7b:c319:0:b0:3fb:e206:ca5f with SMTP id k25-20020a7bc319000000b003fbe206ca5fmr1487585wmj.31.1690380651969; Wed, 26 Jul 2023 07:10:51 -0700 (PDT) Received: from amikhalitsyn.local (dslb-088-066-182-192.088.066.pools.vodafone-ip.de. [88.66.182.192]) by smtp.gmail.com with ESMTPSA id k14-20020a7bc30e000000b003fc02219081sm2099714wmj.33.2023.07.26.07.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 07:10:51 -0700 (PDT) From: Alexander Mikhalitsyn To: xiubli@redhat.com Cc: brauner@kernel.org, stgraber@ubuntu.com, linux-fsdevel@vger.kernel.org, Jeff Layton , Ilya Dryomov , ceph-devel@vger.kernel.org, Christian Brauner , Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v7 08/11] ceph: allow idmapped setattr inode op Date: Wed, 26 Jul 2023 16:10:23 +0200 Message-Id: <20230726141026.307690-9-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230726141026.307690-1-aleksandr.mikhalitsyn@canonical.com> References: <20230726141026.307690-1-aleksandr.mikhalitsyn@canonical.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772497032405993694 X-GMAIL-MSGID: 1772497032405993694 From: Christian Brauner Enable __ceph_setattr() to handle idmapped mounts. This is just a matter of passing down the mount's idmapping. Cc: Xiubo Li Cc: Jeff Layton Cc: Ilya Dryomov Cc: ceph-devel@vger.kernel.org Signed-off-by: Christian Brauner [ adapted to b27c82e12965 ("attr: port attribute changes to new types") ] Signed-off-by: Alexander Mikhalitsyn --- v4: - introduced fsuid/fsgid local variables v3: - reworked as Christian suggested here: https://lore.kernel.org/lkml/20230602-vorzeichen-praktikum-f17931692301@brauner/ --- fs/ceph/inode.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 6c4cc009d819..0a8cc0327f85 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -2553,33 +2553,37 @@ int __ceph_setattr(struct mnt_idmap *idmap, struct inode *inode, #endif /* CONFIG_FS_ENCRYPTION */ if (ia_valid & ATTR_UID) { + kuid_t fsuid = from_vfsuid(idmap, i_user_ns(inode), attr->ia_vfsuid); + doutc(cl, "%p %llx.%llx uid %d -> %d\n", inode, ceph_vinop(inode), from_kuid(&init_user_ns, inode->i_uid), from_kuid(&init_user_ns, attr->ia_uid)); if (issued & CEPH_CAP_AUTH_EXCL) { - inode->i_uid = attr->ia_uid; + inode->i_uid = fsuid; dirtied |= CEPH_CAP_AUTH_EXCL; } else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 || - !uid_eq(attr->ia_uid, inode->i_uid)) { + !uid_eq(fsuid, inode->i_uid)) { req->r_args.setattr.uid = cpu_to_le32( - from_kuid(&init_user_ns, attr->ia_uid)); + from_kuid(&init_user_ns, fsuid)); mask |= CEPH_SETATTR_UID; release |= CEPH_CAP_AUTH_SHARED; } } if (ia_valid & ATTR_GID) { + kgid_t fsgid = from_vfsgid(idmap, i_user_ns(inode), attr->ia_vfsgid); + doutc(cl, "%p %llx.%llx gid %d -> %d\n", inode, ceph_vinop(inode), from_kgid(&init_user_ns, inode->i_gid), from_kgid(&init_user_ns, attr->ia_gid)); if (issued & CEPH_CAP_AUTH_EXCL) { - inode->i_gid = attr->ia_gid; + inode->i_gid = fsgid; dirtied |= CEPH_CAP_AUTH_EXCL; } else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 || - !gid_eq(attr->ia_gid, inode->i_gid)) { + !gid_eq(fsgid, inode->i_gid)) { req->r_args.setattr.gid = cpu_to_le32( - from_kgid(&init_user_ns, attr->ia_gid)); + from_kgid(&init_user_ns, fsgid)); mask |= CEPH_SETATTR_GID; release |= CEPH_CAP_AUTH_SHARED; } @@ -2807,7 +2811,7 @@ int ceph_setattr(struct mnt_idmap *idmap, struct dentry *dentry, if (err) return err; - err = setattr_prepare(&nop_mnt_idmap, dentry, attr); + err = setattr_prepare(idmap, dentry, attr); if (err != 0) return err; @@ -2822,7 +2826,7 @@ int ceph_setattr(struct mnt_idmap *idmap, struct dentry *dentry, err = __ceph_setattr(idmap, inode, attr, NULL); if (err >= 0 && (attr->ia_valid & ATTR_MODE)) - err = posix_acl_chmod(&nop_mnt_idmap, dentry, attr->ia_mode); + err = posix_acl_chmod(idmap, dentry, attr->ia_mode); return err; }