Message ID | 20200903185327.774708-3-lvivier@redhat.com |
---|---|
State | New |
Headers | show |
Series | vhost-vdpa: improve parameters error management | expand |
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); > } >
On 09/09/2020 03:53, Jason Wang wrote: > > On 2020/9/4 上午2:53, 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> >> --- >> net/vhost-vdpa.c | 14 ++++++++++---- >> 1 file changed, 10 insertions(+), 4 deletions(-) > > > Hi Laurent: > > If you don't mind I will add this patch to v2 of my series[1] Yes, please. I think it could replace the PATCH 3 of your series. Thanks, Laurent
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); }
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> --- net/vhost-vdpa.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)