[RFC PATCH 10/16] virtio_ring: packed: introduce vring_virtqueue_detach_packed()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The function vring_virtqueue_detach_packed() is introduced to detach the
vring of the current vq.

Add two new members. last_used_idx is used to record the position where
the current vring desc is used, which can be used to obtain buffers from
the vring in order. Another num_left records how many buffers there are,
which can be used to check the recovery of buffers completed.

Signed-off-by: Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx>
---
 drivers/virtio/virtio_ring.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 436b18184dfe..219e008a4633 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -154,6 +154,10 @@ struct vring_virtqueue_packed {
 	dma_addr_t device_event_dma_addr;
 	size_t ring_size_in_bytes;
 	size_t event_size_in_bytes;
+
+	/* for vring detach */
+	u16 last_used_idx;
+	u32 num_left;
 };
 
 struct vring_virtqueue {
@@ -2090,6 +2094,25 @@ static int vring_alloc_state_extra_packed(struct vring_virtqueue_packed *vring)
 	return -ENOMEM;
 }
 
+static void vring_virtqueue_detach_packed(struct vring_virtqueue *vq,
+					  struct vring_virtqueue_packed *vring)
+{
+	vring->vring = vq->packed.vring;
+
+	vring->ring_dma_addr         = vq->packed.ring_dma_addr;
+	vring->driver_event_dma_addr = vq->packed.driver_event_dma_addr;
+	vring->device_event_dma_addr = vq->packed.device_event_dma_addr;
+
+	vring->ring_size_in_bytes    = vq->packed.ring_size_in_bytes;
+	vring->event_size_in_bytes   = vq->packed.event_size_in_bytes;
+
+	vring->desc_state = vq->packed.desc_state;
+	vring->desc_extra = vq->packed.desc_extra;
+
+	vring->last_used_idx = vq->last_used_idx;
+	vring->num_left = vq->packed.vring.num - vq->vq.num_free;
+}
+
 static void virtqueue_vring_attach_packed(struct vring_virtqueue *vq,
 					  struct vring_virtqueue_packed *vring)
 {
-- 
2.31.0

_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization



[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux