[libvirt] pausing / unpausing guests with libvirt

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. Thanks -matthew 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; } raiseComponentChangeEvent(new ComponentStateChangeEvent(State.PAUSED)); 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 running.) XML for the domain: <domain type='xen'> <name>Linux2</name> <os> <type>hvm</type> <loader>/usr/lib/xen/boot/hvmloader</loader> <boot dev='hd'/> </os> <memory>500000</memory> <vcpu>1</vcpu> <on_shutdown>shutdown</on_shutdown> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <features> <pae/> <acpi/> <apic/> </features> <devices> <emulator>/usr/lib/xen/bin/qemu-dm</emulator> <input type='tablet' bus='usb'/> <graphics type='vnc' autoport='yes' listen='192.168.1.226'/> <serial type='pty'/> <disk type='block'> <source dev='/dev/vgvms/Linux2'/> <target dev='hda'/> </disk> <interface type='bridge'> <mac address='D6:5F:DF:05:45:BB'/> <source bridge='Bridge2'/> </interface> </devices> </domain>

On Fri, Sep 19, 2008 at 09:23:52AM -0400, Matthew Donovan wrote:
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.
Is it possible you could isolate whether the problem is with libvirt or with the Java bindings? One way would be to shell out to 'virsh' just to see if virsh fails to change the state (ie. a libvirt/C) or if the problem is in the Java bindings. Pausing/resuming Xen domains is a very common and well-tested operation so I would be surprised if it's a libvirt problem, but you never know ... Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
participants (2)
-
Matthew Donovan
-
Richard W.M. Jones