Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp945842rwd; Wed, 7 Jun 2023 08:55:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5uuAbYl7mbNj+5hPfHDq6GmRJ+SZuoA7F3xjEYvHZ0CzQya7Pr4NcW0ZFSwEwTHKOOvXV0 X-Received: by 2002:a05:6a20:a39e:b0:110:f65a:13fb with SMTP id w30-20020a056a20a39e00b00110f65a13fbmr1458709pzk.15.1686153353874; Wed, 07 Jun 2023 08:55:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686153353; cv=none; d=google.com; s=arc-20160816; b=N8ZwHHuGYuqKEj6fKkdIiRY8EZkRGYnT1XW27wIVyHPd+8e/kKCA9FOFOO6cEixPz4 hVwy9TBsZAnbvSA41uXumcnQR9wvk6mhoSQKKHgv+o2KDf30Ma1amQ0kTjFW7UqaUjnZ 9L7m2ZKMDJwUSoeHTBYCaPQVqFMrisvMVwdiMBHBQeKXtauJK1FuPRfw6U/KzrAD2kIy LM4xTC6Rc3XNVfPW7y1J5H1QCQTKgQhn6lBrrhbTRXOg0El/lNmgDdhirIx4yyE9irWM Ch3Y08mMuH/rIX69UhJFTJSGHgp1xtysgxGxxnJsyu+cw0ZGaTR1WSyk1dCZU5QDLQME +8TA== 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=aP80D7IJtF5T0WH6ImgNwtx1y7/GP3UA0si/dTzxF1Q=; b=VTk3/dDRFWboSbq3nKruZ96kmj1v7NX+4UIwXen7yYxyflMdD+4tTF2LR/qqlFVywv tyIwlXl7kX05Asy3+vh0HQwMrxXZfYLeUavpHmoG50Natku6wWiR02OG++Xc+kshQYTt j76IWGvMNNN835dcQfM70f9rgQVkF9JDbEGF3EY0cDRBdGKMVX0LtyGGf1fgXKSDrht0 xHaa2SR6D2BZPAMKdUpSI+gXWQKIfPpx7RMEblKI7ykYQt2y3igVnc9qAqw/gHrg706K jZLEUsBeWV4P6mYvuGT52+s07/ua52d99fTQdgjd0DAuKsUHXprNO3U4KLUj4lpGJCvO 2roA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=mRi3m18Q; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w191-20020a6382c8000000b005132342a587si8974024pgd.610.2023.06.07.08.55.37; Wed, 07 Jun 2023 08:55:53 -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=mRi3m18Q; 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 S235631AbjFGPWy (ORCPT + 99 others); Wed, 7 Jun 2023 11:22:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241432AbjFGPWP (ORCPT ); Wed, 7 Jun 2023 11:22:15 -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 6F8EF1FDF for ; Wed, 7 Jun 2023 08:21:44 -0700 (PDT) Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (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 B7EA13F16E for ; Wed, 7 Jun 2023 15:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1686151301; bh=aP80D7IJtF5T0WH6ImgNwtx1y7/GP3UA0si/dTzxF1Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mRi3m18Q76CrGvI81VPbZaBnwTFBqw3xeNS+sziZs+jRKr4zbJ/dNH9XmkaXAMMRw 9LjNuNMSbx5DqsqGjx+scbr3Vu/YHYwKCCMua5R4vGIZcYxTaaWuuMpDkBeRVTnUYn ZtjwnLY4PTDl9j2GaC4HcHekM3KMJD7iB3x5x8/q/eZs0UjvpW4iSp4l/CxJZvtz3c FPRYgYzr5ikCpaaVs1sPksb4+LvGaRJV95tHOvd3DwrHJ1XSupltQd78AUI8Imvq3D 26CcemUj6SzYj5jS6P2qs2hRIF9Rmz+Qf6rwJ1B3jJwnP1SLgcak3iTz8hlp78CNg/ olkJe8tt0w8Qg== Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-514abe67064so1067271a12.0 for ; Wed, 07 Jun 2023 08:21:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686151301; x=1688743301; 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=aP80D7IJtF5T0WH6ImgNwtx1y7/GP3UA0si/dTzxF1Q=; b=Xncw1fQA8b3BFHIGk7Hr8xUvwopXVQEqNmkLzi1BPbn+AYbxdc9pendZv1gE+ULQ7a t1X+C3MbeHA+awaWA8u7kcHoYbw94v9wq5dF+7Qyx7gNMhFNyaClTifab7XlPwphRS9q bGSf0UhJOHpFFJsuUMIkAm0wO957L6c6iVFaNVz4hekJIR+sGFfyMYiCKWH/hKZMJ+ek o8ZHnrjjj+rBbGvqiIeo5BgLJUsmZgn7D3NFfTtZnPpZMo4D05jpwyvFKOpA2j+qZN5e 2CC3bGulxPiNLUIEn+yl7p17burJrxGqdmwmZxa6RBkyguSdetuH0/HSLizEeNC7TzJX go5Q== X-Gm-Message-State: AC+VfDyhdx0TVrzAh5HScA7Tw9Heq1bRAqe7y59KFwE2f7BnlZrMurpI gGWrAaHW0jBhIlZwUNUIkRg3AvE9IJw1zqMSdAh49ejLs4WdyDyiuypomaReJP2CS9V65imCw6x qU5QDSXim27lE2x7X+bFUUWoPwPG6jKg0YhfZgs7LGQ== X-Received: by 2002:a05:6402:1207:b0:514:9c7c:8a30 with SMTP id c7-20020a056402120700b005149c7c8a30mr4752014edw.30.1686151301141; Wed, 07 Jun 2023 08:21:41 -0700 (PDT) X-Received: by 2002:a05:6402:1207:b0:514:9c7c:8a30 with SMTP id c7-20020a056402120700b005149c7c8a30mr4751993edw.30.1686151300822; Wed, 07 Jun 2023 08:21:40 -0700 (PDT) Received: from amikhalitsyn.local (dslb-002-205-064-187.002.205.pools.vodafone-ip.de. [2.205.64.187]) by smtp.gmail.com with ESMTPSA id w17-20020a056402129100b005147503a238sm6263441edv.17.2023.06.07.08.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 08:21:40 -0700 (PDT) From: Alexander Mikhalitsyn To: xiubli@redhat.com Cc: brauner@kernel.org, stgraber@ubuntu.com, linux-fsdevel@vger.kernel.org, Christian Brauner , Jeff Layton , Ilya Dryomov , ceph-devel@vger.kernel.org, Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v3 11/14] ceph: allow idmapped setattr inode op Date: Wed, 7 Jun 2023 17:20:35 +0200 Message-Id: <20230607152038.469739-12-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230607152038.469739-1-aleksandr.mikhalitsyn@canonical.com> References: <20230607152038.469739-1-aleksandr.mikhalitsyn@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- v3: - reworked as Christian suggested here: https://lore.kernel.org/lkml/20230602-vorzeichen-praktikum-f17931692301@brauner/ --- fs/ceph/inode.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index bcd9b506ec3b..09c78a67738b 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -2051,17 +2051,27 @@ int __ceph_setattr(struct mnt_idmap *idmap, struct inode *inode, dout("setattr %p issued %s\n", inode, ceph_cap_string(issued)); + /* + * The attr->ia_{g,u}id members contain the target {g,u}id we're + * sending over the wire. The mount idmapping only matters when we + * create new filesystem objects based on the caller's mapped + * fs{g,u}id. + */ + req->r_mnt_idmap = &nop_mnt_idmap; if (ia_valid & ATTR_UID) { dout("setattr %p uid %d -> %d\n", 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 = from_vfsuid(idmap, i_user_ns(inode), + attr->ia_vfsuid); dirtied |= CEPH_CAP_AUTH_EXCL; } else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 || - !uid_eq(attr->ia_uid, inode->i_uid)) { + !uid_eq(from_vfsuid(idmap, i_user_ns(inode), attr->ia_vfsuid), + inode->i_uid)) { + kuid_t fsuid = from_vfsuid(idmap, i_user_ns(inode), attr->ia_vfsuid); 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; } @@ -2071,12 +2081,15 @@ int __ceph_setattr(struct mnt_idmap *idmap, struct inode *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 = from_vfsgid(idmap, i_user_ns(inode), + attr->ia_vfsgid); dirtied |= CEPH_CAP_AUTH_EXCL; } else if ((issued & CEPH_CAP_AUTH_SHARED) == 0 || - !gid_eq(attr->ia_gid, inode->i_gid)) { + !gid_eq(from_vfsgid(idmap, i_user_ns(inode), attr->ia_vfsgid), + inode->i_gid)) { + kgid_t fsgid = from_vfsgid(idmap, i_user_ns(inode), attr->ia_vfsgid); 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; } @@ -2241,7 +2254,7 @@ int ceph_setattr(struct mnt_idmap *idmap, struct dentry *dentry, if (ceph_inode_is_shutdown(inode)) return -ESTALE; - err = setattr_prepare(&nop_mnt_idmap, dentry, attr); + err = setattr_prepare(idmap, dentry, attr); if (err != 0) return err; @@ -2256,7 +2269,7 @@ int ceph_setattr(struct mnt_idmap *idmap, struct dentry *dentry, err = __ceph_setattr(idmap, inode, attr); 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; } -- 2.34.1