diff mbox series

[v3,2/2] vhost: Add Error parameter to vhost_scsi_common_start()

Message ID 20230830045722.611224-3-fengli@smartx.com (mailing list archive)
State New, archived
Headers show
Series Fix vhost reconnect issues | expand

Commit Message

Li Feng Aug. 30, 2023, 4:57 a.m. UTC
Add a Error parameter to report the real error, like vhost-user-blk.

Signed-off-by: Li Feng <fengli@smartx.com>
---
 hw/scsi/vhost-scsi-common.c           | 16 +++++++++-------
 hw/scsi/vhost-scsi.c                  |  5 +++--
 hw/scsi/vhost-user-scsi.c             | 14 ++++++++------
 include/hw/virtio/vhost-scsi-common.h |  2 +-
 4 files changed, 21 insertions(+), 16 deletions(-)

Comments

Raphael Norwitz Aug. 30, 2023, 8:51 a.m. UTC | #1
> On Aug 30, 2023, at 12:57 AM, Li Feng <fengli@smartx.com> wrote:
> 
> Add a Error parameter to report the real error, like vhost-user-blk.
> 

Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>

> Signed-off-by: Li Feng <fengli@smartx.com>
> ---
> hw/scsi/vhost-scsi-common.c           | 16 +++++++++-------
> hw/scsi/vhost-scsi.c                  |  5 +++--
> hw/scsi/vhost-user-scsi.c             | 14 ++++++++------
> include/hw/virtio/vhost-scsi-common.h |  2 +-
> 4 files changed, 21 insertions(+), 16 deletions(-)
> 
> diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c
> index a61cd0e907..4c8637045d 100644
> --- a/hw/scsi/vhost-scsi-common.c
> +++ b/hw/scsi/vhost-scsi-common.c
> @@ -16,6 +16,7 @@
>  */
> 
> #include "qemu/osdep.h"
> +#include "qapi/error.h"
> #include "qemu/error-report.h"
> #include "qemu/module.h"
> #include "hw/virtio/vhost.h"
> @@ -25,7 +26,7 @@
> #include "hw/virtio/virtio-access.h"
> #include "hw/fw-path-provider.h"
> 
> -int vhost_scsi_common_start(VHostSCSICommon *vsc)
> +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp)
> {
>     int ret, i;
>     VirtIODevice *vdev = VIRTIO_DEVICE(vsc);
> @@ -35,18 +36,19 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc)
>     VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vsc;
> 
>     if (!k->set_guest_notifiers) {
> -        error_report("binding does not support guest notifiers");
> +        error_setg(errp, "binding does not support guest notifiers");
>         return -ENOSYS;
>     }
> 
>     ret = vhost_dev_enable_notifiers(&vsc->dev, vdev);
>     if (ret < 0) {
> +        error_setg_errno(errp, -ret, "Error enabling host notifiers");
>         return ret;
>     }
> 
>     ret = k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, true);
>     if (ret < 0) {
> -        error_report("Error binding guest notifier");
> +        error_setg_errno(errp, -ret, "Error binding guest notifier");
>         goto err_host_notifiers;
>     }
> 
> @@ -54,7 +56,7 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc)
> 
>     ret = vhost_dev_prepare_inflight(&vsc->dev, vdev);
>     if (ret < 0) {
> -        error_report("Error setting inflight format: %d", -ret);
> +        error_setg_errno(errp, -ret, "Error setting inflight format");
>         goto err_guest_notifiers;
>     }
> 
> @@ -64,21 +66,21 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc)
>                                         vs->conf.virtqueue_size,
>                                         vsc->inflight);
>             if (ret < 0) {
> -                error_report("Error getting inflight: %d", -ret);
> +                error_setg_errno(errp, -ret, "Error getting inflight");
>                 goto err_guest_notifiers;
>             }
>         }
> 
>         ret = vhost_dev_set_inflight(&vsc->dev, vsc->inflight);
>         if (ret < 0) {
> -            error_report("Error setting inflight: %d", -ret);
> +            error_setg_errno(errp, -ret, "Error setting inflight");
>             goto err_guest_notifiers;
>         }
>     }
> 
>     ret = vhost_dev_start(&vsc->dev, vdev, true);
>     if (ret < 0) {
> -        error_report("Error start vhost dev");
> +        error_setg_errno(errp, -ret, "Error starting vhost dev");
>         goto err_guest_notifiers;
>     }
> 
> diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
> index 443f67daa4..01a3ab4277 100644
> --- a/hw/scsi/vhost-scsi.c
> +++ b/hw/scsi/vhost-scsi.c
> @@ -75,6 +75,7 @@ static int vhost_scsi_start(VHostSCSI *s)
>     int ret, abi_version;
>     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
>     const VhostOps *vhost_ops = vsc->dev.vhost_ops;
> +    Error *local_err = NULL;
> 
>     ret = vhost_ops->vhost_scsi_get_abi_version(&vsc->dev, &abi_version);
>     if (ret < 0) {
> @@ -88,14 +89,14 @@ static int vhost_scsi_start(VHostSCSI *s)
>         return -ENOSYS;
>     }
> 
> -    ret = vhost_scsi_common_start(vsc);
> +    ret = vhost_scsi_common_start(vsc, &local_err);
>     if (ret < 0) {
>         return ret;
>     }
> 
>     ret = vhost_scsi_set_endpoint(s);
>     if (ret < 0) {
> -        error_report("Error setting vhost-scsi endpoint");
> +        error_reportf_err(local_err, "Error setting vhost-scsi endpoint");
>         vhost_scsi_common_stop(vsc);
>     }
> 
> diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
> index e931df9f5b..62fc98bb1c 100644
> --- a/hw/scsi/vhost-user-scsi.c
> +++ b/hw/scsi/vhost-user-scsi.c
> @@ -43,12 +43,12 @@ enum VhostUserProtocolFeature {
>     VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
> };
> 
> -static int vhost_user_scsi_start(VHostUserSCSI *s)
> +static int vhost_user_scsi_start(VHostUserSCSI *s, Error **errp)
> {
>     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
>     int ret;
> 
> -    ret = vhost_scsi_common_start(vsc);
> +    ret = vhost_scsi_common_start(vsc, errp);
>     s->started_vu = (ret < 0 ? false : true);
> 
>     return ret;
> @@ -73,6 +73,7 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
>     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
>     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
>     bool should_start = virtio_device_should_start(vdev, status);
> +    Error *local_err = NULL;
>     int ret;
> 
>     if (!s->connected) {
> @@ -84,9 +85,10 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
>     }
> 
>     if (should_start) {
> -        ret = vhost_user_scsi_start(s);
> +        ret = vhost_user_scsi_start(s, &local_err);
>         if (ret < 0) {
> -            error_report("unable to start vhost-user-scsi: %s", strerror(-ret));
> +            error_reportf_err(local_err, "unable to start vhost-user-scsi: %s",
> +                              strerror(-ret));
>             qemu_chr_fe_disconnect(&vs->conf.chardev);
>         }
>     } else {
> @@ -139,7 +141,7 @@ static void vhost_user_scsi_handle_output(VirtIODevice *vdev, VirtQueue *vq)
>      * Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start
>      * vhost here instead of waiting for .set_status().
>      */
> -    ret = vhost_user_scsi_start(s);
> +    ret = vhost_user_scsi_start(s, &local_err);
>     if (ret < 0) {
>         error_reportf_err(local_err, "vhost-user-scsi: vhost start failed: ");
>         qemu_chr_fe_disconnect(&vs->conf.chardev);
> @@ -184,7 +186,7 @@ static int vhost_user_scsi_connect(DeviceState *dev, Error **errp)
> 
>     /* restore vhost state */
>     if (virtio_device_started(vdev, vdev->status)) {
> -        ret = vhost_user_scsi_start(s);
> +        ret = vhost_user_scsi_start(s, errp);
>         if (ret < 0) {
>             return ret;
>         }
> diff --git a/include/hw/virtio/vhost-scsi-common.h b/include/hw/virtio/vhost-scsi-common.h
> index 18f115527c..c5d2c09455 100644
> --- a/include/hw/virtio/vhost-scsi-common.h
> +++ b/include/hw/virtio/vhost-scsi-common.h
> @@ -39,7 +39,7 @@ struct VHostSCSICommon {
>     struct vhost_inflight *inflight;
> };
> 
> -int vhost_scsi_common_start(VHostSCSICommon *vsc);
> +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp);
> void vhost_scsi_common_stop(VHostSCSICommon *vsc);
> char *vhost_scsi_common_get_fw_dev_path(FWPathProvider *p, BusState *bus,
>                                         DeviceState *dev);
> -- 
> 2.41.0
>
Markus Armbruster Sept. 1, 2023, noon UTC | #2
Li Feng <fengli@smartx.com> writes:

> Add a Error parameter to report the real error, like vhost-user-blk.
>
> Signed-off-by: Li Feng <fengli@smartx.com>
> ---
>  hw/scsi/vhost-scsi-common.c           | 16 +++++++++-------
>  hw/scsi/vhost-scsi.c                  |  5 +++--
>  hw/scsi/vhost-user-scsi.c             | 14 ++++++++------
>  include/hw/virtio/vhost-scsi-common.h |  2 +-
>  4 files changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c
> index a61cd0e907..4c8637045d 100644
> --- a/hw/scsi/vhost-scsi-common.c
> +++ b/hw/scsi/vhost-scsi-common.c
> @@ -16,6 +16,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qapi/error.h"
>  #include "qemu/error-report.h"
>  #include "qemu/module.h"
>  #include "hw/virtio/vhost.h"
> @@ -25,7 +26,7 @@
>  #include "hw/virtio/virtio-access.h"
>  #include "hw/fw-path-provider.h"
>  
> -int vhost_scsi_common_start(VHostSCSICommon *vsc)
> +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp)
>  {
>      int ret, i;
>      VirtIODevice *vdev = VIRTIO_DEVICE(vsc);
> @@ -35,18 +36,19 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc)
>      VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vsc;
>  
>      if (!k->set_guest_notifiers) {
> -        error_report("binding does not support guest notifiers");
> +        error_setg(errp, "binding does not support guest notifiers");
>          return -ENOSYS;
>      }
>  
>      ret = vhost_dev_enable_notifiers(&vsc->dev, vdev);
>      if (ret < 0) {
> +        error_setg_errno(errp, -ret, "Error enabling host notifiers");

Looks like the error is silent before your patch.  Correct?

>          return ret;
>      }
>  
>      ret = k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, true);
>      if (ret < 0) {
> -        error_report("Error binding guest notifier");
> +        error_setg_errno(errp, -ret, "Error binding guest notifier");

Error message now provides more detail.

>          goto err_host_notifiers;
>      }
>  
> @@ -54,7 +56,7 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc)
>  
>      ret = vhost_dev_prepare_inflight(&vsc->dev, vdev);
>      if (ret < 0) {
> -        error_report("Error setting inflight format: %d", -ret);
> +        error_setg_errno(errp, -ret, "Error setting inflight format");

Error message now shows errno in human-readable form.

>          goto err_guest_notifiers;
>      }
>  
> @@ -64,21 +66,21 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc)
>                                          vs->conf.virtqueue_size,
>                                          vsc->inflight);
>              if (ret < 0) {
> -                error_report("Error getting inflight: %d", -ret);
> +                error_setg_errno(errp, -ret, "Error getting inflight");

Likewise.

>                  goto err_guest_notifiers;
>              }
>          }
>  
>          ret = vhost_dev_set_inflight(&vsc->dev, vsc->inflight);
>          if (ret < 0) {
> -            error_report("Error setting inflight: %d", -ret);
> +            error_setg_errno(errp, -ret, "Error setting inflight");

Likewise.

>              goto err_guest_notifiers;
>          }
>      }
>  
>      ret = vhost_dev_start(&vsc->dev, vdev, true);
>      if (ret < 0) {
> -        error_report("Error start vhost dev");
> +        error_setg_errno(errp, -ret, "Error starting vhost dev");

Likewise.

>          goto err_guest_notifiers;
>      }
>  
> diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
> index 443f67daa4..01a3ab4277 100644
> --- a/hw/scsi/vhost-scsi.c
> +++ b/hw/scsi/vhost-scsi.c
> @@ -75,6 +75,7 @@ static int vhost_scsi_start(VHostSCSI *s)
>      int ret, abi_version;
>      VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
>      const VhostOps *vhost_ops = vsc->dev.vhost_ops;
> +    Error *local_err = NULL;
>  
>      ret = vhost_ops->vhost_scsi_get_abi_version(&vsc->dev, &abi_version);
>      if (ret < 0) {
> @@ -88,14 +89,14 @@ static int vhost_scsi_start(VHostSCSI *s)
>          return -ENOSYS;
>      }
>  
> -    ret = vhost_scsi_common_start(vsc);
> +    ret = vhost_scsi_common_start(vsc, &local_err);
>      if (ret < 0) {
>          return ret;
>      }
>  
>      ret = vhost_scsi_set_endpoint(s);
>      if (ret < 0) {
> -        error_report("Error setting vhost-scsi endpoint");
> +        error_reportf_err(local_err, "Error setting vhost-scsi endpoint");
>          vhost_scsi_common_stop(vsc);
>      }
>  
> diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
> index e931df9f5b..62fc98bb1c 100644
> --- a/hw/scsi/vhost-user-scsi.c
> +++ b/hw/scsi/vhost-user-scsi.c
> @@ -43,12 +43,12 @@ enum VhostUserProtocolFeature {
>      VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
>  };
>  
> -static int vhost_user_scsi_start(VHostUserSCSI *s)
> +static int vhost_user_scsi_start(VHostUserSCSI *s, Error **errp)
>  {
>      VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
>      int ret;
>  
> -    ret = vhost_scsi_common_start(vsc);
> +    ret = vhost_scsi_common_start(vsc, errp);
>      s->started_vu = (ret < 0 ? false : true);
>  
>      return ret;
> @@ -73,6 +73,7 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
>      VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
>      VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
>      bool should_start = virtio_device_should_start(vdev, status);
> +    Error *local_err = NULL;
>      int ret;
>  
>      if (!s->connected) {
> @@ -84,9 +85,10 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
>      }
>  
>      if (should_start) {
> -        ret = vhost_user_scsi_start(s);
> +        ret = vhost_user_scsi_start(s, &local_err);
>          if (ret < 0) {
> -            error_report("unable to start vhost-user-scsi: %s", strerror(-ret));
> +            error_reportf_err(local_err, "unable to start vhost-user-scsi: %s",
> +                              strerror(-ret));
>              qemu_chr_fe_disconnect(&vs->conf.chardev);
>          }
>      } else {
> @@ -139,7 +141,7 @@ static void vhost_user_scsi_handle_output(VirtIODevice *vdev, VirtQueue *vq)
>       * Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start
>       * vhost here instead of waiting for .set_status().
>       */
> -    ret = vhost_user_scsi_start(s);
> +    ret = vhost_user_scsi_start(s, &local_err);
>      if (ret < 0) {
>          error_reportf_err(local_err, "vhost-user-scsi: vhost start failed: ");

The error_reportf_err() is wrong before the patch, as I just pointed out
in my review of "[PATCH v3 5/5] vhost-user-scsi: start vhost when guest
kicks".  It is correct afterwards.

>          qemu_chr_fe_disconnect(&vs->conf.chardev);
> @@ -184,7 +186,7 @@ static int vhost_user_scsi_connect(DeviceState *dev, Error **errp)
>  
>      /* restore vhost state */
>      if (virtio_device_started(vdev, vdev->status)) {
> -        ret = vhost_user_scsi_start(s);
> +        ret = vhost_user_scsi_start(s, errp);
>          if (ret < 0) {
>              return ret;
>          }

Wrong before the patch, as I just pointed out in my review of "[PATCH v3
4/5] vhost-user-scsi: support reconnect to backend".  Correct afterwards.

> diff --git a/include/hw/virtio/vhost-scsi-common.h b/include/hw/virtio/vhost-scsi-common.h
> index 18f115527c..c5d2c09455 100644
> --- a/include/hw/virtio/vhost-scsi-common.h
> +++ b/include/hw/virtio/vhost-scsi-common.h
> @@ -39,7 +39,7 @@ struct VHostSCSICommon {
>      struct vhost_inflight *inflight;
>  };
>  
> -int vhost_scsi_common_start(VHostSCSICommon *vsc);
> +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp);
>  void vhost_scsi_common_stop(VHostSCSICommon *vsc);
>  char *vhost_scsi_common_get_fw_dev_path(FWPathProvider *p, BusState *bus,
>                                          DeviceState *dev);

Please mention in the commit message that error messages improve, and
silent errors are now reported.
Li Feng Sept. 12, 2023, 8:32 a.m. UTC | #3
> On 1 Sep 2023, at 8:00 PM, Markus Armbruster <armbru@redhat.com> wrote:
> 
> Li Feng <fengli@smartx.com <mailto:fengli@smartx.com>> writes:
> 
>> Add a Error parameter to report the real error, like vhost-user-blk.
>> 
>> Signed-off-by: Li Feng <fengli@smartx.com>
>> ---
>> hw/scsi/vhost-scsi-common.c           | 16 +++++++++-------
>> hw/scsi/vhost-scsi.c                  |  5 +++--
>> hw/scsi/vhost-user-scsi.c             | 14 ++++++++------
>> include/hw/virtio/vhost-scsi-common.h |  2 +-
>> 4 files changed, 21 insertions(+), 16 deletions(-)
>> 
>> diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c
>> index a61cd0e907..4c8637045d 100644
>> --- a/hw/scsi/vhost-scsi-common.c
>> +++ b/hw/scsi/vhost-scsi-common.c
>> @@ -16,6 +16,7 @@
>>  */
>> 
>> #include "qemu/osdep.h"
>> +#include "qapi/error.h"
>> #include "qemu/error-report.h"
>> #include "qemu/module.h"
>> #include "hw/virtio/vhost.h"
>> @@ -25,7 +26,7 @@
>> #include "hw/virtio/virtio-access.h"
>> #include "hw/fw-path-provider.h"
>> 
>> -int vhost_scsi_common_start(VHostSCSICommon *vsc)
>> +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp)
>> {
>>     int ret, i;
>>     VirtIODevice *vdev = VIRTIO_DEVICE(vsc);
>> @@ -35,18 +36,19 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc)
>>     VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vsc;
>> 
>>     if (!k->set_guest_notifiers) {
>> -        error_report("binding does not support guest notifiers");
>> +        error_setg(errp, "binding does not support guest notifiers");
>>         return -ENOSYS;
>>     }
>> 
>>     ret = vhost_dev_enable_notifiers(&vsc->dev, vdev);
>>     if (ret < 0) {
>> +        error_setg_errno(errp, -ret, "Error enabling host notifiers");
> 
> Looks like the error is silent before your patch.  Correct?
Yes, before this patch, it’s a silent error.

> 
>>         return ret;
>>     }
>> 
>>     ret = k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, true);
>>     if (ret < 0) {
>> -        error_report("Error binding guest notifier");
>> +        error_setg_errno(errp, -ret, "Error binding guest notifier");
> 
> Error message now provides more detail.
Yes.

> 
>>         goto err_host_notifiers;
>>     }
>> 
>> @@ -54,7 +56,7 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc)
>> 
>>     ret = vhost_dev_prepare_inflight(&vsc->dev, vdev);
>>     if (ret < 0) {
>> -        error_report("Error setting inflight format: %d", -ret);
>> +        error_setg_errno(errp, -ret, "Error setting inflight format");
> 
> Error message now shows errno in human-readable form.
Yes.

> 
>>         goto err_guest_notifiers;
>>     }
>> 
>> @@ -64,21 +66,21 @@ int vhost_scsi_common_start(VHostSCSICommon *vsc)
>>                                         vs->conf.virtqueue_size,
>>                                         vsc->inflight);
>>             if (ret < 0) {
>> -                error_report("Error getting inflight: %d", -ret);
>> +                error_setg_errno(errp, -ret, "Error getting inflight");
> 
> Likewise.
Yes.

> 
>>                 goto err_guest_notifiers;
>>             }
>>         }
>> 
>>         ret = vhost_dev_set_inflight(&vsc->dev, vsc->inflight);
>>         if (ret < 0) {
>> -            error_report("Error setting inflight: %d", -ret);
>> +            error_setg_errno(errp, -ret, "Error setting inflight");
> 
> Likewise.
Yes.

> 
>>             goto err_guest_notifiers;
>>         }
>>     }
>> 
>>     ret = vhost_dev_start(&vsc->dev, vdev, true);
>>     if (ret < 0) {
>> -        error_report("Error start vhost dev");
>> +        error_setg_errno(errp, -ret, "Error starting vhost dev");
> 
> Likewise.
Yes.

> 
>>         goto err_guest_notifiers;
>>     }
>> 
>> diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
>> index 443f67daa4..01a3ab4277 100644
>> --- a/hw/scsi/vhost-scsi.c
>> +++ b/hw/scsi/vhost-scsi.c
>> @@ -75,6 +75,7 @@ static int vhost_scsi_start(VHostSCSI *s)
>>     int ret, abi_version;
>>     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
>>     const VhostOps *vhost_ops = vsc->dev.vhost_ops;
>> +    Error *local_err = NULL;
>> 
>>     ret = vhost_ops->vhost_scsi_get_abi_version(&vsc->dev, &abi_version);
>>     if (ret < 0) {
>> @@ -88,14 +89,14 @@ static int vhost_scsi_start(VHostSCSI *s)
>>         return -ENOSYS;
>>     }
>> 
>> -    ret = vhost_scsi_common_start(vsc);
>> +    ret = vhost_scsi_common_start(vsc, &local_err);
>>     if (ret < 0) {
>>         return ret;
>>     }
>> 
>>     ret = vhost_scsi_set_endpoint(s);
>>     if (ret < 0) {
>> -        error_report("Error setting vhost-scsi endpoint");
>> +        error_reportf_err(local_err, "Error setting vhost-scsi endpoint");
>>         vhost_scsi_common_stop(vsc);
>>     }
>> 
>> diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
>> index e931df9f5b..62fc98bb1c 100644
>> --- a/hw/scsi/vhost-user-scsi.c
>> +++ b/hw/scsi/vhost-user-scsi.c
>> @@ -43,12 +43,12 @@ enum VhostUserProtocolFeature {
>>     VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
>> };
>> 
>> -static int vhost_user_scsi_start(VHostUserSCSI *s)
>> +static int vhost_user_scsi_start(VHostUserSCSI *s, Error **errp)
>> {
>>     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
>>     int ret;
>> 
>> -    ret = vhost_scsi_common_start(vsc);
>> +    ret = vhost_scsi_common_start(vsc, errp);
>>     s->started_vu = (ret < 0 ? false : true);
>> 
>>     return ret;
>> @@ -73,6 +73,7 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
>>     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
>>     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
>>     bool should_start = virtio_device_should_start(vdev, status);
>> +    Error *local_err = NULL;
>>     int ret;
>> 
>>     if (!s->connected) {
>> @@ -84,9 +85,10 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
>>     }
>> 
>>     if (should_start) {
>> -        ret = vhost_user_scsi_start(s);
>> +        ret = vhost_user_scsi_start(s, &local_err);
>>         if (ret < 0) {
>> -            error_report("unable to start vhost-user-scsi: %s", strerror(-ret));
>> +            error_reportf_err(local_err, "unable to start vhost-user-scsi: %s",
>> +                              strerror(-ret));
>>             qemu_chr_fe_disconnect(&vs->conf.chardev);
>>         }
>>     } else {
>> @@ -139,7 +141,7 @@ static void vhost_user_scsi_handle_output(VirtIODevice *vdev, VirtQueue *vq)
>>      * Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start
>>      * vhost here instead of waiting for .set_status().
>>      */
>> -    ret = vhost_user_scsi_start(s);
>> +    ret = vhost_user_scsi_start(s, &local_err);
>>     if (ret < 0) {
>>         error_reportf_err(local_err, "vhost-user-scsi: vhost start failed: ");
> 
> The error_reportf_err() is wrong before the patch, as I just pointed out
> in my review of "[PATCH v3 5/5] vhost-user-scsi: start vhost when guest
> kicks".  It is correct afterwards.
Yes.

> 
>>         qemu_chr_fe_disconnect(&vs->conf.chardev);
>> @@ -184,7 +186,7 @@ static int vhost_user_scsi_connect(DeviceState *dev, Error **errp)
>> 
>>     /* restore vhost state */
>>     if (virtio_device_started(vdev, vdev->status)) {
>> -        ret = vhost_user_scsi_start(s);
>> +        ret = vhost_user_scsi_start(s, errp);
>>         if (ret < 0) {
>>             return ret;
>>         }
> 
> Wrong before the patch, as I just pointed out in my review of "[PATCH v3
> 4/5] vhost-user-scsi: support reconnect to backend".  Correct afterwards.
Yes.

> 
>> diff --git a/include/hw/virtio/vhost-scsi-common.h b/include/hw/virtio/vhost-scsi-common.h
>> index 18f115527c..c5d2c09455 100644
>> --- a/include/hw/virtio/vhost-scsi-common.h
>> +++ b/include/hw/virtio/vhost-scsi-common.h
>> @@ -39,7 +39,7 @@ struct VHostSCSICommon {
>>     struct vhost_inflight *inflight;
>> };
>> 
>> -int vhost_scsi_common_start(VHostSCSICommon *vsc);
>> +int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp);
>> void vhost_scsi_common_stop(VHostSCSICommon *vsc);
>> char *vhost_scsi_common_get_fw_dev_path(FWPathProvider *p, BusState *bus,
>>                                         DeviceState *dev);
> 
> Please mention in the commit message that error messages improve, and
> silent errors are now reported.
Ack.
Michael S. Tsirkin Oct. 1, 2023, 8 p.m. UTC | #4
On Tue, Sep 12, 2023 at 04:32:59PM +0800, Li Feng wrote:
>     Please mention in the commit message that error messages improve, and
>     silent errors are now reported.
> 
> Ack.


Still waiting for v4 with the updated commit log.
diff mbox series

Patch

diff --git a/hw/scsi/vhost-scsi-common.c b/hw/scsi/vhost-scsi-common.c
index a61cd0e907..4c8637045d 100644
--- a/hw/scsi/vhost-scsi-common.c
+++ b/hw/scsi/vhost-scsi-common.c
@@ -16,6 +16,7 @@ 
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "hw/virtio/vhost.h"
@@ -25,7 +26,7 @@ 
 #include "hw/virtio/virtio-access.h"
 #include "hw/fw-path-provider.h"
 
-int vhost_scsi_common_start(VHostSCSICommon *vsc)
+int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp)
 {
     int ret, i;
     VirtIODevice *vdev = VIRTIO_DEVICE(vsc);
@@ -35,18 +36,19 @@  int vhost_scsi_common_start(VHostSCSICommon *vsc)
     VirtIOSCSICommon *vs = (VirtIOSCSICommon *)vsc;
 
     if (!k->set_guest_notifiers) {
-        error_report("binding does not support guest notifiers");
+        error_setg(errp, "binding does not support guest notifiers");
         return -ENOSYS;
     }
 
     ret = vhost_dev_enable_notifiers(&vsc->dev, vdev);
     if (ret < 0) {
+        error_setg_errno(errp, -ret, "Error enabling host notifiers");
         return ret;
     }
 
     ret = k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, true);
     if (ret < 0) {
-        error_report("Error binding guest notifier");
+        error_setg_errno(errp, -ret, "Error binding guest notifier");
         goto err_host_notifiers;
     }
 
@@ -54,7 +56,7 @@  int vhost_scsi_common_start(VHostSCSICommon *vsc)
 
     ret = vhost_dev_prepare_inflight(&vsc->dev, vdev);
     if (ret < 0) {
-        error_report("Error setting inflight format: %d", -ret);
+        error_setg_errno(errp, -ret, "Error setting inflight format");
         goto err_guest_notifiers;
     }
 
@@ -64,21 +66,21 @@  int vhost_scsi_common_start(VHostSCSICommon *vsc)
                                         vs->conf.virtqueue_size,
                                         vsc->inflight);
             if (ret < 0) {
-                error_report("Error getting inflight: %d", -ret);
+                error_setg_errno(errp, -ret, "Error getting inflight");
                 goto err_guest_notifiers;
             }
         }
 
         ret = vhost_dev_set_inflight(&vsc->dev, vsc->inflight);
         if (ret < 0) {
-            error_report("Error setting inflight: %d", -ret);
+            error_setg_errno(errp, -ret, "Error setting inflight");
             goto err_guest_notifiers;
         }
     }
 
     ret = vhost_dev_start(&vsc->dev, vdev, true);
     if (ret < 0) {
-        error_report("Error start vhost dev");
+        error_setg_errno(errp, -ret, "Error starting vhost dev");
         goto err_guest_notifiers;
     }
 
diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index 443f67daa4..01a3ab4277 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -75,6 +75,7 @@  static int vhost_scsi_start(VHostSCSI *s)
     int ret, abi_version;
     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
     const VhostOps *vhost_ops = vsc->dev.vhost_ops;
+    Error *local_err = NULL;
 
     ret = vhost_ops->vhost_scsi_get_abi_version(&vsc->dev, &abi_version);
     if (ret < 0) {
@@ -88,14 +89,14 @@  static int vhost_scsi_start(VHostSCSI *s)
         return -ENOSYS;
     }
 
-    ret = vhost_scsi_common_start(vsc);
+    ret = vhost_scsi_common_start(vsc, &local_err);
     if (ret < 0) {
         return ret;
     }
 
     ret = vhost_scsi_set_endpoint(s);
     if (ret < 0) {
-        error_report("Error setting vhost-scsi endpoint");
+        error_reportf_err(local_err, "Error setting vhost-scsi endpoint");
         vhost_scsi_common_stop(vsc);
     }
 
diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
index e931df9f5b..62fc98bb1c 100644
--- a/hw/scsi/vhost-user-scsi.c
+++ b/hw/scsi/vhost-user-scsi.c
@@ -43,12 +43,12 @@  enum VhostUserProtocolFeature {
     VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
 };
 
