[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] PATCH: Pass -uuid and -domid to QEMU if available



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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]