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