On Wed, Sep 17, 2014 at 17:18:39 +0200, Peter Krempa wrote: > --- > docs/hooks.html.in | 11 ++++++++ > src/qemu/qemu_driver.c | 69 +++++++++++++++++++++++++++++++++++++++++++++----- > src/util/virhook.c | 3 ++- > src/util/virhook.h | 1 + > 4 files changed, 76 insertions(+), 8 deletions(-) > > diff --git a/docs/hooks.html.in b/docs/hooks.html.in > index 07b9d49..265dbb7 100644 > --- a/docs/hooks.html.in > +++ b/docs/hooks.html.in > @@ -177,6 +177,17 @@ > script returns failure or the output XML is not valid, incoming > migration will be canceled. This hook may be used, e.g., to change > location of disk images for incoming domains.</li> > + <li><span class="since">Since 1.2.9</span>, the qemu hook script is > + also called when restoring a saved image either via the API or > + automatically when restoring a managed save machine. It is called > + as: <pre>/etc/libvirt/hooks/qemu guest_name restore begin -</pre> > + with domain XML sent to standard input of the script. In this case, > + the script acts as a filter and is supposed to modify the domain > + XML and print it out on its standard output. Empty output is > + identical to copying the input XML without changing it. In case the > + script returns failure or the output XML is not valid, restore of the > + image will be aborted. This hook may be used, e.g., to change > + location of disk images for incoming domains.</li> Copy&paste? "incoming domains" does not make a lot of sense in case of restore :-) > <li><span class="since">Since 0.9.13</span>, the qemu hook script > is also called when the libvirtd daemon restarts and reconnects > to previously running QEMU processes. If the script fails, the > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c > index 1d82e93..2dd2e48 100644 > --- a/src/qemu/qemu_driver.c > +++ b/src/qemu/qemu_driver.c > @@ -5636,20 +5636,23 @@ qemuDomainRestoreFlags(virConnectPtr conn, > unsigned int flags) > { > virQEMUDriverPtr driver = conn->privateData; > + qemuDomainObjPrivatePtr priv = NULL; > virDomainDefPtr def = NULL; > - virDomainDefPtr newdef = NULL; > virDomainObjPtr vm = NULL; > + char *xml = NULL; > + char *xmlout = NULL; > int fd = -1; > int ret = -1; > virQEMUSaveHeader header; > virFileWrapperFdPtr wrapperFd = NULL; > + bool hook_taint = false; > > virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | > VIR_DOMAIN_SAVE_RUNNING | > VIR_DOMAIN_SAVE_PAUSED, -1); > > > - fd = qemuDomainSaveImageOpen(driver, path, &def, &header, NULL, > + fd = qemuDomainSaveImageOpen(driver, path, &def, &header, &xml, > (flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) != 0, > &wrapperFd, false, false); > if (fd < 0) > @@ -5658,12 +5661,29 @@ qemuDomainRestoreFlags(virConnectPtr conn, > if (virDomainRestoreFlagsEnsureACL(conn, def) < 0) > goto cleanup; > > - if (dxml) { > - if (!(newdef = qemuDomainSaveImageUpdateDef(driver, def, dxml))) > + if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { > + int hookret; > + > + if ((hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, def->name, > + VIR_HOOK_QEMU_OP_RESTORE, > + VIR_HOOK_SUBOP_BEGIN, > + NULL, > + dxml ? dxml : xml, > + &xmlout)) < 0) > goto cleanup; > > - virDomainDefFree(def); > - def = newdef; > + if (hookret == 0 && xmlout) { > + virDomainDefPtr tmp; > + > + VIR_DEBUG("Using hook-filtered domain XML: %s", xmlout); > + > + if (!(tmp = qemuDomainSaveImageUpdateDef(driver, def, xmlout))) > + goto cleanup; > + > + virDomainDefFree(def); > + def = tmp; > + hook_taint = true; > + } I think you wanted to write this in a bit different way... This way dxml is ignored when the hook is not present. > } > > if (!(vm = virDomainObjListAdd(driver->domains, def, ... Jirka -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list