On 3/14/19 2:06 PM, Peter Krempa wrote:
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(a)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.
You mean callers after I do what you suggest in 1/5 (where zpci will
call qemuMonitorDelDevice() directly)? Because after 4/5 there is only
one caller which doesn't want the error to be reported. And I guess you
did not mean to add some code here only to remove it in 4/5, did you?
Michal