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 :|