diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-01-12 00:14:42 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-01-12 00:14:42 -0500 |
commit | f96fde41f7f9af6cf20f6a1919f5d9670f84d574 (patch) | |
tree | 14b8a0343b255989ac8ba0ea34e18dca419723df | |
parent | 5dfc17628d57f9e62043ed0cba03a6e3eb019a78 (diff) |
virtio: rename virtqueue_add_buf_gfp to virtqueue_add_buf
Remove wrapper functions. This makes the allocation type explicit in
all callers; I used GPF_KERNEL where it seemed obvious, left it at
GFP_ATOMIC otherwise.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | drivers/block/virtio_blk.c | 2 | ||||
-rw-r--r-- | drivers/char/hw_random/virtio-rng.c | 2 | ||||
-rw-r--r-- | drivers/char/virtio_console.c | 6 | ||||
-rw-r--r-- | drivers/net/virtio_net.c | 12 | ||||
-rw-r--r-- | drivers/virtio/virtio_balloon.c | 7 | ||||
-rw-r--r-- | drivers/virtio/virtio_ring.c | 22 | ||||
-rw-r--r-- | include/linux/virtio.h | 21 | ||||
-rw-r--r-- | net/9p/trans_virtio.c | 6 | ||||
-rw-r--r-- | tools/virtio/linux/virtio.h | 21 | ||||
-rw-r--r-- | tools/virtio/virtio_test.c | 3 |
10 files changed, 44 insertions, 58 deletions
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 4d0b70adf5f7..a345e40e1bca 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c | |||
@@ -172,7 +172,7 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk, | |||
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | if (virtqueue_add_buf(vblk->vq, vblk->sg, out, in, vbr) < 0) { | 175 | if (virtqueue_add_buf(vblk->vq, vblk->sg, out, in, vbr, GFP_ATOMIC)<0) { |
176 | mempool_free(vbr, vblk->pool); | 176 | mempool_free(vbr, vblk->pool); |
177 | return false; | 177 | return false; |
178 | } | 178 | } |
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index fd699ccecf5b..723725bbb96b 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c | |||
@@ -47,7 +47,7 @@ static void register_buffer(u8 *buf, size_t size) | |||
47 | sg_init_one(&sg, buf, size); | 47 | sg_init_one(&sg, buf, size); |
48 | 48 | ||
49 | /* There should always be room for one buffer. */ | 49 | /* There should always be room for one buffer. */ |
50 | if (virtqueue_add_buf(vq, &sg, 0, 1, buf) < 0) | 50 | if (virtqueue_add_buf(vq, &sg, 0, 1, buf, GFP_KERNEL) < 0) |
51 | BUG(); | 51 | BUG(); |
52 | 52 | ||
53 | virtqueue_kick(vq); | 53 | virtqueue_kick(vq); |
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 8e3c46d67cb3..d1ae1492ee78 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c | |||
@@ -392,7 +392,7 @@ static int add_inbuf(struct virtqueue *vq, struct port_buffer *buf) | |||
392 | 392 | ||
393 | sg_init_one(sg, buf->buf, buf->size); | 393 | sg_init_one(sg, buf->buf, buf->size); |
394 | 394 | ||
395 | ret = virtqueue_add_buf(vq, sg, 0, 1, buf); | 395 | ret = virtqueue_add_buf(vq, sg, 0, 1, buf, GFP_ATOMIC); |
396 | virtqueue_kick(vq); | 396 | virtqueue_kick(vq); |
397 | return ret; | 397 | return ret; |
398 | } | 398 | } |
@@ -457,7 +457,7 @@ static ssize_t __send_control_msg(struct ports_device *portdev, u32 port_id, | |||
457 | vq = portdev->c_ovq; | 457 | vq = portdev->c_ovq; |
458 | 458 | ||
459 | sg_init_one(sg, &cpkt, sizeof(cpkt)); | 459 | sg_init_one(sg, &cpkt, sizeof(cpkt)); |
460 | if (virtqueue_add_buf(vq, sg, 1, 0, &cpkt) >= 0) { | 460 | if (virtqueue_add_buf(vq, sg, 1, 0, &cpkt, GFP_ATOMIC) >= 0) { |
461 | virtqueue_kick(vq); | 461 | virtqueue_kick(vq); |
462 | while (!virtqueue_get_buf(vq, &len)) | 462 | while (!virtqueue_get_buf(vq, &len)) |
463 | cpu_relax(); | 463 | cpu_relax(); |
@@ -506,7 +506,7 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count, | |||
506 | reclaim_consumed_buffers(port); | 506 | reclaim_consumed_buffers(port); |
507 | 507 | ||
508 | sg_init_one(sg, in_buf, in_count); | 508 | sg_init_one(sg, in_buf, in_count); |
509 | ret = virtqueue_add_buf(out_vq, sg, 1, 0, in_buf); | 509 | ret = virtqueue_add_buf(out_vq, sg, 1, 0, in_buf, GFP_ATOMIC); |
510 | 510 | ||
511 | /* Tell Host to go! */ | 511 | /* Tell Host to go! */ |
512 | virtqueue_kick(out_vq); | 512 | virtqueue_kick(out_vq); |
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 76fe14efb2b5..6345a52194f9 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -370,7 +370,7 @@ static int add_recvbuf_small(struct virtnet_info *vi, gfp_t gfp) | |||
370 | 370 | ||
371 | skb_to_sgvec(skb, vi->rx_sg + 1, 0, skb->len); | 371 | skb_to_sgvec(skb, vi->rx_sg + 1, 0, skb->len); |
372 | 372 | ||
373 | err = virtqueue_add_buf_gfp(vi->rvq, vi->rx_sg, 0, 2, skb, gfp); | 373 | err = virtqueue_add_buf(vi->rvq, vi->rx_sg, 0, 2, skb, gfp); |
374 | if (err < 0) | 374 | if (err < 0) |
375 | dev_kfree_skb(skb); | 375 | dev_kfree_skb(skb); |
376 | 376 | ||
@@ -415,8 +415,8 @@ static int add_recvbuf_big(struct virtnet_info *vi, gfp_t gfp) | |||
415 | 415 | ||
416 | /* chain first in list head */ | 416 | /* chain first in list head */ |
417 | first->private = (unsigned long)list; | 417 | first->private = (unsigned long)list; |
418 | err = virtqueue_add_buf_gfp(vi->rvq, vi->rx_sg, 0, MAX_SKB_FRAGS + 2, | 418 | err = virtqueue_add_buf(vi->rvq, vi->rx_sg, 0, MAX_SKB_FRAGS + 2, |
419 | first, gfp); | 419 | first, gfp); |
420 | if (err < 0) | 420 | if (err < 0) |
421 | give_pages(vi, first); | 421 | give_pages(vi, first); |
422 | 422 | ||
@@ -434,7 +434,7 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi, gfp_t gfp) | |||
434 | 434 | ||
435 | sg_init_one(vi->rx_sg, page_address(page), PAGE_SIZE); | 435 | sg_init_one(vi->rx_sg, page_address(page), PAGE_SIZE); |
436 | 436 | ||
437 | err = virtqueue_add_buf_gfp(vi->rvq, vi->rx_sg, 0, 1, page, gfp); | 437 | err = virtqueue_add_buf(vi->rvq, vi->rx_sg, 0, 1, page, gfp); |
438 | if (err < 0) | 438 | if (err < 0) |
439 | give_pages(vi, page); | 439 | give_pages(vi, page); |
440 | 440 | ||
@@ -609,7 +609,7 @@ static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb) | |||
609 | 609 | ||
610 | hdr->num_sg = skb_to_sgvec(skb, vi->tx_sg + 1, 0, skb->len) + 1; | 610 | hdr->num_sg = skb_to_sgvec(skb, vi->tx_sg + 1, 0, skb->len) + 1; |
611 | return virtqueue_add_buf(vi->svq, vi->tx_sg, hdr->num_sg, | 611 | return virtqueue_add_buf(vi->svq, vi->tx_sg, hdr->num_sg, |
612 | 0, skb); | 612 | 0, skb, GFP_ATOMIC); |
613 | } | 613 | } |
614 | 614 | ||
615 | static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) | 615 | static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) |
@@ -767,7 +767,7 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd, | |||
767 | sg_set_buf(&sg[i + 1], sg_virt(s), s->length); | 767 | sg_set_buf(&sg[i + 1], sg_virt(s), s->length); |
768 | sg_set_buf(&sg[out + in - 1], &status, sizeof(status)); | 768 | sg_set_buf(&sg[out + in - 1], &status, sizeof(status)); |
769 | 769 | ||
770 | BUG_ON(virtqueue_add_buf(vi->cvq, sg, out, in, vi) < 0); | 770 | BUG_ON(virtqueue_add_buf(vi->cvq, sg, out, in, vi, GFP_ATOMIC) < 0); |
771 | 771 | ||
772 | virtqueue_kick(vi->cvq); | 772 | virtqueue_kick(vi->cvq); |
773 | 773 | ||
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index f64ff185b8b5..0a6425aadf95 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c | |||
@@ -88,7 +88,7 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq) | |||
88 | init_completion(&vb->acked); | 88 | init_completion(&vb->acked); |
89 | 89 | ||
90 | /* We should always be able to add one buffer to an empty queue. */ | 90 | /* We should always be able to add one buffer to an empty queue. */ |
91 | if (virtqueue_add_buf(vq, &sg, 1, 0, vb) < 0) | 91 | if (virtqueue_add_buf(vq, &sg, 1, 0, vb, GFP_KERNEL) < 0) |
92 | BUG(); | 92 | BUG(); |
93 | virtqueue_kick(vq); | 93 | virtqueue_kick(vq); |
94 | 94 | ||
@@ -220,7 +220,7 @@ static void stats_handle_request(struct virtio_balloon *vb) | |||
220 | 220 | ||
221 | vq = vb->stats_vq; | 221 | vq = vb->stats_vq; |
222 | sg_init_one(&sg, vb->stats, sizeof(vb->stats)); | 222 | sg_init_one(&sg, vb->stats, sizeof(vb->stats)); |
223 | if (virtqueue_add_buf(vq, &sg, 1, 0, vb) < 0) | 223 | if (virtqueue_add_buf(vq, &sg, 1, 0, vb, GFP_KERNEL) < 0) |
224 | BUG(); | 224 | BUG(); |
225 | virtqueue_kick(vq); | 225 | virtqueue_kick(vq); |
226 | } | 226 | } |
@@ -313,7 +313,8 @@ static int virtballoon_probe(struct virtio_device *vdev) | |||
313 | * use it to signal us later. | 313 | * use it to signal us later. |
314 | */ | 314 | */ |
315 | sg_init_one(&sg, vb->stats, sizeof vb->stats); | 315 | sg_init_one(&sg, vb->stats, sizeof vb->stats); |
316 | if (virtqueue_add_buf(vb->stats_vq, &sg, 1, 0, vb) < 0) | 316 | if (virtqueue_add_buf(vb->stats_vq, &sg, 1, 0, vb, GFP_KERNEL) |
317 | < 0) | ||
317 | BUG(); | 318 | BUG(); |
318 | virtqueue_kick(vb->stats_vq); | 319 | virtqueue_kick(vb->stats_vq); |
319 | } | 320 | } |
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index fe50486341a4..6ea92a6d1134 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c | |||
@@ -167,7 +167,7 @@ static int vring_add_indirect(struct vring_virtqueue *vq, | |||
167 | } | 167 | } |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * virtqueue_add_buf_gfp - expose buffer to other end | 170 | * virtqueue_add_buf - expose buffer to other end |
171 | * @vq: the struct virtqueue we're talking about. | 171 | * @vq: the struct virtqueue we're talking about. |
172 | * @sg: the description of the buffer(s). | 172 | * @sg: the description of the buffer(s). |
173 | * @out_num: the number of sg readable by other side | 173 | * @out_num: the number of sg readable by other side |
@@ -183,12 +183,12 @@ static int vring_add_indirect(struct vring_virtqueue *vq, | |||
183 | * positive return values as "available": indirect buffers mean that | 183 | * positive return values as "available": indirect buffers mean that |
184 | * we can put an entire sg[] array inside a single queue entry. | 184 | * we can put an entire sg[] array inside a single queue entry. |
185 | */ | 185 | */ |
186 | int virtqueue_add_buf_gfp(struct virtqueue *_vq, | 186 | int virtqueue_add_buf(struct virtqueue *_vq, |
187 | struct scatterlist sg[], | 187 | struct scatterlist sg[], |
188 | unsigned int out, | 188 | unsigned int out, |
189 | unsigned int in, | 189 | unsigned int in, |
190 | void *data, | 190 | void *data, |
191 | gfp_t gfp) | 191 | gfp_t gfp) |
192 | { | 192 | { |
193 | struct vring_virtqueue *vq = to_vvq(_vq); | 193 | struct vring_virtqueue *vq = to_vvq(_vq); |
194 | unsigned int i, avail, uninitialized_var(prev); | 194 | unsigned int i, avail, uninitialized_var(prev); |
@@ -259,13 +259,13 @@ add_head: | |||
259 | 259 | ||
260 | return vq->num_free; | 260 | return vq->num_free; |
261 | } | 261 | } |
262 | EXPORT_SYMBOL_GPL(virtqueue_add_buf_gfp); | 262 | EXPORT_SYMBOL_GPL(virtqueue_add_buf); |
263 | 263 | ||
264 | /** | 264 | /** |
265 | * virtqueue_kick - update after add_buf | 265 | * virtqueue_kick - update after add_buf |
266 | * @vq: the struct virtqueue | 266 | * @vq: the struct virtqueue |
267 | * | 267 | * |
268 | * After one or more virtqueue_add_buf_gfp calls, invoke this to kick | 268 | * After one or more virtqueue_add_buf calls, invoke this to kick |
269 | * the other side. | 269 | * the other side. |
270 | * | 270 | * |
271 | * Caller must ensure we don't call this with other virtqueue | 271 | * Caller must ensure we don't call this with other virtqueue |
@@ -341,7 +341,7 @@ static inline bool more_used(const struct vring_virtqueue *vq) | |||
341 | * operations at the same time (except where noted). | 341 | * operations at the same time (except where noted). |
342 | * | 342 | * |
343 | * Returns NULL if there are no used buffers, or the "data" token | 343 | * Returns NULL if there are no used buffers, or the "data" token |
344 | * handed to virtqueue_add_buf_gfp(). | 344 | * handed to virtqueue_add_buf(). |
345 | */ | 345 | */ |
346 | void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len) | 346 | void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len) |
347 | { | 347 | { |
@@ -490,7 +490,7 @@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed); | |||
490 | * virtqueue_detach_unused_buf - detach first unused buffer | 490 | * virtqueue_detach_unused_buf - detach first unused buffer |
491 | * @vq: the struct virtqueue we're talking about. | 491 | * @vq: the struct virtqueue we're talking about. |
492 | * | 492 | * |
493 | * Returns NULL or the "data" token handed to virtqueue_add_buf_gfp(). | 493 | * Returns NULL or the "data" token handed to virtqueue_add_buf(). |
494 | * This is not valid on an active queue; it is useful only for device | 494 | * This is not valid on an active queue; it is useful only for device |
495 | * shutdown. | 495 | * shutdown. |
496 | */ | 496 | */ |
diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 73ad7243128f..ec1706e7df50 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h | |||
@@ -25,21 +25,12 @@ struct virtqueue { | |||
25 | void *priv; | 25 | void *priv; |
26 | }; | 26 | }; |
27 | 27 | ||
28 | int virtqueue_add_buf_gfp(struct virtqueue *vq, | 28 | int virtqueue_add_buf(struct virtqueue *vq, |
29 | struct scatterlist sg[], | 29 | struct scatterlist sg[], |
30 | unsigned int out_num, | 30 | unsigned int out_num, |
31 | unsigned int in_num, | 31 | unsigned int in_num, |
32 | void *data, | 32 | void *data, |
33 | gfp_t gfp); | 33 | gfp_t gfp); |
34 | |||
35 | static inline int virtqueue_add_buf(struct virtqueue *vq, | ||
36 | struct scatterlist sg[], | ||
37 | unsigned int out_num, | ||
38 | unsigned int in_num, | ||
39 | void *data) | ||
40 | { | ||
41 | return virtqueue_add_buf_gfp(vq, sg, out_num, in_num, data, GFP_ATOMIC); | ||
42 | } | ||
43 | 34 | ||
44 | void virtqueue_kick(struct virtqueue *vq); | 35 | void virtqueue_kick(struct virtqueue *vq); |
45 | 36 | ||
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 330421e54713..3d432068f627 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c | |||
@@ -272,7 +272,8 @@ req_retry: | |||
272 | in = pack_sg_list(chan->sg, out, | 272 | in = pack_sg_list(chan->sg, out, |
273 | VIRTQUEUE_NUM, req->rc->sdata, req->rc->capacity); | 273 | VIRTQUEUE_NUM, req->rc->sdata, req->rc->capacity); |
274 | 274 | ||
275 | err = virtqueue_add_buf(chan->vq, chan->sg, out, in, req->tc); | 275 | err = virtqueue_add_buf(chan->vq, chan->sg, out, in, req->tc, |
276 | GFP_ATOMIC); | ||
276 | if (err < 0) { | 277 | if (err < 0) { |
277 | if (err == -ENOSPC) { | 278 | if (err == -ENOSPC) { |
278 | chan->ring_bufs_avail = 0; | 279 | chan->ring_bufs_avail = 0; |
@@ -414,7 +415,8 @@ req_retry_pinned: | |||
414 | in += pack_sg_list_p(chan->sg, out + in, VIRTQUEUE_NUM, | 415 | in += pack_sg_list_p(chan->sg, out + in, VIRTQUEUE_NUM, |
415 | in_pages, in_nr_pages, uidata, inlen); | 416 | in_pages, in_nr_pages, uidata, inlen); |
416 | 417 | ||
417 | err = virtqueue_add_buf(chan->vq, chan->sg, out, in, req->tc); | 418 | err = virtqueue_add_buf(chan->vq, chan->sg, out, in, req->tc, |
419 | GFP_ATOMIC); | ||
418 | if (err < 0) { | 420 | if (err < 0) { |
419 | if (err == -ENOSPC) { | 421 | if (err == -ENOSPC) { |
420 | chan->ring_bufs_avail = 0; | 422 | chan->ring_bufs_avail = 0; |
diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h index 953db2abf6b9..b4fbc91c41b4 100644 --- a/tools/virtio/linux/virtio.h +++ b/tools/virtio/linux/virtio.h | |||
@@ -186,21 +186,12 @@ struct virtqueue { | |||
186 | #endif | 186 | #endif |
187 | 187 | ||
188 | /* Interfaces exported by virtio_ring. */ | 188 | /* Interfaces exported by virtio_ring. */ |
189 | int virtqueue_add_buf_gfp(struct virtqueue *vq, | 189 | int virtqueue_add_buf(struct virtqueue *vq, |
190 | struct scatterlist sg[], | 190 | struct scatterlist sg[], |
191 | unsigned int out_num, | 191 | unsigned int out_num, |
192 | unsigned int in_num, | 192 | unsigned int in_num, |
193 | void *data, | 193 | void *data, |
194 | gfp_t gfp); | 194 | gfp_t gfp); |
195 | |||
196 | static inline int virtqueue_add_buf(struct virtqueue *vq, | ||
197 | struct scatterlist sg[], | ||
198 | unsigned int out_num, | ||
199 | unsigned int in_num, | ||
200 | void *data) | ||
201 | { | ||
202 | return virtqueue_add_buf_gfp(vq, sg, out_num, in_num, data, GFP_ATOMIC); | ||
203 | } | ||
204 | 195 | ||
205 | void virtqueue_kick(struct virtqueue *vq); | 196 | void virtqueue_kick(struct virtqueue *vq); |
206 | 197 | ||
diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 0740284396c1..6bf95f995364 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c | |||
@@ -161,7 +161,8 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq, int bufs) | |||
161 | if (started < bufs) { | 161 | if (started < bufs) { |
162 | sg_init_one(&sl, dev->buf, dev->buf_size); | 162 | sg_init_one(&sl, dev->buf, dev->buf_size); |
163 | r = virtqueue_add_buf(vq->vq, &sl, 1, 0, | 163 | r = virtqueue_add_buf(vq->vq, &sl, 1, 0, |
164 | dev->buf + started); | 164 | dev->buf + started, |
165 | GFP_ATOMIC); | ||
165 | if (likely(r >= 0)) { | 166 | if (likely(r >= 0)) { |
166 | ++started; | 167 | ++started; |
167 | virtqueue_kick(vq->vq); | 168 | virtqueue_kick(vq->vq); |