[libvirt] [PATCH 3/3]: Implement logical stopPool and deletePool more fully
by Chris Lalancette
This patch does a few things.
1) Clean up a bunch of comments which I believe are no longer valid, or just
slightly wrong
2) Enable the stopPool command for the logical backend. The comment in the
code worries about a situation where you try to "stop" the logical volume that
your rootfs is on, for example. However, that situation is already taken care
of by the LVM tools; if the logical volume you try to stop is active, it will
throw an error saying that the LV is in use, and won't stop it. Therefore, it
should be pretty safe to try to stop logical volumes; it will fail for ones that
are in use, but will stop volumes that have been properly torn down ahead of time.
3) In deletePool, remove the -f from the vgremove command. Besides the fact
that we probably don't usually want to force things, the -f option doesn't exist
prior to F-9, so this would fail on F-8, RHEL-5, etc.
4) In deletePool, implement pvremove of all source devices. Note that this
should also be relatively safe; it will only pvremove devices that we had
previously pvcreate'd in createPool, which means they were all under control of
libvirt. It will not pvremove devices on an LVM that you previously created,
but were just scanning with libvirt.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
16 years, 3 months
[libvirt] Monitoring guest state (xen hvms)
by Matthew Donovan
I would like to be able to monitor the state of a Xen guest OS via
virDomainGetInfo (and Domain.getInfo() in the Java bindings.)
When I start, pause, and resume the guest via the libvirt API, it works as
expected. However, if I shutdown the guest vm by opening a VNC window and
actually selecting "shutdown" via the OS's favorite mechanism (e.g. Start ->
Shutdown in Windows), I lose the state. In other words, virDomainGetInfo()
returns NOSTATE.
There was some conversation on this list a while ago about
virDomainGetInfo() returning NOSTATE so I added some code and recompiled
libvirt to print the value of the domain_flags returned from the xen
hypervisor. _When_ it printed this value, it was always zero. I stress the
"when" part because after the OS completely shuts down, the value of
domain_flags is no longer printed.
I started virsh and did a list of VMs and the guest is gone. However, if I
look at "xm list", the domain is still there.
Is there a reliable way to monitor the guest state when the guest is
shutdown internally (i.e. via the guest OS itself)?
Thanks
-matthew
16 years, 3 months
[libvirt] [RFC] Events API
by David Lively
Hi -
We have some folks looking into the implementation of events (just VM
state transition events, for now) in libvirtd. I've been assuming that
events will be XML strings, something like:
<event type="domain-state-transition" timestamp="xxxxx">
<domain-id>22</domain-id>
<old-state>nostate</old-state>
<new-state>running</new-state>
</event>
where the contents of the <event> element are determined by the event
type, and the attributes type and timestamp are required.
Originally, I was thinking one would listen for events by registering
a callback, something like:
int virConnectAddEventHandler(virConnPtr conn, char **filter,
virEventHandler handler, void *arg)
where filter is either NULL, indicating interest in all events, or else
a NULL-terminated vector of event type names, allowing filtering by
event type. void handler(conn, const char *eventXML, arg) would be
called for each matching event.
I'm a little concerned that a vector of event type names isn't really
adequate for specifying a filter. Does this need to be more general
(XPathString exprs??)
But my larger concern is that an asynchronous callback mechanism (as
proposed above) assumes the presence of some thread / process from which
to make the callbacks. This works fine in the libvirtd context, but
not outside of it. For instance, we build a "client only" version of
libvirt with ONLY the remote driver, which currently doesn't require
pthreads at all. Introducing asynchronous callbacks into the API means
pthreads is now required for this.
I'm not sure how much requiring this extra thread matters. If it does,
we could always define a synchronous delivery mechanism instead. For
instance, we could have a virDeliverEvents(conn) call to make the
callbacks for any outstanding events. Or we could just dispense with
callbacks altogether, and return a readable (pipe) fd from which the
client can read events.
Comments??
Dave
P.S. We'll also need an internal API for sending events (most likely, an
extension of the existing virEvent stuff), but let's get the basic shape
of the external interface agreed upon first.
16 years, 3 months
[libvirt] [PATCH 1/3]: Cleanup the virStorageDriver structs
by Chris Lalancette
This patch just cleans up the virStorageDriver structs so that they use the
.functionPointer = functionname syntax of gcc. This makes it much easier to
grep in the code later. This patch also re-arranges the order of the function
pointers in remote_internal so that it matches the definition of
virStorageDriver in src/driver.h. While not strictly necessary, it does make it
a little more sane when looking at it in the future.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
16 years, 3 months
[libvirt] [PATCH 2/3]: Fix storage_conf parsing for empty <source>
by Chris Lalancette
This patch fixes a minor bug in the storage_conf parsing. Creating logical
volume pool XML without a source definition is a valid operation (for example,
if you just want to scan an already existing LVM group), but this bug was making
the parser reject that XML. Bugfix from Dan Berrange, tested by me.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
16 years, 3 months
[libvirt] [PATCH] Add libvirt.h to ignore files
by James Morris
Shouldn't libvirt.h be ignored by SCMS ?
----
libvirt.h is automatically generated: it should be ignored by
SCM tools.
Signed-off-by: James Morris <jmorris(a)namei.org>
---
diff --git a/include/libvirt/.cvsignore b/include/libvirt/.cvsignore
index 282522d..7bd42da 100644
--- a/include/libvirt/.cvsignore
+++ b/include/libvirt/.cvsignore
@@ -1,2 +1,3 @@
Makefile
Makefile.in
+libvirt.h
diff --git a/include/libvirt/.gitignore b/include/libvirt/.gitignore
index 282522d..7bd42da 100644
--- a/include/libvirt/.gitignore
+++ b/include/libvirt/.gitignore
@@ -1,2 +1,3 @@
Makefile
Makefile.in
+libvirt.h
16 years, 3 months
[libvirt] [PATCH] read network config in OpenVZ driver
by Evgeniy Sokolov
This patch add possibility to load network configuration for container
in OpenVZ driver.
It support routing network and bridge devices. This types is currently
supported in create/define command.
Also, patch contain fix to small bug in openvzReadConfigParam method.
16 years, 3 months
RE: [libvirt] pausing / unpausing guests with libvirt
by Matthew Donovan
Looks like that did it. I can pause and resume Linux and Windows guests
with this method.
Thanks a lot!
-matthew
> -----Original Message-----
> From: Daniel P. Berrange [mailto:berrange@redhat.com]
> Sent: Monday, September 22, 2008 4:17 AM
> To: Matthew Donovan
> Cc: libvir-list(a)redhat.com
> Subject: Re: [libvirt] pausing / unpausing guests with libvirt
>
> On Sun, Sep 21, 2008 at 05:16:32PM -0400, Matthew Donovan wrote:
> >
> > DEBUG: libvirt.c: virDomainCreate (domain=0x92bd1e0)
> > DEBUG: libvirt.c: virDomainSuspend (domain=0x92bd1e0)
> > virDomainSuspend() failed: 0
>
> I think this is a bug in the Xen driver - the virDomainCreate
> api is not updating the internal 'id' parameter of the virDomainPtr
> object, so when you then call virDomainSuspend() with the same
> virDomainPtr it doesn't have the id it needs
>
> The easy workaround is to just get rid of your existing dom object
> and lookup a new one with 'virDomainLoopByUUID' after starting it.
>
> virDomainPtr dom;
> char uuid[VIR_UUID_BUFLEN];
>
> virDomainCreate(dom);
>
> virDomainGetUUID(dom, uuid);
> virDomainFree(dom);
> dom = virDomainLookupByUUID(conn, uuid);
>
> virDomainSuspend(dom);
>
> Daniel
> --
> |: Red Hat, Engineering, London -o-
> http://people.redhat.com/berrange/ :|
> |: http://libvirt.org -o- http://virt-manager.org -o-
> http://ovirt.org :|
> |: http://autobuild.org -o-
> http://search.cpan.org/~danberr/ :|
> |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF
> F742 7D3B 9505 :|
>
16 years, 3 months
RE: [libvirt] pausing / unpausing guests with libvirt
by Matthew Donovan
> 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 ...
Using following C code does not work. The domain starts but does not
suspend. When I call virConnGetLastError() error->code is 0 and
error->message is NULL. I ran my code with LIBVIRT_DEBUG=1. The output is
below the C code.
I was able to suspend the guest with virsh. The guest was started with my C
code below. You should be able to suspend the guest at any point, correct?
virsh # suspend 65
DEBUG: libvirt.c: virDomainLookupByID (conn=0x882f208, id=65)
DEBUG: hash.c: __virGetDomain (New hash entry 0x8846808)
DEBUG: libvirt.c: virDomainSuspend (domain=0x8846808)
Domain 65 suspended
DEBUG: libvirt.c: virDomainFree (domain=0x8846808)
DEBUG: hash.c: virUnrefDomain (unref domain 0x8846808 Linux2 1)
DEBUG: hash.c: virReleaseDomain (release domain 0x8846808 Linux2)
DEBUG: hash.c: virReleaseDomain (unref connection 0x882f208 xen:/// 2)
Thanks
-matthew
#include <stdio.h>
#include <unistd.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
const char* xml =
"<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>";
int main (int argc, char** argv) {
virConnectPtr conn;
virDomainPtr dom;
if (virInitialize () < 0) {
printf ("virInitialize() failed\n");
return -1;
}
conn = virConnectOpen ("xen:///");
if (!conn) {
printf ("virConnectOpen() failed\n");
return -1;
}
dom = virDomainDefineXML (conn, xml);
if (!dom) {
printf ("virDomainDefineXML() failed\n");
return -1;
}
if (virDomainCreate (dom) < 0) {
printf ("virDomainCreate() failed\n");
return -1;
}
sleep (30);
if (virDomainSuspend (dom) < 0) {
virErrorPtr error = virConnGetLastError (conn);
printf ("virDomainSuspend() failed: %d\n", error->code);
}
sleep (60);
if (virDomainResume (dom) < 0) {
printf ("virDomainResume() failed\n");
}
return 0;
}
[root@grape tmp]$ ./a.out
DEBUG: libvirt.c: virInitialize (register drivers)
DEBUG: xen_internal.c: xenHypervisorInit (Using new hypervisor call: 30001
)
DEBUG: xen_internal.c: xenHypervisorInit (Using hypervisor call v2, sys ver3
dom ver5
)
DEBUG: libvirt.c: virConnectOpen (name=xen:///)
DEBUG: libvirt.c: do_open (name "xen:///" to URI components:
scheme xen
opaque (null)
authority (null)
server (null)
user (null)
port 0
path /
)
DEBUG: libvirt.c: do_open (trying driver 0 (Test) ...)
DEBUG: libvirt.c: do_open (driver 0 Test returned DECLINED)
DEBUG: libvirt.c: do_open (trying driver 1 (Xen) ...)
DEBUG: xen_unified.c: xenUnifiedOpen (Trying hypervisor sub-driver)
DEBUG: xen_unified.c: xenUnifiedOpen (Activated hypervisor sub-driver)
DEBUG: xen_unified.c: xenUnifiedOpen (Trying XenD sub-driver)
DEBUG: xen_unified.c: xenUnifiedOpen (Activated XenD sub-driver)
DEBUG: xen_unified.c: xenUnifiedOpen (Trying XS sub-driver)
DEBUG: xen_unified.c: xenUnifiedOpen (Activated XS sub-driver)
DEBUG: libvirt.c: do_open (driver 1 Xen returned SUCCESS)
DEBUG: libvirt.c: do_open (network driver 0 Test returned DECLINED)
DEBUG: libvirt.c: do_open (network driver 1 QEMU returned DECLINED)
DEBUG: remote_internal.c: doRemoteOpen (proceeding with name = xen:///)
DEBUG: libvirt.c: do_open (network driver 2 remote returned SUCCESS)
DEBUG: libvirt.c: do_open (storage driver 0 Test returned DECLINED)
DEBUG: libvirt.c: do_open (storage driver 1 storage returned DECLINED)
DEBUG: libvirt.c: do_open (storage driver 2 remote returned SUCCESS)
DEBUG: libvirt.c: virDomainDefineXML (conn=0x92ae478, xml=<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</o
n_shutdown><on_reboot>restart</on_reboot><on_crash>restart</on_crash><featur
es><pae/><acpi/><apic/></features><devices><emulator>/usr/lib/xen/bin/qemu-d
m</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>)
DEBUG: xend_internal.c: xenDaemonDomainDefineXML (Defining w/ sexpr:
(vm (name 'Linux2')(memory 488)(maxmem 488)(vcpus 1)(uuid
'5d9f6df2-6930-b2b8-4f71-db8575faa3ae')(on_poweroff 'destroy')(on_reboot
'restart')(on_crash 'restart')(image (hvm (kernel
'/usr/lib/xen/boot/hvmloader')(vcpus 1)(boot c)(acpi 1)(apic 1)(pae 1)(usb
1)(usbdevice tablet)(parallel none)(serial pty)(device_model
'/usr/lib/xen/bin/qemu-dm')))(device (vbd (dev 'hda:disk')(uname
'phy:/dev/vgvms/Linux2')(mode 'w')))(device (vif (mac
'd6:5f:df:05:45:bb')(bridge 'Bridge2')(script 'vif-bridge')))(device
(vkbd))(device (vfb (type vnc)(vncunused 1)(vnclisten '192.168.1.226')))))
DEBUG: libvirt.c: virDomainLookupByName (conn=0x92ae478, name=Linux2)
DEBUG: hash.c: __virGetDomain (New hash entry 0x92bd1e0)
DEBUG: libvirt.c: virDomainCreate (domain=0x92bd1e0)
DEBUG: libvirt.c: virDomainSuspend (domain=0x92bd1e0)
virDomainSuspend() failed: 0
> -----Original Message-----
> From: Richard W.M. Jones [mailto:rjones@redhat.com]
> Sent: Friday, September 19, 2008 2:21 PM
> To: Matthew Donovan
> Cc: libvir-list(a)redhat.com
> Subject: Re: [libvirt] pausing / unpausing guests with libvirt
>
> 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/
>
16 years, 3 months
[libvirt] pausing / unpausing guests with libvirt
by Matthew Donovan
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>
16 years, 3 months