6 * Copyright (C) 2008 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
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.
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.
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
26 #include <linux/module.h>
27 #include <linux/errno.h>
29 #include <linux/poll.h>
30 #include <linux/idr.h>
31 #include <linux/mutex.h>
32 #include <linux/sched.h>
33 #include <linux/uaccess.h>
34 #include <net/9p/9p.h>
35 #include <linux/parser.h>
36 #include <net/9p/client.h>
37 #include <net/9p/transport.h>
41 * Client Option Parsing (code inspired by NFS code)
42 * - a little lazy - parse all client options
52 static const match_table_t tokens = {
53 {Opt_msize, "msize=%u"},
54 {Opt_legacy, "noextend"},
55 {Opt_trans, "trans=%s"},
59 static struct p9_req_t *
60 p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...);
63 * v9fs_parse_options - parse mount options into session structure
64 * @options: options string passed from mount
65 * @v9ses: existing v9fs session information
67 * Return 0 upon success, -ERRNO upon failure
70 static int parse_opts(char *opts, struct p9_client *clnt)
74 substring_t args[MAX_OPT_ARGS];
84 options = kstrdup(opts, GFP_KERNEL);
86 P9_DPRINTK(P9_DEBUG_ERROR,
87 "failed to allocate copy of option string\n");
91 while ((p = strsep(&options, ",")) != NULL) {
95 token = match_token(p, tokens, args);
96 if (token < Opt_trans) {
97 int r = match_int(&args[0], &option);
99 P9_DPRINTK(P9_DEBUG_ERROR,
100 "integer field, but no integer?\n");
107 clnt->msize = option;
110 clnt->trans_mod = v9fs_get_trans_by_name(&args[0]);
120 if (!clnt->trans_mod)
121 clnt->trans_mod = v9fs_get_default_trans();
128 * p9_tag_alloc - lookup/allocate a request by tag
129 * @c: client session to lookup tag within
130 * @tag: numeric id for transaction
132 * this is a simple array lookup, but will grow the
133 * request_slots as necessary to accomodate transaction
134 * ids which did not previously have a slot.
136 * this code relies on the client spinlock to manage locks, its
137 * possible we should switch to something else, but I'd rather
138 * stick with something low-overhead for the common case.
142 static struct p9_req_t *p9_tag_alloc(struct p9_client *c, u16 tag)
146 struct p9_req_t *req;
148 /* This looks up the original request by tag so we know which
149 * buffer to read the data into */
152 if (tag >= c->max_tag) {
153 spin_lock_irqsave(&c->lock, flags);
154 /* check again since original check was outside of lock */
155 while (tag >= c->max_tag) {
156 row = (tag / P9_ROW_MAXTAG);
157 c->reqs[row] = kcalloc(P9_ROW_MAXTAG,
158 sizeof(struct p9_req_t), GFP_ATOMIC);
161 printk(KERN_ERR "Couldn't grow tag array\n");
162 return ERR_PTR(-ENOMEM);
164 for (col = 0; col < P9_ROW_MAXTAG; col++) {
165 c->reqs[row][col].status = REQ_STATUS_IDLE;
166 c->reqs[row][col].tc = NULL;
168 c->max_tag += P9_ROW_MAXTAG;
170 spin_unlock_irqrestore(&c->lock, flags);
172 row = tag / P9_ROW_MAXTAG;
173 col = tag % P9_ROW_MAXTAG;
175 req = &c->reqs[row][col];
177 req->wq = kmalloc(sizeof(wait_queue_head_t), GFP_KERNEL);
179 printk(KERN_ERR "Couldn't grow tag array\n");
180 return ERR_PTR(-ENOMEM);
182 init_waitqueue_head(req->wq);
183 req->tc = kmalloc(sizeof(struct p9_fcall)+c->msize,
185 req->rc = kmalloc(sizeof(struct p9_fcall)+c->msize,
187 if ((!req->tc) || (!req->rc)) {
188 printk(KERN_ERR "Couldn't grow tag array\n");
191 return ERR_PTR(-ENOMEM);
193 req->tc->sdata = (char *) req->tc + sizeof(struct p9_fcall);
194 req->tc->capacity = c->msize;
195 req->rc->sdata = (char *) req->rc + sizeof(struct p9_fcall);
196 req->rc->capacity = c->msize;
199 p9pdu_reset(req->tc);
200 p9pdu_reset(req->rc);
203 req->tc->tag = tag-1;
204 req->status = REQ_STATUS_ALLOC;
206 return &c->reqs[row][col];
210 * p9_tag_lookup - lookup a request by tag
211 * @c: client session to lookup tag within
212 * @tag: numeric id for transaction
216 struct p9_req_t *p9_tag_lookup(struct p9_client *c, u16 tag)
220 /* This looks up the original request by tag so we know which
221 * buffer to read the data into */
224 BUG_ON(tag >= c->max_tag);
226 row = tag / P9_ROW_MAXTAG;
227 col = tag % P9_ROW_MAXTAG;
229 return &c->reqs[row][col];
231 EXPORT_SYMBOL(p9_tag_lookup);
234 * p9_tag_init - setup tags structure and contents
235 * @tags: tags structure from the client struct
237 * This initializes the tags structure for each client instance.
241 static int p9_tag_init(struct p9_client *c)
245 c->tagpool = p9_idpool_create();
246 if (IS_ERR(c->tagpool)) {
247 err = PTR_ERR(c->tagpool);
252 p9_idpool_get(c->tagpool); /* reserve tag 0 */
260 * p9_tag_cleanup - cleans up tags structure and reclaims resources
261 * @tags: tags structure from the client struct
263 * This frees resources associated with the tags structure
266 static void p9_tag_cleanup(struct p9_client *c)
270 /* check to insure all requests are idle */
271 for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) {
272 for (col = 0; col < P9_ROW_MAXTAG; col++) {
273 if (c->reqs[row][col].status != REQ_STATUS_IDLE) {
274 P9_DPRINTK(P9_DEBUG_MUX,
275 "Attempting to cleanup non-free tag %d,%d\n",
277 /* TODO: delay execution of cleanup */
284 p9_idpool_destroy(c->tagpool);
286 /* free requests associated with tags */
287 for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) {
288 for (col = 0; col < P9_ROW_MAXTAG; col++) {
289 kfree(c->reqs[row][col].wq);
290 kfree(c->reqs[row][col].tc);
291 kfree(c->reqs[row][col].rc);
299 * p9_free_req - free a request and clean-up as necessary
301 * r: request to release
305 static void p9_free_req(struct p9_client *c, struct p9_req_t *r)
307 int tag = r->tc->tag;
308 P9_DPRINTK(P9_DEBUG_MUX, "clnt %p req %p tag: %d\n", c, r, tag);
310 r->status = REQ_STATUS_IDLE;
311 if (tag != P9_NOTAG && p9_idpool_check(tag, c->tagpool))
312 p9_idpool_put(tag, c->tagpool);
314 /* if this was a flush request we have to free response fcall */
315 if (r->rc->id == P9_RFLUSH) {
322 * p9_client_cb - call back from transport to client
324 * req: request received
327 void p9_client_cb(struct p9_client *c, struct p9_req_t *req)
329 struct p9_req_t *other_req;
332 P9_DPRINTK(P9_DEBUG_MUX, " tag %d\n", req->tc->tag);
334 if (req->status == REQ_STATUS_ERROR)
337 if (req->flush_tag) { /* flush receive path */
338 P9_DPRINTK(P9_DEBUG_9P, "<<< RFLUSH %d\n", req->tc->tag);
339 spin_lock_irqsave(&c->lock, flags);
340 other_req = p9_tag_lookup(c, req->flush_tag);
341 if (other_req->status != REQ_STATUS_FLSH) /* stale flush */
342 spin_unlock_irqrestore(&c->lock, flags);
344 other_req->status = REQ_STATUS_FLSHD;
345 spin_unlock_irqrestore(&c->lock, flags);
346 wake_up(other_req->wq);
349 } else { /* normal receive path */
350 P9_DPRINTK(P9_DEBUG_MUX, "normal: tag %d\n", req->tc->tag);
351 spin_lock_irqsave(&c->lock, flags);
352 if (req->status != REQ_STATUS_FLSHD)
353 req->status = REQ_STATUS_RCVD;
354 spin_unlock_irqrestore(&c->lock, flags);
356 P9_DPRINTK(P9_DEBUG_MUX, "wakeup: %d\n", req->tc->tag);
359 EXPORT_SYMBOL(p9_client_cb);
362 * p9_parse_header - parse header arguments out of a packet
363 * @pdu: packet to parse
364 * @size: size of packet
365 * @type: type of request
366 * @tag: tag of packet
367 * @rewind: set if we need to rewind offset afterwards
371 p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, int16_t *tag,
377 int offset = pdu->offset;
384 err = p9pdu_readf(pdu, 0, "dbw", &r_size, &r_type, &r_tag);
386 goto rewind_and_exit;
392 P9_DPRINTK(P9_DEBUG_MUX, "pdu: type: %d tag: %d size=%d offset=%d\n",
393 pdu->id, pdu->tag, pdu->size, pdu->offset);
405 pdu->offset = offset;
408 EXPORT_SYMBOL(p9_parse_header);
411 * p9_check_errors - check 9p packet for error return and process it
412 * @c: current client instance
413 * @req: request to parse and check for error conditions
415 * returns error code if one is discovered, otherwise returns 0
417 * this will have to be more complicated if we have multiple
421 static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
426 err = p9_parse_header(req->rc, NULL, &type, NULL, 0);
428 P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse header %d\n", err);
432 if (type == P9_RERROR) {
436 err = p9pdu_readf(req->rc, c->dotu, "s?d", &ename, &ecode);
438 P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n",
447 err = p9_errstr2errno(ename, strlen(ename));
449 /* string match failed */
454 P9_DPRINTK(P9_DEBUG_9P, "<<< RERROR (%d) %s\n", -ecode, ename);
464 * p9_client_flush - flush (cancel) a request
466 * req: request to cancel
468 * This sents a flush for a particular requests and links
469 * the flush request to the original request. The current
470 * code only supports a single flush request although the protocol
471 * allows for multiple flush requests to be sent for a single request.
475 static int p9_client_flush(struct p9_client *c, struct p9_req_t *oldreq)
477 struct p9_req_t *req;
481 err = p9_parse_header(oldreq->tc, NULL, NULL, &oldtag, 1);
485 P9_DPRINTK(P9_DEBUG_9P, ">>> TFLUSH tag %d\n", oldtag);
487 req = p9_client_rpc(c, P9_TFLUSH, "w", oldtag);
491 req->flush_tag = oldtag;
493 /* we don't free anything here because RPC isn't complete */
498 * p9_client_rpc - issue a request and wait for a response
500 * @type: type of request
501 * @fmt: protocol format string (see protocol.c)
503 * Returns request structure (which client must free using p9_free_req)
506 static struct p9_req_t *
507 p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
511 struct p9_req_t *req;
516 P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type);
518 if (c->status != Connected)
519 return ERR_PTR(-EIO);
521 if (signal_pending(current)) {
523 clear_thread_flag(TIF_SIGPENDING);
528 if (type != P9_TVERSION) {
529 tag = p9_idpool_get(c->tagpool);
531 return ERR_PTR(-ENOMEM);
534 req = p9_tag_alloc(c, tag);
538 /* marshall the data */
539 p9pdu_prepare(req->tc, tag, type);
541 err = p9pdu_vwritef(req->tc, c->dotu, fmt, ap);
543 p9pdu_finalize(req->tc);
545 err = c->trans_mod->request(c, req);
547 c->status = Disconnected;
551 /* if it was a flush we just transmitted, return our tag */
552 if (type == P9_TFLUSH)
555 P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d\n", req->wq, tag);
556 err = wait_event_interruptible(*req->wq,
557 req->status >= REQ_STATUS_RCVD);
558 P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d returned %d (flushed=%d)\n",
559 req->wq, tag, err, flushed);
561 if (req->status == REQ_STATUS_ERROR) {
562 P9_DPRINTK(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err);
564 } else if (err == -ERESTARTSYS && flushed) {
565 P9_DPRINTK(P9_DEBUG_MUX, "flushed - going again\n");
567 } else if (req->status == REQ_STATUS_FLSHD) {
568 P9_DPRINTK(P9_DEBUG_MUX, "flushed - erestartsys\n");
572 if ((err == -ERESTARTSYS) && (c->status == Connected) && (!flushed)) {
573 P9_DPRINTK(P9_DEBUG_MUX, "flushing\n");
574 spin_lock_irqsave(&c->lock, flags);
575 if (req->status == REQ_STATUS_SENT)
576 req->status = REQ_STATUS_FLSH;
577 spin_unlock_irqrestore(&c->lock, flags);
580 clear_thread_flag(TIF_SIGPENDING);
582 if (c->trans_mod->cancel(c, req)) {
583 err = p9_client_flush(c, req);
590 spin_lock_irqsave(¤t->sighand->siglock, flags);
592 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
598 err = p9_check_errors(c, req);
600 P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d\n", c, type);
605 P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d error: %d\n", c, type,
611 static struct p9_fid *p9_fid_create(struct p9_client *clnt)
616 P9_DPRINTK(P9_DEBUG_FID, "clnt %p\n", clnt);
617 fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL);
619 return ERR_PTR(-ENOMEM);
621 fid->fid = p9_idpool_get(clnt->fidpool);
627 memset(&fid->qid, 0, sizeof(struct p9_qid));
630 fid->uid = current->fsuid;
634 spin_lock(&clnt->lock);
635 list_add(&fid->flist, &clnt->fidlist);
636 spin_unlock(&clnt->lock);
645 static void p9_fid_destroy(struct p9_fid *fid)
647 struct p9_client *clnt;
649 P9_DPRINTK(P9_DEBUG_FID, "fid %d\n", fid->fid);
651 p9_idpool_put(fid->fid, clnt->fidpool);
652 spin_lock(&clnt->lock);
653 list_del(&fid->flist);
654 spin_unlock(&clnt->lock);
658 int p9_client_version(struct p9_client *c)
661 struct p9_req_t *req;
665 P9_DPRINTK(P9_DEBUG_9P, ">>> TVERSION msize %d extended %d\n",
667 req = p9_client_rpc(c, P9_TVERSION, "ds", c->msize,
668 c->dotu ? "9P2000.u" : "9P2000");
672 err = p9pdu_readf(req->rc, c->dotu, "ds", &msize, &version);
674 P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err);
678 P9_DPRINTK(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version);
679 if (!memcmp(version, "9P2000.u", 8))
681 else if (!memcmp(version, "9P2000", 6))
688 if (msize < c->msize)
697 EXPORT_SYMBOL(p9_client_version);
699 struct p9_client *p9_client_create(const char *dev_name, char *options)
702 struct p9_client *clnt;
705 clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL);
707 return ERR_PTR(-ENOMEM);
709 clnt->trans_mod = NULL;
711 spin_lock_init(&clnt->lock);
712 INIT_LIST_HEAD(&clnt->fidlist);
713 clnt->fidpool = p9_idpool_create();
714 if (IS_ERR(clnt->fidpool)) {
715 err = PTR_ERR(clnt->fidpool);
716 clnt->fidpool = NULL;
722 err = parse_opts(options, clnt);
726 if (clnt->trans_mod == NULL) {
727 err = -EPROTONOSUPPORT;
728 P9_DPRINTK(P9_DEBUG_ERROR,
729 "No transport defined or default transport\n");
733 P9_DPRINTK(P9_DEBUG_MUX, "clnt %p trans %p msize %d dotu %d\n",
734 clnt, clnt->trans_mod, clnt->msize, clnt->dotu);
736 err = clnt->trans_mod->create(clnt, dev_name, options);
740 if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize)
741 clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ;
743 err = p9_client_version(clnt);
750 p9_client_destroy(clnt);
753 EXPORT_SYMBOL(p9_client_create);
755 void p9_client_destroy(struct p9_client *clnt)
757 struct p9_fid *fid, *fidptr;
759 P9_DPRINTK(P9_DEBUG_MUX, "clnt %p\n", clnt);
762 clnt->trans_mod->close(clnt);
764 v9fs_put_trans(clnt->trans_mod);
766 list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist)
770 p9_idpool_destroy(clnt->fidpool);
772 p9_tag_cleanup(clnt);
776 EXPORT_SYMBOL(p9_client_destroy);
778 void p9_client_disconnect(struct p9_client *clnt)
780 P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
781 clnt->status = Disconnected;
783 EXPORT_SYMBOL(p9_client_disconnect);
785 struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
786 char *uname, u32 n_uname, char *aname)
789 struct p9_req_t *req;
793 P9_DPRINTK(P9_DEBUG_9P, ">>> TATTACH afid %d uname %s aname %s\n",
794 afid ? afid->fid : -1, uname, aname);
797 fid = p9_fid_create(clnt);
804 req = p9_client_rpc(clnt, P9_TATTACH, "ddss?d", fid->fid,
805 afid ? afid->fid : P9_NOFID, uname, aname, n_uname);
811 err = p9pdu_readf(req->rc, clnt->dotu, "Q", &qid);
813 p9_free_req(clnt, req);
817 P9_DPRINTK(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n",
818 qid.type, qid.path, qid.version);
820 memmove(&fid->qid, &qid, sizeof(struct p9_qid));
822 p9_free_req(clnt, req);
830 EXPORT_SYMBOL(p9_client_attach);
833 p9_client_auth(struct p9_client *clnt, char *uname, u32 n_uname, char *aname)
836 struct p9_req_t *req;
840 P9_DPRINTK(P9_DEBUG_9P, ">>> TAUTH uname %s aname %s\n", uname, aname);
843 afid = p9_fid_create(clnt);
850 req = p9_client_rpc(clnt, P9_TAUTH, "dss?d",
851 afid ? afid->fid : P9_NOFID, uname, aname, n_uname);
857 err = p9pdu_readf(req->rc, clnt->dotu, "Q", &qid);
859 p9_free_req(clnt, req);
863 P9_DPRINTK(P9_DEBUG_9P, "<<< RAUTH qid %x.%llx.%x\n",
864 qid.type, qid.path, qid.version);
866 memmove(&afid->qid, &qid, sizeof(struct p9_qid));
867 p9_free_req(clnt, req);
872 p9_fid_destroy(afid);
875 EXPORT_SYMBOL(p9_client_auth);
877 struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
881 struct p9_client *clnt;
883 struct p9_qid *wqids;
884 struct p9_req_t *req;
885 int16_t nwqids, count;
890 fid = p9_fid_create(clnt);
897 fid->uid = oldfid->uid;
902 P9_DPRINTK(P9_DEBUG_9P, ">>> TWALK fids %d,%d nwname %d wname[0] %s\n",
903 oldfid->fid, fid->fid, nwname, wnames ? wnames[0] : NULL);
905 req = p9_client_rpc(clnt, P9_TWALK, "ddT", oldfid->fid, fid->fid,
912 err = p9pdu_readf(req->rc, clnt->dotu, "R", &nwqids, &wqids);
913 p9_free_req(clnt, req);
917 P9_DPRINTK(P9_DEBUG_9P, "<<< RWALK nwqid %d:\n", nwqids);
919 if (nwqids != nwname) {
924 for (count = 0; count < nwqids; count++)
925 P9_DPRINTK(P9_DEBUG_9P, "<<< [%d] %x.%llx.%x\n",
926 count, wqids[count].type, wqids[count].path,
927 wqids[count].version);
930 memmove(&fid->qid, &wqids[nwqids - 1], sizeof(struct p9_qid));
932 fid->qid = oldfid->qid;
937 p9_client_clunk(fid);
941 if (fid && (fid != oldfid))
946 EXPORT_SYMBOL(p9_client_walk);
948 int p9_client_open(struct p9_fid *fid, int mode)
951 struct p9_client *clnt;
952 struct p9_req_t *req;
956 P9_DPRINTK(P9_DEBUG_9P, ">>> TOPEN fid %d mode %d\n", fid->fid, mode);
963 req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode);
969 err = p9pdu_readf(req->rc, clnt->dotu, "Qd", &qid, &iounit);
970 p9_free_req(clnt, req);
974 P9_DPRINTK(P9_DEBUG_9P, "<<< ROPEN qid %x.%llx.%x iounit %x\n",
975 qid.type, qid.path, qid.version, iounit);
978 fid->iounit = iounit;
983 EXPORT_SYMBOL(p9_client_open);
985 int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
989 struct p9_client *clnt;
990 struct p9_req_t *req;
994 P9_DPRINTK(P9_DEBUG_9P, ">>> TCREATE fid %d name %s perm %d mode %d\n",
995 fid->fid, name, perm, mode);
1002 req = p9_client_rpc(clnt, P9_TCREATE, "dsdb?s", fid->fid, name, perm,
1009 err = p9pdu_readf(req->rc, clnt->dotu, "Qd", &qid, &iounit);
1010 p9_free_req(clnt, req);
1014 P9_DPRINTK(P9_DEBUG_9P, "<<< RCREATE qid %x.%llx.%x iounit %x\n",
1015 qid.type, qid.path, qid.version, iounit);
1018 fid->iounit = iounit;
1023 EXPORT_SYMBOL(p9_client_fcreate);
1025 int p9_client_clunk(struct p9_fid *fid)
1028 struct p9_client *clnt;
1029 struct p9_req_t *req;
1031 P9_DPRINTK(P9_DEBUG_9P, ">>> TCLUNK fid %d\n", fid->fid);
1035 req = p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid);
1041 P9_DPRINTK(P9_DEBUG_9P, "<<< RCLUNK fid %d\n", fid->fid);
1043 p9_free_req(clnt, req);
1044 p9_fid_destroy(fid);
1049 EXPORT_SYMBOL(p9_client_clunk);
1051 int p9_client_remove(struct p9_fid *fid)
1054 struct p9_client *clnt;
1055 struct p9_req_t *req;
1057 P9_DPRINTK(P9_DEBUG_9P, ">>> TREMOVE fid %d\n", fid->fid);
1061 req = p9_client_rpc(clnt, P9_TREMOVE, "d", fid->fid);
1067 P9_DPRINTK(P9_DEBUG_9P, "<<< RREMOVE fid %d\n", fid->fid);
1069 p9_free_req(clnt, req);
1070 p9_fid_destroy(fid);
1075 EXPORT_SYMBOL(p9_client_remove);
1078 p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
1081 int err, rsize, total;
1082 struct p9_client *clnt;
1083 struct p9_req_t *req;
1086 P9_DPRINTK(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n", fid->fid,
1087 (long long unsigned) offset, count);
1092 rsize = fid->iounit;
1093 if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
1094 rsize = clnt->msize - P9_IOHDRSZ;
1099 req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset, rsize);
1105 err = p9pdu_readf(req->rc, clnt->dotu, "D", &count, &dataptr);
1107 goto free_and_error;
1109 P9_DPRINTK(P9_DEBUG_9P, "<<< RREAD count %d\n", count);
1112 memmove(data, dataptr, count);
1117 err = copy_to_user(udata, dataptr, count);
1120 goto free_and_error;
1124 p9_free_req(clnt, req);
1128 p9_free_req(clnt, req);
1132 EXPORT_SYMBOL(p9_client_read);
1135 p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
1136 u64 offset, u32 count)
1138 int err, rsize, total;
1139 struct p9_client *clnt;
1140 struct p9_req_t *req;
1142 P9_DPRINTK(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %d\n",
1143 fid->fid, (long long unsigned) offset, count);
1148 rsize = fid->iounit;
1149 if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
1150 rsize = clnt->msize - P9_IOHDRSZ;
1155 req = p9_client_rpc(clnt, P9_TWRITE, "dqD", fid->fid, offset,
1158 req = p9_client_rpc(clnt, P9_TWRITE, "dqU", fid->fid, offset,
1165 err = p9pdu_readf(req->rc, clnt->dotu, "d", &count);
1167 goto free_and_error;
1168 P9_DPRINTK(P9_DEBUG_9P, "<<< RWRITE count %d\n", count);
1170 p9_free_req(clnt, req);
1174 p9_free_req(clnt, req);
1178 EXPORT_SYMBOL(p9_client_write);
1180 struct p9_wstat *p9_client_stat(struct p9_fid *fid)
1183 struct p9_client *clnt;
1184 struct p9_wstat *ret = kmalloc(sizeof(struct p9_wstat), GFP_KERNEL);
1185 struct p9_req_t *req;
1188 P9_DPRINTK(P9_DEBUG_9P, ">>> TSTAT fid %d\n", fid->fid);
1191 return ERR_PTR(-ENOMEM);
1196 req = p9_client_rpc(clnt, P9_TSTAT, "d", fid->fid);
1202 err = p9pdu_readf(req->rc, clnt->dotu, "wS", &ignored, ret);
1203 p9_free_req(clnt, req);
1207 P9_DPRINTK(P9_DEBUG_9P,
1208 "<<< RSTAT sz=%x type=%x dev=%x qid=%2.2x %4.4x %8.8llx"
1209 " mode=%8.8x uid=%d gid=%d size=%lld %s\n",
1210 ret->size, ret->type, ret->dev, ret->qid.type,
1211 ret->qid.version, ret->qid.path, ret->mode,
1212 ret->n_uid, ret->n_gid, ret->length, ret->name);
1216 return ERR_PTR(err);
1218 EXPORT_SYMBOL(p9_client_stat);
1220 int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst)
1223 struct p9_req_t *req;
1224 struct p9_client *clnt;
1226 P9_DPRINTK(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", fid->fid);
1230 req = p9_client_rpc(clnt, P9_TWSTAT, "dwS", fid->fid, 0, wst);
1236 P9_DPRINTK(P9_DEBUG_9P, "<<< RWSTAT fid %d\n", fid->fid);
1238 p9_free_req(clnt, req);
1242 EXPORT_SYMBOL(p9_client_wstat);