[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/2] vhost-vdpa: improve error reporting
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH 2/2] vhost-vdpa: improve error reporting |
Date: |
Fri, 4 Sep 2020 15:41:34 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 |
On 9/3/20 8:53 PM, Laurent Vivier wrote:
> Use Error framework to report the id of the device and the details of
> the error (vhostdev name and errno).
>
> For instance:
>
> qemu-system-x86_64 ... -netdev vhost-vdpa,id=hostnet1 ...
> hostnet1: Cannot open '/dev/vhost-vdpa-0': No such file or directory
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> net/vhost-vdpa.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 24103ef241e4..8260902334ae 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -176,7 +176,8 @@ static NetClientInfo net_vhost_vdpa_info = {
> };
>
> static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
> - const char *name, const char *vhostdev)
> + const char *name, const char *vhostdev,
> + Error **errp)
> {
> NetClientState *nc = NULL;
> VhostVDPAState *s;
> @@ -189,11 +190,15 @@ static int net_vhost_vdpa_init(NetClientState *peer,
> const char *device,
> s = DO_UPCAST(VhostVDPAState, nc, nc);
> vdpa_device_fd = qemu_open(vhostdev, O_RDWR);
> if (vdpa_device_fd == -1) {
> - return -errno;
> + error_setg_errno(errp, errno, "%s: Cannot open '%s'", name,
> vhostdev);
> + return -1;
> }
> s->vhost_vdpa.device_fd = vdpa_device_fd;
> ret = vhost_vdpa_add(nc, (void *)&s->vhost_vdpa);
> - assert(s->vhost_net);
> + if (ret == -1) {
> + error_setg(errp, "%s: Cannot add vhost-vdpa '%s'", name, vhostdev);
> + return -1;
> + }
> return ret;
> }
>
> @@ -229,5 +234,6 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char
> *name,
> }
> return net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name,
> opts->has_vhostdev ?
> - opts->vhostdev : VHOST_VDPA_DEFAULT_VHOSTDEV);
> + opts->vhostdev : VHOST_VDPA_DEFAULT_VHOSTDEV,
> + errp);
> }
>