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