aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Van Hensbergen <ericvh@gmail.com>2008-10-13 21:36:14 -0400
committerEric Van Hensbergen <ericvh@gmail.com>2008-10-17 12:04:43 -0400
commit6936bf60d2c407449c09e3f28ec0301e1f937106 (patch)
tree222ca66d663958ff44e7d196f17d1ed0d2cb37d6
parent06b55b464ee5b305aca75cb7d9424b184bf07f68 (diff)
9p: encapsulate version function
Alsmot all 9P client wire functions have their own (set of) functions. Tversion is an exception as its encapsulated into the client_create code. This patch moves the protocol specifics of this to a function to match the rest of the code. Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
-rw-r--r--net/9p/client.c74
1 files changed, 44 insertions, 30 deletions
diff --git a/net/9p/client.c b/net/9p/client.c
index 90ee9efeede3..a9982df00a3a 100644
--- a/net/9p/client.c
+++ b/net/9p/client.c
@@ -587,16 +587,56 @@ static void p9_fid_destroy(struct p9_fid *fid)
587 kfree(fid); 587 kfree(fid);
588} 588}
589 589
590struct p9_client *p9_client_create(const char *dev_name, char *options) 590static int p9_client_version(struct p9_client *clnt)
591{ 591{
592 int err, n; 592 int err = 0;
593 struct p9_client *clnt;
594 struct p9_fcall *tc, *rc; 593 struct p9_fcall *tc, *rc;
595 struct p9_str *version; 594 struct p9_str *version;
596 595
596 P9_DPRINTK(P9_DEBUG_9P, "%p\n", clnt);
597 err = 0; 597 err = 0;
598 tc = NULL; 598 tc = NULL;
599 rc = NULL; 599 rc = NULL;
600
601 tc = p9_create_tversion(clnt->msize,
602 clnt->dotu ? "9P2000.u" : "9P2000");
603 if (IS_ERR(tc)) {
604 err = PTR_ERR(tc);
605 tc = NULL;
606 goto error;
607 }
608
609 err = p9_client_rpc(clnt, tc, &rc);
610 if (err)
611 goto error;
612
613 version = &rc->params.rversion.version;
614 if (version->len == 8 && !memcmp(version->str, "9P2000.u", 8))
615 clnt->dotu = 1;
616 else if (version->len == 6 && !memcmp(version->str, "9P2000", 6))
617 clnt->dotu = 0;
618 else {
619 err = -EREMOTEIO;
620 goto error;
621 }
622
623 if (rc->params.rversion.msize < clnt->msize)
624 clnt->msize = rc->params.rversion.msize;
625
626error:
627 kfree(tc);
628 kfree(rc);
629
630 return err;
631}
632EXPORT_SYMBOL(p9_client_auth);
633
634struct p9_client *p9_client_create(const char *dev_name, char *options)
635{
636 int err;
637 struct p9_client *clnt;
638
639 err = 0;
600 clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL); 640 clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL);
601 if (!clnt) 641 if (!clnt)
602 return ERR_PTR(-ENOMEM); 642 return ERR_PTR(-ENOMEM);
@@ -628,7 +668,6 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
628 P9_DPRINTK(P9_DEBUG_9P, "clnt %p trans %p msize %d dotu %d\n", 668 P9_DPRINTK(P9_DEBUG_9P, "clnt %p trans %p msize %d dotu %d\n",
629 clnt, clnt->trans_mod, clnt->msize, clnt->dotu); 669 clnt, clnt->trans_mod, clnt->msize, clnt->dotu);
630 670
631
632 err = clnt->trans_mod->create(clnt, dev_name, options); 671 err = clnt->trans_mod->create(clnt, dev_name, options);
633 if (err) 672 if (err)
634 goto error; 673 goto error;
@@ -636,38 +675,13 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
636 if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize) 675 if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize)
637 clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ; 676 clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ;
638 677
639 tc = p9_create_tversion(clnt->msize, clnt->dotu?"9P2000.u":"9P2000"); 678 err = p9_client_version(clnt);
640 if (IS_ERR(tc)) {
641 err = PTR_ERR(tc);
642 tc = NULL;
643 goto error;
644 }
645
646 err = p9_client_rpc(clnt, tc, &rc);
647 if (err) 679 if (err)
648 goto error; 680 goto error;
649 681
650 version = &rc->params.rversion.version;
651 if (version->len == 8 && !memcmp(version->str, "9P2000.u", 8))
652 clnt->dotu = 1;
653 else if (version->len == 6 && !memcmp(version->str, "9P2000", 6))
654 clnt->dotu = 0;
655 else {
656 err = -EREMOTEIO;
657 goto error;
658 }
659
660 n = rc->params.rversion.msize;
661 if (n < clnt->msize)
662 clnt->msize = n;
663
664 kfree(tc);
665 kfree(rc);
666 return clnt; 682 return clnt;
667 683
668error: 684error:
669 kfree(tc);
670 kfree(rc);
671 p9_client_destroy(clnt); 685 p9_client_destroy(clnt);
672 return ERR_PTR(err); 686 return ERR_PTR(err);
673} 687}