Unverified Commit 4eb31178 authored by Eric Van Hensbergen's avatar Eric Van Hensbergen
Browse files

fs/9p: Rework cache modes and add new options to Documentation



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: default avatarEric Van Hensbergen <ericvh@kernel.org>
parent 1543b4c5
Loading
Loading
Loading
Loading
+37 −13
Original line number Diff line number Diff line
@@ -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.
+1 −2
Original line number Diff line number Diff line
@@ -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);
+1 −3
Original line number Diff line number Diff line
@@ -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
+12 −22
Original line number Diff line number Diff line
@@ -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;
+43 −24
Original line number Diff line number Diff line
@@ -43,23 +43,42 @@ enum p9_session_flags {
	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
Loading