Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp914364rdb; Tue, 30 Jan 2024 02:24:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3A1luKxeZ/CEZ2zvTjHTlaMscl8K0G8oH1sTcCywKoc3zQeWNZ/JnsJd6O8KJrnX6m7mT X-Received: by 2002:a9d:7f96:0:b0:6dc:680a:6292 with SMTP id t22-20020a9d7f96000000b006dc680a6292mr7632503otp.37.1706610295208; Tue, 30 Jan 2024 02:24:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706610295; cv=pass; d=google.com; s=arc-20160816; b=ETex9t6BkL8LXs4qwXMj3lqOYK8BsngwnnZ3REvX4WlrgAGePDZLlNHICBZUGHcdw2 pyGjz5pBE3OR5zSiAMh+xaGowVnfBje4rDrTuRC5lE5M2LE/XOPA/FVqVfpMzYho1ZjR NbI/JCGKzbftS6KXbvHz7UNrqUc8qBzFlkAkwPddHgm+RWQ/Suxtwq6+x7BXNkVARS8p CrP4tUC0bEkZLZ10LbIzMk6Kc9e0I2pMZwyZpUnj74aTR+4qS8kEG+zHlUwiWMf8lVPq qCcp90PoaJptaLX9ZSgPrHVVdC0Gw/dGI+Oyggl2TOXIm66O6GndQESTk3FI4Nyc9AbK B/KQ== 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=wFG2ISOedSHUCz2B0bx81PefSYxH5myEOgpnc5EOZ7Y=; fh=VpBWx3aAoqFhsjGoHX3K/ycPJA7wBkuCBGlpzvEYdaY=; b=mPta37zQQN/0z3wu6L2y68EDbWNrt9jsNppYD6CigGH7Bb9Ue8rYyCsik0Asfc/qkz TMctcHbbHENWsyVHgw7SxZ3hXeDTP8/umwT//nuHEstonZFv9kx5xdi7QmSwGbcDbAuB YBhIWoSb20RYugWmc+uCngjTMEj0joLdILcHLDQDb8DvTD5p8hpgTyQjjtk/LDcmJ3+t 9229/YsH3feoyQpLrx9SPIC+CEa3OvW105lTU3lpezxCgP5bxG4+G04fOsXIMnSdirJf v81V7OTc3KJsGlqsv/ghr5Els9p9cdhwhYKhd/AHAYvteGRLwI8OyZsknZe2XHP9z+2z Eybw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KXdOzw0G; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44319-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44319-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bv124-20020a632e82000000b005d84e5bb276si6373321pgb.885.2024.01.30.02.24.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 02:24:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44319-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KXdOzw0G; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44319-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44319-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id BD922B31247 for ; Tue, 30 Jan 2024 09:56:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 38B90664BC; Tue, 30 Jan 2024 09:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KXdOzw0G" 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 2C0D6664A9; Tue, 30 Jan 2024 09:52:27 +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=1706608348; cv=none; b=gUdNleFRJEFJzrKMbVP3bbqsyjbjuX1PjBjovDJFCqQmUJAzJ4ijzSzrmhcvFHazX+vJVVdOq94U6GeTuI9vwfh458x+9RKmaqkK0F/7QWrVudbp5AlpuQrsB+IGLSoFoKS5fIltuLHKHlwOuJsZ0amagEXl2+GrsESRVV9W3ag= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706608348; c=relaxed/simple; bh=Kj7uKf/C4kWgSz8bKZaS0Cc4J2SRHT1aScYumeV+1Og=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rntOsnpQN+JXc69YFNeWEZpNdUGUVg1MWvEymJ2cN/V9dKXTBWnd5tpfFaqb8Sy3x8RfzdLXCeRpqCNyXGrCsHWpfEZpu7d7EBmzXzaFFUnsW1+mkgn1YypFMFBWx23UrTJT34DdzZhvjwgN6J9ysA9NadOeQMuZbz8xeNBtlXo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KXdOzw0G; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34906C43390; Tue, 30 Jan 2024 09:52:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706608347; bh=Kj7uKf/C4kWgSz8bKZaS0Cc4J2SRHT1aScYumeV+1Og=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KXdOzw0Ge+S0kxxUwX6xUO6wp/RQAOylY1MqtPueRi0QSlhyI/TZGBUzqDkIjKYXV 1V62ElrAa0Ig2uLTmT9Dv/8k1IM1IxMAsXAAVmtHjXA7e+dnJWv2z/u06D6/Pfq19C TsALPLf65alRx3ngi7L/MSa8oieOEUQX9dsSDzlG+grFoH65UNxtEHmk7m7B61LvLT /AXIHtQZB9+QNpClqOUGK1BCRdX2qxq10yjSVxjii1ef37xtfoMgcc4wNghMmHort8 aZfQ1FsnFf/2rJ7vYmsoaxuiQp2M/czFUG6MwvuPGB+sYmL//vRVHIF1r1MJvshsh0 7qKjPGPNFHC3A== Date: Tue, 30 Jan 2024 10:52:22 +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: <20240130-vielsagend-bauamt-282fd8bff38a@brauner> References: <20240108120824.122178-1-aleksandr.mikhalitsyn@canonical.com> <20240108120824.122178-7-aleksandr.mikhalitsyn@canonical.com> <20240120-zeitmanagement-abbezahlen-8a3e2b5de72a@brauner> <20240129164849.f3f194a800d88fd26a373203@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: <20240129164849.f3f194a800d88fd26a373203@canonical.com> On Mon, Jan 29, 2024 at 04:48:49PM +0100, Alexander Mikhalitsyn wrote: > On Sat, 20 Jan 2024 16:23:38 +0100 > Christian Brauner wrote: > > > 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. :) > > Sure, will be fixed in -v2 ;-) > > Explanation here is that in this specific case attr.ia_valid = ATTR_SIZE | ATTR_FILE, > which but we only need an idmapping for ATTR_UID | ATTR_GID. > > From the other side, having struct file pointer means that getting an idmapping as easy as file_mnt_idmap(file), > and probably it's easier to pass an idmapping in this specific case rather than skipping it for a valid reasons. > What do you think about this? Yeah, I'd just pass it through because then we don't have to think about why we're not passing it through here.