From patchwork Fri Jun 9 09:31:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mikhalitsyn X-Patchwork-Id: 105530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp850332vqr; Fri, 9 Jun 2023 03:39:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7B47PWe0asMkDv8PDsgZ8E2mxG8ArW9hhZ/Ma36qPCh0m4bk0aITedul+yKk1lGuhcRI4s X-Received: by 2002:a17:902:da83:b0:1ae:4562:14f1 with SMTP id j3-20020a170902da8300b001ae456214f1mr713639plx.9.1686307173589; Fri, 09 Jun 2023 03:39:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686307173; cv=none; d=google.com; s=arc-20160816; b=qan4BVB5JqJqAq3CrpkyrQ9D0fBk/Qvp5Xi/ON4FBT+uid8DyWDSo+NYayvaqFCW8K Fxpe+BABV6vJKEDrf9f9LY3BX7xkhxj7RkS3LGa8QPeTmqcGwUZrnju/zf0kGccsxsVk Hmy8iyESQDGovMmUDWLRHXQNLoEjwHyyS+7eybd5fASywq2deZFVdTooRF5dDBujl2SO 2F2o6bnfT5ueJOsq7DLW2vcuetgx+UQgs883BmGJqEXuHo8L1Q5IFRDP6CBRSV/umxpc hsA6OPIn8J2QEh+nw5t7FT4PLP8jQUQRN2jxCna50NMqAG3mgIR1QMbHWT/RRynFSZLu HR6A== 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=d5khlOcPOkR48ashhbagswr/xnjgstKG+L7ceqQR68I=; b=Rfap2zTvnwfeeiwjsbBsQNyI3xLCdmw+OZ2rGJQxx549JAFFd4XhcoqEyZMyFP5Scm yZyFHAnnde3lh39dFrKUqaULdmPQ3z29R1+PS8fuVIcw9PDqjP1L2edYNaQ1ryixyPkD rjJSZRfKyBarhroWD3Cr6GmNp1Zsh6Y7p3rJmmAUsn9KNx0LGm3GdRlCsozHS2LcGuX9 GEe6a6pzEpxhw9yWm82DJRqjn1w1CKCXtDW0PSgbcE+G7lfKY5jrmrNdX+V2X2n4UjS6 jqV/kx77D8z28yRzxmuqGWlYTyrQfHHNmS+GiDXPoJooDWZUxnW7J8oRJB1uYJ69mfBF XzmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=t6MJJajG; 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 l4-20020a170903244400b001b00ffb44c5si2665209pls.229.2023.06.09.03.39.18; Fri, 09 Jun 2023 03:39:33 -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=t6MJJajG; 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 S240418AbjFIKKs (ORCPT + 99 others); Fri, 9 Jun 2023 06:10:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241349AbjFIKKS (ORCPT ); Fri, 9 Jun 2023 06:10:18 -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 C6BE28695 for ; Fri, 9 Jun 2023 02:59:16 -0700 (PDT) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.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 7FC8C3F572 for ; Fri, 9 Jun 2023 09:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1686303175; bh=d5khlOcPOkR48ashhbagswr/xnjgstKG+L7ceqQR68I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t6MJJajGgpqhLtt2ZIK2Vrind5EIIpdL8fNbYVs7VFf0zyttJSFkc6tCUp9F3vRMq meT9Ahciak7NE/P/GJfLTHFU4mq2spljEYmk0E7c/KPwsCzpOjUiZeYdVrpuJ3DI8P dfW8WCTp5hYRXhWQuEFVyEp6E81zp+fUEoBxYZvYQlLnIyq79+ieYytla7giiHMlz0 XpAWF/TXM6t6eaplHF9oBKbBP5iiUZB3QD9CgbLlB4Dd8amhfOOF9XQ5D4MHh9teG/ 8vNYKBU9sXHB4aISSk/VFp5ILxlO2yNEEkxWVcVKmdnJcFq1o+tGp8paKIT1fogCfp E/UA+s5ZGVW4A== Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-977d4b0d9e3so134980666b.0 for ; Fri, 09 Jun 2023 02:32:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686303172; x=1688895172; 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=d5khlOcPOkR48ashhbagswr/xnjgstKG+L7ceqQR68I=; b=X+vaUuOToqm1/QB97u0M4grgBi/UZZaxFfLVLYuLgqSui30pKpGTw3MAPODs2YF/hp /2rUe8x3sK4O/vARajKXRG5uulfx5vOU40mzZokGywZ3+abpridJnyW+l+eoZM3njl0N SYMkItLe/WRddcfiXEVGaUOW6FPsmuc7OOPwXV1IkeU7DWeyrl+mq/HYuK8BBWuWjjju PthznQaYhMzGOPGeTUWGW9NJ4EntN0Af7B7gAR0ount108oMmlodTeJhLEmzFn3DjuY9 fE7xHk4CiWiYMCH/76AcqjAGAb9maMn1gmtiISnktwZXQzE44hZS9oVocWue1kMUvnhT G+aw== X-Gm-Message-State: AC+VfDytV5bnBe/xTuikfk+C7OllSAHqpyxXmcWEKF67cpAs1TE1Xm4Q LVPvCvAAqKDP79W/7w8HUiXZBKYzMt+czrHc6bodX+fczg9SDjtqZu5Cg35UMaJrc++v0JJsEbK 1JYy5zAZGhGTmreHu/lLRx+kLjPy8KZCICbXtJqTUxw== X-Received: by 2002:a17:907:2d0f:b0:965:6075:d0e1 with SMTP id gs15-20020a1709072d0f00b009656075d0e1mr1243440ejc.72.1686303171875; Fri, 09 Jun 2023 02:32:51 -0700 (PDT) X-Received: by 2002:a17:907:2d0f:b0:965:6075:d0e1 with SMTP id gs15-20020a1709072d0f00b009656075d0e1mr1243429ejc.72.1686303171703; Fri, 09 Jun 2023 02:32:51 -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 e25-20020a170906081900b0094ee3e4c934sm1031248ejd.221.2023.06.09.02.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 02:32:51 -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 v6 08/15] ceph: allow idmapped setattr inode op Date: Fri, 9 Jun 2023 11:31:19 +0200 Message-Id: <20230609093125.252186-9-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230609093125.252186-1-aleksandr.mikhalitsyn@canonical.com> References: <20230609093125.252186-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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768221230849911947?= X-GMAIL-MSGID: =?utf-8?q?1768221230849911947?= 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 9a4579da32f8..6a8aeb4b8fb8 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -2509,31 +2509,35 @@ 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); + 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 = 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); + dout("setattr %p gid %d -> %d\n", 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; } @@ -2756,7 +2760,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; @@ -2771,7 +2775,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; }