From 37183e5db83fd476be552fd889edc74d82927981 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 16 May 2014 15:40:06 +0200 Subject: [PATCH] lib: Introduce flag VIR_DOMAIN_BLOCK_REBASE_RELATIVE Introduce flag for the block rebase API to allow the rebase operation to leave the chain relatively addressed. Also adds a virsh switch to enable this behavior. --- include/libvirt/libvirt.h.in | 3 +++ src/libvirt.c | 4 ++++ tools/virsh-domain.c | 12 ++++++++++-- tools/virsh.pod | 4 ++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 8c4ee8b890..ad6785fc8a 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -2587,6 +2587,9 @@ typedef enum { file for a copy */ VIR_DOMAIN_BLOCK_REBASE_COPY_RAW = 1 << 2, /* Make destination file raw */ VIR_DOMAIN_BLOCK_REBASE_COPY = 1 << 3, /* Start a copy job */ + VIR_DOMAIN_BLOCK_REBASE_RELATIVE = 1 << 4, /* Keep backing chain + referenced using relative + names */ } virDomainBlockRebaseFlags; int virDomainBlockRebase(virDomainPtr dom, const char *disk, diff --git a/src/libvirt.c b/src/libvirt.c index f178727f01..316fdf0445 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -19721,6 +19721,10 @@ virDomainBlockPull(virDomainPtr dom, const char *disk, * exists. If the job is aborted, a new one can be started later to * resume from the same point. * + * If @flags contains VIR_DOMAIN_BLOCK_REBASE_RELATIVE, the name recorded + * into the active disk as the location for @base will be kept relative. + * The operation will fail if libvirt can't infer the name. + * * When @flags includes VIR_DOMAIN_BLOCK_REBASE_COPY, this starts a copy, * where @base must be the name of a new file to copy the chain to. By * default, the copy will pull the entire source chain into the destination diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ff804c5447..b5b9f91e0e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1488,10 +1488,14 @@ blockJobImpl(vshControl *ctl, const vshCmd *cmd, case VSH_CMD_BLOCK_JOB_PULL: if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0) goto cleanup; - if (base) - ret = virDomainBlockRebase(dom, path, base, bandwidth, 0); + if (vshCommandOptBool(cmd, "keep-relative")) + flags |= VIR_DOMAIN_BLOCK_REBASE_RELATIVE; + + if (base || flags) + ret = virDomainBlockRebase(dom, path, base, bandwidth, flags); else ret = virDomainBlockPull(dom, path, bandwidth, 0); + break; case VSH_CMD_BLOCK_JOB_COMMIT: if (vshCommandOptStringReq(ctl, cmd, "base", &base) < 0 || @@ -2127,6 +2131,10 @@ static const vshCmdOptDef opts_block_pull[] = { .type = VSH_OT_BOOL, .help = N_("with --wait, don't wait for cancel to finish") }, + {.name = "keep-relative", + .type = VSH_OT_BOOL, + .help = N_("keep the backing chain relatively referenced") + }, {.name = NULL} }; diff --git a/tools/virsh.pod b/tools/virsh.pod index 7f0e76a3ef..99d0b746b4 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -911,6 +911,7 @@ I specifies copying bandwidth limit in MiB/s. =item B I I [I] [I] [I<--wait> [I<--verbose>] [I<--timeout> B] [I<--async>]] +[I<--keep-relative>] Populate a disk from its backing image chain. By default, this command flattens the entire chain; but if I is specified, containing the @@ -930,6 +931,9 @@ is triggered, I<--async> will return control to the user as fast as possible, otherwise the command may continue to block a little while longer until the job is done cleaning up. +Using the I<--keep-relative> flag will keep the backing chain names +relative. + I specifies fully-qualified path of the disk; it corresponds to a unique target name () or source file () for one of the disk devices attached to I (see