#include <linux/file.h>
#include <linux/parser.h>
#include <net/9p/9p.h>
+#include <net/9p/client.h>
#include <net/9p/transport.h>
#define P9_PORT 564
* @mux_list: list link for mux to manage multiple connections (?)
* @msize: maximum size for connection (dup)
* @extended: 9p2000.u flag (dup)
- * @trans: reference to transport instance for this connection
+ * @client: reference to client instance for this connection
* @tagpool: id accounting for transactions
* @err: error state
* @req_list: accounting for requests which have been sent
struct list_head mux_list;
int msize;
unsigned char extended;
- struct p9_trans *trans;
+ struct p9_client *client;
struct p9_idpool *tagpool;
int err;
struct list_head req_list;
static void p9_write_work(struct work_struct *work);
static void p9_pollwait(struct file *filp, wait_queue_head_t *wait_address,
poll_table *p);
-static int p9_fd_write(struct p9_trans *trans, void *v, int len);
-static int p9_fd_read(struct p9_trans *trans, void *v, int len);
+static int p9_fd_write(struct p9_client *client, void *v, int len);
+static int p9_fd_read(struct p9_client *client, void *v, int len);
static DEFINE_SPINLOCK(p9_poll_lock);
static LIST_HEAD(p9_poll_pending_list);
static struct task_struct *p9_poll_task;
static void p9_conn_destroy(struct p9_conn *);
-static unsigned int p9_fd_poll(struct p9_trans *trans,
+static unsigned int p9_fd_poll(struct p9_client *client,
struct poll_table_struct *pt);
#ifdef P9_NONBLOCK
/**
* p9_conn_create - allocate and initialize the per-session mux data
- * @trans: transport structure
+ * @client: client instance
*
* Note: Creates the polling task if this is the first session.
*/
-static struct p9_conn *p9_conn_create(struct p9_trans *trans)
+static struct p9_conn *p9_conn_create(struct p9_client *client)
{
int i, n;
struct p9_conn *m;
- P9_DPRINTK(P9_DEBUG_MUX, "transport %p msize %d\n", trans,
- trans->msize);
+ P9_DPRINTK(P9_DEBUG_MUX, "client %p msize %d\n", client, client->msize);
m = kzalloc(sizeof(struct p9_conn), GFP_KERNEL);
if (!m)
return ERR_PTR(-ENOMEM);
spin_lock_init(&m->lock);
INIT_LIST_HEAD(&m->mux_list);
- m->msize = trans->msize;
- m->extended = trans->extended;
- m->trans = trans;
+ m->msize = client->msize;
+ m->extended = client->dotu;
+ m->client = client;
m->tagpool = p9_idpool_create();
if (IS_ERR(m->tagpool)) {
kfree(m);
INIT_LIST_HEAD(&m->poll_pending_link);
init_poll_funcptr(&m->pt, p9_pollwait);
- n = p9_fd_poll(trans, &m->pt);
+ n = p9_fd_poll(client, &m->pt);
if (n & POLLIN) {
P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m);
set_bit(Rpending, &m->wsched);
p9_conn_cancel(m, -ECONNRESET);
- m->trans = NULL;
+ m->client = NULL;
p9_idpool_destroy(m->tagpool);
kfree(m);
}
if (m->err < 0)
return;
- n = p9_fd_poll(m->trans, NULL);
+ n = p9_fd_poll(m->client, NULL);
if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) {
P9_DPRINTK(P9_DEBUG_MUX, "error mux %p err %d\n", m, n);
if (n >= 0)
P9_DPRINTK(P9_DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos,
m->wsize);
clear_bit(Wpending, &m->wsched);
- err = p9_fd_write(m->trans, m->wbuf + m->wpos, m->wsize - m->wpos);
+ err = p9_fd_write(m->client, m->wbuf + m->wpos, m->wsize - m->wpos);
P9_DPRINTK(P9_DEBUG_MUX, "mux %p sent %d bytes\n", m, err);
if (err == -EAGAIN) {
clear_bit(Wworksched, &m->wsched);
if (test_and_clear_bit(Wpending, &m->wsched))
n = POLLOUT;
else
- n = p9_fd_poll(m->trans, NULL);
+ n = p9_fd_poll(m->client, NULL);
if (n & POLLOUT) {
P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m);
}
clear_bit(Rpending, &m->wsched);
- err = p9_fd_read(m->trans, m->rbuf + m->rpos, m->msize - m->rpos);
+ err = p9_fd_read(m->client, m->rbuf + m->rpos, m->msize - m->rpos);
P9_DPRINTK(P9_DEBUG_MUX, "mux %p got %d bytes\n", m, err);
if (err == -EAGAIN) {
clear_bit(Rworksched, &m->wsched);
if (test_and_clear_bit(Rpending, &m->wsched))
n = POLLIN;
else
- n = p9_fd_poll(m->trans, NULL);
+ n = p9_fd_poll(m->client, NULL);
if (n & POLLIN) {
P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m);
if (test_and_clear_bit(Wpending, &m->wsched))
n = POLLOUT;
else
- n = p9_fd_poll(m->trans, NULL);
+ n = p9_fd_poll(m->client, NULL);
if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched))
queue_work(p9_mux_wq, &m->wq);
/**
* p9_fd_rpc- sends 9P request and waits until a response is available.
* The function can be interrupted.
- * @t: transport data
+ * @client: client instance
* @tc: request to be sent
* @rc: pointer where a pointer to the response is stored
*
*/
int
-p9_fd_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
+p9_fd_rpc(struct p9_client *client, struct p9_fcall *tc, struct p9_fcall **rc)
{
- struct p9_trans_fd *p = t->priv;
+ struct p9_trans_fd *p = client->trans;
struct p9_conn *m = p->conn;
int err, sigpending;
unsigned long flags;
if (r.err < 0)
err = r.err;
- if (err == -ERESTARTSYS && m->trans->status == Connected
+ if (err == -ERESTARTSYS && client->status == Connected
&& m->err == 0) {
if (p9_mux_flush_request(m, req)) {
/* wait until we get response of the flush message */
err = wait_event_interruptible(r.wqueue,
r.rcall || r.err);
} while (!r.rcall && !r.err && err == -ERESTARTSYS &&
- m->trans->status == Connected && !m->err);
+ client->status == Connected && !m->err);
err = -ERESTARTSYS;
}
return 0;
}
-static int p9_fd_open(struct p9_trans *trans, int rfd, int wfd)
+static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
{
struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd),
GFP_KERNEL);
return -EIO;
}
- trans->priv = ts;
- trans->status = Connected;
+ client->trans = ts;
+ client->status = Connected;
return 0;
}
-static int p9_socket_open(struct p9_trans *trans, struct socket *csocket)
+static int p9_socket_open(struct p9_client *client, struct socket *csocket)
{
int fd, ret;
return fd;
}
- ret = p9_fd_open(trans, fd, fd);
+ ret = p9_fd_open(client, fd, fd);
if (ret < 0) {
P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to open fd\n");
sockfd_put(csocket);
return ret;
}
- ((struct p9_trans_fd *)trans->priv)->rd->f_flags |= O_NONBLOCK;
+ ((struct p9_trans_fd *)client->trans)->rd->f_flags |= O_NONBLOCK;
return 0;
}
/**
* p9_fd_read- read from a fd
- * @trans: transport instance state
+ * @client: client instance
* @v: buffer to receive data into
* @len: size of receive buffer
*
*/
-static int p9_fd_read(struct p9_trans *trans, void *v, int len)
+static int p9_fd_read(struct p9_client *client, void *v, int len)
{
int ret;
struct p9_trans_fd *ts = NULL;
- if (trans && trans->status != Disconnected)
- ts = trans->priv;
+ if (client && client->status != Disconnected)
+ ts = client->trans;
if (!ts)
return -EREMOTEIO;
ret = kernel_read(ts->rd, ts->rd->f_pos, v, len);
if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
- trans->status = Disconnected;
+ client->status = Disconnected;
return ret;
}
/**
* p9_fd_write - write to a socket
- * @trans: transport instance state
+ * @client: client instance
* @v: buffer to send data from
* @len: size of send buffer
*
*/
-static int p9_fd_write(struct p9_trans *trans, void *v, int len)
+static int p9_fd_write(struct p9_client *client, void *v, int len)
{
int ret;
mm_segment_t oldfs;
struct p9_trans_fd *ts = NULL;
- if (trans && trans->status != Disconnected)
- ts = trans->priv;
+ if (client && client->status != Disconnected)
+ ts = client->trans;
if (!ts)
return -EREMOTEIO;
set_fs(oldfs);
if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
- trans->status = Disconnected;
+ client->status = Disconnected;
return ret;
}
static unsigned int
-p9_fd_poll(struct p9_trans *trans, struct poll_table_struct *pt)
+p9_fd_poll(struct p9_client *client, struct poll_table_struct *pt)
{
int ret, n;
struct p9_trans_fd *ts = NULL;
- if (trans && trans->status == Connected)
- ts = trans->priv;
+ if (client && client->status == Connected)
+ ts = client->trans;
if (!ts)
return -EREMOTEIO;
}
/**
- * p9_fd_close - shutdown socket
- * @trans: private socket structure
+ * p9_fd_close - shutdown file descriptor transport
+ * @client: client instance
*
*/
-static void p9_fd_close(struct p9_trans *trans)
+static void p9_fd_close(struct p9_client *client)
{
struct p9_trans_fd *ts;
- if (!trans)
+ if (!client)
return;
- ts = xchg(&trans->priv, NULL);
-
+ ts = client->trans;
if (!ts)
return;
+ client->status = Disconnected;
+
p9_conn_destroy(ts->conn);
- trans->status = Disconnected;
if (ts->rd)
fput(ts->rd);
if (ts->wr)
fput(ts->wr);
+
kfree(ts);
}
return 0;
}
-static struct p9_trans *
-p9_trans_create_tcp(const char *addr, char *args, int msize, unsigned char dotu)
+static int
+p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args)
{
int err;
- struct p9_trans *trans;
struct socket *csocket;
struct sockaddr_in sin_server;
struct p9_fd_opts opts;
- struct p9_trans_fd *p;
+ struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */
err = parse_opts(args, &opts);
if (err < 0)
- return ERR_PTR(err);
+ return err;
if (valid_ipaddr4(addr) < 0)
- return ERR_PTR(-EINVAL);
+ return -EINVAL;
csocket = NULL;
- trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
- if (!trans)
- return ERR_PTR(-ENOMEM);
- trans->msize = msize;
- trans->extended = dotu;
- trans->rpc = p9_fd_rpc;
- trans->close = p9_fd_close;
sin_server.sin_family = AF_INET;
sin_server.sin_addr.s_addr = in_aton(addr);
goto error;
}
- err = p9_socket_open(trans, csocket);
+ err = p9_socket_open(client, csocket);
if (err < 0)
goto error;
- p = (struct p9_trans_fd *) trans->priv;
- p->conn = p9_conn_create(trans);
+ p = (struct p9_trans_fd *) client->trans;
+ p->conn = p9_conn_create(client);
if (IS_ERR(p->conn)) {
err = PTR_ERR(p->conn);
p->conn = NULL;
goto error;
}
- return trans;
+ return 0;
error:
if (csocket)
sock_release(csocket);
- kfree(trans);
- return ERR_PTR(err);
+ kfree(p);
+
+ return err;
}
-static struct p9_trans *
-p9_trans_create_unix(const char *addr, char *args, int msize,
- unsigned char dotu)
+static int
+p9_fd_create_unix(struct p9_client *client, const char *addr, char *args)
{
int err;
struct socket *csocket;
struct sockaddr_un sun_server;
- struct p9_trans *trans;
- struct p9_trans_fd *p;
+ struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */
csocket = NULL;
- trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
- if (!trans)
- return ERR_PTR(-ENOMEM);
-
- trans->rpc = p9_fd_rpc;
- trans->close = p9_fd_close;
if (strlen(addr) > UNIX_PATH_MAX) {
P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n",
goto error;
}
- err = p9_socket_open(trans, csocket);
+ err = p9_socket_open(client, csocket);
if (err < 0)
goto error;
- trans->msize = msize;
- trans->extended = dotu;
- p = (struct p9_trans_fd *) trans->priv;
- p->conn = p9_conn_create(trans);
+ p = (struct p9_trans_fd *) client->trans;
+ p->conn = p9_conn_create(client);
if (IS_ERR(p->conn)) {
err = PTR_ERR(p->conn);
p->conn = NULL;
goto error;
}
- return trans;
+ return 0;
error:
if (csocket)
sock_release(csocket);
- kfree(trans);
- return ERR_PTR(err);
+ kfree(p);
+ return err;
}
-static struct p9_trans *
-p9_trans_create_fd(const char *name, char *args, int msize,
- unsigned char extended)
+static int
+p9_fd_create(struct p9_client *client, const char *addr, char *args)
{
int err;
- struct p9_trans *trans;
struct p9_fd_opts opts;
- struct p9_trans_fd *p;
+ struct p9_trans_fd *p = NULL; /* this get allocated in p9_fd_open */
parse_opts(args, &opts);
if (opts.rfd == ~0 || opts.wfd == ~0) {
printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n");
- return ERR_PTR(-ENOPROTOOPT);
+ return -ENOPROTOOPT;
}
- trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
- if (!trans)
- return ERR_PTR(-ENOMEM);
-
- trans->rpc = p9_fd_rpc;
- trans->close = p9_fd_close;
-
- err = p9_fd_open(trans, opts.rfd, opts.wfd);
+ err = p9_fd_open(client, opts.rfd, opts.wfd);
if (err < 0)
goto error;
- trans->msize = msize;
- trans->extended = extended;
- p = (struct p9_trans_fd *) trans->priv;
- p->conn = p9_conn_create(trans);
+ p = (struct p9_trans_fd *) client->trans;
+ p->conn = p9_conn_create(client);
if (IS_ERR(p->conn)) {
err = PTR_ERR(p->conn);
p->conn = NULL;
goto error;
}
- return trans;
+ return 0;
error:
- kfree(trans);
- return ERR_PTR(err);
+ kfree(p);
+ return err;
}
static struct p9_trans_module p9_tcp_trans = {
.name = "tcp",
.maxsize = MAX_SOCK_BUF,
.def = 1,
- .create = p9_trans_create_tcp,
+ .create = p9_fd_create_tcp,
+ .close = p9_fd_close,
+ .rpc = p9_fd_rpc,
.owner = THIS_MODULE,
};
.name = "unix",
.maxsize = MAX_SOCK_BUF,
.def = 0,
- .create = p9_trans_create_unix,
+ .create = p9_fd_create_unix,
+ .close = p9_fd_close,
+ .rpc = p9_fd_rpc,
.owner = THIS_MODULE,
};
.name = "fd",
.maxsize = MAX_SOCK_BUF,
.def = 0,
- .create = p9_trans_create_fd,
+ .create = p9_fd_create,
+ .close = p9_fd_close,
+ .rpc = p9_fd_rpc,
.owner = THIS_MODULE,
};
#include <linux/file.h>
#include <net/9p/9p.h>
#include <linux/parser.h>
+#include <net/9p/client.h>
#include <net/9p/transport.h>
#include <linux/scatterlist.h>
#include <linux/virtio.h>
#define P9_INIT_MAXTAG 16
-
/**
* enum p9_req_status_t - virtio request status
* @REQ_STATUS_IDLE: request slot unused
*
*/
-static void p9_virtio_close(struct p9_trans *trans)
+static void p9_virtio_close(struct p9_client *client)
{
- struct virtio_chan *chan = trans->priv;
+ struct virtio_chan *chan = client->trans;
int count;
unsigned long flags;
chan->inuse = false;
mutex_unlock(&virtio_9p_lock);
- kfree(trans);
+ client->trans = NULL;
}
/**
*/
static int
-p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
+p9_virtio_rpc(struct p9_client *c, struct p9_fcall *tc, struct p9_fcall **rc)
{
int in, out;
int n, err, size;
- struct virtio_chan *chan = t->priv;
+ struct virtio_chan *chan = c->trans;
char *rdata;
struct p9_req_t *req;
unsigned long flags;
if (*rc == NULL) {
- *rc = kmalloc(sizeof(struct p9_fcall) + t->msize, GFP_KERNEL);
+ *rc = kmalloc(sizeof(struct p9_fcall) + c->msize, GFP_KERNEL);
if (!*rc)
return -ENOMEM;
}
P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio rpc tag %d\n", n);
out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, tc->sdata, tc->size);
- in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, t->msize);
+ in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, c->msize);
req->status = REQ_STATUS_SENT;
size = le32_to_cpu(*(__le32 *) rdata);
- err = p9_deserialize_fcall(rdata, size, *rc, t->extended);
+ err = p9_deserialize_fcall(rdata, size, *rc, c->dotu);
if (err < 0) {
P9_DPRINTK(P9_DEBUG_TRANS,
"9p debug: virtio rpc deserialize returned %d\n", err);
if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
char buf[150];
- p9_printfcall(buf, sizeof(buf), *rc, t->extended);
- printk(KERN_NOTICE ">>> %p %s\n", t, buf);
+ p9_printfcall(buf, sizeof(buf), *rc, c->dotu);
+ printk(KERN_NOTICE ">>> %p %s\n", c, buf);
}
#endif
/**
* p9_virtio_create - allocate a new virtio channel
+ * @client: client instance invoking this transport
* @devname: string identifying the channel to connect to (unused)
* @args: args passed from sys_mount() for per-transport options (unused)
- * @msize: requested maximum packet size
- * @extended: 9p2000.u enabled flag
*
* This sets up a transport channel for 9p communication. Right now
* we only match the first available channel, but eventually we couldlook up
*
*/
-static struct p9_trans *
-p9_virtio_create(const char *devname, char *args, int msize,
- unsigned char extended)
+static int
+p9_virtio_create(struct p9_client *client, const char *devname, char *args)
{
- struct p9_trans *trans;
struct virtio_chan *chan = channels;
int index = 0;
if (index >= MAX_9P_CHAN) {
printk(KERN_ERR "9p: no channels available\n");
- return ERR_PTR(-ENODEV);
+ return -ENODEV;
}
chan->tagpool = p9_idpool_create();
if (IS_ERR(chan->tagpool)) {
printk(KERN_ERR "9p: couldn't allocate tagpool\n");
- return ERR_PTR(-ENOMEM);
+ return -ENOMEM;
}
p9_idpool_get(chan->tagpool); /* reserve tag 0 */
chan->max_tag = 0;
chan->reqs = NULL;
- trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
- if (!trans) {
- printk(KERN_ERR "9p: couldn't allocate transport\n");
- return ERR_PTR(-ENOMEM);
- }
- trans->extended = extended;
- trans->msize = msize;
- trans->close = p9_virtio_close;
- trans->rpc = p9_virtio_rpc;
- trans->priv = chan;
+ client->trans = (void *)chan;
- return trans;
+ return 0;
}
/**
static struct p9_trans_module p9_virtio_trans = {
.name = "virtio",
.create = p9_virtio_create,
+ .close = p9_virtio_close,
+ .rpc = p9_virtio_rpc,
.maxsize = PAGE_SIZE*16,
.def = 0,
.owner = THIS_MODULE,