vhost: use another variable to store vhost msg result code
PATCH 1/1 vhost: use another variable to store vhost msg result code
Currently in function vhost_user_msg_handler, variable ret is used to store both vhost msg result code and function call return value. After this patch, variable ret is used only to store function call return value, a new variable msg_result is used to store vhost msg result. This can improve readability.
--- lib/vhost/vhost_user.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
lib/vhost/vhost_user.c +12 -12
@@ -2969,6 +2969,7 @@ static int is_vring_iotlb(struct virtio_net *dev,struct vhu_msg_context ctx;vhost_message_handler_t *msg_handler;struct rte_vdpa_device *vdpa_dev; +int msg_result =RTE_VHOST_MSG_RESULT_OK ;int ret;int unlock_required =0 ;bool handled;
@@ -3061,8 +3062,8 @@ static int is_vring_iotlb(struct virtio_net *dev, handled = false;if (dev->extern_ops.pre_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);/* Fall-through */
@@ -3080,12 +3081,12 @@ static int is_vring_iotlb(struct virtio_net *dev, goto skip_to_post_handle;if (!msg_handler->accepts_fd &&validate_msg_fds (dev, &ctx,0 ) !=0 ) { - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }else { - ret = msg_handler->callback (&dev, &ctx, fd); + msg_result = msg_handler->callback (&dev, &ctx, fd); } -switch (ret) { +switch (msg_result) {case RTE_VHOST_MSG_RESULT_ERR : VHOST_LOG_CONFIG(dev->ifname, ERR, "processing %s failed.\n",
@@ -3110,11 +3111,11 @@ static int is_vring_iotlb(struct virtio_net *dev, } skip_to_post_handle: -if (ret !=RTE_VHOST_MSG_RESULT_ERR && +if (msg_result !=RTE_VHOST_MSG_RESULT_ERR && dev->extern_ops.post_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);/* Fall-through */
@@ -3133,7 +3134,7 @@ static int is_vring_iotlb(struct virtio_net *dev,"vhost message (req: %d) was not handled.\n" , request);close_msg_fds (&ctx); - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }/*
@@ -3142,17 +3143,16 @@ static int is_vring_iotlb(struct virtio_net *dev,* VHOST_USER_NEED_REPLY was cleared in send_vhost_reply(). */ if (ctx.msg.flags &VHOST_USER_NEED_REPLY ) { - ctx.msg.payload.u64 = ret ==RTE_VHOST_MSG_RESULT_ERR ; + ctx.msg.payload.u64 = msg_result ==RTE_VHOST_MSG_RESULT_ERR ; ctx.msg.size =sizeof (ctx.msg.payload.u64); ctx.fd_num =0 ;send_vhost_reply (dev, fd, &ctx); - }else if (ret ==RTE_VHOST_MSG_RESULT_ERR ) { + }else if (msg_result ==RTE_VHOST_MSG_RESULT_ERR ) {VHOST_LOG_CONFIG (dev->ifname,ERR ,"vhost message handling failed.\n" ); ret =-1 ; goto unlock; } - ret =0 ;for (i =0 ; i < dev->nr_vring; i++) {struct vhost_virtqueue *vq = dev->virtqueue[i];bool cur_ready =vq_is_ready (dev, vq);
Signature · 1 line
1.8.3.1
Quoted 8 lines
-----Original Message-----
From: Pei, Andy <[email protected]>
Sent: Monday, July 18, 2022 10:07 AM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Ma, WenwuX <[email protected]>
Subject: [PATCH] vhost: use another variable to store vhost msg result code
Patch looks good. I suggest to use title:
vhost: use dedicated variable for vhost message result code\\
Thanks,
Chenbo
Quoted 100 lines
Currently in function
vhost_user_msg_handler, variable ret is used to store both vhost msg result code and function call return value. After this patch, variable ret is used only to store function call return value, a new variablemsg_resultis used to store vhost msg result. This can improve readability.Signed-off-by Andy Pei <[email protected]>--- lib/vhost/vhost_user.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)lib/vhost/vhost_user.c +6
-5@@ -2969,6 +2969,7 @@ static int is_vring_iotlb(struct virtio_net *dev,struct vhu_msg_context ctx;vhost_message_handler_t *msg_handler;struct rte_vdpa_device *vdpa_dev; +int msg_result =RTE_VHOST_MSG_RESULT_OK ;int ret;int unlock_required =0 ;bool handled;@@ -3061,8 +3062,8 @@ static int is_vring_iotlb(struct virtio_net *dev, handled = false;if (dev->extern_ops.pre_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);/* Fall-through */ @@ -3080,12 +3081,12 @@ static int is_vring_iotlb(struct virtio_net *dev, goto skip_to_post_handle;if (!msg_handler->accepts_fd &&validate_msg_fds (dev, &ctx,0 ) !=0 ) { - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }else { - ret = msg_handler->callback (&dev, &ctx, fd); + msg_result = msg_handler->callback (&dev, &ctx, fd); } -switch (ret) { +switch (msg_result) {case RTE_VHOST_MSG_RESULT_ERR : VHOST_LOG_CONFIG(dev->ifname, ERR,lib/vhost/vhost_user.c +3
-3"processing %s failed.\n",@@ -3110,11 +3111,11 @@ static int is_vring_iotlb(struct virtio_net *dev, } skip_to_post_handle: -if (ret !=RTE_VHOST_MSG_RESULT_ERR && +if (msg_result !=RTE_VHOST_MSG_RESULT_ERR && dev->extern_ops.post_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);lib/vhost/vhost_user.c +3
-4/* Fall-through */ @@ -3133,7 +3134,7 @@ static int is_vring_iotlb(struct virtio_net *dev,"vhost message (req: %d) was not handled.\n" , request);close_msg_fds (&ctx); - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }/* @@ -3142,17 +3143,16 @@ static int is_vring_iotlb(struct virtio_net *dev,* VHOST_USER_NEED_REPLY was cleared in send_vhost_reply(). */ if (ctx.msg.flags &VHOST_USER_NEED_REPLY ) { - ctx.msg.payload.u64 = ret ==RTE_VHOST_MSG_RESULT_ERR ; + ctx.msg.payload.u64 = msg_result ==RTE_VHOST_MSG_RESULT_ERR ; ctx.msg.size =sizeof (ctx.msg.payload.u64); ctx.fd_num =0 ;send_vhost_reply (dev, fd, &ctx); - }else if (ret ==RTE_VHOST_MSG_RESULT_ERR ) { + }else if (msg_result ==RTE_VHOST_MSG_RESULT_ERR ) { VHOST_LOG_CONFIG(dev->ifname, ERR, "vhost message handling failed.\n"); ret =-1 ; goto unlock; } - ret =0 ;for (i =0 ; i < dev->nr_vring; i++) {struct vhost_virtqueue *vq = dev->virtqueue[i];bool
cur_ready=vq_is_ready(dev, vq);
--
1.8.3.1
HI Chenbo,
Thanks for your reply.
I think your suggestion is good, and I will send a V2 patch to address this.
Quoted 127 lines
-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Thursday, September 22, 2022 9:27 PM
To: Pei, Andy <[email protected]>; [email protected]
Cc: [email protected]; Ma, WenwuX <[email protected]>
Subject: RE: [PATCH] vhost: use another variable to store vhost msg result codeQuoted 8 lines
-----Original Message-----
From: Pei, Andy <[email protected]>
Sent: Monday, July 18, 2022 10:07 AM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Ma, WenwuX <[email protected]>
Subject: [PATCH] vhost: use another variable to store vhost msg result codePatch looks good. I suggest to use title:
vhost: use dedicated variable for vhost message result code\\Thanks,
ChenboQuoted 25 lines
Currently in function
vhost_user_msg_handler, variable ret is used to store both vhost msg result code and function call return value. After this patch, variable ret is used only to store function call return value, a new variablemsg_resultis used to store vhost msg result. This can improve readability.Signed-off-by Andy Pei <[email protected]>--- lib/vhost/vhost_user.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)lib/vhost/vhost_user.c index renamed from lib/vhost/vhost_user.c +0
-04ad28ba..dac06c9 100644
lib/vhost/vhost_user.c +1
-0@@ -2969,6 +2969,7 @@ static int is_vring_iotlb(struct virtio_net *dev,struct vhu_msg_context ctx;vhost_message_handler_t *msg_handler;struct rte_vdpa_device *vdpa_dev; +int msg_result =RTE_VHOST_MSG_RESULT_OK ;int ret;int unlock_required =0 ;bool handled;lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev, · line 3064
Quoted 3 lines
lib/vhost/vhost_user.c +0
-0@@ -3061,8 +3062,8 @@ static int is_vring_iotlb(struct virtio_net *dev, handled = false;if (dev->extern_ops.pre_msg_handle) { RTE_BUILD_BUG_ON(offsetof(struct vhu_msg_context, msg) !=0);
lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev,
Quoted 3 lines
lib/vhost/vhost_user.c +1
-2- ret = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.pre_msg_handle)(dev->vid,&ctx);
Quoted 22 lines
lib/vhost/vhost_user.c +4
-3+switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);/* Fall-through */ @@ -3080,12 +3081,12 @@ static int is_vring_iotlb(struct virtio_net *dev, goto skip_to_post_handle;if (!msg_handler->accepts_fd &&validate_msg_fds (dev, &ctx,0 ) !=0 ) { - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }else { - ret = msg_handler->callback (&dev, &ctx, fd); + msg_result = msg_handler->callback (&dev, &ctx, fd); } -switch (ret) { +switch (msg_result) {case RTE_VHOST_MSG_RESULT_ERR : VHOST_LOG_CONFIG(dev->ifname, ERR,lib/vhost/vhost_user.c +0
-0"processing %s failed.\n",lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev, · line 3116
Quoted 7 lines
lib/vhost/vhost_user.c +1
-1@@ -3110,11 +3111,11 @@ static int is_vring_iotlb(struct virtio_net *dev, } skip_to_post_handle: -if (ret !=RTE_VHOST_MSG_RESULT_ERR && +if (msg_result !=RTE_VHOST_MSG_RESULT_ERR && dev->extern_ops.post_msg_handle) { RTE_BUILD_BUG_ON(offsetof(struct vhu_msg_context, msg) !=0);
Quoted 18 lines
lib/vhost/vhost_user.c +2
-2- ret = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);lib/vhost/vhost_user.c +1
-1/* Fall-through */ @@ -3133,7 +3134,7 @@ static int is_vring_iotlb(struct virtio_net *dev,"vhost message (req: %d) was not handled.\n" , request);close_msg_fds (&ctx); - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }/* lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev, · line 3146
Quoted 5 lines
lib/vhost/vhost_user.c +1
-1@@ -3142,17 +3143,16 @@ static int is_vring_iotlb(struct virtio_net *dev,* VHOST_USER_NEED_REPLY was cleared in send_vhost_reply(). */ if (ctx.msg.flags &VHOST_USER_NEED_REPLY ) { - ctx.msg.payload.u64 = ret ==RTE_VHOST_MSG_RESULT_ERR ; + ctx.msg.payload.u64 = msg_result ==
RTE_VHOST_MSG_RESULT_ERR;lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev,
Quoted 6 lines
lib/vhost/vhost_user.c +1
-1ctx.msg.size =sizeof (ctx.msg.payload.u64); ctx.fd_num =0 ;send_vhost_reply (dev, fd, &ctx); - }else if (ret ==RTE_VHOST_MSG_RESULT_ERR ) { + }else if (msg_result ==RTE_VHOST_MSG_RESULT_ERR ) { VHOST_LOG_CONFIG(dev->ifname, ERR, "vhost messagehandling
Quoted 11 lines
lib/vhost/vhost_user.c +0
-1failed.\n"); ret =-1 ; goto unlock; } - ret =0 ;for (i =0 ; i < dev->nr_vring; i++) {struct vhost_virtqueue *vq = dev->virtqueue[i];bool
cur_ready=vq_is_ready(dev, vq);
--
1.8.3.1
PATCH v2 1/1 vhost: use dedicated variable for vhost message result code
In reply to Andy PeiCurrently in function vhost_user_msg_handler, variable ret is used to store both vhost msg result code and function call return value. After this patch, variable ret is used only to store function call return value, a new dedicated variable msg_result is used to store vhost msg result. This can improve readability.
--- lib/vhost/vhost_user.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
lib/vhost/vhost_user.c +12 -12
@@ -2954,6 +2954,7 @@ static int is_vring_iotlb(struct virtio_net *dev,struct vhu_msg_context ctx;vhost_message_handler_t *msg_handler;struct rte_vdpa_device *vdpa_dev; +int msg_result =RTE_VHOST_MSG_RESULT_OK ;int ret;int unlock_required =0 ;bool handled;
@@ -3046,8 +3047,8 @@ static int is_vring_iotlb(struct virtio_net *dev, handled = false;if (dev->extern_ops.pre_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);/* Fall-through */
@@ -3065,12 +3066,12 @@ static int is_vring_iotlb(struct virtio_net *dev, goto skip_to_post_handle;if (!msg_handler->accepts_fd &&validate_msg_fds (dev, &ctx,0 ) !=0 ) { - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }else { - ret = msg_handler->callback (&dev, &ctx, fd); + msg_result = msg_handler->callback (&dev, &ctx, fd); } -switch (ret) { +switch (msg_result) {case RTE_VHOST_MSG_RESULT_ERR : VHOST_LOG_CONFIG(dev->ifname, ERR, "processing %s failed.\n",
@@ -3095,11 +3096,11 @@ static int is_vring_iotlb(struct virtio_net *dev, } skip_to_post_handle: -if (ret !=RTE_VHOST_MSG_RESULT_ERR && +if (msg_result !=RTE_VHOST_MSG_RESULT_ERR && dev->extern_ops.post_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);/* Fall-through */
@@ -3118,7 +3119,7 @@ static int is_vring_iotlb(struct virtio_net *dev,"vhost message (req: %d) was not handled.\n" , request);close_msg_fds (&ctx); - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }/*
@@ -3127,17 +3128,16 @@ static int is_vring_iotlb(struct virtio_net *dev,* VHOST_USER_NEED_REPLY was cleared in send_vhost_reply(). */ if (ctx.msg.flags &VHOST_USER_NEED_REPLY ) { - ctx.msg.payload.u64 = ret ==RTE_VHOST_MSG_RESULT_ERR ; + ctx.msg.payload.u64 = msg_result ==RTE_VHOST_MSG_RESULT_ERR ; ctx.msg.size =sizeof (ctx.msg.payload.u64); ctx.fd_num =0 ;send_vhost_reply (dev, fd, &ctx); - }else if (ret ==RTE_VHOST_MSG_RESULT_ERR ) { + }else if (msg_result ==RTE_VHOST_MSG_RESULT_ERR ) {VHOST_LOG_CONFIG (dev->ifname,ERR ,"vhost message handling failed.\n" ); ret =-1 ; goto unlock; } - ret =0 ;for (i =0 ; i < dev->nr_vring; i++) {struct vhost_virtqueue *vq = dev->virtqueue[i];bool cur_ready =vq_is_ready (dev, vq);
Signature · 1 line
1.8.3.1
RE: [PATCH v2] vhost: use dedicated variable for vhost message result code
Quoted 104 lines
-----Original Message-----
From: Pei, Andy <[email protected]>
Sent: Friday, September 23, 2022 10:33 AM
To: [email protected]
Cc: Xia, Chenbo <[email protected]>; [email protected]
Subject: [PATCH v2] vhost: use dedicated variable for vhost message result codeCurrently in function
vhost_user_msg_handler, variable ret is used to store both vhost msg result code and function call return value. After this patch, variable ret is used only to store function call return value, a new dedicated variablemsg_resultis used to store vhost msg result. This can improve readability.Signed-off-by Andy Pei <[email protected]>--- lib/vhost/vhost_user.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)lib/vhost/vhost_user.c +6
-5@@ -2954,6 +2954,7 @@ static int is_vring_iotlb(struct virtio_net *dev,struct vhu_msg_context ctx;vhost_message_handler_t *msg_handler;struct rte_vdpa_device *vdpa_dev; +int msg_result =RTE_VHOST_MSG_RESULT_OK ;int ret;int unlock_required =0 ;bool handled;@@ -3046,8 +3047,8 @@ static int is_vring_iotlb(struct virtio_net *dev, handled = false;if (dev->extern_ops.pre_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);/* Fall-through */ @@ -3065,12 +3066,12 @@ static int is_vring_iotlb(struct virtio_net *dev, goto skip_to_post_handle;if (!msg_handler->accepts_fd &&validate_msg_fds (dev, &ctx,0 ) !=0 ) { - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }else { - ret = msg_handler->callback (&dev, &ctx, fd); + msg_result = msg_handler->callback (&dev, &ctx, fd); } -switch (ret) { +switch (msg_result) {case RTE_VHOST_MSG_RESULT_ERR : VHOST_LOG_CONFIG(dev->ifname, ERR,lib/vhost/vhost_user.c +3
-3"processing %s failed.\n",@@ -3095,11 +3096,11 @@ static int is_vring_iotlb(struct virtio_net *dev, } skip_to_post_handle: -if (ret !=RTE_VHOST_MSG_RESULT_ERR && +if (msg_result !=RTE_VHOST_MSG_RESULT_ERR && dev->extern_ops.post_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);lib/vhost/vhost_user.c +3
-4/* Fall-through */ @@ -3118,7 +3119,7 @@ static int is_vring_iotlb(struct virtio_net *dev,"vhost message (req: %d) was not handled.\n" , request);close_msg_fds (&ctx); - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }/* @@ -3127,17 +3128,16 @@ static int is_vring_iotlb(struct virtio_net *dev,* VHOST_USER_NEED_REPLY was cleared in send_vhost_reply(). */ if (ctx.msg.flags &VHOST_USER_NEED_REPLY ) { - ctx.msg.payload.u64 = ret ==RTE_VHOST_MSG_RESULT_ERR ; + ctx.msg.payload.u64 = msg_result ==RTE_VHOST_MSG_RESULT_ERR ; ctx.msg.size =sizeof (ctx.msg.payload.u64); ctx.fd_num =0 ;send_vhost_reply (dev, fd, &ctx); - }else if (ret ==RTE_VHOST_MSG_RESULT_ERR ) { + }else if (msg_result ==RTE_VHOST_MSG_RESULT_ERR ) { VHOST_LOG_CONFIG(dev->ifname, ERR, "vhost message handling failed.\n"); ret =-1 ; goto unlock; } - ret =0 ;for (i =0 ; i < dev->nr_vring; i++) {struct vhost_virtqueue *vq = dev->virtqueue[i];
Quoted 3 lines
bool
cur_ready=vq_is_ready(dev, vq);
--
1.8.3.1
Xia, Chenbo
AppliedRE: [PATCH v2] vhost: use dedicated variable for vhost message result code
Quoted 110 lines
-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Monday, September 26, 2022 2:58 PM
To: Pei, Andy <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v2] vhost: use dedicated variable for vhost message result codeQuoted 6 lines
-----Original Message-----
From: Pei, Andy <[email protected]>
Sent: Friday, September 23, 2022 10:33 AM
To: [email protected]
Cc: Xia, Chenbo <[email protected]>; [email protected]
Subject: [PATCH v2] vhost: use dedicated variable for vhost messageresult
Quoted 95 lines
code
Currently in function
vhost_user_msg_handler, variable ret is used to store both vhost msg result code and function call return value. After this patch, variable ret is used only to store function call return value, a new dedicated variablemsg_resultis used to store vhost msg result. This can improve readability.Signed-off-by Andy Pei <[email protected]>--- lib/vhost/vhost_user.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)lib/vhost/vhost_user.c +6
-5@@ -2954,6 +2954,7 @@ static int is_vring_iotlb(struct virtio_net *dev,struct vhu_msg_context ctx;vhost_message_handler_t *msg_handler;struct rte_vdpa_device *vdpa_dev; +int msg_result =RTE_VHOST_MSG_RESULT_OK ;int ret;int unlock_required =0 ;bool handled;@@ -3046,8 +3047,8 @@ static int is_vring_iotlb(struct virtio_net *dev, handled = false;if (dev->extern_ops.pre_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);/* Fall-through */ @@ -3065,12 +3066,12 @@ static int is_vring_iotlb(struct virtio_net *dev, goto skip_to_post_handle;if (!msg_handler->accepts_fd &&validate_msg_fds (dev, &ctx,0 ) !=0 ) { - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }else { - ret = msg_handler->callback (&dev, &ctx, fd); + msg_result = msg_handler->callback (&dev, &ctx, fd); } -switch (ret) { +switch (msg_result) {case RTE_VHOST_MSG_RESULT_ERR : VHOST_LOG_CONFIG(dev->ifname, ERR,lib/vhost/vhost_user.c +3
-3"processing %s failed.\n",@@ -3095,11 +3096,11 @@ static int is_vring_iotlb(struct virtio_net *dev, } skip_to_post_handle: -if (ret !=RTE_VHOST_MSG_RESULT_ERR && +if (msg_result !=RTE_VHOST_MSG_RESULT_ERR && dev->extern_ops.post_msg_handle) {RTE_BUILD_BUG_ON (offsetof(struct vhu_msg_context , msg) !=0 ); - ret = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);lib/vhost/vhost_user.c +3
-3/* Fall-through */ @@ -3118,7 +3119,7 @@ static int is_vring_iotlb(struct virtio_net *dev,"vhost message (req: %d) was not handled.\n" , request);close_msg_fds (&ctx); - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }/* @@ -3127,17 +3128,16 @@ static int is_vring_iotlb(struct virtio_net *dev,* VHOST_USER_NEED_REPLY was cleared in send_vhost_reply(). */ if (ctx.msg.flags &VHOST_USER_NEED_REPLY ) { - ctx.msg.payload.u64 = ret ==RTE_VHOST_MSG_RESULT_ERR ; + ctx.msg.payload.u64 = msg_result ==RTE_VHOST_MSG_RESULT_ERR ; ctx.msg.size =sizeof (ctx.msg.payload.u64); ctx.fd_num =0 ;send_vhost_reply (dev, fd, &ctx); - }else if (ret ==RTE_VHOST_MSG_RESULT_ERR ) { + }else if (msg_result ==RTE_VHOST_MSG_RESULT_ERR ) { VHOST_LOG_CONFIG(dev->ifname, ERR, "vhost message handling failed.\n"); ret =-1 ; goto unlock; }
Quoted 8 lines
Quoted 6 lines
lib/vhost/vhost_user.c +0
-1- ret =0 ;for (i =0 ; i < dev->nr_vring; i++) {struct vhost_virtqueue *vq = dev->virtqueue[i];bool
cur_ready=vq_is_ready(dev, vq);
--
1.8.3.1Reviewed-by Chenbo Xia <[email protected]>
Applied to next-virtio/main, thanks
RE: [PATCH v2] vhost: use dedicated variable for vhost message result code
Hi Chenbo,
Thanks for your efforts.
Quoted 133 lines
-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Thursday, September 29, 2022 4:38 PM
To: Pei, Andy <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v2] vhost: use dedicated variable for vhost message result codeQuoted 28 lines
-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Monday, September 26, 2022 2:58 PM
To: Pei, Andy <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v2] vhost: use dedicated variable for vhost message result codeQuoted 6 lines
-----Original Message-----
From: Pei, Andy <[email protected]>
Sent: Friday, September 23, 2022 10:33 AM
To: [email protected]
Cc: Xia, Chenbo <[email protected]>; [email protected]
Subject: [PATCH v2] vhost: use dedicated variable for vhost messageresult
Quoted 13 lines
code
Currently in function
vhost_user_msg_handler, variable ret is used to store both vhost msg result code and function call return value. After this patch, variable ret is used only to store function call return value, a new dedicated variablemsg_resultis used to store vhost msg result. This can improve readability.Signed-off-by Andy Pei <[email protected]>--- lib/vhost/vhost_user.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)Quoted 16 lines
Quoted 13 lines
lib/vhost/vhost_user.c index renamed from lib/vhost/vhost_user.c +0
-00182090..6d93495 100644
lib/vhost/vhost_user.c +1
-0@@ -2954,6 +2954,7 @@ static int is_vring_iotlb(struct virtio_net *dev,struct vhu_msg_context ctx;vhost_message_handler_t *msg_handler;struct rte_vdpa_device *vdpa_dev; +int msg_result =RTE_VHOST_MSG_RESULT_OK ;int ret;int unlock_required =0 ;bool handled;lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev, · line 3049
Quoted 3 lines
lib/vhost/vhost_user.c +0
-0@@ -3046,8 +3047,8 @@ static int is_vring_iotlb(struct virtio_net *dev, handled = false;if (dev->extern_ops.pre_msg_handle) { RTE_BUILD_BUG_ON(offsetof(struct vhu_msg_context,msg) != 0);
Quoted 3 lines
lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev,
Quoted 3 lines
lib/vhost/vhost_user.c +1
-2- ret = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.pre_msg_handle)(dev->vid,&ctx);
Quoted 24 lines
Quoted 24 lines
lib/vhost/vhost_user.c +4
-3+switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);/* Fall-through */ @@ -3065,12 +3066,12 @@ static int is_vring_iotlb(struct virtio_net *dev, goto skip_to_post_handle;if (!msg_handler->accepts_fd &&validate_msg_fds (dev, &ctx,0 ) !=0 ) { - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }else { - ret = msg_handler->callback (&dev, &ctx, fd); + msg_result = msg_handler->callback (&dev, &ctx, fd); } -switch (ret) { +switch (msg_result) {case RTE_VHOST_MSG_RESULT_ERR : VHOST_LOG_CONFIG(dev->ifname, ERR,lib/vhost/vhost_user.c +0
-0"processing %s failed.\n",@@ -3095,11 +3096,11 @@ static int is_vring_iotlb(struct virtio_net *dev, }Quoted 5 lines
lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev,
Quoted 5 lines
lib/vhost/vhost_user.c +1
-1skip_to_post_handle: -if (ret !=RTE_VHOST_MSG_RESULT_ERR && +if (msg_result !=RTE_VHOST_MSG_RESULT_ERR && dev->extern_ops.post_msg_handle) { RTE_BUILD_BUG_ON(offsetof(struct vhu_msg_context,msg) != 0);
Quoted 16 lines
Quoted 16 lines
lib/vhost/vhost_user.c +2
-2- ret = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); -switch (ret) { + msg_result = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx); +switch (msg_result) {case RTE_VHOST_MSG_RESULT_REPLY :send_vhost_reply (dev, fd, &ctx);lib/vhost/vhost_user.c +1
-1/* Fall-through */ @@ -3118,7 +3119,7 @@ static int is_vring_iotlb(struct virtio_net *dev,"vhost message (req: %d) was not handled.\n" , request);close_msg_fds (&ctx); - ret =RTE_VHOST_MSG_RESULT_ERR ; + msg_result =RTE_VHOST_MSG_RESULT_ERR ; }Quoted 7 lines
lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev, · line 3131
Quoted 7 lines
lib/vhost/vhost_user.c +1
-1/* @@ -3127,17 +3128,16 @@ static int is_vring_iotlb(struct virtio_net *dev,* VHOST_USER_NEED_REPLY was cleared in send_vhost_reply(). */ if (ctx.msg.flags &VHOST_USER_NEED_REPLY ) { - ctx.msg.payload.u64 = ret ==RTE_VHOST_MSG_RESULT_ERR ; + ctx.msg.payload.u64 = msg_result ==
RTE_VHOST_MSG_RESULT_ERR;Quoted 6 lines
lib/vhost/vhost_user.c static int is_vring_iotlb(struct virtio_net *dev,
Quoted 6 lines
lib/vhost/vhost_user.c +1
-1ctx.msg.size =sizeof (ctx.msg.payload.u64); ctx.fd_num =0 ;send_vhost_reply (dev, fd, &ctx); - }else if (ret ==RTE_VHOST_MSG_RESULT_ERR ) { + }else if (msg_result ==RTE_VHOST_MSG_RESULT_ERR ) { VHOST_LOG_CONFIG(dev->ifname, ERR, "vhost messagehandling
Quoted 5 lines
Quoted 5 lines
lib/vhost/vhost_user.c +0
-0failed.\n"); ret =-1 ; goto unlock; }Quoted 8 lines
Quoted 6 lines
lib/vhost/vhost_user.c +0
-1- ret =0 ;for (i =0 ; i < dev->nr_vring; i++) {struct vhost_virtqueue *vq = dev->virtqueue[i];bool
cur_ready=vq_is_ready(dev, vq);
--
1.8.3.1Reviewed-by Chenbo Xia <[email protected]>Applied to next-virtio/main, thanks