aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShirley Ma <mashirle@us.ibm.com>2010-01-18 08:45:23 -0500
committerRusty Russell <rusty@rustcorp.com.au>2010-02-23 22:52:27 -0500
commitc021eac4148c16bf53baa0dd14e8ebee6f39dab5 (patch)
tree558db2ede74488606614d6e7e277f9914e38fbc1
parent69740c8ba878f58bc3c71f74618fc2cd1da990da (diff)
virtio: Add ability to detach unused buffers from vrings
There's currently no way for a virtio driver to ask for unused buffers, so it has to keep a list itself to reclaim them at shutdown. This is redundant, since virtio_ring stores that information. So add a new hook to do this. Signed-off-by: Shirley Ma <xma@us.ibm.com> Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--drivers/virtio/virtio_ring.c25
-rw-r--r--include/linux/virtio.h4
2 files changed, 29 insertions, 0 deletions
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 827f7e042610..782b7292a3d8 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -351,6 +351,30 @@ static bool vring_enable_cb(struct virtqueue *_vq)
351 return true; 351 return true;
352} 352}
353 353
354static void *vring_detach_unused_buf(struct virtqueue *_vq)
355{
356 struct vring_virtqueue *vq = to_vvq(_vq);
357 unsigned int i;
358 void *buf;
359
360 START_USE(vq);
361
362 for (i = 0; i < vq->vring.num; i++) {
363 if (!vq->data[i])
364 continue;
365 /* detach_buf clears data, so grab it now. */
366 buf = vq->data[i];
367 detach_buf(vq, i);
368 END_USE(vq);
369 return buf;
370 }
371 /* That should have freed everything. */
372 BUG_ON(vq->num_free != vq->vring.num);
373
374 END_USE(vq);
375 return NULL;
376}
377
354irqreturn_t vring_interrupt(int irq, void *_vq) 378irqreturn_t vring_interrupt(int irq, void *_vq)
355{ 379{
356 struct vring_virtqueue *vq = to_vvq(_vq); 380 struct vring_virtqueue *vq = to_vvq(_vq);
@@ -377,6 +401,7 @@ static struct virtqueue_ops vring_vq_ops = {
377 .kick = vring_kick, 401 .kick = vring_kick,
378 .disable_cb = vring_disable_cb, 402 .disable_cb = vring_disable_cb,
379 .enable_cb = vring_enable_cb, 403 .enable_cb = vring_enable_cb,
404 .detach_unused_buf = vring_detach_unused_buf,
380}; 405};
381 406
382struct virtqueue *vring_new_virtqueue(unsigned int num, 407struct virtqueue *vring_new_virtqueue(unsigned int num,
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 057a2e010758..f508c651e53d 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -51,6 +51,9 @@ struct virtqueue {
51 * This re-enables callbacks; it returns "false" if there are pending 51 * This re-enables callbacks; it returns "false" if there are pending
52 * buffers in the queue, to detect a possible race between the driver 52 * buffers in the queue, to detect a possible race between the driver
53 * checking for more work, and enabling callbacks. 53 * checking for more work, and enabling callbacks.
54 * @detach_unused_buf: detach first unused buffer
55 * vq: the struct virtqueue we're talking about.
56 * Returns NULL or the "data" token handed to add_buf
54 * 57 *
55 * Locking rules are straightforward: the driver is responsible for 58 * Locking rules are straightforward: the driver is responsible for
56 * locking. No two operations may be invoked simultaneously, with the exception 59 * locking. No two operations may be invoked simultaneously, with the exception
@@ -71,6 +74,7 @@ struct virtqueue_ops {
71 74
72 void (*disable_cb)(struct virtqueue *vq); 75 void (*disable_cb)(struct virtqueue *vq);
73 bool (*enable_cb)(struct virtqueue *vq); 76 bool (*enable_cb)(struct virtqueue *vq);
77 void *(*detach_unused_buf)(struct virtqueue *vq);
74}; 78};
75 79
76/** 80/**