Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1 | /* |
| 2 | * net/9p/clnt.c |
| 3 | * |
| 4 | * 9P Client |
| 5 | * |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 6 | * Copyright (C) 2008 by Eric Van Hensbergen <ericvh@gmail.com> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 7 | * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 |
| 11 | * as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to: |
| 20 | * Free Software Foundation |
| 21 | * 51 Franklin Street, Fifth Floor |
| 22 | * Boston, MA 02111-1301 USA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/fs.h> |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 29 | #include <linux/poll.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 30 | #include <linux/idr.h> |
| 31 | #include <linux/mutex.h> |
| 32 | #include <linux/sched.h> |
| 33 | #include <linux/uaccess.h> |
| 34 | #include <net/9p/9p.h> |
Eric Van Hensbergen | fb0466c | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 35 | #include <linux/parser.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 36 | #include <net/9p/client.h> |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 37 | #include <net/9p/transport.h> |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 38 | #include "protocol.h" |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 39 | |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 40 | /* |
| 41 | * Client Option Parsing (code inspired by NFS code) |
| 42 | * - a little lazy - parse all client options |
| 43 | */ |
| 44 | |
| 45 | enum { |
| 46 | Opt_msize, |
| 47 | Opt_trans, |
| 48 | Opt_legacy, |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 49 | Opt_version, |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 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 | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 54 | {Opt_msize, "msize=%u"}, |
| 55 | {Opt_legacy, "noextend"}, |
| 56 | {Opt_trans, "trans=%s"}, |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 57 | {Opt_version, "version=%s"}, |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 58 | {Opt_err, NULL}, |
| 59 | }; |
| 60 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 61 | inline int p9_is_proto_dotl(struct p9_client *clnt) |
| 62 | { |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 63 | return (clnt->proto_version == p9_proto_2000L); |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 64 | } |
| 65 | EXPORT_SYMBOL(p9_is_proto_dotl); |
| 66 | |
| 67 | inline int p9_is_proto_dotu(struct p9_client *clnt) |
| 68 | { |
| 69 | return (clnt->proto_version == p9_proto_2000u); |
| 70 | } |
| 71 | EXPORT_SYMBOL(p9_is_proto_dotu); |
| 72 | |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 73 | /* Interpret mount option for protocol version */ |
Dan Carpenter | 3dc9fef | 2010-04-05 14:37:28 -0500 | [diff] [blame^] | 74 | static int get_protocol_version(const substring_t *name) |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 75 | { |
Dan Carpenter | 3dc9fef | 2010-04-05 14:37:28 -0500 | [diff] [blame^] | 76 | int version = -EINVAL; |
| 77 | |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 78 | if (!strncmp("9p2000", name->from, name->to-name->from)) { |
| 79 | version = p9_proto_legacy; |
| 80 | P9_DPRINTK(P9_DEBUG_9P, "Protocol version: Legacy\n"); |
| 81 | } else if (!strncmp("9p2000.u", name->from, name->to-name->from)) { |
| 82 | version = p9_proto_2000u; |
| 83 | P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.u\n"); |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 84 | } else if (!strncmp("9p2000.L", name->from, name->to-name->from)) { |
| 85 | version = p9_proto_2000L; |
| 86 | P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.L\n"); |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 87 | } else { |
| 88 | P9_DPRINTK(P9_DEBUG_ERROR, "Unknown protocol version %s. ", |
| 89 | name->from); |
| 90 | } |
| 91 | return version; |
| 92 | } |
| 93 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 94 | static struct p9_req_t * |
| 95 | p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 96 | |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 97 | /** |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 98 | * parse_options - parse mount options into client structure |
| 99 | * @opts: options string passed from mount |
| 100 | * @clnt: existing v9fs client information |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 101 | * |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 102 | * Return 0 upon success, -ERRNO upon failure |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 103 | */ |
| 104 | |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 105 | static int parse_opts(char *opts, struct p9_client *clnt) |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 106 | { |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 107 | char *options, *tmp_options; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 108 | char *p; |
| 109 | substring_t args[MAX_OPT_ARGS]; |
| 110 | int option; |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 111 | int ret = 0; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 112 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 113 | clnt->proto_version = p9_proto_2000u; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 114 | clnt->msize = 8192; |
| 115 | |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 116 | if (!opts) |
| 117 | return 0; |
| 118 | |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 119 | tmp_options = kstrdup(opts, GFP_KERNEL); |
| 120 | if (!tmp_options) { |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 121 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 122 | "failed to allocate copy of option string\n"); |
| 123 | return -ENOMEM; |
| 124 | } |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 125 | options = tmp_options; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 126 | |
| 127 | while ((p = strsep(&options, ",")) != NULL) { |
| 128 | int token; |
| 129 | if (!*p) |
| 130 | continue; |
| 131 | token = match_token(p, tokens, args); |
| 132 | if (token < Opt_trans) { |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 133 | int r = match_int(&args[0], &option); |
| 134 | if (r < 0) { |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 135 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 136 | "integer field, but no integer?\n"); |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 137 | ret = r; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 138 | continue; |
| 139 | } |
| 140 | } |
| 141 | switch (token) { |
| 142 | case Opt_msize: |
| 143 | clnt->msize = option; |
| 144 | break; |
| 145 | case Opt_trans: |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 146 | clnt->trans_mod = v9fs_get_trans_by_name(&args[0]); |
Eric Van Hensbergen | 349d3bb | 2010-01-15 19:01:10 -0600 | [diff] [blame] | 147 | if(clnt->trans_mod == NULL) { |
| 148 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 149 | "Could not find request transport: %s\n", |
| 150 | (char *) &args[0]); |
| 151 | ret = -EINVAL; |
| 152 | goto free_and_return; |
| 153 | } |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 154 | break; |
| 155 | case Opt_legacy: |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 156 | clnt->proto_version = p9_proto_legacy; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 157 | break; |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 158 | case Opt_version: |
| 159 | ret = get_protocol_version(&args[0]); |
| 160 | if (ret == -EINVAL) |
| 161 | goto free_and_return; |
| 162 | clnt->proto_version = ret; |
| 163 | break; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 164 | default: |
| 165 | continue; |
| 166 | } |
| 167 | } |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 168 | |
Eric Van Hensbergen | 349d3bb | 2010-01-15 19:01:10 -0600 | [diff] [blame] | 169 | free_and_return: |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 170 | kfree(tmp_options); |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 171 | return ret; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 172 | } |
| 173 | |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 174 | /** |
| 175 | * p9_tag_alloc - lookup/allocate a request by tag |
| 176 | * @c: client session to lookup tag within |
| 177 | * @tag: numeric id for transaction |
| 178 | * |
| 179 | * this is a simple array lookup, but will grow the |
| 180 | * request_slots as necessary to accomodate transaction |
| 181 | * ids which did not previously have a slot. |
| 182 | * |
| 183 | * this code relies on the client spinlock to manage locks, its |
| 184 | * possible we should switch to something else, but I'd rather |
| 185 | * stick with something low-overhead for the common case. |
| 186 | * |
| 187 | */ |
| 188 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 189 | static struct p9_req_t *p9_tag_alloc(struct p9_client *c, u16 tag) |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 190 | { |
| 191 | unsigned long flags; |
| 192 | int row, col; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 193 | struct p9_req_t *req; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 194 | |
| 195 | /* This looks up the original request by tag so we know which |
| 196 | * buffer to read the data into */ |
| 197 | tag++; |
| 198 | |
| 199 | if (tag >= c->max_tag) { |
| 200 | spin_lock_irqsave(&c->lock, flags); |
| 201 | /* check again since original check was outside of lock */ |
| 202 | while (tag >= c->max_tag) { |
| 203 | row = (tag / P9_ROW_MAXTAG); |
| 204 | c->reqs[row] = kcalloc(P9_ROW_MAXTAG, |
| 205 | sizeof(struct p9_req_t), GFP_ATOMIC); |
| 206 | |
| 207 | if (!c->reqs[row]) { |
| 208 | printk(KERN_ERR "Couldn't grow tag array\n"); |
Eric Van Hensbergen | e45c540 | 2008-10-22 18:54:47 -0500 | [diff] [blame] | 209 | spin_unlock_irqrestore(&c->lock, flags); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 210 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 211 | } |
| 212 | for (col = 0; col < P9_ROW_MAXTAG; col++) { |
| 213 | c->reqs[row][col].status = REQ_STATUS_IDLE; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 214 | c->reqs[row][col].tc = NULL; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 215 | } |
| 216 | c->max_tag += P9_ROW_MAXTAG; |
| 217 | } |
| 218 | spin_unlock_irqrestore(&c->lock, flags); |
| 219 | } |
| 220 | row = tag / P9_ROW_MAXTAG; |
| 221 | col = tag % P9_ROW_MAXTAG; |
| 222 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 223 | req = &c->reqs[row][col]; |
| 224 | if (!req->tc) { |
| 225 | req->wq = kmalloc(sizeof(wait_queue_head_t), GFP_KERNEL); |
| 226 | if (!req->wq) { |
| 227 | printk(KERN_ERR "Couldn't grow tag array\n"); |
| 228 | return ERR_PTR(-ENOMEM); |
| 229 | } |
| 230 | init_waitqueue_head(req->wq); |
| 231 | req->tc = kmalloc(sizeof(struct p9_fcall)+c->msize, |
| 232 | GFP_KERNEL); |
| 233 | req->rc = kmalloc(sizeof(struct p9_fcall)+c->msize, |
| 234 | GFP_KERNEL); |
| 235 | if ((!req->tc) || (!req->rc)) { |
| 236 | printk(KERN_ERR "Couldn't grow tag array\n"); |
| 237 | kfree(req->tc); |
| 238 | kfree(req->rc); |
Tom Tucker | 45abdf1 | 2008-10-23 16:33:25 -0500 | [diff] [blame] | 239 | kfree(req->wq); |
| 240 | req->tc = req->rc = NULL; |
| 241 | req->wq = NULL; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 242 | return ERR_PTR(-ENOMEM); |
| 243 | } |
| 244 | req->tc->sdata = (char *) req->tc + sizeof(struct p9_fcall); |
| 245 | req->tc->capacity = c->msize; |
| 246 | req->rc->sdata = (char *) req->rc + sizeof(struct p9_fcall); |
| 247 | req->rc->capacity = c->msize; |
| 248 | } |
| 249 | |
| 250 | p9pdu_reset(req->tc); |
| 251 | p9pdu_reset(req->rc); |
| 252 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 253 | req->tc->tag = tag-1; |
| 254 | req->status = REQ_STATUS_ALLOC; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 255 | |
| 256 | return &c->reqs[row][col]; |
| 257 | } |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 258 | |
| 259 | /** |
| 260 | * p9_tag_lookup - lookup a request by tag |
| 261 | * @c: client session to lookup tag within |
| 262 | * @tag: numeric id for transaction |
| 263 | * |
| 264 | */ |
| 265 | |
| 266 | struct p9_req_t *p9_tag_lookup(struct p9_client *c, u16 tag) |
| 267 | { |
| 268 | int row, col; |
| 269 | |
| 270 | /* This looks up the original request by tag so we know which |
| 271 | * buffer to read the data into */ |
| 272 | tag++; |
| 273 | |
| 274 | BUG_ON(tag >= c->max_tag); |
| 275 | |
| 276 | row = tag / P9_ROW_MAXTAG; |
| 277 | col = tag % P9_ROW_MAXTAG; |
| 278 | |
| 279 | return &c->reqs[row][col]; |
| 280 | } |
| 281 | EXPORT_SYMBOL(p9_tag_lookup); |
| 282 | |
| 283 | /** |
| 284 | * p9_tag_init - setup tags structure and contents |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 285 | * @c: v9fs client struct |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 286 | * |
| 287 | * This initializes the tags structure for each client instance. |
| 288 | * |
| 289 | */ |
| 290 | |
| 291 | static int p9_tag_init(struct p9_client *c) |
| 292 | { |
| 293 | int err = 0; |
| 294 | |
| 295 | c->tagpool = p9_idpool_create(); |
| 296 | if (IS_ERR(c->tagpool)) { |
| 297 | err = PTR_ERR(c->tagpool); |
| 298 | c->tagpool = NULL; |
| 299 | goto error; |
| 300 | } |
| 301 | |
| 302 | p9_idpool_get(c->tagpool); /* reserve tag 0 */ |
| 303 | |
| 304 | c->max_tag = 0; |
| 305 | error: |
| 306 | return err; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * p9_tag_cleanup - cleans up tags structure and reclaims resources |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 311 | * @c: v9fs client struct |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 312 | * |
| 313 | * This frees resources associated with the tags structure |
| 314 | * |
| 315 | */ |
| 316 | static void p9_tag_cleanup(struct p9_client *c) |
| 317 | { |
| 318 | int row, col; |
| 319 | |
| 320 | /* check to insure all requests are idle */ |
| 321 | for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) { |
| 322 | for (col = 0; col < P9_ROW_MAXTAG; col++) { |
| 323 | if (c->reqs[row][col].status != REQ_STATUS_IDLE) { |
| 324 | P9_DPRINTK(P9_DEBUG_MUX, |
| 325 | "Attempting to cleanup non-free tag %d,%d\n", |
| 326 | row, col); |
| 327 | /* TODO: delay execution of cleanup */ |
| 328 | return; |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | if (c->tagpool) |
| 334 | p9_idpool_destroy(c->tagpool); |
| 335 | |
| 336 | /* free requests associated with tags */ |
| 337 | for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 338 | for (col = 0; col < P9_ROW_MAXTAG; col++) { |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 339 | kfree(c->reqs[row][col].wq); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 340 | kfree(c->reqs[row][col].tc); |
| 341 | kfree(c->reqs[row][col].rc); |
| 342 | } |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 343 | kfree(c->reqs[row]); |
| 344 | } |
| 345 | c->max_tag = 0; |
| 346 | } |
| 347 | |
Eric Van Hensbergen | 673d62cd | 2008-10-13 18:45:22 -0500 | [diff] [blame] | 348 | /** |
| 349 | * p9_free_req - free a request and clean-up as necessary |
| 350 | * c: client state |
| 351 | * r: request to release |
| 352 | * |
| 353 | */ |
| 354 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 355 | static void p9_free_req(struct p9_client *c, struct p9_req_t *r) |
Eric Van Hensbergen | 673d62cd | 2008-10-13 18:45:22 -0500 | [diff] [blame] | 356 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 357 | int tag = r->tc->tag; |
| 358 | P9_DPRINTK(P9_DEBUG_MUX, "clnt %p req %p tag: %d\n", c, r, tag); |
| 359 | |
Eric Van Hensbergen | 673d62cd | 2008-10-13 18:45:22 -0500 | [diff] [blame] | 360 | r->status = REQ_STATUS_IDLE; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 361 | if (tag != P9_NOTAG && p9_idpool_check(tag, c->tagpool)) |
| 362 | p9_idpool_put(tag, c->tagpool); |
Eric Van Hensbergen | 673d62cd | 2008-10-13 18:45:22 -0500 | [diff] [blame] | 363 | } |
| 364 | |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 365 | /** |
| 366 | * p9_client_cb - call back from transport to client |
| 367 | * c: client state |
| 368 | * req: request received |
| 369 | * |
| 370 | */ |
| 371 | void p9_client_cb(struct p9_client *c, struct p9_req_t *req) |
| 372 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 373 | P9_DPRINTK(P9_DEBUG_MUX, " tag %d\n", req->tc->tag); |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 374 | wake_up(req->wq); |
| 375 | P9_DPRINTK(P9_DEBUG_MUX, "wakeup: %d\n", req->tc->tag); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 376 | } |
| 377 | EXPORT_SYMBOL(p9_client_cb); |
| 378 | |
| 379 | /** |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 380 | * p9_parse_header - parse header arguments out of a packet |
| 381 | * @pdu: packet to parse |
| 382 | * @size: size of packet |
| 383 | * @type: type of request |
| 384 | * @tag: tag of packet |
| 385 | * @rewind: set if we need to rewind offset afterwards |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 386 | */ |
| 387 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 388 | int |
| 389 | p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, int16_t *tag, |
| 390 | int rewind) |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 391 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 392 | int8_t r_type; |
| 393 | int16_t r_tag; |
| 394 | int32_t r_size; |
| 395 | int offset = pdu->offset; |
| 396 | int err; |
| 397 | |
| 398 | pdu->offset = 0; |
| 399 | if (pdu->size == 0) |
| 400 | pdu->size = 7; |
| 401 | |
| 402 | err = p9pdu_readf(pdu, 0, "dbw", &r_size, &r_type, &r_tag); |
| 403 | if (err) |
| 404 | goto rewind_and_exit; |
| 405 | |
| 406 | pdu->size = r_size; |
| 407 | pdu->id = r_type; |
| 408 | pdu->tag = r_tag; |
| 409 | |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 410 | P9_DPRINTK(P9_DEBUG_9P, "<<< size=%d type: %d tag: %d\n", pdu->size, |
| 411 | pdu->id, pdu->tag); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 412 | |
| 413 | if (type) |
| 414 | *type = r_type; |
| 415 | if (tag) |
| 416 | *tag = r_tag; |
| 417 | if (size) |
| 418 | *size = r_size; |
| 419 | |
| 420 | |
| 421 | rewind_and_exit: |
| 422 | if (rewind) |
| 423 | pdu->offset = offset; |
| 424 | return err; |
| 425 | } |
| 426 | EXPORT_SYMBOL(p9_parse_header); |
| 427 | |
| 428 | /** |
| 429 | * p9_check_errors - check 9p packet for error return and process it |
| 430 | * @c: current client instance |
| 431 | * @req: request to parse and check for error conditions |
| 432 | * |
| 433 | * returns error code if one is discovered, otherwise returns 0 |
| 434 | * |
| 435 | * this will have to be more complicated if we have multiple |
| 436 | * error packet types |
| 437 | */ |
| 438 | |
| 439 | static int p9_check_errors(struct p9_client *c, struct p9_req_t *req) |
| 440 | { |
| 441 | int8_t type; |
| 442 | int err; |
| 443 | |
| 444 | err = p9_parse_header(req->rc, NULL, &type, NULL, 0); |
| 445 | if (err) { |
| 446 | P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse header %d\n", err); |
| 447 | return err; |
| 448 | } |
| 449 | |
| 450 | if (type == P9_RERROR) { |
| 451 | int ecode; |
| 452 | char *ename; |
| 453 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 454 | err = p9pdu_readf(req->rc, c->proto_version, "s?d", |
| 455 | &ename, &ecode); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 456 | if (err) { |
| 457 | P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n", |
| 458 | err); |
| 459 | return err; |
| 460 | } |
| 461 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 462 | if (p9_is_proto_dotu(c)) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 463 | err = -ecode; |
| 464 | |
Abhishek Kulkarni | 0aad37e | 2009-08-17 16:38:45 -0500 | [diff] [blame] | 465 | if (!err || !IS_ERR_VALUE(err)) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 466 | err = p9_errstr2errno(ename, strlen(ename)); |
| 467 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 468 | P9_DPRINTK(P9_DEBUG_9P, "<<< RERROR (%d) %s\n", -ecode, ename); |
| 469 | |
| 470 | kfree(ename); |
| 471 | } else |
| 472 | err = 0; |
| 473 | |
| 474 | return err; |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * p9_client_flush - flush (cancel) a request |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 479 | * @c: client state |
| 480 | * @oldreq: request to cancel |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 481 | * |
| 482 | * This sents a flush for a particular requests and links |
| 483 | * the flush request to the original request. The current |
| 484 | * code only supports a single flush request although the protocol |
| 485 | * allows for multiple flush requests to be sent for a single request. |
| 486 | * |
| 487 | */ |
| 488 | |
| 489 | static int p9_client_flush(struct p9_client *c, struct p9_req_t *oldreq) |
| 490 | { |
| 491 | struct p9_req_t *req; |
| 492 | int16_t oldtag; |
| 493 | int err; |
| 494 | |
| 495 | err = p9_parse_header(oldreq->tc, NULL, NULL, &oldtag, 1); |
| 496 | if (err) |
| 497 | return err; |
| 498 | |
| 499 | P9_DPRINTK(P9_DEBUG_9P, ">>> TFLUSH tag %d\n", oldtag); |
| 500 | |
| 501 | req = p9_client_rpc(c, P9_TFLUSH, "w", oldtag); |
| 502 | if (IS_ERR(req)) |
| 503 | return PTR_ERR(req); |
| 504 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 505 | |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 506 | /* if we haven't received a response for oldreq, |
| 507 | remove it from the list. */ |
| 508 | spin_lock(&c->lock); |
| 509 | if (oldreq->status == REQ_STATUS_FLSH) |
| 510 | list_del(&oldreq->req_list); |
| 511 | spin_unlock(&c->lock); |
| 512 | |
| 513 | p9_free_req(c, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * p9_client_rpc - issue a request and wait for a response |
| 519 | * @c: client session |
| 520 | * @type: type of request |
| 521 | * @fmt: protocol format string (see protocol.c) |
| 522 | * |
| 523 | * Returns request structure (which client must free using p9_free_req) |
| 524 | */ |
| 525 | |
| 526 | static struct p9_req_t * |
| 527 | p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...) |
| 528 | { |
| 529 | va_list ap; |
| 530 | int tag, err; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 531 | struct p9_req_t *req; |
| 532 | unsigned long flags; |
| 533 | int sigpending; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 534 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 535 | P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 536 | |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 537 | /* we allow for any status other than disconnected */ |
| 538 | if (c->status == Disconnected) |
| 539 | return ERR_PTR(-EIO); |
| 540 | |
| 541 | /* if status is begin_disconnected we allow only clunk request */ |
| 542 | if ((c->status == BeginDisconnect) && (type != P9_TCLUNK)) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 543 | return ERR_PTR(-EIO); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 544 | |
| 545 | if (signal_pending(current)) { |
| 546 | sigpending = 1; |
| 547 | clear_thread_flag(TIF_SIGPENDING); |
| 548 | } else |
| 549 | sigpending = 0; |
| 550 | |
| 551 | tag = P9_NOTAG; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 552 | if (type != P9_TVERSION) { |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 553 | tag = p9_idpool_get(c->tagpool); |
| 554 | if (tag < 0) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 555 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | req = p9_tag_alloc(c, tag); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 559 | if (IS_ERR(req)) |
| 560 | return req; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 561 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 562 | /* marshall the data */ |
| 563 | p9pdu_prepare(req->tc, tag, type); |
| 564 | va_start(ap, fmt); |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 565 | err = p9pdu_vwritef(req->tc, c->proto_version, fmt, ap); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 566 | va_end(ap); |
| 567 | p9pdu_finalize(req->tc); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 568 | |
| 569 | err = c->trans_mod->request(c, req); |
| 570 | if (err < 0) { |
| 571 | c->status = Disconnected; |
| 572 | goto reterr; |
| 573 | } |
| 574 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 575 | P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d\n", req->wq, tag); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 576 | err = wait_event_interruptible(*req->wq, |
| 577 | req->status >= REQ_STATUS_RCVD); |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 578 | P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d returned %d\n", |
| 579 | req->wq, tag, err); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 580 | |
| 581 | if (req->status == REQ_STATUS_ERROR) { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 582 | P9_DPRINTK(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 583 | err = req->t_err; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 584 | } |
| 585 | |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 586 | if ((err == -ERESTARTSYS) && (c->status == Connected)) { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 587 | P9_DPRINTK(P9_DEBUG_MUX, "flushing\n"); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 588 | sigpending = 1; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 589 | clear_thread_flag(TIF_SIGPENDING); |
| 590 | |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 591 | if (c->trans_mod->cancel(c, req)) |
| 592 | p9_client_flush(c, req); |
| 593 | |
| 594 | /* if we received the response anyway, don't signal error */ |
| 595 | if (req->status == REQ_STATUS_RCVD) |
| 596 | err = 0; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | if (sigpending) { |
| 600 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
| 601 | recalc_sigpending(); |
| 602 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
| 603 | } |
| 604 | |
| 605 | if (err < 0) |
| 606 | goto reterr; |
| 607 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 608 | err = p9_check_errors(c, req); |
| 609 | if (!err) { |
| 610 | P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d\n", c, type); |
| 611 | return req; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 612 | } |
| 613 | |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 614 | reterr: |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 615 | P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d error: %d\n", c, type, |
| 616 | err); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 617 | p9_free_req(c, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 618 | return ERR_PTR(err); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 619 | } |
| 620 | |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 621 | static struct p9_fid *p9_fid_create(struct p9_client *clnt) |
| 622 | { |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 623 | int ret; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 624 | struct p9_fid *fid; |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 625 | unsigned long flags; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 626 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 627 | P9_DPRINTK(P9_DEBUG_FID, "clnt %p\n", clnt); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 628 | fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL); |
| 629 | if (!fid) |
| 630 | return ERR_PTR(-ENOMEM); |
| 631 | |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 632 | ret = p9_idpool_get(clnt->fidpool); |
Roel Kluin | 24e94de | 2009-01-18 21:32:11 -0800 | [diff] [blame] | 633 | if (ret < 0) { |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 634 | ret = -ENOSPC; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 635 | goto error; |
| 636 | } |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 637 | fid->fid = ret; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 638 | |
| 639 | memset(&fid->qid, 0, sizeof(struct p9_qid)); |
| 640 | fid->mode = -1; |
David Howells | f8b9d53 | 2008-11-14 10:38:44 +1100 | [diff] [blame] | 641 | fid->uid = current_fsuid(); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 642 | fid->clnt = clnt; |
Eric Van Hensbergen | 3e2796a | 2009-11-02 08:39:28 -0600 | [diff] [blame] | 643 | fid->rdir = NULL; |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 644 | spin_lock_irqsave(&clnt->lock, flags); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 645 | list_add(&fid->flist, &clnt->fidlist); |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 646 | spin_unlock_irqrestore(&clnt->lock, flags); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 647 | |
| 648 | return fid; |
| 649 | |
| 650 | error: |
| 651 | kfree(fid); |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 652 | return ERR_PTR(ret); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | static void p9_fid_destroy(struct p9_fid *fid) |
| 656 | { |
| 657 | struct p9_client *clnt; |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 658 | unsigned long flags; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 659 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 660 | P9_DPRINTK(P9_DEBUG_FID, "fid %d\n", fid->fid); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 661 | clnt = fid->clnt; |
| 662 | p9_idpool_put(fid->fid, clnt->fidpool); |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 663 | spin_lock_irqsave(&clnt->lock, flags); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 664 | list_del(&fid->flist); |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 665 | spin_unlock_irqrestore(&clnt->lock, flags); |
Eric Van Hensbergen | 3e2796a | 2009-11-02 08:39:28 -0600 | [diff] [blame] | 666 | kfree(fid->rdir); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 667 | kfree(fid); |
| 668 | } |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 669 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 670 | int p9_client_version(struct p9_client *c) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 671 | { |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 672 | int err = 0; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 673 | struct p9_req_t *req; |
| 674 | char *version; |
| 675 | int msize; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 676 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 677 | P9_DPRINTK(P9_DEBUG_9P, ">>> TVERSION msize %d protocol %d\n", |
| 678 | c->msize, c->proto_version); |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 679 | |
| 680 | switch (c->proto_version) { |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 681 | case p9_proto_2000L: |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 682 | req = p9_client_rpc(c, P9_TVERSION, "ds", |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 683 | c->msize, "9P2000.L"); |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 684 | break; |
| 685 | case p9_proto_2000u: |
| 686 | req = p9_client_rpc(c, P9_TVERSION, "ds", |
| 687 | c->msize, "9P2000.u"); |
| 688 | break; |
| 689 | case p9_proto_legacy: |
| 690 | req = p9_client_rpc(c, P9_TVERSION, "ds", |
| 691 | c->msize, "9P2000"); |
| 692 | break; |
| 693 | default: |
| 694 | return -EINVAL; |
| 695 | break; |
| 696 | } |
| 697 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 698 | if (IS_ERR(req)) |
| 699 | return PTR_ERR(req); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 700 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 701 | err = p9pdu_readf(req->rc, c->proto_version, "ds", &msize, &version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 702 | if (err) { |
| 703 | P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 704 | p9pdu_dump(1, req->rc); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 705 | goto error; |
| 706 | } |
| 707 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 708 | P9_DPRINTK(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version); |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 709 | if (!strncmp(version, "9P2000.L", 8)) |
| 710 | c->proto_version = p9_proto_2000L; |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 711 | else if (!strncmp(version, "9P2000.u", 8)) |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 712 | c->proto_version = p9_proto_2000u; |
| 713 | else if (!strncmp(version, "9P2000", 6)) |
| 714 | c->proto_version = p9_proto_legacy; |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 715 | else { |
| 716 | err = -EREMOTEIO; |
| 717 | goto error; |
| 718 | } |
| 719 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 720 | if (msize < c->msize) |
| 721 | c->msize = msize; |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 722 | |
| 723 | error: |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 724 | kfree(version); |
| 725 | p9_free_req(c, req); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 726 | |
| 727 | return err; |
| 728 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 729 | EXPORT_SYMBOL(p9_client_version); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 730 | |
| 731 | struct p9_client *p9_client_create(const char *dev_name, char *options) |
| 732 | { |
| 733 | int err; |
| 734 | struct p9_client *clnt; |
| 735 | |
| 736 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 737 | clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL); |
| 738 | if (!clnt) |
| 739 | return ERR_PTR(-ENOMEM); |
| 740 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 741 | clnt->trans_mod = NULL; |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 742 | clnt->trans = NULL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 743 | spin_lock_init(&clnt->lock); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 744 | INIT_LIST_HEAD(&clnt->fidlist); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 745 | |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 746 | p9_tag_init(clnt); |
| 747 | |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 748 | err = parse_opts(options, clnt); |
| 749 | if (err < 0) |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 750 | goto free_client; |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 751 | |
Abhishek Kulkarni | a17d172 | 2009-07-14 13:24:10 -0500 | [diff] [blame] | 752 | if (!clnt->trans_mod) |
| 753 | clnt->trans_mod = v9fs_get_default_trans(); |
| 754 | |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 755 | if (clnt->trans_mod == NULL) { |
| 756 | err = -EPROTONOSUPPORT; |
| 757 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 758 | "No transport defined or default transport\n"); |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 759 | goto free_client; |
| 760 | } |
| 761 | |
| 762 | clnt->fidpool = p9_idpool_create(); |
| 763 | if (IS_ERR(clnt->fidpool)) { |
| 764 | err = PTR_ERR(clnt->fidpool); |
| 765 | clnt->fidpool = NULL; |
| 766 | goto put_trans; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 767 | } |
| 768 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 769 | P9_DPRINTK(P9_DEBUG_MUX, "clnt %p trans %p msize %d protocol %d\n", |
| 770 | clnt, clnt->trans_mod, clnt->msize, clnt->proto_version); |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 771 | |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 772 | err = clnt->trans_mod->create(clnt, dev_name, options); |
| 773 | if (err) |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 774 | goto destroy_fidpool; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 775 | |
| 776 | if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize) |
| 777 | clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ; |
| 778 | |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 779 | err = p9_client_version(clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 780 | if (err) |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 781 | goto close_trans; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 782 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 783 | return clnt; |
| 784 | |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 785 | close_trans: |
| 786 | clnt->trans_mod->close(clnt); |
| 787 | destroy_fidpool: |
| 788 | p9_idpool_destroy(clnt->fidpool); |
| 789 | put_trans: |
| 790 | v9fs_put_trans(clnt->trans_mod); |
| 791 | free_client: |
| 792 | kfree(clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 793 | return ERR_PTR(err); |
| 794 | } |
| 795 | EXPORT_SYMBOL(p9_client_create); |
| 796 | |
| 797 | void p9_client_destroy(struct p9_client *clnt) |
| 798 | { |
| 799 | struct p9_fid *fid, *fidptr; |
| 800 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 801 | P9_DPRINTK(P9_DEBUG_MUX, "clnt %p\n", clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 802 | |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 803 | if (clnt->trans_mod) |
| 804 | clnt->trans_mod->close(clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 805 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 806 | v9fs_put_trans(clnt->trans_mod); |
| 807 | |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 808 | list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist) { |
| 809 | printk(KERN_INFO "Found fid %d not clunked\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 810 | p9_fid_destroy(fid); |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 811 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 812 | |
Eric Van Hensbergen | 0af8887 | 2007-07-13 16:47:58 -0500 | [diff] [blame] | 813 | if (clnt->fidpool) |
| 814 | p9_idpool_destroy(clnt->fidpool); |
| 815 | |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 816 | p9_tag_cleanup(clnt); |
| 817 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 818 | kfree(clnt); |
| 819 | } |
| 820 | EXPORT_SYMBOL(p9_client_destroy); |
| 821 | |
| 822 | void p9_client_disconnect(struct p9_client *clnt) |
| 823 | { |
| 824 | P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt); |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 825 | clnt->status = Disconnected; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 826 | } |
| 827 | EXPORT_SYMBOL(p9_client_disconnect); |
| 828 | |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 829 | void p9_client_begin_disconnect(struct p9_client *clnt) |
| 830 | { |
| 831 | P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt); |
| 832 | clnt->status = BeginDisconnect; |
| 833 | } |
| 834 | EXPORT_SYMBOL(p9_client_begin_disconnect); |
| 835 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 836 | struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 837 | char *uname, u32 n_uname, char *aname) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 838 | { |
| 839 | int err; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 840 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 841 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 842 | struct p9_qid qid; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 843 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 844 | P9_DPRINTK(P9_DEBUG_9P, ">>> TATTACH afid %d uname %s aname %s\n", |
| 845 | afid ? afid->fid : -1, uname, aname); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 846 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 847 | |
| 848 | fid = p9_fid_create(clnt); |
| 849 | if (IS_ERR(fid)) { |
| 850 | err = PTR_ERR(fid); |
| 851 | fid = NULL; |
| 852 | goto error; |
| 853 | } |
| 854 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 855 | req = p9_client_rpc(clnt, P9_TATTACH, "ddss?d", fid->fid, |
| 856 | afid ? afid->fid : P9_NOFID, uname, aname, n_uname); |
| 857 | if (IS_ERR(req)) { |
| 858 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 859 | goto error; |
| 860 | } |
| 861 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 862 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 863 | if (err) { |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 864 | p9pdu_dump(1, req->rc); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 865 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 866 | goto error; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 867 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 868 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 869 | P9_DPRINTK(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n", |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 870 | qid.type, |
| 871 | (unsigned long long)qid.path, |
| 872 | qid.version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 873 | |
| 874 | memmove(&fid->qid, &qid, sizeof(struct p9_qid)); |
| 875 | |
| 876 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 877 | return fid; |
| 878 | |
| 879 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 880 | if (fid) |
| 881 | p9_fid_destroy(fid); |
| 882 | return ERR_PTR(err); |
| 883 | } |
| 884 | EXPORT_SYMBOL(p9_client_attach); |
| 885 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 886 | struct p9_fid * |
| 887 | p9_client_auth(struct p9_client *clnt, char *uname, u32 n_uname, char *aname) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 888 | { |
| 889 | int err; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 890 | struct p9_req_t *req; |
| 891 | struct p9_qid qid; |
| 892 | struct p9_fid *afid; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 893 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 894 | P9_DPRINTK(P9_DEBUG_9P, ">>> TAUTH uname %s aname %s\n", uname, aname); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 895 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 896 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 897 | afid = p9_fid_create(clnt); |
| 898 | if (IS_ERR(afid)) { |
| 899 | err = PTR_ERR(afid); |
| 900 | afid = NULL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 901 | goto error; |
| 902 | } |
| 903 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 904 | req = p9_client_rpc(clnt, P9_TAUTH, "dss?d", |
| 905 | afid ? afid->fid : P9_NOFID, uname, aname, n_uname); |
| 906 | if (IS_ERR(req)) { |
| 907 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 908 | goto error; |
| 909 | } |
| 910 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 911 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 912 | if (err) { |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 913 | p9pdu_dump(1, req->rc); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 914 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 915 | goto error; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 916 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 917 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 918 | P9_DPRINTK(P9_DEBUG_9P, "<<< RAUTH qid %x.%llx.%x\n", |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 919 | qid.type, |
| 920 | (unsigned long long)qid.path, |
| 921 | qid.version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 922 | |
| 923 | memmove(&afid->qid, &qid, sizeof(struct p9_qid)); |
| 924 | p9_free_req(clnt, req); |
| 925 | return afid; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 926 | |
| 927 | error: |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 928 | if (afid) |
| 929 | p9_fid_destroy(afid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 930 | return ERR_PTR(err); |
| 931 | } |
| 932 | EXPORT_SYMBOL(p9_client_auth); |
| 933 | |
| 934 | struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames, |
| 935 | int clone) |
| 936 | { |
| 937 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 938 | struct p9_client *clnt; |
| 939 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 940 | struct p9_qid *wqids; |
| 941 | struct p9_req_t *req; |
| 942 | int16_t nwqids, count; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 943 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 944 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 945 | clnt = oldfid->clnt; |
| 946 | if (clone) { |
| 947 | fid = p9_fid_create(clnt); |
| 948 | if (IS_ERR(fid)) { |
| 949 | err = PTR_ERR(fid); |
| 950 | fid = NULL; |
| 951 | goto error; |
| 952 | } |
| 953 | |
| 954 | fid->uid = oldfid->uid; |
| 955 | } else |
| 956 | fid = oldfid; |
| 957 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 958 | |
| 959 | P9_DPRINTK(P9_DEBUG_9P, ">>> TWALK fids %d,%d nwname %d wname[0] %s\n", |
| 960 | oldfid->fid, fid->fid, nwname, wnames ? wnames[0] : NULL); |
| 961 | |
| 962 | req = p9_client_rpc(clnt, P9_TWALK, "ddT", oldfid->fid, fid->fid, |
| 963 | nwname, wnames); |
| 964 | if (IS_ERR(req)) { |
| 965 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 966 | goto error; |
| 967 | } |
| 968 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 969 | err = p9pdu_readf(req->rc, clnt->proto_version, "R", &nwqids, &wqids); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 970 | if (err) { |
| 971 | p9pdu_dump(1, req->rc); |
| 972 | p9_free_req(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 973 | goto clunk_fid; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 974 | } |
| 975 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 976 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 977 | P9_DPRINTK(P9_DEBUG_9P, "<<< RWALK nwqid %d:\n", nwqids); |
| 978 | |
| 979 | if (nwqids != nwname) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 980 | err = -ENOENT; |
| 981 | goto clunk_fid; |
| 982 | } |
| 983 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 984 | for (count = 0; count < nwqids; count++) |
| 985 | P9_DPRINTK(P9_DEBUG_9P, "<<< [%d] %x.%llx.%x\n", |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 986 | count, wqids[count].type, |
| 987 | (unsigned long long)wqids[count].path, |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 988 | wqids[count].version); |
| 989 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 990 | if (nwname) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 991 | memmove(&fid->qid, &wqids[nwqids - 1], sizeof(struct p9_qid)); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 992 | else |
| 993 | fid->qid = oldfid->qid; |
| 994 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 995 | return fid; |
| 996 | |
| 997 | clunk_fid: |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 998 | p9_client_clunk(fid); |
| 999 | fid = NULL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1000 | |
| 1001 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1002 | if (fid && (fid != oldfid)) |
| 1003 | p9_fid_destroy(fid); |
| 1004 | |
| 1005 | return ERR_PTR(err); |
| 1006 | } |
| 1007 | EXPORT_SYMBOL(p9_client_walk); |
| 1008 | |
| 1009 | int p9_client_open(struct p9_fid *fid, int mode) |
| 1010 | { |
| 1011 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1012 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1013 | struct p9_req_t *req; |
| 1014 | struct p9_qid qid; |
| 1015 | int iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1016 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1017 | P9_DPRINTK(P9_DEBUG_9P, ">>> TOPEN fid %d mode %d\n", fid->fid, mode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1018 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1019 | clnt = fid->clnt; |
| 1020 | |
| 1021 | if (fid->mode != -1) |
| 1022 | return -EINVAL; |
| 1023 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1024 | req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode); |
| 1025 | if (IS_ERR(req)) { |
| 1026 | err = PTR_ERR(req); |
| 1027 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1028 | } |
| 1029 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1030 | err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1031 | if (err) { |
| 1032 | p9pdu_dump(1, req->rc); |
| 1033 | goto free_and_error; |
| 1034 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1035 | |
| 1036 | P9_DPRINTK(P9_DEBUG_9P, "<<< ROPEN qid %x.%llx.%x iounit %x\n", |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 1037 | qid.type, |
| 1038 | (unsigned long long)qid.path, |
| 1039 | qid.version, iounit); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1040 | |
| 1041 | fid->mode = mode; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1042 | fid->iounit = iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1043 | |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1044 | free_and_error: |
| 1045 | p9_free_req(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1046 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1047 | return err; |
| 1048 | } |
| 1049 | EXPORT_SYMBOL(p9_client_open); |
| 1050 | |
| 1051 | int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode, |
| 1052 | char *extension) |
| 1053 | { |
| 1054 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1055 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1056 | struct p9_req_t *req; |
| 1057 | struct p9_qid qid; |
| 1058 | int iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1059 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1060 | P9_DPRINTK(P9_DEBUG_9P, ">>> TCREATE fid %d name %s perm %d mode %d\n", |
| 1061 | fid->fid, name, perm, mode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1062 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1063 | clnt = fid->clnt; |
| 1064 | |
| 1065 | if (fid->mode != -1) |
| 1066 | return -EINVAL; |
| 1067 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1068 | req = p9_client_rpc(clnt, P9_TCREATE, "dsdb?s", fid->fid, name, perm, |
| 1069 | mode, extension); |
| 1070 | if (IS_ERR(req)) { |
| 1071 | err = PTR_ERR(req); |
| 1072 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1073 | } |
| 1074 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1075 | err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1076 | if (err) { |
| 1077 | p9pdu_dump(1, req->rc); |
| 1078 | goto free_and_error; |
| 1079 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1080 | |
| 1081 | P9_DPRINTK(P9_DEBUG_9P, "<<< RCREATE qid %x.%llx.%x iounit %x\n", |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 1082 | qid.type, |
| 1083 | (unsigned long long)qid.path, |
| 1084 | qid.version, iounit); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1085 | |
| 1086 | fid->mode = mode; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1087 | fid->iounit = iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1088 | |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1089 | free_and_error: |
| 1090 | p9_free_req(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1091 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1092 | return err; |
| 1093 | } |
| 1094 | EXPORT_SYMBOL(p9_client_fcreate); |
| 1095 | |
| 1096 | int p9_client_clunk(struct p9_fid *fid) |
| 1097 | { |
| 1098 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1099 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1100 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1101 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1102 | P9_DPRINTK(P9_DEBUG_9P, ">>> TCLUNK fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1103 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1104 | clnt = fid->clnt; |
| 1105 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1106 | req = p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid); |
| 1107 | if (IS_ERR(req)) { |
| 1108 | err = PTR_ERR(req); |
| 1109 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1110 | } |
| 1111 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1112 | P9_DPRINTK(P9_DEBUG_9P, "<<< RCLUNK fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1113 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1114 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1115 | p9_fid_destroy(fid); |
| 1116 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1117 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1118 | return err; |
| 1119 | } |
| 1120 | EXPORT_SYMBOL(p9_client_clunk); |
| 1121 | |
| 1122 | int p9_client_remove(struct p9_fid *fid) |
| 1123 | { |
| 1124 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1125 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1126 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1127 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1128 | P9_DPRINTK(P9_DEBUG_9P, ">>> TREMOVE fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1129 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1130 | clnt = fid->clnt; |
| 1131 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1132 | req = p9_client_rpc(clnt, P9_TREMOVE, "d", fid->fid); |
| 1133 | if (IS_ERR(req)) { |
| 1134 | err = PTR_ERR(req); |
| 1135 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1136 | } |
| 1137 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1138 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREMOVE fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1139 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1140 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1141 | p9_fid_destroy(fid); |
| 1142 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1143 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1144 | return err; |
| 1145 | } |
| 1146 | EXPORT_SYMBOL(p9_client_remove); |
| 1147 | |
Eric Van Hensbergen | 0fc9655 | 2008-10-13 20:36:17 -0500 | [diff] [blame] | 1148 | int |
| 1149 | p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, |
| 1150 | u32 count) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1151 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1152 | int err, rsize, total; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1153 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1154 | struct p9_req_t *req; |
| 1155 | char *dataptr; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1156 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1157 | P9_DPRINTK(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n", fid->fid, |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1158 | (long long unsigned) offset, count); |
| 1159 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1160 | clnt = fid->clnt; |
| 1161 | total = 0; |
| 1162 | |
| 1163 | rsize = fid->iounit; |
| 1164 | if (!rsize || rsize > clnt->msize-P9_IOHDRSZ) |
| 1165 | rsize = clnt->msize - P9_IOHDRSZ; |
| 1166 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1167 | if (count < rsize) |
| 1168 | rsize = count; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1169 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1170 | req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset, rsize); |
| 1171 | if (IS_ERR(req)) { |
| 1172 | err = PTR_ERR(req); |
| 1173 | goto error; |
| 1174 | } |
| 1175 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1176 | err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1177 | if (err) { |
| 1178 | p9pdu_dump(1, req->rc); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1179 | goto free_and_error; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1180 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1181 | |
| 1182 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREAD count %d\n", count); |
| 1183 | |
| 1184 | if (data) { |
| 1185 | memmove(data, dataptr, count); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | if (udata) { |
| 1189 | err = copy_to_user(udata, dataptr, count); |
| 1190 | if (err) { |
| 1191 | err = -EFAULT; |
| 1192 | goto free_and_error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1193 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1194 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1195 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1196 | p9_free_req(clnt, req); |
| 1197 | return count; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1198 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1199 | free_and_error: |
| 1200 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1201 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1202 | return err; |
| 1203 | } |
| 1204 | EXPORT_SYMBOL(p9_client_read); |
| 1205 | |
Eric Van Hensbergen | 0fc9655 | 2008-10-13 20:36:17 -0500 | [diff] [blame] | 1206 | int |
| 1207 | p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, |
| 1208 | u64 offset, u32 count) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1209 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1210 | int err, rsize, total; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1211 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1212 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1213 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1214 | P9_DPRINTK(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %d\n", |
| 1215 | fid->fid, (long long unsigned) offset, count); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1216 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1217 | clnt = fid->clnt; |
| 1218 | total = 0; |
| 1219 | |
| 1220 | rsize = fid->iounit; |
| 1221 | if (!rsize || rsize > clnt->msize-P9_IOHDRSZ) |
| 1222 | rsize = clnt->msize - P9_IOHDRSZ; |
| 1223 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1224 | if (count < rsize) |
| 1225 | rsize = count; |
| 1226 | if (data) |
| 1227 | req = p9_client_rpc(clnt, P9_TWRITE, "dqD", fid->fid, offset, |
| 1228 | rsize, data); |
| 1229 | else |
| 1230 | req = p9_client_rpc(clnt, P9_TWRITE, "dqU", fid->fid, offset, |
| 1231 | rsize, udata); |
| 1232 | if (IS_ERR(req)) { |
| 1233 | err = PTR_ERR(req); |
| 1234 | goto error; |
| 1235 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1236 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1237 | err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1238 | if (err) { |
| 1239 | p9pdu_dump(1, req->rc); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1240 | goto free_and_error; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1241 | } |
| 1242 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1243 | P9_DPRINTK(P9_DEBUG_9P, "<<< RWRITE count %d\n", count); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1244 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1245 | p9_free_req(clnt, req); |
| 1246 | return count; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1247 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1248 | free_and_error: |
| 1249 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1250 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1251 | return err; |
| 1252 | } |
| 1253 | EXPORT_SYMBOL(p9_client_write); |
| 1254 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1255 | struct p9_wstat *p9_client_stat(struct p9_fid *fid) |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1256 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1257 | int err; |
| 1258 | struct p9_client *clnt; |
| 1259 | struct p9_wstat *ret = kmalloc(sizeof(struct p9_wstat), GFP_KERNEL); |
| 1260 | struct p9_req_t *req; |
| 1261 | u16 ignored; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1262 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1263 | P9_DPRINTK(P9_DEBUG_9P, ">>> TSTAT fid %d\n", fid->fid); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1264 | |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1265 | if (!ret) |
| 1266 | return ERR_PTR(-ENOMEM); |
| 1267 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1268 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1269 | clnt = fid->clnt; |
| 1270 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1271 | req = p9_client_rpc(clnt, P9_TSTAT, "d", fid->fid); |
| 1272 | if (IS_ERR(req)) { |
| 1273 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1274 | goto error; |
| 1275 | } |
| 1276 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1277 | err = p9pdu_readf(req->rc, clnt->proto_version, "wS", &ignored, ret); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1278 | if (err) { |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1279 | p9pdu_dump(1, req->rc); |
Abhishek Kulkarni | eedfe1c | 2009-07-14 13:25:41 -0500 | [diff] [blame] | 1280 | p9_free_req(clnt, req); |
| 1281 | goto error; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1282 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1283 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1284 | P9_DPRINTK(P9_DEBUG_9P, |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1285 | "<<< RSTAT sz=%x type=%x dev=%x qid=%x.%llx.%x\n" |
| 1286 | "<<< mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n" |
| 1287 | "<<< name=%s uid=%s gid=%s muid=%s extension=(%s)\n" |
| 1288 | "<<< uid=%d gid=%d n_muid=%d\n", |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1289 | ret->size, ret->type, ret->dev, ret->qid.type, |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 1290 | (unsigned long long)ret->qid.path, ret->qid.version, ret->mode, |
| 1291 | ret->atime, ret->mtime, (unsigned long long)ret->length, |
| 1292 | ret->name, ret->uid, ret->gid, ret->muid, ret->extension, |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1293 | ret->n_uid, ret->n_gid, ret->n_muid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1294 | |
Latchesar Ionkov | 742b11a | 2009-04-05 16:26:41 -0500 | [diff] [blame] | 1295 | p9_free_req(clnt, req); |
| 1296 | return ret; |
| 1297 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1298 | error: |
Latchesar Ionkov | 742b11a | 2009-04-05 16:26:41 -0500 | [diff] [blame] | 1299 | kfree(ret); |
| 1300 | return ERR_PTR(err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1301 | } |
| 1302 | EXPORT_SYMBOL(p9_client_stat); |
| 1303 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1304 | static int p9_client_statsize(struct p9_wstat *wst, int proto_version) |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1305 | { |
| 1306 | int ret; |
| 1307 | |
Eric Van Hensbergen | 9d6939d | 2010-01-15 19:01:56 -0600 | [diff] [blame] | 1308 | /* NOTE: size shouldn't include its own length */ |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1309 | /* size[2] type[2] dev[4] qid[13] */ |
| 1310 | /* mode[4] atime[4] mtime[4] length[8]*/ |
| 1311 | /* name[s] uid[s] gid[s] muid[s] */ |
Eric Van Hensbergen | 9d6939d | 2010-01-15 19:01:56 -0600 | [diff] [blame] | 1312 | ret = 2+4+13+4+4+4+8+2+2+2+2; |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1313 | |
| 1314 | if (wst->name) |
| 1315 | ret += strlen(wst->name); |
| 1316 | if (wst->uid) |
| 1317 | ret += strlen(wst->uid); |
| 1318 | if (wst->gid) |
| 1319 | ret += strlen(wst->gid); |
| 1320 | if (wst->muid) |
| 1321 | ret += strlen(wst->muid); |
| 1322 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1323 | if (proto_version == p9_proto_2000u) { |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1324 | ret += 2+4+4+4; /* extension[s] n_uid[4] n_gid[4] n_muid[4] */ |
| 1325 | if (wst->extension) |
| 1326 | ret += strlen(wst->extension); |
| 1327 | } |
| 1328 | |
| 1329 | return ret; |
| 1330 | } |
| 1331 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1332 | int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst) |
| 1333 | { |
| 1334 | int err; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1335 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1336 | struct p9_client *clnt; |
| 1337 | |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1338 | err = 0; |
| 1339 | clnt = fid->clnt; |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1340 | wst->size = p9_client_statsize(wst, clnt->proto_version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1341 | P9_DPRINTK(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", fid->fid); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1342 | P9_DPRINTK(P9_DEBUG_9P, |
| 1343 | " sz=%x type=%x dev=%x qid=%x.%llx.%x\n" |
| 1344 | " mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n" |
| 1345 | " name=%s uid=%s gid=%s muid=%s extension=(%s)\n" |
| 1346 | " uid=%d gid=%d n_muid=%d\n", |
| 1347 | wst->size, wst->type, wst->dev, wst->qid.type, |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 1348 | (unsigned long long)wst->qid.path, wst->qid.version, wst->mode, |
| 1349 | wst->atime, wst->mtime, (unsigned long long)wst->length, |
| 1350 | wst->name, wst->uid, wst->gid, wst->muid, wst->extension, |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1351 | wst->n_uid, wst->n_gid, wst->n_muid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1352 | |
Eric Van Hensbergen | 9d6939d | 2010-01-15 19:01:56 -0600 | [diff] [blame] | 1353 | req = p9_client_rpc(clnt, P9_TWSTAT, "dwS", fid->fid, wst->size+2, wst); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1354 | if (IS_ERR(req)) { |
| 1355 | err = PTR_ERR(req); |
| 1356 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1357 | } |
| 1358 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1359 | P9_DPRINTK(P9_DEBUG_9P, "<<< RWSTAT fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1360 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1361 | p9_free_req(clnt, req); |
| 1362 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1363 | return err; |
| 1364 | } |
| 1365 | EXPORT_SYMBOL(p9_client_wstat); |