From patchwork Wed Jul 26 14:06:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Mikhalitsyn X-Patchwork-Id: 13328096 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79B52C0015E for ; Wed, 26 Jul 2023 14:08:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234409AbjGZOI1 (ORCPT ); Wed, 26 Jul 2023 10:08:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234480AbjGZOIA (ORCPT ); Wed, 26 Jul 2023 10:08:00 -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 E33A735A8 for ; Wed, 26 Jul 2023 07:07:23 -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 608A840822 for ; Wed, 26 Jul 2023 14:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1690380440; bh=5Jek2ao2Gg23mz8Y2ufU3Ts9QQq34R72Sad2dO2kfLI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OWW09cfCCnqHIH2Xpfn1l+9qgFiaIVwWEIVdJegZea1/fLJRYcsJV2qjz4biLTPaz 7mvK8XxP8eftrs9VFgCAMlrbMwtRaklMZVyHvRFKYmqxJ+kWQUJ5MZJ1RoctSfAhTY CjYs50tvgFVBsw3cCzsK6cWIKBBrmt1PTVpje4fZEr4X0UUXaqpAupYJsnaM9D1yox 3jC2ln1zgO+7JuH5kAB3XpAowEhkjxbDI7yTqNkC99/BV1jepTXwm9DlW+IZQJJ3/o mESStbuFZTFPy37kJwwdhjzJ373cNP5okIoVf8EwvqCzSrWshP6BK+LRY+EODGKMkE 4wYWVhHXya7uQ== Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-992e6840901so115543666b.0 for ; Wed, 26 Jul 2023 07:07:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690380439; x=1690985239; 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=SSlt/AfpXz8VbvnusA8rixhyTKDeeEP/7fkV+VwNg/oxUBGcch/tDcZN1loEp3DzOD 6PIBiIdx1oe+zK/pMtED6aOiGScJPpo5pkW46MQolmLuVkWwT+RCBQWDEZ+PV/7L6cj4 gflrqdPrLWtytSGnQsPl2GxpynV7QGB/l/8IjXH+sXP0V7NPo/ccA6iN5Sqm/dvPdq54 /xD1kQC6XbEFSfu76JzHuFGaZ+ASpDs3oK720YXrLPkMww0b25ccIjHH38u+u5Mujce2 IzFmrqpbHrRpEYoNzlPN1eC0yaGQyTCyxTGOvnCv7Lx1Tw2+cxkeIl2UweEzNqNTQvDL s2hQ== X-Gm-Message-State: ABy/qLagcTEww4JVyaZsRUv35W/Ojdwy2B3XrDJEw4gEKEDK/x3NZXRJ HtKW/zBk9JN+G+IrIEjtaSmuYXzjvDFMLeu7Vp72qb6kpwOSBdgt6fbddXK0ciJFrss42cQdmuc ymEEV7PtvK2dl6EAH7FQeFJ6j0o494nVxxps0GvlZuXY= X-Received: by 2002:a17:906:ef0e:b0:974:fb94:8067 with SMTP id f14-20020a170906ef0e00b00974fb948067mr5498051ejs.23.1690380438854; Wed, 26 Jul 2023 07:07:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlFGAZZdJ2VxStlZQEsuWXvxIePi0KL5JcxCe5ljTK+JmzoTN37r/TLz5Y4osgx4A1xiDgwsEQ== X-Received: by 2002:a17:906:ef0e:b0:974:fb94:8067 with SMTP id f14-20020a170906ef0e00b00974fb948067mr5498036ejs.23.1690380438638; Wed, 26 Jul 2023 07:07:18 -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 o22-20020a170906289600b00977c7566ccbsm9572931ejd.164.2023.07.26.07.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 07:07:18 -0700 (PDT) From: Alexander Mikhalitsyn To: xiubli@redhat.com Cc: brauner@kernel.org, stgraber@ubuntu.com, linux-fsdevel@vger.kernel.org Subject: [PATCH v7 08/11] ceph: allow idmapped setattr inode op Date: Wed, 26 Jul 2023 16:06:46 +0200 Message-Id: <20230726140649.307158-9-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230726140649.307158-1-aleksandr.mikhalitsyn@canonical.com> References: <20230726140649.307158-1-aleksandr.mikhalitsyn@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 --- 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; }