-static int vhost_user_scsi_start(VHostUserSCSI *s)
+static int vhost_user_scsi_start(VHostUserSCSI *s, Error **errp)
 {
     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
     int ret;
 
-    ret = vhost_scsi_common_start(vsc);
+    ret = vhost_scsi_common_start(vsc, errp);
     s->started_vu = (ret < 0 ? false : true);
 
     return ret;
@@ -73,6 +73,7 @@  static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(s);
     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
     bool should_start = virtio_device_should_start(vdev, status);
+    Error *local_err = NULL;
     int ret;
 
     if (!s->connected) {
@@ -84,9 +85,10 @@  static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
     }
 
     if (should_start) {
-        ret = vhost_user_scsi_start(s);
+        ret = vhost_user_scsi_start(s, &local_err);
         if (ret < 0) {
-            error_report("unable to start vhost-user-scsi: %s", strerror(-ret));
+            error_reportf_err(local_err, "unable to start vhost-user-scsi: %s",
+                              strerror(-ret));
             qemu_chr_fe_disconnect(&vs->conf.chardev);
         }
     } else {
@@ -139,7 +141,7 @@  static void vhost_user_scsi_handle_output(VirtIODevice *vdev, VirtQueue *vq)
      * Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start
      * vhost here instead of waiting for .set_status().
      */
-    ret = vhost_user_scsi_start(s);
+    ret = vhost_user_scsi_start(s, &local_err);
     if (ret < 0) {
         error_reportf_err(local_err, "vhost-user-scsi: vhost start failed: ");
         qemu_chr_fe_disconnect(&vs->conf.chardev);
@@ -184,7 +186,7 @@  static int vhost_user_scsi_connect(DeviceState *dev, Error **errp)
 
     /* restore vhost state */
     if (virtio_device_started(vdev, vdev->status)) {
-        ret = vhost_user_scsi_start(s);
+        ret = vhost_user_scsi_start(s, errp);
         if (ret < 0) {
             return ret;
         }
diff --git a/include/hw/virtio/vhost-scsi-common.h b/include/hw/virtio/vhost-scsi-common.h
index 18f115527c..c5d2c09455 100644
--- a/include/hw/virtio/vhost-scsi-common.h
+++ b/include/hw/virtio/vhost-scsi-common.h
@@ -39,7 +39,7 @@  struct VHostSCSICommon {
     struct vhost_inflight *inflight;
 };
 
-int vhost_scsi_common_start(VHostSCSICommon *vsc);
+int vhost_scsi_common_start(VHostSCSICommon *vsc, Error **errp);
 void vhost_scsi_common_stop(VHostSCSICommon *vsc);
 char *vhost_scsi_common_get_fw_dev_path(FWPathProvider *p, BusState *bus,
                                         DeviceState *dev);