diff mbox

[v7,1/3] tcm_vhost: Introduce tcm_vhost_check_feature()

Message ID 1366247154-3136-2-git-send-email-asias@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Asias He April 18, 2013, 1:05 a.m. UTC
This helper is useful to check if a feature is supported.

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

Comments

Michael S. Tsirkin April 18, 2013, 7:06 a.m. UTC | #1
On Thu, Apr 18, 2013 at 09:05:52AM +0800, Asias He wrote:
> This helper is useful to check if a feature is supported.
> 
> Signed-off-by: Asias He <asias@redhat.com>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

Why do we need the locking here by the way?
It seems features don't change while vhost
is running.

> ---
>  drivers/vhost/tcm_vhost.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
> index 957a0b9..88ebb79 100644
> --- a/drivers/vhost/tcm_vhost.c
> +++ b/drivers/vhost/tcm_vhost.c
> @@ -99,6 +99,18 @@ 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, int feature)
> +{
> +	bool ret = false;
> +
> +	mutex_lock(&vs->dev.mutex);
> +	if (vhost_has_feature(&vs->dev, feature))
> +		ret = true;
> +	mutex_unlock(&vs->dev.mutex);
> +
> +	return ret;
> +}
> +
>  static int tcm_vhost_check_true(struct se_portal_group *se_tpg)
>  {
>  	return 1;
> -- 
> 1.8.1.4
--
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
Michael S. Tsirkin April 18, 2013, 7:44 a.m. UTC | #2
On Thu, Apr 18, 2013 at 04:25:21PM +0800, Asias He wrote:
> On Thu, Apr 18, 2013 at 10:06:06AM +0300, Michael S. Tsirkin wrote:
> > On Thu, Apr 18, 2013 at 09:05:52AM +0800, Asias He wrote:
> > > This helper is useful to check if a feature is supported.
> > > 
> > > Signed-off-by: Asias He <asias@redhat.com>
> > > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> > 
> > Why do we need the locking here by the way?
> > It seems features don't change while vhost
> > is running.
> 
> See:
> 
> static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
> {
>         unsigned acked_features;
>         
>         /* TODO: check that we are running from vhost_worker or dev mutex is
>          * held? */
>         acked_features = rcu_dereference_index_check(dev->acked_features, 1);
>         return acked_features & (1 << bit);
> }       
> 
> We are accessing it outside the vhost_worker thread.

Hmm I see, we allow changing features on the fly, and the
reason is the LOG_ALL feature.

Okay ... do we ever call this from worker
thread? Because if we do, this will deadlock.
Maybe add a comment about this.

> > > ---
> > >  drivers/vhost/tcm_vhost.c | 12 ++++++++++++
> > >  1 file changed, 12 insertions(+)
> > > 
> > > diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
> > > index 957a0b9..88ebb79 100644
> > > --- a/drivers/vhost/tcm_vhost.c
> > > +++ b/drivers/vhost/tcm_vhost.c
> > > @@ -99,6 +99,18 @@ 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, int feature)
> > > +{
> > > +	bool ret = false;
> > > +
> > > +	mutex_lock(&vs->dev.mutex);
> > > +	if (vhost_has_feature(&vs->dev, feature))
> > > +		ret = true;
> > > +	mutex_unlock(&vs->dev.mutex);
> > > +
> > > +	return ret;
> > > +}
> > > +
> > >  static int tcm_vhost_check_true(struct se_portal_group *se_tpg)
> > >  {
> > >  	return 1;
> > > -- 
> > > 1.8.1.4
> 
> -- 
> Asias
--
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 April 18, 2013, 8:25 a.m. UTC | #3
On Thu, Apr 18, 2013 at 10:06:06AM +0300, Michael S. Tsirkin wrote:
> On Thu, Apr 18, 2013 at 09:05:52AM +0800, Asias He wrote:
> > This helper is useful to check if a feature is supported.
> > 
> > Signed-off-by: Asias He <asias@redhat.com>
> > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> 
> Why do we need the locking here by the way?
> It seems features don't change while vhost
> is running.

See:

static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
{
        unsigned acked_features;
        
        /* TODO: check that we are running from vhost_worker or dev mutex is
         * held? */
        acked_features = rcu_dereference_index_check(dev->acked_features, 1);
        return acked_features & (1 << bit);
}       

We are accessing it outside the vhost_worker thread.

> > ---
> >  drivers/vhost/tcm_vhost.c | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> > 
> > diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
> > index 957a0b9..88ebb79 100644
> > --- a/drivers/vhost/tcm_vhost.c
> > +++ b/drivers/vhost/tcm_vhost.c
> > @@ -99,6 +99,18 @@ 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, int feature)
> > +{
> > +	bool ret = false;
> > +
> > +	mutex_lock(&vs->dev.mutex);
> > +	if (vhost_has_feature(&vs->dev, feature))
> > +		ret = true;
> > +	mutex_unlock(&vs->dev.mutex);
> > +
> > +	return ret;
> > +}
> > +
> >  static int tcm_vhost_check_true(struct se_portal_group *se_tpg)
> >  {
> >  	return 1;
> > -- 
> > 1.8.1.4
diff mbox

Patch

diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
index 957a0b9..88ebb79 100644
--- a/drivers/vhost/tcm_vhost.c
+++ b/drivers/vhost/tcm_vhost.c
@@ -99,6 +99,18 @@  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, int feature)
+{
+	bool ret = false;
+
+	mutex_lock(&vs->dev.mutex);
+	if (vhost_has_feature(&vs->dev, feature))
+		ret = true;
+	mutex_unlock(&vs->dev.mutex);
+
+	return ret;
+}
+
 static int tcm_vhost_check_true(struct se_portal_group *se_tpg)
 {
 	return 1;