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 spin_unlock_irqrestore(&c->lock, flags);
163 return ERR_PTR(-ENOMEM);
165 for (col = 0; col < P9_ROW_MAXTAG; col++) {
166 c->reqs[row][col].status = REQ_STATUS_IDLE;
167 c->reqs[row][col].tc = NULL;
169 c->max_tag += P9_ROW_MAXTAG;
171 spin_unlock_irqrestore(&c->lock, flags);
173 row = tag / P9_ROW_MAXTAG;
174 col = tag % P9_ROW_MAXTAG;
176 req = &c->reqs[row][col];
178 req->wq = kmalloc(sizeof(wait_queue_head_t), GFP_KERNEL);
180 printk(KERN_ERR "Couldn't grow tag array\n");
181 return ERR_PTR(-ENOMEM);
183 init_waitqueue_head(req->wq);
184 req->tc = kmalloc(sizeof(struct p9_fcall)+c->msize,
186 req->rc = kmalloc(sizeof(struct p9_fcall)+c->msize,
188 if ((!req->tc) || (!req->rc)) {
189 printk(KERN_ERR "Couldn't grow tag array\n");
192 return ERR_PTR(-ENOMEM);
194 req->tc->sdata = (char *) req->tc + sizeof(struct p9_fcall);
195 req->tc->capacity = c->msize;
196 req->rc->sdata = (char *) req->rc + sizeof(struct p9_fcall);
197 req->rc->capacity = c->msize;
200 p9pdu_reset(req->tc);
201 p9pdu_reset(req->rc);
204 req->tc->tag = tag-1;
205 req->status = REQ_STATUS_ALLOC;
207 return &c->reqs[row][col];
211 * p9_tag_lookup - lookup a request by tag
212 * @c: client session to lookup tag within
213 * @tag: numeric id for transaction
217 struct p9_req_t *p9_tag_lookup(struct p9_client *c, u16 tag)
221 /* This looks up the original request by tag so we know which
222 * buffer to read the data into */
225 BUG_ON(tag >= c->max_tag);
227 row = tag / P9_ROW_MAXTAG;
228 col = tag % P9_ROW_MAXTAG;
230 return &c->reqs[row][col];
232 EXPORT_SYMBOL(p9_tag_lookup);
235 * p9_tag_init - setup tags structure and contents
236 * @tags: tags structure from the client struct
238 * This initializes the tags structure for each client instance.
242 static int p9_tag_init(struct p9_client *c)
246 c->tagpool = p9_idpool_create();
247 if (IS_ERR(c->tagpool)) {
248 err = PTR_ERR(c->tagpool);
253 p9_idpool_get(c->tagpool); /* reserve tag 0 */
261 * p9_tag_cleanup - cleans up tags structure and reclaims resources
262 * @tags: tags structure from the client struct
264 * This frees resources associated with the tags structure
267 static void p9_tag_cleanup(struct p9_client *c)
271 /* check to insure all requests are idle */
272 for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) {
273 for (col = 0; col < P9_ROW_MAXTAG; col++) {
274 if (c->reqs[row][col].status != REQ_STATUS_IDLE) {
275 P9_DPRINTK(P9_DEBUG_MUX,
276 "Attempting to cleanup non-free tag %d,%d\n",
278 /* TODO: delay execution of cleanup */
285 p9_idpool_destroy(c->tagpool);
287 /* free requests associated with tags */
288 for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) {
289 for (col = 0; col < P9_ROW_MAXTAG; col++) {
290 kfree(c->reqs[row][col].wq);
291 kfree(c->reqs[row][col].tc);
292 kfree(c->reqs[row][col].rc);
300 * p9_free_req - free a request and clean-up as necessary
302 * r: request to release
306 static void p9_free_req(struct p9_client *c, struct p9_req_t *r)
308 int tag = r->tc->tag;
309 P9_DPRINTK(P9_DEBUG_MUX, "clnt %p req %p tag: %d\n", c, r, tag);
311 r->status = REQ_STATUS_IDLE;
312 if (tag != P9_NOTAG && p9_idpool_check(tag, c->tagpool))
313 p9_idpool_put(tag, c->tagpool);
317 * p9_client_cb - call back from transport to client
319 * req: request received
322 void p9_client_cb(struct p9_client *c, struct p9_req_t *req)
324 struct p9_req_t *other_req;
327 P9_DPRINTK(P9_DEBUG_MUX, " tag %d\n", req->tc->tag);
329 if (req->status == REQ_STATUS_ERROR)
332 if (req->flush_tag) { /* flush receive path */
333 P9_DPRINTK(P9_DEBUG_9P, "<<< RFLUSH %d\n", req->tc->tag);
334 spin_lock_irqsave(&c->lock, flags);
335 other_req = p9_tag_lookup(c, req->flush_tag);
336 if (other_req->status != REQ_STATUS_FLSH) /* stale flush */
337 spin_unlock_irqrestore(&c->lock, flags);
339 other_req->status = REQ_STATUS_FLSHD;
340 spin_unlock_irqrestore(&c->lock, flags);
341 wake_up(other_req->wq);
344 } else { /* normal receive path */
345 P9_DPRINTK(P9_DEBUG_MUX, "normal: tag %d\n", req->tc->tag);
346 spin_lock_irqsave(&c->lock, flags);
347 if (req->status != REQ_STATUS_FLSHD)
348 req->status = REQ_STATUS_RCVD;
349 spin_unlock_irqrestore(&c->lock, flags);
351 P9_DPRINTK(P9_DEBUG_MUX, "wakeup: %d\n", req->tc->tag);
354 EXPORT_SYMBOL(p9_client_cb);
357 * p9_parse_header - parse header arguments out of a packet
358 * @pdu: packet to parse
359 * @size: size of packet
360 * @type: type of request
361 * @tag: tag of packet
362 * @rewind: set if we need to rewind offset afterwards
366 p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, int16_t *tag,
372 int offset = pdu->offset;
379 err = p9pdu_readf(pdu, 0, "dbw", &r_size, &r_type, &r_tag);
381 goto rewind_and_exit;
387 P9_DPRINTK(P9_DEBUG_9P, "<<< size=%d type: %d tag: %d\n", pdu->size,
400 pdu->offset = offset;
403 EXPORT_SYMBOL(p9_parse_header);
406 * p9_check_errors - check 9p packet for error return and process it
407 * @c: current client instance
408 * @req: request to parse and check for error conditions
410 * returns error code if one is discovered, otherwise returns 0
412 * this will have to be more complicated if we have multiple
416 static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
421 err = p9_parse_header(req->rc, NULL, &type, NULL, 0);
423 P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse header %d\n", err);
427 if (type == P9_RERROR) {
431 err = p9pdu_readf(req->rc, c->dotu, "s?d", &ename, &ecode);
433 P9_DPRINTK(P9_DEBUG_ERROR, "couldn't parse error%d\n",
442 err = p9_errstr2errno(ename, strlen(ename));
444 /* string match failed */
449 P9_DPRINTK(P9_DEBUG_9P, "<<< RERROR (%d) %s\n", -ecode, ename);
459 * p9_client_flush - flush (cancel) a request
461 * req: request to cancel
463 * This sents a flush for a particular requests and links
464 * the flush request to the original request. The current
465 * code only supports a single flush request although the protocol
466 * allows for multiple flush requests to be sent for a single request.
470 static int p9_client_flush(struct p9_client *c, struct p9_req_t *oldreq)
472 struct p9_req_t *req;
476 err = p9_parse_header(oldreq->tc, NULL, NULL, &oldtag, 1);
480 P9_DPRINTK(P9_DEBUG_9P, ">>> TFLUSH tag %d\n", oldtag);
482 req = p9_client_rpc(c, P9_TFLUSH, "w", oldtag);
486 req->flush_tag = oldtag;
488 /* we don't free anything here because RPC isn't complete */
493 * p9_client_rpc - issue a request and wait for a response
495 * @type: type of request
496 * @fmt: protocol format string (see protocol.c)
498 * Returns request structure (which client must free using p9_free_req)
501 static struct p9_req_t *
502 p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
506 struct p9_req_t *req;
511 P9_DPRINTK(P9_DEBUG_MUX, "client %p op %d\n", c, type);
513 if (c->status != Connected)
514 return ERR_PTR(-EIO);
516 if (signal_pending(current)) {
518 clear_thread_flag(TIF_SIGPENDING);
523 if (type != P9_TVERSION) {
524 tag = p9_idpool_get(c->tagpool);
526 return ERR_PTR(-ENOMEM);
529 req = p9_tag_alloc(c, tag);
533 /* marshall the data */
534 p9pdu_prepare(req->tc, tag, type);
536 err = p9pdu_vwritef(req->tc, c->dotu, fmt, ap);
538 p9pdu_finalize(req->tc);
540 err = c->trans_mod->request(c, req);
542 c->status = Disconnected;
546 /* if it was a flush we just transmitted, return our tag */
547 if (type == P9_TFLUSH)
550 P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d\n", req->wq, tag);
551 err = wait_event_interruptible(*req->wq,
552 req->status >= REQ_STATUS_RCVD);
553 P9_DPRINTK(P9_DEBUG_MUX, "wait %p tag: %d returned %d (flushed=%d)\n",
554 req->wq, tag, err, flushed);
556 if (req->status == REQ_STATUS_ERROR) {
557 P9_DPRINTK(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err);
559 } else if (err == -ERESTARTSYS && flushed) {
560 P9_DPRINTK(P9_DEBUG_MUX, "flushed - going again\n");
562 } else if (req->status == REQ_STATUS_FLSHD) {
563 P9_DPRINTK(P9_DEBUG_MUX, "flushed - erestartsys\n");
567 if ((err == -ERESTARTSYS) && (c->status == Connected) && (!flushed)) {
568 P9_DPRINTK(P9_DEBUG_MUX, "flushing\n");
569 spin_lock_irqsave(&c->lock, flags);
570 if (req->status == REQ_STATUS_SENT)
571 req->status = REQ_STATUS_FLSH;
572 spin_unlock_irqrestore(&c->lock, flags);
575 clear_thread_flag(TIF_SIGPENDING);
577 if (c->trans_mod->cancel(c, req)) {
578 err = p9_client_flush(c, req);
585 spin_lock_irqsave(¤t->sighand->siglock, flags);
587 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
593 err = p9_check_errors(c, req);
595 P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d\n", c, type);
600 P9_DPRINTK(P9_DEBUG_MUX, "exit: client %p op %d error: %d\n", c, type,
606 static struct p9_fid *p9_fid_create(struct p9_client *clnt)
612 P9_DPRINTK(P9_DEBUG_FID, "clnt %p\n", clnt);
613 fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL);
615 return ERR_PTR(-ENOMEM);
617 fid->fid = p9_idpool_get(clnt->fidpool);
623 memset(&fid->qid, 0, sizeof(struct p9_qid));
626 fid->uid = current->fsuid;
630 spin_lock_irqsave(&clnt->lock, flags);
631 list_add(&fid->flist, &clnt->fidlist);
632 spin_unlock_irqrestore(&clnt->lock, flags);
641 static void p9_fid_destroy(struct p9_fid *fid)
643 struct p9_client *clnt;
646 P9_DPRINTK(P9_DEBUG_FID, "fid %d\n", fid->fid);
648 p9_idpool_put(fid->fid, clnt->fidpool);
649 spin_lock_irqsave(&clnt->lock, flags);
650 list_del(&fid->flist);
651 spin_unlock_irqrestore(&clnt->lock, flags);
655 int p9_client_version(struct p9_client *c)
658 struct p9_req_t *req;
662 P9_DPRINTK(P9_DEBUG_9P, ">>> TVERSION msize %d extended %d\n",
664 req = p9_client_rpc(c, P9_TVERSION, "ds", c->msize,
665 c->dotu ? "9P2000.u" : "9P2000");
669 err = p9pdu_readf(req->rc, c->dotu, "ds", &msize, &version);
671 P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err);
672 p9pdu_dump(1, req->rc);
676 P9_DPRINTK(P9_DEBUG_9P, "<<< RVERSION msize %d %s\n", msize, version);
677 if (!memcmp(version, "9P2000.u", 8))
679 else if (!memcmp(version, "9P2000", 6))
686 if (msize < c->msize)
695 EXPORT_SYMBOL(p9_client_version);
697 struct p9_client *p9_client_create(const char *dev_name, char *options)
700 struct p9_client *clnt;
703 clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL);
705 return ERR_PTR(-ENOMEM);
707 clnt->trans_mod = NULL;
709 spin_lock_init(&clnt->lock);
710 INIT_LIST_HEAD(&clnt->fidlist);
711 clnt->fidpool = p9_idpool_create();
712 if (IS_ERR(clnt->fidpool)) {
713 err = PTR_ERR(clnt->fidpool);
714 clnt->fidpool = NULL;
720 err = parse_opts(options, clnt);
724 if (clnt->trans_mod == NULL) {
725 err = -EPROTONOSUPPORT;
726 P9_DPRINTK(P9_DEBUG_ERROR,
727 "No transport defined or default transport\n");
731 P9_DPRINTK(P9_DEBUG_MUX, "clnt %p trans %p msize %d dotu %d\n",
732 clnt, clnt->trans_mod, clnt->msize, clnt->dotu);
734 err = clnt->trans_mod->create(clnt, dev_name, options);
738 if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize)
739 clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ;
741 err = p9_client_version(clnt);
748 p9_client_destroy(clnt);
751 EXPORT_SYMBOL(p9_client_create);
753 void p9_client_destroy(struct p9_client *clnt)
755 struct p9_fid *fid, *fidptr;
757 P9_DPRINTK(P9_DEBUG_MUX, "clnt %p\n", clnt);
760 clnt->trans_mod->close(clnt);
762 v9fs_put_trans(clnt->trans_mod);
764 list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist)
768 p9_idpool_destroy(clnt->fidpool);
770 p9_tag_cleanup(clnt);
774 EXPORT_SYMBOL(p9_client_destroy);
776 void p9_client_disconnect(struct p9_client *clnt)
778 P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
779 clnt->status = Disconnected;
781 EXPORT_SYMBOL(p9_client_disconnect);
783 struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
784 char *uname, u32 n_uname, char *aname)
787 struct p9_req_t *req;
791 P9_DPRINTK(P9_DEBUG_9P, ">>> TATTACH afid %d uname %s aname %s\n",
792 afid ? afid->fid : -1, uname, aname);
795 fid = p9_fid_create(clnt);
802 req = p9_client_rpc(clnt, P9_TATTACH, "ddss?d", fid->fid,
803 afid ? afid->fid : P9_NOFID, uname, aname, n_uname);
809 err = p9pdu_readf(req->rc, clnt->dotu, "Q", &qid);
811 p9pdu_dump(1, req->rc);
812 p9_free_req(clnt, req);
816 P9_DPRINTK(P9_DEBUG_9P, "<<< RATTACH qid %x.%llx.%x\n",
817 qid.type, qid.path, qid.version);
819 memmove(&fid->qid, &qid, sizeof(struct p9_qid));
821 p9_free_req(clnt, req);
829 EXPORT_SYMBOL(p9_client_attach);
832 p9_client_auth(struct p9_client *clnt, char *uname, u32 n_uname, char *aname)
835 struct p9_req_t *req;
839 P9_DPRINTK(P9_DEBUG_9P, ">>> TAUTH uname %s aname %s\n", uname, aname);
842 afid = p9_fid_create(clnt);
849 req = p9_client_rpc(clnt, P9_TAUTH, "dss?d",
850 afid ? afid->fid : P9_NOFID, uname, aname, n_uname);
856 err = p9pdu_readf(req->rc, clnt->dotu, "Q", &qid);
858 p9pdu_dump(1, req->rc);
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);
914 p9pdu_dump(1, req->rc);
915 p9_free_req(clnt, req);
918 p9_free_req(clnt, req);
920 P9_DPRINTK(P9_DEBUG_9P, "<<< RWALK nwqid %d:\n", nwqids);
922 if (nwqids != nwname) {
927 for (count = 0; count < nwqids; count++)
928 P9_DPRINTK(P9_DEBUG_9P, "<<< [%d] %x.%llx.%x\n",
929 count, wqids[count].type, wqids[count].path,
930 wqids[count].version);
933 memmove(&fid->qid, &wqids[nwqids - 1], sizeof(struct p9_qid));
935 fid->qid = oldfid->qid;
940 p9_client_clunk(fid);
944 if (fid && (fid != oldfid))
949 EXPORT_SYMBOL(p9_client_walk);
951 int p9_client_open(struct p9_fid *fid, int mode)
954 struct p9_client *clnt;
955 struct p9_req_t *req;
959 P9_DPRINTK(P9_DEBUG_9P, ">>> TOPEN fid %d mode %d\n", fid->fid, mode);
966 req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode);
972 err = p9pdu_readf(req->rc, clnt->dotu, "Qd", &qid, &iounit);
974 p9pdu_dump(1, req->rc);
978 P9_DPRINTK(P9_DEBUG_9P, "<<< ROPEN qid %x.%llx.%x iounit %x\n",
979 qid.type, qid.path, qid.version, iounit);
982 fid->iounit = iounit;
985 p9_free_req(clnt, req);
989 EXPORT_SYMBOL(p9_client_open);
991 int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
995 struct p9_client *clnt;
996 struct p9_req_t *req;
1000 P9_DPRINTK(P9_DEBUG_9P, ">>> TCREATE fid %d name %s perm %d mode %d\n",
1001 fid->fid, name, perm, mode);
1005 if (fid->mode != -1)
1008 req = p9_client_rpc(clnt, P9_TCREATE, "dsdb?s", fid->fid, name, perm,
1015 err = p9pdu_readf(req->rc, clnt->dotu, "Qd", &qid, &iounit);
1017 p9pdu_dump(1, req->rc);
1018 goto free_and_error;
1021 P9_DPRINTK(P9_DEBUG_9P, "<<< RCREATE qid %x.%llx.%x iounit %x\n",
1022 qid.type, qid.path, qid.version, iounit);
1025 fid->iounit = iounit;
1028 p9_free_req(clnt, req);
1032 EXPORT_SYMBOL(p9_client_fcreate);
1034 int p9_client_clunk(struct p9_fid *fid)
1037 struct p9_client *clnt;
1038 struct p9_req_t *req;
1040 P9_DPRINTK(P9_DEBUG_9P, ">>> TCLUNK fid %d\n", fid->fid);
1044 req = p9_client_rpc(clnt, P9_TCLUNK, "d", fid->fid);
1050 P9_DPRINTK(P9_DEBUG_9P, "<<< RCLUNK fid %d\n", fid->fid);
1052 p9_free_req(clnt, req);
1053 p9_fid_destroy(fid);
1058 EXPORT_SYMBOL(p9_client_clunk);
1060 int p9_client_remove(struct p9_fid *fid)
1063 struct p9_client *clnt;
1064 struct p9_req_t *req;
1066 P9_DPRINTK(P9_DEBUG_9P, ">>> TREMOVE fid %d\n", fid->fid);
1070 req = p9_client_rpc(clnt, P9_TREMOVE, "d", fid->fid);
1076 P9_DPRINTK(P9_DEBUG_9P, "<<< RREMOVE fid %d\n", fid->fid);
1078 p9_free_req(clnt, req);
1079 p9_fid_destroy(fid);
1084 EXPORT_SYMBOL(p9_client_remove);
1087 p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
1090 int err, rsize, total;
1091 struct p9_client *clnt;
1092 struct p9_req_t *req;
1095 P9_DPRINTK(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n", fid->fid,
1096 (long long unsigned) offset, count);
1101 rsize = fid->iounit;
1102 if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
1103 rsize = clnt->msize - P9_IOHDRSZ;
1108 req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset, rsize);
1114 err = p9pdu_readf(req->rc, clnt->dotu, "D", &count, &dataptr);
1116 p9pdu_dump(1, req->rc);
1117 goto free_and_error;
1120 P9_DPRINTK(P9_DEBUG_9P, "<<< RREAD count %d\n", count);
1123 memmove(data, dataptr, count);
1128 err = copy_to_user(udata, dataptr, count);
1131 goto free_and_error;
1135 p9_free_req(clnt, req);
1139 p9_free_req(clnt, req);
1143 EXPORT_SYMBOL(p9_client_read);
1146 p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
1147 u64 offset, u32 count)
1149 int err, rsize, total;
1150 struct p9_client *clnt;
1151 struct p9_req_t *req;
1153 P9_DPRINTK(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %d\n",
1154 fid->fid, (long long unsigned) offset, count);
1159 rsize = fid->iounit;
1160 if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
1161 rsize = clnt->msize - P9_IOHDRSZ;
1166 req = p9_client_rpc(clnt, P9_TWRITE, "dqD", fid->fid, offset,
1169 req = p9_client_rpc(clnt, P9_TWRITE, "dqU", fid->fid, offset,
1176 err = p9pdu_readf(req->rc, clnt->dotu, "d", &count);
1178 p9pdu_dump(1, req->rc);
1179 goto free_and_error;
1182 P9_DPRINTK(P9_DEBUG_9P, "<<< RWRITE count %d\n", count);
1184 p9_free_req(clnt, req);
1188 p9_free_req(clnt, req);
1192 EXPORT_SYMBOL(p9_client_write);
1194 struct p9_wstat *p9_client_stat(struct p9_fid *fid)
1197 struct p9_client *clnt;
1198 struct p9_wstat *ret = kmalloc(sizeof(struct p9_wstat), GFP_KERNEL);
1199 struct p9_req_t *req;
1202 P9_DPRINTK(P9_DEBUG_9P, ">>> TSTAT fid %d\n", fid->fid);
1205 return ERR_PTR(-ENOMEM);
1210 req = p9_client_rpc(clnt, P9_TSTAT, "d", fid->fid);
1216 err = p9pdu_readf(req->rc, clnt->dotu, "wS", &ignored, ret);
1219 p9pdu_dump(1, req->rc);
1220 goto free_and_error;
1223 P9_DPRINTK(P9_DEBUG_9P,
1224 "<<< RSTAT sz=%x type=%x dev=%x qid=%x.%llx.%x\n"
1225 "<<< mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n"
1226 "<<< name=%s uid=%s gid=%s muid=%s extension=(%s)\n"
1227 "<<< uid=%d gid=%d n_muid=%d\n",
1228 ret->size, ret->type, ret->dev, ret->qid.type,
1229 ret->qid.path, ret->qid.version, ret->mode,
1230 ret->atime, ret->mtime, ret->length, ret->name,
1231 ret->uid, ret->gid, ret->muid, ret->extension,
1232 ret->n_uid, ret->n_gid, ret->n_muid);
1235 p9_free_req(clnt, req);
1239 EXPORT_SYMBOL(p9_client_stat);
1241 int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst)
1244 struct p9_req_t *req;
1245 struct p9_client *clnt;
1247 P9_DPRINTK(P9_DEBUG_9P, ">>> TWSTAT fid %d\n", fid->fid);
1248 P9_DPRINTK(P9_DEBUG_9P,
1249 " sz=%x type=%x dev=%x qid=%x.%llx.%x\n"
1250 " mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n"
1251 " name=%s uid=%s gid=%s muid=%s extension=(%s)\n"
1252 " uid=%d gid=%d n_muid=%d\n",
1253 wst->size, wst->type, wst->dev, wst->qid.type,
1254 wst->qid.path, wst->qid.version, wst->mode,
1255 wst->atime, wst->mtime, wst->length, wst->name,
1256 wst->uid, wst->gid, wst->muid, wst->extension,
1257 wst->n_uid, wst->n_gid, wst->n_muid);
1261 req = p9_client_rpc(clnt, P9_TWSTAT, "dwS", fid->fid, 0, wst);
1267 P9_DPRINTK(P9_DEBUG_9P, "<<< RWSTAT fid %d\n", fid->fid);
1269 p9_free_req(clnt, req);
1273 EXPORT_SYMBOL(p9_client_wstat);