[libvirt] [PATCHv2] virsh: Fix msg: blockjob is aborted from another client

Peter Krempa pkrempa at redhat.com
Thu Nov 20 10:12:31 UTC 2014


On 11/19/14 14:54, Erik Skultety wrote:
> When a block{pull, copy, commit} is aborted via keyboard interrupt,
> the job is properly canceled followed by proper error message.
> However, when the job receives an abort from another client connected
> to the same domain, the error message incorrectly indicates that
> a blockjob has been finished successfully, though the abort request
> took effect. This patch introduces a new blockjob abort handler, which
> is registered when the client calls block{copy,commit,pull} routine,
> providing its caller the status of the finished blockjob.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
> ---
>  tools/virsh-domain.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 62 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index a7e9151..90960e9 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c

> @@ -1808,6 +1819,8 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
>      const char *path = NULL;
>      bool quit = false;
>      int abort_flags = 0;
> +    int status = -1;
> +    int cb_id = -1;
>  
>      blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish;
>      if (blocking) {
> @@ -1837,6 +1850,16 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
>          return false;
>      }
>  
> +    virConnectDomainEventGenericCallback cb =
> +        VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler);
> +
> +    cb_id = virConnectDomainEventRegisterAny(ctl->conn,
> +                                             dom,
> +                                             VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
> +                                             cb,
> +                                             &status,
> +                                             NULL);

You should call vshResetLibvirtError in case you want to ignore failure
of registration of the callback.

> +
>      if (!blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_COMMIT, &dom))
>          goto cleanup;
>  

> @@ -1920,6 +1946,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
>          virDomainFree(dom);
>      if (blocking)
>          sigaction(SIGINT, &old_sig_action, NULL);
> +    virConnectDomainEventDeregisterAny(ctl->conn, cb_id);

And deregister it only if the callback id isn't -1 as it will again
overwrite the saved error.

>      return ret;
>  }
>  

Otherwise looks good.

Peter


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20141120/8fe4b77f/attachment-0001.sig>


More information about the libvir-list mailing list