virDomainDefFree(dom->def);
virDomainDefFree(dom->newDef);
- virDomainChrDefFree(dom->monitor_chr);
-
- VIR_FREE(dom->vcpupids);
-
if (dom->privateDataFreeFunc)
(dom->privateDataFreeFunc)(dom->privateData);
virDomainObjLock(domain);
domain->state = VIR_DOMAIN_SHUTOFF;
- domain->monitorWatch = -1;
- domain->monitor = -1;
domain->refs = 1;
VIR_DEBUG("obj=%p", domain);
xmlNodePtr config;
xmlNodePtr oldnode;
virDomainObjPtr obj;
- char *monitorpath;
- xmlNodePtr *nodes = NULL;
- int n, i;
if (!(obj = virDomainObjNew(conn, caps)))
return NULL;
}
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;
}
}
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,
}
int virDomainSaveStatus(virConnectPtr conn,
+ virCapsPtr caps,
const char *statusDir,
virDomainObjPtr obj)
{
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))
#include "security/security_driver.h"
#include "cgroup.h"
#include "libvirt_internal.h"
+#include "xml.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
* information, not merely actions */
qemuMonitorPtr mon;
+ virDomainChrDefPtr monConfig;
+
+ int nvcpupids;
+ int *vcpupids;
};
static int qemudShutdown(void);
{
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");
}
+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
*
* deleted while the monitor is active */
virDomainObjRef(vm);
- 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;
}
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;
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;
}
return -1;
}
- vm->nvcpupids = ncpupids;
- vm->vcpupids = cpupids;
+ priv->nvcpupids = ncpupids;
+ priv->vcpupids = cpupids;
return 0;
}
virNodeInfo nodeinfo;
unsigned char *cpumap;
int cpumaplen;
+ qemuDomainObjPrivatePtr priv = vm->privateData;
if (nodeGetInfo(conn, &nodeinfo) < 0)
return -1;
/* 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;
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;
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) {
}
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;
qemuDomainObjExitMonitorWithDriver(driver, vm);
- if (virDomainSaveStatus(conn, driver->stateDir, vm) < 0)
+ if (virDomainSaveStatus(conn, driver->caps, driver->stateDir, vm) < 0)
goto abort;
return 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 */
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);
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;
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;
int maxcpu, hostcpus;
virNodeInfo nodeinfo;
int ret = -1;
+ qemuDomainObjPrivatePtr priv;
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
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;
}
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 {
virNodeInfo nodeinfo;
int i, v, maxcpu, hostcpus;
int ret = -1;
+ qemuDomainObjPrivatePtr priv;
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
goto cleanup;
}
+ priv = vm->privateData;
+
if (nodeGetInfo(dom->conn, &nodeinfo) < 0)
goto cleanup;
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) {
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;
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;
}
}
qemuDomainObjExitMonitorWithDriver(driver, vm);
vm->state = VIR_DOMAIN_RUNNING;
- virDomainSaveStatus(conn, driver->stateDir, vm);
+ virDomainSaveStatus(conn, driver->caps, driver->stateDir, vm);
}
ret = 0;
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;
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) {
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"),
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:
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:
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,