Commit 6936bf60 authored by Eric Van Hensbergen's avatar Eric Van Hensbergen

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: default avatarEric Van Hensbergen <ericvh@gmail.com>


parent 06b55b46
...@@ -587,16 +587,56 @@ static void p9_fid_destroy(struct p9_fid *fid) ...@@ -587,16 +587,56 @@ static void p9_fid_destroy(struct p9_fid *fid)
kfree(fid); kfree(fid);
} }
struct p9_client *p9_client_create(const char *dev_name, char *options) static int p9_client_version(struct p9_client *clnt)
{ {
int err, n; int err = 0;
struct p9_client *clnt;
struct p9_fcall *tc, *rc; struct p9_fcall *tc, *rc;
struct p9_str *version; struct p9_str *version;
P9_DPRINTK(P9_DEBUG_9P, "%p\n", clnt);
err = 0; err = 0;
tc = NULL; tc = NULL;
rc = NULL; rc = NULL;
tc = p9_create_tversion(clnt->msize,
clnt->dotu ? "9P2000.u" : "9P2000");
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_client_rpc(clnt, tc, &rc);
if (err)
goto error;
version = &rc->params.rversion.version;
if (version->len == 8 && !memcmp(version->str, "9P2000.u", 8))
clnt->dotu = 1;
else if (version->len == 6 && !memcmp(version->str, "9P2000", 6))
clnt->dotu = 0;
else {
err = -EREMOTEIO;
goto error;
}
if (rc->params.rversion.msize < clnt->msize)
clnt->msize = rc->params.rversion.msize;
error:
kfree(tc);
kfree(rc);
return err;
}
EXPORT_SYMBOL(p9_client_auth);
struct p9_client *p9_client_create(const char *dev_name, char *options)
{
int err;
struct p9_client *clnt;
err = 0;
clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL); clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL);
if (!clnt) if (!clnt)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -628,7 +668,6 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) ...@@ -628,7 +668,6 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
P9_DPRINTK(P9_DEBUG_9P, "clnt %p trans %p msize %d dotu %d\n", P9_DPRINTK(P9_DEBUG_9P, "clnt %p trans %p msize %d dotu %d\n",
clnt, clnt->trans_mod, clnt->msize, clnt->dotu); clnt, clnt->trans_mod, clnt->msize, clnt->dotu);
err = clnt->trans_mod->create(clnt, dev_name, options); err = clnt->trans_mod->create(clnt, dev_name, options);
if (err) if (err)
goto error; goto error;
...@@ -636,38 +675,13 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) ...@@ -636,38 +675,13 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize) if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize)
clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ; clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ;
tc = p9_create_tversion(clnt->msize, clnt->dotu?"9P2000.u":"9P2000"); err = p9_client_version(clnt);
if (IS_ERR(tc)) {
err = PTR_ERR(tc);
tc = NULL;
goto error;
}
err = p9_client_rpc(clnt, tc, &rc);
if (err) if (err)
goto error; goto error;
version = &rc->params.rversion.version;
if (version->len == 8 && !memcmp(version->str, "9P2000.u", 8))
clnt->dotu = 1;
else if (version->len == 6 && !memcmp(version->str, "9P2000", 6))
clnt->dotu = 0;
else {
err = -EREMOTEIO;
goto error;
}
n = rc->params.rversion.msize;
if (n < clnt->msize)
clnt->msize = n;
kfree(tc);
kfree(rc);
return clnt; return clnt;
error: error:
kfree(tc);
kfree(rc);
p9_client_destroy(clnt); p9_client_destroy(clnt);
return ERR_PTR(err); return ERR_PTR(err);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment