Convert Xen domain device hotplug driver methods to use virDomainDefPtr

Introduce use of a virDomainDefPtr in the domain hotplug
APIs to simplify introduction of ACL security checks.
The virDomainPtr cannot be safely used, since the app
may have supplied mis-matching name/uuid/id fields. eg
the name points to domain X, while the uuid points to
domain Y. Resolving the virDomainPtr to a virDomainDefPtr
ensures a consistent name/uuid/id set.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-05-02 10:56:31 +01:00
parent 95e18efddd
commit 21213a4b13
5 changed files with 134 additions and 72 deletions

View File

@ -1693,6 +1693,8 @@ xenUnifiedDomainAttachDevice(virDomainPtr dom, const char *xml)
{ {
xenUnifiedPrivatePtr priv = dom->conn->privateData; xenUnifiedPrivatePtr priv = dom->conn->privateData;
unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE; unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE;
virDomainDefPtr def = NULL;
int ret = -1;
/* /*
* HACK: xend with xendConfigVersion >= 3 does not support changing live * HACK: xend with xendConfigVersion >= 3 does not support changing live
@ -1702,12 +1704,17 @@ xenUnifiedDomainAttachDevice(virDomainPtr dom, const char *xml)
if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4) if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG; flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) if (!(def = xenGetDomainDefForDom(dom)))
return xenXMDomainAttachDeviceFlags(dom, xml, flags); goto cleanup;
else
return xenDaemonAttachDeviceFlags(dom, xml, flags);
return -1; if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
ret = xenXMDomainAttachDeviceFlags(dom->conn, def, xml, flags);
else
ret = xenDaemonAttachDeviceFlags(dom->conn, def, xml, flags);
cleanup:
virDomainDefFree(def);
return ret;
} }
static int static int
@ -1715,11 +1722,20 @@ xenUnifiedDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags) unsigned int flags)
{ {
xenUnifiedPrivatePtr priv = dom->conn->privateData; xenUnifiedPrivatePtr priv = dom->conn->privateData;
virDomainDefPtr def = NULL;
int ret = -1;
if (!(def = xenGetDomainDefForDom(dom)))
goto cleanup;
if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return xenXMDomainAttachDeviceFlags(dom, xml, flags); ret = xenXMDomainAttachDeviceFlags(dom->conn, def, xml, flags);
else else
return xenDaemonAttachDeviceFlags(dom, xml, flags); ret = xenDaemonAttachDeviceFlags(dom->conn, def, xml, flags);
cleanup:
virDomainDefFree(def);
return ret;
} }
static int static int
@ -1727,6 +1743,8 @@ xenUnifiedDomainDetachDevice(virDomainPtr dom, const char *xml)
{ {
xenUnifiedPrivatePtr priv = dom->conn->privateData; xenUnifiedPrivatePtr priv = dom->conn->privateData;
unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE; unsigned int flags = VIR_DOMAIN_DEVICE_MODIFY_LIVE;
virDomainDefPtr def = NULL;
int ret = -1;
/* /*
* HACK: xend with xendConfigVersion >= 3 does not support changing live * HACK: xend with xendConfigVersion >= 3 does not support changing live
@ -1736,10 +1754,17 @@ xenUnifiedDomainDetachDevice(virDomainPtr dom, const char *xml)
if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4) if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG; flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
if (!(def = xenGetDomainDefForDom(dom)))
goto cleanup;
if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return xenXMDomainDetachDeviceFlags(dom, xml, flags); ret = xenXMDomainDetachDeviceFlags(dom->conn, def, xml, flags);
else else
return xenDaemonDetachDeviceFlags(dom, xml, flags); ret = xenDaemonDetachDeviceFlags(dom->conn, def, xml, flags);
cleanup:
virDomainDefFree(def);
return ret;
} }
static int static int
@ -1747,18 +1772,37 @@ xenUnifiedDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags) unsigned int flags)
{ {
xenUnifiedPrivatePtr priv = dom->conn->privateData; xenUnifiedPrivatePtr priv = dom->conn->privateData;
virDomainDefPtr def = NULL;
int ret = -1;
if (!(def = xenGetDomainDefForDom(dom)))
goto cleanup;
if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) if (dom->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return xenXMDomainDetachDeviceFlags(dom, xml, flags); ret = xenXMDomainDetachDeviceFlags(dom->conn, def, xml, flags);
else else
return xenDaemonDetachDeviceFlags(dom, xml, flags); ret = xenDaemonDetachDeviceFlags(dom->conn, def, xml, flags);
cleanup:
virDomainDefFree(def);
return ret;
} }
static int static int
xenUnifiedDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, xenUnifiedDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags) unsigned int flags)
{ {
return xenDaemonUpdateDeviceFlags(dom, xml, flags); virDomainDefPtr def = NULL;
int ret = -1;
if (!(def = xenGetDomainDefForDom(dom)))
goto cleanup;
ret = xenDaemonUpdateDeviceFlags(dom->conn, def, xml, flags);
cleanup:
virDomainDefFree(def);
return ret;
} }
static int static int

View File

@ -70,7 +70,8 @@
#define XEND_RCV_BUF_MAX_LEN (256 * 1024) #define XEND_RCV_BUF_MAX_LEN (256 * 1024)
static int static int
virDomainXMLDevID(virDomainPtr domain, virDomainDeviceDefPtr dev, char *class, virDomainXMLDevID(virConnectPtr conn, virDomainDefPtr domain,
virDomainDeviceDefPtr dev, char *class,
char *ref, int ref_len); char *ref, int ref_len);
/** /**
@ -2205,7 +2206,8 @@ xenDaemonCreateXML(virConnectPtr conn, virDomainDefPtr def)
/** /**
* xenDaemonAttachDeviceFlags: * xenDaemonAttachDeviceFlags:
* @domain: pointer to domain object * @conn: the connection object
* @minidef: domain configuration
* @xml: pointer to XML description of device * @xml: pointer to XML description of device
* @flags: an OR'ed set of virDomainDeviceModifyFlags * @flags: an OR'ed set of virDomainDeviceModifyFlags
* *
@ -2215,11 +2217,12 @@ xenDaemonCreateXML(virConnectPtr conn, virDomainDefPtr def)
* Returns 0 in case of success, -1 in case of failure. * Returns 0 in case of success, -1 in case of failure.
*/ */
int int
xenDaemonAttachDeviceFlags(virDomainPtr domain, xenDaemonAttachDeviceFlags(virConnectPtr conn,
virDomainDefPtr minidef,
const char *xml, const char *xml,
unsigned int flags) unsigned int flags)
{ {
xenUnifiedPrivatePtr priv = domain->conn->privateData; xenUnifiedPrivatePtr priv = conn->privateData;
char *sexpr = NULL; char *sexpr = NULL;
int ret = -1; int ret = -1;
virDomainDeviceDefPtr dev = NULL; virDomainDeviceDefPtr dev = NULL;
@ -2230,7 +2233,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain,
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
if (domain->id < 0) { if (minidef->id < 0) {
/* Cannot modify live config if domain is inactive */ /* Cannot modify live config if domain is inactive */
if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) { if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@ -2260,9 +2263,9 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain,
} }
} }
if (!(def = xenDaemonDomainFetch(domain->conn, if (!(def = xenDaemonDomainFetch(conn,
domain->id, minidef->id,
domain->name, minidef->name,
NULL))) NULL)))
goto cleanup; goto cleanup;
@ -2288,7 +2291,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain,
break; break;
case VIR_DOMAIN_DEVICE_NET: case VIR_DOMAIN_DEVICE_NET:
if (xenFormatSxprNet(domain->conn, if (xenFormatSxprNet(conn,
dev->data.net, dev->data.net,
&buf, &buf,
STREQ(def->os.type, "hvm") ? 1 : 0, STREQ(def->os.type, "hvm") ? 1 : 0,
@ -2333,9 +2336,9 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain,
sexpr = virBufferContentAndReset(&buf); sexpr = virBufferContentAndReset(&buf);
if (virDomainXMLDevID(domain, dev, class, ref, sizeof(ref))) { if (virDomainXMLDevID(conn, minidef, dev, class, ref, sizeof(ref))) {
/* device doesn't exist, define it */ /* device doesn't exist, define it */
ret = xend_op(domain->conn, domain->name, "op", "device_create", ret = xend_op(conn, def->name, "op", "device_create",
"config", sexpr, NULL); "config", sexpr, NULL);
} else { } else {
if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) { if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
@ -2343,7 +2346,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain,
_("target '%s' already exists"), target); _("target '%s' already exists"), target);
} else { } else {
/* device exists, attempt to modify it */ /* device exists, attempt to modify it */
ret = xend_op(domain->conn, domain->name, "op", "device_configure", ret = xend_op(conn, minidef->name, "op", "device_configure",
"config", sexpr, "dev", ref, NULL); "config", sexpr, "dev", ref, NULL);
} }
} }
@ -2358,7 +2361,8 @@ cleanup:
/** /**
* xenDaemonUpdateDeviceFlags: * xenDaemonUpdateDeviceFlags:
* @domain: pointer to domain object * @conn: the connection object
* @minidef: domain configuration
* @xml: pointer to XML description of device * @xml: pointer to XML description of device
* @flags: an OR'ed set of virDomainDeviceModifyFlags * @flags: an OR'ed set of virDomainDeviceModifyFlags
* *
@ -2368,11 +2372,12 @@ cleanup:
* Returns 0 in case of success, -1 in case of failure. * Returns 0 in case of success, -1 in case of failure.
*/ */
int int
xenDaemonUpdateDeviceFlags(virDomainPtr domain, xenDaemonUpdateDeviceFlags(virConnectPtr conn,
virDomainDefPtr minidef,
const char *xml, const char *xml,
unsigned int flags) unsigned int flags)
{ {
xenUnifiedPrivatePtr priv = domain->conn->privateData; xenUnifiedPrivatePtr priv = conn->privateData;
char *sexpr = NULL; char *sexpr = NULL;
int ret = -1; int ret = -1;
virDomainDeviceDefPtr dev = NULL; virDomainDeviceDefPtr dev = NULL;
@ -2383,7 +2388,7 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain,
virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE | virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1); VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
if (domain->id < 0) { if (minidef->id < 0) {
/* Cannot modify live config if domain is inactive */ /* Cannot modify live config if domain is inactive */
if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) { if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@ -2413,9 +2418,9 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain,
} }
} }
if (!(def = xenDaemonDomainFetch(domain->conn, if (!(def = xenDaemonDomainFetch(conn,
domain->id, minidef->id,
domain->name, minidef->name,
NULL))) NULL)))
goto cleanup; goto cleanup;
@ -2441,13 +2446,13 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain,
sexpr = virBufferContentAndReset(&buf); sexpr = virBufferContentAndReset(&buf);
if (virDomainXMLDevID(domain, dev, class, ref, sizeof(ref))) { if (virDomainXMLDevID(conn, minidef, dev, class, ref, sizeof(ref))) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("requested device does not exist")); _("requested device does not exist"));
goto cleanup; goto cleanup;
} else { } else {
/* device exists, attempt to modify it */ /* device exists, attempt to modify it */
ret = xend_op(domain->conn, domain->name, "op", "device_configure", ret = xend_op(conn, minidef->name, "op", "device_configure",
"config", sexpr, "dev", ref, NULL); "config", sexpr, "dev", ref, NULL);
} }
@ -2460,7 +2465,8 @@ cleanup:
/** /**
* xenDaemonDetachDeviceFlags: * xenDaemonDetachDeviceFlags:
* @domain: pointer to domain object * @conn: the connection object
* @minidef: domain configuration
* @xml: pointer to XML description of device * @xml: pointer to XML description of device
* @flags: an OR'ed set of virDomainDeviceModifyFlags * @flags: an OR'ed set of virDomainDeviceModifyFlags
* *
@ -2469,11 +2475,12 @@ cleanup:
* Returns 0 in case of success, -1 in case of failure. * Returns 0 in case of success, -1 in case of failure.
*/ */
int int
xenDaemonDetachDeviceFlags(virDomainPtr domain, xenDaemonDetachDeviceFlags(virConnectPtr conn,
virDomainDefPtr minidef,
const char *xml, const char *xml,
unsigned int flags) unsigned int flags)
{ {
xenUnifiedPrivatePtr priv = domain->conn->privateData; xenUnifiedPrivatePtr priv = conn->privateData;
char class[8], ref[80]; char class[8], ref[80];
virDomainDeviceDefPtr dev = NULL; virDomainDeviceDefPtr dev = NULL;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
@ -2483,7 +2490,7 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain,
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
if (domain->id < 0) { if (minidef->id < 0) {
/* Cannot modify live config if domain is inactive */ /* Cannot modify live config if domain is inactive */
if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) { if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@ -2513,9 +2520,9 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain,
} }
} }
if (!(def = xenDaemonDomainFetch(domain->conn, if (!(def = xenDaemonDomainFetch(conn,
domain->id, minidef->id,
domain->name, minidef->name,
NULL))) NULL)))
goto cleanup; goto cleanup;
@ -2523,7 +2530,7 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain,
VIR_DOMAIN_XML_INACTIVE))) VIR_DOMAIN_XML_INACTIVE)))
goto cleanup; goto cleanup;
if (virDomainXMLDevID(domain, dev, class, ref, sizeof(ref))) if (virDomainXMLDevID(conn, minidef, dev, class, ref, sizeof(ref)))
goto cleanup; goto cleanup;
if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) { if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
@ -2537,12 +2544,12 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain,
goto cleanup; goto cleanup;
} }
xendev = virBufferContentAndReset(&buf); xendev = virBufferContentAndReset(&buf);
ret = xend_op(domain->conn, domain->name, "op", "device_configure", ret = xend_op(conn, minidef->name, "op", "device_configure",
"config", xendev, "dev", ref, NULL); "config", xendev, "dev", ref, NULL);
VIR_FREE(xendev); VIR_FREE(xendev);
} }
else { else {
ret = xend_op(domain->conn, domain->name, "op", "device_destroy", ret = xend_op(conn, minidef->name, "op", "device_destroy",
"type", class, "dev", ref, "force", "0", "rm_cfg", "1", "type", class, "dev", ref, "force", "0", "rm_cfg", "1",
NULL); NULL);
} }
@ -3347,13 +3354,14 @@ xenDaemonDomainBlockPeek(virDomainPtr domain,
* Returns 0 in case of success, -1 in case of failure. * Returns 0 in case of success, -1 in case of failure.
*/ */
static int static int
virDomainXMLDevID(virDomainPtr domain, virDomainXMLDevID(virConnectPtr conn,
virDomainDefPtr def,
virDomainDeviceDefPtr dev, virDomainDeviceDefPtr dev,
char *class, char *class,
char *ref, char *ref,
int ref_len) int ref_len)
{ {
xenUnifiedPrivatePtr priv = domain->conn->privateData; xenUnifiedPrivatePtr priv = conn->privateData;
char *xref; char *xref;
char *tmp; char *tmp;
@ -3370,7 +3378,7 @@ virDomainXMLDevID(virDomainPtr domain,
if (dev->data.disk->dst == NULL) if (dev->data.disk->dst == NULL)
return -1; return -1;
xenUnifiedLock(priv); xenUnifiedLock(priv);
xref = xenStoreDomainGetDiskID(domain->conn, domain->id, xref = xenStoreDomainGetDiskID(conn, def->id,
dev->data.disk->dst); dev->data.disk->dst);
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);
if (xref == NULL) if (xref == NULL)
@ -3382,13 +3390,13 @@ virDomainXMLDevID(virDomainPtr domain,
return -1; return -1;
} else if (dev->type == VIR_DOMAIN_DEVICE_NET) { } else if (dev->type == VIR_DOMAIN_DEVICE_NET) {
char mac[VIR_MAC_STRING_BUFLEN]; char mac[VIR_MAC_STRING_BUFLEN];
virDomainNetDefPtr def = dev->data.net; virDomainNetDefPtr netdef = dev->data.net;
virMacAddrFormat(&def->mac, mac); virMacAddrFormat(&netdef->mac, mac);
strcpy(class, "vif"); strcpy(class, "vif");
xenUnifiedLock(priv); xenUnifiedLock(priv);
xref = xenStoreDomainGetNetworkID(domain->conn, domain->id, mac); xref = xenStoreDomainGetNetworkID(conn, def->id, mac);
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);
if (xref == NULL) if (xref == NULL)
return -1; return -1;
@ -3401,13 +3409,13 @@ virDomainXMLDevID(virDomainPtr domain,
dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
dev->data.hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) { dev->data.hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
char *bdf; char *bdf;
virDomainHostdevDefPtr def = dev->data.hostdev; virDomainHostdevDefPtr hostdef = dev->data.hostdev;
if (virAsprintf(&bdf, "%04x:%02x:%02x.%0x", if (virAsprintf(&bdf, "%04x:%02x:%02x.%0x",
def->source.subsys.u.pci.addr.domain, hostdef->source.subsys.u.pci.addr.domain,
def->source.subsys.u.pci.addr.bus, hostdef->source.subsys.u.pci.addr.bus,
def->source.subsys.u.pci.addr.slot, hostdef->source.subsys.u.pci.addr.slot,
def->source.subsys.u.pci.addr.function) < 0) { hostdef->source.subsys.u.pci.addr.function) < 0) {
virReportOOMError(); virReportOOMError();
return -1; return -1;
} }
@ -3415,7 +3423,7 @@ virDomainXMLDevID(virDomainPtr domain,
strcpy(class, "pci"); strcpy(class, "pci");
xenUnifiedLock(priv); xenUnifiedLock(priv);
xref = xenStoreDomainGetPCIID(domain->conn, domain->id, bdf); xref = xenStoreDomainGetPCIID(conn, def->id, bdf);
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);
VIR_FREE(bdf); VIR_FREE(bdf);
if (xref == NULL) if (xref == NULL)

View File

@ -133,10 +133,12 @@ int xenDaemonListDefinedDomains(virConnectPtr conn,
char **const names, char **const names,
int maxnames); int maxnames);
int xenDaemonAttachDeviceFlags(virDomainPtr domain, int xenDaemonAttachDeviceFlags(virConnectPtr conn,
virDomainDefPtr def,
const char *xml, const char *xml,
unsigned int flags); unsigned int flags);
int xenDaemonDetachDeviceFlags(virDomainPtr domain, int xenDaemonDetachDeviceFlags(virConnectPtr conn,
virDomainDefPtr def,
const char *xml, const char *xml,
unsigned int flags); unsigned int flags);
@ -168,7 +170,9 @@ int xenDaemonDomainGetVcpus (virConnectPtr conn,
int maxinfo, int maxinfo,
unsigned char *cpumaps, unsigned char *cpumaps,
int maplen); int maplen);
int xenDaemonUpdateDeviceFlags(virDomainPtr domain, const char *xml, int xenDaemonUpdateDeviceFlags(virConnectPtr conn,
virDomainDefPtr def,
const char *xml,
unsigned int flags); unsigned int flags);
int xenDaemonDomainGetAutostart (virDomainPtr dom, int xenDaemonDomainGetAutostart (virDomainPtr dom,
int *autostart); int *autostart);

View File

@ -1211,7 +1211,8 @@ cleanup:
/** /**
* xenXMDomainAttachDeviceFlags: * xenXMDomainAttachDeviceFlags:
* @domain: pointer to domain object * @conn: the connection object
* @minidef: domain configuration
* @xml: pointer to XML description of device * @xml: pointer to XML description of device
* @flags: an OR'ed set of virDomainDeviceModifyFlags * @flags: an OR'ed set of virDomainDeviceModifyFlags
* *
@ -1223,7 +1224,8 @@ cleanup:
* Returns 0 in case of success, -1 in case of failure. * Returns 0 in case of success, -1 in case of failure.
*/ */
int int
xenXMDomainAttachDeviceFlags(virDomainPtr domain, xenXMDomainAttachDeviceFlags(virConnectPtr conn,
virDomainDefPtr minidef,
const char *xml, const char *xml,
unsigned int flags) unsigned int flags)
{ {
@ -1232,12 +1234,12 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain,
int ret = -1; int ret = -1;
virDomainDeviceDefPtr dev = NULL; virDomainDeviceDefPtr dev = NULL;
virDomainDefPtr def; virDomainDefPtr def;
xenUnifiedPrivatePtr priv = domain->conn->privateData; xenUnifiedPrivatePtr priv = conn->privateData;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
if ((flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) || if ((flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) ||
(domain->id != -1 && flags == VIR_DOMAIN_DEVICE_MODIFY_CURRENT)) { (minidef->id != -1 && flags == VIR_DOMAIN_DEVICE_MODIFY_CURRENT)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Xm driver only supports modifying persistent config")); _("Xm driver only supports modifying persistent config"));
return -1; return -1;
@ -1245,7 +1247,7 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain,
xenUnifiedLock(priv); xenUnifiedLock(priv);
if (!(filename = virHashLookup(priv->nameConfigMap, domain->name))) if (!(filename = virHashLookup(priv->nameConfigMap, minidef->name)))
goto cleanup; goto cleanup;
if (!(entry = virHashLookup(priv->configCache, filename))) if (!(entry = virHashLookup(priv->configCache, filename)))
goto cleanup; goto cleanup;
@ -1288,7 +1290,7 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain,
/* If this fails, should we try to undo our changes to the /* If this fails, should we try to undo our changes to the
* in-memory representation of the config file. I say not! * in-memory representation of the config file. I say not!
*/ */
if (xenXMConfigSaveFile(domain->conn, entry->filename, entry->def) < 0) if (xenXMConfigSaveFile(conn, entry->filename, entry->def) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -1302,7 +1304,8 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain,
/** /**
* xenXMDomainDetachDeviceFlags: * xenXMDomainDetachDeviceFlags:
* @domain: pointer to domain object * @conn: the connection object
* @minidef: domain configuration
* @xml: pointer to XML description of device * @xml: pointer to XML description of device
* @flags: an OR'ed set of virDomainDeviceModifyFlags * @flags: an OR'ed set of virDomainDeviceModifyFlags
* *
@ -1313,7 +1316,8 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain,
* Returns 0 in case of success, -1 in case of failure. * Returns 0 in case of success, -1 in case of failure.
*/ */
int int
xenXMDomainDetachDeviceFlags(virDomainPtr domain, xenXMDomainDetachDeviceFlags(virConnectPtr conn,
virDomainDefPtr minidef,
const char *xml, const char *xml,
unsigned int flags) unsigned int flags)
{ {
@ -1323,12 +1327,12 @@ xenXMDomainDetachDeviceFlags(virDomainPtr domain,
virDomainDefPtr def; virDomainDefPtr def;
int ret = -1; int ret = -1;
int i; int i;
xenUnifiedPrivatePtr priv = domain->conn->privateData; xenUnifiedPrivatePtr priv = conn->privateData;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1); virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
if ((flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) || if ((flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) ||
(domain->id != -1 && flags == VIR_DOMAIN_DEVICE_MODIFY_CURRENT)) { (minidef->id != -1 && flags == VIR_DOMAIN_DEVICE_MODIFY_CURRENT)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Xm driver only supports modifying persistent config")); _("Xm driver only supports modifying persistent config"));
return -1; return -1;
@ -1336,7 +1340,7 @@ xenXMDomainDetachDeviceFlags(virDomainPtr domain,
xenUnifiedLock(priv); xenUnifiedLock(priv);
if (!(filename = virHashLookup(priv->nameConfigMap, domain->name))) if (!(filename = virHashLookup(priv->nameConfigMap, minidef->name)))
goto cleanup; goto cleanup;
if (!(entry = virHashLookup(priv->configCache, filename))) if (!(entry = virHashLookup(priv->configCache, filename)))
goto cleanup; goto cleanup;
@ -1394,7 +1398,7 @@ xenXMDomainDetachDeviceFlags(virDomainPtr domain,
/* If this fails, should we try to undo our changes to the /* If this fails, should we try to undo our changes to the
* in-memory representation of the config file. I say not! * in-memory representation of the config file. I say not!
*/ */
if (xenXMConfigSaveFile(domain->conn, entry->filename, entry->def) < 0) if (xenXMConfigSaveFile(conn, entry->filename, entry->def) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;

View File

@ -85,11 +85,13 @@ int xenXMDomainBlockPeek (virDomainPtr dom, const char *path, unsigned long long
int xenXMDomainGetAutostart(virDomainPtr dom, int *autostart); int xenXMDomainGetAutostart(virDomainPtr dom, int *autostart);
int xenXMDomainSetAutostart(virDomainPtr dom, int autostart); int xenXMDomainSetAutostart(virDomainPtr dom, int autostart);
int xenXMDomainAttachDeviceFlags(virDomainPtr domain, int xenXMDomainAttachDeviceFlags(virConnectPtr conn,
virDomainDefPtr def,
const char *xml, const char *xml,
unsigned int flags); unsigned int flags);
int xenXMDomainDetachDeviceFlags(virDomainPtr domain, int xenXMDomainDetachDeviceFlags(virConnectPtr conn,
virDomainDefPtr def,
const char *xml, const char *xml,
unsigned int flags); unsigned int flags);