linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/9p: Rework cache modes and add new options to Documentation
@ 2023-04-01 23:16 Eric Van Hensbergen
  2023-04-02  0:37 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Van Hensbergen @ 2023-04-01 23:16 UTC (permalink / raw)
  To: Latchesar Ionkov, Dominique Martinet, Christian Schoenebeck, v9fs
  Cc: v9fs-developer, linux-doc, linux-kernel, Eric Van Hensbergen

Switch cache modes to a bit-mask and use legacy
cache names as shortcuts.  Update documentation to
include information on both shortcuts and bitmasks.

This patch also fixes missing guards related to fscache.

Update the documentation for new mount flags
and cache modes.

Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
---
 Documentation/filesystems/9p.rst | 50 ++++++++++++++++++++++--------
 fs/9p/cache.h                    |  3 +-
 fs/9p/fid.h                      |  4 +--
 fs/9p/v9fs.c                     | 34 +++++++-------------
 fs/9p/v9fs.h                     | 67 ++++++++++++++++++++++++++--------------
 fs/9p/vfs_addr.c                 | 37 +++++++++++++---------
 fs/9p/vfs_file.c                 |  6 ++--
 fs/9p/vfs_inode.c                | 28 ++++++++++++-----
 fs/9p/vfs_inode_dotl.c           | 24 +++++++-------
 fs/9p/vfs_super.c                |  4 +--
 10 files changed, 154 insertions(+), 103 deletions(-)

diff --git a/Documentation/filesystems/9p.rst b/Documentation/filesystems/9p.rst
index 0e800b8f73cc..d79bf4e41a71 100644
--- a/Documentation/filesystems/9p.rst
+++ b/Documentation/filesystems/9p.rst
@@ -78,19 +78,39 @@ Options
   		offering several exported file systems.
 
   cache=mode	specifies a caching policy.  By default, no caches are used.
-
-                        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=none
+		The mode can be specified as a bitmask or by using one of the
+		prexisting common 'shortcuts'.
+		The bitmask is described below: (unspecified bits are reserved)
+
+			==========	================================================
+			0b00000000	all caches disabled, mmap disabled
+			0b00000001	file caches enabled
+			0b00000010	meta-data caches enabled
+			0b00000100	writeback behavior (as opposed to writethrough)
+			0b00001000	loose caches (no explicit consistency with server)
+			0b10000000	fscache enabled for persistent caching
+			=========	================================================
+
+		The current shortcuts and their associated bitmask are:
+
+			=========	=============================================
+			none		0b00000000 (no caching)
+			readahead	0b00000001 (only read-ahead file caching)
+			mmap		0b00000101 (read-ahead + writeback file cache)
+			loose		0b00001111 (non-coherent file and meta-data caches)
+			fscache		0b10001111 (persistent loose cache)
+			=========	=============================================
+
+		NOTE: only these shortcuts are tested modes of operation at the
+		moment, so using other combinations of bit-patterns is not
+		known to work.  Work on better cache support is in progress.
+
+		IMPORTANT: loose caches (and by extension at the moment fscache)
+		do not necessarily validate cached values on the server.  In other
+		words changes on the server are not guaranteed to be reflected
+		on the client system.  Only use this mode of operation if you
+		have an exclusive mount and the server will modify the filesystem
+		underneath you.
 
   debug=n	specifies debug level.  The debug level is a bitmask.
 
@@ -137,6 +157,10 @@ Options
   		This can be used to share devices/named pipes/sockets between
 		hosts.  This functionality will be expanded in later versions.
 
+  directio	bypass page cache on all read/write operations
+
+  ignoreqv	ignore qid.version==0 as a marker to ignore cache
+
   noxattr	do not offer xattr functions on this mount.
 
   access	there are four access modes.
diff --git a/fs/9p/cache.h b/fs/9p/cache.h
index 1923affcdc62..ee1b6b06a2fd 100644
--- a/fs/9p/cache.h
+++ b/fs/9p/cache.h
@@ -8,9 +8,8 @@
 #ifndef _9P_CACHE_H
 #define _9P_CACHE_H
 
-#include <linux/fscache.h>
-
 #ifdef CONFIG_9P_FSCACHE
+#include <linux/fscache.h>
 
 extern int v9fs_cache_session_get_cookie(struct v9fs_session_info *v9ses,
 					  const char *dev_name);
diff --git a/fs/9p/fid.h b/fs/9p/fid.h
index 11576e1364bf..0c51889a60b3 100644
--- a/fs/9p/fid.h
+++ b/fs/9p/fid.h
@@ -56,11 +56,9 @@ static inline void v9fs_fid_add_modes(struct p9_fid *fid, int s_flags,
 	   ((fid->qid.version == 0) && !(s_flags & V9FS_IGNORE_QV)) ||
 	   (s_flags & V9FS_DIRECT_IO) || (f_flags & O_DIRECT)) {
 		fid->mode |= P9L_DIRECT; /* no read or write cache */
-	} else if ((s_cache < CACHE_WRITEBACK) ||
+	} else if ((!(s_cache & CACHE_WRITEBACK)) ||
 				(f_flags & O_DSYNC) | (s_flags & V9FS_SYNC)) {
 		fid->mode |= P9L_NOWRITECACHE;
-	} else if (s_cache == CACHE_LOOSE) {
-		fid->mode |= P9L_LOOSE; /* noncoherent cache */
 	}
 }
 #endif
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index 43d3806150a9..c7f774fe398f 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -66,40 +66,30 @@ static const match_table_t tokens = {
 	{Opt_err, NULL}
 };
 
