diff mbox series

[2/8] vhost: add helper to check if a vq has been setup

Message ID 1600712588-9514-3-git-send-email-michael.christie@oracle.com
State New
Headers show
Series vhost scsi: fixes and cleanups | expand

Commit Message

Mike Christie Sept. 21, 2020, 6:23 p.m. UTC
This adds a helper check if a vq has been setup. The next patches
will use this when we move the vhost scsi cmd preallocation from per
session to per vq. In the per vq case, we only want to allocate cmds
for vqs that have actually been setup and not for all the possible
vqs.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/vhost/vhost.c | 9 +++++++++
 drivers/vhost/vhost.h | 1 +
 2 files changed, 10 insertions(+)

Comments

Jason Wang Sept. 22, 2020, 2:02 a.m. UTC | #1
On 2020/9/22 上午2:23, Mike Christie wrote:
> This adds a helper check if a vq has been setup. The next patches

> will use this when we move the vhost scsi cmd preallocation from per

> session to per vq. In the per vq case, we only want to allocate cmds

> for vqs that have actually been setup and not for all the possible

> vqs.

>

> Signed-off-by: Mike Christie <michael.christie@oracle.com>

> ---

>   drivers/vhost/vhost.c | 9 +++++++++

>   drivers/vhost/vhost.h | 1 +

>   2 files changed, 10 insertions(+)

>

> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c

> index b45519c..5dd9eb1 100644

> --- a/drivers/vhost/vhost.c

> +++ b/drivers/vhost/vhost.c

> @@ -305,6 +305,15 @@ static void vhost_vring_call_reset(struct vhost_vring_call *call_ctx)

>   	spin_lock_init(&call_ctx->ctx_lock);

>   }

>   

> +bool vhost_vq_is_setup(struct vhost_virtqueue *vq)

> +{

> +	if (vq->avail && vq->desc && vq->used && vhost_vq_access_ok(vq))

> +		return true;

> +	else

> +		return false;

> +}

> +EXPORT_SYMBOL_GPL(vhost_vq_is_setup);



This is probably ok but I wonder maybe we should have something like 
what vDPA did (VHOST_SET_VRING_ENABLE) to match virtio 1.0 device 
definition.

Thanks


> +

>   static void vhost_vq_reset(struct vhost_dev *dev,

>   			   struct vhost_virtqueue *vq)

>   {

> diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h

> index 9032d3c..3d30b3d 100644

> --- a/drivers/vhost/vhost.h

> +++ b/drivers/vhost/vhost.h

> @@ -190,6 +190,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *,

>   		      struct vhost_log *log, unsigned int *log_num);

>   void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);

>   

> +bool vhost_vq_is_setup(struct vhost_virtqueue *vq);

>   int vhost_vq_init_access(struct vhost_virtqueue *);

>   int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len);

>   int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads,
Bart Van Assche Sept. 22, 2020, 2:45 a.m. UTC | #2
On 2020-09-21 11:23, Mike Christie wrote:
> +bool vhost_vq_is_setup(struct vhost_virtqueue *vq)

> +{

> +	if (vq->avail && vq->desc && vq->used && vhost_vq_access_ok(vq))

> +		return true;

> +	else

> +		return false;

> +}


Has it been considered changing the body of this function into
"return vq->avail && vq->desc && vq->used && vhost_vq_access_ok(vq)"? I'm
concerned otherwise one or another build bot will suggest to make that
change.

Thanks,

Bart.
Mike Christie Sept. 22, 2020, 3:34 p.m. UTC | #3
> On Sep 21, 2020, at 9:45 PM, Bart Van Assche <bvanassche@acm.org> wrote:

> 

> On 2020-09-21 11:23, Mike Christie wrote:

>> +bool vhost_vq_is_setup(struct vhost_virtqueue *vq)

>> +{

>> +	if (vq->avail && vq->desc && vq->used && vhost_vq_access_ok(vq))

>> +		return true;

>> +	else

>> +		return false;

>> +}

> 

> Has it been considered changing the body of this function into

> "return vq->avail && vq->desc && vq->used && vhost_vq_access_ok(vq)"? I'm


If we do not go the VHOST_SET_VRING_ENABLE route, then I'll do what you suggest.


> concerned otherwise one or another build bot will suggest to make that

> change.
diff mbox series

Patch

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index b45519c..5dd9eb1 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -305,6 +305,15 @@  static void vhost_vring_call_reset(struct vhost_vring_call *call_ctx)
 	spin_lock_init(&call_ctx->ctx_lock);
 }
 
+bool vhost_vq_is_setup(struct vhost_virtqueue *vq)
+{
+	if (vq->avail && vq->desc && vq->used && vhost_vq_access_ok(vq))
+		return true;
+	else
+		return false;
+}
+EXPORT_SYMBOL_GPL(vhost_vq_is_setup);
+
 static void vhost_vq_reset(struct vhost_dev *dev,
 			   struct vhost_virtqueue *vq)
 {
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 9032d3c..3d30b3d 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -190,6 +190,7 @@  int vhost_get_vq_desc(struct vhost_virtqueue *,
 		      struct vhost_log *log, unsigned int *log_num);
 void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);
 
+bool vhost_vq_is_setup(struct vhost_virtqueue *vq);
 int vhost_vq_init_access(struct vhost_virtqueue *);
 int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len);
 int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads,