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