virDomainDefPtr def = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
char class[8], ref[80];
+ char *target = NULL;
if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
virXendError(VIR_ERR_INVALID_ARG, __FUNCTION__);
STREQ(def->os.type, "hvm") ? 1 : 0,
priv->xendConfigVersion, 1) < 0)
goto cleanup;
+
+ if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
+ if (!(target = strdup(dev->data.disk->dst))) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ }
break;
case VIR_DOMAIN_DEVICE_NET:
STREQ(def->os.type, "hvm") ? 1 : 0,
priv->xendConfigVersion, 1) < 0)
goto cleanup;
+
+ char macStr[VIR_MAC_STRING_BUFLEN];
+ virFormatMacAddr(dev->data.net->mac, macStr);
+
+ if (!(target = strdup(macStr))) {
+ virReportOOMError();
+ goto cleanup;
+ }
break;
case VIR_DOMAIN_DEVICE_HOSTDEV:
if (xenDaemonFormatSxprOnePCI(dev->data.hostdev,
&buf, 0) < 0)
goto cleanup;
+
+ virDomainDevicePCIAddress PCIAddr;
+
+ PCIAddr = dev->data.hostdev->source.subsys.u.pci;
+ virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x", PCIAddr.domain,
+ PCIAddr.bus, PCIAddr.slot);
+
+ if (target == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
} else {
virXendError(VIR_ERR_NO_SUPPORT, "%s",
_("unsupported device type"));
/* device doesn't exist, define it */
ret = xend_op(domain->conn, domain->name, "op", "device_create",
"config", sexpr, NULL);
- }
- else {
- /* device exists, attempt to modify it */
- ret = xend_op(domain->conn, domain->name, "op", "device_configure",
- "config", sexpr, "dev", ref, NULL);
+ } else {
+ if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
+ virXendError(VIR_ERR_OPERATION_INVALID,
+ _("target '%s' already exists"), target);
+ } else {
+ /* device exists, attempt to modify it */
+ ret = xend_op(domain->conn, domain->name, "op", "device_configure",
+ "config", sexpr, "dev", ref, NULL);
+ }
}
cleanup:
VIR_FREE(sexpr);
virDomainDefFree(def);
virDomainDeviceDefFree(dev);
+ VIR_FREE(target);
return ret;
}