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