From nobody Thu Sep 11 14:11:02 2025 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 85B97C6379F for ; Sat, 18 Feb 2023 00:49:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbjBRAs7 (ORCPT ); Fri, 17 Feb 2023 19:48:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjBRAs4 (ORCPT ); Fri, 17 Feb 2023 19:48:56 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10DFF53EC8; Fri, 17 Feb 2023 16:48:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 99FFFCE2D11; Sat, 18 Feb 2023 00:33:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17A3FC433EF; Sat, 18 Feb 2023 00:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680434; bh=PwWjKgBCrFlHwrWRE5cwXvsrY7AklcLgKZPzMWv8M98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uoiSvOjVFdldq06YEWUWJ5d6yYyCFmNKfK/nQJ1caAuYFBSe7ItFqXHlKS9KpiDJb MSsdsh4qjW9ARIQiNRph5Oo4iG0l1JDWo7qyb67VWywhZy7Dywf1a7xANo3+otCeum GJ9XzUoh9k+IeI7+mGixH2//iLtq8jT8swpMNuKcsuSABU0n7xrejOOIThxQV3L8iI MSdh9sPUNQS7hNH8DRYKMfA+gocsbqWcCxOCX5k/OPtHxLqSW3D4lpZgHvTTDFNx08 tqSwZFSqXIshydzqltmUOmhWXj+UD5dqeCchUFrIMIE3GNcsjsq41AlA5uz+B1MiwH FuDUdno65CPvg== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 01/11] net/9p: Adjust maximum MSIZE to account for p9 header Date: Sat, 18 Feb 2023 00:33:13 +0000 Message-Id: <20230218003323.2322580-2-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add maximum p9 header size to MSIZE to make sure we can have page aligned data. Signed-off-by: Eric Van Hensbergen Reviewed-by: Dominique Martinet --- net/9p/client.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/9p/client.c b/net/9p/client.c index 622ec6a586ee..6c2a768a6ab1 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -28,7 +28,11 @@ #define CREATE_TRACE_POINTS #include =20 -#define DEFAULT_MSIZE (128 * 1024) +/* DEFAULT MSIZE =3D 32 pages worth of payload + P9_HDRSZ + + * room for write (16 extra) or read (11 extra) operands. + */ + +#define DEFAULT_MSIZE ((128 * 1024) + P9_IOHDRSZ) =20 /* Client Option Parsing (code inspired by NFS code) * - a little lazy - parse all client options --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 736ABC636D6 for ; Sat, 18 Feb 2023 00:49:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229891AbjBRAtK (ORCPT ); Fri, 17 Feb 2023 19:49:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbjBRAtE (ORCPT ); Fri, 17 Feb 2023 19:49:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB2233B86F; Fri, 17 Feb 2023 16:48:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 57792B82ED4; Sat, 18 Feb 2023 00:33:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2510FC4339B; Sat, 18 Feb 2023 00:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680435; bh=SK5Jy+6rCKveBD5nbCJDN3evu772cvxZ/alFpEsNfhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P0fOYxs8c6GQ3wDUi9RThrIWsEWcmhutUXhMt2Bp7pkuvCF4YW1cbSIfmtu1xMyZQ ZbVmW6/+yg7AWH54gZXk/Yh/LdUllzhhH4A3589o/MgFuG7kGSvu90qLZRIuX1W7o9 0ws7j+OIQ+zGthBGMrTewYG7dq662bt4yhnoCRgmcZb0TDTwUYsNvcoAv5CM5wbH6X RM2OH7MBZfuUYqfjJJc6H1DTzOkDBnHLBtRfFq14vBzInZGann7vrvml+nlSy5T98Y WxGzBCcu6L+3nZoFGhnF+HRywhz71AdlIQk/yzcbiOWmX5aXGmuOnDkLaohVfv5V0B aM9CEe1HOhuUw== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 02/11] fs/9p: Expand setup of writeback cache to all levels Date: Sat, 18 Feb 2023 00:33:14 +0000 Message-Id: <20230218003323.2322580-3-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If cache is enabled, make sure we are putting the right things in place (mainly impacts mmap). This also sets us up for more cache levels. Signed-off-by: Eric Van Hensbergen Reviewed-by: Dominique Martinet --- fs/9p/v9fs.c | 2 +- fs/9p/vfs_addr.c | 2 -- fs/9p/vfs_file.c | 7 ++++--- fs/9p/vfs_inode.c | 3 +-- fs/9p/vfs_inode_dotl.c | 7 ++++--- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index 3a9c4517265f..61a51b90600d 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c @@ -468,7 +468,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_in= fo *v9ses, =20 #ifdef CONFIG_9P_FSCACHE /* register the session for caching */ - if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE)= { + if (v9ses->cache =3D=3D CACHE_FSCACHE) { rc =3D v9fs_cache_session_get_cookie(v9ses, dev_name); if (rc < 0) goto err_clnt; diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c index 97599edbc300..6f46d7e4c750 100644 --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c @@ -279,8 +279,6 @@ static int v9fs_write_begin(struct file *filp, struct a= ddress_space *mapping, =20 p9_debug(P9_DEBUG_VFS, "filp %p, mapping %p\n", filp, mapping); =20 - BUG_ON(!v9inode->writeback_fid); - /* Prefetch area to be written into the cache if we're caching this * file. We need to do this before we get a lock on the page in case * there's more than one writer competing for the same cache block. diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index b740017634ef..3b6458846a0b 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -73,8 +73,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) } =20 mutex_lock(&v9inode->v_mutex); - if ((v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE= ) && - !v9inode->writeback_fid && + if ((v9ses->cache) && !v9inode->writeback_fid && ((file->f_flags & O_ACCMODE) !=3D O_RDONLY)) { /* * clone a fid and add it to writeback_fid @@ -92,9 +91,11 @@ int v9fs_file_open(struct inode *inode, struct file *fil= e) v9inode->writeback_fid =3D (void *) writeback_fid; } mutex_unlock(&v9inode->v_mutex); - if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE) +#ifdef CONFIG_9P_FSCACHE + if (v9ses->cache =3D=3D CACHE_FSCACHE) fscache_use_cookie(v9fs_inode_cookie(v9inode), file->f_mode & FMODE_WRITE); +#endif v9fs_open_fid_add(inode, &fid); return 0; out_error: diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 27a04a226d97..33e521c60e2c 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -843,8 +843,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *= dentry, inode =3D d_inode(dentry); v9inode =3D V9FS_I(inode); mutex_lock(&v9inode->v_mutex); - if ((v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE= ) && - !v9inode->writeback_fid && + if ((v9ses->cache) && !v9inode->writeback_fid && ((flags & O_ACCMODE) !=3D O_RDONLY)) { /* * clone a fid and add it to writeback_fid diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index f806b3f11649..bff37a312e64 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -316,8 +316,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct den= try *dentry, =20 v9inode =3D V9FS_I(inode); mutex_lock(&v9inode->v_mutex); - if ((v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE= ) && - !v9inode->writeback_fid && + if ((v9ses->cache) && !v9inode->writeback_fid && ((flags & O_ACCMODE) !=3D O_RDONLY)) { /* * clone a fid and add it to writeback_fid @@ -340,9 +339,11 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct de= ntry *dentry, if (err) goto out; file->private_data =3D ofid; - if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE) +#ifdef CONFIG_9P_FSCACHE + if (v9ses->cache =3D=3D CACHE_FSCACHE) fscache_use_cookie(v9fs_inode_cookie(v9inode), file->f_mode & FMODE_WRITE); +#endif v9fs_open_fid_add(inode, &ofid); file->f_mode |=3D FMODE_CREATED; out: --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 A5953C05027 for ; Sat, 18 Feb 2023 00:44:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230113AbjBRAoN (ORCPT ); Fri, 17 Feb 2023 19:44:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbjBRAoL (ORCPT ); Fri, 17 Feb 2023 19:44:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E69C012F2C; Fri, 17 Feb 2023 16:43:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 925BA620A2; Sat, 18 Feb 2023 00:33:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3027CC4339E; Sat, 18 Feb 2023 00:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680437; bh=mymNDkevMQYIG0EuJKwW+vW2nl/JDaGZIYQfwskVSfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uLQAga7q/Yf63DHmXWtGMAdDbmgyinqRuLR5Cd4JwVopda5N651oAOiuuFjWrePhF Hu31gqYKiKFt11Dz/jceTkCER1qHjNY4tcKY9WgNG4hDVsLxmJTG0kdunfReq5itkq NAMdyp64Ry9U2e3Armd8itTU7D9YNaQmm8lEkvlCswRXwvfoHoD6ZjQwc5w7+3FB9T yOpvYyHwcgjjH2A7nywMpHok7NXN/bNl9RIRBbCajXBWsIIqY8yENgfl9kp4F6NVfm caX5mh1zBdlGRpLon08U5Nt8fodGzMWF9uVCuJRxMf7LXTFFzWKzCYMUBaSzVOSkO/ 8BPrVqMfdBtlA== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 03/11] fs/9p: Consolidate file operations and add readahead and writeback Date: Sat, 18 Feb 2023 00:33:15 +0000 Message-Id: <20230218003323.2322580-4-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We had 3 different sets of file operations across 2 different protocol variants differentiated by cache which really only changed 3 functions. But the real problem is that certain file modes, mount options, and other factors weren't being considered when we decided whether or not to use caches. This consolidates all the operations and switches to conditionals within a common set to decide whether or not to do different aspects of caching. Signed-off-by: Eric Van Hensbergen Reviewed-by: Dominique Martinet --- fs/9p/v9fs.c | 30 ++++------ fs/9p/v9fs.h | 3 + fs/9p/v9fs_vfs.h | 4 -- fs/9p/vfs_dir.c | 3 + fs/9p/vfs_file.c | 131 +++++++---------------------------------- fs/9p/vfs_inode.c | 62 ++++++++++++------- fs/9p/vfs_inode_dotl.c | 22 +++++-- 7 files changed, 98 insertions(+), 157 deletions(-) diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index 61a51b90600d..a46bf9121f11 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c @@ -39,8 +39,6 @@ enum { Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag, /* Options that take no arguments */ Opt_nodevmap, - /* Cache options */ - Opt_cache_loose, Opt_fscache, Opt_mmap, /* Access options */ Opt_access, Opt_posixacl, /* Lock timeout option */ @@ -58,9 +56,6 @@ static const match_table_t tokens =3D { {Opt_remotename, "aname=3D%s"}, {Opt_nodevmap, "nodevmap"}, {Opt_cache, "cache=3D%s"}, - {Opt_cache_loose, "loose"}, - {Opt_fscache, "fscache"}, - {Opt_mmap, "mmap"}, {Opt_cachetag, "cachetag=3D%s"}, {Opt_access, "access=3D%s"}, {Opt_posixacl, "posixacl"}, @@ -69,10 +64,12 @@ static const match_table_t tokens =3D { }; =20 static const char *const v9fs_cache_modes[nr__p9_cache_modes] =3D { - [CACHE_NONE] =3D "none", - [CACHE_MMAP] =3D "mmap", - [CACHE_LOOSE] =3D "loose", - [CACHE_FSCACHE] =3D "fscache", + [CACHE_NONE] =3D "none", + [CACHE_READAHEAD] =3D "readahead", + [CACHE_WRITEBACK] =3D "writeback", + [CACHE_MMAP] =3D "mmap", + [CACHE_LOOSE] =3D "loose", + [CACHE_FSCACHE] =3D "fscache", }; =20 /* Interpret mount options for cache mode */ @@ -89,6 +86,12 @@ static int get_cache_mode(char *s) } else if (!strcmp(s, "mmap")) { version =3D CACHE_MMAP; p9_debug(P9_DEBUG_9P, "Cache mode: mmap\n"); + } else if (!strcmp(s, "writeback")) { + version =3D CACHE_WRITEBACK; + p9_debug(P9_DEBUG_9P, "Cache mode: writeback\n"); + } else if (!strcmp(s, "readahead")) { + version =3D CACHE_READAHEAD; + p9_debug(P9_DEBUG_9P, "Cache mode: readahead\n"); } else if (!strcmp(s, "none")) { version =3D CACHE_NONE; p9_debug(P9_DEBUG_9P, "Cache mode: none\n"); @@ -266,15 +269,6 @@ static int v9fs_parse_options(struct v9fs_session_info= *v9ses, char *opts) case Opt_nodevmap: v9ses->nodev =3D 1; break; - case Opt_cache_loose: - v9ses->cache =3D CACHE_LOOSE; - break; - case Opt_fscache: - v9ses->cache =3D CACHE_FSCACHE; - break; - case Opt_mmap: - v9ses->cache =3D CACHE_MMAP; - break; case Opt_cachetag: #ifdef CONFIG_9P_FSCACHE kfree(v9ses->cachetag); diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index 6acabc2e7dc9..517b2201ad24 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h @@ -51,6 +51,8 @@ enum p9_session_flags { enum p9_cache_modes { CACHE_NONE, CACHE_MMAP, + CACHE_READAHEAD, + CACHE_WRITEBACK, CACHE_LOOSE, CACHE_FSCACHE, nr__p9_cache_modes @@ -155,6 +157,7 @@ extern int v9fs_vfs_rename(struct user_namespace *mnt_u= serns, struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags); +extern int v9fs_flush_inode_writeback(struct inode *inode); extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, struct super_block *sb, int new); diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h index bc417da7e9c1..cce87c9bdd8b 100644 --- a/fs/9p/v9fs_vfs.h +++ b/fs/9p/v9fs_vfs.h @@ -36,10 +36,6 @@ extern const struct file_operations v9fs_dir_operations; extern const struct file_operations v9fs_dir_operations_dotl; extern const struct dentry_operations v9fs_dentry_operations; extern const struct dentry_operations v9fs_cached_dentry_operations; -extern const struct file_operations v9fs_cached_file_operations; -extern const struct file_operations v9fs_cached_file_operations_dotl; -extern const struct file_operations v9fs_mmap_file_operations; -extern const struct file_operations v9fs_mmap_file_operations_dotl; extern struct kmem_cache *v9fs_inode_cache; =20 struct inode *v9fs_alloc_inode(struct super_block *sb); diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 59b0e8948f78..bd31593437f3 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -214,6 +214,9 @@ int v9fs_dir_release(struct inode *inode, struct file *= filp) p9_debug(P9_DEBUG_VFS, "inode: %p filp: %p fid: %d\n", inode, filp, fid ? fid->fid : -1); if (fid) { + if ((fid->qid.type =3D=3D P9_QTFILE) && (filp->f_mode & FMODE_WRITE)) + v9fs_flush_inode_writeback(inode); + spin_lock(&inode->i_lock); hlist_del(&fid->ilist); spin_unlock(&inode->i_lock); diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 3b6458846a0b..20e4bd299fc2 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -28,7 +28,6 @@ #include "fid.h" #include "cache.h" =20 -static const struct vm_operations_struct v9fs_file_vm_ops; static const struct vm_operations_struct v9fs_mmap_file_vm_ops; =20 /** @@ -73,7 +72,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) } =20 mutex_lock(&v9inode->v_mutex); - if ((v9ses->cache) && !v9inode->writeback_fid && + if ((v9ses->cache >=3D CACHE_WRITEBACK) && !v9inode->writeback_fid && ((file->f_flags & O_ACCMODE) !=3D O_RDONLY)) { /* * clone a fid and add it to writeback_fid @@ -367,10 +366,15 @@ v9fs_file_read_iter(struct kiocb *iocb, struct iov_it= er *to) { struct p9_fid *fid =3D iocb->ki_filp->private_data; int ret, err =3D 0; + struct inode *inode =3D file_inode(iocb->ki_filp); + struct v9fs_session_info *v9ses =3D v9fs_inode2v9ses(inode); =20 p9_debug(P9_DEBUG_VFS, "count %zu offset %lld\n", iov_iter_count(to), iocb->ki_pos); =20 + if (v9ses->cache > CACHE_MMAP) + return generic_file_read_iter(iocb, to); + if (iocb->ki_filp->f_flags & O_NONBLOCK) ret =3D p9_client_read_once(fid, iocb->ki_pos, to, &err); else @@ -395,6 +399,11 @@ v9fs_file_write_iter(struct kiocb *iocb, struct iov_it= er *from) ssize_t retval; loff_t origin; int err =3D 0; + struct inode *inode =3D file_inode(iocb->ki_filp); + struct v9fs_session_info *v9ses =3D v9fs_inode2v9ses(inode); + + if (v9ses->cache >=3D CACHE_WRITEBACK) + return generic_file_write_iter(iocb, from); =20 retval =3D generic_write_checks(iocb, from); if (retval <=3D 0) @@ -477,25 +486,16 @@ static int v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma) { int retval; - - - retval =3D generic_file_mmap(filp, vma); - if (!retval) - vma->vm_ops =3D &v9fs_file_vm_ops; - - return retval; -} - -static int -v9fs_mmap_file_mmap(struct file *filp, struct vm_area_struct *vma) -{ - int retval; - struct inode *inode; - struct v9fs_inode *v9inode; + struct inode *inode =3D file_inode(filp); + struct v9fs_inode *v9inode =3D V9FS_I(inode); + struct v9fs_session_info *v9ses =3D v9fs_inode2v9ses(inode); struct p9_fid *fid; =20 - inode =3D file_inode(filp); - v9inode =3D V9FS_I(inode); + if (v9ses->cache < CACHE_MMAP) { + invalidate_inode_pages2(filp->f_mapping); + return generic_file_readonly_mmap(filp, vma); + } + mutex_lock(&v9inode->v_mutex); if (!v9inode->writeback_fid && (vma->vm_flags & VM_SHARED) && @@ -563,35 +563,6 @@ v9fs_vm_page_mkwrite(struct vm_fault *vmf) return VM_FAULT_NOPAGE; } =20 -/** - * v9fs_mmap_file_read_iter - read from a file - * @iocb: The operation parameters - * @to: The buffer to read into - * - */ -static ssize_t -v9fs_mmap_file_read_iter(struct kiocb *iocb, struct iov_iter *to) -{ - /* TODO: Check if there are dirty pages */ - return v9fs_file_read_iter(iocb, to); -} - -/** - * v9fs_mmap_file_write_iter - write to a file - * @iocb: The operation parameters - * @from: The data to write - * - */ -static ssize_t -v9fs_mmap_file_write_iter(struct kiocb *iocb, struct iov_iter *from) -{ - /* - * TODO: invalidate mmaps on filp's inode between - * offset and offset+count - */ - return v9fs_file_write_iter(iocb, from); -} - static void v9fs_mmap_vm_close(struct vm_area_struct *vma) { struct inode *inode; @@ -614,13 +585,6 @@ static void v9fs_mmap_vm_close(struct vm_area_struct *= vma) filemap_fdatawrite_wbc(inode->i_mapping, &wbc); } =20 - -static const struct vm_operations_struct v9fs_file_vm_ops =3D { - .fault =3D filemap_fault, - .map_pages =3D filemap_map_pages, - .page_mkwrite =3D v9fs_vm_page_mkwrite, -}; - static const struct vm_operations_struct v9fs_mmap_file_vm_ops =3D { .close =3D v9fs_mmap_vm_close, .fault =3D filemap_fault, @@ -628,34 +592,6 @@ static const struct vm_operations_struct v9fs_mmap_fil= e_vm_ops =3D { .page_mkwrite =3D v9fs_vm_page_mkwrite, }; =20 - -const struct file_operations v9fs_cached_file_operations =3D { - .llseek =3D generic_file_llseek, - .read_iter =3D generic_file_read_iter, - .write_iter =3D generic_file_write_iter, - .open =3D v9fs_file_open, - .release =3D v9fs_dir_release, - .lock =3D v9fs_file_lock, - .mmap =3D v9fs_file_mmap, - .splice_read =3D generic_file_splice_read, - .splice_write =3D iter_file_splice_write, - .fsync =3D v9fs_file_fsync, -}; - -const struct file_operations v9fs_cached_file_operations_dotl =3D { - .llseek =3D generic_file_llseek, - .read_iter =3D generic_file_read_iter, - .write_iter =3D generic_file_write_iter, - .open =3D v9fs_file_open, - .release =3D v9fs_dir_release, - .lock =3D v9fs_file_lock_dotl, - .flock =3D v9fs_file_flock_dotl, - .mmap =3D v9fs_file_mmap, - .splice_read =3D generic_file_splice_read, - .splice_write =3D iter_file_splice_write, - .fsync =3D v9fs_file_fsync_dotl, -}; - const struct file_operations v9fs_file_operations =3D { .llseek =3D generic_file_llseek, .read_iter =3D v9fs_file_read_iter, @@ -677,34 +613,7 @@ const struct file_operations v9fs_file_operations_dotl= =3D { .release =3D v9fs_dir_release, .lock =3D v9fs_file_lock_dotl, .flock =3D v9fs_file_flock_dotl, - .mmap =3D generic_file_readonly_mmap, - .splice_read =3D generic_file_splice_read, - .splice_write =3D iter_file_splice_write, - .fsync =3D v9fs_file_fsync_dotl, -}; - -const struct file_operations v9fs_mmap_file_operations =3D { - .llseek =3D generic_file_llseek, - .read_iter =3D v9fs_mmap_file_read_iter, - .write_iter =3D v9fs_mmap_file_write_iter, - .open =3D v9fs_file_open, - .release =3D v9fs_dir_release, - .lock =3D v9fs_file_lock, - .mmap =3D v9fs_mmap_file_mmap, - .splice_read =3D generic_file_splice_read, - .splice_write =3D iter_file_splice_write, - .fsync =3D v9fs_file_fsync, -}; - -const struct file_operations v9fs_mmap_file_operations_dotl =3D { - .llseek =3D generic_file_llseek, - .read_iter =3D v9fs_mmap_file_read_iter, - .write_iter =3D v9fs_mmap_file_write_iter, - .open =3D v9fs_file_open, - .release =3D v9fs_dir_release, - .lock =3D v9fs_file_lock_dotl, - .flock =3D v9fs_file_flock_dotl, - .mmap =3D v9fs_mmap_file_mmap, + .mmap =3D v9fs_file_mmap, .splice_read =3D generic_file_splice_read, .splice_write =3D iter_file_splice_write, .fsync =3D v9fs_file_fsync_dotl, diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 33e521c60e2c..8ffa6631b1fd 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -219,6 +219,35 @@ v9fs_blank_wstat(struct p9_wstat *wstat) wstat->extension =3D NULL; } =20 +/** + * v9fs_flush_inode_writeback - writeback any data associated with inode + * @inode: inode to writeback + * + * This is used to make sure anything that needs to be written + * to server gets flushed before we do certain operations (setattr, getatt= r, close) + * + */ + +int v9fs_flush_inode_writeback(struct inode *inode) +{ + struct writeback_control wbc =3D { + .nr_to_write =3D LONG_MAX, + .sync_mode =3D WB_SYNC_ALL, + .range_start =3D 0, + .range_end =3D -1, + }; + + int retval =3D filemap_fdatawrite_wbc(inode->i_mapping, &wbc); + + if (retval !=3D 0) { + p9_debug(P9_DEBUG_ERROR, + "trying to flush inode %p failed with error code %d\n", + inode, retval); + } + + return retval; +} + /** * v9fs_alloc_inode - helper function to allocate an inode * @sb: The superblock to allocate the inode from @@ -287,24 +316,10 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses, case S_IFREG: if (v9fs_proto_dotl(v9ses)) { inode->i_op =3D &v9fs_file_inode_operations_dotl; - if (v9ses->cache =3D=3D CACHE_LOOSE || - v9ses->cache =3D=3D CACHE_FSCACHE) - inode->i_fop =3D - &v9fs_cached_file_operations_dotl; - else if (v9ses->cache =3D=3D CACHE_MMAP) - inode->i_fop =3D &v9fs_mmap_file_operations_dotl; - else - inode->i_fop =3D &v9fs_file_operations_dotl; + inode->i_fop =3D &v9fs_file_operations_dotl; } else { inode->i_op =3D &v9fs_file_inode_operations; - if (v9ses->cache =3D=3D CACHE_LOOSE || - v9ses->cache =3D=3D CACHE_FSCACHE) - inode->i_fop =3D - &v9fs_cached_file_operations; - else if (v9ses->cache =3D=3D CACHE_MMAP) - inode->i_fop =3D &v9fs_mmap_file_operations; - else - inode->i_fop =3D &v9fs_file_operations; + inode->i_fop =3D &v9fs_file_operations; } =20 break; @@ -843,7 +858,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *= dentry, inode =3D d_inode(dentry); v9inode =3D V9FS_I(inode); mutex_lock(&v9inode->v_mutex); - if ((v9ses->cache) && !v9inode->writeback_fid && + if ((v9ses->cache >=3D CACHE_WRITEBACK) && !v9inode->writeback_fid && ((flags & O_ACCMODE) !=3D O_RDONLY)) { /* * clone a fid and add it to writeback_fid @@ -1030,6 +1045,7 @@ v9fs_vfs_getattr(struct user_namespace *mnt_userns, c= onst struct path *path, struct kstat *stat, u32 request_mask, unsigned int flags) { struct dentry *dentry =3D path->dentry; + struct inode *inode =3D d_inode(dentry); struct v9fs_session_info *v9ses; struct p9_fid *fid; struct p9_wstat *st; @@ -1039,6 +1055,9 @@ v9fs_vfs_getattr(struct user_namespace *mnt_userns, c= onst struct path *path, if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE)= { generic_fillattr(&init_user_ns, d_inode(dentry), stat); return 0; + } else if (v9ses->cache >=3D CACHE_WRITEBACK) { + if (S_ISREG(inode->i_mode)) + v9fs_flush_inode_writeback(inode); } fid =3D v9fs_fid_lookup(dentry); if (IS_ERR(fid)) @@ -1116,7 +1135,7 @@ static int v9fs_vfs_setattr(struct user_namespace *mn= t_userns, =20 /* Write all dirty data */ if (d_is_reg(dentry)) - filemap_write_and_wait(inode->i_mapping); + v9fs_flush_inode_writeback(inode); =20 retval =3D p9_client_wstat(fid, &wstat); =20 @@ -1127,9 +1146,12 @@ static int v9fs_vfs_setattr(struct user_namespace *m= nt_userns, return retval; =20 if ((iattr->ia_valid & ATTR_SIZE) && - iattr->ia_size !=3D i_size_read(inode)) { + iattr->ia_size !=3D i_size_read(inode)) { truncate_setsize(inode, iattr->ia_size); - fscache_resize_cookie(v9fs_inode_cookie(v9inode), iattr->ia_size); + if (v9ses->cache =3D=3D CACHE_FSCACHE) + fscache_resize_cookie(v9fs_inode_cookie(v9inode), iattr->ia_size); + else + invalidate_mapping_pages(&inode->i_data, 0, -1); } =20 v9fs_invalidate_inode_attr(inode); diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index bff37a312e64..4f01808c3bae 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -458,6 +458,7 @@ v9fs_vfs_getattr_dotl(struct user_namespace *mnt_userns, struct dentry *dentry =3D path->dentry; struct v9fs_session_info *v9ses; struct p9_fid *fid; + struct inode *inode =3D d_inode(dentry); struct p9_stat_dotl *st; =20 p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry); @@ -465,6 +466,10 @@ v9fs_vfs_getattr_dotl(struct user_namespace *mnt_usern= s, if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE)= { generic_fillattr(&init_user_ns, d_inode(dentry), stat); return 0; + } else if (v9ses->cache >=3D CACHE_WRITEBACK) { + if (S_ISREG(inode->i_mode)) + v9fs_flush_inode_writeback(inode); + } fid =3D v9fs_fid_lookup(dentry); if (IS_ERR(fid)) @@ -540,12 +545,14 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_= userns, struct dentry *dentry, struct iattr *iattr) { int retval, use_dentry =3D 0; + struct inode *inode =3D d_inode(dentry); + struct v9fs_inode *v9inode =3D V9FS_I(inode); + struct v9fs_session_info *v9ses; struct p9_fid *fid =3D NULL; struct p9_iattr_dotl p9attr =3D { .uid =3D INVALID_UID, .gid =3D INVALID_GID, }; - struct inode *inode =3D d_inode(dentry); =20 p9_debug(P9_DEBUG_VFS, "\n"); =20 @@ -553,6 +560,8 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_us= erns, if (retval) return retval; =20 + v9ses =3D v9fs_dentry2v9ses(dentry); + p9attr.valid =3D v9fs_mapped_iattr_valid(iattr->ia_valid); if (iattr->ia_valid & ATTR_MODE) p9attr.mode =3D iattr->ia_mode; @@ -584,7 +593,7 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_us= erns, =20 /* Write all dirty data */ if (S_ISREG(inode->i_mode)) - filemap_write_and_wait(inode->i_mapping); + v9fs_flush_inode_writeback(inode); =20 retval =3D p9_client_setattr(fid, &p9attr); if (retval < 0) { @@ -593,9 +602,14 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_u= serns, return retval; } =20 - if ((iattr->ia_valid & ATTR_SIZE) && - iattr->ia_size !=3D i_size_read(inode)) + if ((iattr->ia_valid & ATTR_SIZE) && iattr->ia_size !=3D + i_size_read(inode)) { truncate_setsize(inode, iattr->ia_size); + if (v9ses->cache =3D=3D CACHE_FSCACHE) + fscache_resize_cookie(v9fs_inode_cookie(v9inode), iattr->ia_size); + else + invalidate_mapping_pages(&inode->i_data, 0, -1); + } =20 v9fs_invalidate_inode_attr(inode); setattr_copy(&init_user_ns, inode, iattr); --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 B1852C636D6 for ; Sat, 18 Feb 2023 00:35:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbjBRAfy (ORCPT ); Fri, 17 Feb 2023 19:35:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbjBRAfw (ORCPT ); Fri, 17 Feb 2023 19:35:52 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDFC883F7; Fri, 17 Feb 2023 16:35:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 98EF6620A7; Sat, 18 Feb 2023 00:33:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F4C2C433A0; Sat, 18 Feb 2023 00:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680438; bh=r7VYuVAQDU98smxxlBwk5mo68iLowdZ4mILXuE17YKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sDJ1tW0nJd35lXKg/oEsGs3Ne79q5RUlNKJDhBoD/8r2U17+sfDm/9TIdBPUfTFp8 PGDwxrROXHSZvpgHxEO+DmkbufWFUSZ1tKsY+eywqQMKQhG7nOrY8YylC0Co29AjER Tang6L0vTIU+SYJJo8r3oqG3c5+CWkIRlNTZfMw73FCXjXQXE0yqX8lqC4pzGL0qzo UUg22R5WDeTe3nTQpDehgTaMut4l+XnBpZp+H7x9EoaPrWg7WKqkTEgdW5zMQEYbl9 zcULamDlKZwhtpnYeq+ogRkPovsOb9QrWMOLPWUvUGdr+iCZLPQ6TWtpvjrGlEfsw/ TaEUfsQFg9uWg== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 04/11] fs/9p: Remove unnecessary superblock flags Date: Sat, 18 Feb 2023 00:33:16 +0000 Message-Id: <20230218003323.2322580-5-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" These flags just add unnecessary extra operations. When 9p is run without cache, it inherently implements these options so we don't need them in the superblock (which ends up sending extraneous fsyncs, etc.). User can still request these options on mount, but we don't need to set them as default. Signed-off-by: Eric Van Hensbergen --- fs/9p/vfs_super.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index 266c4693e20c..65d96fa94ba2 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c @@ -84,9 +84,7 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_sessi= on_info *v9ses, sb->s_bdi->io_pages =3D v9ses->maxdata >> PAGE_SHIFT; } =20 - sb->s_flags |=3D SB_ACTIVE | SB_DIRSYNC; - if (!v9ses->cache) - sb->s_flags |=3D SB_SYNCHRONOUS; + sb->s_flags |=3D SB_ACTIVE; =20 #ifdef CONFIG_9P_FS_POSIX_ACL if ((v9ses->flags & V9FS_ACL_MASK) =3D=3D V9FS_POSIX_ACL) --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 DE06FC64ED6 for ; Sat, 18 Feb 2023 00:49:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229787AbjBRAtN (ORCPT ); Fri, 17 Feb 2023 19:49:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229678AbjBRAtF (ORCPT ); Fri, 17 Feb 2023 19:49:05 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 051305CF3A; Fri, 17 Feb 2023 16:48:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 65B10B82EA6; Sat, 18 Feb 2023 00:34:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49C24C4339B; Sat, 18 Feb 2023 00:33:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680439; bh=rvDymktanf6MSiAzIPMCTiULQZumTY7dlyrm9CYAra8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y5s5bduuvTJwpmyQLndx1q3QKOTxY+MAvEohBtO6bBJ6vHrq0ksXVYJ4u2Gl+9nSl 7K/36OoDsVN6AUW7UiEMpCLQvbsTDVB7peDF132Xy4u9m9XIYPWa2aYp3Wj9zjVFq6 dq2VzOo8zBT6Jd0kbQdknCeq3vsB4VPHVDGQ/9AoqdOE2m6TiKPvYLl5cjsJWaYmFF CfCy0IhVlokPKNpaYe5gmjDFNdJSAG0uMMBTD1/lORsD75nBYeYx5MoeU0sdMMi9IX F063gTxW5kJw2iG0n9bqEs/7mmCZmQ5AyzI/CjWrvUtFGYWbfDHeCRqs6hfLuBgADl OkLTeNp9oxs8g== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 05/11] fs/9p: allow disable of xattr support on mount Date: Sat, 18 Feb 2023 00:33:17 +0000 Message-Id: <20230218003323.2322580-6-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" xattr creates a lot of additional messages for 9p in the current implementation. This allows users to conditionalize xattr support on 9p mount if they are on a connection with bad latency. Using this flag is also useful when debugging other aspects of 9p as it reduces the noise in the trace files. Signed-off-by: Eric Van Hensbergen Reviewed-by: Dominique Martinet --- Documentation/filesystems/9p.rst | 2 ++ fs/9p/v9fs.c | 9 ++++++++- fs/9p/v9fs.h | 3 ++- fs/9p/vfs_super.c | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Documentation/filesystems/9p.rst b/Documentation/filesystems/9= p.rst index 7b5964bc8865..0e800b8f73cc 100644 --- a/Documentation/filesystems/9p.rst +++ b/Documentation/filesystems/9p.rst @@ -137,6 +137,8 @@ Options This can be used to share devices/named pipes/sockets between hosts. This functionality will be expanded in later versions. =20 + noxattr do not offer xattr functions on this mount. + access there are four access modes. user if a user tries to access a file on v9fs diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index a46bf9121f11..f8e952c013f9 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c @@ -38,7 +38,7 @@ enum { /* String options */ Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag, /* Options that take no arguments */ - Opt_nodevmap, + Opt_nodevmap, Opt_noxattr, /* Access options */ Opt_access, Opt_posixacl, /* Lock timeout option */ @@ -55,6 +55,7 @@ static const match_table_t tokens =3D { {Opt_uname, "uname=3D%s"}, {Opt_remotename, "aname=3D%s"}, {Opt_nodevmap, "nodevmap"}, + {Opt_noxattr, "noxattr"}, {Opt_cache, "cache=3D%s"}, {Opt_cachetag, "cachetag=3D%s"}, {Opt_access, "access=3D%s"}, @@ -149,6 +150,9 @@ int v9fs_show_options(struct seq_file *m, struct dentry= *root) if (v9ses->flags & V9FS_POSIX_ACL) seq_puts(m, ",posixacl"); =20 + if (v9ses->flags & V9FS_NO_XATTR) + seq_puts(m, ",noxattr"); + return p9_show_client_options(m, v9ses->clnt); } =20 @@ -269,6 +273,9 @@ static int v9fs_parse_options(struct v9fs_session_info = *v9ses, char *opts) case Opt_nodevmap: v9ses->nodev =3D 1; break; + case Opt_noxattr: + v9ses->flags |=3D V9FS_NO_XATTR; + break; case Opt_cachetag: #ifdef CONFIG_9P_FSCACHE kfree(v9ses->cachetag); diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index 517b2201ad24..d90141d25d0d 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h @@ -36,7 +36,8 @@ enum p9_session_flags { V9FS_ACCESS_SINGLE =3D 0x04, V9FS_ACCESS_USER =3D 0x08, V9FS_ACCESS_CLIENT =3D 0x10, - V9FS_POSIX_ACL =3D 0x20 + V9FS_POSIX_ACL =3D 0x20, + V9FS_NO_XATTR =3D 0x40 }; =20 /* possible values of ->cache */ diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index 65d96fa94ba2..5fc6a945bfff 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c @@ -64,7 +64,8 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_sessi= on_info *v9ses, sb->s_magic =3D V9FS_MAGIC; if (v9fs_proto_dotl(v9ses)) { sb->s_op =3D &v9fs_super_ops_dotl; - sb->s_xattr =3D v9fs_xattr_handlers; + if (!(v9ses->flags & V9FS_NO_XATTR)) + sb->s_xattr =3D v9fs_xattr_handlers; } else { sb->s_op =3D &v9fs_super_ops; sb->s_time_max =3D U32_MAX; --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 78690C05027 for ; Sat, 18 Feb 2023 00:41:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229496AbjBRAlY (ORCPT ); Fri, 17 Feb 2023 19:41:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbjBRAlV (ORCPT ); Fri, 17 Feb 2023 19:41:21 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 043616D245; Fri, 17 Feb 2023 16:40:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4E242B82EB3; Sat, 18 Feb 2023 00:34:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5136AC433EF; Sat, 18 Feb 2023 00:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680440; bh=Ok4fLl47ydowKVxThK8D575DI78XULsYZEvV5sQqQ3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ca0eOXl9ADJhsTGTNxOb4mqO6T2bOzENafCVhVAm0mc7ONXbnuaPYU4OAjdctPxYr PUo1IhvajR87EijDJTzX5g0oyLby1fPOxQCK1LLzQ8rGhDkD/uNKawSj1QTf5rqFJ6 F6mvmr32jGwLhcDR0laMVj5xemgb0Eakz5y0vZjaNyROYFV6vho8H3FhFJ3B8H4eFV E3CfKi4Z1mmtBNAfXEfv3iT6OqevRcyCRHUjcsZgxucBOoAEJKeXS+cq0cvwWFKYiu U9BFA32XpUCxRjDCchHpdIKUxb+xC9llr2zVITdTbqaafSWtqPCoX59XT5oWGUh5Ps z5Mi5F8D5jXNA== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 06/11] net/9p: fix bug in client create for .L Date: Sat, 18 Feb 2023 00:33:18 +0000 Message-Id: <20230218003323.2322580-7-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We are supposed to set fid->mode to reflect the flags that were used to open the file. We were actually setting it to the creation mode which is the default perms of the file not the flags the file was opened with. Signed-off-by: Eric Van Hensbergen Reviewed-by: Dominique Martinet --- net/9p/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/9p/client.c b/net/9p/client.c index 6c2a768a6ab1..2adcb5e7b0e2 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1293,7 +1293,7 @@ int p9_client_create_dotl(struct p9_fid *ofid, const = char *name, u32 flags, qid->type, qid->path, qid->version, iounit); =20 memmove(&ofid->qid, qid, sizeof(struct p9_qid)); - ofid->mode =3D mode; + ofid->mode =3D flags; ofid->iounit =3D iounit; =20 free_and_error: --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 AD81CC636D6 for ; Sat, 18 Feb 2023 00:36:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229953AbjBRAga (ORCPT ); Fri, 17 Feb 2023 19:36:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbjBRAg2 (ORCPT ); Fri, 17 Feb 2023 19:36:28 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73FF36D251; Fri, 17 Feb 2023 16:35:57 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B308E6209C; Sat, 18 Feb 2023 00:34:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54E37C433D2; Sat, 18 Feb 2023 00:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680441; bh=cW3tqr7Wz1/+iCrGEv007ARmFZP9bjEOtTw2DUtSkXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n66eBIPF5VOPlydJO6o1F9Id9ahHIQmnpN9qb9pfpbH2CclkG8oyade30qFmGYJHc IkNEcigIpm9Y/Zk6c0an3pmtrIf93u6e9mKMpaQ7ROqpkAN9p6+TWZxSOoGtn1GEsl qMARtGiDDlKjmJOUEqJtvKAjUahxqFbIHqf4kjlDvYueYDzZ5qqygu9fGUe1wobML8 JaSTrVbi1pGfB2C8zeD9slAWsW39qcybUL1TwF8ZtrKB9WyIS2P9Sr3J0npQgsfUTH r2oG9P+csiuyYPLQKnAo0fwOg5jXFwYauD+0V5i7nALf/3S8dUGbE1BFAFyD1ysu5O X/SFmxVdZ2vGg== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 07/11] 9p: Add additional debug flags and open modes Date: Sat, 18 Feb 2023 00:33:19 +0000 Message-Id: <20230218003323.2322580-8-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add some additional debug flags to assist with debugging cache changes. Also add some additional open modes so we can track cache state in fids more directly. Signed-off-by: Eric Van Hensbergen --- include/net/9p/9p.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h index 429adf6be29c..61c20b89becd 100644 --- a/include/net/9p/9p.h +++ b/include/net/9p/9p.h @@ -42,6 +42,8 @@ enum p9_debug_flags { P9_DEBUG_PKT =3D (1<<10), P9_DEBUG_FSC =3D (1<<11), P9_DEBUG_VPKT =3D (1<<12), + P9_DEBUG_CACHE =3D (1<<13), + P9_DEBUG_MMAP =3D (1<<14), }; =20 #ifdef CONFIG_NET_9P_DEBUG @@ -213,6 +215,9 @@ enum p9_open_mode_t { P9_ORCLOSE =3D 0x40, P9_OAPPEND =3D 0x80, P9_OEXCL =3D 0x1000, + P9L_DIRECT =3D 0x2000, /* cache disabled */ + P9L_NOWRITECACHE =3D 0x4000, /* no write caching */ + P9L_LOOSE =3D 0x8000, /* loose cache */ }; =20 /** --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 EFE2DC05027 for ; Sat, 18 Feb 2023 00:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229637AbjBRApW (ORCPT ); Fri, 17 Feb 2023 19:45:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbjBRApI (ORCPT ); Fri, 17 Feb 2023 19:45:08 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B2D56E67E; Fri, 17 Feb 2023 16:44:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 856D6B82EDB; Sat, 18 Feb 2023 00:34:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61CB8C4339E; Sat, 18 Feb 2023 00:34:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680442; bh=KENVm6Mybvc2iHuCzsErqi8WG1g+ScHvDff49cLzyDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k2zvKVLYQRYHVPCHNW4CkVsb+xtQmWFci14aAHMmH5MuhKOi5lq8QRlpLTzVC7jcv +eKBBcUB1xn7Q8YXHws7r0KqMU64v+Hi78jLoj4GRyIfUsAFqRsGXYacyVThPsKL7N Y7p2mn4y024cFomTPs83Gt2ARvuZAqJ/fwgVKQiCtYM95oCIhecekSRfR9jXd863Ht 77GpUmI/2rEgtZAJD0ZIhaSB8mx1SbPlR2DAPqNt2fhJZF+tB56mq8rV+jXxKQux+1 aXAjJvGX0vsSjDqF3W1R2BABHde2pKPUvB7UU3gXu/FR9oXlQb4LnLXTnTe3sTMhvt TkZX5pCShykFQ== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 08/11] fs/9p: Add new mount modes Date: Sat, 18 Feb 2023 00:33:20 +0000 Message-Id: <20230218003323.2322580-9-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add some additional mount modes for cache management including specifying directio as a mount option and an option for ignore qid.version for determining whether or not a file is cacheable. Signed-off-by: Eric Van Hensbergen --- fs/9p/v9fs.c | 16 ++++++++++++++-- fs/9p/v9fs.h | 5 ++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index f8e952c013f9..43d3806150a9 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c @@ -38,7 +38,7 @@ enum { /* String options */ Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag, /* Options that take no arguments */ - Opt_nodevmap, Opt_noxattr, + Opt_nodevmap, Opt_noxattr, Opt_directio, Opt_ignoreqv, /* Access options */ Opt_access, Opt_posixacl, /* Lock timeout option */ @@ -56,6 +56,8 @@ static const match_table_t tokens =3D { {Opt_remotename, "aname=3D%s"}, {Opt_nodevmap, "nodevmap"}, {Opt_noxattr, "noxattr"}, + {Opt_directio, "directio"}, + {Opt_ignoreqv, "ignoreqv"}, {Opt_cache, "cache=3D%s"}, {Opt_cachetag, "cachetag=3D%s"}, {Opt_access, "access=3D%s"}, @@ -125,7 +127,7 @@ int v9fs_show_options(struct seq_file *m, struct dentry= *root) if (v9ses->nodev) seq_puts(m, ",nodevmap"); if (v9ses->cache) - seq_printf(m, ",%s", v9fs_cache_modes[v9ses->cache]); + seq_printf(m, ",cache=3D%s", v9fs_cache_modes[v9ses->cache]); #ifdef CONFIG_9P_FSCACHE if (v9ses->cachetag && v9ses->cache =3D=3D CACHE_FSCACHE) seq_printf(m, ",cachetag=3D%s", v9ses->cachetag); @@ -147,6 +149,10 @@ int v9fs_show_options(struct seq_file *m, struct dentr= y *root) break; } =20 + if (v9ses->flags & V9FS_IGNORE_QV) + seq_puts(m, ",ignoreqv"); + if (v9ses->flags & V9FS_DIRECT_IO) + seq_puts(m, ",directio"); if (v9ses->flags & V9FS_POSIX_ACL) seq_puts(m, ",posixacl"); =20 @@ -276,6 +282,12 @@ static int v9fs_parse_options(struct v9fs_session_info= *v9ses, char *opts) case Opt_noxattr: v9ses->flags |=3D V9FS_NO_XATTR; break; + case Opt_directio: + v9ses->flags |=3D V9FS_DIRECT_IO; + break; + case Opt_ignoreqv: + v9ses->flags |=3D V9FS_IGNORE_QV; + break; case Opt_cachetag: #ifdef CONFIG_9P_FSCACHE kfree(v9ses->cachetag); diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index d90141d25d0d..48c7614c9333 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h @@ -37,7 +37,10 @@ enum p9_session_flags { V9FS_ACCESS_USER =3D 0x08, V9FS_ACCESS_CLIENT =3D 0x10, V9FS_POSIX_ACL =3D 0x20, - V9FS_NO_XATTR =3D 0x40 + V9FS_NO_XATTR =3D 0x40, + V9FS_IGNORE_QV =3D 0x80, + V9FS_DIRECT_IO =3D 0x100, + V9FS_SYNC =3D 0x200 }; =20 /* possible values of ->cache */ --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 D7E43C636D6 for ; Sat, 18 Feb 2023 00:44:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbjBRAoT (ORCPT ); Fri, 17 Feb 2023 19:44:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230103AbjBRAoN (ORCPT ); Fri, 17 Feb 2023 19:44:13 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0B1C3B21A; Fri, 17 Feb 2023 16:43:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C8907620AA; Sat, 18 Feb 2023 00:34:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F8D0C433A0; Sat, 18 Feb 2023 00:34:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680443; bh=nMiGIejp8egMtRxiDVnE9HTGeqlIR/0m0XbHmw05N0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JyAPiwayh+ahtkxPDlCeK7rK+JUasC7BwIhvdjEuJhjHIYVnxqfM2wATkuMr0ZAIZ YSNB8lijKrih19gWPp32j8lOYicYvyUbLGyYi8b5XoijJiA3+Vin2rtaO1tJdV5OQb YJAr3fDCRLKsT360UgqC7Gxy+zlVuThPw2uLjCAzP9S3RzY6zJ/v9QwsB7hYN8yj4U JTXQPgvYlhcjzVWOzYXDKQ+zef2mRPa13qwrhZM8GlOUN9GrET9ZUTaRSszMOMO+Qq xMnjHtPnfV3kyzh0iF8/k/YiezbHtJlLwOPN2HfvZtXY1/CwMLsvzwKT0lmglvUSKN fdvTZXscyjCzg== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 09/11] fs/9p: fix error reporting in v9fs_dir_release Date: Sat, 18 Feb 2023 00:33:21 +0000 Message-Id: <20230218003323.2322580-10-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Checking the p9_fid_put value allows us to pass back errors involved if we end up clunking the fid as part of dir_release. This can help with more graceful response to errors in writeback among other things. Signed-off-by: Eric Van Hensbergen Reviewed-by: Dominique Martinet --- fs/9p/vfs_dir.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index bd31593437f3..44918c60357f 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -197,7 +197,7 @@ static int v9fs_dir_readdir_dotl(struct file *file, str= uct dir_context *ctx) =20 =20 /** - * v9fs_dir_release - close a directory + * v9fs_dir_release - called on a close of a file or directory * @inode: inode of the directory * @filp: file pointer to a directory * @@ -209,6 +209,7 @@ int v9fs_dir_release(struct inode *inode, struct file *= filp) struct p9_fid *fid; __le32 version; loff_t i_size; + int retval =3D 0; =20 fid =3D filp->private_data; p9_debug(P9_DEBUG_VFS, "inode: %p filp: %p fid: %d\n", @@ -220,7 +221,7 @@ int v9fs_dir_release(struct inode *inode, struct file *= filp) spin_lock(&inode->i_lock); hlist_del(&fid->ilist); spin_unlock(&inode->i_lock); - p9_fid_put(fid); + retval =3D p9_fid_put(fid); } =20 if ((filp->f_mode & FMODE_WRITE)) { @@ -231,7 +232,7 @@ int v9fs_dir_release(struct inode *inode, struct file *= filp) } else { fscache_unuse_cookie(v9fs_inode_cookie(v9inode), NULL, NULL); } - return 0; + return retval; } =20 const struct file_operations v9fs_dir_operations =3D { --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 83A4FC636D6 for ; Sat, 18 Feb 2023 00:40:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbjBRAku (ORCPT ); Fri, 17 Feb 2023 19:40:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbjBRAkr (ORCPT ); Fri, 17 Feb 2023 19:40:47 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71442F776; Fri, 17 Feb 2023 16:40:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8F07DB82ED6; Sat, 18 Feb 2023 00:34:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7ACFFC4339C; Sat, 18 Feb 2023 00:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680444; bh=KJ9deFMojFpl3u+l/cyL8DHjpFaJjqmrjoujoFfiocQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M0BKipAaAwkd0Ow0bFmI5SmgYkvSBEEodiVCJMTDYkQ1uODcitDAer3LnfXinRp9a PO58nt7Dl3nmIvsEB+jQua+FFHlOdItBQQZjh68JnrP16SBEkv6A0W6QkLQHKbI5cO ZFwPguvCRAIHpHn2BJXScdsmaGplb83KjPLGPJjXpxqE1qhAiCa6PHT1tEPuCHUBVh 8650e8r52KDmKC27JnLnEXHLaTW4r/o1P6e3fLg2Qs/tVJ/tIzFFnpqS3b1my5rS4J pFQ+uBl1d+Qkvl9dQi4cOp33euL06l8u0Dw6Db1Hw1TbhuKPvIzcRpo5D2OQ6wQD+G WqPuYOHvrwkvA== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 10/11] fs/9p: writeback mode fixes Date: Sat, 18 Feb 2023 00:33:22 +0000 Message-Id: <20230218003323.2322580-11-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This fixes several detected problems from preivous patches when running with writeback mode. In particular this fixes issues with files which are opened as write only and getattr on files which dirty caches. This patch makes sure that cache behavior for an open file is stored in the client copy of fid->mode. This allows us to reflect cache behavior from mount flags, open mode, and information from the server to inform readahead and writeback behavior. This includes adding support for a 9p semantic that qid.version=3D=3D0 is used to mark a file as non-cachable which is important for synthetic files. This may have a side-effect of not supporting caching on certain legacy file servers that do not properly set qid.version. There is also now a mount flag which can disable the qid.version behavior. Signed-off-by: Eric Van Hensbergen --- Documentation/filesystems/9p.rst | 24 ++++----- fs/9p/fid.c | 49 +++++++---------- fs/9p/fid.h | 33 +++++++++++- fs/9p/v9fs.h | 1 - fs/9p/vfs_addr.c | 22 ++++---- fs/9p/vfs_file.c | 91 +++++++++++--------------------- fs/9p/vfs_inode.c | 45 ++++++---------- fs/9p/vfs_inode_dotl.c | 50 +++++++----------- fs/9p/vfs_super.c | 21 +++++--- 9 files changed, 153 insertions(+), 183 deletions(-) diff --git a/Documentation/filesystems/9p.rst b/Documentation/filesystems/9= p.rst index 0e800b8f73cc..0c2c7a181d85 100644 --- a/Documentation/filesystems/9p.rst +++ b/Documentation/filesystems/9p.rst @@ -79,18 +79,14 @@ Options =20 cache=3Dmode specifies a caching policy. By default, no caches are used. =20 - none - default no cache policy, metadata and data - alike are synchronous. - loose - no attempts are made at consistency, - intended for exclusive, read-only mounts - fscache - use FS-Cache for a persistent, read-only - cache backend. - mmap - minimal cache that is only used for read-write - mmap. Northing else is cached, like cache= =3Dnone + =3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D + none no cache of file or metadata + readahead readahead caching of files + writeback delayed writeback of files + mmap support mmap operations read/write with cache + loose meta-data and file cache with no coherency + fscache use FS-Cache for a persistent cache backend + =3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D =20 debug=3Dn specifies debug level. The debug level is a bitmask. =20 @@ -137,6 +133,10 @@ Options This can be used to share devices/named pipes/sockets between hosts. This functionality will be expanded in later versions. =20 + directio bypass page cache on all read/write operations + + ignoreqv ignore qid.version=3D=3D0 as a marker to ignore cache + noxattr do not offer xattr functions on this mount. =20 access there are four access modes. diff --git a/fs/9p/fid.c b/fs/9p/fid.c index 805151114e96..8c1697619f3d 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -23,7 +23,6 @@ static inline void __add_fid(struct dentry *dentry, struc= t p9_fid *fid) hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata); } =20 - /** * v9fs_fid_add - add a fid to a dentry * @dentry: dentry that the fid is being added to @@ -41,14 +40,24 @@ void v9fs_fid_add(struct dentry *dentry, struct p9_fid = **pfid) *pfid =3D NULL; } =20 +static bool v9fs_is_writeable(int mode) +{ + if ((mode & P9_OWRITE) || (mode & P9_ORDWR)) + return true; + else + return false; +} + /** * v9fs_fid_find_inode - search for an open fid off of the inode list * @inode: return a fid pointing to a specific inode + * @writeable: only consider fids which are writeable * @uid: return a fid belonging to the specified user + * @any: ignore uid as a selection criteria * */ - -static struct p9_fid *v9fs_fid_find_inode(struct inode *inode, kuid_t uid) +struct p9_fid *v9fs_fid_find_inode(struct inode *inode, bool want_writeabl= e, + kuid_t uid, bool any) { struct hlist_head *h; struct p9_fid *fid, *ret =3D NULL; @@ -58,7 +67,12 @@ static struct p9_fid *v9fs_fid_find_inode(struct inode *= inode, kuid_t uid) spin_lock(&inode->i_lock); h =3D (struct hlist_head *)&inode->i_private; hlist_for_each_entry(fid, h, ilist) { - if (uid_eq(fid->uid, uid)) { + if (any || uid_eq(fid->uid, uid)) { + if (want_writeable && !v9fs_is_writeable(fid->mode)) { + p9_debug(P9_DEBUG_VFS, " mode: %x not writeable?\n", + fid->mode); + continue; + } p9_fid_get(fid); ret =3D fid; break; @@ -118,7 +132,7 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dent= ry, kuid_t uid, int any) spin_unlock(&dentry->d_lock); } else { if (dentry->d_inode) - ret =3D v9fs_fid_find_inode(dentry->d_inode, uid); + ret =3D v9fs_fid_find_inode(dentry->d_inode, false, uid, any); } =20 return ret; @@ -299,28 +313,3 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry) return v9fs_fid_lookup_with_uid(dentry, uid, any); } =20 -struct p9_fid *v9fs_writeback_fid(struct dentry *dentry) -{ - int err; - struct p9_fid *fid, *ofid; - - ofid =3D v9fs_fid_lookup_with_uid(dentry, GLOBAL_ROOT_UID, 0); - fid =3D clone_fid(ofid); - if (IS_ERR(fid)) - goto error_out; - p9_fid_put(ofid); - /* - * writeback fid will only be used to write back the - * dirty pages. We always request for the open fid in read-write - * mode so that a partial page write which result in page - * read can work. - */ - err =3D p9_client_open(fid, O_RDWR); - if (err < 0) { - p9_fid_put(fid); - fid =3D ERR_PTR(err); - goto error_out; - } -error_out: - return fid; -} diff --git a/fs/9p/fid.h b/fs/9p/fid.h index 8a4e8cd12ca2..11576e1364bf 100644 --- a/fs/9p/fid.h +++ b/fs/9p/fid.h @@ -7,14 +7,16 @@ #ifndef FS_9P_FID_H #define FS_9P_FID_H #include +#include "v9fs.h" =20 +struct p9_fid *v9fs_fid_find_inode(struct inode *inode, bool want_writeabl= e, + kuid_t uid, bool any); struct p9_fid *v9fs_fid_lookup(struct dentry *dentry); static inline struct p9_fid *v9fs_parent_fid(struct dentry *dentry) { return v9fs_fid_lookup(dentry->d_parent); } void v9fs_fid_add(struct dentry *dentry, struct p9_fid **fid); -struct p9_fid *v9fs_writeback_fid(struct dentry *dentry); void v9fs_open_fid_add(struct inode *inode, struct p9_fid **fid); static inline struct p9_fid *clone_fid(struct p9_fid *fid) { @@ -32,4 +34,33 @@ static inline struct p9_fid *v9fs_fid_clone(struct dentr= y *dentry) p9_fid_put(fid); return nfid; } +/** + * v9fs_fid_addmodes - add cache flags to fid mode (for client use only) + * @fid: fid to augment + * @s_flags: session info mount flags + * @s_cache: session info cache flags + * @f_flags: unix open flags + * + * make sure mode reflects flags of underlying mounts + * also qid.version =3D=3D 0 reflects a synthetic or legacy file system + * NOTE: these are set after open so only reflect 9p client not + * underlying file system on server. + */ +static inline void v9fs_fid_add_modes(struct p9_fid *fid, int s_flags, + int s_cache, unsigned int f_flags) +{ + if (fid->qid.type !=3D P9_QTFILE) + return; + + if ((!s_cache) || + ((fid->qid.version =3D=3D 0) && !(s_flags & V9FS_IGNORE_QV)) || + (s_flags & V9FS_DIRECT_IO) || (f_flags & O_DIRECT)) { + fid->mode |=3D P9L_DIRECT; /* no read or write cache */ + } else if ((s_cache < CACHE_WRITEBACK) || + (f_flags & O_DSYNC) | (s_flags & V9FS_SYNC)) { + fid->mode |=3D P9L_NOWRITECACHE; + } else if (s_cache =3D=3D CACHE_LOOSE) { + fid->mode |=3D P9L_LOOSE; /* noncoherent cache */ + } +} #endif diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index 48c7614c9333..8be9c0f59679 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h @@ -118,7 +118,6 @@ struct v9fs_inode { struct netfs_inode netfs; /* Netfslib context and vfs inode */ struct p9_qid qid; unsigned int cache_validity; - struct p9_fid *writeback_fid; struct mutex v_mutex; }; =20 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c index 6f46d7e4c750..211165430a8a 100644 --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c @@ -57,8 +57,6 @@ static void v9fs_issue_read(struct netfs_io_subrequest *s= ubreq) */ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *f= ile) { - struct inode *inode =3D file_inode(file); - struct v9fs_inode *v9inode =3D V9FS_I(inode); struct p9_fid *fid =3D file->private_data; =20 BUG_ON(!fid); @@ -66,11 +64,8 @@ static int v9fs_init_request(struct netfs_io_request *rr= eq, struct file *file) /* we might need to read from a fid that was opened write-only * for read-modify-write of page cache, use the writeback fid * for that */ - if (rreq->origin =3D=3D NETFS_READ_FOR_WRITE && - (fid->mode & O_ACCMODE) =3D=3D O_WRONLY) { - fid =3D v9inode->writeback_fid; - BUG_ON(!fid); - } + WARN_ON(rreq->origin =3D=3D NETFS_READ_FOR_WRITE && + !(fid->mode & P9_ORDWR)); =20 p9_fid_get(fid); rreq->netfs_priv =3D fid; @@ -164,6 +159,7 @@ static int v9fs_vfs_write_folio_locked(struct folio *fo= lio) loff_t i_size =3D i_size_read(inode); struct iov_iter from; size_t len =3D folio_size(folio); + struct p9_fid *writeback_fid; int err; =20 if (start >=3D i_size) @@ -173,13 +169,17 @@ static int v9fs_vfs_write_folio_locked(struct folio *= folio) =20 iov_iter_xarray(&from, ITER_SOURCE, &folio_mapping(folio)->i_pages, start= , len); =20 - /* We should have writeback_fid always set */ - BUG_ON(!v9inode->writeback_fid); + writeback_fid =3D v9fs_fid_find_inode(inode, true, INVALID_UID, true); + if (!writeback_fid) { + WARN_ONCE(1, "folio expected an open fid inode->i_private=3D%p\n", + inode->i_private); + return -EINVAL; + } =20 folio_wait_fscache(folio); folio_start_writeback(folio); =20 - p9_client_write(v9inode->writeback_fid, start, &from, &err); + p9_client_write(writeback_fid, start, &from, &err); =20 if (err =3D=3D 0 && fscache_cookie_enabled(cookie) && @@ -192,6 +192,8 @@ static int v9fs_vfs_write_folio_locked(struct folio *fo= lio) } =20 folio_end_writeback(folio); + p9_fid_put(writeback_fid); + return err; } =20 diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 20e4bd299fc2..936daff9f948 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -42,7 +42,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) int err; struct v9fs_inode *v9inode; struct v9fs_session_info *v9ses; - struct p9_fid *fid, *writeback_fid; + struct p9_fid *fid; int omode; =20 p9_debug(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, file); @@ -59,7 +59,19 @@ int v9fs_file_open(struct inode *inode, struct file *fil= e) if (IS_ERR(fid)) return PTR_ERR(fid); =20 - err =3D p9_client_open(fid, omode); + if ((v9ses->cache >=3D CACHE_WRITEBACK) && (omode & P9_OWRITE)) { + int writeback_omode =3D (omode & !P9_OWRITE) | P9_ORDWR; + + p9_debug(P9_DEBUG_CACHE, "write-only file with writeback enabled, try o= pening O_RDWR\n"); + err =3D p9_client_open(fid, writeback_omode); + if (err < 0) { + p9_debug(P9_DEBUG_CACHE, "could not open O_RDWR, disabling caches\n"); + err =3D p9_client_open(fid, omode); + fid->mode |=3D P9L_DIRECT; + } + } else { + err =3D p9_client_open(fid, omode); + } if (err < 0) { p9_fid_put(fid); return err; @@ -71,36 +83,14 @@ int v9fs_file_open(struct inode *inode, struct file *fi= le) file->private_data =3D fid; } =20 - mutex_lock(&v9inode->v_mutex); - if ((v9ses->cache >=3D CACHE_WRITEBACK) && !v9inode->writeback_fid && - ((file->f_flags & O_ACCMODE) !=3D O_RDONLY)) { - /* - * clone a fid and add it to writeback_fid - * we do it during open time instead of - * page dirty time via write_begin/page_mkwrite - * because we want write after unlink usecase - * to work. - */ - writeback_fid =3D v9fs_writeback_fid(file_dentry(file)); - if (IS_ERR(writeback_fid)) { - err =3D PTR_ERR(writeback_fid); - mutex_unlock(&v9inode->v_mutex); - goto out_error; - } - v9inode->writeback_fid =3D (void *) writeback_fid; - } - mutex_unlock(&v9inode->v_mutex); #ifdef CONFIG_9P_FSCACHE if (v9ses->cache =3D=3D CACHE_FSCACHE) fscache_use_cookie(v9fs_inode_cookie(v9inode), file->f_mode & FMODE_WRITE); #endif + v9fs_fid_add_modes(fid, v9ses->flags, v9ses->cache, file->f_flags); v9fs_open_fid_add(inode, &fid); return 0; -out_error: - p9_fid_put(file->private_data); - file->private_data =3D NULL; - return err; } =20 /** @@ -366,14 +356,14 @@ v9fs_file_read_iter(struct kiocb *iocb, struct iov_it= er *to) { struct p9_fid *fid =3D iocb->ki_filp->private_data; int ret, err =3D 0; - struct inode *inode =3D file_inode(iocb->ki_filp); - struct v9fs_session_info *v9ses =3D v9fs_inode2v9ses(inode); =20 - p9_debug(P9_DEBUG_VFS, "count %zu offset %lld\n", - iov_iter_count(to), iocb->ki_pos); + p9_debug(P9_DEBUG_VFS, "fid %d count %zu offset %lld\n", + fid->fid, iov_iter_count(to), iocb->ki_pos); =20 - if (v9ses->cache > CACHE_MMAP) + if (!(fid->mode & P9L_DIRECT)) { + p9_debug(P9_DEBUG_VFS, "(cached)\n"); return generic_file_read_iter(iocb, to); + } =20 if (iocb->ki_filp->f_flags & O_NONBLOCK) ret =3D p9_client_read_once(fid, iocb->ki_pos, to, &err); @@ -396,14 +386,17 @@ static ssize_t v9fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file =3D iocb->ki_filp; + struct p9_fid *fid =3D file->private_data; ssize_t retval; loff_t origin; int err =3D 0; - struct inode *inode =3D file_inode(iocb->ki_filp); - struct v9fs_session_info *v9ses =3D v9fs_inode2v9ses(inode); =20 - if (v9ses->cache >=3D CACHE_WRITEBACK) + p9_debug(P9_DEBUG_VFS, "fid %d\n", fid->fid); + + if (!(fid->mode & (P9L_DIRECT | P9L_NOWRITECACHE))) { + p9_debug(P9_DEBUG_CACHE, "(cached)\n"); return generic_file_write_iter(iocb, from); + } =20 retval =3D generic_write_checks(iocb, from); if (retval <=3D 0) @@ -487,36 +480,18 @@ v9fs_file_mmap(struct file *filp, struct vm_area_stru= ct *vma) { int retval; struct inode *inode =3D file_inode(filp); - struct v9fs_inode *v9inode =3D V9FS_I(inode); struct v9fs_session_info *v9ses =3D v9fs_inode2v9ses(inode); - struct p9_fid *fid; + + p9_debug(P9_DEBUG_MMAP, "filp :%p\n", filp); =20 if (v9ses->cache < CACHE_MMAP) { + p9_debug(P9_DEBUG_CACHE, "(no mmap mode)"); + if (vma->vm_flags & VM_MAYSHARE) + return -ENODEV; invalidate_inode_pages2(filp->f_mapping); return generic_file_readonly_mmap(filp, vma); } =20 - mutex_lock(&v9inode->v_mutex); - if (!v9inode->writeback_fid && - (vma->vm_flags & VM_SHARED) && - (vma->vm_flags & VM_WRITE)) { - /* - * clone a fid and add it to writeback_fid - * we do it during mmap instead of - * page dirty time via write_begin/page_mkwrite - * because we want write after unlink usecase - * to work. - */ - fid =3D v9fs_writeback_fid(file_dentry(filp)); - if (IS_ERR(fid)) { - retval =3D PTR_ERR(fid); - mutex_unlock(&v9inode->v_mutex); - return retval; - } - v9inode->writeback_fid =3D (void *) fid; - } - mutex_unlock(&v9inode->v_mutex); - retval =3D generic_file_mmap(filp, vma); if (!retval) vma->vm_ops =3D &v9fs_mmap_file_vm_ops; @@ -527,7 +502,6 @@ v9fs_file_mmap(struct file *filp, struct vm_area_struct= *vma) static vm_fault_t v9fs_vm_page_mkwrite(struct vm_fault *vmf) { - struct v9fs_inode *v9inode; struct folio *folio =3D page_folio(vmf->page); struct file *filp =3D vmf->vma->vm_file; struct inode *inode =3D file_inode(filp); @@ -536,8 +510,6 @@ v9fs_vm_page_mkwrite(struct vm_fault *vmf) p9_debug(P9_DEBUG_VFS, "folio %p fid %lx\n", folio, (unsigned long)filp->private_data); =20 - v9inode =3D V9FS_I(inode); - /* Wait for the page to be written to the cache before we allow it to * be modified. We then assume the entire page will need writing back. */ @@ -550,7 +522,6 @@ v9fs_vm_page_mkwrite(struct vm_fault *vmf) /* Update file times before taking page lock */ file_update_time(filp); =20 - BUG_ON(!v9inode->writeback_fid); if (folio_lock_killable(folio) < 0) return VM_FAULT_RETRY; if (folio_mapping(folio) !=3D inode->i_mapping) diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 8ffa6631b1fd..d53475e1ba27 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -259,7 +259,6 @@ struct inode *v9fs_alloc_inode(struct super_block *sb) v9inode =3D alloc_inode_sb(sb, v9fs_inode_cache, GFP_KERNEL); if (!v9inode) return NULL; - v9inode->writeback_fid =3D NULL; v9inode->cache_validity =3D 0; mutex_init(&v9inode->v_mutex); return &v9inode->netfs.inode; @@ -412,9 +411,6 @@ void v9fs_evict_inode(struct inode *inode) filemap_fdatawrite(&inode->i_data); =20 fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false); - /* clunk the fid stashed in writeback_fid */ - p9_fid_put(v9inode->writeback_fid); - v9inode->writeback_fid =3D NULL; } =20 static int v9fs_test_inode(struct inode *inode, void *data) @@ -825,9 +821,10 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry = *dentry, u32 perm; struct v9fs_inode *v9inode; struct v9fs_session_info *v9ses; - struct p9_fid *fid, *inode_fid; + struct p9_fid *fid; struct dentry *res =3D NULL; struct inode *inode; + int p9_omode; =20 if (d_in_lookup(dentry)) { res =3D v9fs_vfs_lookup(dir, dentry, 0); @@ -846,9 +843,14 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry = *dentry, =20 v9ses =3D v9fs_inode2v9ses(dir); perm =3D unixmode2p9mode(v9ses, mode); - fid =3D v9fs_create(v9ses, dir, dentry, NULL, perm, - v9fs_uflags2omode(flags, - v9fs_proto_dotu(v9ses))); + p9_omode =3D v9fs_uflags2omode(flags, v9fs_proto_dotu(v9ses)); + + if ((v9ses->cache >=3D CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) { + p9_omode =3D (p9_omode & !P9_OWRITE) | P9_ORDWR; + p9_debug(P9_DEBUG_CACHE, + "write-only file with writeback enabled, creating w/ O_RDWR\n"); + } + fid =3D v9fs_create(v9ses, dir, dentry, NULL, perm, p9_omode); if (IS_ERR(fid)) { err =3D PTR_ERR(fid); goto error; @@ -857,25 +859,6 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry = *dentry, v9fs_invalidate_inode_attr(dir); inode =3D d_inode(dentry); v9inode =3D V9FS_I(inode); - mutex_lock(&v9inode->v_mutex); - if ((v9ses->cache >=3D CACHE_WRITEBACK) && !v9inode->writeback_fid && - ((flags & O_ACCMODE) !=3D O_RDONLY)) { - /* - * clone a fid and add it to writeback_fid - * we do it during open time instead of - * page dirty time via write_begin/page_mkwrite - * because we want write after unlink usecase - * to work. - */ - inode_fid =3D v9fs_writeback_fid(dentry); - if (IS_ERR(inode_fid)) { - err =3D PTR_ERR(inode_fid); - mutex_unlock(&v9inode->v_mutex); - goto error; - } - v9inode->writeback_fid =3D (void *) inode_fid; - } - mutex_unlock(&v9inode->v_mutex); err =3D finish_open(file, dentry, generic_file_open); if (err) goto error; @@ -884,6 +867,8 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *= dentry, if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE) fscache_use_cookie(v9fs_inode_cookie(v9inode), file->f_mode & FMODE_WRITE); + + v9fs_fid_add_modes(fid, v9ses->flags, v9ses->cache, file->f_flags); v9fs_open_fid_add(inode, &fid); =20 file->f_mode |=3D FMODE_CREATED; @@ -1053,7 +1038,7 @@ v9fs_vfs_getattr(struct user_namespace *mnt_userns, c= onst struct path *path, p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry); v9ses =3D v9fs_dentry2v9ses(dentry); if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE)= { - generic_fillattr(&init_user_ns, d_inode(dentry), stat); + generic_fillattr(&init_user_ns, inode, stat); return 0; } else if (v9ses->cache >=3D CACHE_WRITEBACK) { if (S_ISREG(inode->i_mode)) @@ -1148,10 +1133,10 @@ static int v9fs_vfs_setattr(struct user_namespace *= mnt_userns, if ((iattr->ia_valid & ATTR_SIZE) && iattr->ia_size !=3D i_size_read(inode)) { truncate_setsize(inode, iattr->ia_size); + truncate_pagecache(inode, iattr->ia_size); + if (v9ses->cache =3D=3D CACHE_FSCACHE) fscache_resize_cookie(v9fs_inode_cookie(v9inode), iattr->ia_size); - else - invalidate_mapping_pages(&inode->i_data, 0, -1); } =20 v9fs_invalidate_inode_attr(inode); diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index 4f01808c3bae..f5f15878cbb7 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c @@ -232,12 +232,12 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct d= entry *dentry, int err =3D 0; kgid_t gid; umode_t mode; + int p9_omode =3D v9fs_open_to_dotl_flags(flags); const unsigned char *name =3D NULL; struct p9_qid qid; struct inode *inode; struct p9_fid *fid =3D NULL; - struct v9fs_inode *v9inode; - struct p9_fid *dfid =3D NULL, *ofid =3D NULL, *inode_fid =3D NULL; + struct p9_fid *dfid =3D NULL, *ofid =3D NULL; struct v9fs_session_info *v9ses; struct posix_acl *pacl =3D NULL, *dacl =3D NULL; struct dentry *res =3D NULL; @@ -282,14 +282,19 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct d= entry *dentry, /* Update mode based on ACL value */ err =3D v9fs_acl_mode(dir, &mode, &dacl, &pacl); if (err) { - p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n", + p9_debug(P9_DEBUG_VFS, "Failed to get acl values in create %d\n", err); goto out; } - err =3D p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags), - mode, gid, &qid); + + if ((v9ses->cache >=3D CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) { + p9_omode =3D (p9_omode & !P9_OWRITE) | P9_ORDWR; + p9_debug(P9_DEBUG_CACHE, + "write-only file with writeback enabled, creating w/ O_RDWR\n"); + } + err =3D p9_client_create_dotl(ofid, name, p9_omode, mode, gid, &qid); if (err < 0) { - p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n", + p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in create %d\n", err); goto out; } @@ -314,36 +319,19 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct d= entry *dentry, v9fs_fid_add(dentry, &fid); d_instantiate(dentry, inode); =20 - v9inode =3D V9FS_I(inode); - mutex_lock(&v9inode->v_mutex); - if ((v9ses->cache) && !v9inode->writeback_fid && - ((flags & O_ACCMODE) !=3D O_RDONLY)) { - /* - * clone a fid and add it to writeback_fid - * we do it during open time instead of - * page dirty time via write_begin/page_mkwrite - * because we want write after unlink usecase - * to work. - */ - inode_fid =3D v9fs_writeback_fid(dentry); - if (IS_ERR(inode_fid)) { - err =3D PTR_ERR(inode_fid); - mutex_unlock(&v9inode->v_mutex); - goto out; - } - v9inode->writeback_fid =3D (void *) inode_fid; - } - mutex_unlock(&v9inode->v_mutex); /* Since we are opening a file, assign the open fid to the file */ err =3D finish_open(file, dentry, generic_file_open); if (err) goto out; file->private_data =3D ofid; #ifdef CONFIG_9P_FSCACHE - if (v9ses->cache =3D=3D CACHE_FSCACHE) + if (v9ses->cache =3D=3D CACHE_FSCACHE) { + struct v9fs_inode *v9inode =3D V9FS_I(inode); fscache_use_cookie(v9fs_inode_cookie(v9inode), file->f_mode & FMODE_WRITE); + } #endif + v9fs_fid_add_modes(ofid, v9ses->flags, v9ses->cache, flags); v9fs_open_fid_add(inode, &ofid); file->f_mode |=3D FMODE_CREATED; out: @@ -464,9 +452,9 @@ v9fs_vfs_getattr_dotl(struct user_namespace *mnt_userns, p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry); v9ses =3D v9fs_dentry2v9ses(dentry); if (v9ses->cache =3D=3D CACHE_LOOSE || v9ses->cache =3D=3D CACHE_FSCACHE)= { - generic_fillattr(&init_user_ns, d_inode(dentry), stat); + generic_fillattr(&init_user_ns, inode, stat); return 0; - } else if (v9ses->cache >=3D CACHE_WRITEBACK) { + } else if (v9ses->cache) { if (S_ISREG(inode->i_mode)) v9fs_flush_inode_writeback(inode); =20 @@ -605,10 +593,10 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_= userns, if ((iattr->ia_valid & ATTR_SIZE) && iattr->ia_size !=3D i_size_read(inode)) { truncate_setsize(inode, iattr->ia_size); + truncate_pagecache(inode, iattr->ia_size); + if (v9ses->cache =3D=3D CACHE_FSCACHE) fscache_resize_cookie(v9fs_inode_cookie(v9inode), iattr->ia_size); - else - invalidate_mapping_pages(&inode->i_data, 0, -1); } =20 v9fs_invalidate_inode_attr(inode); diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index 5fc6a945bfff..797f717e1a91 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c @@ -292,23 +292,26 @@ static int v9fs_write_inode(struct inode *inode, { int ret; struct p9_wstat wstat; + struct p9_fid *fid =3D v9fs_fid_find_inode(inode, false, INVALID_UID, tru= e); struct v9fs_inode *v9inode; + /* * send an fsync request to server irrespective of * wbc->sync_mode. */ - p9_debug(P9_DEBUG_VFS, "%s: inode %p\n", __func__, inode); + p9_debug(P9_DEBUG_VFS, "%s: inode %p writeback_fid: %p\n", __func__, inod= e, fid); v9inode =3D V9FS_I(inode); - if (!v9inode->writeback_fid) - return 0; + if (!fid) + return -EINVAL; v9fs_blank_wstat(&wstat); =20 - ret =3D p9_client_wstat(v9inode->writeback_fid, &wstat); + ret =3D p9_client_wstat(fid, &wstat); if (ret < 0) { __mark_inode_dirty(inode, I_DIRTY_DATASYNC); return ret; } fscache_unpin_writeback(wbc, v9fs_inode_cookie(v9inode)); + p9_fid_put(fid); return 0; } =20 @@ -316,6 +319,7 @@ static int v9fs_write_inode_dotl(struct inode *inode, struct writeback_control *wbc) { int ret; + struct p9_fid *fid =3D v9fs_fid_find_inode(inode, FMODE_WRITE, INVALID_UI= D, 1); struct v9fs_inode *v9inode; /* * send an fsync request to server irrespective of @@ -323,16 +327,17 @@ static int v9fs_write_inode_dotl(struct inode *inode, */ v9inode =3D V9FS_I(inode); p9_debug(P9_DEBUG_VFS, "%s: inode %p, writeback_fid %p\n", - __func__, inode, v9inode->writeback_fid); - if (!v9inode->writeback_fid) - return 0; + __func__, inode, fid); + if (!fid) + return -EINVAL; =20 - ret =3D p9_client_fsync(v9inode->writeback_fid, 0); + ret =3D p9_client_fsync(fid, 0); if (ret < 0) { __mark_inode_dirty(inode, I_DIRTY_DATASYNC); return ret; } fscache_unpin_writeback(wbc, v9fs_inode_cookie(v9inode)); + p9_fid_put(fid); return 0; } =20 --=20 2.37.2 From nobody Thu Sep 11 14:11:02 2025 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 D8AB5C636D6 for ; Sat, 18 Feb 2023 00:48:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbjBRAs1 (ORCPT ); Fri, 17 Feb 2023 19:48:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjBRAsY (ORCPT ); Fri, 17 Feb 2023 19:48:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BBA1193F9; Fri, 17 Feb 2023 16:47:57 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 01D01620AE; Sat, 18 Feb 2023 00:34:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 938A9C433D2; Sat, 18 Feb 2023 00:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676680445; bh=fE7TnKGk+7sECniXW1Co7rrNpfck1npdV3aCIbmWvVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AnkqWYzFMTcdBZm4UR/n3WPvCPfwOaEkymB8fMNPzSu0yOxGLVyau2YonIEyaQqoL H1m4s4pnyONyULyAczlSbveBWREsET+3AZnQvVr4sFVPoAraoRstlRDW6lPMP7r6sW JRybBRGFFujDXu1tXKRT4axSewCYNlRcsbjD9pw8XxGl0dOkA0kU/UXUkV2npA5J44 HpQr5oj/1qWUKUfbEVz5eb1EIRclPNLvl5RzZiDwy9Mp76CoaCttX1bgibxDb5KiUB d+3vnLsbMfPviaSfeaSy2zMxKTpYZxc5BKlfl7BtGImwSvyHie7kCN9dknVu4ClUGO IzO9GwMrSJcdw== From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net, asmadeus@codewreck.org, rminnich@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux_oss@crudebyte.com, Eric Van Hensbergen Subject: [PATCH v4 11/11] fs/9p: Fix revalidate Date: Sat, 18 Feb 2023 00:33:23 +0000 Message-Id: <20230218003323.2322580-12-ericvh@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230218003323.2322580-1-ericvh@kernel.org> References: <20230124023834.106339-1-ericvh@kernel.org> <20230218003323.2322580-1-ericvh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Unclear if this case ever happens, but if no inode in dentry, then the dentry is definitely invalid. Seemed to be the opposite in the existing code. Signed-off-by: Eric Van Hensbergen --- fs/9p/vfs_dentry.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c index 65fa2df5e49b..b0c3f8e8ea00 100644 --- a/fs/9p/vfs_dentry.c +++ b/fs/9p/vfs_dentry.c @@ -68,7 +68,7 @@ static int v9fs_lookup_revalidate(struct dentry *dentry, = unsigned int flags) =20 inode =3D d_inode(dentry); if (!inode) - goto out_valid; + return 0; =20 v9inode =3D V9FS_I(inode); if (v9inode->cache_validity & V9FS_INO_INVALID_ATTR) { @@ -91,7 +91,6 @@ static int v9fs_lookup_revalidate(struct dentry *dentry, = unsigned int flags) if (retval < 0) return retval; } -out_valid: return 1; } =20 --=20 2.37.2