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