Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/fs/9p/v9fs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  This file contains functions assisting in mapping VFS to 9P2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/cred.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <net/9p/9p.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <net/9p/client.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/9p/transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "v9fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "v9fs_vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "cache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static DEFINE_SPINLOCK(v9fs_sessionlist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static LIST_HEAD(v9fs_sessionlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct kmem_cache *v9fs_inode_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * Option Parsing (code inspired by NFS code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *  NOTE: each transport will parse its own options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* Options that take integer arguments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	Opt_debug, Opt_dfltuid, Opt_dfltgid, Opt_afid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	/* String options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	Opt_uname, Opt_remotename, Opt_cache, Opt_cachetag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	/* Options that take no arguments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	Opt_nodevmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/* Cache options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	Opt_cache_loose, Opt_fscache, Opt_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	/* Access options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	Opt_access, Opt_posixacl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	/* Lock timeout option */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	Opt_locktimeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	/* Error token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	Opt_err
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static const match_table_t tokens = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	{Opt_debug, "debug=%x"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	{Opt_dfltuid, "dfltuid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	{Opt_dfltgid, "dfltgid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	{Opt_afid, "afid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	{Opt_uname, "uname=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	{Opt_remotename, "aname=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	{Opt_nodevmap, "nodevmap"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	{Opt_cache, "cache=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	{Opt_cache_loose, "loose"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	{Opt_fscache, "fscache"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	{Opt_mmap, "mmap"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	{Opt_cachetag, "cachetag=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	{Opt_access, "access=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	{Opt_posixacl, "posixacl"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	{Opt_locktimeout, "locktimeout=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	{Opt_err, NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static const char *const v9fs_cache_modes[nr__p9_cache_modes] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	[CACHE_NONE]	= "none",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	[CACHE_MMAP]	= "mmap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	[CACHE_LOOSE]	= "loose",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	[CACHE_FSCACHE]	= "fscache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) /* Interpret mount options for cache mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static int get_cache_mode(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int version = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!strcmp(s, "loose")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		version = CACHE_LOOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		p9_debug(P9_DEBUG_9P, "Cache mode: loose\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	} else if (!strcmp(s, "fscache")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		version = CACHE_FSCACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		p9_debug(P9_DEBUG_9P, "Cache mode: fscache\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	} else if (!strcmp(s, "mmap")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		version = CACHE_MMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		p9_debug(P9_DEBUG_9P, "Cache mode: mmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	} else if (!strcmp(s, "none")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		version = CACHE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		p9_debug(P9_DEBUG_9P, "Cache mode: none\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		pr_info("Unknown Cache mode %s\n", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * Display the mount options in /proc/mounts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int v9fs_show_options(struct seq_file *m, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct v9fs_session_info *v9ses = root->d_sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (v9ses->debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		seq_printf(m, ",debug=%x", v9ses->debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (!uid_eq(v9ses->dfltuid, V9FS_DEFUID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		seq_printf(m, ",dfltuid=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			   from_kuid_munged(&init_user_ns, v9ses->dfltuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!gid_eq(v9ses->dfltgid, V9FS_DEFGID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		seq_printf(m, ",dfltgid=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			   from_kgid_munged(&init_user_ns, v9ses->dfltgid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (v9ses->afid != ~0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		seq_printf(m, ",afid=%u", v9ses->afid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (strcmp(v9ses->uname, V9FS_DEFUSER) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		seq_printf(m, ",uname=%s", v9ses->uname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (strcmp(v9ses->aname, V9FS_DEFANAME) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		seq_printf(m, ",aname=%s", v9ses->aname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (v9ses->nodev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		seq_puts(m, ",nodevmap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (v9ses->cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		seq_printf(m, ",%s", v9fs_cache_modes[v9ses->cache]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (v9ses->cachetag && v9ses->cache == CACHE_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		seq_printf(m, ",cachetag=%s", v9ses->cachetag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	switch (v9ses->flags & V9FS_ACCESS_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	case V9FS_ACCESS_USER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		seq_puts(m, ",access=user");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	case V9FS_ACCESS_ANY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		seq_puts(m, ",access=any");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	case V9FS_ACCESS_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		seq_puts(m, ",access=client");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	case V9FS_ACCESS_SINGLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		seq_printf(m, ",access=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			   from_kuid_munged(&init_user_ns, v9ses->uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (v9ses->flags & V9FS_POSIX_ACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		seq_puts(m, ",posixacl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return p9_show_client_options(m, v9ses->clnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * v9fs_parse_options - parse mount options into session structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * @v9ses: existing v9fs session information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * Return 0 upon success, -ERRNO upon failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static int v9fs_parse_options(struct v9fs_session_info *v9ses, char *opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	char *options, *tmp_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int option = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	char *s, *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/* setup defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	v9ses->afid = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	v9ses->debug = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	v9ses->cache = CACHE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	v9ses->cachetag = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	v9ses->session_lock_timeout = P9_LOCK_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (!opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	tmp_options = kstrdup(opts, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!tmp_options) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		goto fail_option_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	options = tmp_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	while ((p = strsep(&options, ",")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		int token, r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if (!*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		case Opt_debug:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			r = match_int(&args[0], &option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 					 "integer field, but no integer?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 				ret = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 				v9ses->debug = option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #ifdef CONFIG_NET_9P_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 				p9_debug_level = option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		case Opt_dfltuid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			r = match_int(&args[0], &option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 					 "integer field, but no integer?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 				ret = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			v9ses->dfltuid = make_kuid(current_user_ns(), option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			if (!uid_valid(v9ses->dfltuid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 					 "uid field, but not a uid?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		case Opt_dfltgid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			r = match_int(&args[0], &option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 					 "integer field, but no integer?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 				ret = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			v9ses->dfltgid = make_kgid(current_user_ns(), option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			if (!gid_valid(v9ses->dfltgid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 					 "gid field, but not a gid?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 				ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		case Opt_afid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			r = match_int(&args[0], &option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 					 "integer field, but no integer?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				ret = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				v9ses->afid = option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		case Opt_uname:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			kfree(v9ses->uname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			v9ses->uname = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			if (!v9ses->uname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				goto free_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		case Opt_remotename:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			kfree(v9ses->aname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			v9ses->aname = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			if (!v9ses->aname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 				goto free_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		case Opt_nodevmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			v9ses->nodev = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		case Opt_cache_loose:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			v9ses->cache = CACHE_LOOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		case Opt_fscache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			v9ses->cache = CACHE_FSCACHE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		case Opt_mmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			v9ses->cache = CACHE_MMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		case Opt_cachetag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			kfree(v9ses->cachetag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			v9ses->cachetag = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			if (!v9ses->cachetag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 				goto free_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		case Opt_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			s = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			if (!s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 				ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 					 "problem allocating copy of cache arg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 				goto free_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			r = get_cache_mode(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 				ret = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				v9ses->cache = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		case Opt_access:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			s = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			if (!s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 				ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 					 "problem allocating copy of access arg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 				goto free_and_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			v9ses->flags &= ~V9FS_ACCESS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			if (strcmp(s, "user") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 				v9ses->flags |= V9FS_ACCESS_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			else if (strcmp(s, "any") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 				v9ses->flags |= V9FS_ACCESS_ANY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			else if (strcmp(s, "client") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 				v9ses->flags |= V9FS_ACCESS_CLIENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 				uid_t uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 				v9ses->flags |= V9FS_ACCESS_SINGLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 				uid = simple_strtoul(s, &e, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 				if (*e != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 					ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 					pr_info("Unknown access argument %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 						s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 					kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				v9ses->uid = make_kuid(current_user_ns(), uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				if (!uid_valid(v9ses->uid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 					ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 					pr_info("Unknown uid %s\n", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			kfree(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		case Opt_posixacl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #ifdef CONFIG_9P_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			v9ses->flags |= V9FS_POSIX_ACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 				 "Not defined CONFIG_9P_FS_POSIX_ACL. Ignoring posixacl option\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		case Opt_locktimeout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			r = match_int(&args[0], &option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 					 "integer field, but no integer?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				ret = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			if (option < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 				p9_debug(P9_DEBUG_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 					 "locktimeout must be a greater than zero integer.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 				ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			v9ses->session_lock_timeout = (long)option * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) free_and_return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	kfree(tmp_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) fail_option_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  * v9fs_session_init - initialize session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  * @v9ses: session information structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  * @dev_name: device being mounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  * @data: options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		  const char *dev_name, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	int rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	v9ses->uname = kstrdup(V9FS_DEFUSER, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (!v9ses->uname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		goto err_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	v9ses->aname = kstrdup(V9FS_DEFANAME, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (!v9ses->aname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		goto err_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	init_rwsem(&v9ses->rename_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	v9ses->uid = INVALID_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	v9ses->dfltuid = V9FS_DEFUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	v9ses->dfltgid = V9FS_DEFGID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	v9ses->clnt = p9_client_create(dev_name, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (IS_ERR(v9ses->clnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		rc = PTR_ERR(v9ses->clnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		p9_debug(P9_DEBUG_ERROR, "problem initializing 9p client\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		goto err_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	v9ses->flags = V9FS_ACCESS_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (p9_is_proto_dotl(v9ses->clnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		v9ses->flags = V9FS_ACCESS_CLIENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		v9ses->flags |= V9FS_PROTO_2000L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	} else if (p9_is_proto_dotu(v9ses->clnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		v9ses->flags |= V9FS_PROTO_2000U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	rc = v9fs_parse_options(v9ses, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		goto err_clnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (!v9fs_proto_dotl(v9ses) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	    ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_CLIENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		 * We support ACCESS_CLIENT only for dotl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		 * Fall back to ACCESS_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		v9ses->flags &= ~V9FS_ACCESS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		v9ses->flags |= V9FS_ACCESS_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	/*FIXME !! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	/* for legacy mode, fall back to V9FS_ACCESS_ANY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (!(v9fs_proto_dotu(v9ses) || v9fs_proto_dotl(v9ses)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		v9ses->flags &= ~V9FS_ACCESS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		v9ses->flags |= V9FS_ACCESS_ANY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		v9ses->uid = INVALID_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	if (!v9fs_proto_dotl(v9ses) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		!((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_CLIENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		 * We support ACL checks on clinet only if the protocol is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		 * 9P2000.L and access is V9FS_ACCESS_CLIENT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		v9ses->flags &= ~V9FS_ACL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	fid = p9_client_attach(v9ses->clnt, NULL, v9ses->uname, INVALID_UID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 							v9ses->aname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (IS_ERR(fid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		rc = PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		p9_debug(P9_DEBUG_ERROR, "cannot attach\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		goto err_clnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_SINGLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		fid->uid = v9ses->uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		fid->uid = INVALID_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	/* register the session for caching */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	v9fs_cache_session_get_cookie(v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	spin_lock(&v9fs_sessionlist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	list_add(&v9ses->slist, &v9fs_sessionlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	spin_unlock(&v9fs_sessionlist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	return fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) err_clnt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	kfree(v9ses->cachetag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	p9_client_destroy(v9ses->clnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) err_names:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	kfree(v9ses->uname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	kfree(v9ses->aname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)  * v9fs_session_close - shutdown a session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)  * @v9ses: session information structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) void v9fs_session_close(struct v9fs_session_info *v9ses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	if (v9ses->clnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		p9_client_destroy(v9ses->clnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		v9ses->clnt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (v9ses->fscache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		v9fs_cache_session_put_cookie(v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	kfree(v9ses->cachetag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	kfree(v9ses->uname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	kfree(v9ses->aname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	spin_lock(&v9fs_sessionlist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	list_del(&v9ses->slist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	spin_unlock(&v9fs_sessionlist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)  * v9fs_session_cancel - terminate a session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  * @v9ses: session to terminate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)  * mark transport as disconnected and cancel all pending requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	p9_debug(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	p9_client_disconnect(v9ses->clnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)  * v9fs_session_begin_cancel - Begin terminate of a session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)  * @v9ses: session to terminate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  * After this call we don't allow any request other than clunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	p9_debug(P9_DEBUG_ERROR, "begin cancel session %p\n", v9ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	p9_client_begin_disconnect(v9ses->clnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) extern int v9fs_error_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static struct kobject *v9fs_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)  * caches_show - list caches associated with a session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)  * Returns the size of buffer written.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static ssize_t caches_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 			   struct kobj_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 			   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	ssize_t n = 0, count = 0, limit = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	spin_lock(&v9fs_sessionlist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	list_for_each_entry(v9ses, &v9fs_sessionlist, slist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		if (v9ses->cachetag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 			n = snprintf(buf, limit, "%s\n", v9ses->cachetag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 			if (n < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 				count = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 			count += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 			limit -= n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	spin_unlock(&v9fs_sessionlist_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static struct kobj_attribute v9fs_attr_cache = __ATTR_RO(caches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) #endif /* CONFIG_9P_FSCACHE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static struct attribute *v9fs_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	&v9fs_attr_cache.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) static struct attribute_group v9fs_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	.attrs = v9fs_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)  * v9fs_sysfs_init - Initialize the v9fs sysfs interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static int __init v9fs_sysfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	v9fs_kobj = kobject_create_and_add("9p", fs_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	if (!v9fs_kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	if (sysfs_create_group(v9fs_kobj, &v9fs_attr_group)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		kobject_put(v9fs_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)  * v9fs_sysfs_cleanup - Unregister the v9fs sysfs interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) static void v9fs_sysfs_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	sysfs_remove_group(v9fs_kobj, &v9fs_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	kobject_put(v9fs_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) static void v9fs_inode_init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	struct v9fs_inode *v9inode = (struct v9fs_inode *)foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	v9inode->fscache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	memset(&v9inode->qid, 0, sizeof(v9inode->qid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	inode_init_once(&v9inode->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)  * v9fs_init_inode_cache - initialize a cache for 9P
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)  * Returns 0 on success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static int v9fs_init_inode_cache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	v9fs_inode_cache = kmem_cache_create("v9fs_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 					  sizeof(struct v9fs_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 					  0, (SLAB_RECLAIM_ACCOUNT|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 					      SLAB_MEM_SPREAD|SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 					  v9fs_inode_init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	if (!v9fs_inode_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)  * v9fs_destroy_inode_cache - destroy the cache of 9P inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) static void v9fs_destroy_inode_cache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	 * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	 * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	kmem_cache_destroy(v9fs_inode_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) static int v9fs_cache_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	ret = v9fs_init_inode_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	ret = fscache_register_netfs(&v9fs_cache_netfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		v9fs_destroy_inode_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) static void v9fs_cache_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	v9fs_destroy_inode_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) #ifdef CONFIG_9P_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	fscache_unregister_netfs(&v9fs_cache_netfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)  * init_v9fs - Initialize module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static int __init init_v9fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	pr_info("Installing v9fs 9p2000 file system support\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	/* TODO: Setup list of registered trasnport modules */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	err = v9fs_cache_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		pr_err("Failed to register v9fs for caching\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	err = v9fs_sysfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		pr_err("Failed to register with sysfs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		goto out_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	err = register_filesystem(&v9fs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		pr_err("Failed to register filesystem\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 		goto out_sysfs_cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) out_sysfs_cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	v9fs_sysfs_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) out_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	v9fs_cache_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)  * exit_v9fs - shutdown module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) static void __exit exit_v9fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	v9fs_sysfs_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	v9fs_cache_unregister();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	unregister_filesystem(&v9fs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) module_init(init_v9fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) module_exit(exit_v9fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);