Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1645802rdb; Sat, 20 Jan 2024 07:23:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IF72UBeELmOJvj+WYab6tSs1FA1oj5Pk+GHrAayqY0HEhIkNe48R2m+UGBmWPjNFlqGKp7p X-Received: by 2002:a17:903:22c2:b0:1d6:ee5c:42ba with SMTP id y2-20020a17090322c200b001d6ee5c42bamr2652503plg.100.1705764235444; Sat, 20 Jan 2024 07:23:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705764235; cv=pass; d=google.com; s=arc-20160816; b=SS+zQ58p2PfJUntjVZyJeMThlWqNyoxepRQWoBEPpol0J8cP9dKHbid/yJmCEXsOiu HBJmplGrscnGG+PEB+XKCkEYcoJjBTm6zCS0dSC8pVzM8c+Kv4AZdu0cj92kJfblLXw4 ETHIvqD8YVK7i+cMr0DXhrVtloqRLaiRUs40d3oQwceUFY28ji4k5Vn4o12gwII40Z5b 01SBQzH8UDTtRvmRvnaAoKs0Z0ziM6eDkMH6nxtKBjTQxUxoPyyGnQj0p/cW5wsLZFJk Zan4A7Pgm3vbhHRiWRPJDd1L2ducE2njQvAI1VkHxjbjXFkrGr4DqD4VM0UuR6kQ0cBx smDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=X6cFoGdsgTfUD2t2sLrV50qz4KdfobheRlOxfBHklJ4=; fh=VpBWx3aAoqFhsjGoHX3K/ycPJA7wBkuCBGlpzvEYdaY=; b=ZBVJ0IdW8JaOXdEVSzsrejjjLGE+VHS8eJVBDnH2X66SwssQmQ1lUnTs7R8pNaNW1m s0IHSUwMKZNH9DRMbZ5/jeevTLOPT5cHLbeD4Vsv1TCtCf1HuxDKLPvSHJ3Y+LWU+jsC USU2fb8Aah0ulJr8ovN8Y99sZ/+/U8vvY/C8KQVz8hym0a6MkHV+p7q5mwTQO+8QzHJ4 Sr4mwkuBuW8kAB+/XS28/T8p8xGyWrpIE8NkcVUtPb7wziQBZB2+ySblSlq7JbKtvLMt JFW4dMn57/BPFA0AO7j+bwQVYlSPHdHdDFcQOw8nDFE4QFrg7RA9MBuBKisORoQr4c5E mlYw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HMxaR02z; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-31828-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31828-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h12-20020a170902704c00b001d4af344a66si5064963plt.141.2024.01.20.07.23.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 07:23:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31828-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HMxaR02z; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-31828-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31828-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1AE46283287 for ; Sat, 20 Jan 2024 15:23:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1A1A10788; Sat, 20 Jan 2024 15:23:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HMxaR02z" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8FC1F515; Sat, 20 Jan 2024 15:23:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705764224; cv=none; b=joDKX3gNKHe/4GXkDhQCQmUifeU9SjQtrm5zPbi6IspF31NUqpDs0uKd7kLZUjBZD+QzxqgqUod5o1Ao1DxDpT6l3MI9aIg07ZU1pnztLdo8z+9PTGvnl6YGTDlFb2tuW4ECd22lnTrdaRT/J9xi/iY1bZR8M9hVL7oSNaRvPUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705764224; c=relaxed/simple; bh=7+7RUx7Pil+a2kyG9u8gC474V725SmOCGQ9QaE+x60o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i+C4NOiYbG1I+lXUGkt4SkW3gHNXBhdfMTXjL8l0eEo8Mviv5FegVABB50izzVaexFzvB6faLZvLRsNemgn5CZV5P+5CWOWncl+0OyE0oD1Wrec3/peq6fnKD/OQvX8ZAhtfUDnYfIkU9HMv1+z/Kpr0Qe3jF/wApiPsehlvYoo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HMxaR02z; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E221CC433F1; Sat, 20 Jan 2024 15:23:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705764224; bh=7+7RUx7Pil+a2kyG9u8gC474V725SmOCGQ9QaE+x60o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HMxaR02zNPkYr4GYoX4GbP5gdggaPIpv+Tv16glt2UIdat2OWnXQ/tVwqgkKFji6U 1LN4tLyTuBpXEQdMIfx86T15FsiVRtj4B/l5NQnR00nn2ypsSITPzY3J2KsMa8PZy5 jat6D92FyKvVu0VLuJRYBfXdjHePJXL9RkQC2Mj+DVQU3O3+1k38m8lW5/b9I43e1x KB4srI/lqSW25iecwNRrQEOyExtiIw3zAJOfZ0e99MoHNuIcam6R5PEizQ5bEk1nWR ub9zJ6Evirkkq6GbpKifKjYSqPEmWOyI+vPXjI0e02jmbe7G9TRdEmVuTpL12TBIKF 0FQoQs8t5JzmA== Date: Sat, 20 Jan 2024 16:23:38 +0100 From: Christian Brauner To: Alexander Mikhalitsyn Cc: mszeredi@redhat.com, stgraber@stgraber.org, linux-fsdevel@vger.kernel.org, Seth Forshee , Miklos Szeredi , Amir Goldstein , Bernd Schubert , linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 6/9] fs/fuse: support idmapped ->setattr op Message-ID: <20240120-zeitmanagement-abbezahlen-8a3e2b5de72a@brauner> References: <20240108120824.122178-1-aleksandr.mikhalitsyn@canonical.com> <20240108120824.122178-7-aleksandr.mikhalitsyn@canonical.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240108120824.122178-7-aleksandr.mikhalitsyn@canonical.com> On Mon, Jan 08, 2024 at 01:08:21PM +0100, Alexander Mikhalitsyn wrote: > Cc: Christian Brauner > Cc: Seth Forshee > Cc: Miklos Szeredi > Cc: Amir Goldstein > Cc: Bernd Schubert > Cc: > Signed-off-by: Alexander Mikhalitsyn > --- > fs/fuse/dir.c | 32 +++++++++++++++++++++----------- > fs/fuse/file.c | 2 +- > fs/fuse/fuse_i.h | 4 ++-- > 3 files changed, 24 insertions(+), 14 deletions(-) > > diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c > index f7c2c54f7122..5fbb7100ad1c 100644 > --- a/fs/fuse/dir.c > +++ b/fs/fuse/dir.c > @@ -1739,17 +1739,27 @@ static bool update_mtime(unsigned ivalid, bool trust_local_mtime) > return true; > } > > -static void iattr_to_fattr(struct fuse_conn *fc, struct iattr *iattr, > - struct fuse_setattr_in *arg, bool trust_local_cmtime) > +static void iattr_to_fattr(struct mnt_idmap *idmap, struct fuse_conn *fc, > + struct iattr *iattr, struct fuse_setattr_in *arg, > + bool trust_local_cmtime) > { > unsigned ivalid = iattr->ia_valid; > > if (ivalid & ATTR_MODE) > arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode; > - if (ivalid & ATTR_UID) > - arg->valid |= FATTR_UID, arg->uid = from_kuid(fc->user_ns, iattr->ia_uid); > - if (ivalid & ATTR_GID) > - arg->valid |= FATTR_GID, arg->gid = from_kgid(fc->user_ns, iattr->ia_gid); > + > + if (ivalid & ATTR_UID) { > + kuid_t fsuid = from_vfsuid(idmap, fc->user_ns, iattr->ia_vfsuid); > + arg->valid |= FATTR_UID; > + arg->uid = from_kuid(fc->user_ns, fsuid); > + } > + > + if (ivalid & ATTR_GID) { > + kgid_t fsgid = from_vfsgid(idmap, fc->user_ns, iattr->ia_vfsgid); > + arg->valid |= FATTR_GID; > + arg->gid = from_kgid(fc->user_ns, fsgid); > + } > + > if (ivalid & ATTR_SIZE) > arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size; > if (ivalid & ATTR_ATIME) { > @@ -1869,8 +1879,8 @@ int fuse_flush_times(struct inode *inode, struct fuse_file *ff) > * vmtruncate() doesn't allow for this case, so do the rlimit checking > * and the actual truncation by hand. > */ > -int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, > - struct file *file) > +int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry, > + struct iattr *attr, struct file *file) > { > struct inode *inode = d_inode(dentry); > struct fuse_mount *fm = get_fuse_mount(inode); > @@ -1890,7 +1900,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, > if (!fc->default_permissions) > attr->ia_valid |= ATTR_FORCE; > > - err = setattr_prepare(&nop_mnt_idmap, dentry, attr); > + err = setattr_prepare(idmap, dentry, attr); > if (err) > return err; > > @@ -1949,7 +1959,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, > > memset(&inarg, 0, sizeof(inarg)); > memset(&outarg, 0, sizeof(outarg)); > - iattr_to_fattr(fc, attr, &inarg, trust_local_cmtime); > + iattr_to_fattr(idmap, fc, attr, &inarg, trust_local_cmtime); > if (file) { > struct fuse_file *ff = file->private_data; > inarg.valid |= FATTR_FH; > @@ -2084,7 +2094,7 @@ static int fuse_setattr(struct mnt_idmap *idmap, struct dentry *entry, > if (!attr->ia_valid) > return 0; > > - ret = fuse_do_setattr(entry, attr, file); > + ret = fuse_do_setattr(idmap, entry, attr, file); > if (!ret) { > /* > * If filesystem supports acls it may have updated acl xattrs in > diff --git a/fs/fuse/file.c b/fs/fuse/file.c > index a660f1f21540..e0fe5497a548 100644 > --- a/fs/fuse/file.c > +++ b/fs/fuse/file.c > @@ -2870,7 +2870,7 @@ static void fuse_do_truncate(struct file *file) > attr.ia_file = file; > attr.ia_valid |= ATTR_FILE; > > - fuse_do_setattr(file_dentry(file), &attr, file); > + fuse_do_setattr(&nop_mnt_idmap, file_dentry(file), &attr, file); Same as for the other patch. Please leave a comment in the commit message that briefly explains why it's ok to pass &nop_mnt_idmap here. It'll help us later. :)