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

[libvirt] [PATCH 3/3] Introduce UPDATE_CPU flag for virDomainGetXMLDesc



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 |    5 ++-
 src/libvirt.c                |    3 +-
 src/qemu/qemu_driver.c       |   54 +++++++++++++++++++++++++++++++++++------
 tools/virsh.c                |    4 +++
 4 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index aaefa09..d22443e 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -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 to match the CPU the guest is currently running on */
 } virDomainXMLFlags;
 
 char *                  virDomainGetXMLDesc     (virDomainPtr domain,
diff --git a/src/libvirt.c b/src/libvirt.c
index 7b74fd9..e540630 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3176,7 +3176,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;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2c81d68..9e133b6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5350,6 +5350,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;
@@ -5360,7 +5398,6 @@ static char *qemudDomainDumpXML(virDomainPtr dom,
 
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
-    qemuDriverUnlock(driver);
 
     if (!vm) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -5376,12 +5413,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;
@@ -5394,13 +5431,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;
 }
 
@@ -9050,7 +9086,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"));
diff --git a/tools/virsh.c b/tools/virsh.c
index 32895b2..95a7f7e 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2504,6 +2504,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}
 };
 
@@ -2516,11 +2517,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;
-- 
1.7.0.3


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