Bug 618970

Summary: RFE: QEMU hooks: Add new guest startup hook prior to disk labelling
Product: [Community] Virtualization Tools Reporter: Matthias Hensler <mails.bugzilla.redhat.com>
Component: libvirtAssignee: Daniel Veillard <veillard>
Status: CLOSED UPSTREAM QA Contact:
Severity: low Docs Contact:
Priority: low    
Version: unspecifiedCC: ajia, berrange, clalance, crobinso, itamar, jforbes, jyang, thibault.vincent, veillard, virt-maint, xen-maint
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-03-24 06:53:01 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 636033    
Attachments:
Description Flags
Simple patch to add a prepare hook to libvirt
none
Updated patch for 0.8.8
none
Vanilla compatible patch sent to the ML none

Description Matthias Hensler 2010-07-28 08:44:37 UTC
Created attachment 434953 [details]
Simple patch to add a prepare hook to libvirt

Description of problem:
Since version 0.8 libvirt allows to execute hooks on startup and shutdown of a machine. This mechanism would be great if it could used to setup certain resources needed by the maschine to be run (eg. DRBD, see below). However, the "start" hook is called by libvirt pretty late, after several checks where already perfomed. For example it is not possible to setup the blockdevice needed by machine in the start-hook, since the machine refuses to start long before that hook will be called.

Because of that I suggest to ad a prepare hook which will be called before a machine is started and the checks are performed.

Consider the following szenario: the diskimage for a machine is a DRBD blockdevice. Normally the machine will be run on a primary host, but it should also be possible to migrate the machine to secondary host. Of course you could configure DRBD for primary/primary configuration, but that will be dangerous, as a machine could be started on both hosts, causing filesystem corruption.

The prefered method would be to setup the DRBD to secondary/secondary configuration. Whenever a machine is started it calls the preparehook first. That hook can then bring up the DRBD into primary configuration, so that the machine can actually run. Furthermore that hook can also check if the DRBD is already in primary state on the other side and exit with an error so that libvirt will refuse to start the machine again.

Version-Release number of selected component (if applicable):
0.8.1

How reproducible:
Setup a machine on a DRBD blockdevice and bring that DRBD resource into secondary state. Starting the machine using libvirt is not possible, since the blockdevice is not accessible. Adding a start-hook script to bring the resource up does not work, since the check for the blockdevice is done prior to calling that hook.

Additional info:
I added a patch that will add a prepare hook to libvirt, to give you a better understanding of what would be helpful here.

That patch is already in use here and improves the experience of running a failover machine on a DRBD device considerably. The only thing we do here is to call the hookhandler early in the startup process, passing the operation "prepare" to the hookscript. Also the migrateFrom string is passed as extra parameter.

The hookscript itself then will do the following things:

a) when passed "prepare" as operation and the extra parameter is empty, it considers a normal startup of the machine. It checks the DRBD resource. If the DRBD is already primary on the other side it will exits with an error, otherwise it will try to bring the DRBD into primary state on its own side and exits normally.

b) when passed "prepare" as operation and the extra parameter is not empty (eg a migration is taking place), it will try to bring the DRBD into primary state regardless of the current state.

c) when passed "stopped" it will try to bring the DRBD into secondary state.

The patch will allow to run and migrate virtual machines with libvirt when DRBD is used. It is not longer necessary to have the DRBD resource always in primary/primary state (which can be considerbly dangerous) or using other hacks to configure the correct state prior to using libvirt/virsh.

Comment 1 Thibault VINCENT 2011-03-18 11:36:09 UTC
Created attachment 486215 [details]
Updated patch for 0.8.8

Adds an early qemu hook before the VM ressources allocation, and a hook at the end of VM destruction.

Comment 2 Thibault VINCENT 2011-03-18 11:41:35 UTC
Hi,

Do you plan to include the proposed patch in a future release ?
We highly depend to this feature. It is used to bring up vlan virtual interfaces and bridges on-demand, when the domain is configured to attach to a bridge that does not exist yet. Regular hooks would not be usable in this case as libvirt would fail early when it finds out the required "br" is inexistant.

Thanks

Comment 3 Daniel Veillard 2011-03-21 03:00:38 UTC
Hum, could you post the patch to the mailing-list ? We are entering
freeze for 0.9.0 in 3 days, but since the patch is relatively simple
it is likely we can apply it in time.
See http://libvirt.org/contact.html , the best would be to subscribe
to the libvir-list list before posting. If subscribing is
a problem then I can carry the patch but it's better if we have one of
the reporter listed as the originator for the patch,

  thanks !

Daniel

Comment 4 Thibault VINCENT 2011-03-21 09:47:11 UTC
Thanks Daniel, I sent it to the mailling-list, and also add the git patch here because my previous attachement was specific to Debian sources.

Comment 5 Thibault VINCENT 2011-03-21 09:50:08 UTC
Created attachment 486580 [details]
Vanilla compatible patch sent to the ML

Previous patch was not applicable to the vanilla sources.

Comment 6 Daniel Veillard 2011-03-24 06:53:01 UTC
Done, applied upstream, documentation still need to be augmented though,

Daniel