[libvirt] [PATCHv4 17/18] blockjob: enhance virsh 'blockcopy'

Jiri Denemark jdenemar at redhat.com
Fri Apr 13 21:30:39 UTC 2012


On Mon, Apr 09, 2012 at 21:52:26 -0600, Eric Blake wrote:
> Expose the full abilities of virDomainBlockCopy.
> 
> * tools/virsh.c (blockJobImpl): Add --format option for block copy.
> * tools/virsh.pod (blockcopy): Document this.
> ---
>  tools/virsh.c   |   26 ++++++++++++++++++++------
>  tools/virsh.pod |   10 +++++-----
>  2 files changed, 25 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 25403f5..8669a8a 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -7527,6 +7527,7 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
>      unsigned long bandwidth = 0;
>      int ret = -1;
>      const char *base = NULL;
> +    const char *format = NULL;
>      unsigned int flags = 0;
> 
>      if (!vshConnectionUsability(ctl, ctl->conn))
> @@ -7566,16 +7567,28 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd,
>              ret = virDomainBlockPull(dom, path, bandwidth, 0);
>          break;
>      case VSH_CMD_BLOCK_JOB_COPY:
> -        flags |= VIR_DOMAIN_BLOCK_REBASE_COPY;
>          if (vshCommandOptBool(cmd, "shallow"))
> -            flags |= VIR_DOMAIN_BLOCK_REBASE_SHALLOW;
> +            flags |= VIR_DOMAIN_BLOCK_COPY_SHALLOW;
>          if (vshCommandOptBool(cmd, "reuse-external"))
> -            flags |= VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT;
> -        if (vshCommandOptBool(cmd, "raw"))
> -            flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_RAW;
> +            flags |= VIR_DOMAIN_BLOCK_COPY_REUSE_EXT;
>          if (vshCommandOptString(cmd, "dest", &base) < 0)
>              goto cleanup;
> -        ret = virDomainBlockRebase(dom, path, base, bandwidth, flags);
> +        if (vshCommandOptString(cmd, "format", &format) < 0)
> +            goto cleanup;
> +        if (!format) {
> +            if (vshCommandOptBool(cmd, "raw"))
> +                flags |= VIR_DOMAIN_BLOCK_REBASE_COPY_RAW;
> +            flags |= VIR_DOMAIN_BLOCK_REBASE_COPY;
> +            ret = virDomainBlockRebase(dom, path, base, bandwidth, flags);
> +        } else {
> +            if (vshCommandOptBool(cmd, "raw")) {
> +                vshError(ctl, "%s",
> +                         _("--raw and --format are mutually exclusive"));
> +                goto cleanup;
> +            }
> +            ret = virDomainBlockCopy(dom, path, base, format,
> +                                     bandwidth, flags);
> +        }
>      }
> 
>  cleanup:
> @@ -7598,6 +7611,7 @@ static const vshCmdOptDef opts_block_copy[] = {
>      {"path", VSH_OT_DATA, VSH_OFLAG_REQ, N_("Fully-qualified path of disk")},
>      {"dest", VSH_OT_DATA, VSH_OFLAG_REQ, N_("path of the copy to create")},
>      {"bandwidth", VSH_OT_DATA, VSH_OFLAG_NONE, N_("Bandwidth limit in MB/s")},
> +    {"format", VSH_OT_DATA, VSH_OFLAG_NONE, N_("file format of dest")},
>      {"shallow", VSH_OT_BOOL, 0, N_("make the copy share a backing chain")},
>      {"reuse-external", VSH_OT_BOOL, 0, N_("reuse existing destination")},
>      {"raw", VSH_OT_BOOL, 0, N_("use raw destination file")},
> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index ee84ce5..65e2429 100644
> --- a/tools/virsh.pod
> +++ b/tools/virsh.pod
> @@ -639,7 +639,7 @@ address of virtual interface (such as I<detach-interface> or
>  I<domif-setlink>) will accept the MAC address printed by this command.
> 
>  =item B<blockcopy> I<domain> I<path> I<dest> [I<bandwidth>] [I<--shallow>]
> -[I<--reuse-external>] [I<--raw>]
> +[I<--reuse-external>] { [I<--raw>] | I<format> }
> 
>  Copy a disk backing image chain to I<dest>. By default, this command
>  flattens the entire chain; but if I<--shallow> is specified, the copy
> @@ -652,10 +652,10 @@ is used, otherwise it must start empty); this option is typically used
>  to set up a relative backing file name in the destination.
> 
>  The format of the destination is determined by the first match in the
> -following list: if I<--raw> is specified, it will be raw; if
> -I<--reuse-external> is specified, the existing destination is probed
> -for a format; and in all other cases, the destination format will
> -match the source format.
> +following list: if I<--raw> is specified, it will be raw; if I<format>
> +is specified, it will have that format; if I<--reuse-external> is
> +specified, the existing destination is probed for a format; and in
> +all other cases, the destination format will match the source format.
> 
>  The copy runs in the background; initially, the job must copy all data
>  from the source, and during this phase, the job can only be canceled to

OK but this patch may be affected in case we decide to rename
virDomainBlockCopy.

Jirka




More information about the libvir-list mailing list