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