diff mbox

[2/5] tcm_vhost: Introduce tcm_vhost_check_feature()

Message ID 1362550590-3534-3-git-send-email-asias@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Asias He March 6, 2013, 6:16 a.m. UTC
This helper is useful to check if a feature is supported.

Signed-off-by: Asias He <asias@redhat.com>
---
 drivers/vhost/tcm_vhost.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Stefan Hajnoczi March 6, 2013, 9:06 a.m. UTC | #1
On Wed, Mar 06, 2013 at 02:16:27PM +0800, Asias He wrote:
> This helper is useful to check if a feature is supported.
> 
> Signed-off-by: Asias He <asias@redhat.com>
> ---
>  drivers/vhost/tcm_vhost.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
> index b3e50d7..fdbf986 100644
> --- a/drivers/vhost/tcm_vhost.c
> +++ b/drivers/vhost/tcm_vhost.c
> @@ -91,6 +91,20 @@ static int iov_num_pages(struct iovec *iov)
>  	       ((unsigned long)iov->iov_base & PAGE_MASK)) >> PAGE_SHIFT;
>  }
>  
> +static bool tcm_vhost_check_feature(struct vhost_scsi *vs, u64 feature)
> +{
> +	u64 acked_features;
> +	bool ret = false;
> +
> +	mutex_lock(&vs->dev.mutex);
> +	acked_features = vs->dev.acked_features;
> +	if (acked_features & 1ULL << feature)
> +		ret = true;
> +	mutex_unlock(&vs->dev.mutex);
> +
> +	return ret;
> +}

This is like vhost_has_feature() except it acquires dev.mutex?

In any case it isn't tcm_vhost-specific and could be in vhost.c.

Stefan
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Asias He March 7, 2013, 12:35 a.m. UTC | #2
On Wed, Mar 06, 2013 at 10:06:20AM +0100, Stefan Hajnoczi wrote:
> On Wed, Mar 06, 2013 at 02:16:27PM +0800, Asias He wrote:
> > This helper is useful to check if a feature is supported.
> > 
> > Signed-off-by: Asias He <asias@redhat.com>
> > ---
> >  drivers/vhost/tcm_vhost.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
> > index b3e50d7..fdbf986 100644
> > --- a/drivers/vhost/tcm_vhost.c
> > +++ b/drivers/vhost/tcm_vhost.c
> > @@ -91,6 +91,20 @@ static int iov_num_pages(struct iovec *iov)
> >  	       ((unsigned long)iov->iov_base & PAGE_MASK)) >> PAGE_SHIFT;
> >  }
> >  
> > +static bool tcm_vhost_check_feature(struct vhost_scsi *vs, u64 feature)
> > +{
> > +	u64 acked_features;
> > +	bool ret = false;
> > +
> > +	mutex_lock(&vs->dev.mutex);
> > +	acked_features = vs->dev.acked_features;
> > +	if (acked_features & 1ULL << feature)
> > +		ret = true;
> > +	mutex_unlock(&vs->dev.mutex);
> > +
> > +	return ret;
> > +}
> 
> This is like vhost_has_feature() except it acquires dev.mutex?
> 
> In any case it isn't tcm_vhost-specific and could be in vhost.c.

tcm_vhost_check_feature() is called outside the vhost worker thread. So
the dev.mutex is needed. 

Mst, what's your preference here? Add vhost_has_feature_locked() in
vhost.c or I use vhost_has_feature() in tcm_vhost_check_feature().

Thanks.
diff mbox

Patch

diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
index b3e50d7..fdbf986 100644
--- a/drivers/vhost/tcm_vhost.c
+++ b/drivers/vhost/tcm_vhost.c
@@ -91,6 +91,20 @@  static int iov_num_pages(struct iovec *iov)
 	       ((unsigned long)iov->iov_base & PAGE_MASK)) >> PAGE_SHIFT;
 }
 
+static bool tcm_vhost_check_feature(struct vhost_scsi *vs, u64 feature)
+{
+	u64 acked_features;
+	bool ret = false;
+
+	mutex_lock(&vs->dev.mutex);
+	acked_features = vs->dev.acked_features;
+	if (acked_features & 1ULL << feature)
+		ret = true;
+	mutex_unlock(&vs->dev.mutex);
+
+	return ret;
+}
+
 static int tcm_vhost_check_true(struct se_portal_group *se_tpg)
 {
 	return 1;