[libvirt] pausing / unpausing guests with libvirt

Matthew Donovan matthew at atc-nycorp.com
Fri Sep 19 13:23:52 UTC 2008

I'm working on a management application that will control Xen guest vms
(HVMs) with libvirt Java bindings.  I want to be able to pause and unpause
the VMs but doing so through the libvirt functions does not seem to actually
pause the VM.  The suspend function returns true and doesn't throw any
exceptions, however, the guest VM is still running and responsive.

Any pointers are greatly appreciated.


I'm using:

libvirt 0.4.5 
libvirt-java 0.2.1 
Xen 3.1.2

The guest I'm working with is a Fedora Core 6 HVM (though I'd like it to
work with any guest.)
The host is Fedora Core 8.

Code to define and create the domain:

       try {
            con = new Connect ("xen:///");
            String xml = buildXMLConfig(config);	// config is a
string of XML shown below
            domain = con.domainDefineXML(xml);
            domain.create ();
        } catch (LibvirtException ex) {
            logger.error ("Error starting VM", ex);
            return false;

Code to pause the VM:

	public boolean pause() throws RemoteException {
        logger.info ("Pause operation in progress.  domain = "+domain);
        if (domain == null)
            return false;
        try {
            synchronized (domain) {
                domain.suspend ();	// using suspend() because there is
no pause() function.
        } catch (LibvirtException ex) {
            logger.error ("Could not suspend "+vm.getName(), ex);
            return false;
        return true;

(The synchronized() statement is because I was running a second thread
watching the state of the VM and I thought maybe that might be contributing
to the problem.  The VM is still not paused when there is only one thread

XML for the domain:

<domain type='xen'>
	<boot dev='hd'/>
	<input type='tablet' bus='usb'/>
	<graphics type='vnc' autoport='yes' listen=''/>
	<serial type='pty'/>
	<disk type='block'>
		<source dev='/dev/vgvms/Linux2'/>
		<target dev='hda'/>
	<interface type='bridge'>
		<mac address='D6:5F:DF:05:45:BB'/>
		<source bridge='Bridge2'/>

More information about the libvir-list mailing list