-static const char *const v9fs_cache_modes[nr__p9_cache_modes] = {
-	[CACHE_NONE]		= "none",
-	[CACHE_READAHEAD]	= "readahead",
-	[CACHE_WRITEBACK]	= "writeback",
-	[CACHE_MMAP]		= "mmap",
-	[CACHE_LOOSE]		= "loose",
-	[CACHE_FSCACHE]		= "fscache",
-};
-
 /* Interpret mount options for cache mode */
 static int get_cache_mode(char *s)
 {
 	int version = -EINVAL;
 
 	if (!strcmp(s, "loose")) {
-		version = CACHE_LOOSE;
+		version = CACHE_SC_LOOSE;
 		p9_debug(P9_DEBUG_9P, "Cache mode: loose\n");
 	} else if (!strcmp(s, "fscache")) {
-		version = CACHE_FSCACHE;
+		version = CACHE_SC_FSCACHE;
 		p9_debug(P9_DEBUG_9P, "Cache mode: fscache\n");
 	} else if (!strcmp(s, "mmap")) {
-		version = CACHE_MMAP;
+		version = CACHE_SC_MMAP;
 		p9_debug(P9_DEBUG_9P, "Cache mode: mmap\n");
-	} else if (!strcmp(s, "writeback")) {
-		version = CACHE_WRITEBACK;
-		p9_debug(P9_DEBUG_9P, "Cache mode: writeback\n");
 	} else if (!strcmp(s, "readahead")) {
-		version = CACHE_READAHEAD;
+		version = CACHE_SC_READAHEAD;
 		p9_debug(P9_DEBUG_9P, "Cache mode: readahead\n");
 	} else if (!strcmp(s, "none")) {
-		version = CACHE_NONE;
+		version = CACHE_SC_NONE;
 		p9_debug(P9_DEBUG_9P, "Cache mode: none\n");
-	} else
-		pr_info("Unknown Cache mode %s\n", s);
+	} else if (kstrtoint(s, 0, &version) != 0) {
+		version = -EINVAL;
+		pr_info("Unknown Cache mode or invalid value %s\n", s);
+	}
 	return version;
 }
 
@@ -127,9 +117,9 @@ int v9fs_show_options(struct seq_file *m, struct dentry *root)
 	if (v9ses->nodev)
 		seq_puts(m, ",nodevmap");
 	if (v9ses->cache)
-		seq_printf(m, ",cache=%s", v9fs_cache_modes[v9ses->cache]);
+		seq_printf(m, ",cache=%x", v9ses->cache);
 #ifdef CONFIG_9P_FSCACHE
-	if (v9ses->cachetag && v9ses->cache == CACHE_FSCACHE)
+	if (v9ses->cachetag && (v9ses->cache & CACHE_FSCACHE))
 		seq_printf(m, ",cachetag=%s", v9ses->cachetag);
 #endif
 
@@ -481,7 +471,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
 
 #ifdef CONFIG_9P_FSCACHE
 	/* register the session for caching */
