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

[libvirt] [PATCH 10/14] Introduce callbacks for serializing domain object private data to XML



Now that drivers are using a private domain object state blob,
the virDomainObjFormat/Parse methods are no longer able to
directly serialize all neccessary state to/from XML. It is
thus neccessary to introduce a pair of callbacks fo serializing
private state.

The code for serializing vCPU PIDs and the monitor device
config can now move out of domain_conf.c and into the
qemu_driver.c where they belong.

* src/conf/capabilities.h: Add callbacks for serializing private
  state to/from XML
* src/conf/domain_conf.c, src/conf/domain_conf.h: Remove the
  monitor, monitor_chr, monitorWatch, nvcpupids and vcpupids
  fields from virDomainObjPtr. Remove code that serialized
  those fields
* src/libvirt_private.syms: Export virXPathBoolean
* src/qemu/qemu_driver.c: Add callbacks for serializing monitor
  and vcpupid data to/from XML
* src/qemu/qemu_monitor.h, src/qemu/qemu_monitor.c: Pass monitor
  char device config into qemuMonitorOpen directly.
---
 src/conf/capabilities.h  |    5 +
 src/conf/domain_conf.c   |  103 ++--------------------
 src/conf/domain_conf.h   |    8 +--
 src/libvirt_private.syms |    1 +
 src/qemu/qemu_driver.c   |  217 ++++++++++++++++++++++++++++++++++++---------
 src/qemu/qemu_monitor.c  |    9 +-
 src/qemu/qemu_monitor.h  |    1 +
 7 files changed, 195 insertions(+), 149 deletions(-)

diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 7234cf4..f8cbae6 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -26,6 +26,9 @@
 
 #include "internal.h"
 #include "util.h"
+#include "buf.h"
+
+#include <libxml/xpath.h>
 
 typedef struct _virCapsGuestFeature virCapsGuestFeature;
 typedef virCapsGuestFeature *virCapsGuestFeaturePtr;
@@ -117,6 +120,8 @@ struct _virCaps {
     unsigned int emulatorRequired : 1;
     void *(*privateDataAllocFunc)(void);
     void (*privateDataFreeFunc)(void *);
+    int (*privateDataXMLFormat)(virBufferPtr, void *);
+    int (*privateDataXMLParse)(xmlXPathContextPtr, void *);
 };
 
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 42820a7..e9f79b7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -615,10 +615,6 @@ static void virDomainObjFree(virDomainObjPtr dom)
     virDomainDefFree(dom->def);
     virDomainDefFree(dom->newDef);
 
-    virDomainChrDefFree(dom->monitor_chr);
-
-    VIR_FREE(dom->vcpupids);
-
     if (dom->privateDataFreeFunc)
         (dom->privateDataFreeFunc)(dom->privateData);
 
@@ -675,8 +671,6 @@ static virDomainObjPtr virDomainObjNew(virConnectPtr conn,
 
     virDomainObjLock(domain);
     domain->state = VIR_DOMAIN_SHUTOFF;
-    domain->monitorWatch = -1;
-    domain->monitor = -1;
     domain->refs = 1;
 
     VIR_DEBUG("obj=%p", domain);
@@ -3389,9 +3383,6 @@ static virDomainObjPtr virDomainObjParseXML(virConnectPtr conn,
     xmlNodePtr config;
     xmlNodePtr oldnode;
     virDomainObjPtr obj;
-    char *monitorpath;
-    xmlNodePtr *nodes = NULL;
-    int n, i;
 
     if (!(obj = virDomainObjNew(conn, caps)))
         return NULL;
@@ -3430,69 +3421,13 @@ static virDomainObjPtr virDomainObjParseXML(virConnectPtr conn,
     }
     obj->pid = (pid_t)val;
 
-    if (VIR_ALLOC(obj->monitor_chr) < 0) {
-        virReportOOMError(conn);
-        goto error;
-    }
-
-    if (!(monitorpath =
-          virXPathString(conn, "string(./monitor[1]/@path)", ctxt))) {
-        virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("no monitor path"));
+    if (caps->privateDataXMLParse &&
+        ((caps->privateDataXMLParse)(ctxt, obj->privateData)) < 0)
         goto error;
-    }
-
-    tmp = virXPathString(conn, "string(./monitor[1]/@type)", ctxt);
-    if (tmp)
-        obj->monitor_chr->type = virDomainChrTypeFromString(tmp);
-    else
-        obj->monitor_chr->type = VIR_DOMAIN_CHR_TYPE_PTY;
-    VIR_FREE(tmp);
-
-    switch (obj->monitor_chr->type) {
-    case VIR_DOMAIN_CHR_TYPE_PTY:
-        obj->monitor_chr->data.file.path = monitorpath;
-        break;
-    case VIR_DOMAIN_CHR_TYPE_UNIX:
-        obj->monitor_chr->data.nix.path = monitorpath;
-        break;
-    default:
-        VIR_FREE(monitorpath);
-        virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                             _("unsupported monitor type '%s'"),
-                             virDomainChrTypeToString(obj->monitor_chr->type));
-        break;
-    }
-
-    n = virXPathNodeSet(conn, "./vcpus/vcpu", ctxt, &nodes);
-    if (n < 0)
-        goto error;
-    if (n) {
-        obj->nvcpupids = n;
-        if (VIR_REALLOC_N(obj->vcpupids, obj->nvcpupids) < 0) {
-            virReportOOMError(conn);
-            goto error;
-        }
-
-        for (i = 0 ; i < n ; i++) {
-            char *pidstr = virXMLPropString(nodes[i], "pid");
-            if (!pidstr)
-                goto error;
-
-            if (virStrToLong_i(pidstr, NULL, 10, &(obj->vcpupids[i])) < 0) {
-                VIR_FREE(pidstr);
-                goto error;
-            }
-            VIR_FREE(pidstr);
-        }
-        VIR_FREE(nodes);
-    }
 
     return obj;
 
 error:
