Commit c623106c authored by Jason Wang's avatar Jason Wang Committed by Michael S. Tsirkin
Browse files

virtio_ring: factor out core logic of buffer detaching



Factor out core logic of buffer detaching and leave the free list
management to the caller so in_order can just call the core logic.

Acked-by: default avatarEugenio Pérez <eperezma@redhat.com>
Reviewed-by: default avatarXuan Zhuo <xuanzhuo@linux.alibaba.com>
Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Message-Id: <20251230064649.55597-16-jasowang@redhat.com>
parent 03f05c4e
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -1665,7 +1665,7 @@ static bool virtqueue_kick_prepare_packed(struct vring_virtqueue *vq)
	return needs_kick;
}

static void detach_buf_packed(struct vring_virtqueue *vq,
static void detach_buf_packed_in_order(struct vring_virtqueue *vq,
				       unsigned int id, void **ctx)
{
	struct vring_desc_state_packed *state = NULL;
@@ -1677,8 +1677,6 @@ static void detach_buf_packed(struct vring_virtqueue *vq,
	/* Clear data ptr. */
	state->data = NULL;

	vq->packed.desc_extra[state->last].next = vq->free_head;
	vq->free_head = id;
	vq->vq.num_free += state->num;

	if (unlikely(vq->use_map_api)) {
@@ -1715,6 +1713,17 @@ static void detach_buf_packed(struct vring_virtqueue *vq,
	}
}

static void detach_buf_packed(struct vring_virtqueue *vq,
			      unsigned int id, void **ctx)
{
	struct vring_desc_state_packed *state = &vq->packed.desc_state[id];

	vq->packed.desc_extra[state->last].next = vq->free_head;
	vq->free_head = id;

	detach_buf_packed_in_order(vq, id, ctx);
}

static inline bool is_used_desc_packed(const struct vring_virtqueue *vq,
				       u16 idx, bool used_wrap_counter)
{