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