[RFC,23/27] vhost: add support for virtqueue state get event

Message ID 20230331154259.1447831-24-maxime.coquelin@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series Add VDUSE support to Vhost library |

Commit Message

Maxime Coquelin March 31, 2023, 3:42 p.m. UTC
  This patch adds support for VDUSE_GET_VQ_STATE event
handling, which consists in providing the backend last
available index for the specified virtqueue.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/vhost/vduse.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Chenbo Xia May 9, 2023, 5:34 a.m. UTC | #1
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Friday, March 31, 2023 11:43 PM
> To: dev@dpdk.org; david.marchand@redhat.com; Xia, Chenbo
> <chenbo.xia@intel.com>; mkp@redhat.com; fbl@redhat.com;
> jasowang@redhat.com; Liang, Cunming <cunming.liang@intel.com>; Xie, Yongji
> <xieyongji@bytedance.com>; echaudro@redhat.com; eperezma@redhat.com;
> amorenoz@redhat.com
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: [RFC 23/27] vhost: add support for virtqueue state get event
> 
> This patch adds support for VDUSE_GET_VQ_STATE event
> handling, which consists in providing the backend last
> available index for the specified virtqueue.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  lib/vhost/vduse.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c
> index 2a183130d3..36028b7315 100644
> --- a/lib/vhost/vduse.c
> +++ b/lib/vhost/vduse.c
> @@ -133,6 +133,7 @@ vduse_events_handler(int fd, void *arg, int *remove
> __rte_unused)
>  	struct virtio_net *dev = arg;
>  	struct vduse_dev_request req;
>  	struct vduse_dev_response resp;
> +	struct vhost_virtqueue *vq;
>  	int ret;
> 
>  	memset(&resp, 0, sizeof(resp));
> @@ -155,6 +156,13 @@ vduse_events_handler(int fd, void *arg, int *remove
> __rte_unused)
>  			req.type);
> 
>  	switch (req.type) {
> +	case VDUSE_GET_VQ_STATE:
> +		vq = dev->virtqueue[req.vq_state.index];
> +		VHOST_LOG_CONFIG(dev->ifname, INFO, "\tvq index: %u,
> avail_index: %u\n",
> +				req.vq_state.index, vq->last_avail_idx);
> +		resp.vq_state.split.avail_index = vq->last_avail_idx;
> +		resp.result = VDUSE_REQ_RESULT_OK;
> +		break;
>  	default:
>  		resp.result = VDUSE_REQ_RESULT_FAILED;
>  		break;
> --
> 2.39.2

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  

Patch

diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c
index 2a183130d3..36028b7315 100644
--- a/lib/vhost/vduse.c
+++ b/lib/vhost/vduse.c
@@ -133,6 +133,7 @@  vduse_events_handler(int fd, void *arg, int *remove __rte_unused)
 	struct virtio_net *dev = arg;
 	struct vduse_dev_request req;
 	struct vduse_dev_response resp;
+	struct vhost_virtqueue *vq;
 	int ret;
 
 	memset(&resp, 0, sizeof(resp));
@@ -155,6 +156,13 @@  vduse_events_handler(int fd, void *arg, int *remove __rte_unused)
 			req.type);
 
 	switch (req.type) {
+	case VDUSE_GET_VQ_STATE:
+		vq = dev->virtqueue[req.vq_state.index];
+		VHOST_LOG_CONFIG(dev->ifname, INFO, "\tvq index: %u, avail_index: %u\n",
+				req.vq_state.index, vq->last_avail_idx);
+		resp.vq_state.split.avail_index = vq->last_avail_idx;
+		resp.result = VDUSE_REQ_RESULT_OK;
+		break;
 	default:
 		resp.result = VDUSE_REQ_RESULT_FAILED;
 		break;