[libvirt] PATCH: Remove PID file before starting QEMU, and after shutdown
by Daniel P. Berrange
We spawn QEMU with a -pidfile option to write its PID out to a file. This
file is never removed though, so next time the guest starts there is small
race condition where we might be unlucky enough to read the old PID out of
the file, instead of the new QEMU PID. This patch adds a call to remove
the pidfile from disk when a guest is shut down. As an extra preventative
measure, we also delete it before starting a guest
Daniel
diff -r ba0066a358b6 src/qemu_driver.c
--- a/src/qemu_driver.c Mon Apr 20 12:10:15 2009 +0100
+++ b/src/qemu_driver.c Mon Apr 20 13:52:47 2009 +0100
@@ -1389,6 +1389,14 @@ static int qemudStartVMDaemon(virConnect
if (qemuPrepareHostDevices(conn, vm->def) < 0)
goto cleanup;
+ if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
+ virReportSystemError(conn, ret,
+ _("Cannot remove stale PID file for %s"),
+ vm->def->name);
+ goto cleanup;
+ }
+
+
vm->def->id = driver->nextvmid++;
if (qemudBuildCommandLine(conn, driver, vm->def,
qemuCmdFlags, &argv, &progenv,
@@ -1512,6 +1520,8 @@ cleanup:
static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
struct qemud_driver *driver,
virDomainObjPtr vm) {
+ int ret;
+
if (!virDomainIsActive(vm))
return;
@@ -1556,6 +1566,12 @@ static void qemudShutdownVMDaemon(virCon
VIR_WARN(_("Failed to remove domain status for %s"),
vm->def->name);
}
+ if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
+ char ebuf[1024];
+ VIR_WARN(_("Failed to remove PID file for %s: %s"),
+ vm->def->name, virStrerror(errno, ebuf, sizeof ebuf));
+ }
+
vm->pid = -1;
vm->def->id = -1;
vm->state = VIR_DOMAIN_SHUTOFF;
--
|: 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 :|
15 years, 6 months
[libvirt] PATCH: Make VirtualBox domain IDs start from 1 instead of 0
by Daniel P. Berrange
The VirtualBox driver currently returns domain IDs starting from 0. The
domain ID 0 is reserved for a special scenario. It refers to a guest which
is also the host OS. ie its the guest in which libvirt is running. This
guest will only exist in virtualization technology where there is a
separate hypervisor / host OS, eg Xen or MicroSoft Hyper-V. Thus, it
should be avoided for drivers like QEMU or VirtualBox.
This patch simply rebases the virtualbox domain IDs to start from 1.
Daniel
Index: src/vbox/vbox_tmpl.c
===================================================================
RCS file: /data/cvs/libvirt/src/vbox/vbox_tmpl.c,v
retrieving revision 1.1
diff -u -p -r1.1 vbox_tmpl.c
--- src/vbox/vbox_tmpl.c 17 Apr 2009 16:09:07 -0000 1.1
+++ src/vbox/vbox_tmpl.c 21 Apr 2009 10:11:48 -0000
@@ -434,7 +434,7 @@ static int vboxListDomains(virConnectPtr
if ((state == MachineState_Running) ||
(state == MachineState_Paused) ) {
ret++;
- ids[j++] = i;
+ ids[j++] = i + 1;
}
}
}
@@ -535,6 +535,15 @@ static virDomainPtr vboxDomainLookupByID
PRUint32 state;
int i;
+ /* Internal vbox IDs start from 0, the public libvirt ID
+ * starts from 1, so refuse id==0, and adjust the rest*/
+ if (id == 0) {
+ vboxError(conn, VIR_ERR_NO_DOMAIN,
+ _("no domain with matching id %d"), id);
+ return NULL;
+ }
+ id = id - 1;
+
if(data->vboxObj) {
rc = data->vboxObj->vtbl->GetMachines(data->vboxObj, &machineCnt, &machines);
if (NS_FAILED(rc)) {
@@ -568,7 +577,7 @@ static virDomainPtr vboxDomainLookupByID
dom = virGetDomain(conn, machineName, iidl);
if (dom)
- dom->id = id;
+ dom->id = id + 1;
/* Cleanup all the XPCOM allocated stuff here */
g_pVBoxFuncs->pfnComUnallocMem(iid);
@@ -645,7 +654,7 @@ static virDomainPtr vboxDomainLookupByUU
if (dom)
if ((state == MachineState_Running) ||
(state == MachineState_Paused) )
- dom->id = i;
+ dom->id = i + 1;
}
if (iid) {
@@ -725,7 +734,7 @@ static virDomainPtr vboxDomainLookupByNa
if (dom)
if ((state == MachineState_Running) ||
(state == MachineState_Paused) )
- dom->id = i;
+ dom->id = i + 1;
}
if (machineName) {
@@ -2311,7 +2320,7 @@ static int vboxDomainCreate(virDomainPtr
ret = -1;
} else {
/* all ok set the domid */
- dom->id = i;
+ dom->id = i + 1;
ret = 0;
}
}
--
|: 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 :|
15 years, 6 months
[libvirt] Supporting dynamic bridge names
by Soren Hansen
I'm fairly sure we've discussed this before, but I couldn't find it in
my archives..
A rather long time ago (0.4.0 timeframe, I think) we switched the
default network in Ubuntu to use a bridge whose name was defined as
"virbr%d". This was done to be able to actually supply a default,
enabled network without the risk of interfering with an existing bridge
called "virbr0" (ignoring the possible implications of unconditionally
using 192.168.122.0/24 (about which, I might add, I've never had /any/
complaints)).
Now, since 0.5.0 (or thereabouts, I think), libvirt doesn't support
this, which
a) makes it rather difficult to achieve our goal of not clashing with
existing bridges named "virbr0", and
b) causes some amount of grief for updates.
To overcome this, I've changed virNetworkAllocateBridge like so:
--- libvirt-0.6.1.orig/src/network_conf.c 2009-03-03 09:23:22.000000000 +0100
+++ libvirt-0.6.1/src/network_conf.c 2009-04-16 20:36:43.660996644 +0200
@@ -875,16 +875,20 @@
}
char *virNetworkAllocateBridge(virConnectPtr conn,
- const virNetworkObjListPtr nets)
+ const virNetworkObjListPtr nets,
+ const char *template)
{
int id = 0;
char *newname;
+ if (!template)
+ template = "virbr%d";
+
do {
char try[50];
- snprintf(try, sizeof(try), "virbr%d", id);
+ snprintf(try, sizeof(try), template, id);
if (!virNetworkBridgeInUse(nets, try, NULL)) {
if (!(newname = strdup(try))) {
--- libvirt-0.6.1.orig/src/network_conf.h 2009-03-03 09:23:22.000000000 +0100
+++ libvirt-0.6.1/src/network_conf.h 2009-04-16 15:36:46.975452201 +0200
@@ -174,7 +174,8 @@
const char *skipname);
char *virNetworkAllocateBridge(virConnectPtr conn,
- const virNetworkObjListPtr nets);
+ const virNetworkObjListPtr nets,
+ const char *template);
int virNetworkSetBridgeName(virConnectPtr conn,
const virNetworkObjListPtr nets,
And virNetworkSetBridgeName like so:
--- libvirt-0.6.1.orig/src/network_conf.c 2009-03-03 09:23:22.000000000 +0100
+++ libvirt-0.6.1/src/network_conf.c 2009-04-16 20:36:43.660996644 +0200
@@ -909,7 +913,7 @@
int ret = -1;
- if (def->bridge) {
+ if (def->bridge && !strstr(def->bridge, "%d")) {
if (virNetworkBridgeInUse(nets, def->bridge, def->name)) {
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("bridge name '%s' already in use."),
@@ -918,7 +922,7 @@
}
} else {
/* Allocate a bridge name */
- if (!(def->bridge = virNetworkAllocateBridge(conn, nets)))
+ if (!(def->bridge = virNetworkAllocateBridge(conn, nets, def->bridge)))
goto error;
}
And finally virNetworkLoadConfig like so:
--- libvirt-0.6.1.orig/src/network_conf.c 2009-03-03 09:23:22.000000000 +0100
+++ libvirt-0.6.1/src/network_conf.c 2009-04-16 20:36:43.660996644 +0200
@@ -747,7 +747,7 @@
/* Generate a bridge if none is found, but don't check for collisions
* if a bridge is hardcoded, so the network is at least defined
*/
- if (!def->bridge && !(def->bridge = virNetworkAllocateBridge(conn, nets)))
+ if (!(def->bridge = virNetworkAllocateBridge(conn, nets, def->bridge)))
goto error;
if (!(net = virNetworkAssignDef(conn, nets, def)))
This is far from perfect, though.
a) As used to be the case for the VNC port, "virsh net-dumpxml" will
give you /current/ bridge name, so e.g. "virsh net-edit" will cause you
to hardcode the bridge name if you're not careful to replace the current
name with one that says '%d' somewhere. This can be fixed by e.g. either
adding a "template" or "current" attribute on the bridge element in the
network XML (depending on whether you want the "name" attribute to be
set to the current value or the template value).
b) Even if you /do/ remember to put '%d' in place of the assigned number
during editing, the bridge number will be increased, because
virNetworkBridgeInUse thinks the bridge name is in use. This should be
easy to fix, though.
I'm perfectly willing to work on this, but I'd like to get you guys' gut
feeling on this first.
--
Soren Hansen |
Lead Virtualisation Engineer | Ubuntu Server Team
Canonical Ltd. | http://www.ubuntu.com/
15 years, 6 months
[libvirt] Dummy tag in xml desc?
by Jean-Michel Guillaume
Hello Everybody!
I'd like to find a way to pass information between a machine & a virtual
machine managed by libvirt (like we can with VirtualBox or VMware thanks
to guest tools for instance ). I thought that I would have been able to
write a comment section or something like that within the xml
description of the right domain, but every new comments or xml tags are
erased once I save them... Maybe somebody's got an idea to help me :D...
JMi
15 years, 6 months
[Libvirt] Python version
by Christian Weyermann
Hello everybody,
we are doing a project for university where we want to use libvirt. We
decided to use the Python bindings. The question is, which python
versions are supported by libvirt 0.6.2? We are especially interested in
Python 3.0.
Thanks and best Regards,
Chris
15 years, 6 months
[libvirt] [RFC] Storage volume clone API
by Cole Robinson
Hi all,
Attached is a stab at an API for cloning a storage volume. This patch
implements the command for FS volumes, along with a virsh command
'vol-clone'. This builds on the previously posted 'drop pool lock during
volume creation' work.
The new API call looks like:
/**
* virStorageVolClone:
* @vol: pointer to storage vol to clone
* @xmldesc: description of volume to create
* @flags: flags for creation (unused, pass 0)
*
* Clone a storage volume within the parent pool.
* Information for the new volume (name, perms)
* are passed via a typical volume XML description
* Not all pools support cloning of volumes
*
* return the storage volume, or NULL on error
*/
virStorageVolPtr
virStorageVolClone(virStorageVolPtr vol,
const char *xmldesc,
unsigned int flags)
The user passes information about the new volume via <volume> XML.
Currently we only use the passed name and permissions values, but
backingStore info could also be relevant, and 'format' if we allow
cloning between image formats.
Current limitations:
- Parsing the 'clone' xml will complain if the 'capacity' element hasn't
been specified, even though it is meaningless for the new volume. Not
too sure what the right thing to do here is.
- A clone of a raw sparse file will turn out fully allocated. Could
probably borrow code from 'cp' to try and get this right.
- Doesn't handle backing stores. I think we would need to call out to
'qemu-img convert' to have any chance of getting this right. And if we
do that, we could also allow cloning from one image format to another.
A lot of the patch is just plumbing, which I will break out into
separate patches on the next post. For now, most of the interesting bits
are at near the bottom.
Feedback appreciated.
Thanks,
Cole
15 years, 6 months
[libvirt] Question about the specification of "virsh vcpupin" and "virsh vcpuinfo" in libvirt-0.6.1.
by Takahashi Tomohiro
Hi,
I have questions.
I would like to know the specification of "virsh vcpupin" and "virsh
vcpuinfo" in libvirt-0.6.1.
"virsh vcpupin" and "virsh vcpuinfo" can not be executed to inactive
domains.
I think it is the specification.
Is it correct ?
I would like to know whether the libvirt-community have a support plan
for pinning inactive domains or not.
Because "xm vcpu-pin" and "vcpu-list" can be excuted to inactive
domains in Xen3.3.
Thanks,
Tomohiro Takahashi
15 years, 6 months
[libvirt] Dummy tag in xml desc?
by Jean-Michel Guillaume
Hello Everybody!
I'd like to find a way to pass information between a machine & a virtual
machine managed by libvirt (like we can with VirtualBox or VMware thanks
to guest tools for instance ). I thought that I would have been able to
write a comment section or something like that within the xml
description of the right domain, but every new comments or xml tags are
erased once I save them... Maybe somebody's got an idea to help me :D...
JMi
--
Guillaume Jean-Michel
E-Mail : jean-michel.guillaume(a)activeeon.com
Phone : + 33 (0)4 97 15 53 84
ACTIVEEON SAS
SAS au capital de 75.000 € - RCS de Grasse n° 500 807 284
http://www.activeeon.com
2004, route des Lucioles – B.P.93
15 years, 6 months
[libvirt] [PATCH 2/4] VirtualBox support
by Pritesh Kothari
Hi All,
I have attached a patch which when applied on the HEAD as of today would allow
virtualbox support in libvirt. It takes cares of all the stuff mentioned on
the list earlier. Still if I have missed anything, please do tell me.
The patches are organized as below:
Patch 0/4: contains sample xml file
Patch 1/4: contains diff of files already in libvirt.
Patch 2/4: contains new files needed for VirtualBox support.
Patch 3/4: contains support for host only and internal network.
Patch 4/4: contains support for rdp in libvirt as mentioned by danpb (also had
sent it separately earlier today)
Regards,
Pritesh
15 years, 6 months
[libvirt] Release of libvirt-0.6.2
by Daniel Veillard
Trying to keep up with last week posted schedule, the new release was
pushed to the usual place:
ftp://libvirt.org/libvirt/
This is mostly a bug fix release, though it also includes a few new
features and some improvements:
* New features:
- support SASL auth for VNC server (Daniel Berrange)
- memory ballooning in QEMU (Daniel Berrange)
- SCSI HBA storage pool support (Dave Allan)
- PCI passthrough in Xen driver (Daniel Berrange)
* Portability:
- be more flexible in QEmu binaries paths (Daniel Berrange)
- Mingw portability fixes (Daniel Berrange)
* Documentation:
- add security attributes in RNG schemas
- cleanup of architecture docs
- missing disk bus values in RNG schemas
* Bug fixes:
- tap vs vbd type on block detach (Cole Robinson and Takahashi
Tomohiro)
- bad free on storage volume error (Daniel Berrange)
- maplenght computations in remote driver (Daniel Berrange)
- event dispatching in the daemon (Daniel Berrange)
- virDomainSetVcpus deadlock (Daniel Berrange)
- save deadlock in test driver (Cole Robinson)
- fix timing of security driver init (Cole Robinson)
- forbid readonly connections from dumping the XML safe info (Cole
Robinson)
- file descriptor leak on remote access
- fix labelling of shared/readonly devices (Dan Walsh)
- virsh missing auth on shell commands (Matthias Bolte)
- avoid zombie on exec pipe errors (Ryota Ozaki)
- memory leak in virNodeDeviceGetParent (Daniel Berrange)
- URI check in migration (Daniel Berrange)
- various memory bug fixes (Daniel Berrange)
- python bindings generator fix (Daniel Berrange)
- NUMA memory fixes (Daniel Berrange)
- various svirt fixes (Daniel Berrange)
- fix sparse volume allocation reporting (Cole Robinson)
- test driver domain restore return value (Cole Robinson)
- do not lose file format info on volume refresh (Cole Robinson)
* Improvements:
- get CPU usage info for LXC (Ryota Ozaki)
- fix domain RNG to add ac97 and tests (Pritesh Kothari)
- OpenVZ support for non-template filesystem root (Florian Vichot)
- improve arch capabilities generation (Daniel Berrange)
- modularization of spec file (Ryota Ozaki)
- better error reports in SEXPR generation (Daniel Berrange)
- support for vifname parameter in VIF config (Daniel Berrange)
- localtime handling for new xen (Daniel Berrange)
- error reporting/ verification of security labels (Dan Walsh)
- add --console arg for create and start virsh commands (Daniel
Berrange)
- refresh volume alloc/capacity when dumping XML (Cole Robinson)
* Cleanups:
- FILE * leaks removal
- unused parameters flagging (Maximilian Wilhelm)
- switch to pre-C99 struct initialization for drivers (Chris
Lalancette)
- symlinks resolving cleanup (Daniel Berrange)
Thanks to everybody who helped with reports, ideas or patches !
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
15 years, 6 months