Skip to content

Commit ba3e0c4

Browse files
fengidrimstsirkin
authored andcommitted
virtio_ring: introduce virtqueue_reset()
Introduce virtqueue_reset() to release all buffer inside vq. Signed-off-by: Xuan Zhuo <[email protected]> Acked-by: Jason Wang <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent ad48d53 commit ba3e0c4

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

drivers/virtio/virtio_ring.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,39 @@ int virtqueue_set_dma_premapped(struct virtqueue *_vq)
28122812
}
28132813
EXPORT_SYMBOL_GPL(virtqueue_set_dma_premapped);
28142814

2815+
/**
2816+
* virtqueue_reset - detach and recycle all unused buffers
2817+
* @_vq: the struct virtqueue we're talking about.
2818+
* @recycle: callback to recycle unused buffers
2819+
*
2820+
* Caller must ensure we don't call this with other virtqueue operations
2821+
* at the same time (except where noted).
2822+
*
2823+
* Returns zero or a negative error.
2824+
* 0: success.
2825+
* -EBUSY: Failed to sync with device, vq may not work properly
2826+
* -ENOENT: Transport or device not supported
2827+
* -EPERM: Operation not permitted
2828+
*/
2829+
int virtqueue_reset(struct virtqueue *_vq,
2830+
void (*recycle)(struct virtqueue *vq, void *buf))
2831+
{
2832+
struct vring_virtqueue *vq = to_vvq(_vq);
2833+
int err;
2834+
2835+
err = virtqueue_disable_and_recycle(_vq, recycle);
2836+
if (err)
2837+
return err;
2838+
2839+
if (vq->packed_ring)
2840+
virtqueue_reinit_packed(vq);
2841+
else
2842+
virtqueue_reinit_split(vq);
2843+
2844+
return virtqueue_enable_after_reset(_vq);
2845+
}
2846+
EXPORT_SYMBOL_GPL(virtqueue_reset);
2847+
28152848
/* Only available for split ring */
28162849
struct virtqueue *vring_new_virtqueue(unsigned int index,
28172850
unsigned int num,

include/linux/virtio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ dma_addr_t virtqueue_get_used_addr(const struct virtqueue *vq);
9999

100100
int virtqueue_resize(struct virtqueue *vq, u32 num,
101101
void (*recycle)(struct virtqueue *vq, void *buf));
102+
int virtqueue_reset(struct virtqueue *vq,
103+
void (*recycle)(struct virtqueue *vq, void *buf));
102104

103105
/**
104106
* struct virtio_device - representation of a device using virtio

0 commit comments

Comments
 (0)