]> xenbits.xensource.com Git - libvirt.git/commitdiff
Introduce UPDATE_CPU flag for virDomainGetXMLDesc
authorJiri Denemark <jdenemar@redhat.com>
Tue, 23 Mar 2010 08:34:19 +0000 (09:34 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 26 Mar 2010 22:05:23 +0000 (23:05 +0100)
This flag is used in migration prepare step to send updated XML
definition of a guest.

Also ``virsh dumpxml --update-cpu [--inactive] guest'' command can be
used to see the updated CPU requirements.

include/libvirt/libvirt.h.in
src/libvirt.c
src/qemu/qemu_driver.c
tools/virsh.c

index fd32529299025c9243279dcefd75eb7778bbf1e5..6d8552f6eaadc1fa149a2d2cd4d230a98e595bfe 100644 (file)
@@ -686,8 +686,9 @@ int                     virDomainGetSecurityLabel (virDomainPtr domain,
  */
 
 typedef enum {
-    VIR_DOMAIN_XML_SECURE = 1, /* dump security sensitive information too */
-    VIR_DOMAIN_XML_INACTIVE = 2/* dump inactive domain information */
+    VIR_DOMAIN_XML_SECURE       = (1 << 0), /* dump security sensitive information too */
+    VIR_DOMAIN_XML_INACTIVE     = (1 << 1), /* dump inactive domain information */
+    VIR_DOMAIN_XML_UPDATE_CPU   = (1 << 2), /* update guest CPU requirements according to host CPU */
 } virDomainXMLFlags;
 
 char *                  virDomainGetXMLDesc     (virDomainPtr domain,
index 1ee299ab741cbf538ea05386b9d2e00447aeec72..cc5b4c5e93b29a0b33654a62fa2701083ba9d36e 100644 (file)
@@ -3256,7 +3256,8 @@ virDomainMigrateVersion2 (virDomainPtr domain,
         return NULL;
     }
     dom_xml = domain->conn->driver->domainDumpXML (domain,
-                                                   VIR_DOMAIN_XML_SECURE);
+                                                   VIR_DOMAIN_XML_SECURE |
+                                                   VIR_DOMAIN_XML_UPDATE_CPU);
     if (!dom_xml)
         return NULL;
 
index 6d76de697a80cb3319f9b98af46f73a12e84f033..3df0398801db80b56a469e6af7a7c53550c127a2 100644 (file)
@@ -5596,6 +5596,44 @@ cleanup:
 }
 
 
+static char *qemudVMDumpXML(struct qemud_driver *driver,
+                            virDomainObjPtr vm,
+                            int flags)
+{
+    char *ret = NULL;
+    virCPUDefPtr cpu = NULL;
+    virDomainDefPtr def;
+    virCPUDefPtr def_cpu;
+
+    if ((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef)
+        def = vm->newDef;
+    else
+        def = vm->def;
+    def_cpu = def->cpu;
+
+    /* Update guest CPU requirements according to host CPU */
+    if ((flags & VIR_DOMAIN_XML_UPDATE_CPU) && def_cpu && def_cpu->model) {
+        if (!driver->caps || !driver->caps->host.cpu) {
+            qemuReportError(VIR_ERR_OPERATION_FAILED,
+                            "%s", _("cannot get host CPU capabilities"));
+            goto cleanup;
+        }
+
+        if (!(cpu = virCPUDefCopy(def_cpu))
+            || cpuUpdate(cpu, driver->caps->host.cpu))
+            goto cleanup;
+        def->cpu = cpu;
+    }
+
+    ret = virDomainDefFormat(def, flags);
+
+cleanup:
+    def->cpu = def_cpu;
+    virCPUDefFree(cpu);
+    return ret;
+}
+
+
 static char *qemudDomainDumpXML(virDomainPtr dom,
                                 int flags) {
     struct qemud_driver *driver = dom->conn->privateData;
@@ -5606,7 +5644,6 @@ static char *qemudDomainDumpXML(virDomainPtr dom,
 
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
-    qemuDriverUnlock(driver);
 
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -5622,12 +5659,12 @@ static char *qemudDomainDumpXML(virDomainPtr dom,
         /* Don't delay if someone's using the monitor, just use
          * existing most recent data instead */
         if (!priv->jobActive) {
-            if (qemuDomainObjBeginJob(vm) < 0)
+            if (qemuDomainObjBeginJobWithDriver(driver, vm) < 0)
                 goto cleanup;
 
-            qemuDomainObjEnterMonitor(vm);
+            qemuDomainObjEnterMonitorWithDriver(driver, vm);
             err = qemuMonitorGetBalloonInfo(priv->mon, &balloon);
-            qemuDomainObjExitMonitor(vm);
+            qemuDomainObjExitMonitorWithDriver(driver, vm);
             if (qemuDomainObjEndJob(vm) == 0) {
                 vm = NULL;
                 goto cleanup;
@@ -5640,13 +5677,12 @@ static char *qemudDomainDumpXML(virDomainPtr dom,
         }
     }
 
-    ret = virDomainDefFormat((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef ?
-                             vm->newDef : vm->def,
-                             flags);
+    ret = qemudVMDumpXML(driver, vm, flags);
 
 cleanup:
     if (vm)
         virDomainObjUnlock(vm);
+    qemuDriverUnlock(driver);
     return ret;
 }
 
@@ -9540,7 +9576,9 @@ static int doPeer2PeerMigrate(virDomainPtr dom,
         goto cleanup;
     }
 
-    dom_xml = virDomainDefFormat(vm->def, VIR_DOMAIN_XML_SECURE);
+    dom_xml = qemudVMDumpXML(driver, vm,
+                             VIR_DOMAIN_XML_SECURE |
+                             VIR_DOMAIN_XML_UPDATE_CPU);
     if (!dom_xml) {
         qemuReportError(VIR_ERR_OPERATION_FAILED,
                         "%s", _("failed to get domain xml"));
index c8ee1917ef0c52f1777d8d674a2a33ac22c1eeb7..cfc4803c1abbf62cb6a97688cebb5818a60a306c 100644 (file)
@@ -2512,6 +2512,7 @@ static const vshCmdOptDef opts_dumpxml[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
     {"inactive", VSH_OT_BOOL, 0, N_("show inactive defined XML")},
     {"security-info", VSH_OT_BOOL, 0, N_("include security sensitive information in XML dump")},
+    {"update-cpu", VSH_OT_BOOL, 0, N_("update guest CPU according to host CPU")},
     {NULL, 0, 0, NULL}
 };
 
@@ -2524,11 +2525,14 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
     int flags = 0;
     int inactive = vshCommandOptBool(cmd, "inactive");
     int secure = vshCommandOptBool(cmd, "security-info");
+    int update = vshCommandOptBool(cmd, "update-cpu");
 
     if (inactive)
         flags |= VIR_DOMAIN_XML_INACTIVE;
     if (secure)
         flags |= VIR_DOMAIN_XML_SECURE;
+    if (update)
+        flags |= VIR_DOMAIN_XML_UPDATE_CPU;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;