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 * parse_options - parse mount options into client structure
64 * @opts: options string passed from mount
65 * @clnt: existing v9fs client information
67 * Return 0 upon success, -ERRNO upon failure
70 static int parse_opts(char *opts
, struct p9_client
*clnt
)
72 char *options
, *tmp_options
;
74 substring_t args
[MAX_OPT_ARGS
];
84 tmp_options
= kstrdup(opts
, GFP_KERNEL
);
86 P9_DPRINTK(P9_DEBUG_ERROR
,
87 "failed to allocate copy of option string\n");
90 options
= tmp_options
;
92 while ((p
= strsep(&options
, ",")) != NULL
) {
96 token
= match_token(p
, tokens
, args
);
97 if (token
< Opt_trans
) {
98 int r
= match_int(&args
[0], &option
);
100 P9_DPRINTK(P9_DEBUG_ERROR
,
101 "integer field, but no integer?\n");
108 clnt
->msize
= option
;
111 clnt
->trans_mod
= v9fs_get_trans_by_name(&args
[0]);
112 if(clnt
->trans_mod
== NULL
) {
113 P9_DPRINTK(P9_DEBUG_ERROR
,
114 "Could not find request transport: %s\n",
117 goto free_and_return
;
134 * p9_tag_alloc - lookup/allocate a request by tag
135 * @c: client session to lookup tag within
136 * @tag: numeric id for transaction
138 * this is a simple array lookup, but will grow the
139 * request_slots as necessary to accomodate transaction
140 * ids which did not previously have a slot.
142 * this code relies on the client spinlock to manage locks, its
143 * possible we should switch to something else, but I'd rather
144 * stick with something low-overhead for the common case.
148 static struct p9_req_t
*p9_tag_alloc(struct p9_client
*c
, u16 tag
)
152 struct p9_req_t
*req
;
154 /* This looks up the original request by tag so we know which
155 * buffer to read the data into */
158 if (tag
>= c
->max_tag
) {
159 spin_lock_irqsave(&c
->lock
, flags
);
160 /* check again since original check was outside of lock */
161 while (tag
>= c
->max_tag
) {
162 row
= (tag
/ P9_ROW_MAXTAG
);
163 c
->reqs
[row
] = kcalloc(P9_ROW_MAXTAG
,
164 sizeof(struct p9_req_t
), GFP_ATOMIC
);
167 printk(KERN_ERR
"Couldn't grow tag array\n");
168 spin_unlock_irqrestore(&c
->lock
, flags
);
169 return ERR_PTR(-ENOMEM
);
171 for (col
= 0; col
< P9_ROW_MAXTAG
; col
++) {
172 c
->reqs
[row
][col
].status
= REQ_STATUS_IDLE
;
173 c
->reqs
[row
][col
].tc
= NULL
;
175 c
->max_tag
+= P9_ROW_MAXTAG
;
177 spin_unlock_irqrestore(&c
->lock
, flags
);
179 row
= tag
/ P9_ROW_MAXTAG
;
180 col
= tag
% P9_ROW_MAXTAG
;
182 req
= &c
->reqs
[row
][col
];
184 req
->wq
= kmalloc(sizeof(wait_queue_head_t
), GFP_KERNEL
);
186 printk(KERN_ERR
"Couldn't grow tag array\n");
187 return ERR_PTR(-ENOMEM
);
189 init_waitqueue_head(req
->wq
);
190 req
->tc
= kmalloc(sizeof(struct p9_fcall
)+c
->msize
,
192 req
->rc
= kmalloc(sizeof(struct p9_fcall
)+c
->msize
,
194 if ((!req
->tc
) || (!req
->rc
)) {
195 printk(KERN_ERR
"Couldn't grow tag array\n");
199 req
->tc
= req
->rc
= NULL
;
201 return ERR_PTR(-ENOMEM
);
203 req
->tc
->sdata
= (char *) req
->tc
+ sizeof(struct p9_fcall
);
204 req
->tc
->capacity
= c
->msize
;
205 req
->rc
->sdata
= (char *) req
->rc
+ sizeof(struct p9_fcall
);
206 req
->rc
->capacity
= c
->msize
;
209 p9pdu_reset(req
->tc
);
210 p9pdu_reset(req
->rc
);
212 req
->tc
->tag
= tag
-1;
213 req
->status
= REQ_STATUS_ALLOC
;
215 return &c
->reqs
[row
][col
];
219 * p9_tag_lookup - lookup a request by tag
220 * @c: client session to lookup tag within
221 * @tag: numeric id for transaction
225 struct p9_req_t
*p9_tag_lookup(struct p9_client
*c
, u16 tag
)
229 /* This looks up the original request by tag so we know which
230 * buffer to read the data into */
233 BUG_ON(tag
>= c
->max_tag
);
235 row
= tag
/ P9_ROW_MAXTAG
;
236 col
= tag
% P9_ROW_MAXTAG
;
238 return &c
->reqs
[row
][col
];
240 EXPORT_SYMBOL(p9_tag_lookup
);
243 * p9_tag_init - setup tags structure and contents
244 * @c: v9fs client struct
246 * This initializes the tags structure for each client instance.
250 static int p9_tag_init(struct p9_client
*c
)
254 c
->tagpool
= p9_idpool_create();
255 if (IS_ERR(c
->tagpool
)) {
256 err
= PTR_ERR(c
->tagpool
);
261 p9_idpool_get(c
->tagpool
); /* reserve tag 0 */
269 * p9_tag_cleanup - cleans up tags structure and reclaims resources
270 * @c: v9fs client struct
272 * This frees resources associated with the tags structure
275 static void p9_tag_cleanup(struct p9_client
*c
)
279 /* check to insure all requests are idle */
280 for (row
= 0; row
< (c
->max_tag
/P9_ROW_MAXTAG
); row
++) {
281 for (col
= 0; col
< P9_ROW_MAXTAG
; col
++) {
282 if (c
->reqs
[row
][col
].status
!= REQ_STATUS_IDLE
) {
283 P9_DPRINTK(P9_DEBUG_MUX
,
284 "Attempting to cleanup non-free tag %d,%d\n",
286 /* TODO: delay execution of cleanup */
293 p9_idpool_destroy(c
->tagpool
);
295 /* free requests associated with tags */
296 for (row
= 0; row
< (c
->max_tag
/P9_ROW_MAXTAG
); row
++) {
297 for (col
= 0; col
< P9_ROW_MAXTAG
; col
++) {
298 kfree(c
->reqs
[row
][col
].wq
);
299 kfree(c
->reqs
[row
][col
].tc
);
300 kfree(c
->reqs
[row
][col
].rc
);
308 * p9_free_req - free a request and clean-up as necessary
310 * r: request to release
314 static void p9_free_req(struct p9_client
*c
, struct p9_req_t
*r
)
316 int tag
= r
->tc
->tag
;
317 P9_DPRINTK(P9_DEBUG_MUX
, "clnt %p req %p tag: %d\n", c
, r
, tag
);
319 r
->status
= REQ_STATUS_IDLE
;
320 if (tag
!= P9_NOTAG
&& p9_idpool_check(tag
, c
->tagpool
))
321 p9_idpool_put(tag
, c
->tagpool
);
325 * p9_client_cb - call back from transport to client
327 * req: request received
330 void p9_client_cb(struct p9_client
*c
, struct p9_req_t
*req
)
332 P9_DPRINTK(P9_DEBUG_MUX
, " tag %d\n", req
->tc
->tag
);
334 P9_DPRINTK(P9_DEBUG_MUX
, "wakeup: %d\n", req
->tc
->tag
);
336 EXPORT_SYMBOL(p9_client_cb
);
339 * p9_parse_header - parse header arguments out of a packet
340 * @pdu: packet to parse
341 * @size: size of packet
342 * @type: type of request
343 * @tag: tag of packet
344 * @rewind: set if we need to rewind offset afterwards
348 p9_parse_header(struct p9_fcall
*pdu
, int32_t *size
, int8_t *type
, int16_t *tag
,
354 int offset
= pdu
->offset
;
361 err
= p9pdu_readf(pdu
, 0, "dbw", &r_size
, &r_type
, &r_tag
);
363 goto rewind_and_exit
;
369 P9_DPRINTK(P9_DEBUG_9P
, "<<< size=%d type: %d tag: %d\n", pdu
->size
,
382 pdu
->offset
= offset
;
385 EXPORT_SYMBOL(p9_parse_header
);
388 * p9_check_errors - check 9p packet for error return and process it
389 * @c: current client instance
390 * @req: request to parse and check for error conditions
392 * returns error code if one is discovered, otherwise returns 0
394 * this will have to be more complicated if we have multiple
398 static int p9_check_errors(struct p9_client
*c
, struct p9_req_t
*req
)
403 err
= p9_parse_header(req
->rc
, NULL
, &type
, NULL
, 0);
405 P9_DPRINTK(P9_DEBUG_ERROR
, "couldn't parse header %d\n", err
);
409 if (type
== P9_RERROR
) {
413 err
= p9pdu_readf(req
->rc
, c
->dotu
, "s?d", &ename
, &ecode
);
415 P9_DPRINTK(P9_DEBUG_ERROR
, "couldn't parse error%d\n",
423 if (!err
|| !IS_ERR_VALUE(err
))
424 err
= p9_errstr2errno(ename
, strlen(ename
));
426 P9_DPRINTK(P9_DEBUG_9P
, "<<< RERROR (%d) %s\n", -ecode
, ename
);
436 * p9_client_flush - flush (cancel) a request
438 * @oldreq: request to cancel
440 * This sents a flush for a particular requests and links
441 * the flush request to the original request. The current
442 * code only supports a single flush request although the protocol
443 * allows for multiple flush requests to be sent for a single request.
447 static int p9_client_flush(struct p9_client
*c
, struct p9_req_t
*oldreq
)
449 struct p9_req_t
*req
;
453 err
= p9_parse_header(oldreq
->tc
, NULL
, NULL
, &oldtag
, 1);
457 P9_DPRINTK(P9_DEBUG_9P
, ">>> TFLUSH tag %d\n", oldtag
);
459 req
= p9_client_rpc(c
, P9_TFLUSH
, "w", oldtag
);
464 /* if we haven't received a response for oldreq,
465 remove it from the list. */
467 if (oldreq
->status
== REQ_STATUS_FLSH
)
468 list_del(&oldreq
->req_list
);
469 spin_unlock(&c
->lock
);
476 * p9_client_rpc - issue a request and wait for a response
478 * @type: type of request
479 * @fmt: protocol format string (see protocol.c)
481 * Returns request structure (which client must free using p9_free_req)
484 static struct p9_req_t
*
485 p9_client_rpc(struct p9_client
*c
, int8_t type
, const char *fmt
, ...)
489 struct p9_req_t
*req
;
493 P9_DPRINTK(P9_DEBUG_MUX
, "client %p op %d\n", c
, type
);
495 if (c
->status
!= Connected
)
496 return ERR_PTR(-EIO
);
498 if (signal_pending(current
)) {
500 clear_thread_flag(TIF_SIGPENDING
);
505 if (type
!= P9_TVERSION
) {
506 tag
= p9_idpool_get(c
->tagpool
);
508 return ERR_PTR(-ENOMEM
);
511 req
= p9_tag_alloc(c
, tag
);
515 /* marshall the data */
516 p9pdu_prepare(req
->tc
, tag
, type
);
518 err
= p9pdu_vwritef(req
->tc
, c
->dotu
, fmt
, ap
);
520 p9pdu_finalize(req
->tc
);
522 err
= c
->trans_mod
->request(c
, req
);
524 c
->status
= Disconnected
;
528 P9_DPRINTK(P9_DEBUG_MUX
, "wait %p tag: %d\n", req
->wq
, tag
);
529 err
= wait_event_interruptible(*req
->wq
,
530 req
->status
>= REQ_STATUS_RCVD
);
531 P9_DPRINTK(P9_DEBUG_MUX
, "wait %p tag: %d returned %d\n",
534 if (req
->status
== REQ_STATUS_ERROR
) {
535 P9_DPRINTK(P9_DEBUG_ERROR
, "req_status error %d\n", req
->t_err
);
539 if ((err
== -ERESTARTSYS
) && (c
->status
== Connected
)) {
540 P9_DPRINTK(P9_DEBUG_MUX
, "flushing\n");
542 clear_thread_flag(TIF_SIGPENDING
);
544 if (c
->trans_mod
->cancel(c
, req
))
545 p9_client_flush(c
, req
);
547 /* if we received the response anyway, don't signal error */
548 if (req
->status
== REQ_STATUS_RCVD
)
553 spin_lock_irqsave(¤t
->sighand
->siglock
, flags
);
555 spin_unlock_irqrestore(¤t
->sighand
->siglock
, flags
);
561 err
= p9_check_errors(c
, req
);
563 P9_DPRINTK(P9_DEBUG_MUX
, "exit: client %p op %d\n", c
, type
);
568 P9_DPRINTK(P9_DEBUG_MUX
, "exit: client %p op %d error: %d\n", c
, type
,
574 static struct p9_fid
*p9_fid_create(struct p9_client
*clnt
)
580 P9_DPRINTK(P9_DEBUG_FID
, "clnt %p\n", clnt
);
581 fid
= kmalloc(sizeof(struct p9_fid
), GFP_KERNEL
);
583 return ERR_PTR(-ENOMEM
);
585 ret
= p9_idpool_get(clnt
->fidpool
);
592 memset(&fid
->qid
, 0, sizeof(struct p9_qid
));
594 fid
->uid
= current_fsuid();
597 spin_lock_irqsave(&clnt
->lock
, flags
);
598 list_add(&fid
->flist
, &clnt
->fidlist
);
599 spin_unlock_irqrestore(&clnt
->lock
, flags
);
608 static void p9_fid_destroy(struct p9_fid
*fid
)
610 struct p9_client
*clnt
;
613 P9_DPRINTK(P9_DEBUG_FID
, "fid %d\n", fid
->fid
);
615 p9_idpool_put(fid
->fid
, clnt
->fidpool
);
616 spin_lock_irqsave(&clnt
->lock
, flags
);
617 list_del(&fid
->flist
);
618 spin_unlock_irqrestore(&clnt
->lock
, flags
);
623 int p9_client_version(struct p9_client
*c
)
626 struct p9_req_t
*req
;
630 P9_DPRINTK(P9_DEBUG_9P
, ">>> TVERSION msize %d extended %d\n",
632 req
= p9_client_rpc(c
, P9_TVERSION
, "ds", c
->msize
,
633 c
->dotu
? "9P2000.u" : "9P2000");
637 err
= p9pdu_readf(req
->rc
, c
->dotu
, "ds", &msize
, &version
);
639 P9_DPRINTK(P9_DEBUG_9P
, "version error %d\n", err
);
640 p9pdu_dump(1, req
->rc
);
644 P9_DPRINTK(P9_DEBUG_9P
, "<<< RVERSION msize %d %s\n", msize
, version
);
645 if (!memcmp(version
, "9P2000.u", 8))
647 else if (!memcmp(version
, "9P2000", 6))
654 if (msize
< c
->msize
)
663 EXPORT_SYMBOL(p9_client_version
);
665 struct p9_client
*p9_client_create(const char *dev_name
, char *options
)
668 struct p9_client
*clnt
;
671 clnt
= kmalloc(sizeof(struct p9_client
), GFP_KERNEL
);
673 return ERR_PTR(-ENOMEM
);
675 clnt
->trans_mod
= NULL
;
677 spin_lock_init(&clnt
->lock
);
678 INIT_LIST_HEAD(&clnt
->fidlist
);
682 err
= parse_opts(options
, clnt
);
686 if (!clnt
->trans_mod
)
687 clnt
->trans_mod
= v9fs_get_default_trans();
689 if (clnt
->trans_mod
== NULL
) {
690 err
= -EPROTONOSUPPORT
;
691 P9_DPRINTK(P9_DEBUG_ERROR
,
692 "No transport defined or default transport\n");
696 clnt
->fidpool
= p9_idpool_create();
697 if (IS_ERR(clnt
->fidpool
)) {
698 err
= PTR_ERR(clnt
->fidpool
);
699 clnt
->fidpool
= NULL
;
703 P9_DPRINTK(P9_DEBUG_MUX
, "clnt %p trans %p msize %d dotu %d\n",
704 clnt
, clnt
->trans_mod
, clnt
->msize
, clnt
->dotu
);
706 err
= clnt
->trans_mod
->create(clnt
, dev_name
, options
);
708 goto destroy_fidpool
;
710 if ((clnt
->msize
+P9_IOHDRSZ
) > clnt
->trans_mod
->maxsize
)
711 clnt
->msize
= clnt
->trans_mod
->maxsize
-P9_IOHDRSZ
;
713 err
= p9_client_version(clnt
);
720 clnt
->trans_mod
->close(clnt
);
722 p9_idpool_destroy(clnt
->fidpool
);
724 v9fs_put_trans(clnt
->trans_mod
);
729 EXPORT_SYMBOL(p9_client_create
);
731 void p9_client_destroy(struct p9_client
*clnt
)
733 struct p9_fid
*fid
, *fidptr
;
735 P9_DPRINTK(P9_DEBUG_MUX
, "clnt %p\n", clnt
);
738 clnt
->trans_mod
->close(clnt
);
740 v9fs_put_trans(clnt
->trans_mod
);
742 list_for_each_entry_safe(fid
, fidptr
, &clnt
->fidlist
, flist
)
746 p9_idpool_destroy(clnt
->fidpool
);
748 p9_tag_cleanup(clnt
);
752 EXPORT_SYMBOL(p9_client_destroy
);
754 void p9_client_disconnect(struct p9_client
*clnt
)
756 P9_DPRINTK(P9_DEBUG_9P
, "clnt %p\n", clnt
);
757 clnt
->status
= Disconnected
;
759 EXPORT_SYMBOL(p9_client_disconnect
);
761 struct p9_fid
*p9_client_attach(struct p9_client
*clnt
, struct p9_fid
*afid
,
762 char *uname
, u32 n_uname
, char *aname
)
765 struct p9_req_t
*req
;
769 P9_DPRINTK(P9_DEBUG_9P
, ">>> TATTACH afid %d uname %s aname %s\n",
770 afid
? afid
->fid
: -1, uname
, aname
);
773 fid
= p9_fid_create(clnt
);
780 req
= p9_client_rpc(clnt
, P9_TATTACH
, "ddss?d", fid
->fid
,
781 afid
? afid
->fid
: P9_NOFID
, uname
, aname
, n_uname
);
787 err
= p9pdu_readf(req
->rc
, clnt
->dotu
, "Q", &qid
);
789 p9pdu_dump(1, req
->rc
);
790 p9_free_req(clnt
, req
);
794 P9_DPRINTK(P9_DEBUG_9P
, "<<< RATTACH qid %x.%llx.%x\n",
796 (unsigned long long)qid
.path
,
799 memmove(&fid
->qid
, &qid
, sizeof(struct p9_qid
));
801 p9_free_req(clnt
, req
);
809 EXPORT_SYMBOL(p9_client_attach
);
812 p9_client_auth(struct p9_client
*clnt
, char *uname
, u32 n_uname
, char *aname
)
815 struct p9_req_t
*req
;
819 P9_DPRINTK(P9_DEBUG_9P
, ">>> TAUTH uname %s aname %s\n", uname
, aname
);
822 afid
= p9_fid_create(clnt
);
829 req
= p9_client_rpc(clnt
, P9_TAUTH
, "dss?d",
830 afid
? afid
->fid
: P9_NOFID
, uname
, aname
, n_uname
);
836 err
= p9pdu_readf(req
->rc
, clnt
->dotu
, "Q", &qid
);
838 p9pdu_dump(1, req
->rc
);
839 p9_free_req(clnt
, req
);
843 P9_DPRINTK(P9_DEBUG_9P
, "<<< RAUTH qid %x.%llx.%x\n",
845 (unsigned long long)qid
.path
,
848 memmove(&afid
->qid
, &qid
, sizeof(struct p9_qid
));
849 p9_free_req(clnt
, req
);
854 p9_fid_destroy(afid
);
857 EXPORT_SYMBOL(p9_client_auth
);
859 struct p9_fid
*p9_client_walk(struct p9_fid
*oldfid
, int nwname
, char **wnames
,
863 struct p9_client
*clnt
;
865 struct p9_qid
*wqids
;
866 struct p9_req_t
*req
;
867 int16_t nwqids
, count
;
872 fid
= p9_fid_create(clnt
);
879 fid
->uid
= oldfid
->uid
;
884 P9_DPRINTK(P9_DEBUG_9P
, ">>> TWALK fids %d,%d nwname %d wname[0] %s\n",
885 oldfid
->fid
, fid
->fid
, nwname
, wnames
? wnames
[0] : NULL
);
887 req
= p9_client_rpc(clnt
, P9_TWALK
, "ddT", oldfid
->fid
, fid
->fid
,
894 err
= p9pdu_readf(req
->rc
, clnt
->dotu
, "R", &nwqids
, &wqids
);
896 p9pdu_dump(1, req
->rc
);
897 p9_free_req(clnt
, req
);
900 p9_free_req(clnt
, req
);
902 P9_DPRINTK(P9_DEBUG_9P
, "<<< RWALK nwqid %d:\n", nwqids
);
904 if (nwqids
!= nwname
) {
909 for (count
= 0; count
< nwqids
; count
++)
910 P9_DPRINTK(P9_DEBUG_9P
, "<<< [%d] %x.%llx.%x\n",
911 count
, wqids
[count
].type
,
912 (unsigned long long)wqids
[count
].path
,
913 wqids
[count
].version
);
916 memmove(&fid
->qid
, &wqids
[nwqids
- 1], sizeof(struct p9_qid
));
918 fid
->qid
= oldfid
->qid
;
923 p9_client_clunk(fid
);
927 if (fid
&& (fid
!= oldfid
))
932 EXPORT_SYMBOL(p9_client_walk
);
934 int p9_client_open(struct p9_fid
*fid
, int mode
)
937 struct p9_client
*clnt
;
938 struct p9_req_t
*req
;
942 P9_DPRINTK(P9_DEBUG_9P
, ">>> TOPEN fid %d mode %d\n", fid
->fid
, mode
);
949 req
= p9_client_rpc(clnt
, P9_TOPEN
, "db", fid
->fid
, mode
);
955 err
= p9pdu_readf(req
->rc
, clnt
->dotu
, "Qd", &qid
, &iounit
);
957 p9pdu_dump(1, req
->rc
);
961 P9_DPRINTK(P9_DEBUG_9P
, "<<< ROPEN qid %x.%llx.%x iounit %x\n",
963 (unsigned long long)qid
.path
,
964 qid
.version
, iounit
);
967 fid
->iounit
= iounit
;
970 p9_free_req(clnt
, req
);
974 EXPORT_SYMBOL(p9_client_open
);
976 int p9_client_fcreate(struct p9_fid
*fid
, char *name
, u32 perm
, int mode
,
980 struct p9_client
*clnt
;
981 struct p9_req_t
*req
;
985 P9_DPRINTK(P9_DEBUG_9P
, ">>> TCREATE fid %d name %s perm %d mode %d\n",
986 fid
->fid
, name
, perm
, mode
);
993 req
= p9_client_rpc(clnt
, P9_TCREATE
, "dsdb?s", fid
->fid
, name
, perm
,
1000 err
= p9pdu_readf(req
->rc
, clnt
->dotu
, "Qd", &qid
, &iounit
);
1002 p9pdu_dump(1, req
->rc
);
1003 goto free_and_error
;
1006 P9_DPRINTK(P9_DEBUG_9P
, "<<< RCREATE qid %x.%llx.%x iounit %x\n",
1008 (unsigned long long)qid
.path
,
1009 qid
.version
, iounit
);
1012 fid
->iounit
= iounit
;
1015 p9_free_req(clnt
, req
);
1019 EXPORT_SYMBOL(p9_client_fcreate
);
1021 int p9_client_clunk(struct p9_fid
*fid
)
1024 struct p9_client
*clnt
;
1025 struct p9_req_t
*req
;
1027 P9_DPRINTK(P9_DEBUG_9P
, ">>> TCLUNK fid %d\n", fid
->fid
);
1031 req
= p9_client_rpc(clnt
, P9_TCLUNK
, "d", fid
->fid
);
1037 P9_DPRINTK(P9_DEBUG_9P
, "<<< RCLUNK fid %d\n", fid
->fid
);
1039 p9_free_req(clnt
, req
);
1040 p9_fid_destroy(fid
);
1045 EXPORT_SYMBOL(p9_client_clunk
);
1047 int p9_client_remove(struct p9_fid
*fid
)
1050 struct p9_client
*clnt
;
1051 struct p9_req_t
*req
;
1053 P9_DPRINTK(P9_DEBUG_9P
, ">>> TREMOVE fid %d\n", fid
->fid
);
1057 req
= p9_client_rpc(clnt
, P9_TREMOVE
, "d", fid
->fid
);
1063 P9_DPRINTK(P9_DEBUG_9P
, "<<< RREMOVE fid %d\n", fid
->fid
);
1065 p9_free_req(clnt
, req
);
1066 p9_fid_destroy(fid
);
1071 EXPORT_SYMBOL(p9_client_remove
);
1074 p9_client_read(struct p9_fid
*fid
, char *data
, char __user
*udata
, u64 offset
,
1077 int err
, rsize
, total
;
1078 struct p9_client
*clnt
;
1079 struct p9_req_t
*req
;
1082 P9_DPRINTK(P9_DEBUG_9P
, ">>> TREAD fid %d offset %llu %d\n", fid
->fid
,
1083 (long long unsigned) offset
, count
);
1088 rsize
= fid
->iounit
;
1089 if (!rsize
|| rsize
> clnt
->msize
-P9_IOHDRSZ
)
1090 rsize
= clnt
->msize
- P9_IOHDRSZ
;
1095 req
= p9_client_rpc(clnt
, P9_TREAD
, "dqd", fid
->fid
, offset
, rsize
);
1101 err
= p9pdu_readf(req
->rc
, clnt
->dotu
, "D", &count
, &dataptr
);
1103 p9pdu_dump(1, req
->rc
);
1104 goto free_and_error
;
1107 P9_DPRINTK(P9_DEBUG_9P
, "<<< RREAD count %d\n", count
);
1110 memmove(data
, dataptr
, count
);
1114 err
= copy_to_user(udata
, dataptr
, count
);
1117 goto free_and_error
;
1121 p9_free_req(clnt
, req
);
1125 p9_free_req(clnt
, req
);
1129 EXPORT_SYMBOL(p9_client_read
);
1132 p9_client_write(struct p9_fid
*fid
, char *data
, const char __user
*udata
,
1133 u64 offset
, u32 count
)
1135 int err
, rsize
, total
;
1136 struct p9_client
*clnt
;
1137 struct p9_req_t
*req
;
1139 P9_DPRINTK(P9_DEBUG_9P
, ">>> TWRITE fid %d offset %llu count %d\n",
1140 fid
->fid
, (long long unsigned) offset
, count
);
1145 rsize
= fid
->iounit
;
1146 if (!rsize
|| rsize
> clnt
->msize
-P9_IOHDRSZ
)
1147 rsize
= clnt
->msize
- P9_IOHDRSZ
;
1152 req
= p9_client_rpc(clnt
, P9_TWRITE
, "dqD", fid
->fid
, offset
,
1155 req
= p9_client_rpc(clnt
, P9_TWRITE
, "dqU", fid
->fid
, offset
,
1162 err
= p9pdu_readf(req
->rc
, clnt
->dotu
, "d", &count
);
1164 p9pdu_dump(1, req
->rc
);
1165 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
);
1204 p9pdu_dump(1, req
->rc
);
1205 p9_free_req(clnt
, req
);
1209 P9_DPRINTK(P9_DEBUG_9P
,
1210 "<<< RSTAT sz=%x type=%x dev=%x qid=%x.%llx.%x\n"
1211 "<<< mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n"
1212 "<<< name=%s uid=%s gid=%s muid=%s extension=(%s)\n"
1213 "<<< uid=%d gid=%d n_muid=%d\n",
1214 ret
->size
, ret
->type
, ret
->dev
, ret
->qid
.type
,
1215 (unsigned long long)ret
->qid
.path
, ret
->qid
.version
, ret
->mode
,
1216 ret
->atime
, ret
->mtime
, (unsigned long long)ret
->length
,
1217 ret
->name
, ret
->uid
, ret
->gid
, ret
->muid
, ret
->extension
,
1218 ret
->n_uid
, ret
->n_gid
, ret
->n_muid
);
1220 p9_free_req(clnt
, req
);
1225 return ERR_PTR(err
);
1227 EXPORT_SYMBOL(p9_client_stat
);
1229 static int p9_client_statsize(struct p9_wstat
*wst
, int optional
)
1233 /* NOTE: size shouldn't include its own length */
1234 /* size[2] type[2] dev[4] qid[13] */
1235 /* mode[4] atime[4] mtime[4] length[8]*/
1236 /* name[s] uid[s] gid[s] muid[s] */
1237 ret
= 2+4+13+4+4+4+8+2+2+2+2;
1240 ret
+= strlen(wst
->name
);
1242 ret
+= strlen(wst
->uid
);
1244 ret
+= strlen(wst
->gid
);
1246 ret
+= strlen(wst
->muid
);
1249 ret
+= 2+4+4+4; /* extension[s] n_uid[4] n_gid[4] n_muid[4] */
1251 ret
+= strlen(wst
->extension
);
1257 int p9_client_wstat(struct p9_fid
*fid
, struct p9_wstat
*wst
)
1260 struct p9_req_t
*req
;
1261 struct p9_client
*clnt
;
1265 wst
->size
= p9_client_statsize(wst
, clnt
->dotu
);
1266 P9_DPRINTK(P9_DEBUG_9P
, ">>> TWSTAT fid %d\n", fid
->fid
);
1267 P9_DPRINTK(P9_DEBUG_9P
,
1268 " sz=%x type=%x dev=%x qid=%x.%llx.%x\n"
1269 " mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n"
1270 " name=%s uid=%s gid=%s muid=%s extension=(%s)\n"
1271 " uid=%d gid=%d n_muid=%d\n",
1272 wst
->size
, wst
->type
, wst
->dev
, wst
->qid
.type
,
1273 (unsigned long long)wst
->qid
.path
, wst
->qid
.version
, wst
->mode
,
1274 wst
->atime
, wst
->mtime
, (unsigned long long)wst
->length
,
1275 wst
->name
, wst
->uid
, wst
->gid
, wst
->muid
, wst
->extension
,
1276 wst
->n_uid
, wst
->n_gid
, wst
->n_muid
);
1278 req
= p9_client_rpc(clnt
, P9_TWSTAT
, "dwS", fid
->fid
, wst
->size
+2, wst
);
1284 P9_DPRINTK(P9_DEBUG_9P
, "<<< RWSTAT fid %d\n", fid
->fid
);
1286 p9_free_req(clnt
, req
);
1290 EXPORT_SYMBOL(p9_client_wstat
);