-    VIR_FREE(nodes);
-    virDomainChrDefFree(obj->monitor_chr);
     virDomainObjUnref(obj);
     return NULL;
 }
@@ -4858,43 +4793,20 @@ char *virDomainDefFormat(virConnectPtr conn,
 }
 
 char *virDomainObjFormat(virConnectPtr conn,
+                         virCapsPtr caps,
                          virDomainObjPtr obj,
                          int flags)
 {
     char *config_xml = NULL, *xml = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
-    const char *monitorpath;
 
     virBufferVSprintf(&buf, "<domstatus state='%s' pid='%d'>\n",
                       virDomainStateTypeToString(obj->state),
                       obj->pid);
 
-    /* obj->monitor_chr is set only for qemu */
-    if (obj->monitor_chr) {
-        switch (obj->monitor_chr->type) {
-        case VIR_DOMAIN_CHR_TYPE_UNIX:
-            monitorpath = obj->monitor_chr->data.nix.path;
-            break;
-        default:
-        case VIR_DOMAIN_CHR_TYPE_PTY:
-            monitorpath = obj->monitor_chr->data.file.path;
-            break;
-        }
-
-        virBufferEscapeString(&buf, "  <monitor path='%s'", monitorpath);
-        virBufferVSprintf(&buf, " type='%s'/>\n",
-                          virDomainChrTypeToString(obj->monitor_chr->type));
-    }
-
-
-    if (obj->nvcpupids) {
-        int i;
-        virBufferAddLit(&buf, "  <vcpus>\n");
-        for (i = 0 ; i < obj->nvcpupids ; i++) {
-            virBufferVSprintf(&buf, "    <vcpu pid='%d'/>\n", obj->vcpupids[i]);
-        }
-        virBufferAddLit(&buf, "  </vcpus>\n");
-    }
+    if (caps->privateDataXMLFormat &&
+        ((caps->privateDataXMLFormat)(&buf, obj->privateData)) < 0)
+        goto error;
 
     if (!(config_xml = virDomainDefFormat(conn,
                                           obj->def,
@@ -4994,6 +4906,7 @@ cleanup:
 }
 
 int virDomainSaveStatus(virConnectPtr conn,
+                        virCapsPtr caps,
                         const char *statusDir,
                         virDomainObjPtr obj)
 {
@@ -5001,7 +4914,7 @@ int virDomainSaveStatus(virConnectPtr conn,
     int ret = -1;
     char *xml;
 
-    if (!(xml = virDomainObjFormat(conn, obj, flags)))
+    if (!(xml = virDomainObjFormat(conn, caps, obj, flags)))
         goto cleanup;
 
     if (virDomainSaveXML(conn, statusDir, obj->def, xml))
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6201463..ac39dcd 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -644,15 +644,9 @@ struct _virDomainObj {
     virMutex lock;
     int refs;
 
-    int monitor;
-    virDomainChrDefPtr monitor_chr;
-    int monitorWatch;
     int pid;
     int state;
 
-    int nvcpupids;
-    int *vcpupids;
-
     unsigned int autostart : 1;
     unsigned int persistent : 1;
 
@@ -744,6 +738,7 @@ char *virDomainDefFormat(virConnectPtr conn,
                          virDomainDefPtr def,
                          int flags);
 char *virDomainObjFormat(virConnectPtr conn,
+                         virCapsPtr caps,
                          virDomainObjPtr obj,
                          int flags);
 
@@ -770,6 +765,7 @@ int virDomainSaveConfig(virConnectPtr conn,
                         const char *configDir,
                         virDomainDefPtr def);
 int virDomainSaveStatus(virConnectPtr conn,
+                        virCapsPtr caps,
                         const char *statusDir,
                         virDomainObjPtr obj);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ee7f3ed..09628ba 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -583,6 +583,7 @@ virStrerror;
 
 
 # xml.h
+virXPathBoolean;
 virXPathLong;
 virXPathNode;
 virXPathNodeSet;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b1f5894..468e0ab 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -72,6 +72,7 @@
 #include "security/security_driver.h"
 #include "cgroup.h"
 #include "libvirt_internal.h"
+#include "xml.h"
 
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
@@ -85,6 +86,10 @@ struct _qemuDomainObjPrivate {
                     * information, not merely actions */
 
     qemuMonitorPtr mon;
+    virDomainChrDefPtr monConfig;
+
+    int nvcpupids;
+    int *vcpupids;
 };
 
 static int qemudShutdown(void);
@@ -138,6 +143,9 @@ static void qemuDomainObjPrivateFree(void *data)
 {
     qemuDomainObjPrivatePtr priv = data;
 
+    virDomainChrDefFree(priv->monConfig);
+    VIR_FREE(priv->vcpupids);
+
     /* This should never be non-NULL if we get here, but just in case... */
     if (priv->mon) {
         VIR_ERROR0("Unexpected QEMU monitor still active during domain deletion");
@@ -147,6 +155,116 @@ static void qemuDomainObjPrivateFree(void *data)
 }
 
 
+static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
+{
+    qemuDomainObjPrivatePtr priv = data;
+    const char *monitorpath;
+
+    /* priv->monitor_chr is set only for qemu */
+    if (priv->monConfig) {
+        switch (priv->monConfig->type) {
+        case VIR_DOMAIN_CHR_TYPE_UNIX:
+            monitorpath = priv->monConfig->data.nix.path;
+            break;
+        default:
+        case VIR_DOMAIN_CHR_TYPE_PTY:
+            monitorpath = priv->monConfig->data.file.path;
+            break;
+        }
+
+        virBufferEscapeString(buf, "  <monitor path='%s'", monitorpath);
+        virBufferVSprintf(buf, " type='%s'/>\n",
+                          virDomainChrTypeToString(priv->monConfig->type));
+    }
+
+
+    if (priv->nvcpupids) {
+        int i;
+        virBufferAddLit(buf, "  <vcpus>\n");
+        for (i = 0 ; i < priv->nvcpupids ; i++) {
+            virBufferVSprintf(buf, "    <vcpu pid='%d'/>\n", priv->vcpupids[i]);
+        }
+        virBufferAddLit(buf, "  </vcpus>\n");
+    }
+
+    return 0;
+}
+
+static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)
+{
+    qemuDomainObjPrivatePtr priv = data;
+    char *monitorpath;
+    char *tmp;
+    int n, i;
+    xmlNodePtr *nodes = NULL;
+
+    if (VIR_ALLOC(priv->monConfig) < 0) {
+        virReportOOMError(NULL);
+        goto error;
+    }
+
+    if (!(monitorpath =
+          virXPathString(NULL, "string(./monitor[1]/@path)", ctxt))) {
+        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                         "%s", _("no monitor path"));
+        goto error;
+    }
+
+    tmp = virXPathString(NULL, "string(./monitor[1]/@type)", ctxt);
+    if (tmp)
+        priv->monConfig->type = virDomainChrTypeFromString(tmp);
+    else
+        priv->monConfig->type = VIR_DOMAIN_CHR_TYPE_PTY;
+    VIR_FREE(tmp);
+
+    switch (priv->monConfig->type) {
+    case VIR_DOMAIN_CHR_TYPE_PTY:
+        priv->monConfig->data.file.path = monitorpath;
+        break;
+    case VIR_DOMAIN_CHR_TYPE_UNIX:
+        priv->monConfig->data.nix.path = monitorpath;
+        break;
+    default:
+        VIR_FREE(monitorpath);
+        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                         _("unsupported monitor type '%s'"),
+                         virDomainChrTypeToString(priv->monConfig->type));
+        goto error;
+    }
+
+    n = virXPathNodeSet(NULL, "./vcpus/vcpu", ctxt, &nodes);
+    if (n < 0)
+        goto error;
+    if (n) {
+        priv->nvcpupids = n;
+        if (VIR_REALLOC_N(priv->vcpupids, priv->nvcpupids) < 0) {
+            virReportOOMError(NULL);
+            goto error;
+        }
+
+        for (i = 0 ; i < n ; i++) {
+            char *pidstr = virXMLPropString(nodes[i], "pid");
+            if (!pidstr)
+                goto error;
+
+            if (virStrToLong_i(pidstr, NULL, 10, &(priv->vcpupids[i])) < 0) {
+                VIR_FREE(pidstr);
+                goto error;
+            }
+            VIR_FREE(pidstr);
+        }
+        VIR_FREE(nodes);
+    }
+
+    return 0;
+
+error:
+    VIR_FREE(nodes);
+    return -1;
+}
+
+
+
 /*
  * obj must be locked before calling, qemud_driver must NOT be locked
  *
@@ -660,7 +778,9 @@ qemuConnectMonitor(virDomainObjPtr vm)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
-    if ((priv->mon = qemuMonitorOpen(vm, qemuHandleMonitorEOF)) == NULL) {
+    if ((priv->mon = qemuMonitorOpen(vm,
+                                     priv->monConfig,
+                                     qemuHandleMonitorEOF)) == NULL) {
         VIR_ERROR(_("Failed to connect monitor for %s\n"), vm->def->name);
         return -1;
     }
@@ -917,6 +1037,8 @@ qemudStartup(int privileged) {
 
     qemu_driver->caps->privateDataAllocFunc = qemuDomainObjPrivateAlloc;
     qemu_driver->caps->privateDataFreeFunc = qemuDomainObjPrivateFree;
+    qemu_driver->caps->privateDataXMLFormat = qemuDomainObjPrivateXMLFormat;
+    qemu_driver->caps->privateDataXMLParse = qemuDomainObjPrivateXMLParse;
 
     if ((qemu_driver->activePciHostdevs = pciDeviceListNew(NULL)) == NULL)
         goto error;
@@ -1334,12 +1456,12 @@ qemuDetectVcpuPIDs(virConnectPtr conn,
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
     if (vm->def->virtType != VIR_DOMAIN_VIRT_KVM) {
-        vm->nvcpupids = 1;
-        if (VIR_ALLOC_N(vm->vcpupids, vm->nvcpupids) < 0) {
+        priv->nvcpupids = 1;
+        if (VIR_ALLOC_N(priv->vcpupids, priv->nvcpupids) < 0) {
             virReportOOMError(conn);
             return -1;
         }
-        vm->vcpupids[0] = vm->pid;
+        priv->vcpupids[0] = vm->pid;
         return 0;
     }
 
@@ -1364,8 +1486,8 @@ qemuDetectVcpuPIDs(virConnectPtr conn,
         return -1;
     }
 
-    vm->nvcpupids = ncpupids;
-    vm->vcpupids = cpupids;
+    priv->nvcpupids = ncpupids;
+    priv->vcpupids = cpupids;
     return 0;
 }
 
@@ -1376,6 +1498,7 @@ qemudInitCpuAffinity(virConnectPtr conn,
     virNodeInfo nodeinfo;
     unsigned char *cpumap;
     int cpumaplen;
+    qemuDomainObjPrivatePtr priv = vm->privateData;
 
     if (nodeGetInfo(conn, &nodeinfo) < 0)
         return -1;
@@ -1409,8 +1532,8 @@ qemudInitCpuAffinity(virConnectPtr conn,
 
     /* The XML config only gives a per-VM affinity, so we apply
      * the same mapping to all vCPUs */
-    for (i = 0 ; i < vm->nvcpupids ; i++) {
-        if (virProcessInfoSetAffinity(vm->vcpupids[i],
+    for (i = 0 ; i < priv->nvcpupids ; i++) {
+        if (virProcessInfoSetAffinity(priv->vcpupids[i],
                                       cpumap, cpumaplen, maxcpu) < 0) {
             VIR_FREE(cpumap);
             return -1;
@@ -2089,15 +2212,15 @@ static int qemudSecurityHook(void *data) {
 static int
 qemuPrepareMonitorChr(virConnectPtr conn,
                       struct qemud_driver *driver,
-                      virDomainChrDefPtr monitor_chr,
+                      virDomainChrDefPtr monConfig,
                       const char *vm)
 {
-    monitor_chr->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_MONITOR;
+    monConfig->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_MONITOR;
 
-    monitor_chr->type = VIR_DOMAIN_CHR_TYPE_UNIX;
-    monitor_chr->data.nix.listen = 1;
+    monConfig->type = VIR_DOMAIN_CHR_TYPE_UNIX;
+    monConfig->data.nix.listen = 1;
 
-    if (virAsprintf(&monitor_chr->data.nix.path, "%s/%s.monitor",
+    if (virAsprintf(&monConfig->data.nix.path, "%s/%s.monitor",
                     driver->libDir, vm) < 0) {
         virReportOOMError(conn);
         return -1;
@@ -2197,12 +2320,12 @@ static int qemudStartVMDaemon(virConnectPtr conn,
     if (qemuPrepareHostDevices(conn, driver, vm->def) < 0)
         goto cleanup;
 
-    if (VIR_ALLOC(vm->monitor_chr) < 0) {
+    if (VIR_ALLOC(priv->monConfig) < 0) {
         virReportOOMError(conn);
         goto cleanup;
     }
 
-    if (qemuPrepareMonitorChr(conn, driver, vm->monitor_chr, vm->def->name) < 0)
+    if (qemuPrepareMonitorChr(conn, driver, priv->monConfig, vm->def->name) < 0)
         goto cleanup;
 
     if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
@@ -2219,7 +2342,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
     }
 
     vm->def->id = driver->nextvmid++;
-    if (qemudBuildCommandLine(conn, driver, vm->def, vm->monitor_chr,
+    if (qemudBuildCommandLine(conn, driver, vm->def, priv->monConfig,
                               qemuCmdFlags, &argv, &progenv,
                               &tapfds, &ntapfds, migrateFrom) < 0)
         goto cleanup;
@@ -2334,7 +2457,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
     }
 
 
-    if (virDomainSaveStatus(conn, driver->stateDir, vm) < 0)
+    if (virDomainSaveStatus(conn, driver->caps, driver->stateDir, vm) < 0)
         goto abort;
 
     return 0;
@@ -2408,11 +2531,11 @@ static void qemudShutdownVMDaemon(virConnectPtr conn,
         qemuMonitorClose(priv->mon) == 0)
         priv->mon = NULL;
 
-    if (vm->monitor_chr) {
-        if (vm->monitor_chr->type == VIR_DOMAIN_CHR_TYPE_UNIX)
-            unlink(vm->monitor_chr->data.nix.path);
-        virDomainChrDefFree(vm->monitor_chr);
-        vm->monitor_chr = NULL;
+    if (priv->monConfig) {
+        if (priv->monConfig->type == VIR_DOMAIN_CHR_TYPE_UNIX)
+            unlink(priv->monConfig->data.nix.path);
+        virDomainChrDefFree(priv->monConfig);
+        priv->monConfig = NULL;
     }
 
     /* shut it off for sure */
@@ -2450,8 +2573,8 @@ retry:
     vm->pid = -1;
     vm->def->id = -1;
     vm->state = VIR_DOMAIN_SHUTOFF;
-    VIR_FREE(vm->vcpupids);
-    vm->nvcpupids = 0;
+    VIR_FREE(priv->vcpupids);
+    priv->nvcpupids = 0;
 
     if (vm->newDef) {
         virDomainDefFree(vm->def);
@@ -2949,7 +3072,7 @@ static int qemudDomainSuspend(virDomainPtr dom) {
                                          VIR_DOMAIN_EVENT_SUSPENDED,
                                          VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
     }
-    if (virDomainSaveStatus(dom->conn, driver->stateDir, vm) < 0)
+    if (virDomainSaveStatus(dom->conn, driver->caps, driver->stateDir, vm) < 0)
         goto endjob;
     ret = 0;
 
@@ -3008,7 +3131,7 @@ static int qemudDomainResume(virDomainPtr dom) {
                                          VIR_DOMAIN_EVENT_RESUMED,
                                          VIR_DOMAIN_EVENT_RESUMED_UNPAUSED);
     }
-    if (virDomainSaveStatus(dom->conn, driver->stateDir, vm) < 0)
+    if (virDomainSaveStatus(dom->conn, driver->caps, driver->stateDir, vm) < 0)
         goto endjob;
     ret = 0;
 
@@ -3690,6 +3813,7 @@ qemudDomainPinVcpu(virDomainPtr dom,
     int maxcpu, hostcpus;
     virNodeInfo nodeinfo;
     int ret = -1;
+    qemuDomainObjPrivatePtr priv;
 
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -3709,10 +3833,12 @@ qemudDomainPinVcpu(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (vcpu > (vm->nvcpupids-1)) {
+    priv = vm->privateData;
+
+    if (vcpu > (priv->nvcpupids-1)) {
         qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
                          _("vcpu number out of range %d > %d"),
-                         vcpu, vm->nvcpupids);
+                         vcpu, priv->nvcpupids);
         goto cleanup;
     }
 
@@ -3724,8 +3850,8 @@ qemudDomainPinVcpu(virDomainPtr dom,
     if (maxcpu > hostcpus)
         maxcpu = hostcpus;
 
-    if (vm->vcpupids != NULL) {
-        if (virProcessInfoSetAffinity(vm->vcpupids[vcpu],
+    if (priv->vcpupids != NULL) {
+        if (virProcessInfoSetAffinity(priv->vcpupids[vcpu],
                                       cpumap, maplen, maxcpu) < 0)
             goto cleanup;
     } else {
@@ -3752,6 +3878,7 @@ qemudDomainGetVcpus(virDomainPtr dom,
     virNodeInfo nodeinfo;
     int i, v, maxcpu, hostcpus;
     int ret = -1;
+    qemuDomainObjPrivatePtr priv;
 
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -3772,6 +3899,8 @@ qemudDomainGetVcpus(virDomainPtr dom,
         goto cleanup;
     }
 
+    priv = vm->privateData;
+
     if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
         goto cleanup;
 
@@ -3781,8 +3910,8 @@ qemudDomainGetVcpus(virDomainPtr dom,
         maxcpu = hostcpus;
 
     /* Clamp to actual number of vcpus */
-    if (maxinfo > vm->nvcpupids)
-        maxinfo = vm->nvcpupids;
+    if (maxinfo > priv->nvcpupids)
+        maxinfo = priv->nvcpupids;
 
     if (maxinfo >= 1) {
         if (info != NULL) {
@@ -3791,11 +3920,11 @@ qemudDomainGetVcpus(virDomainPtr dom,
                 info[i].number = i;
                 info[i].state = VIR_VCPU_RUNNING;
 
-                if (vm->vcpupids != NULL &&
+                if (priv->vcpupids != NULL &&
                     qemudGetProcessInfo(&(info[i].cpuTime),
                                         &(info[i].cpu),
                                         vm->pid,
-                                        vm->vcpupids[i]) < 0) {
+                                        priv->vcpupids[i]) < 0) {
                     virReportSystemError(dom->conn, errno, "%s",
                                          _("cannot get vCPU placement & pCPU time"));
                     goto cleanup;
@@ -3805,11 +3934,11 @@ qemudDomainGetVcpus(virDomainPtr dom,
 
         if (cpumaps != NULL) {
             memset(cpumaps, 0, maplen * maxinfo);
-            if (vm->vcpupids != NULL) {
+            if (priv->vcpupids != NULL) {
                 for (v = 0 ; v < maxinfo ; v++) {
                     unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
 
-                    if (virProcessInfoGetAffinity(vm->vcpupids[v],
+                    if (virProcessInfoGetAffinity(priv->vcpupids[v],
                                                   cpumap, maplen, maxcpu) < 0)
                         goto cleanup;
                 }
@@ -4098,7 +4227,7 @@ static int qemudDomainRestore(virConnectPtr conn,
         }
         qemuDomainObjExitMonitorWithDriver(driver, vm);
         vm->state = VIR_DOMAIN_RUNNING;
-        virDomainSaveStatus(conn, driver->stateDir, vm);
+        virDomainSaveStatus(conn, driver->caps, driver->stateDir, vm);
     }
     ret = 0;
 
@@ -4206,7 +4335,7 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
                                    unsigned int flags ATTRIBUTE_UNUSED) {
     struct qemud_driver *driver = conn->privateData;
     virDomainDefPtr def = NULL;
-    virDomainChrDef monitor_chr;
+    virDomainChrDef monConfig;
     const char *emulator;
     unsigned int qemuCmdFlags;
     struct stat sb;
@@ -4285,11 +4414,11 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (qemuPrepareMonitorChr(conn, driver, &monitor_chr, def->name) < 0)
+    if (qemuPrepareMonitorChr(conn, driver, &monConfig, def->name) < 0)
         goto cleanup;
 
     if (qemudBuildCommandLine(conn, driver, def,
-                              &monitor_chr, qemuCmdFlags,
+                              &monConfig, qemuCmdFlags,
                               &retargv, &retenv,
                               NULL, NULL, /* Don't want it to create TAP devices */
                               NULL) < 0) {
@@ -4834,7 +4963,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
 
     if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
         net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
-        if (vm->monitor_chr->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
+        if (priv->monConfig->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
             qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT,
                              _("network device type '%s' cannot be attached: "
                                "qemu is not using a unix socket monitor"),
@@ -5172,7 +5301,7 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
         goto endjob;
     }
 
-    if (!ret && virDomainSaveStatus(dom->conn, driver->stateDir, vm) < 0)
+    if (!ret && virDomainSaveStatus(dom->conn, driver->caps, driver->stateDir, vm) < 0)
         ret = -1;
 
 endjob:
@@ -5506,7 +5635,7 @@ static int qemudDomainDetachDevice(virDomainPtr dom,
         qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
                          "%s", _("only SCSI or virtio disk device can be detached dynamically"));
 
-    if (!ret && virDomainSaveStatus(dom->conn, driver->stateDir, vm) < 0)
+    if (!ret && virDomainSaveStatus(dom->conn, driver->caps, driver->stateDir, vm) < 0)
         ret = -1;
 
 endjob:
@@ -7354,7 +7483,7 @@ qemudDomainMigrateFinish2 (virConnectPtr dconn,
         event = virDomainEventNewFromObj(vm,
                                          VIR_DOMAIN_EVENT_RESUMED,
                                          VIR_DOMAIN_EVENT_RESUMED_MIGRATED);
-        virDomainSaveStatus(dconn, driver->stateDir, vm);
+        virDomainSaveStatus(dconn, driver->caps, driver->stateDir, vm);
     } else {
         qemudShutdownVMDaemon (dconn, driver, vm);
         event = virDomainEventNewFromObj(vm,
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a6b445e..6c4dfde 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -533,6 +533,7 @@ qemuMonitorIO(int watch, int fd, int events, void *opaque) {
 
 qemuMonitorPtr
 qemuMonitorOpen(virDomainObjPtr vm,
+                virDomainChrDefPtr config,
                 qemuMonitorEOFNotify eofCB)
 {
     qemuMonitorPtr mon;
@@ -562,20 +563,20 @@ qemuMonitorOpen(virDomainObjPtr vm,
     qemuMonitorLock(mon);
     virDomainObjRef(vm);
 
-    switch (vm->monitor_chr->type) {
+    switch (config->type) {
     case VIR_DOMAIN_CHR_TYPE_UNIX:
         mon->hasSendFD = 1;
-        mon->fd = qemuMonitorOpenUnix(vm->monitor_chr->data.nix.path);
+        mon->fd = qemuMonitorOpenUnix(config->data.nix.path);
         break;
 
     case VIR_DOMAIN_CHR_TYPE_PTY:
-        mon->fd = qemuMonitorOpenPty(vm->monitor_chr->data.file.path);
+        mon->fd = qemuMonitorOpenPty(config->data.file.path);
         break;
 
     default:
         qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                          _("unable to handle monitor type: %s"),
-                         virDomainChrTypeToString(vm->monitor_chr->type));
+                         virDomainChrTypeToString(config->type));
         goto cleanup;
     }
 
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 14198fb..5f1a65d 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -79,6 +79,7 @@ char *qemuMonitorEscapeArg(const char *in);
 char *qemuMonitorEscapeShell(const char *in);
 
 qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
+                               virDomainChrDefPtr config,
                                qemuMonitorEOFNotify eofCB);
 
 int qemuMonitorClose(qemuMonitorPtr mon);
-- 
1.6.5.2


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