[libvirt] [PATCH v2 3/5] qemuMonitorJSONDelDevice: Return -2 on DeviceNotFound error

Peter Krempa pkrempa at redhat.com
Thu Mar 14 13:06:46 UTC 2019


On Thu, Mar 14, 2019 at 13:22:37 +0100, Michal Privoznik wrote:
> A caller might be interested in differentiating the cause for
> error, especially if DeviceNotFound error occurred.
> 
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/qemu/qemu_monitor.c      | 10 ++++++++++
>  src/qemu/qemu_monitor_json.c |  5 +++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 8bd4d4d761..5602a20ee4 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -3008,6 +3008,16 @@ qemuMonitorDriveDel(qemuMonitorPtr mon,
>  }
>  
>  
> +/**
> + * @mon: monitor object
> + * @devalias: alias of the device to detach
> + *
> + * Sends device detach request to qemu.
> + *
> + * Returns: 0 on success,
> + *         -2 if DeviceNotFound error encountered
> + *         -1 otherwise
> + */
>  int
>  qemuMonitorDelDevice(qemuMonitorPtr mon,
>                       const char *devalias)
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index 0236323a51..5c16e1f3a1 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -4191,6 +4191,11 @@ int qemuMonitorJSONDelDevice(qemuMonitorPtr mon,
>      if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
>          goto cleanup;
>  
> +    if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
> +        ret = -2;
> +        goto cleanup;

With this patch you'll stop reporting the error. Given that callers
currently jump to an error label this would make us return error
without setting the error object.

Callers need to be fixed that in case when they choose not to ignore the
error they report some error.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190314/68fb39f5/attachment-0001.sig>


More information about the libvir-list mailing list