[libvirt] PATCH: Pass -uuid and -domid to QEMU if available
by Daniel P. Berrange
Latest QEMU code now allows setting of the UUID in its SMBIOS data tables
via the -uuid command line arg. THis patch makes use of that feature by
pasing in the libvirt UUID for the VM. While doing this I also added
support for the Xenner specific -domid flag
Daniel
Index: src/qemu_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_conf.c,v
retrieving revision 1.103
diff -u -p -r1.103 qemu_conf.c
--- src/qemu_conf.c 28 Oct 2008 17:43:25 -0000 1.103
+++ src/qemu_conf.c 3 Nov 2008 12:52:06 -0000
@@ -439,6 +439,10 @@ int qemudExtractVersionInfo(const char *
flags |= QEMUD_CMD_FLAG_NO_REBOOT;
if (strstr(help, "-name"))
flags |= QEMUD_CMD_FLAG_NAME;
+ if (strstr(help, "-uuid"))
+ flags |= QEMUD_CMD_FLAG_UUID;
+ if (strstr(help, "-domid"))
+ flags |= QEMUD_CMD_FLAG_DOMID;
if (strstr(help, "-drive"))
flags |= QEMUD_CMD_FLAG_DRIVE;
if (strstr(help, "boot=on"))
@@ -713,6 +717,8 @@ int qemudBuildCommandLine(virConnectPtr
int qenvc = 0, qenva = 0;
const char **qenv = NULL;
const char *emulator;
+ char uuid[VIR_UUID_STRING_BUFLEN];
+ char domid[50];
uname(&ut);
@@ -723,6 +729,8 @@ int qemudBuildCommandLine(virConnectPtr
!ut.machine[4])
ut.machine[1] = '6';
+ virUUIDFormat(vm->def->uuid, uuid);
+
/* Need to explicitly disable KQEMU if
* 1. Arch matches host arch
* 2. Guest is 'qemu'
@@ -802,6 +810,7 @@ int qemudBuildCommandLine(virConnectPtr
snprintf(memory, sizeof(memory), "%lu", vm->def->memory/1024);
snprintf(vcpus, sizeof(vcpus), "%lu", vm->def->vcpus);
+ snprintf(domid, sizeof(domid), "%d", vm->def->id);
ADD_ENV_LIT("LC_ALL=C");
@@ -834,6 +843,15 @@ int qemudBuildCommandLine(virConnectPtr
ADD_ARG_LIT("-name");
ADD_ARG_LIT(vm->def->name);
}
+ if (qemuCmdFlags & QEMUD_CMD_FLAG_UUID) {
+ ADD_ARG_LIT("-uuid");
+ ADD_ARG_LIT(uuid);
+ }
+ if (qemuCmdFlags & QEMUD_CMD_FLAG_DOMID) {
+ ADD_ARG_LIT("-domid");
+ ADD_ARG_LIT(domid);
+ }
+
/*
* NB, -nographic *MUST* come before any serial, or monitor
* or parallel port flags due to QEMU craziness, where it
Index: src/qemu_conf.h
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_conf.h,v
retrieving revision 1.43
diff -u -p -r1.43 qemu_conf.h
--- src/qemu_conf.h 23 Oct 2008 13:18:18 -0000 1.43
+++ src/qemu_conf.h 3 Nov 2008 12:52:06 -0000
@@ -44,6 +44,8 @@ enum qemud_cmd_flags {
QEMUD_CMD_FLAG_DRIVE = (1 << 3),
QEMUD_CMD_FLAG_DRIVE_BOOT = (1 << 4),
QEMUD_CMD_FLAG_NAME = (1 << 5),
+ QEMUD_CMD_FLAG_UUID = (1 << 6),
+ QEMUD_CMD_FLAG_DOMID = (1 << 7), /* Xenner only */
};
/* Main driver state */
Index: src/qemu_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_driver.c,v
retrieving revision 1.144
diff -u -p -r1.144 qemu_driver.c
--- src/qemu_driver.c 29 Oct 2008 14:32:41 -0000 1.144
+++ src/qemu_driver.c 3 Nov 2008 12:52:07 -0000
@@ -860,10 +860,12 @@ static int qemudStartVMDaemon(virConnect
return -1;
}
+ vm->def->id = driver->nextvmid++;
if (qemudBuildCommandLine(conn, driver, vm,
qemuCmdFlags, &argv, &progenv,
&tapfds, &ntapfds, migrateFrom) < 0) {
close(vm->logfile);
+ vm->def->id = -1;
vm->logfile = -1;
return -1;
}
@@ -901,10 +903,10 @@ static int qemudStartVMDaemon(virConnect
ret = virExec(conn, argv, progenv, &keepfd, &vm->pid,
vm->stdin_fd, &vm->stdout_fd, &vm->stderr_fd,
VIR_EXEC_NONBLOCK);
- if (ret == 0) {
- vm->def->id = driver->nextvmid++;
+ if (ret == 0)
vm->state = migrateFrom ? VIR_DOMAIN_PAUSED : VIR_DOMAIN_RUNNING;
- }
+ else
+ vm->def->id = -1;
for (i = 0 ; argv[i] ; i++)
VIR_FREE(argv[i]);
Index: tests/qemuxml2argvtest.c
===================================================================
RCS file: /data/cvs/libvirt/tests/qemuxml2argvtest.c,v
retrieving revision 1.32
diff -u -p -r1.32 qemuxml2argvtest.c
--- tests/qemuxml2argvtest.c 10 Oct 2008 16:52:20 -0000 1.32
+++ tests/qemuxml2argvtest.c 3 Nov 2008 12:52:07 -0000
@@ -43,7 +43,10 @@ static int testCompareXMLToArgvFiles(con
memset(&vm, 0, sizeof vm);
vm.def = vmdef;
- vm.def->id = -1;
+ if (extraFlags & QEMUD_CMD_FLAG_DOMID)
+ vm.def->id = 6;
+ else
+ vm.def->id = -1;
vm.pid = -1;
flags = QEMUD_CMD_FLAG_VNC_COLON |
@@ -196,6 +199,8 @@ mymain(int argc, char **argv)
DO_TEST("input-xen", 0);
DO_TEST("misc-acpi", 0);
DO_TEST("misc-no-reboot", 0);
+ DO_TEST("misc-uuid", QEMUD_CMD_FLAG_NAME |
+ QEMUD_CMD_FLAG_UUID | QEMUD_CMD_FLAG_DOMID);
DO_TEST("net-user", 0);
DO_TEST("net-virtio", 0);
Index: tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.args
===================================================================
RCS file: tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.args
diff -N tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.args
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.args 3 Nov 2008 12:52:07 -0000
@@ -0,0 +1 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -name QEMUGuest1 -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 -domid 6 -nographic -monitor pty -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb
Index: tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml
===================================================================
RCS file: tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml
diff -N tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml 3 Nov 2008 12:52:07 -0000
@@ -0,0 +1,25 @@
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory>219200</memory>
+ <currentMemory>219200</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ </features>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ </disk>
+ </devices>
+</domain>
--
|: 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
[libvirt] one more warning
by Jim Meyering
One more warning question:
Compiling with all storage backends disabled, I get this:
storage_backend.c:91: warning: comparison of unsigned expression < 0 is always false
That's because of this code:
static virStorageBackendPtr backends[] = {
#if WITH_STORAGE_DIR
&virStorageBackendDirectory,
#endif
#if WITH_STORAGE_FS
&virStorageBackendFileSystem,
&virStorageBackendNetFileSystem,
#endif
#if WITH_STORAGE_LVM
&virStorageBackendLogical,
#endif
#if WITH_STORAGE_ISCSI
&virStorageBackendISCSI,
#endif
#if WITH_STORAGE_DISK
&virStorageBackendDisk,
#endif
};
virStorageBackendPtr
virStorageBackendForType(int type) {
unsigned int i;
for (i = 0 ; i < ARRAY_CARDINALITY(backends); i++)
if (backends[i]->type == type)
return backends[i];
virStorageReportError(NULL, VIR_ERR_INTERNAL_ERROR,
_("missing backend for pool type %d"), type);
return NULL;
}
The above loses because ARRAY_CARDINALITY(backends) is 0.
One solution is to always have at least one backend,
e.g., the first one, in which case, this patch works fine:
[but if you like this (i don't), it'd make sense also to remove the
configure-time option ]
diff --git a/src/storage_backend.c b/src/storage_backend.c
index e33f98c..264cc53 100644
--- a/src/storage_backend.c
+++ b/src/storage_backend.c
@@ -56,9 +56,7 @@
#if WITH_STORAGE_DISK
#include "storage_backend_disk.h"
#endif
-#if WITH_STORAGE_DIR
#include "storage_backend_fs.h"
-#endif
VIR_ENUM_IMPL(virStorageBackendPartTable,
VIR_STORAGE_POOL_DISK_LAST,
@@ -66,9 +64,7 @@ VIR_ENUM_IMPL(virStorageBackendPartTable,
"mac", "bsd", "pc98", "sun", "lvm2");
static virStorageBackendPtr backends[] = {
-#if WITH_STORAGE_DIR
&virStorageBackendDirectory,
-#endif
#if WITH_STORAGE_FS
&virStorageBackendFileSystem,
&virStorageBackendNetFileSystem,
Another way is to add a NULL pointer at the end
and change the loop not to use the array size at all:
for (i = 0; backends[i]; i++)
if (backends[i]->type == type)
return backends[i];
I chose the latter:
diff --git a/src/storage_backend.c b/src/storage_backend.c
index e33f98c..1f4ed10 100644
--- a/src/storage_backend.c
+++ b/src/storage_backend.c
@@ -82,13 +82,14 @@ static virStorageBackendPtr backends[] = {
#if WITH_STORAGE_DISK
&virStorageBackendDisk,
#endif
+ NULL
};
virStorageBackendPtr
virStorageBackendForType(int type) {
unsigned int i;
- for (i = 0 ; i < ARRAY_CARDINALITY(backends); i++)
+ for (i = 0; backends[i]; i++)
if (backends[i]->type == type)
return backends[i];
16 years
[libvirt] Does libvirt support Solaris Zones?
by jovialGuy _
Hi!
I have a quick question, does libvirt latest release supports Solaris Zones?
I know it supports LDoms and xVM support is being integrated towards xVM
Server. But which release to date supports Solaris Zones?
Regards,
Jovial
16 years
[libvirt] Have any commands in libvirt to run a domain
by Ian jonhson
Hi all,
Are there any commands in console to start/suspend/resume/stop a domain?
Is it possible to start a domain as following command:
# libvirt-command -cpu <cpu cycle> -mem <memory> -disk <disk quota>
-network <network bandwith> -template <windows>
If not, can I build this command with existing libvirt API?
Thanks,
Ian
16 years
[libvirt] [PATCH]: Allow arbitrary paths to virStorageVolLookupByPath
by Chris Lalancette
In ovirt, we have to scan iSCSI LUN's for LVM storage when they are first added
to the database. To do this, we do roughly the following:
iscsi_pool = libvirt.define_and_start_iscsi_pool("/dev/disk/by-id")
iscsi_pool.add_luns_to_db
logical = conn.discover_storage_pool_sources("logical")
for each logical_volume_group in logical:
for each device in logical_volume_group:
iscsi_pool.lookup_vol_by_path(device.path)
And then we use that information to associate an iSCSI LUN with this volume
group. The problem is that there is an mis-match between how we define the
iscsi pool (with /dev/disk/by-id devices), and what data the
discover_storage_pool_sources() returns (/dev devices), so we can't easily
associate the two.
The following patch implements stable path naming when the
virStorageVolLookupByPath method is called. Basically, it tries to convert
whatever path it is given (say /dev/sdc) into the form currently used by the
Pool (say /dev/disk/by-id). It then goes and looks up the form in the pool, and
returns the storageVolume object as appropriate. Note that it only tries to do
this for the Pool types where it makes sense, namely iSCSI and disk; all other
pool types stay exactly the same.
With this in place, we can solve the mis-match in the above code, and LVM
scanning seems to work in ovirt.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
16 years
[libvirt] Error setting up graphics device:list index out of range
by Frederik Himpe
When I try to create a new KVM VM x86_64, os variant Ubuntu Hardy, it
fails at the end with this message:
Error setting up graphics device:list index out of range
Traceback (most recent call last):
File "/usr/share/virt-manager/virtManager/create.py", line 640, in
finish
guest._graphics_dev = virtinst.VirtualGraphics
(type=virtinst.VirtualGraphics.TYPE_VNC)
File "/usr/lib/python2.5/site-packages/virtinst/Guest.py", line 207, in
__init__
self.set_keymap(keymap)
File "/usr/lib/python2.5/site-packages/virtinst/Guest.py", line 219, in
set_keymap
val = util.default_keymap()
File "/usr/lib/python2.5/site-packages/virtinst/util.py", line 293, in
default_keymap
kt = s.split('"')[1]
IndexError: list index out of range
What could be wrong here? I'm using virt-manager 0.6.0, libvirt 0.4.6,
python-virtinst 0.400.0 on Mandriva Linux 2009.0 x86_64.
--
Frederik Himpe
16 years