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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 33 | #include <linux/sched.h> |
| 34 | #include <linux/uaccess.h> |
| 35 | #include <net/9p/9p.h> |
Eric Van Hensbergen | fb0466c | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 36 | #include <linux/parser.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 37 | #include <net/9p/client.h> |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 38 | #include <net/9p/transport.h> |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 39 | #include "protocol.h" |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 40 | |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 41 | /* |
| 42 | * Client Option Parsing (code inspired by NFS code) |
| 43 | * - a little lazy - parse all client options |
| 44 | */ |
| 45 | |
| 46 | enum { |
| 47 | Opt_msize, |
| 48 | Opt_trans, |
| 49 | Opt_legacy, |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 50 | Opt_version, |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 51 | Opt_err, |
| 52 | }; |
| 53 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 54 | static const match_table_t tokens = { |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 55 | {Opt_msize, "msize=%u"}, |
| 56 | {Opt_legacy, "noextend"}, |
| 57 | {Opt_trans, "trans=%s"}, |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 58 | {Opt_version, "version=%s"}, |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 59 | {Opt_err, NULL}, |
| 60 | }; |
| 61 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 62 | inline int p9_is_proto_dotl(struct p9_client *clnt) |
| 63 | { |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 64 | return clnt->proto_version == p9_proto_2000L; |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 65 | } |
| 66 | EXPORT_SYMBOL(p9_is_proto_dotl); |
| 67 | |
| 68 | inline int p9_is_proto_dotu(struct p9_client *clnt) |
| 69 | { |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 70 | return clnt->proto_version == p9_proto_2000u; |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 71 | } |
| 72 | EXPORT_SYMBOL(p9_is_proto_dotu); |
| 73 | |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 74 | /* Interpret mount option for protocol version */ |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 75 | static int get_protocol_version(char *s) |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 76 | { |
Dan Carpenter | 3dc9fef | 2010-04-05 14:37:28 -0500 | [diff] [blame] | 77 | int version = -EINVAL; |
| 78 | |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 79 | if (!strcmp(s, "9p2000")) { |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 80 | version = p9_proto_legacy; |
| 81 | P9_DPRINTK(P9_DEBUG_9P, "Protocol version: Legacy\n"); |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 82 | } else if (!strcmp(s, "9p2000.u")) { |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 83 | version = p9_proto_2000u; |
| 84 | P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.u\n"); |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 85 | } else if (!strcmp(s, "9p2000.L")) { |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 86 | version = p9_proto_2000L; |
| 87 | P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.L\n"); |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 88 | } else |
| 89 | printk(KERN_INFO "9p: Unknown protocol version %s.\n", s); |
| 90 | |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 91 | return version; |
| 92 | } |
| 93 | |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 94 | /** |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 95 | * parse_options - parse mount options into client structure |
| 96 | * @opts: options string passed from mount |
| 97 | * @clnt: existing v9fs client information |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 98 | * |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 99 | * Return 0 upon success, -ERRNO upon failure |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 100 | */ |
| 101 | |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 102 | static int parse_opts(char *opts, struct p9_client *clnt) |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 103 | { |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 104 | char *options, *tmp_options; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 105 | char *p; |
| 106 | substring_t args[MAX_OPT_ARGS]; |
| 107 | int option; |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 108 | char *s; |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 109 | int ret = 0; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 110 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 111 | clnt->proto_version = p9_proto_2000u; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 112 | clnt->msize = 8192; |
| 113 | |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 114 | if (!opts) |
| 115 | return 0; |
| 116 | |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 117 | tmp_options = kstrdup(opts, GFP_KERNEL); |
| 118 | if (!tmp_options) { |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 119 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 120 | "failed to allocate copy of option string\n"); |
| 121 | return -ENOMEM; |
| 122 | } |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 123 | options = tmp_options; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 124 | |
| 125 | while ((p = strsep(&options, ",")) != NULL) { |
| 126 | int token; |
| 127 | if (!*p) |
| 128 | continue; |
| 129 | token = match_token(p, tokens, args); |
| 130 | if (token < Opt_trans) { |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 131 | int r = match_int(&args[0], &option); |
| 132 | if (r < 0) { |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 133 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 134 | "integer field, but no integer?\n"); |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 135 | ret = r; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 136 | continue; |
| 137 | } |
| 138 | } |
| 139 | switch (token) { |
| 140 | case Opt_msize: |
| 141 | clnt->msize = option; |
| 142 | break; |
| 143 | case Opt_trans: |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 144 | s = match_strdup(&args[0]); |
| 145 | if (!s) { |
| 146 | ret = -ENOMEM; |
Eric Van Hensbergen | 349d3bb | 2010-01-15 19:01:10 -0600 | [diff] [blame] | 147 | P9_DPRINTK(P9_DEBUG_ERROR, |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 148 | "problem allocating copy of trans arg\n"); |
| 149 | goto free_and_return; |
| 150 | } |
| 151 | clnt->trans_mod = v9fs_get_trans_by_name(s); |
| 152 | if (clnt->trans_mod == NULL) { |
| 153 | printk(KERN_INFO |
| 154 | "9p: Could not find " |
| 155 | "request transport: %s\n", s); |
Eric Van Hensbergen | 349d3bb | 2010-01-15 19:01:10 -0600 | [diff] [blame] | 156 | ret = -EINVAL; |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 157 | kfree(s); |
Eric Van Hensbergen | 349d3bb | 2010-01-15 19:01:10 -0600 | [diff] [blame] | 158 | goto free_and_return; |
| 159 | } |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 160 | kfree(s); |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 161 | break; |
| 162 | case Opt_legacy: |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 163 | clnt->proto_version = p9_proto_legacy; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 164 | break; |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 165 | case Opt_version: |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 166 | s = match_strdup(&args[0]); |
| 167 | if (!s) { |
| 168 | ret = -ENOMEM; |
| 169 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 170 | "problem allocating copy of version arg\n"); |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 171 | goto free_and_return; |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 172 | } |
| 173 | ret = get_protocol_version(s); |
| 174 | if (ret == -EINVAL) { |
| 175 | kfree(s); |
| 176 | goto free_and_return; |
| 177 | } |
| 178 | kfree(s); |
Sripathi Kodi | 0fb80ab | 2010-03-05 18:49:11 +0000 | [diff] [blame] | 179 | clnt->proto_version = ret; |
| 180 | break; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 181 | default: |
| 182 | continue; |
| 183 | } |
| 184 | } |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 185 | |
Eric Van Hensbergen | 349d3bb | 2010-01-15 19:01:10 -0600 | [diff] [blame] | 186 | free_and_return: |
Eric Van Hensbergen | d8c8a9e | 2010-02-08 16:23:23 -0600 | [diff] [blame] | 187 | kfree(tmp_options); |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 188 | return ret; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 189 | } |
| 190 | |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 191 | /** |
| 192 | * p9_tag_alloc - lookup/allocate a request by tag |
| 193 | * @c: client session to lookup tag within |
| 194 | * @tag: numeric id for transaction |
| 195 | * |
| 196 | * this is a simple array lookup, but will grow the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 197 | * request_slots as necessary to accommodate transaction |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 198 | * ids which did not previously have a slot. |
| 199 | * |
| 200 | * this code relies on the client spinlock to manage locks, its |
| 201 | * possible we should switch to something else, but I'd rather |
| 202 | * stick with something low-overhead for the common case. |
| 203 | * |
| 204 | */ |
| 205 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 206 | static struct p9_req_t *p9_tag_alloc(struct p9_client *c, u16 tag, int max_size) |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 207 | { |
| 208 | unsigned long flags; |
| 209 | int row, col; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 210 | struct p9_req_t *req; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 211 | int alloc_msize = min(c->msize, max_size); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 212 | |
| 213 | /* This looks up the original request by tag so we know which |
| 214 | * buffer to read the data into */ |
| 215 | tag++; |
| 216 | |
| 217 | if (tag >= c->max_tag) { |
| 218 | spin_lock_irqsave(&c->lock, flags); |
| 219 | /* check again since original check was outside of lock */ |
| 220 | while (tag >= c->max_tag) { |
| 221 | row = (tag / P9_ROW_MAXTAG); |
| 222 | c->reqs[row] = kcalloc(P9_ROW_MAXTAG, |
| 223 | sizeof(struct p9_req_t), GFP_ATOMIC); |
| 224 | |
| 225 | if (!c->reqs[row]) { |
| 226 | printk(KERN_ERR "Couldn't grow tag array\n"); |
Eric Van Hensbergen | e45c540 | 2008-10-22 18:54:47 -0500 | [diff] [blame] | 227 | spin_unlock_irqrestore(&c->lock, flags); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 228 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 229 | } |
| 230 | for (col = 0; col < P9_ROW_MAXTAG; col++) { |
| 231 | c->reqs[row][col].status = REQ_STATUS_IDLE; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 232 | c->reqs[row][col].tc = NULL; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 233 | } |
| 234 | c->max_tag += P9_ROW_MAXTAG; |
| 235 | } |
| 236 | spin_unlock_irqrestore(&c->lock, flags); |
| 237 | } |
| 238 | row = tag / P9_ROW_MAXTAG; |
| 239 | col = tag % P9_ROW_MAXTAG; |
| 240 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 241 | req = &c->reqs[row][col]; |
| 242 | if (!req->tc) { |
Aneesh Kumar K.V | eeff66e | 2011-03-08 16:39:47 +0530 | [diff] [blame] | 243 | req->wq = kmalloc(sizeof(wait_queue_head_t), GFP_NOFS); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 244 | if (!req->wq) { |
| 245 | printk(KERN_ERR "Couldn't grow tag array\n"); |
| 246 | return ERR_PTR(-ENOMEM); |
| 247 | } |
| 248 | init_waitqueue_head(req->wq); |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 249 | req->tc = kmalloc(sizeof(struct p9_fcall) + alloc_msize, |
| 250 | GFP_NOFS); |
| 251 | req->tc->capacity = alloc_msize; |
| 252 | req->rc = kmalloc(sizeof(struct p9_fcall) + alloc_msize, |
| 253 | GFP_NOFS); |
| 254 | req->rc->capacity = alloc_msize; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 255 | if ((!req->tc) || (!req->rc)) { |
| 256 | printk(KERN_ERR "Couldn't grow tag array\n"); |
| 257 | kfree(req->tc); |
| 258 | kfree(req->rc); |
Tom Tucker | 45abdf1 | 2008-10-23 16:33:25 -0500 | [diff] [blame] | 259 | kfree(req->wq); |
| 260 | req->tc = req->rc = NULL; |
| 261 | req->wq = NULL; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 262 | return ERR_PTR(-ENOMEM); |
| 263 | } |
| 264 | req->tc->sdata = (char *) req->tc + sizeof(struct p9_fcall); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 265 | req->rc->sdata = (char *) req->rc + sizeof(struct p9_fcall); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | p9pdu_reset(req->tc); |
| 269 | p9pdu_reset(req->rc); |
| 270 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 271 | req->tc->tag = tag-1; |
| 272 | req->status = REQ_STATUS_ALLOC; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 273 | |
| 274 | return &c->reqs[row][col]; |
| 275 | } |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * p9_tag_lookup - lookup a request by tag |
| 279 | * @c: client session to lookup tag within |
| 280 | * @tag: numeric id for transaction |
| 281 | * |
| 282 | */ |
| 283 | |
| 284 | struct p9_req_t *p9_tag_lookup(struct p9_client *c, u16 tag) |
| 285 | { |
| 286 | int row, col; |
| 287 | |
| 288 | /* This looks up the original request by tag so we know which |
| 289 | * buffer to read the data into */ |
| 290 | tag++; |
| 291 | |
Eric Van Hensbergen | b85f7d92 | 2011-07-13 19:12:18 -0500 | [diff] [blame] | 292 | if(tag >= c->max_tag) |
| 293 | return NULL; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 294 | |
| 295 | row = tag / P9_ROW_MAXTAG; |
| 296 | col = tag % P9_ROW_MAXTAG; |
| 297 | |
| 298 | return &c->reqs[row][col]; |
| 299 | } |
| 300 | EXPORT_SYMBOL(p9_tag_lookup); |
| 301 | |
| 302 | /** |
| 303 | * p9_tag_init - setup tags structure and contents |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 304 | * @c: v9fs client struct |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 305 | * |
| 306 | * This initializes the tags structure for each client instance. |
| 307 | * |
| 308 | */ |
| 309 | |
| 310 | static int p9_tag_init(struct p9_client *c) |
| 311 | { |
| 312 | int err = 0; |
| 313 | |
| 314 | c->tagpool = p9_idpool_create(); |
| 315 | if (IS_ERR(c->tagpool)) { |
| 316 | err = PTR_ERR(c->tagpool); |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 317 | goto error; |
| 318 | } |
Aneesh Kumar K.V | fe1cbab | 2011-05-20 18:55:52 +0000 | [diff] [blame] | 319 | err = p9_idpool_get(c->tagpool); /* reserve tag 0 */ |
| 320 | if (err < 0) { |
| 321 | p9_idpool_destroy(c->tagpool); |
| 322 | goto error; |
| 323 | } |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 324 | c->max_tag = 0; |
| 325 | error: |
| 326 | return err; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * p9_tag_cleanup - cleans up tags structure and reclaims resources |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 331 | * @c: v9fs client struct |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 332 | * |
| 333 | * This frees resources associated with the tags structure |
| 334 | * |
| 335 | */ |
| 336 | static void p9_tag_cleanup(struct p9_client *c) |
| 337 | { |
| 338 | int row, col; |
| 339 | |
| 340 | /* check to insure all requests are idle */ |
| 341 | for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) { |
| 342 | for (col = 0; col < P9_ROW_MAXTAG; col++) { |
| 343 | if (c->reqs[row][col].status != REQ_STATUS_IDLE) { |
| 344 | P9_DPRINTK(P9_DEBUG_MUX, |
| 345 | "Attempting to cleanup non-free tag %d,%d\n", |
| 346 | row, col); |
| 347 | /* TODO: delay execution of cleanup */ |
| 348 | return; |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 353 | if (c->tagpool) { |
| 354 | p9_idpool_put(0, c->tagpool); /* free reserved tag 0 */ |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 355 | p9_idpool_destroy(c->tagpool); |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 356 | } |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 357 | |
| 358 | /* free requests associated with tags */ |
| 359 | for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 360 | for (col = 0; col < P9_ROW_MAXTAG; col++) { |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 361 | kfree(c->reqs[row][col].wq); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 362 | kfree(c->reqs[row][col].tc); |
| 363 | kfree(c->reqs[row][col].rc); |
| 364 | } |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 365 | kfree(c->reqs[row]); |
| 366 | } |
| 367 | c->max_tag = 0; |
| 368 | } |
| 369 | |
Eric Van Hensbergen | 673d62cd | 2008-10-13 18:45:22 -0500 | [diff] [blame] | 370 | /** |
| 371 | * p9_free_req - free a request and clean-up as necessary |
| 372 | * c: client state |
| 373 | * r: request to release |
| 374 | * |
| 375 | */ |
| 376 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 377 | 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] | 378 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 379 | int tag = r->tc->tag; |
| 380 | P9_DPRINTK(P9_DEBUG_MUX, "clnt %p req %p tag: %d\n", c, r, tag); |
| 381 | |
Eric Van Hensbergen | 673d62cd | 2008-10-13 18:45:22 -0500 | [diff] [blame] | 382 | r->status = REQ_STATUS_IDLE; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 383 | if (tag != P9_NOTAG && p9_idpool_check(tag, c->tagpool)) |
| 384 | p9_idpool_put(tag, c->tagpool); |
Eric Van Hensbergen | 673d62cd | 2008-10-13 18:45:22 -0500 | [diff] [blame] | 385 | } |
| 386 | |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 387 | /** |
| 388 | * p9_client_cb - call back from transport to client |
| 389 | * c: client state |
| 390 | * req: request received |
| 391 | * |
| 392 | */ |
| 393 | void p9_client_cb(struct p9_client *c, struct p9_req_t *req) |
| 394 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 395 | P9_DPRINTK(P9_DEBUG_MUX, " tag %d\n", req->tc->tag); |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 396 | wake_up(req->wq); |
| 397 | P9_DPRINTK(P9_DEBUG_MUX, "wakeup: %d\n", req->tc->tag); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 398 | } |
| 399 | EXPORT_SYMBOL(p9_client_cb); |
| 400 | |
| 401 | /** |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 402 | * p9_parse_header - parse header arguments out of a packet |
| 403 | * @pdu: packet to parse |
| 404 | * @size: size of packet |
| 405 | * @type: type of request |
| 406 | * @tag: tag of packet |
| 407 | * @rewind: set if we need to rewind offset afterwards |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 408 | */ |
| 409 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 410 | int |
| 411 | p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, int16_t *tag, |
| 412 | int rewind) |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 413 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 414 | int8_t r_type; |
| 415 | int16_t r_tag; |
| 416 | int32_t r_size; |
| 417 | int offset = pdu->offset; |
| 418 | int err; |
| 419 | |
| 420 | pdu->offset = 0; |
| 421 | if (pdu->size == 0) |
| 422 | pdu->size = 7; |
| 423 | |
| 424 | err = p9pdu_readf(pdu, 0, "dbw", &r_size, &r_type, &r_tag); |
| 425 | if (err) |
| 426 | goto rewind_and_exit; |
| 427 | |
| 428 | pdu->size = r_size; |
| 429 | pdu->id = r_type; |
| 430 | pdu->tag = r_tag; |
| 431 | |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 432 | P9_DPRINTK(P9_DEBUG_9P, "<<< size=%d type: %d tag: %d\n", pdu->size, |
| 433 | pdu->id, pdu->tag); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 434 | |
| 435 | if (type) |
| 436 | *type = r_type; |
| 437 | if (tag) |
| 438 | *tag = r_tag; |
| 439 | if (size) |
| 440 | *size = r_size; |
| 441 | |
| 442 | |
| 443 | rewind_and_exit: |
| 444 | if (rewind) |
| 445 | pdu->offset = offset; |
| 446 | return err; |
| 447 | } |
| 448 | EXPORT_SYMBOL(p9_parse_header); |
| 449 | |
| 450 | /** |
| 451 | * p9_check_errors - check 9p packet for error return and process it |
| 452 | * @c: current client instance |
| 453 | * @req: request to parse and check for error conditions |
| 454 | * |
| 455 | * returns error code if one is discovered, otherwise returns 0 |
| 456 | * |
| 457 | * this will have to be more complicated if we have multiple |
| 458 | * error packet types |
| 459 | */ |
| 460 | |
| 461 | static int p9_check_errors(struct p9_client *c, struct p9_req_t *req) |
| 462 | { |
| 463 | int8_t type; |
| 464 | int err; |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 465 | int ecode; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 466 | |
| 467 | err = p9_parse_header(req->rc, NULL, &type, NULL, 0); |
| 468 | if (err) { |
| 469 | P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse header %d\n", err); |
| 470 | return err; |
| 471 | } |
| 472 | |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 473 | if (type != P9_RERROR && type != P9_RLERROR) |
| 474 | return 0; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 475 | |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 476 | if (!p9_is_proto_dotl(c)) { |
| 477 | char *ename; |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 478 | err = p9pdu_readf(req->rc, c->proto_version, "s?d", |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 479 | &ename, &ecode); |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 480 | if (err) |
| 481 | goto out_err; |
| 482 | |
| 483 | if (p9_is_proto_dotu(c)) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 484 | err = -ecode; |
| 485 | |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 486 | if (!err || !IS_ERR_VALUE(err)) { |
| 487 | err = p9_errstr2errno(ename, strlen(ename)); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 488 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 489 | P9_DPRINTK(P9_DEBUG_9P, "<<< RERROR (%d) %s\n", |
| 490 | -ecode, ename); |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 491 | } |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 492 | kfree(ename); |
Venkateswararao Jujjuri (JV) | ca41bb3 | 2011-02-01 20:04:59 -0800 | [diff] [blame] | 493 | } else { |
| 494 | err = p9pdu_readf(req->rc, c->proto_version, "d", &ecode); |
| 495 | err = -ecode; |
| 496 | |
| 497 | P9_DPRINTK(P9_DEBUG_9P, "<<< RLERROR (%d)\n", -ecode); |
| 498 | } |
| 499 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 500 | return err; |
Arun R Bharadwaj | 4f7ebe8 | 2010-07-28 14:17:26 +0530 | [diff] [blame] | 501 | |
| 502 | out_err: |
| 503 | P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n", err); |
| 504 | |
| 505 | return err; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 506 | } |
| 507 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 508 | /** |
| 509 | * p9_check_zc_errors - check 9p packet for error return and process it |
| 510 | * @c: current client instance |
| 511 | * @req: request to parse and check for error conditions |
| 512 | * @in_hdrlen: Size of response protocol buffer. |
| 513 | * |
| 514 | * returns error code if one is discovered, otherwise returns 0 |
| 515 | * |
| 516 | * this will have to be more complicated if we have multiple |
| 517 | * error packet types |
| 518 | */ |
| 519 | |
| 520 | static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req, |
| 521 | char *uidata, int in_hdrlen, int kern_buf) |
| 522 | { |
| 523 | int err; |
| 524 | int ecode; |
| 525 | int8_t type; |
| 526 | char *ename = NULL; |
| 527 | |
| 528 | err = p9_parse_header(req->rc, NULL, &type, NULL, 0); |
| 529 | if (err) { |
| 530 | P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse header %d\n", err); |
| 531 | return err; |
| 532 | } |
| 533 | |
| 534 | if (type != P9_RERROR && type != P9_RLERROR) |
| 535 | return 0; |
| 536 | |
| 537 | if (!p9_is_proto_dotl(c)) { |
| 538 | /* Error is reported in string format */ |
| 539 | uint16_t len; |
| 540 | /* 7 = header size for RERROR, 2 is the size of string len; */ |
| 541 | int inline_len = in_hdrlen - (7 + 2); |
| 542 | |
| 543 | /* Read the size of error string */ |
| 544 | err = p9pdu_readf(req->rc, c->proto_version, "w", &len); |
| 545 | if (err) |
| 546 | goto out_err; |
| 547 | |
| 548 | ename = kmalloc(len + 1, GFP_NOFS); |
| 549 | if (!ename) { |
| 550 | err = -ENOMEM; |
| 551 | goto out_err; |
| 552 | } |
| 553 | if (len <= inline_len) { |
| 554 | /* We have error in protocol buffer itself */ |
| 555 | if (pdu_read(req->rc, ename, len)) { |
| 556 | err = -EFAULT; |
| 557 | goto out_free; |
| 558 | |
| 559 | } |
| 560 | } else { |
| 561 | /* |
| 562 | * Part of the data is in user space buffer. |
| 563 | */ |
| 564 | if (pdu_read(req->rc, ename, inline_len)) { |
| 565 | err = -EFAULT; |
| 566 | goto out_free; |
| 567 | |
| 568 | } |
| 569 | if (kern_buf) { |
| 570 | memcpy(ename + inline_len, uidata, |
| 571 | len - inline_len); |
| 572 | } else { |
| 573 | err = copy_from_user(ename + inline_len, |
| 574 | uidata, len - inline_len); |
| 575 | if (err) { |
| 576 | err = -EFAULT; |
| 577 | goto out_free; |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | ename[len] = 0; |
| 582 | if (p9_is_proto_dotu(c)) { |
| 583 | /* For dotu we also have error code */ |
| 584 | err = p9pdu_readf(req->rc, |
| 585 | c->proto_version, "d", &ecode); |
| 586 | if (err) |
| 587 | goto out_free; |
| 588 | err = -ecode; |
| 589 | } |
| 590 | if (!err || !IS_ERR_VALUE(err)) { |
| 591 | err = p9_errstr2errno(ename, strlen(ename)); |
| 592 | |
| 593 | P9_DPRINTK(P9_DEBUG_9P, "<<< RERROR (%d) %s\n", |
| 594 | -ecode, ename); |
| 595 | } |
| 596 | kfree(ename); |
| 597 | } else { |
| 598 | err = p9pdu_readf(req->rc, c->proto_version, "d", &ecode); |
| 599 | err = -ecode; |
| 600 | |
| 601 | P9_DPRINTK(P9_DEBUG_9P, "<<< RLERROR (%d)\n", -ecode); |
| 602 | } |
| 603 | return err; |
| 604 | |
| 605 | out_free: |
| 606 | kfree(ename); |
| 607 | out_err: |
| 608 | P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n", err); |
| 609 | return err; |
| 610 | } |
| 611 | |
Rob Landley | aca0076 | 2011-05-08 18:46:38 +0000 | [diff] [blame] | 612 | static struct p9_req_t * |
| 613 | p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...); |
| 614 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 615 | /** |
| 616 | * p9_client_flush - flush (cancel) a request |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 617 | * @c: client state |
| 618 | * @oldreq: request to cancel |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 619 | * |
Rob Landley | aca0076 | 2011-05-08 18:46:38 +0000 | [diff] [blame] | 620 | * This sents a flush for a particular request and links |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 621 | * the flush request to the original request. The current |
| 622 | * code only supports a single flush request although the protocol |
| 623 | * allows for multiple flush requests to be sent for a single request. |
| 624 | * |
| 625 | */ |
| 626 | |
| 627 | static int p9_client_flush(struct p9_client *c, struct p9_req_t *oldreq) |
| 628 | { |
| 629 | struct p9_req_t *req; |
| 630 | int16_t oldtag; |
| 631 | int err; |
| 632 | |
| 633 | err = p9_parse_header(oldreq->tc, NULL, NULL, &oldtag, 1); |
| 634 | if (err) |
| 635 | return err; |
| 636 | |
| 637 | P9_DPRINTK(P9_DEBUG_9P, ">>> TFLUSH tag %d\n", oldtag); |
| 638 | |
| 639 | req = p9_client_rpc(c, P9_TFLUSH, "w", oldtag); |
| 640 | if (IS_ERR(req)) |
| 641 | return PTR_ERR(req); |
| 642 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 643 | |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 644 | /* if we haven't received a response for oldreq, |
| 645 | remove it from the list. */ |
| 646 | spin_lock(&c->lock); |
| 647 | if (oldreq->status == REQ_STATUS_FLSH) |
| 648 | list_del(&oldreq->req_list); |
| 649 | spin_unlock(&c->lock); |
| 650 | |
| 651 | p9_free_req(c, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 652 | return 0; |
| 653 | } |
| 654 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 655 | static struct p9_req_t *p9_client_prepare_req(struct p9_client *c, |
| 656 | int8_t type, int req_size, |
| 657 | const char *fmt, va_list ap) |
| 658 | { |
| 659 | int tag, err; |
| 660 | struct p9_req_t *req; |
| 661 | |
| 662 | P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type); |
| 663 | |
| 664 | /* we allow for any status other than disconnected */ |
| 665 | if (c->status == Disconnected) |
| 666 | return ERR_PTR(-EIO); |
| 667 | |
| 668 | /* if status is begin_disconnected we allow only clunk request */ |
| 669 | if ((c->status == BeginDisconnect) && (type != P9_TCLUNK)) |
| 670 | return ERR_PTR(-EIO); |
| 671 | |
| 672 | tag = P9_NOTAG; |
| 673 | if (type != P9_TVERSION) { |
| 674 | tag = p9_idpool_get(c->tagpool); |
| 675 | if (tag < 0) |
| 676 | return ERR_PTR(-ENOMEM); |
| 677 | } |
| 678 | |
| 679 | req = p9_tag_alloc(c, tag, req_size); |
| 680 | if (IS_ERR(req)) |
| 681 | return req; |
| 682 | |
| 683 | /* marshall the data */ |
| 684 | p9pdu_prepare(req->tc, tag, type); |
| 685 | err = p9pdu_vwritef(req->tc, c->proto_version, fmt, ap); |
| 686 | if (err) |
| 687 | goto reterr; |
| 688 | p9pdu_finalize(req->tc); |
| 689 | return req; |
| 690 | reterr: |
| 691 | p9_free_req(c, req); |
| 692 | return ERR_PTR(err); |
| 693 | } |
| 694 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 695 | /** |
| 696 | * p9_client_rpc - issue a request and wait for a response |
| 697 | * @c: client session |
| 698 | * @type: type of request |
| 699 | * @fmt: protocol format string (see protocol.c) |
| 700 | * |
| 701 | * Returns request structure (which client must free using p9_free_req) |
| 702 | */ |
| 703 | |
| 704 | static struct p9_req_t * |
| 705 | p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...) |
| 706 | { |
| 707 | va_list ap; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 708 | int sigpending, err; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 709 | unsigned long flags; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 710 | struct p9_req_t *req; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 711 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 712 | va_start(ap, fmt); |
| 713 | req = p9_client_prepare_req(c, type, c->msize, fmt, ap); |
| 714 | va_end(ap); |
| 715 | if (IS_ERR(req)) |
| 716 | return req; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 717 | |
| 718 | if (signal_pending(current)) { |
| 719 | sigpending = 1; |
| 720 | clear_thread_flag(TIF_SIGPENDING); |
| 721 | } else |
| 722 | sigpending = 0; |
| 723 | |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 724 | err = c->trans_mod->request(c, req); |
| 725 | if (err < 0) { |
M. Mohan Kumar | 3cd7967 | 2011-04-15 13:59:33 +0530 | [diff] [blame] | 726 | if (err != -ERESTARTSYS && err != -EFAULT) |
Venkateswararao Jujjuri (JV) | 52f44e0 | 2010-09-29 18:33:41 -0700 | [diff] [blame] | 727 | c->status = Disconnected; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 728 | goto reterr; |
| 729 | } |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 730 | /* Wait for the response */ |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 731 | err = wait_event_interruptible(*req->wq, |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 732 | req->status >= REQ_STATUS_RCVD); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 733 | |
| 734 | if (req->status == REQ_STATUS_ERROR) { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 735 | 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] | 736 | err = req->t_err; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 737 | } |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 738 | if ((err == -ERESTARTSYS) && (c->status == Connected)) { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 739 | P9_DPRINTK(P9_DEBUG_MUX, "flushing\n"); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 740 | sigpending = 1; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 741 | clear_thread_flag(TIF_SIGPENDING); |
| 742 | |
Latchesar Ionkov | 1bab88b | 2009-04-05 16:28:59 -0500 | [diff] [blame] | 743 | if (c->trans_mod->cancel(c, req)) |
| 744 | p9_client_flush(c, req); |
| 745 | |
| 746 | /* if we received the response anyway, don't signal error */ |
| 747 | if (req->status == REQ_STATUS_RCVD) |
| 748 | err = 0; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 749 | } |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 750 | if (sigpending) { |
| 751 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
| 752 | recalc_sigpending(); |
| 753 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
| 754 | } |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 755 | if (err < 0) |
| 756 | goto reterr; |
| 757 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 758 | err = p9_check_errors(c, req); |
| 759 | if (!err) { |
| 760 | P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d\n", c, type); |
| 761 | return req; |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 762 | } |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 763 | reterr: |
| 764 | P9_DPRINTK(P9_DEBUG_MUX, |
| 765 | "exit: client %p op %d error: %d\n", c, type, err); |
| 766 | p9_free_req(c, req); |
| 767 | return ERR_PTR(err); |
| 768 | } |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 769 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 770 | /** |
| 771 | * p9_client_zc_rpc - issue a request and wait for a response |
| 772 | * @c: client session |
| 773 | * @type: type of request |
| 774 | * @uidata: user bffer that should be ued for zero copy read |
| 775 | * @uodata: user buffer that shoud be user for zero copy write |
| 776 | * @inlen: read buffer size |
| 777 | * @olen: write buffer size |
| 778 | * @hdrlen: reader header size, This is the size of response protocol data |
| 779 | * @fmt: protocol format string (see protocol.c) |
| 780 | * |
| 781 | * Returns request structure (which client must free using p9_free_req) |
| 782 | */ |
| 783 | static struct p9_req_t *p9_client_zc_rpc(struct p9_client *c, int8_t type, |
| 784 | char *uidata, char *uodata, |
| 785 | int inlen, int olen, int in_hdrlen, |
| 786 | int kern_buf, const char *fmt, ...) |
| 787 | { |
| 788 | va_list ap; |
| 789 | int sigpending, err; |
| 790 | unsigned long flags; |
| 791 | struct p9_req_t *req; |
| 792 | |
| 793 | va_start(ap, fmt); |
| 794 | /* |
| 795 | * We allocate a inline protocol data of only 4k bytes. |
| 796 | * The actual content is passed in zero-copy fashion. |
| 797 | */ |
| 798 | req = p9_client_prepare_req(c, type, P9_ZC_HDR_SZ, fmt, ap); |
| 799 | va_end(ap); |
| 800 | if (IS_ERR(req)) |
| 801 | return req; |
| 802 | |
| 803 | if (signal_pending(current)) { |
| 804 | sigpending = 1; |
| 805 | clear_thread_flag(TIF_SIGPENDING); |
| 806 | } else |
| 807 | sigpending = 0; |
| 808 | |
| 809 | /* If we are called with KERNEL_DS force kern_buf */ |
| 810 | if (segment_eq(get_fs(), KERNEL_DS)) |
| 811 | kern_buf = 1; |
| 812 | |
| 813 | err = c->trans_mod->zc_request(c, req, uidata, uodata, |
| 814 | inlen, olen, in_hdrlen, kern_buf); |
| 815 | if (err < 0) { |
| 816 | if (err == -EIO) |
| 817 | c->status = Disconnected; |
| 818 | goto reterr; |
| 819 | } |
| 820 | if (req->status == REQ_STATUS_ERROR) { |
| 821 | P9_DPRINTK(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err); |
| 822 | err = req->t_err; |
| 823 | } |
| 824 | if ((err == -ERESTARTSYS) && (c->status == Connected)) { |
| 825 | P9_DPRINTK(P9_DEBUG_MUX, "flushing\n"); |
| 826 | sigpending = 1; |
| 827 | clear_thread_flag(TIF_SIGPENDING); |
| 828 | |
| 829 | if (c->trans_mod->cancel(c, req)) |
| 830 | p9_client_flush(c, req); |
| 831 | |
| 832 | /* if we received the response anyway, don't signal error */ |
| 833 | if (req->status == REQ_STATUS_RCVD) |
| 834 | err = 0; |
| 835 | } |
| 836 | if (sigpending) { |
| 837 | spin_lock_irqsave(¤t->sighand->siglock, flags); |
| 838 | recalc_sigpending(); |
| 839 | spin_unlock_irqrestore(¤t->sighand->siglock, flags); |
| 840 | } |
| 841 | if (err < 0) |
| 842 | goto reterr; |
| 843 | |
| 844 | err = p9_check_zc_errors(c, req, uidata, in_hdrlen, kern_buf); |
| 845 | if (!err) { |
| 846 | P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d\n", c, type); |
| 847 | return req; |
| 848 | } |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 849 | reterr: |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 850 | P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d error: %d\n", c, type, |
| 851 | err); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 852 | p9_free_req(c, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 853 | return ERR_PTR(err); |
Eric Van Hensbergen | 91b8534 | 2008-10-13 18:45:21 -0500 | [diff] [blame] | 854 | } |
| 855 | |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 856 | static struct p9_fid *p9_fid_create(struct p9_client *clnt) |
| 857 | { |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 858 | int ret; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 859 | struct p9_fid *fid; |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 860 | unsigned long flags; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 861 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 862 | P9_DPRINTK(P9_DEBUG_FID, "clnt %p\n", clnt); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 863 | fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL); |
| 864 | if (!fid) |
| 865 | return ERR_PTR(-ENOMEM); |
| 866 | |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 867 | ret = p9_idpool_get(clnt->fidpool); |
Roel Kluin | 24e94de | 2009-01-18 21:32:11 -0800 | [diff] [blame] | 868 | if (ret < 0) { |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 869 | ret = -ENOSPC; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 870 | goto error; |
| 871 | } |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 872 | fid->fid = ret; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 873 | |
| 874 | memset(&fid->qid, 0, sizeof(struct p9_qid)); |
| 875 | fid->mode = -1; |
David Howells | f8b9d53 | 2008-11-14 10:38:44 +1100 | [diff] [blame] | 876 | fid->uid = current_fsuid(); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 877 | fid->clnt = clnt; |
Eric Van Hensbergen | 3e2796a | 2009-11-02 08:39:28 -0600 | [diff] [blame] | 878 | fid->rdir = NULL; |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 879 | spin_lock_irqsave(&clnt->lock, flags); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 880 | list_add(&fid->flist, &clnt->fidlist); |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 881 | spin_unlock_irqrestore(&clnt->lock, flags); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 882 | |
| 883 | return fid; |
| 884 | |
| 885 | error: |
| 886 | kfree(fid); |
Roel Kluin | 9f3e9bb | 2008-10-28 14:22:43 -0500 | [diff] [blame] | 887 | return ERR_PTR(ret); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | static void p9_fid_destroy(struct p9_fid *fid) |
| 891 | { |
| 892 | struct p9_client *clnt; |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 893 | unsigned long flags; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 894 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 895 | P9_DPRINTK(P9_DEBUG_FID, "fid %d\n", fid->fid); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 896 | clnt = fid->clnt; |
| 897 | p9_idpool_put(fid->fid, clnt->fidpool); |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 898 | spin_lock_irqsave(&clnt->lock, flags); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 899 | list_del(&fid->flist); |
Tom Tucker | cac23d6 | 2008-10-23 16:31:02 -0500 | [diff] [blame] | 900 | spin_unlock_irqrestore(&clnt->lock, flags); |
Eric Van Hensbergen | 3e2796a | 2009-11-02 08:39:28 -0600 | [diff] [blame] | 901 | kfree(fid->rdir); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 902 | kfree(fid); |
| 903 | } |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 904 | |
stephen hemminger | 32a875a | 2010-10-19 06:48:16 +0000 | [diff] [blame] | 905 | static int p9_client_version(struct p9_client *c) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 906 | { |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 907 | int err = 0; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 908 | struct p9_req_t *req; |
| 909 | char *version; |
| 910 | int msize; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 911 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 912 | P9_DPRINTK(P9_DEBUG_9P, ">>> TVERSION msize %d protocol %d\n", |
| 913 | c->msize, c->proto_version); |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 914 | |
| 915 | switch (c->proto_version) { |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 916 | case p9_proto_2000L: |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 917 | req = p9_client_rpc(c, P9_TVERSION, "ds", |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 918 | c->msize, "9P2000.L"); |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 919 | break; |
| 920 | case p9_proto_2000u: |
| 921 | req = p9_client_rpc(c, P9_TVERSION, "ds", |
| 922 | c->msize, "9P2000.u"); |
| 923 | break; |
| 924 | case p9_proto_legacy: |
| 925 | req = p9_client_rpc(c, P9_TVERSION, "ds", |
| 926 | c->msize, "9P2000"); |
| 927 | break; |
| 928 | default: |
| 929 | return -EINVAL; |
| 930 | break; |
| 931 | } |
| 932 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 933 | if (IS_ERR(req)) |
| 934 | return PTR_ERR(req); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 935 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 936 | err = p9pdu_readf(req->rc, c->proto_version, "ds", &msize, &version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 937 | if (err) { |
| 938 | P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err); |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 939 | P9_DUMP_PKT(1, req->rc); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 940 | goto error; |
| 941 | } |
| 942 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 943 | P9_DPRINTK(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version); |
Sripathi Kodi | 45bc21e | 2010-03-08 17:33:04 +0000 | [diff] [blame] | 944 | if (!strncmp(version, "9P2000.L", 8)) |
| 945 | c->proto_version = p9_proto_2000L; |
Sripathi Kodi | c5a7697 | 2010-03-05 18:51:04 +0000 | [diff] [blame] | 946 | else if (!strncmp(version, "9P2000.u", 8)) |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 947 | c->proto_version = p9_proto_2000u; |
| 948 | else if (!strncmp(version, "9P2000", 6)) |
| 949 | c->proto_version = p9_proto_legacy; |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 950 | else { |
| 951 | err = -EREMOTEIO; |
| 952 | goto error; |
| 953 | } |
| 954 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 955 | if (msize < c->msize) |
| 956 | c->msize = msize; |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 957 | |
| 958 | error: |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 959 | kfree(version); |
| 960 | p9_free_req(c, req); |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 961 | |
| 962 | return err; |
| 963 | } |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 964 | |
| 965 | struct p9_client *p9_client_create(const char *dev_name, char *options) |
| 966 | { |
| 967 | int err; |
| 968 | struct p9_client *clnt; |
| 969 | |
| 970 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 971 | clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL); |
| 972 | if (!clnt) |
| 973 | return ERR_PTR(-ENOMEM); |
| 974 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 975 | clnt->trans_mod = NULL; |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 976 | clnt->trans = NULL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 977 | spin_lock_init(&clnt->lock); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 978 | INIT_LIST_HEAD(&clnt->fidlist); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 979 | |
Aneesh Kumar K.V | fe1cbab | 2011-05-20 18:55:52 +0000 | [diff] [blame] | 980 | err = p9_tag_init(clnt); |
| 981 | if (err < 0) |
| 982 | goto free_client; |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 983 | |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 984 | err = parse_opts(options, clnt); |
| 985 | if (err < 0) |
Aneesh Kumar K.V | fe1cbab | 2011-05-20 18:55:52 +0000 | [diff] [blame] | 986 | goto destroy_tagpool; |
Eric Van Hensbergen | bb8ffdf | 2008-03-07 10:53:53 -0600 | [diff] [blame] | 987 | |
Abhishek Kulkarni | a17d172 | 2009-07-14 13:24:10 -0500 | [diff] [blame] | 988 | if (!clnt->trans_mod) |
| 989 | clnt->trans_mod = v9fs_get_default_trans(); |
| 990 | |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 991 | if (clnt->trans_mod == NULL) { |
| 992 | err = -EPROTONOSUPPORT; |
| 993 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 994 | "No transport defined or default transport\n"); |
Aneesh Kumar K.V | fe1cbab | 2011-05-20 18:55:52 +0000 | [diff] [blame] | 995 | goto destroy_tagpool; |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | clnt->fidpool = p9_idpool_create(); |
| 999 | if (IS_ERR(clnt->fidpool)) { |
| 1000 | err = PTR_ERR(clnt->fidpool); |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 1001 | goto put_trans; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1002 | } |
| 1003 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1004 | P9_DPRINTK(P9_DEBUG_MUX, "clnt %p trans %p msize %d protocol %d\n", |
| 1005 | clnt, clnt->trans_mod, clnt->msize, clnt->proto_version); |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 1006 | |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 1007 | err = clnt->trans_mod->create(clnt, dev_name, options); |
| 1008 | if (err) |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 1009 | goto destroy_fidpool; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 1010 | |
Venkateswararao Jujjuri (JV) | c9ffb05 | 2011-06-29 18:06:33 -0700 | [diff] [blame] | 1011 | if (clnt->msize > clnt->trans_mod->maxsize) |
| 1012 | clnt->msize = clnt->trans_mod->maxsize; |
Eric Van Hensbergen | 8a0dc95 | 2008-02-06 19:25:03 -0600 | [diff] [blame] | 1013 | |
Eric Van Hensbergen | 6936bf6 | 2008-10-13 20:36:14 -0500 | [diff] [blame] | 1014 | err = p9_client_version(clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1015 | if (err) |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 1016 | goto close_trans; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1017 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1018 | return clnt; |
| 1019 | |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 1020 | close_trans: |
| 1021 | clnt->trans_mod->close(clnt); |
| 1022 | destroy_fidpool: |
| 1023 | p9_idpool_destroy(clnt->fidpool); |
| 1024 | put_trans: |
| 1025 | v9fs_put_trans(clnt->trans_mod); |
Aneesh Kumar K.V | fe1cbab | 2011-05-20 18:55:52 +0000 | [diff] [blame] | 1026 | destroy_tagpool: |
| 1027 | p9_idpool_destroy(clnt->tagpool); |
Eric Van Hensbergen | 8781ff9 | 2010-02-08 18:18:34 -0600 | [diff] [blame] | 1028 | free_client: |
| 1029 | kfree(clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1030 | return ERR_PTR(err); |
| 1031 | } |
| 1032 | EXPORT_SYMBOL(p9_client_create); |
| 1033 | |
| 1034 | void p9_client_destroy(struct p9_client *clnt) |
| 1035 | { |
| 1036 | struct p9_fid *fid, *fidptr; |
| 1037 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1038 | P9_DPRINTK(P9_DEBUG_MUX, "clnt %p\n", clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1039 | |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 1040 | if (clnt->trans_mod) |
| 1041 | clnt->trans_mod->close(clnt); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1042 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 1043 | v9fs_put_trans(clnt->trans_mod); |
| 1044 | |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 1045 | list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist) { |
| 1046 | printk(KERN_INFO "Found fid %d not clunked\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1047 | p9_fid_destroy(fid); |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 1048 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1049 | |
Eric Van Hensbergen | 0af8887 | 2007-07-13 16:47:58 -0500 | [diff] [blame] | 1050 | if (clnt->fidpool) |
| 1051 | p9_idpool_destroy(clnt->fidpool); |
| 1052 | |
Eric Van Hensbergen | fea511a | 2008-10-13 18:45:23 -0500 | [diff] [blame] | 1053 | p9_tag_cleanup(clnt); |
| 1054 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1055 | kfree(clnt); |
| 1056 | } |
| 1057 | EXPORT_SYMBOL(p9_client_destroy); |
| 1058 | |
| 1059 | void p9_client_disconnect(struct p9_client *clnt) |
| 1060 | { |
| 1061 | P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt); |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 1062 | clnt->status = Disconnected; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1063 | } |
| 1064 | EXPORT_SYMBOL(p9_client_disconnect); |
| 1065 | |
Aneesh Kumar K.V | 6d96d3a | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 1066 | void p9_client_begin_disconnect(struct p9_client *clnt) |
| 1067 | { |
| 1068 | P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt); |
| 1069 | clnt->status = BeginDisconnect; |
| 1070 | } |
| 1071 | EXPORT_SYMBOL(p9_client_begin_disconnect); |
| 1072 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1073 | 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] | 1074 | char *uname, u32 n_uname, char *aname) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1075 | { |
| 1076 | int err; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1077 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1078 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1079 | struct p9_qid qid; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1080 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1081 | P9_DPRINTK(P9_DEBUG_9P, ">>> TATTACH afid %d uname %s aname %s\n", |
| 1082 | afid ? afid->fid : -1, uname, aname); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1083 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1084 | |
| 1085 | fid = p9_fid_create(clnt); |
| 1086 | if (IS_ERR(fid)) { |
| 1087 | err = PTR_ERR(fid); |
| 1088 | fid = NULL; |
| 1089 | goto error; |
| 1090 | } |
| 1091 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1092 | req = p9_client_rpc(clnt, P9_TATTACH, "ddss?d", fid->fid, |
| 1093 | afid ? afid->fid : P9_NOFID, uname, aname, n_uname); |
| 1094 | if (IS_ERR(req)) { |
| 1095 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1096 | goto error; |
| 1097 | } |
| 1098 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1099 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1100 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1101 | P9_DUMP_PKT(1, req->rc); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1102 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1103 | goto error; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1104 | } |
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_DPRINTK(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n", |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 1107 | qid.type, |
| 1108 | (unsigned long long)qid.path, |
| 1109 | qid.version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1110 | |
| 1111 | memmove(&fid->qid, &qid, sizeof(struct p9_qid)); |
| 1112 | |
| 1113 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1114 | return fid; |
| 1115 | |
| 1116 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1117 | if (fid) |
| 1118 | p9_fid_destroy(fid); |
| 1119 | return ERR_PTR(err); |
| 1120 | } |
| 1121 | EXPORT_SYMBOL(p9_client_attach); |
| 1122 | |
Harsh Prateek Bora | b76225e | 2011-03-31 15:49:39 +0530 | [diff] [blame] | 1123 | struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, |
| 1124 | char **wnames, int clone) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1125 | { |
| 1126 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1127 | struct p9_client *clnt; |
| 1128 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1129 | struct p9_qid *wqids; |
| 1130 | struct p9_req_t *req; |
Harsh Prateek Bora | b76225e | 2011-03-31 15:49:39 +0530 | [diff] [blame] | 1131 | uint16_t nwqids, count; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1132 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1133 | err = 0; |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1134 | wqids = NULL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1135 | clnt = oldfid->clnt; |
| 1136 | if (clone) { |
| 1137 | fid = p9_fid_create(clnt); |
| 1138 | if (IS_ERR(fid)) { |
| 1139 | err = PTR_ERR(fid); |
| 1140 | fid = NULL; |
| 1141 | goto error; |
| 1142 | } |
| 1143 | |
| 1144 | fid->uid = oldfid->uid; |
| 1145 | } else |
| 1146 | fid = oldfid; |
| 1147 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1148 | |
Harsh Prateek Bora | b76225e | 2011-03-31 15:49:39 +0530 | [diff] [blame] | 1149 | P9_DPRINTK(P9_DEBUG_9P, ">>> TWALK fids %d,%d nwname %ud wname[0] %s\n", |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1150 | oldfid->fid, fid->fid, nwname, wnames ? wnames[0] : NULL); |
| 1151 | |
| 1152 | req = p9_client_rpc(clnt, P9_TWALK, "ddT", oldfid->fid, fid->fid, |
| 1153 | nwname, wnames); |
| 1154 | if (IS_ERR(req)) { |
| 1155 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1156 | goto error; |
| 1157 | } |
| 1158 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1159 | err = p9pdu_readf(req->rc, clnt->proto_version, "R", &nwqids, &wqids); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1160 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1161 | P9_DUMP_PKT(1, req->rc); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1162 | p9_free_req(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1163 | goto clunk_fid; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1164 | } |
| 1165 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1166 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1167 | P9_DPRINTK(P9_DEBUG_9P, "<<< RWALK nwqid %d:\n", nwqids); |
| 1168 | |
| 1169 | if (nwqids != nwname) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1170 | err = -ENOENT; |
| 1171 | goto clunk_fid; |
| 1172 | } |
| 1173 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1174 | for (count = 0; count < nwqids; count++) |
| 1175 | P9_DPRINTK(P9_DEBUG_9P, "<<< [%d] %x.%llx.%x\n", |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 1176 | count, wqids[count].type, |
| 1177 | (unsigned long long)wqids[count].path, |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1178 | wqids[count].version); |
| 1179 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1180 | if (nwname) |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1181 | memmove(&fid->qid, &wqids[nwqids - 1], sizeof(struct p9_qid)); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1182 | else |
| 1183 | fid->qid = oldfid->qid; |
| 1184 | |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1185 | kfree(wqids); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1186 | return fid; |
| 1187 | |
| 1188 | clunk_fid: |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1189 | kfree(wqids); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1190 | p9_client_clunk(fid); |
| 1191 | fid = NULL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1192 | |
| 1193 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1194 | if (fid && (fid != oldfid)) |
| 1195 | p9_fid_destroy(fid); |
| 1196 | |
| 1197 | return ERR_PTR(err); |
| 1198 | } |
| 1199 | EXPORT_SYMBOL(p9_client_walk); |
| 1200 | |
| 1201 | int p9_client_open(struct p9_fid *fid, int mode) |
| 1202 | { |
| 1203 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1204 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1205 | struct p9_req_t *req; |
| 1206 | struct p9_qid qid; |
| 1207 | int iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1208 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1209 | clnt = fid->clnt; |
M. Mohan Kumar | ef56547 | 2010-06-22 19:47:50 +0530 | [diff] [blame] | 1210 | P9_DPRINTK(P9_DEBUG_9P, ">>> %s fid %d mode %d\n", |
| 1211 | p9_is_proto_dotl(clnt) ? "TLOPEN" : "TOPEN", fid->fid, mode); |
| 1212 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1213 | |
| 1214 | if (fid->mode != -1) |
| 1215 | return -EINVAL; |
| 1216 | |
M. Mohan Kumar | ef56547 | 2010-06-22 19:47:50 +0530 | [diff] [blame] | 1217 | if (p9_is_proto_dotl(clnt)) |
| 1218 | req = p9_client_rpc(clnt, P9_TLOPEN, "dd", fid->fid, mode); |
| 1219 | else |
| 1220 | req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1221 | if (IS_ERR(req)) { |
| 1222 | err = PTR_ERR(req); |
| 1223 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1224 | } |
| 1225 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1226 | err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1227 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1228 | P9_DUMP_PKT(1, req->rc); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1229 | goto free_and_error; |
| 1230 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1231 | |
M. Mohan Kumar | ef56547 | 2010-06-22 19:47:50 +0530 | [diff] [blame] | 1232 | P9_DPRINTK(P9_DEBUG_9P, "<<< %s qid %x.%llx.%x iounit %x\n", |
| 1233 | p9_is_proto_dotl(clnt) ? "RLOPEN" : "ROPEN", qid.type, |
| 1234 | (unsigned long long)qid.path, qid.version, iounit); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1235 | |
| 1236 | fid->mode = mode; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1237 | fid->iounit = iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1238 | |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1239 | free_and_error: |
| 1240 | p9_free_req(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1241 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1242 | return err; |
| 1243 | } |
| 1244 | EXPORT_SYMBOL(p9_client_open); |
| 1245 | |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1246 | int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode, |
| 1247 | gid_t gid, struct p9_qid *qid) |
| 1248 | { |
| 1249 | int err = 0; |
| 1250 | struct p9_client *clnt; |
| 1251 | struct p9_req_t *req; |
| 1252 | int iounit; |
| 1253 | |
| 1254 | P9_DPRINTK(P9_DEBUG_9P, |
| 1255 | ">>> TLCREATE fid %d name %s flags %d mode %d gid %d\n", |
| 1256 | ofid->fid, name, flags, mode, gid); |
| 1257 | clnt = ofid->clnt; |
| 1258 | |
| 1259 | if (ofid->mode != -1) |
| 1260 | return -EINVAL; |
| 1261 | |
| 1262 | req = p9_client_rpc(clnt, P9_TLCREATE, "dsddd", ofid->fid, name, flags, |
| 1263 | mode, gid); |
| 1264 | if (IS_ERR(req)) { |
| 1265 | err = PTR_ERR(req); |
| 1266 | goto error; |
| 1267 | } |
| 1268 | |
| 1269 | err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", qid, &iounit); |
| 1270 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1271 | P9_DUMP_PKT(1, req->rc); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1272 | goto free_and_error; |
| 1273 | } |
| 1274 | |
| 1275 | P9_DPRINTK(P9_DEBUG_9P, "<<< RLCREATE qid %x.%llx.%x iounit %x\n", |
| 1276 | qid->type, |
| 1277 | (unsigned long long)qid->path, |
| 1278 | qid->version, iounit); |
| 1279 | |
| 1280 | ofid->mode = mode; |
| 1281 | ofid->iounit = iounit; |
| 1282 | |
| 1283 | free_and_error: |
| 1284 | p9_free_req(clnt, req); |
| 1285 | error: |
| 1286 | return err; |
| 1287 | } |
| 1288 | EXPORT_SYMBOL(p9_client_create_dotl); |
| 1289 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1290 | int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode, |
| 1291 | char *extension) |
| 1292 | { |
| 1293 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1294 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1295 | struct p9_req_t *req; |
| 1296 | struct p9_qid qid; |
| 1297 | int iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1298 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1299 | P9_DPRINTK(P9_DEBUG_9P, ">>> TCREATE fid %d name %s perm %d mode %d\n", |
| 1300 | fid->fid, name, perm, mode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1301 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1302 | clnt = fid->clnt; |
| 1303 | |
| 1304 | if (fid->mode != -1) |
| 1305 | return -EINVAL; |
| 1306 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1307 | req = p9_client_rpc(clnt, P9_TCREATE, "dsdb?s", fid->fid, name, perm, |
| 1308 | mode, extension); |
| 1309 | if (IS_ERR(req)) { |
| 1310 | err = PTR_ERR(req); |
| 1311 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1312 | } |
| 1313 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1314 | err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1315 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1316 | P9_DUMP_PKT(1, req->rc); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1317 | goto free_and_error; |
| 1318 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1319 | |
| 1320 | 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] | 1321 | qid.type, |
| 1322 | (unsigned long long)qid.path, |
| 1323 | qid.version, iounit); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1324 | |
| 1325 | fid->mode = mode; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1326 | fid->iounit = iounit; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1327 | |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1328 | free_and_error: |
| 1329 | p9_free_req(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1330 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1331 | return err; |
| 1332 | } |
| 1333 | EXPORT_SYMBOL(p9_client_fcreate); |
| 1334 | |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1335 | int p9_client_symlink(struct p9_fid *dfid, char *name, char *symtgt, gid_t gid, |
| 1336 | struct p9_qid *qid) |
| 1337 | { |
| 1338 | int err = 0; |
| 1339 | struct p9_client *clnt; |
| 1340 | struct p9_req_t *req; |
| 1341 | |
| 1342 | P9_DPRINTK(P9_DEBUG_9P, ">>> TSYMLINK dfid %d name %s symtgt %s\n", |
| 1343 | dfid->fid, name, symtgt); |
| 1344 | clnt = dfid->clnt; |
| 1345 | |
| 1346 | req = p9_client_rpc(clnt, P9_TSYMLINK, "dssd", dfid->fid, name, symtgt, |
| 1347 | gid); |
| 1348 | if (IS_ERR(req)) { |
| 1349 | err = PTR_ERR(req); |
| 1350 | goto error; |
| 1351 | } |
| 1352 | |
| 1353 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid); |
| 1354 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1355 | P9_DUMP_PKT(1, req->rc); |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1356 | goto free_and_error; |
| 1357 | } |
| 1358 | |
| 1359 | P9_DPRINTK(P9_DEBUG_9P, "<<< RSYMLINK qid %x.%llx.%x\n", |
| 1360 | qid->type, (unsigned long long)qid->path, qid->version); |
| 1361 | |
| 1362 | free_and_error: |
| 1363 | p9_free_req(clnt, req); |
| 1364 | error: |
| 1365 | return err; |
| 1366 | } |
| 1367 | EXPORT_SYMBOL(p9_client_symlink); |
| 1368 | |
Venkateswararao Jujjuri (JV) | 652df9a | 2010-06-03 15:16:59 -0700 | [diff] [blame] | 1369 | int p9_client_link(struct p9_fid *dfid, struct p9_fid *oldfid, char *newname) |
| 1370 | { |
| 1371 | struct p9_client *clnt; |
| 1372 | struct p9_req_t *req; |
| 1373 | |
| 1374 | P9_DPRINTK(P9_DEBUG_9P, ">>> TLINK dfid %d oldfid %d newname %s\n", |
| 1375 | dfid->fid, oldfid->fid, newname); |
| 1376 | clnt = dfid->clnt; |
| 1377 | req = p9_client_rpc(clnt, P9_TLINK, "dds", dfid->fid, oldfid->fid, |
| 1378 | newname); |
| 1379 | if (IS_ERR(req)) |
| 1380 | return PTR_ERR(req); |
| 1381 | |
| 1382 | P9_DPRINTK(P9_DEBUG_9P, "<<< RLINK\n"); |
| 1383 | p9_free_req(clnt, req); |
| 1384 | return 0; |
| 1385 | } |
| 1386 | EXPORT_SYMBOL(p9_client_link); |
| 1387 | |
Venkateswararao Jujjuri (JV) | b165d60 | 2010-10-22 10:13:12 -0700 | [diff] [blame] | 1388 | int p9_client_fsync(struct p9_fid *fid, int datasync) |
Venkateswararao Jujjuri (JV) | 920e65d | 2010-09-22 17:19:19 -0700 | [diff] [blame] | 1389 | { |
| 1390 | int err; |
| 1391 | struct p9_client *clnt; |
| 1392 | struct p9_req_t *req; |
| 1393 | |
Venkateswararao Jujjuri (JV) | b165d60 | 2010-10-22 10:13:12 -0700 | [diff] [blame] | 1394 | P9_DPRINTK(P9_DEBUG_9P, ">>> TFSYNC fid %d datasync:%d\n", |
| 1395 | fid->fid, datasync); |
Venkateswararao Jujjuri (JV) | 920e65d | 2010-09-22 17:19:19 -0700 | [diff] [blame] | 1396 | err = 0; |
| 1397 | clnt = fid->clnt; |
| 1398 | |
Venkateswararao Jujjuri (JV) | b165d60 | 2010-10-22 10:13:12 -0700 | [diff] [blame] | 1399 | req = p9_client_rpc(clnt, P9_TFSYNC, "dd", fid->fid, datasync); |
Venkateswararao Jujjuri (JV) | 920e65d | 2010-09-22 17:19:19 -0700 | [diff] [blame] | 1400 | if (IS_ERR(req)) { |
| 1401 | err = PTR_ERR(req); |
| 1402 | goto error; |
| 1403 | } |
| 1404 | |
| 1405 | P9_DPRINTK(P9_DEBUG_9P, "<<< RFSYNC fid %d\n", fid->fid); |
| 1406 | |
| 1407 | p9_free_req(clnt, req); |
| 1408 | |
| 1409 | error: |
| 1410 | return err; |
| 1411 | } |
| 1412 | EXPORT_SYMBOL(p9_client_fsync); |
| 1413 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1414 | int p9_client_clunk(struct p9_fid *fid) |
| 1415 | { |
| 1416 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1417 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1418 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1419 | |
jvrao | 8e44a08 | 2010-08-25 16:27:06 +0000 | [diff] [blame] | 1420 | if (!fid) { |
| 1421 | P9_EPRINTK(KERN_WARNING, "Trying to clunk with NULL fid\n"); |
| 1422 | dump_stack(); |
| 1423 | return 0; |
| 1424 | } |
| 1425 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1426 | P9_DPRINTK(P9_DEBUG_9P, ">>> TCLUNK fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1427 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1428 | clnt = fid->clnt; |
| 1429 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1430 | req = p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid); |
| 1431 | if (IS_ERR(req)) { |
| 1432 | err = PTR_ERR(req); |
| 1433 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1434 | } |
| 1435 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1436 | P9_DPRINTK(P9_DEBUG_9P, "<<< RCLUNK fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1437 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1438 | p9_free_req(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1439 | error: |
Aneesh Kumar K.V | 5034990 | 2011-07-11 16:40:58 +0000 | [diff] [blame] | 1440 | /* |
| 1441 | * Fid is not valid even after a failed clunk |
| 1442 | */ |
| 1443 | p9_fid_destroy(fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1444 | return err; |
| 1445 | } |
| 1446 | EXPORT_SYMBOL(p9_client_clunk); |
| 1447 | |
| 1448 | int p9_client_remove(struct p9_fid *fid) |
| 1449 | { |
| 1450 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1451 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1452 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1453 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1454 | P9_DPRINTK(P9_DEBUG_9P, ">>> TREMOVE fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1455 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1456 | clnt = fid->clnt; |
| 1457 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1458 | req = p9_client_rpc(clnt, P9_TREMOVE, "d", fid->fid); |
| 1459 | if (IS_ERR(req)) { |
| 1460 | err = PTR_ERR(req); |
| 1461 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1462 | } |
| 1463 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1464 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREMOVE fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1465 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1466 | p9_free_req(clnt, req); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1467 | error: |
Aneesh Kumar K.V | 0b1208b | 2010-07-02 12:21:20 +0530 | [diff] [blame] | 1468 | p9_fid_destroy(fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1469 | return err; |
| 1470 | } |
| 1471 | EXPORT_SYMBOL(p9_client_remove); |
| 1472 | |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 1473 | int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags) |
| 1474 | { |
| 1475 | int err = 0; |
| 1476 | struct p9_req_t *req; |
| 1477 | struct p9_client *clnt; |
| 1478 | |
| 1479 | P9_DPRINTK(P9_DEBUG_9P, ">>> TUNLINKAT fid %d %s %d\n", |
| 1480 | dfid->fid, name, flags); |
| 1481 | |
| 1482 | clnt = dfid->clnt; |
| 1483 | req = p9_client_rpc(clnt, P9_TUNLINKAT, "dsd", dfid->fid, name, flags); |
| 1484 | if (IS_ERR(req)) { |
| 1485 | err = PTR_ERR(req); |
| 1486 | goto error; |
| 1487 | } |
| 1488 | P9_DPRINTK(P9_DEBUG_9P, "<<< RUNLINKAT fid %d %s\n", dfid->fid, name); |
| 1489 | |
| 1490 | p9_free_req(clnt, req); |
| 1491 | error: |
| 1492 | return err; |
| 1493 | } |
| 1494 | EXPORT_SYMBOL(p9_client_unlinkat); |
| 1495 | |
Eric Van Hensbergen | 0fc9655 | 2008-10-13 20:36:17 -0500 | [diff] [blame] | 1496 | int |
| 1497 | p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, |
| 1498 | u32 count) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1499 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1500 | char *dataptr; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1501 | int kernel_buf = 0; |
| 1502 | struct p9_req_t *req; |
| 1503 | struct p9_client *clnt; |
| 1504 | int err, rsize, non_zc = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1505 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1506 | |
| 1507 | P9_DPRINTK(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n", |
| 1508 | fid->fid, (long long unsigned) offset, count); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1509 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1510 | clnt = fid->clnt; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1511 | |
| 1512 | rsize = fid->iounit; |
| 1513 | if (!rsize || rsize > clnt->msize-P9_IOHDRSZ) |
| 1514 | rsize = clnt->msize - P9_IOHDRSZ; |
| 1515 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1516 | if (count < rsize) |
| 1517 | rsize = count; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1518 | |
Rob Landley | aca0076 | 2011-05-08 18:46:38 +0000 | [diff] [blame] | 1519 | /* Don't bother zerocopy for small IO (< 1024) */ |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1520 | if (clnt->trans_mod->zc_request && rsize > 1024) { |
| 1521 | char *indata; |
| 1522 | if (data) { |
| 1523 | kernel_buf = 1; |
| 1524 | indata = data; |
| 1525 | } else |
| 1526 | indata = (char *)udata; |
| 1527 | /* |
| 1528 | * response header len is 11 |
| 1529 | * PDU Header(7) + IO Size (4) |
| 1530 | */ |
| 1531 | req = p9_client_zc_rpc(clnt, P9_TREAD, indata, NULL, rsize, 0, |
| 1532 | 11, kernel_buf, "dqd", fid->fid, |
| 1533 | offset, rsize); |
Venkateswararao Jujjuri (JV) | bb2f8a5 | 2011-01-28 17:05:59 -0800 | [diff] [blame] | 1534 | } else { |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1535 | non_zc = 1; |
Venkateswararao Jujjuri (JV) | bb2f8a5 | 2011-01-28 17:05:59 -0800 | [diff] [blame] | 1536 | req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset, |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1537 | rsize); |
Venkateswararao Jujjuri (JV) | bb2f8a5 | 2011-01-28 17:05:59 -0800 | [diff] [blame] | 1538 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1539 | if (IS_ERR(req)) { |
| 1540 | err = PTR_ERR(req); |
| 1541 | goto error; |
| 1542 | } |
| 1543 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1544 | err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1545 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1546 | P9_DUMP_PKT(1, req->rc); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1547 | goto free_and_error; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1548 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1549 | |
| 1550 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREAD count %d\n", count); |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1551 | P9_DUMP_PKT(1, req->rc); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1552 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1553 | if (non_zc) { |
Venkateswararao Jujjuri (JV) | bb2f8a5 | 2011-01-28 17:05:59 -0800 | [diff] [blame] | 1554 | if (data) { |
| 1555 | memmove(data, dataptr, count); |
| 1556 | } else { |
| 1557 | err = copy_to_user(udata, dataptr, count); |
| 1558 | if (err) { |
| 1559 | err = -EFAULT; |
| 1560 | goto free_and_error; |
| 1561 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1562 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1563 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1564 | p9_free_req(clnt, req); |
| 1565 | return count; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1566 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1567 | free_and_error: |
| 1568 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1569 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1570 | return err; |
| 1571 | } |
| 1572 | EXPORT_SYMBOL(p9_client_read); |
| 1573 | |
Eric Van Hensbergen | 0fc9655 | 2008-10-13 20:36:17 -0500 | [diff] [blame] | 1574 | int |
| 1575 | p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, |
| 1576 | u64 offset, u32 count) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1577 | { |
David S. Miller | 095d3da | 2011-04-12 15:58:41 -0700 | [diff] [blame] | 1578 | int err, rsize; |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1579 | int kernel_buf = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1580 | struct p9_client *clnt; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1581 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1582 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1583 | P9_DPRINTK(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %d\n", |
| 1584 | fid->fid, (long long unsigned) offset, count); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1585 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1586 | clnt = fid->clnt; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1587 | |
| 1588 | rsize = fid->iounit; |
| 1589 | if (!rsize || rsize > clnt->msize-P9_IOHDRSZ) |
| 1590 | rsize = clnt->msize - P9_IOHDRSZ; |
| 1591 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1592 | if (count < rsize) |
| 1593 | rsize = count; |
Venkateswararao Jujjuri (JV) | 1fc5248 | 2011-02-13 16:23:59 -0800 | [diff] [blame] | 1594 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1595 | /* Don't bother zerocopy for small IO (< 1024) */ |
| 1596 | if (clnt->trans_mod->zc_request && rsize > 1024) { |
| 1597 | char *odata; |
| 1598 | if (data) { |
| 1599 | kernel_buf = 1; |
| 1600 | odata = data; |
| 1601 | } else |
| 1602 | odata = (char *)udata; |
| 1603 | req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize, |
| 1604 | P9_ZC_HDR_SZ, kernel_buf, "dqd", |
| 1605 | fid->fid, offset, rsize); |
Venkateswararao Jujjuri (JV) | 1fc5248 | 2011-02-13 16:23:59 -0800 | [diff] [blame] | 1606 | } else { |
Venkateswararao Jujjuri (JV) | 1fc5248 | 2011-02-13 16:23:59 -0800 | [diff] [blame] | 1607 | if (data) |
| 1608 | req = p9_client_rpc(clnt, P9_TWRITE, "dqD", fid->fid, |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1609 | offset, rsize, data); |
Venkateswararao Jujjuri (JV) | 1fc5248 | 2011-02-13 16:23:59 -0800 | [diff] [blame] | 1610 | else |
| 1611 | req = p9_client_rpc(clnt, P9_TWRITE, "dqU", fid->fid, |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 1612 | offset, rsize, udata); |
Venkateswararao Jujjuri (JV) | 1fc5248 | 2011-02-13 16:23:59 -0800 | [diff] [blame] | 1613 | } |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1614 | if (IS_ERR(req)) { |
| 1615 | err = PTR_ERR(req); |
| 1616 | goto error; |
| 1617 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1618 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1619 | err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1620 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1621 | P9_DUMP_PKT(1, req->rc); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1622 | goto free_and_error; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1623 | } |
| 1624 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1625 | P9_DPRINTK(P9_DEBUG_9P, "<<< RWRITE count %d\n", count); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1626 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1627 | p9_free_req(clnt, req); |
| 1628 | return count; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1629 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1630 | free_and_error: |
| 1631 | p9_free_req(clnt, req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1632 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1633 | return err; |
| 1634 | } |
| 1635 | EXPORT_SYMBOL(p9_client_write); |
| 1636 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1637 | struct p9_wstat *p9_client_stat(struct p9_fid *fid) |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1638 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1639 | int err; |
| 1640 | struct p9_client *clnt; |
| 1641 | struct p9_wstat *ret = kmalloc(sizeof(struct p9_wstat), GFP_KERNEL); |
| 1642 | struct p9_req_t *req; |
| 1643 | u16 ignored; |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1644 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1645 | P9_DPRINTK(P9_DEBUG_9P, ">>> TSTAT fid %d\n", fid->fid); |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1646 | |
Eric Van Hensbergen | 5503ac5 | 2008-10-13 18:45:24 -0500 | [diff] [blame] | 1647 | if (!ret) |
| 1648 | return ERR_PTR(-ENOMEM); |
| 1649 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1650 | err = 0; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1651 | clnt = fid->clnt; |
| 1652 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1653 | req = p9_client_rpc(clnt, P9_TSTAT, "d", fid->fid); |
| 1654 | if (IS_ERR(req)) { |
| 1655 | err = PTR_ERR(req); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1656 | goto error; |
| 1657 | } |
| 1658 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1659 | err = p9pdu_readf(req->rc, clnt->proto_version, "wS", &ignored, ret); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1660 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1661 | P9_DUMP_PKT(1, req->rc); |
Abhishek Kulkarni | eedfe1c | 2009-07-14 13:25:41 -0500 | [diff] [blame] | 1662 | p9_free_req(clnt, req); |
| 1663 | goto error; |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1664 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1665 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1666 | P9_DPRINTK(P9_DEBUG_9P, |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1667 | "<<< RSTAT sz=%x type=%x dev=%x qid=%x.%llx.%x\n" |
| 1668 | "<<< mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n" |
| 1669 | "<<< name=%s uid=%s gid=%s muid=%s extension=(%s)\n" |
| 1670 | "<<< uid=%d gid=%d n_muid=%d\n", |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1671 | ret->size, ret->type, ret->dev, ret->qid.type, |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 1672 | (unsigned long long)ret->qid.path, ret->qid.version, ret->mode, |
| 1673 | ret->atime, ret->mtime, (unsigned long long)ret->length, |
| 1674 | ret->name, ret->uid, ret->gid, ret->muid, ret->extension, |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1675 | ret->n_uid, ret->n_gid, ret->n_muid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1676 | |
Latchesar Ionkov | 742b11a | 2009-04-05 16:26:41 -0500 | [diff] [blame] | 1677 | p9_free_req(clnt, req); |
| 1678 | return ret; |
| 1679 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1680 | error: |
Latchesar Ionkov | 742b11a | 2009-04-05 16:26:41 -0500 | [diff] [blame] | 1681 | kfree(ret); |
| 1682 | return ERR_PTR(err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1683 | } |
| 1684 | EXPORT_SYMBOL(p9_client_stat); |
| 1685 | |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1686 | struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid, |
| 1687 | u64 request_mask) |
| 1688 | { |
| 1689 | int err; |
| 1690 | struct p9_client *clnt; |
| 1691 | struct p9_stat_dotl *ret = kmalloc(sizeof(struct p9_stat_dotl), |
| 1692 | GFP_KERNEL); |
| 1693 | struct p9_req_t *req; |
| 1694 | |
| 1695 | P9_DPRINTK(P9_DEBUG_9P, ">>> TGETATTR fid %d, request_mask %lld\n", |
| 1696 | fid->fid, request_mask); |
| 1697 | |
| 1698 | if (!ret) |
| 1699 | return ERR_PTR(-ENOMEM); |
| 1700 | |
| 1701 | err = 0; |
| 1702 | clnt = fid->clnt; |
| 1703 | |
| 1704 | req = p9_client_rpc(clnt, P9_TGETATTR, "dq", fid->fid, request_mask); |
| 1705 | if (IS_ERR(req)) { |
| 1706 | err = PTR_ERR(req); |
| 1707 | goto error; |
| 1708 | } |
| 1709 | |
| 1710 | err = p9pdu_readf(req->rc, clnt->proto_version, "A", ret); |
| 1711 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1712 | P9_DUMP_PKT(1, req->rc); |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1713 | p9_free_req(clnt, req); |
| 1714 | goto error; |
| 1715 | } |
| 1716 | |
| 1717 | P9_DPRINTK(P9_DEBUG_9P, |
| 1718 | "<<< RGETATTR st_result_mask=%lld\n" |
| 1719 | "<<< qid=%x.%llx.%x\n" |
| 1720 | "<<< st_mode=%8.8x st_nlink=%llu\n" |
| 1721 | "<<< st_uid=%d st_gid=%d\n" |
| 1722 | "<<< st_rdev=%llx st_size=%llx st_blksize=%llu st_blocks=%llu\n" |
| 1723 | "<<< st_atime_sec=%lld st_atime_nsec=%lld\n" |
| 1724 | "<<< st_mtime_sec=%lld st_mtime_nsec=%lld\n" |
| 1725 | "<<< st_ctime_sec=%lld st_ctime_nsec=%lld\n" |
| 1726 | "<<< st_btime_sec=%lld st_btime_nsec=%lld\n" |
| 1727 | "<<< st_gen=%lld st_data_version=%lld", |
| 1728 | ret->st_result_mask, ret->qid.type, ret->qid.path, |
| 1729 | ret->qid.version, ret->st_mode, ret->st_nlink, ret->st_uid, |
| 1730 | ret->st_gid, ret->st_rdev, ret->st_size, ret->st_blksize, |
| 1731 | ret->st_blocks, ret->st_atime_sec, ret->st_atime_nsec, |
| 1732 | ret->st_mtime_sec, ret->st_mtime_nsec, ret->st_ctime_sec, |
| 1733 | ret->st_ctime_nsec, ret->st_btime_sec, ret->st_btime_nsec, |
| 1734 | ret->st_gen, ret->st_data_version); |
| 1735 | |
| 1736 | p9_free_req(clnt, req); |
| 1737 | return ret; |
| 1738 | |
| 1739 | error: |
| 1740 | kfree(ret); |
| 1741 | return ERR_PTR(err); |
| 1742 | } |
| 1743 | EXPORT_SYMBOL(p9_client_getattr_dotl); |
| 1744 | |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1745 | static int p9_client_statsize(struct p9_wstat *wst, int proto_version) |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1746 | { |
| 1747 | int ret; |
| 1748 | |
Eric Van Hensbergen | 9d6939d | 2010-01-15 19:01:56 -0600 | [diff] [blame] | 1749 | /* NOTE: size shouldn't include its own length */ |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1750 | /* size[2] type[2] dev[4] qid[13] */ |
| 1751 | /* mode[4] atime[4] mtime[4] length[8]*/ |
| 1752 | /* name[s] uid[s] gid[s] muid[s] */ |
Eric Van Hensbergen | 9d6939d | 2010-01-15 19:01:56 -0600 | [diff] [blame] | 1753 | ret = 2+4+13+4+4+4+8+2+2+2+2; |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1754 | |
| 1755 | if (wst->name) |
| 1756 | ret += strlen(wst->name); |
| 1757 | if (wst->uid) |
| 1758 | ret += strlen(wst->uid); |
| 1759 | if (wst->gid) |
| 1760 | ret += strlen(wst->gid); |
| 1761 | if (wst->muid) |
| 1762 | ret += strlen(wst->muid); |
| 1763 | |
Sripathi Kodi | c56e4ac | 2010-03-25 12:40:35 +0000 | [diff] [blame] | 1764 | if ((proto_version == p9_proto_2000u) || |
| 1765 | (proto_version == p9_proto_2000L)) { |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1766 | ret += 2+4+4+4; /* extension[s] n_uid[4] n_gid[4] n_muid[4] */ |
| 1767 | if (wst->extension) |
| 1768 | ret += strlen(wst->extension); |
| 1769 | } |
| 1770 | |
| 1771 | return ret; |
| 1772 | } |
| 1773 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1774 | int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst) |
| 1775 | { |
| 1776 | int err; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1777 | struct p9_req_t *req; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1778 | struct p9_client *clnt; |
| 1779 | |
Latchesar Ionkov | 453ed90 | 2009-04-05 16:22:16 -0500 | [diff] [blame] | 1780 | err = 0; |
| 1781 | clnt = fid->clnt; |
Sripathi Kodi | 342fee1 | 2010-03-05 18:50:14 +0000 | [diff] [blame] | 1782 | wst->size = p9_client_statsize(wst, clnt->proto_version); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1783 | P9_DPRINTK(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", fid->fid); |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1784 | P9_DPRINTK(P9_DEBUG_9P, |
| 1785 | " sz=%x type=%x dev=%x qid=%x.%llx.%x\n" |
| 1786 | " mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n" |
| 1787 | " name=%s uid=%s gid=%s muid=%s extension=(%s)\n" |
| 1788 | " uid=%d gid=%d n_muid=%d\n", |
| 1789 | wst->size, wst->type, wst->dev, wst->qid.type, |
Randy Dunlap | b0d5fde | 2008-11-04 20:46:46 -0800 | [diff] [blame] | 1790 | (unsigned long long)wst->qid.path, wst->qid.version, wst->mode, |
| 1791 | wst->atime, wst->mtime, (unsigned long long)wst->length, |
| 1792 | wst->name, wst->uid, wst->gid, wst->muid, wst->extension, |
Eric Van Hensbergen | e7f4b8f | 2008-10-17 16:20:07 -0500 | [diff] [blame] | 1793 | wst->n_uid, wst->n_gid, wst->n_muid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1794 | |
Eric Van Hensbergen | 9d6939d | 2010-01-15 19:01:56 -0600 | [diff] [blame] | 1795 | 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] | 1796 | if (IS_ERR(req)) { |
| 1797 | err = PTR_ERR(req); |
| 1798 | goto error; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1799 | } |
| 1800 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1801 | P9_DPRINTK(P9_DEBUG_9P, "<<< RWSTAT fid %d\n", fid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1802 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1803 | p9_free_req(clnt, req); |
| 1804 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1805 | return err; |
| 1806 | } |
| 1807 | EXPORT_SYMBOL(p9_client_wstat); |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1808 | |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1809 | int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *p9attr) |
| 1810 | { |
| 1811 | int err; |
| 1812 | struct p9_req_t *req; |
| 1813 | struct p9_client *clnt; |
| 1814 | |
| 1815 | err = 0; |
| 1816 | clnt = fid->clnt; |
| 1817 | P9_DPRINTK(P9_DEBUG_9P, ">>> TSETATTR fid %d\n", fid->fid); |
| 1818 | P9_DPRINTK(P9_DEBUG_9P, |
| 1819 | " valid=%x mode=%x uid=%d gid=%d size=%lld\n" |
| 1820 | " atime_sec=%lld atime_nsec=%lld\n" |
| 1821 | " mtime_sec=%lld mtime_nsec=%lld\n", |
| 1822 | p9attr->valid, p9attr->mode, p9attr->uid, p9attr->gid, |
| 1823 | p9attr->size, p9attr->atime_sec, p9attr->atime_nsec, |
| 1824 | p9attr->mtime_sec, p9attr->mtime_nsec); |
| 1825 | |
| 1826 | req = p9_client_rpc(clnt, P9_TSETATTR, "dI", fid->fid, p9attr); |
| 1827 | |
| 1828 | if (IS_ERR(req)) { |
| 1829 | err = PTR_ERR(req); |
| 1830 | goto error; |
| 1831 | } |
| 1832 | P9_DPRINTK(P9_DEBUG_9P, "<<< RSETATTR fid %d\n", fid->fid); |
| 1833 | p9_free_req(clnt, req); |
| 1834 | error: |
| 1835 | return err; |
| 1836 | } |
| 1837 | EXPORT_SYMBOL(p9_client_setattr); |
| 1838 | |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1839 | int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb) |
| 1840 | { |
| 1841 | int err; |
| 1842 | struct p9_req_t *req; |
| 1843 | struct p9_client *clnt; |
| 1844 | |
| 1845 | err = 0; |
| 1846 | clnt = fid->clnt; |
| 1847 | |
| 1848 | P9_DPRINTK(P9_DEBUG_9P, ">>> TSTATFS fid %d\n", fid->fid); |
| 1849 | |
| 1850 | req = p9_client_rpc(clnt, P9_TSTATFS, "d", fid->fid); |
| 1851 | if (IS_ERR(req)) { |
| 1852 | err = PTR_ERR(req); |
| 1853 | goto error; |
| 1854 | } |
| 1855 | |
| 1856 | err = p9pdu_readf(req->rc, clnt->proto_version, "ddqqqqqqd", &sb->type, |
| 1857 | &sb->bsize, &sb->blocks, &sb->bfree, &sb->bavail, |
| 1858 | &sb->files, &sb->ffree, &sb->fsid, &sb->namelen); |
| 1859 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1860 | P9_DUMP_PKT(1, req->rc); |
Sripathi Kodi | bda8e77 | 2010-03-25 12:45:30 +0000 | [diff] [blame] | 1861 | p9_free_req(clnt, req); |
| 1862 | goto error; |
| 1863 | } |
| 1864 | |
| 1865 | P9_DPRINTK(P9_DEBUG_9P, "<<< RSTATFS fid %d type 0x%lx bsize %ld " |
| 1866 | "blocks %llu bfree %llu bavail %llu files %llu ffree %llu " |
| 1867 | "fsid %llu namelen %ld\n", |
| 1868 | fid->fid, (long unsigned int)sb->type, (long int)sb->bsize, |
| 1869 | sb->blocks, sb->bfree, sb->bavail, sb->files, sb->ffree, |
| 1870 | sb->fsid, (long int)sb->namelen); |
| 1871 | |
| 1872 | p9_free_req(clnt, req); |
| 1873 | error: |
| 1874 | return err; |
| 1875 | } |
| 1876 | EXPORT_SYMBOL(p9_client_statfs); |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1877 | |
Aneesh Kumar K.V | 9e8fb38 | 2011-06-28 15:41:16 +0530 | [diff] [blame] | 1878 | int p9_client_rename(struct p9_fid *fid, |
| 1879 | struct p9_fid *newdirfid, const char *name) |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1880 | { |
| 1881 | int err; |
| 1882 | struct p9_req_t *req; |
| 1883 | struct p9_client *clnt; |
| 1884 | |
| 1885 | err = 0; |
| 1886 | clnt = fid->clnt; |
| 1887 | |
| 1888 | P9_DPRINTK(P9_DEBUG_9P, ">>> TRENAME fid %d newdirfid %d name %s\n", |
| 1889 | fid->fid, newdirfid->fid, name); |
| 1890 | |
| 1891 | req = p9_client_rpc(clnt, P9_TRENAME, "dds", fid->fid, |
| 1892 | newdirfid->fid, name); |
| 1893 | if (IS_ERR(req)) { |
| 1894 | err = PTR_ERR(req); |
| 1895 | goto error; |
| 1896 | } |
| 1897 | |
| 1898 | P9_DPRINTK(P9_DEBUG_9P, "<<< RRENAME fid %d\n", fid->fid); |
| 1899 | |
| 1900 | p9_free_req(clnt, req); |
| 1901 | error: |
| 1902 | return err; |
| 1903 | } |
| 1904 | EXPORT_SYMBOL(p9_client_rename); |
| 1905 | |
Aneesh Kumar K.V | 9e8fb38 | 2011-06-28 15:41:16 +0530 | [diff] [blame] | 1906 | int p9_client_renameat(struct p9_fid *olddirfid, const char *old_name, |
| 1907 | struct p9_fid *newdirfid, const char *new_name) |
| 1908 | { |
| 1909 | int err; |
| 1910 | struct p9_req_t *req; |
| 1911 | struct p9_client *clnt; |
| 1912 | |
| 1913 | err = 0; |
| 1914 | clnt = olddirfid->clnt; |
| 1915 | |
| 1916 | P9_DPRINTK(P9_DEBUG_9P, ">>> TRENAMEAT olddirfid %d old name %s" |
| 1917 | " newdirfid %d new name %s\n", olddirfid->fid, old_name, |
| 1918 | newdirfid->fid, new_name); |
| 1919 | |
| 1920 | req = p9_client_rpc(clnt, P9_TRENAMEAT, "dsds", olddirfid->fid, |
| 1921 | old_name, newdirfid->fid, new_name); |
| 1922 | if (IS_ERR(req)) { |
| 1923 | err = PTR_ERR(req); |
| 1924 | goto error; |
| 1925 | } |
| 1926 | |
| 1927 | P9_DPRINTK(P9_DEBUG_9P, "<<< RRENAMEAT newdirfid %d new name %s\n", |
| 1928 | newdirfid->fid, new_name); |
| 1929 | |
| 1930 | p9_free_req(clnt, req); |
| 1931 | error: |
| 1932 | return err; |
| 1933 | } |
| 1934 | EXPORT_SYMBOL(p9_client_renameat); |
| 1935 | |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 1936 | /* |
| 1937 | * An xattrwalk without @attr_name gives the fid for the lisxattr namespace |
| 1938 | */ |
| 1939 | struct p9_fid *p9_client_xattrwalk(struct p9_fid *file_fid, |
| 1940 | const char *attr_name, u64 *attr_size) |
| 1941 | { |
| 1942 | int err; |
| 1943 | struct p9_req_t *req; |
| 1944 | struct p9_client *clnt; |
| 1945 | struct p9_fid *attr_fid; |
| 1946 | |
| 1947 | err = 0; |
| 1948 | clnt = file_fid->clnt; |
| 1949 | attr_fid = p9_fid_create(clnt); |
| 1950 | if (IS_ERR(attr_fid)) { |
| 1951 | err = PTR_ERR(attr_fid); |
| 1952 | attr_fid = NULL; |
| 1953 | goto error; |
| 1954 | } |
| 1955 | P9_DPRINTK(P9_DEBUG_9P, |
| 1956 | ">>> TXATTRWALK file_fid %d, attr_fid %d name %s\n", |
| 1957 | file_fid->fid, attr_fid->fid, attr_name); |
| 1958 | |
| 1959 | req = p9_client_rpc(clnt, P9_TXATTRWALK, "dds", |
| 1960 | file_fid->fid, attr_fid->fid, attr_name); |
| 1961 | if (IS_ERR(req)) { |
| 1962 | err = PTR_ERR(req); |
| 1963 | goto error; |
| 1964 | } |
| 1965 | err = p9pdu_readf(req->rc, clnt->proto_version, "q", attr_size); |
| 1966 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 1967 | P9_DUMP_PKT(1, req->rc); |
Aneesh Kumar K.V | 0ef63f3 | 2010-05-31 13:22:45 +0530 | [diff] [blame] | 1968 | p9_free_req(clnt, req); |
| 1969 | goto clunk_fid; |
| 1970 | } |
| 1971 | p9_free_req(clnt, req); |
| 1972 | P9_DPRINTK(P9_DEBUG_9P, "<<< RXATTRWALK fid %d size %llu\n", |
| 1973 | attr_fid->fid, *attr_size); |
| 1974 | return attr_fid; |
| 1975 | clunk_fid: |
| 1976 | p9_client_clunk(attr_fid); |
| 1977 | attr_fid = NULL; |
| 1978 | error: |
| 1979 | if (attr_fid && (attr_fid != file_fid)) |
| 1980 | p9_fid_destroy(attr_fid); |
| 1981 | |
| 1982 | return ERR_PTR(err); |
| 1983 | } |
| 1984 | EXPORT_SYMBOL_GPL(p9_client_xattrwalk); |
| 1985 | |
Aneesh Kumar K.V | eda25e46 | 2010-05-31 13:22:50 +0530 | [diff] [blame] | 1986 | int p9_client_xattrcreate(struct p9_fid *fid, const char *name, |
| 1987 | u64 attr_size, int flags) |
| 1988 | { |
| 1989 | int err; |
| 1990 | struct p9_req_t *req; |
| 1991 | struct p9_client *clnt; |
| 1992 | |
| 1993 | P9_DPRINTK(P9_DEBUG_9P, |
| 1994 | ">>> TXATTRCREATE fid %d name %s size %lld flag %d\n", |
| 1995 | fid->fid, name, (long long)attr_size, flags); |
| 1996 | err = 0; |
| 1997 | clnt = fid->clnt; |
| 1998 | req = p9_client_rpc(clnt, P9_TXATTRCREATE, "dsqd", |
| 1999 | fid->fid, name, attr_size, flags); |
| 2000 | if (IS_ERR(req)) { |
| 2001 | err = PTR_ERR(req); |
| 2002 | goto error; |
| 2003 | } |
| 2004 | P9_DPRINTK(P9_DEBUG_9P, "<<< RXATTRCREATE fid %d\n", fid->fid); |
| 2005 | p9_free_req(clnt, req); |
| 2006 | error: |
| 2007 | return err; |
| 2008 | } |
| 2009 | EXPORT_SYMBOL_GPL(p9_client_xattrcreate); |
| 2010 | |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2011 | int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset) |
| 2012 | { |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 2013 | int err, rsize, non_zc = 0; |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2014 | struct p9_client *clnt; |
| 2015 | struct p9_req_t *req; |
| 2016 | char *dataptr; |
| 2017 | |
| 2018 | P9_DPRINTK(P9_DEBUG_9P, ">>> TREADDIR fid %d offset %llu count %d\n", |
| 2019 | fid->fid, (long long unsigned) offset, count); |
| 2020 | |
| 2021 | err = 0; |
| 2022 | clnt = fid->clnt; |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2023 | |
| 2024 | rsize = fid->iounit; |
| 2025 | if (!rsize || rsize > clnt->msize-P9_READDIRHDRSZ) |
| 2026 | rsize = clnt->msize - P9_READDIRHDRSZ; |
| 2027 | |
| 2028 | if (count < rsize) |
| 2029 | rsize = count; |
| 2030 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 2031 | /* Don't bother zerocopy for small IO (< 1024) */ |
| 2032 | if (clnt->trans_mod->zc_request && rsize > 1024) { |
| 2033 | /* |
| 2034 | * response header len is 11 |
| 2035 | * PDU Header(7) + IO Size (4) |
| 2036 | */ |
| 2037 | req = p9_client_zc_rpc(clnt, P9_TREADDIR, data, NULL, rsize, 0, |
| 2038 | 11, 1, "dqd", fid->fid, offset, rsize); |
Venkateswararao Jujjuri (JV) | 2c66523 | 2011-02-16 18:43:20 -0800 | [diff] [blame] | 2039 | } else { |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 2040 | non_zc = 1; |
Venkateswararao Jujjuri (JV) | 2c66523 | 2011-02-16 18:43:20 -0800 | [diff] [blame] | 2041 | req = p9_client_rpc(clnt, P9_TREADDIR, "dqd", fid->fid, |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 2042 | offset, rsize); |
Venkateswararao Jujjuri (JV) | 2c66523 | 2011-02-16 18:43:20 -0800 | [diff] [blame] | 2043 | } |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2044 | if (IS_ERR(req)) { |
| 2045 | err = PTR_ERR(req); |
| 2046 | goto error; |
| 2047 | } |
| 2048 | |
| 2049 | err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr); |
| 2050 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 2051 | P9_DUMP_PKT(1, req->rc); |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2052 | goto free_and_error; |
| 2053 | } |
| 2054 | |
| 2055 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREADDIR count %d\n", count); |
| 2056 | |
Aneesh Kumar K.V | abfa034 | 2011-08-16 10:50:10 +0530 | [diff] [blame^] | 2057 | if (non_zc) |
Sripathi Kodi | 7751bdb | 2010-06-04 13:41:26 +0000 | [diff] [blame] | 2058 | memmove(data, dataptr, count); |
| 2059 | |
| 2060 | p9_free_req(clnt, req); |
| 2061 | return count; |
| 2062 | |
| 2063 | free_and_error: |
| 2064 | p9_free_req(clnt, req); |
| 2065 | error: |
| 2066 | return err; |
| 2067 | } |
| 2068 | EXPORT_SYMBOL(p9_client_readdir); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2069 | |
| 2070 | int p9_client_mknod_dotl(struct p9_fid *fid, char *name, int mode, |
| 2071 | dev_t rdev, gid_t gid, struct p9_qid *qid) |
| 2072 | { |
| 2073 | int err; |
| 2074 | struct p9_client *clnt; |
| 2075 | struct p9_req_t *req; |
| 2076 | |
| 2077 | err = 0; |
| 2078 | clnt = fid->clnt; |
| 2079 | P9_DPRINTK(P9_DEBUG_9P, ">>> TMKNOD fid %d name %s mode %d major %d " |
| 2080 | "minor %d\n", fid->fid, name, mode, MAJOR(rdev), MINOR(rdev)); |
| 2081 | req = p9_client_rpc(clnt, P9_TMKNOD, "dsdddd", fid->fid, name, mode, |
| 2082 | MAJOR(rdev), MINOR(rdev), gid); |
| 2083 | if (IS_ERR(req)) |
| 2084 | return PTR_ERR(req); |
| 2085 | |
| 2086 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid); |
| 2087 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 2088 | P9_DUMP_PKT(1, req->rc); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2089 | goto error; |
| 2090 | } |
| 2091 | P9_DPRINTK(P9_DEBUG_9P, "<<< RMKNOD qid %x.%llx.%x\n", qid->type, |
| 2092 | (unsigned long long)qid->path, qid->version); |
| 2093 | |
| 2094 | error: |
| 2095 | p9_free_req(clnt, req); |
| 2096 | return err; |
| 2097 | |
| 2098 | } |
| 2099 | EXPORT_SYMBOL(p9_client_mknod_dotl); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2100 | |
| 2101 | int p9_client_mkdir_dotl(struct p9_fid *fid, char *name, int mode, |
| 2102 | gid_t gid, struct p9_qid *qid) |
| 2103 | { |
| 2104 | int err; |
| 2105 | struct p9_client *clnt; |
| 2106 | struct p9_req_t *req; |
| 2107 | |
| 2108 | err = 0; |
| 2109 | clnt = fid->clnt; |
| 2110 | P9_DPRINTK(P9_DEBUG_9P, ">>> TMKDIR fid %d name %s mode %d gid %d\n", |
| 2111 | fid->fid, name, mode, gid); |
| 2112 | req = p9_client_rpc(clnt, P9_TMKDIR, "dsdd", fid->fid, name, mode, |
| 2113 | gid); |
| 2114 | if (IS_ERR(req)) |
| 2115 | return PTR_ERR(req); |
| 2116 | |
| 2117 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid); |
| 2118 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 2119 | P9_DUMP_PKT(1, req->rc); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2120 | goto error; |
| 2121 | } |
| 2122 | P9_DPRINTK(P9_DEBUG_9P, "<<< RMKDIR qid %x.%llx.%x\n", qid->type, |
| 2123 | (unsigned long long)qid->path, qid->version); |
| 2124 | |
| 2125 | error: |
| 2126 | p9_free_req(clnt, req); |
| 2127 | return err; |
| 2128 | |
| 2129 | } |
| 2130 | EXPORT_SYMBOL(p9_client_mkdir_dotl); |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2131 | |
| 2132 | int p9_client_lock_dotl(struct p9_fid *fid, struct p9_flock *flock, u8 *status) |
| 2133 | { |
| 2134 | int err; |
| 2135 | struct p9_client *clnt; |
| 2136 | struct p9_req_t *req; |
| 2137 | |
| 2138 | err = 0; |
| 2139 | clnt = fid->clnt; |
| 2140 | P9_DPRINTK(P9_DEBUG_9P, ">>> TLOCK fid %d type %i flags %d " |
| 2141 | "start %lld length %lld proc_id %d client_id %s\n", |
| 2142 | fid->fid, flock->type, flock->flags, flock->start, |
| 2143 | flock->length, flock->proc_id, flock->client_id); |
| 2144 | |
| 2145 | req = p9_client_rpc(clnt, P9_TLOCK, "dbdqqds", fid->fid, flock->type, |
| 2146 | flock->flags, flock->start, flock->length, |
| 2147 | flock->proc_id, flock->client_id); |
| 2148 | |
| 2149 | if (IS_ERR(req)) |
| 2150 | return PTR_ERR(req); |
| 2151 | |
| 2152 | err = p9pdu_readf(req->rc, clnt->proto_version, "b", status); |
| 2153 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 2154 | P9_DUMP_PKT(1, req->rc); |
M. Mohan Kumar | a099027 | 2010-09-27 11:34:24 +0530 | [diff] [blame] | 2155 | goto error; |
| 2156 | } |
| 2157 | P9_DPRINTK(P9_DEBUG_9P, "<<< RLOCK status %i\n", *status); |
| 2158 | error: |
| 2159 | p9_free_req(clnt, req); |
| 2160 | return err; |
| 2161 | |
| 2162 | } |
| 2163 | EXPORT_SYMBOL(p9_client_lock_dotl); |
M. Mohan Kumar | 1d769cd | 2010-09-27 12:22:13 +0530 | [diff] [blame] | 2164 | |
| 2165 | int p9_client_getlock_dotl(struct p9_fid *fid, struct p9_getlock *glock) |
| 2166 | { |
| 2167 | int err; |
| 2168 | struct p9_client *clnt; |
| 2169 | struct p9_req_t *req; |
| 2170 | |
| 2171 | err = 0; |
| 2172 | clnt = fid->clnt; |
| 2173 | P9_DPRINTK(P9_DEBUG_9P, ">>> TGETLOCK fid %d, type %i start %lld " |
| 2174 | "length %lld proc_id %d client_id %s\n", fid->fid, glock->type, |
| 2175 | glock->start, glock->length, glock->proc_id, glock->client_id); |
| 2176 | |
| 2177 | req = p9_client_rpc(clnt, P9_TGETLOCK, "dbqqds", fid->fid, glock->type, |
| 2178 | glock->start, glock->length, glock->proc_id, glock->client_id); |
| 2179 | |
| 2180 | if (IS_ERR(req)) |
| 2181 | return PTR_ERR(req); |
| 2182 | |
| 2183 | err = p9pdu_readf(req->rc, clnt->proto_version, "bqqds", &glock->type, |
| 2184 | &glock->start, &glock->length, &glock->proc_id, |
| 2185 | &glock->client_id); |
| 2186 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 2187 | P9_DUMP_PKT(1, req->rc); |
M. Mohan Kumar | 1d769cd | 2010-09-27 12:22:13 +0530 | [diff] [blame] | 2188 | goto error; |
| 2189 | } |
| 2190 | P9_DPRINTK(P9_DEBUG_9P, "<<< RGETLOCK type %i start %lld length %lld " |
| 2191 | "proc_id %d client_id %s\n", glock->type, glock->start, |
| 2192 | glock->length, glock->proc_id, glock->client_id); |
| 2193 | error: |
| 2194 | p9_free_req(clnt, req); |
| 2195 | return err; |
| 2196 | } |
| 2197 | EXPORT_SYMBOL(p9_client_getlock_dotl); |
M. Mohan Kumar | 329176cc | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2198 | |
| 2199 | int p9_client_readlink(struct p9_fid *fid, char **target) |
| 2200 | { |
| 2201 | int err; |
| 2202 | struct p9_client *clnt; |
| 2203 | struct p9_req_t *req; |
| 2204 | |
| 2205 | err = 0; |
| 2206 | clnt = fid->clnt; |
| 2207 | P9_DPRINTK(P9_DEBUG_9P, ">>> TREADLINK fid %d\n", fid->fid); |
| 2208 | |
| 2209 | req = p9_client_rpc(clnt, P9_TREADLINK, "d", fid->fid); |
| 2210 | if (IS_ERR(req)) |
| 2211 | return PTR_ERR(req); |
| 2212 | |
| 2213 | err = p9pdu_readf(req->rc, clnt->proto_version, "s", target); |
| 2214 | if (err) { |
Eric Van Hensbergen | e660a82 | 2011-06-19 16:38:21 -0500 | [diff] [blame] | 2215 | P9_DUMP_PKT(1, req->rc); |
M. Mohan Kumar | 329176cc | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2216 | goto error; |
| 2217 | } |
| 2218 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREADLINK target %s\n", *target); |
| 2219 | error: |
| 2220 | p9_free_req(clnt, req); |
| 2221 | return err; |
| 2222 | } |
| 2223 | EXPORT_SYMBOL(p9_client_readlink); |