[v3,5/8] net/virtio: check protocol feature in user backend

Message ID 20200929161404.124580-6-maxime.coquelin@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series virtio-user: introduce vhost-vdpa backend |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Maxime Coquelin Sept. 29, 2020, 4:14 p.m. UTC
  When sending set status message, move protocol feature check
to vhost_user to be compatible with different backend types.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/net/virtio/virtio_user/vhost_user.c      | 6 +++++-
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 6 ------
 2 files changed, 5 insertions(+), 7 deletions(-)
  

Comments

Chenbo Xia Sept. 30, 2020, 5:49 a.m. UTC | #1
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Wednesday, September 30, 2020 12:14 AM
> To: dev@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>; Fu, Patrick
> <patrick.fu@intel.com>; amorenoz@redhat.com
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: [PATCH v3 5/8] net/virtio: check protocol feature in user backend
> 
> When sending set status message, move protocol feature check
> to vhost_user to be compatible with different backend types.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  drivers/net/virtio/virtio_user/vhost_user.c      | 6 +++++-
>  drivers/net/virtio/virtio_user/virtio_user_dev.c | 6 ------
>  2 files changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/vhost_user.c
> b/drivers/net/virtio/virtio_user/vhost_user.c
> index 12b6c7dbcf..ef290c357b 100644
> --- a/drivers/net/virtio/virtio_user/vhost_user.c
> +++ b/drivers/net/virtio/virtio_user/vhost_user.c
> @@ -277,9 +277,13 @@ vhost_user_sock(struct virtio_user_dev *dev,
>  	msg.size = 0;
> 
>  	switch (req) {
> +	case VHOST_USER_GET_STATUS:
> +		if (!(dev->protocol_features &
> +				(1ULL << VHOST_USER_PROTOCOL_F_STATUS)))
> +			return 0;
> +		/* Fallthrough */
>  	case VHOST_USER_GET_FEATURES:
>  	case VHOST_USER_GET_PROTOCOL_FEATURES:
> -	case VHOST_USER_GET_STATUS:
>  		need_reply = 1;
>  		break;
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index b79a9f84aa..d7cd6b0346 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -788,9 +788,6 @@ virtio_user_send_status_update(struct virtio_user_dev
> *dev, uint8_t status)
>  	if (dev->backend_type != VIRTIO_USER_BACKEND_VHOST_USER)
>  		return 0;
> 
> -	if (!(dev->protocol_features & (1ULL <<
> VHOST_USER_PROTOCOL_F_STATUS)))
> -		return 0;
> -
>  	ret = dev->ops->send_request(dev, VHOST_USER_SET_STATUS, &arg);
>  	if (ret) {
>  		PMD_INIT_LOG(ERR, "VHOST_USER_SET_STATUS failed (%d): %s", ret,
> @@ -811,9 +808,6 @@ virtio_user_update_status(struct virtio_user_dev *dev)
>  	if (dev->backend_type != VIRTIO_USER_BACKEND_VHOST_USER)
>  		return 0;
> 
> -	if (!(dev->protocol_features & (1UL <<
> VHOST_USER_PROTOCOL_F_STATUS)))
> -		return 0;
> -
>  	err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret);
>  	if (err) {
>  		PMD_INIT_LOG(ERR, "VHOST_USER_GET_STATUS failed (%d): %s", err,
> --
> 2.26.2

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

Patch

diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c
index 12b6c7dbcf..ef290c357b 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -277,9 +277,13 @@  vhost_user_sock(struct virtio_user_dev *dev,
 	msg.size = 0;
 
 	switch (req) {
+	case VHOST_USER_GET_STATUS:
+		if (!(dev->protocol_features &
+				(1ULL << VHOST_USER_PROTOCOL_F_STATUS)))
+			return 0;
+		/* Fallthrough */
 	case VHOST_USER_GET_FEATURES:
 	case VHOST_USER_GET_PROTOCOL_FEATURES:
-	case VHOST_USER_GET_STATUS:
 		need_reply = 1;
 		break;
 
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index b79a9f84aa..d7cd6b0346 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -788,9 +788,6 @@  virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status)
 	if (dev->backend_type != VIRTIO_USER_BACKEND_VHOST_USER)
 		return 0;
 
-	if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_STATUS)))
-		return 0;
-
 	ret = dev->ops->send_request(dev, VHOST_USER_SET_STATUS, &arg);
 	if (ret) {
 		PMD_INIT_LOG(ERR, "VHOST_USER_SET_STATUS failed (%d): %s", ret,
@@ -811,9 +808,6 @@  virtio_user_update_status(struct virtio_user_dev *dev)
 	if (dev->backend_type != VIRTIO_USER_BACKEND_VHOST_USER)
 		return 0;
 
-	if (!(dev->protocol_features & (1UL << VHOST_USER_PROTOCOL_F_STATUS)))
-		return 0;
-
 	err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret);
 	if (err) {
 		PMD_INIT_LOG(ERR, "VHOST_USER_GET_STATUS failed (%d): %s", err,