Commit 0b36f1ad authored by Rusty Russell's avatar Rusty Russell

9p/trans_virtio.c: use virtio_add_sgs[]

virtio_add_buf() is going away, replaced with virtio_add_sgs() which
takes multiple terminated scatterlists.

Cc: Eric Van Hensbergen <ericvh@gmail.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 92549abc
...@@ -194,11 +194,14 @@ static int pack_sg_list(struct scatterlist *sg, int start, ...@@ -194,11 +194,14 @@ static int pack_sg_list(struct scatterlist *sg, int start,
if (s > count) if (s > count)
s = count; s = count;
BUG_ON(index > limit); BUG_ON(index > limit);
/* Make sure we don't terminate early. */
sg_unmark_end(&sg[index]);
sg_set_buf(&sg[index++], data, s); sg_set_buf(&sg[index++], data, s);
count -= s; count -= s;
data += s; data += s;
} }
if (index-start)
sg_mark_end(&sg[index - 1]);
return index-start; return index-start;
} }
...@@ -236,12 +239,17 @@ pack_sg_list_p(struct scatterlist *sg, int start, int limit, ...@@ -236,12 +239,17 @@ pack_sg_list_p(struct scatterlist *sg, int start, int limit,
s = rest_of_page(data); s = rest_of_page(data);
if (s > count) if (s > count)
s = count; s = count;
/* Make sure we don't terminate early. */
sg_unmark_end(&sg[index]);
sg_set_page(&sg[index++], pdata[i++], s, data_off); sg_set_page(&sg[index++], pdata[i++], s, data_off);
data_off = 0; data_off = 0;
data += s; data += s;
count -= s; count -= s;
nr_pages--; nr_pages--;
} }
if (index-start)
sg_mark_end(&sg[index - 1]);
return index - start; return index - start;
} }
...@@ -256,9 +264,10 @@ static int ...@@ -256,9 +264,10 @@ static int
p9_virtio_request(struct p9_client *client, struct p9_req_t *req) p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
{ {
int err; int err;
int in, out; int in, out, out_sgs, in_sgs;
unsigned long flags; unsigned long flags;
struct virtio_chan *chan = client->trans; struct virtio_chan *chan = client->trans;
struct scatterlist *sgs[2];
p9_debug(P9_DEBUG_TRANS, "9p debug: virtio request\n"); p9_debug(P9_DEBUG_TRANS, "9p debug: virtio request\n");
...@@ -266,14 +275,19 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req) ...@@ -266,14 +275,19 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
req_retry: req_retry:
spin_lock_irqsave(&chan->lock, flags); spin_lock_irqsave(&chan->lock, flags);
out_sgs = in_sgs = 0;
/* Handle out VirtIO ring buffers */ /* Handle out VirtIO ring buffers */
out = pack_sg_list(chan->sg, 0, out = pack_sg_list(chan->sg, 0,
VIRTQUEUE_NUM, req->tc->sdata, req->tc->size); VIRTQUEUE_NUM, req->tc->sdata, req->tc->size);
if (out)
sgs[out_sgs++] = chan->sg;
in = pack_sg_list(chan->sg, out, in = pack_sg_list(chan->sg, out,
VIRTQUEUE_NUM, req->rc->sdata, req->rc->capacity); VIRTQUEUE_NUM, req->rc->sdata, req->rc->capacity);
if (in)
sgs[out_sgs + in_sgs++] = chan->sg + out;
err = virtqueue_add_buf(chan->vq, chan->sg, out, in, req->tc, err = virtqueue_add_sgs(chan->vq, sgs, out_sgs, in_sgs, req->tc,
GFP_ATOMIC); GFP_ATOMIC);
if (err < 0) { if (err < 0) {
if (err == -ENOSPC) { if (err == -ENOSPC) {
...@@ -289,7 +303,7 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req) ...@@ -289,7 +303,7 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
} else { } else {
spin_unlock_irqrestore(&chan->lock, flags); spin_unlock_irqrestore(&chan->lock, flags);
p9_debug(P9_DEBUG_TRANS, p9_debug(P9_DEBUG_TRANS,
"virtio rpc add_buf returned failure\n"); "virtio rpc add_sgs returned failure\n");
return -EIO; return -EIO;
} }
} }
...@@ -351,11 +365,12 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, ...@@ -351,11 +365,12 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
char *uidata, char *uodata, int inlen, char *uidata, char *uodata, int inlen,
int outlen, int in_hdr_len, int kern_buf) int outlen, int in_hdr_len, int kern_buf)
{ {
int in, out, err; int in, out, err, out_sgs, in_sgs;
unsigned long flags; unsigned long flags;
int in_nr_pages = 0, out_nr_pages = 0; int in_nr_pages = 0, out_nr_pages = 0;
struct page **in_pages = NULL, **out_pages = NULL; struct page **in_pages = NULL, **out_pages = NULL;
struct virtio_chan *chan = client->trans; struct virtio_chan *chan = client->trans;
struct scatterlist *sgs[4];
p9_debug(P9_DEBUG_TRANS, "virtio request\n"); p9_debug(P9_DEBUG_TRANS, "virtio request\n");
...@@ -396,13 +411,22 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, ...@@ -396,13 +411,22 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
req->status = REQ_STATUS_SENT; req->status = REQ_STATUS_SENT;
req_retry_pinned: req_retry_pinned:
spin_lock_irqsave(&chan->lock, flags); spin_lock_irqsave(&chan->lock, flags);
out_sgs = in_sgs = 0;
/* out data */ /* out data */
out = pack_sg_list(chan->sg, 0, out = pack_sg_list(chan->sg, 0,
VIRTQUEUE_NUM, req->tc->sdata, req->tc->size); VIRTQUEUE_NUM, req->tc->sdata, req->tc->size);
if (out_pages) if (out)
sgs[out_sgs++] = chan->sg;
if (out_pages) {
sgs[out_sgs++] = chan->sg + out;
out += pack_sg_list_p(chan->sg, out, VIRTQUEUE_NUM, out += pack_sg_list_p(chan->sg, out, VIRTQUEUE_NUM,
out_pages, out_nr_pages, uodata, outlen); out_pages, out_nr_pages, uodata, outlen);
}
/* /*
* Take care of in data * Take care of in data
* For example TREAD have 11. * For example TREAD have 11.
...@@ -412,11 +436,17 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, ...@@ -412,11 +436,17 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
*/ */
in = pack_sg_list(chan->sg, out, in = pack_sg_list(chan->sg, out,
VIRTQUEUE_NUM, req->rc->sdata, in_hdr_len); VIRTQUEUE_NUM, req->rc->sdata, in_hdr_len);
if (in_pages) if (in)
sgs[out_sgs + in_sgs++] = chan->sg + out;
if (in_pages) {
sgs[out_sgs + in_sgs++] = chan->sg + out + in;
in += pack_sg_list_p(chan->sg, out + in, VIRTQUEUE_NUM, in += pack_sg_list_p(chan->sg, out + in, VIRTQUEUE_NUM,
in_pages, in_nr_pages, uidata, inlen); in_pages, in_nr_pages, uidata, inlen);
}
err = virtqueue_add_buf(chan->vq, chan->sg, out, in, req->tc, BUG_ON(out_sgs + in_sgs > ARRAY_SIZE(sgs));
err = virtqueue_add_sgs(chan->vq, sgs, out_sgs, in_sgs, req->tc,
GFP_ATOMIC); GFP_ATOMIC);
if (err < 0) { if (err < 0) {
if (err == -ENOSPC) { if (err == -ENOSPC) {
...@@ -432,7 +462,7 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req, ...@@ -432,7 +462,7 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
} else { } else {
spin_unlock_irqrestore(&chan->lock, flags); spin_unlock_irqrestore(&chan->lock, flags);
p9_debug(P9_DEBUG_TRANS, p9_debug(P9_DEBUG_TRANS,
"virtio rpc add_buf returned failure\n"); "virtio rpc add_sgs returned failure\n");
err = -EIO; err = -EIO;
goto err_out; goto err_out;
} }
......
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