From patchwork Thu Aug 3 13:59:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 130688 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1230351vqx; Thu, 3 Aug 2023 08:35:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlGeRQDkBGSmqNygNfI3AJYPEXgVsfbc86ImEcEwxtMIRDQMytEO2kDFm69xt0aigtPjpugt X-Received: by 2002:a17:902:a705:b0:1bc:2bd:8520 with SMTP id w5-20020a170902a70500b001bc02bd8520mr12411832plq.6.1691076912673; Thu, 03 Aug 2023 08:35:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691076912; cv=none; d=google.com; s=arc-20160816; b=ck0sUkopoWvFbTB8klaKGrtKBWjCcl2RybrI0nCkqRTekApF+GufFpoWuMzndjeMta wgDDkLkVPlJ6TEkqj6JkzkDaX7g5oVEdYEQT+eOqQEvwmB5+Sn6z8O3XSQei4Ng5mMhI aIxyg5jxY0bLPROv9JfdZuQdTyp7BGcHV+pAg2HgngrNOGWFl0PBiGDZ4I85X6sez7jT 1OPtjCmOVvBU3JMXrBvg7KxwcxOEiBvJPaG/T01Ki+nu7+ZQYEQT5p9BDV33L/Y6KDqx qnHIr7jPcKslNKcuLgUNryCOERg8to/H7kXz3sIc18tyxVRG5IWH2TTmMlTgNMEH4FJM vhkA== 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=CQAHRH/ms/cFOl3S4jtiakCJJYzaMB08Yq0KPV8/UVY=; fh=Z2mkFIQPI1atT1PXylFFs5aXkUtGzwkgwqJaEftWDsI=; b=ZAx6NGcs7LkCFKsWpIEn5oYywRD3nUq/1Ft3yaIMoUPr06L74e36Pf0wUjqAmTMnBH nf8YdwkTdFJK8bszP5tl5m4gjaaZAtDQcU8uv/9n5b4CSBXZ6ZSASoHZhrQ4CWsqQnPm yrZHbvjK0pgI5E2DnjmE/VwGtQFhbR+5vZUzki3p38TFeXCEdVkh2oFVyFgZCMfRpISM 4lR5chqrtJ1eBtwjP5o3S12pjahzfNiiFNN6PmQoO9OcSLiOlN8IARUpiAEVB6L5CAg7 WhqoVtQl2s03eHbMCrJm0Pru+6uvF7u7ElkppCwWxxOe0OV9KgXfE14X7pbdKWmiZM1g jnVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=L9SQQCM2; 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 kt4-20020a170903088400b001b55070e154si43316plb.96.2023.08.03.08.34.39; Thu, 03 Aug 2023 08:35:12 -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=L9SQQCM2; 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 S236617AbjHCOCZ (ORCPT + 99 others); Thu, 3 Aug 2023 10:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236616AbjHCOB1 (ORCPT ); Thu, 3 Aug 2023 10:01:27 -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 60DF74481 for ; Thu, 3 Aug 2023 07:00:56 -0700 (PDT) Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.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 4C564423E9 for ; Thu, 3 Aug 2023 14:00:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1691071234; bh=CQAHRH/ms/cFOl3S4jtiakCJJYzaMB08Yq0KPV8/UVY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L9SQQCM2L1t0eF+GcnbEpskA8H2VXKalllhgVsx0RXSdoJ0HSOrrH71ZTDiYFXkZb x84H8VgnQwsSqj0R3+GQIDlmuuqfeABsO9qHU717A6eNq/ZRQdTqtNu2nLEt0UzF0l VIQ5rfCCFVpTryRkdpOALw4bbhHvJHNeFnnLKaZ3va7jEuHHU20u4oQKd+NA1s7xA+ tYJqqlHLzYOwvftTjjI0nm8/TfdvmM4T/INuJhDp8uIrrX7Q/2VB0arxc4pM+bBpvi onCuMI18GyGKt/7w56ICIbQJsb8/OF+cvyYnENifXh1jIyXVYuiFt6Q995MnBsG3Oo FFp5/M+uu37hw== Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-4fe0e1dfdbaso1000190e87.1 for ; Thu, 03 Aug 2023 07:00:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691071233; x=1691676033; 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=CQAHRH/ms/cFOl3S4jtiakCJJYzaMB08Yq0KPV8/UVY=; b=RCa9bLYZDW45HccihFA/APmqbxnsuq+pfAXPpeaF/4HGkJdP299KYwOAFrMZizWeE7 +MhnF4X6fb5goUvpr4/9Ocwm9/iqAuaKFxR4EfBS1BU2yX6wBVilq6gZCicFfoeoNI/z PsIfiKGK8y6OGhnMWR+lfc8iQw/nTLpGoHqfntAriP6nZrkRxlNfQeJHbyxsPizCLuZw Co3mgpjwyYSScNeR/rOiN0qhLDyIW/M12kgmZFZo6U8SiMFYeFTzEUonLW/gcHsOaViF Cnpjr3QlJhKex/3mYEP5kYfJRie0EGUdvCGuv0OLI4oHEwIKMxI09sG6UrIEkE0KFrc7 vEzQ== X-Gm-Message-State: ABy/qLZdJOBpK6lX2C9kJVYGvEqc7WghVf0XMiy0x+dzau+yuKxLtueT OOmX/PBioT/oqGUcyqUaLoBIcUFU4UNFCBNULT6SxTcwSCH2s3Aj6J4elIF8yaZli2qiWN9tGJ8 uGy2q719Lfq0Nf+LdjO5VPzo80zHcQocsEk+4qwnkwg== X-Received: by 2002:a19:7b12:0:b0:4fe:958:88ac with SMTP id w18-20020a197b12000000b004fe095888acmr6943483lfc.6.1691071233259; Thu, 03 Aug 2023 07:00:33 -0700 (PDT) X-Received: by 2002:a19:7b12:0:b0:4fe:958:88ac with SMTP id w18-20020a197b12000000b004fe095888acmr6943455lfc.6.1691071232890; Thu, 03 Aug 2023 07:00:32 -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 bc21-20020a056402205500b0052229882fb0sm10114822edb.71.2023.08.03.07.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:00:32 -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, Alexander Mikhalitsyn , linux-kernel@vger.kernel.org Subject: [PATCH v8 09/12] ceph: allow idmapped setattr inode op Date: Thu, 3 Aug 2023 15:59:52 +0200 Message-Id: <20230803135955.230449-10-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230803135955.230449-1-aleksandr.mikhalitsyn@canonical.com> References: <20230803135955.230449-1-aleksandr.mikhalitsyn@canonical.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1773222665086451433 X-GMAIL-MSGID: 1773222665086451433 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; }