-	if (v9ses->cache == CACHE_FSCACHE) {
+	if (v9ses->cache & CACHE_FSCACHE) {
 		rc = v9fs_cache_session_get_cookie(v9ses, dev_name);
 		if (rc < 0)
 			goto err_clnt;
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h
index 999cdbcbfed9..06a2514f0d88 100644
--- a/fs/9p/v9fs.h
+++ b/fs/9p/v9fs.h
@@ -31,35 +31,54 @@
 #define V9FS_ACL_MASK V9FS_POSIX_ACL
 
 enum p9_session_flags {
-	V9FS_PROTO_2000U	= 0x01,
-	V9FS_PROTO_2000L	= 0x02,
-	V9FS_ACCESS_SINGLE	= 0x04,
-	V9FS_ACCESS_USER	= 0x08,
-	V9FS_ACCESS_CLIENT	= 0x10,
-	V9FS_POSIX_ACL		= 0x20,
-	V9FS_NO_XATTR		= 0x40,
-	V9FS_IGNORE_QV		= 0x80, /* ignore qid.version for cache hints */
-	V9FS_DIRECT_IO		= 0x100,
-	V9FS_SYNC		= 0x200
+	V9FS_PROTO_2000U    = 0x01,
+	V9FS_PROTO_2000L    = 0x02,
+	V9FS_ACCESS_SINGLE  = 0x04,
+	V9FS_ACCESS_USER    = 0x08,
+	V9FS_ACCESS_CLIENT  = 0x10,
+	V9FS_POSIX_ACL      = 0x20,
+	V9FS_NO_XATTR       = 0x40,
+	V9FS_IGNORE_QV      = 0x80, /* ignore qid.version for cache hints */
+	V9FS_DIRECT_IO      = 0x100,
+	V9FS_SYNC           = 0x200
 };
 
-/* possible values of ->cache */
 /**
- * enum p9_cache_modes - user specified cache preferences
- * @CACHE_NONE: do not cache data, dentries, or directory contents (default)
- * @CACHE_LOOSE: cache data, dentries, and directory contents w/no consistency
+ * enum p9_cache_shortcuts - human readable cache preferences
+ * @CACHE_SC_NONE: disable all caches
+ * @CACHE_SC_READAHEAD: only provide caching for readahead
+ * @CACHE_SC_MMAP: provide caching to enable mmap
+ * @CACHE_SC_LOOSE: non-coherent caching for files and meta data
+ * @CACHE_SC_FSCACHE: persistent non-coherent caching for files and meta-data
  *
- * eventually support loose, tight, time, session, default always none
  */
 
-enum p9_cache_modes {
-	CACHE_NONE,
-	CACHE_READAHEAD,
-	CACHE_WRITEBACK,
-	CACHE_MMAP,
-	CACHE_LOOSE,
-	CACHE_FSCACHE,
-	nr__p9_cache_modes
+enum p9_cache_shortcuts {
+	CACHE_SC_NONE       = 0b00000000,
+	CACHE_SC_READAHEAD  = 0b00000001,
+	CACHE_SC_MMAP       = 0b00000101,
+	CACHE_SC_LOOSE      = 0b00001111,
+	CACHE_SC_FSCACHE    = 0b10001111,
+};
+
+/**
+ * enum p9_cache_bits - possible values of ->cache
+ * @CACHE_NONE: caches disabled
+ * @CACHE_FILE: file caching (open to close)
+ * @CACHE_META: meta-data and directory caching
+ * @CACHE_WRITEBACK: write-back caching for files
+ * @CACHE_LOOSE: don't check cache consistency
+ * @CACHE_FSCACHE: local persistent caches
+ *
+ */
+
+enum p9_cache_bits {
+	CACHE_NONE          = 0b00000000,
+	CACHE_FILE          = 0b00000001,
+	CACHE_META          = 0b00000010,
+	CACHE_WRITEBACK     = 0b00000100,
+	CACHE_LOOSE         = 0b00001000,
+	CACHE_FSCACHE       = 0b10000000,
 };
 
 /**
@@ -68,7 +87,7 @@ enum p9_cache_modes {
  * @nodev: set to 1 to disable device mapping
  * @debug: debug level
  * @afid: authentication handle
- * @cache: cache mode of type &p9_cache_modes
+ * @cache: cache mode of type &p9_cache_bits
  * @cachetag: the tag of the cache associated with this session
  * @fscache: session cookie associated with FS-Cache
  * @uname: string user name to mount hierarchy as
diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
index 211165430a8a..193e898093cd 100644
--- a/fs/9p/vfs_addr.c
+++ b/fs/9p/vfs_addr.c
@@ -115,8 +115,6 @@ const struct netfs_request_ops v9fs_req_ops = {
 
 static bool v9fs_release_folio(struct folio *folio, gfp_t gfp)
 {
-	struct inode *inode = folio_inode(folio);
-
 	if (folio_test_private(folio))
 		return false;
 #ifdef CONFIG_9P_FSCACHE
@@ -125,8 +123,8 @@ static bool v9fs_release_folio(struct folio *folio, gfp_t gfp)
 			return false;
 		folio_wait_fscache(folio);
 	}
+	fscache_note_page_release(v9fs_inode_cookie(V9FS_I(folio_inode(folio))));
 #endif
-	fscache_note_page_release(v9fs_inode_cookie(V9FS_I(inode)));
 	return true;
 }
 
@@ -136,6 +134,7 @@ static void v9fs_invalidate_folio(struct folio *folio, size_t offset,
 	folio_wait_fscache(folio);
 }
 
+#ifdef CONFIG_9P_FSCACHE
 static void v9fs_write_to_cache_done(void *priv, ssize_t transferred_or_error,
 				     bool was_async)
 {
@@ -149,12 +148,11 @@ static void v9fs_write_to_cache_done(void *priv, ssize_t transferred_or_error,
 				   i_size_read(&v9inode->netfs.inode), 0);
 	}
 }
+#endif
 
 static int v9fs_vfs_write_folio_locked(struct folio *folio)
 {
 	struct inode *inode = folio_inode(folio);
-	struct v9fs_inode *v9inode = V9FS_I(inode);
-	struct fscache_cookie *cookie = v9fs_inode_cookie(v9inode);
 	loff_t start = folio_pos(folio);
 	loff_t i_size = i_size_read(inode);
 	struct iov_iter from;
@@ -181,15 +179,22 @@ static int v9fs_vfs_write_folio_locked(struct folio *folio)
 
 	p9_client_write(writeback_fid, start, &from, &err);
 
-	if (err == 0 &&
-	    fscache_cookie_enabled(cookie) &&
-	    test_bit(FSCACHE_COOKIE_IS_CACHING, &cookie->flags)) {
-		folio_start_fscache(folio);
-		fscache_write_to_cache(v9fs_inode_cookie(v9inode),
-				       folio_mapping(folio), start, len, i_size,
-				       v9fs_write_to_cache_done, v9inode,
-				       true);
+#ifdef CONFIG_9P_FSCACHE
+	{
+		struct v9fs_inode *v9inode = V9FS_I(inode);
+		struct fscache_cookie *cookie = v9fs_inode_cookie(v9inode);
+
+		if (err == 0 &&
+			fscache_cookie_enabled(cookie) &&
+			test_bit(FSCACHE_COOKIE_IS_CACHING, &cookie->flags)) {
+			folio_start_fscache(folio);
+			fscache_write_to_cache(v9fs_inode_cookie(v9inode),
+						folio_mapping(folio), start, len, i_size,
+						v9fs_write_to_cache_done, v9inode,
+						true);
+		}
 	}
+#endif
 
 	folio_end_writeback(folio);
 	p9_fid_put(writeback_fid);
@@ -300,7 +305,6 @@ static int v9fs_write_end(struct file *filp, struct address_space *mapping,
 	loff_t last_pos = pos + copied;
 	struct folio *folio = page_folio(subpage);
 	struct inode *inode = mapping->host;
-	struct v9fs_inode *v9inode = V9FS_I(inode);
 
 	p9_debug(P9_DEBUG_VFS, "filp %p, mapping %p\n", filp, mapping);
 
@@ -320,7 +324,10 @@ static int v9fs_write_end(struct file *filp, struct address_space *mapping,
 	if (last_pos > inode->i_size) {
 		inode_add_bytes(inode, last_pos - inode->i_size);
 		i_size_write(inode, last_pos);
-		fscache_update_cookie(v9fs_inode_cookie(v9inode), NULL, &last_pos);
+#ifdef CONFIG_9P_FSCACHE
+		fscache_update_cookie(v9fs_inode_cookie(V9FS_I(inode)), NULL,
+			&last_pos);
+#endif
 	}
 	folio_mark_dirty(folio);
 out:
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index 9f1d464bc1b5..581d2a3a037a 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -60,7 +60,7 @@ int v9fs_file_open(struct inode *inode, struct file *file)
 		if (IS_ERR(fid))
 			return PTR_ERR(fid);
 
-		if ((v9ses->cache >= CACHE_WRITEBACK) && (omode & P9_OWRITE)) {
+		if ((v9ses->cache & CACHE_WRITEBACK) && (omode & P9_OWRITE)) {
 			int writeback_omode = (omode & ~P9_OWRITE) | P9_ORDWR;
 
 			p9_debug(P9_DEBUG_CACHE, "write-only file with writeback enabled, try opening O_RDWR\n");
@@ -85,7 +85,7 @@ int v9fs_file_open(struct inode *inode, struct file *file)
 	}
 
 #ifdef CONFIG_9P_FSCACHE
-	if (v9ses->cache == CACHE_FSCACHE)
+	if (v9ses->cache & CACHE_FSCACHE)
 		fscache_use_cookie(v9fs_inode_cookie(v9inode),
 				   file->f_mode & FMODE_WRITE);
 #endif
@@ -485,7 +485,7 @@ v9fs_file_mmap(struct file *filp, struct vm_area_struct *vma)
 
 	p9_debug(P9_DEBUG_MMAP, "filp :%p\n", filp);
 
-	if (v9ses->cache < CACHE_MMAP) {
+	if (!(v9ses->cache & CACHE_WRITEBACK)) {
 		p9_debug(P9_DEBUG_CACHE, "(no mmap mode)");
 		if (vma->vm_flags & VM_MAYSHARE)
 			return -ENODEV;
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index fb5e5c0e41e4..5d106cbcdf25 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -376,12 +376,18 @@ void v9fs_evict_inode(struct inode *inode)
 
 	truncate_inode_pages_final(&inode->i_data);
 	version = cpu_to_le32(v9inode->qid.version);
+
+#ifdef CONFIG_9P_FSCACHE
 	fscache_clear_inode_writeback(v9fs_inode_cookie(v9inode), inode,
 				      &version);
+#endif
+
 	clear_inode(inode);
 	filemap_fdatawrite(&inode->i_data);
 
+#ifdef CONFIG_9P_FSCACHE
 	fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false);
+#endif
 }
 
 static int v9fs_test_inode(struct inode *inode, void *data)
@@ -761,7 +767,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
 		inode = NULL;
 	else if (IS_ERR(fid))
 		inode = ERR_CAST(fid);
-	else if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
+	else if (v9ses->cache & (CACHE_META|CACHE_LOOSE))
 		inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
 	else
 		inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
@@ -816,7 +822,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
 	perm = unixmode2p9mode(v9ses, mode);
 	p9_omode = v9fs_uflags2omode(flags, v9fs_proto_dotu(v9ses));
 
-	if ((v9ses->cache >= CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) {
+	if ((v9ses->cache & CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) {
 		p9_omode = (p9_omode & !P9_OWRITE) | P9_ORDWR;
 		p9_debug(P9_DEBUG_CACHE,
 			"write-only file with writeback enabled, creating w/ O_RDWR\n");
@@ -835,9 +841,11 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
 		goto error;
 
 	file->private_data = fid;
-	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
+#ifdef CONFIG_9P_FSCACHE
+	if (v9ses->cache & 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);
@@ -1008,10 +1016,10 @@ v9fs_vfs_getattr(struct mnt_idmap *idmap, const struct path *path,
 
 	p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
 	v9ses = v9fs_dentry2v9ses(dentry);
-	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+	if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
 		generic_fillattr(&nop_mnt_idmap, inode, stat);
 		return 0;
-	} else if (v9ses->cache >= CACHE_WRITEBACK) {
+	} else if (v9ses->cache & CACHE_WRITEBACK) {
 		if (S_ISREG(inode->i_mode)) {
 			int retval = filemap_fdatawrite(inode->i_mapping);
 
@@ -1050,7 +1058,6 @@ static int v9fs_vfs_setattr(struct mnt_idmap *idmap,
 {
 	int retval, use_dentry = 0;
 	struct inode *inode = d_inode(dentry);
-	struct v9fs_inode *v9inode = V9FS_I(inode);
 	struct v9fs_session_info *v9ses;
 	struct p9_fid *fid = NULL;
 	struct p9_wstat wstat;
@@ -1115,8 +1122,13 @@ static int v9fs_vfs_setattr(struct mnt_idmap *idmap,
 		truncate_setsize(inode, iattr->ia_size);
 		truncate_pagecache(inode, iattr->ia_size);
 
-		if (v9ses->cache == CACHE_FSCACHE)
+#ifdef CONFIG_9P_FSCACHE
+		if (v9ses->cache & CACHE_FSCACHE) {
+			struct v9fs_inode *v9inode = V9FS_I(inode);
+
 			fscache_resize_cookie(v9fs_inode_cookie(v9inode), iattr->ia_size);
+		}
+#endif
 	}
 
 	v9fs_invalidate_inode_attr(inode);
@@ -1400,7 +1412,7 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
 	 * We don't want to refresh inode->i_size,
 	 * because we may have cached data
 	 */
-	flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
+	flags = (v9ses->cache & CACHE_LOOSE) ?
 		V9FS_STAT2INODE_KEEP_ISIZE : 0;
 	v9fs_stat2inode(st, inode, inode->i_sb, flags);
 out:
diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
index 4b9488cb7a56..a1c7dae6795c 100644
--- a/fs/9p/vfs_inode_dotl.c
+++ b/fs/9p/vfs_inode_dotl.c
@@ -287,7 +287,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
 		goto out;
 	}
 
-	if ((v9ses->cache >= CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) {
+	if ((v9ses->cache & CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) {
 		p9_omode = (p9_omode & !P9_OWRITE) | P9_ORDWR;
 		p9_debug(P9_DEBUG_CACHE,
 			"write-only file with writeback enabled, creating w/ O_RDWR\n");
@@ -325,7 +325,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
 		goto out;
 	file->private_data = ofid;
 #ifdef CONFIG_9P_FSCACHE
-	if (v9ses->cache == CACHE_FSCACHE) {
+	if (v9ses->cache & CACHE_FSCACHE) {
 		struct v9fs_inode *v9inode = V9FS_I(inode);
 		fscache_use_cookie(v9fs_inode_cookie(v9inode),
 				   file->f_mode & FMODE_WRITE);
@@ -403,7 +403,7 @@ static int v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap,
 	}
 
 	/* instantiate inode and assign the unopened fid to the dentry */
-	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+	if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
 		inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
 		if (IS_ERR(inode)) {
 			err = PTR_ERR(inode);
@@ -451,7 +451,7 @@ v9fs_vfs_getattr_dotl(struct mnt_idmap *idmap,
 
 	p9_debug(P9_DEBUG_VFS, "dentry: %p\n", dentry);
 	v9ses = v9fs_dentry2v9ses(dentry);
-	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+	if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
 		generic_fillattr(&nop_mnt_idmap, inode, stat);
 		return 0;
 	} else if (v9ses->cache) {
@@ -538,7 +538,6 @@ int v9fs_vfs_setattr_dotl(struct mnt_idmap *idmap,
 {
 	int retval, use_dentry = 0;
 	struct inode *inode = d_inode(dentry);
-	struct v9fs_inode *v9inode = V9FS_I(inode);
 	struct v9fs_session_info *v9ses;
 	struct p9_fid *fid = NULL;
 	struct p9_iattr_dotl p9attr = {
@@ -603,8 +602,11 @@ int v9fs_vfs_setattr_dotl(struct mnt_idmap *idmap,
 		truncate_setsize(inode, iattr->ia_size);
 		truncate_pagecache(inode, iattr->ia_size);
 
-		if (v9ses->cache == CACHE_FSCACHE)
-			fscache_resize_cookie(v9fs_inode_cookie(v9inode), iattr->ia_size);
+#ifdef CONFIG_9P_FSCACHE
+		if (v9ses->cache & CACHE_FSCACHE)
+			fscache_resize_cookie(v9fs_inode_cookie(V9FS_I(inode)),
+				iattr->ia_size);
+#endif
 	}
 
 	v9fs_invalidate_inode_attr(inode);
@@ -732,7 +734,7 @@ v9fs_vfs_symlink_dotl(struct mnt_idmap *idmap, struct inode *dir,
 	}
 
 	v9fs_invalidate_inode_attr(dir);
-	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+	if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
 		/* Now walk from the parent so we can get an unopened fid. */
 		fid = p9_client_walk(dfid, 1, &name, 1);
 		if (IS_ERR(fid)) {
@@ -809,7 +811,7 @@ v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
 	}
 
 	v9fs_invalidate_inode_attr(dir);
-	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+	if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
 		/* Get the latest stat info from server. */
 		struct p9_fid *fid;
 
@@ -886,7 +888,7 @@ v9fs_vfs_mknod_dotl(struct mnt_idmap *idmap, struct inode *dir,
 	}
 
 	/* instantiate inode and assign the unopened fid to the dentry */
-	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+	if (v9ses->cache & (CACHE_META|CACHE_LOOSE)) {
 		inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
 		if (IS_ERR(inode)) {
 			err = PTR_ERR(inode);
@@ -971,7 +973,7 @@ int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
 	 * We don't want to refresh inode->i_size,
 	 * because we may have cached data
 	 */
-	flags = (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) ?
+	flags = (v9ses->cache & CACHE_LOOSE) ?
 		V9FS_STAT2INODE_KEEP_ISIZE : 0;
 	v9fs_stat2inode_dotl(st, inode, flags);
 out:
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index af83b39e340c..c6cbc666a4c1 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -136,7 +136,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
 	if (retval)
 		goto release_sb;
 
-	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
+	if (v9ses->cache & (CACHE_META|CACHE_LOOSE))
 		sb->s_d_op = &v9fs_cached_dentry_operations;
 	else
 		sb->s_d_op = &v9fs_dentry_operations;
@@ -277,7 +277,7 @@ static int v9fs_drop_inode(struct inode *inode)
 	struct v9fs_session_info *v9ses;
 
 	v9ses = v9fs_inode2v9ses(inode);
-	if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
+	if (v9ses->cache & (CACHE_META|CACHE_LOOSE))
 		return generic_drop_inode(inode);
 	/*
 	 * in case of non cached mode always drop the

---
base-commit: 1543b4c5071c54d76aad7a7a26a6e43082269b0c
change-id: 20230401-ericvh-dev-rework-cache-options-2c6638bea240

Best regards,
-- 
Eric Van Hensbergen <ericvh@kernel.org>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/9p: Rework cache modes and add new options to Documentation
  2023-04-01 23:16 [PATCH] fs/9p: Rework cache modes and add new options to Documentation Eric Van Hensbergen
@ 2023-04-02  0:37 ` kernel test robot
  2023-04-02  1:32 ` Randy Dunlap
  2023-04-02 10:34 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2023-04-02  0:37 UTC (permalink / raw)
  To: Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
	Christian Schoenebeck, v9fs
  Cc: oe-kbuild-all, v9fs-developer, linux-doc, linux-kernel,
	Eric Van Hensbergen

Hi Eric,

I love your patch! Perhaps something to improve:

[auto build test WARNING on 1543b4c5071c54d76aad7a7a26a6e43082269b0c]

url:    https://github.com/intel-lab-lkp/linux/commits/Eric-Van-Hensbergen/fs-9p-Rework-cache-modes-and-add-new-options-to-Documentation/20230402-071815
base:   1543b4c5071c54d76aad7a7a26a6e43082269b0c
patch link:    https://lore.kernel.org/r/20230401-ericvh-dev-rework-cache-options-v1-1-12d3adbdd33a%40kernel.org
patch subject: [PATCH] fs/9p: Rework cache modes and add new options to Documentation
config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20230402/202304020858.JARvGo8W-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/8d563b947e70b7fe9a067ef3be10471a05452505
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Eric-Van-Hensbergen/fs-9p-Rework-cache-modes-and-add-new-options-to-Documentation/20230402-071815
        git checkout 8d563b947e70b7fe9a067ef3be10471a05452505
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/9p/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304020858.JARvGo8W-lkp@intel.com/

All warnings (new ones prefixed by >>):

   fs/9p/vfs_inode.c: In function 'v9fs_evict_inode':
>> fs/9p/vfs_inode.c:375:16: warning: variable 'version' set but not used [-Wunused-but-set-variable]
     375 |         __le32 version;
         |                ^~~~~~~
   fs/9p/vfs_inode.c: In function 'v9fs_vfs_atomic_open':
>> fs/9p/vfs_inode.c:799:28: warning: variable 'v9inode' set but not used [-Wunused-but-set-variable]
     799 |         struct v9fs_inode *v9inode;
         |                            ^~~~~~~
--
   fs/9p/vfs_inode_dotl.c: In function 'v9fs_vfs_setattr_dotl':
>> fs/9p/vfs_inode_dotl.c:541:35: warning: variable 'v9ses' set but not used [-Wunused-but-set-variable]
     541 |         struct v9fs_session_info *v9ses;
         |                                   ^~~~~


vim +/version +375 fs/9p/vfs_inode.c

2bad8471511ce5 Eric Van Hensbergen 2005-09-09  366  
60e78d2c993e58 Abhishek Kulkarni   2009-09-23  367  /**
bc868036569e1d David Howells       2021-10-04  368   * v9fs_evict_inode - Remove an inode from the inode cache
60e78d2c993e58 Abhishek Kulkarni   2009-09-23  369   * @inode: inode to release
60e78d2c993e58 Abhishek Kulkarni   2009-09-23  370   *
60e78d2c993e58 Abhishek Kulkarni   2009-09-23  371   */
b57922d97fd6f7 Al Viro             2010-06-07  372  void v9fs_evict_inode(struct inode *inode)
60e78d2c993e58 Abhishek Kulkarni   2009-09-23  373  {
6b39f6d22fbf67 Aneesh Kumar K.V    2011-02-28  374  	struct v9fs_inode *v9inode = V9FS_I(inode);
93c846143d8630 David Howells       2020-11-18 @375  	__le32 version;
6b39f6d22fbf67 Aneesh Kumar K.V    2011-02-28  376  
4ad78628445d26 Al Viro             2015-12-08  377  	truncate_inode_pages_final(&inode->i_data);
93c846143d8630 David Howells       2020-11-18  378  	version = cpu_to_le32(v9inode->qid.version);
8d563b947e70b7 Eric Van Hensbergen 2023-04-01  379  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/9p: Rework cache modes and add new options to Documentation
  2023-04-01 23:16 [PATCH] fs/9p: Rework cache modes and add new options to Documentation Eric Van Hensbergen
  2023-04-02  0:37 ` kernel test robot
@ 2023-04-02  1:32 ` Randy Dunlap
  2023-04-02 10:34 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: Randy Dunlap @ 2023-04-02  1:32 UTC (permalink / raw)
  To: Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
	Christian Schoenebeck, v9fs
  Cc: v9fs-developer, linux-doc, linux-kernel

Hi--

On 4/1/23 16:16, Eric Van Hensbergen wrote:
> diff --git a/Documentation/filesystems/9p.rst b/Documentation/filesystems/9p.rst
> index 0e800b8f73cc..d79bf4e41a71 100644
> --- a/Documentation/filesystems/9p.rst
> +++ b/Documentation/filesystems/9p.rst
> @@ -78,19 +78,39 @@ Options
>    		offering several exported file systems.
>  
>    cache=mode	specifies a caching policy.  By default, no caches are used.
> -
> -                        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=none
> +		The mode can be specified as a bitmask or by using one of the
> +		prexisting common 'shortcuts'.
> +		The bitmask is described below: (unspecified bits are reserved)
> +
> +			==========	================================================
> +			0b00000000	all caches disabled, mmap disabled
> +			0b00000001	file caches enabled
> +			0b00000010	meta-data caches enabled
> +			0b00000100	writeback behavior (as opposed to writethrough)
> +			0b00001000	loose caches (no explicit consistency with server)
> +			0b10000000	fscache enabled for persistent caching
> +			=========	================================================
> +

Extend the === lines to that no text extends beyond the last '=' character,
both above and below.
Otherwise there will be warnings.

> +		The current shortcuts and their associated bitmask are:
> +
> +			=========	=============================================
> +			none		0b00000000 (no caching)
> +			readahead	0b00000001 (only read-ahead file caching)
> +			mmap		0b00000101 (read-ahead + writeback file cache)
> +			loose		0b00001111 (non-coherent file and meta-data caches)
> +			fscache		0b10001111 (persistent loose cache)
> +			=========	=============================================
> +
> +		NOTE: only these shortcuts are tested modes of operation at the
> +		moment, so using other combinations of bit-patterns is not
> +		known to work.  Work on better cache support is in progress.
> +
> +		IMPORTANT: loose caches (and by extension at the moment fscache)
> +		do not necessarily validate cached values on the server.  In other
> +		words changes on the server are not guaranteed to be reflected
> +		on the client system.  Only use this mode of operation if you
> +		have an exclusive mount and the server will modify the filesystem
> +		underneath you.
>  
>    debug=n	specifies debug level.  The debug level is a bitmask.
>  
> @@ -137,6 +157,10 @@ Options
>    		This can be used to share devices/named pipes/sockets between
>  		hosts.  This functionality will be expanded in later versions.
>  
> +  directio	bypass page cache on all read/write operations
> +
> +  ignoreqv	ignore qid.version==0 as a marker to ignore cache
> +
>    noxattr	do not offer xattr functions on this mount.
>  
>    access	there are four access modes.

-- 
~Randy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/9p: Rework cache modes and add new options to Documentation
  2023-04-01 23:16 [PATCH] fs/9p: Rework cache modes and add new options to Documentation Eric Van Hensbergen
  2023-04-02  0:37 ` kernel test robot
  2023-04-02  1:32 ` Randy Dunlap
@ 2023-04-02 10:34 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2023-04-02 10:34 UTC (permalink / raw)
  To: Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet,
	Christian Schoenebeck, v9fs
  Cc: oe-kbuild-all, v9fs-developer, linux-doc, linux-kernel,
	Eric Van Hensbergen

Hi Eric,

I love your patch! Perhaps something to improve:

[auto build test WARNING on 1543b4c5071c54d76aad7a7a26a6e43082269b0c]

url:    https://github.com/intel-lab-lkp/linux/commits/Eric-Van-Hensbergen/fs-9p-Rework-cache-modes-and-add-new-options-to-Documentation/20230402-071815
base:   1543b4c5071c54d76aad7a7a26a6e43082269b0c
patch link:    https://lore.kernel.org/r/20230401-ericvh-dev-rework-cache-options-v1-1-12d3adbdd33a%40kernel.org
patch subject: [PATCH] fs/9p: Rework cache modes and add new options to Documentation
reproduce:
        # https://github.com/intel-lab-lkp/linux/commit/8d563b947e70b7fe9a067ef3be10471a05452505
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Eric-Van-Hensbergen/fs-9p-Rework-cache-modes-and-add-new-options-to-Documentation/20230402-071815
        git checkout 8d563b947e70b7fe9a067ef3be10471a05452505
        make menuconfig
        # enable CONFIG_COMPILE_TEST, CONFIG_WARN_MISSING_DOCUMENTS, CONFIG_WARN_ABI_ERRORS
        make htmldocs

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304021848.dGo1cazM-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> Documentation/filesystems/9p.rst:92: WARNING: Malformed table.

vim +92 Documentation/filesystems/9p.rst

    58	
    59	  ============= ===============================================================
    60	  trans=name	select an alternative transport.  Valid options are
    61	  		currently:
    62	
    63				========  ============================================
    64				unix 	  specifying a named pipe mount point
    65				tcp	  specifying a normal TCP/IP connection
    66				fd   	  used passed file descriptors for connection
    67	                                  (see rfdno and wfdno)
    68				virtio	  connect to the next virtio channel available
    69					  (from QEMU with trans_virtio module)
    70				rdma	  connect to a specified RDMA channel
    71				========  ============================================
    72	
    73	  uname=name	user name to attempt mount as on the remote server.  The
    74	  		server may override or ignore this value.  Certain user
    75			names may require authentication.
    76	
    77	  aname=name	aname specifies the file tree to access when the server is
    78	  		offering several exported file systems.
    79	
    80	  cache=mode	specifies a caching policy.  By default, no caches are used.
    81			The mode can be specified as a bitmask or by using one of the
    82			prexisting common 'shortcuts'.
    83			The bitmask is described below: (unspecified bits are reserved)
    84	
    85				==========	================================================
    86				0b00000000	all caches disabled, mmap disabled
    87				0b00000001	file caches enabled
    88				0b00000010	meta-data caches enabled
    89				0b00000100	writeback behavior (as opposed to writethrough)
    90				0b00001000	loose caches (no explicit consistency with server)
    91				0b10000000	fscache enabled for persistent caching
  > 92				=========	================================================
    93	
    94			The current shortcuts and their associated bitmask are:
    95	
    96				=========	=============================================
    97				none		0b00000000 (no caching)
    98				readahead	0b00000001 (only read-ahead file caching)
    99				mmap		0b00000101 (read-ahead + writeback file cache)
   100				loose		0b00001111 (non-coherent file and meta-data caches)
   101				fscache		0b10001111 (persistent loose cache)
   102				=========	=============================================
   103	
   104			NOTE: only these shortcuts are tested modes of operation at the
   105			moment, so using other combinations of bit-patterns is not
   106			known to work.  Work on better cache support is in progress.
   107	
   108			IMPORTANT: loose caches (and by extension at the moment fscache)
   109			do not necessarily validate cached values on the server.  In other
   110			words changes on the server are not guaranteed to be reflected
   111			on the client system.  Only use this mode of operation if you
   112			have an exclusive mount and the server will modify the filesystem
   113			underneath you.
   114	
   115	  debug=n	specifies debug level.  The debug level is a bitmask.
   116	
   117				=====   ================================
   118				0x01    display verbose error messages
   119				0x02    developer debug (DEBUG_CURRENT)
   120				0x04    display 9p trace
   121				0x08    display VFS trace
   122				0x10    display Marshalling debug
   123				0x20    display RPC debug
   124				0x40    display transport debug
   125				0x80    display allocation debug
   126				0x100   display protocol message debug
   127				0x200   display Fid debug
   128				0x400   display packet debug
   129				0x800   display fscache tracing debug
   130				=====   ================================
   131	
   132	  rfdno=n	the file descriptor for reading with trans=fd
   133	
   134	  wfdno=n	the file descriptor for writing with trans=fd
   135	
   136	  msize=n	the number of bytes to use for 9p packet payload
   137	
   138	  port=n	port to connect to on the remote server
   139	
   140	  noextend	force legacy mode (no 9p2000.u or 9p2000.L semantics)
   141	
   142	  version=name	Select 9P protocol version. Valid options are:
   143	
   144				========        ==============================
   145				9p2000          Legacy mode (same as noextend)
   146				9p2000.u        Use 9P2000.u protocol
   147				9p2000.L        Use 9P2000.L protocol
   148				========        ==============================
   149	
   150	  dfltuid	attempt to mount as a particular uid
   151	
   152	  dfltgid	attempt to mount with a particular gid
   153	
   154	  afid		security channel - used by Plan 9 authentication protocols
   155	
   156	  nodevmap	do not map special files - represent them as normal files.
   157	  		This can be used to share devices/named pipes/sockets between
   158			hosts.  This functionality will be expanded in later versions.
   159	
   160	  directio	bypass page cache on all read/write operations
   161	
   162	  ignoreqv	ignore qid.version==0 as a marker to ignore cache
   163	
   164	  noxattr	do not offer xattr functions on this mount.
   165	
   166	  access	there are four access modes.
   167				user
   168					if a user tries to access a file on v9fs
   169				        filesystem for the first time, v9fs sends an
   170				        attach command (Tattach) for that user.
   171					This is the default mode.
   172				<uid>
   173					allows only user with uid=<uid> to access
   174					the files on the mounted filesystem
   175				any
   176					v9fs does single attach and performs all
   177					operations as one user
   178				clien
   179					 ACL based access check on the 9p client
   180				         side for access validation
   181	
   182	  cachetag	cache tag to use the specified persistent cache.
   183			cache tags for existing cache sessions can be listed at
   184			/sys/fs/9p/caches. (applies only to cache=fscache)
   185	  ============= ===============================================================
   186	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-02 10:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-01 23:16 [PATCH] fs/9p: Rework cache modes and add new options to Documentation Eric Van Hensbergen
2023-04-02  0:37 ` kernel test robot
2023-04-02  1:32 ` Randy Dunlap
2023-04-02 10:34 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).