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

[libvirt] [PATCH v3 06/13] Move the qemu[*]DomainDeviceConfig to qemu_domain.c



No functional change.

Signed-off-by: Shivaprasad G Bhat <sbhat linux vnet ibm com>
---
 src/qemu/qemu_domain.c |  401 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h |   17 ++
 src/qemu/qemu_driver.c |  401 ------------------------------------------------
 3 files changed, 418 insertions(+), 401 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b0eb3b6..e1d3824 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -30,6 +30,7 @@
 #include "qemu_parse_command.h"
 #include "qemu_capabilities.h"
 #include "qemu_migration.h"
+#include "qemu_hotplug.h"
 #include "viralloc.h"
 #include "virlog.h"
 #include "virerror.h"
@@ -5352,3 +5353,403 @@ qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
 
     return 0;
 }
+
+int
+qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
+                             virDomainDefPtr vmdef,
+                             virDomainDeviceDefPtr dev,
+                             virConnectPtr conn)
+{
+    virDomainDiskDefPtr disk;
+    virDomainNetDefPtr net;
+    virDomainHostdevDefPtr hostdev;
+    virDomainLeaseDefPtr lease;
+    virDomainControllerDefPtr controller;
+    virDomainFSDefPtr fs;
+
+    switch ((virDomainDeviceType) dev->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        disk = dev->data.disk;
+        if (virDomainDiskIndexByName(vmdef, disk->dst, true) >= 0) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("target %s already exists"), disk->dst);
+            return -1;
+        }
+        if (virStorageTranslateDiskSourcePool(conn, disk) < 0)
+            return -1;
+        if (qemuCheckDiskConfig(disk) < 0)
+            return -1;
+        if (virDomainDiskInsert(vmdef, disk))
+            return -1;
+        /* vmdef has the pointer. Generic codes for vmdef will do all jobs */
+        dev->data.disk = NULL;
+        if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO)
+            if (virDomainDefAddImplicitDevices(vmdef) < 0)
+                return -1;
+        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_DEVICE_NET:
+        net = dev->data.net;
+        if (virDomainNetInsert(vmdef, net))
+            return -1;
+        dev->data.net = NULL;
+        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
+        hostdev = dev->data.hostdev;
+        if (virDomainHostdevFind(vmdef, hostdev, NULL) >= 0) {
+            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                           _("device is already in the domain configuration"));
+            return -1;
+        }
+        if (virDomainHostdevInsert(vmdef, hostdev))
+            return -1;
+        dev->data.hostdev = NULL;
+        if (virDomainDefAddImplicitDevices(vmdef) < 0)
+            return -1;
+        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_DEVICE_LEASE:
+        lease = dev->data.lease;
+        if (virDomainLeaseIndex(vmdef, lease) >= 0) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("Lease %s in lockspace %s already exists"),
+                           lease->key, NULLSTR(lease->lockspace));
+            return -1;
+        }
+        if (virDomainLeaseInsert(vmdef, lease) < 0)
+            return -1;
+
+        /* vmdef has the pointer. Generic codes for vmdef will do all jobs */
+        dev->data.lease = NULL;
+        break;
+
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+        controller = dev->data.controller;
+        if (virDomainControllerFind(vmdef, controller->type,
+                                    controller->idx) >= 0) {
+            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                           _("Target already exists"));
+            return -1;
+        }
+
+        if (virDomainControllerInsert(vmdef, controller) < 0)
+            return -1;
+        dev->data.controller = NULL;
+
+        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_DEVICE_CHR:
+        if (qemuDomainChrInsert(vmdef, dev->data.chr) < 0)
+            return -1;
+        dev->data.chr = NULL;
+        if (virDomainDefAddImplicitDevices(vmdef) < 0)
+            return -1;
+        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_DEVICE_FS:
+        fs = dev->data.fs;
+        if (virDomainFSIndexByName(vmdef, fs->dst) >= 0) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                         "%s", _("Target already exists"));
+            return -1;
+        }
+
+        if (virDomainFSInsert(vmdef, fs) < 0)
+            return -1;
+        dev->data.fs = NULL;
+        break;
+
+    case VIR_DOMAIN_DEVICE_RNG:
+        if (dev->data.rng->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+            virDomainDefHasDeviceAddress(vmdef, &dev->data.rng->info)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("a device with the same address already exists "));
+            return -1;
+        }
+
+        if (virDomainRNGInsert(vmdef, dev->data.rng, false) < 0)
+            return -1;
+        dev->data.rng = NULL;
+
+        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_DEVICE_MEMORY:
+        if (vmdef->nmems == vmdef->mem.memory_slots) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("no free memory device slot available"));
+            return -1;
+        }
+
+        if (vmdef->mem.cur_balloon == virDomainDefGetMemoryActual(vmdef))
+            vmdef->mem.cur_balloon += dev->data.memory->size;
+
+        if (virDomainMemoryInsert(vmdef, dev->data.memory) < 0)
+            return -1;
+        dev->data.memory = NULL;
+        break;
+
+    case VIR_DOMAIN_DEVICE_INPUT:
+    case VIR_DOMAIN_DEVICE_SOUND:
+    case VIR_DOMAIN_DEVICE_VIDEO:
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
+    case VIR_DOMAIN_DEVICE_HUB:
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
+    case VIR_DOMAIN_DEVICE_NVRAM:
+    case VIR_DOMAIN_DEVICE_SHMEM:
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
+    case VIR_DOMAIN_DEVICE_NONE:
+    case VIR_DOMAIN_DEVICE_TPM:
+    case VIR_DOMAIN_DEVICE_PANIC:
+    case VIR_DOMAIN_DEVICE_LAST:
+         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+                        _("persistent attach of device '%s' is not supported"),
+                        virDomainDeviceTypeToString(dev->type));
+         return -1;
+    }
+    return 0;
+}
+
+int
+qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
+                             virDomainDeviceDefPtr dev)
+{
+    virDomainDiskDefPtr disk, det_disk;
+    virDomainNetDefPtr net;
+    virDomainHostdevDefPtr hostdev, det_hostdev;
+    virDomainLeaseDefPtr lease, det_lease;
+    virDomainControllerDefPtr cont, det_cont;
+    virDomainChrDefPtr chr;
+    virDomainFSDefPtr fs;
+    int idx;
+
+    switch ((virDomainDeviceType) dev->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        disk = dev->data.disk;
+        if (!(det_disk = virDomainDiskRemoveByName(vmdef, disk->dst))) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("no target device %s"), disk->dst);
+            return -1;
+        }
+        virDomainDiskDefFree(det_disk);
+        break;
+
+    case VIR_DOMAIN_DEVICE_NET:
+        net = dev->data.net;
+        if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
+            return -1;
+
+        /* this is guaranteed to succeed */
+        virDomainNetDefFree(virDomainNetRemove(vmdef, idx));
+        break;
+
+    case VIR_DOMAIN_DEVICE_HOSTDEV: {
+        hostdev = dev->data.hostdev;
+        if ((idx = virDomainHostdevFind(vmdef, hostdev, &det_hostdev)) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG, "%s",
+                           _("device not present in domain configuration"));
+            return -1;
+        }
+        virDomainHostdevRemove(vmdef, idx);
+        virDomainHostdevDefFree(det_hostdev);
+        break;
+    }
+
+    case VIR_DOMAIN_DEVICE_LEASE:
+        lease = dev->data.lease;
+        if (!(det_lease = virDomainLeaseRemove(vmdef, lease))) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Lease %s in lockspace %s does not exist"),
+                           lease->key, NULLSTR(lease->lockspace));
+            return -1;
+        }
+        virDomainLeaseDefFree(det_lease);
+        break;
+
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+        cont = dev->data.controller;
+        if ((idx = virDomainControllerFind(vmdef, cont->type,
+                                           cont->idx)) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG, "%s",
+                           _("device not present in domain configuration"));
+            return -1;
+        }
+        det_cont = virDomainControllerRemove(vmdef, idx);
+        virDomainControllerDefFree(det_cont);
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_CHR:
+        if (!(chr = qemuDomainChrRemove(vmdef, dev->data.chr)))
+            return -1;
+
+        virDomainChrDefFree(chr);
+        virDomainChrDefFree(dev->data.chr);
+        dev->data.chr = NULL;
+        break;
+
+    case VIR_DOMAIN_DEVICE_FS:
+        fs = dev->data.fs;
+        idx = virDomainFSIndexByName(vmdef, fs->dst);
+        if (idx < 0) {
+            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                           _("no matching filesystem device was found"));
+            return -1;
+        }
+
+        fs = virDomainFSRemove(vmdef, idx);
+        virDomainFSDefFree(fs);
+        break;
+
+    case VIR_DOMAIN_DEVICE_RNG:
+        if ((idx = virDomainRNGFind(vmdef, dev->data.rng)) < 0) {
+            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                           _("no matching RNG device was found"));
+            return -1;
+        }
+
+        virDomainRNGDefFree(virDomainRNGRemove(vmdef, idx));
+        break;
+
+    case VIR_DOMAIN_DEVICE_MEMORY:
+        if ((idx = virDomainMemoryFindInactiveByDef(vmdef,
+                                                    dev->data.memory)) < 0) {
+            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                           _("matching memory device was not found"));
+            return -1;
+        }
+
+        virDomainMemoryDefFree(virDomainMemoryRemove(vmdef, idx));
+        break;
+
+    case VIR_DOMAIN_DEVICE_INPUT:
+    case VIR_DOMAIN_DEVICE_SOUND:
+    case VIR_DOMAIN_DEVICE_VIDEO:
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
+    case VIR_DOMAIN_DEVICE_HUB:
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
+    case VIR_DOMAIN_DEVICE_NVRAM:
+    case VIR_DOMAIN_DEVICE_SHMEM:
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
+    case VIR_DOMAIN_DEVICE_NONE:
+    case VIR_DOMAIN_DEVICE_TPM:
+    case VIR_DOMAIN_DEVICE_PANIC:
+    case VIR_DOMAIN_DEVICE_LAST:
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+                       _("persistent detach of device '%s' is not supported"),
+                       virDomainDeviceTypeToString(dev->type));
+        return -1;
+    }
+    return 0;
+}
+
+int
+qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps,
+                             virDomainDefPtr vmdef,
+                             virDomainDeviceDefPtr dev)
+{
+    virDomainDiskDefPtr orig, disk;
+    virDomainGraphicsDefPtr newGraphics;
+    virDomainNetDefPtr net;
+    int pos;
+
+    switch ((virDomainDeviceType) dev->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        disk = dev->data.disk;
+        if (!(orig = virDomainDiskByName(vmdef, disk->dst, false))) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("target %s doesn't exist."), disk->dst);
+            return -1;
+        }
+        if (!(orig->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
+            !(orig->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)) {
+            virReportError(VIR_ERR_INVALID_ARG, "%s",
+                           _("this disk doesn't support update"));
+            return -1;
+        }
+        /*
+         * Update 'orig'
+         * We allow updating src/type//driverType/cachemode/
+         */
+        orig->cachemode = disk->cachemode;
+        orig->startupPolicy = disk->startupPolicy;
+
+        virStorageSourceFree(orig->src);
+        orig->src = disk->src;
+        disk->src = NULL;
+        break;
+
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
+        newGraphics = dev->data.graphics;
+        pos = qemuDomainFindGraphicsIndex(vmdef, newGraphics);
+        if (pos < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("cannot find existing graphics type '%s' device to modify"),
+                           virDomainGraphicsTypeToString(newGraphics->type));
+            return -1;
+        }
+
+        virDomainGraphicsDefFree(vmdef->graphics[pos]);
+
+        vmdef->graphics[pos] = newGraphics;
+        dev->data.graphics = NULL;
+        break;
+
+    case VIR_DOMAIN_DEVICE_NET:
+        net = dev->data.net;
+        if ((pos = virDomainNetFindIdx(vmdef, net)) < 0)
+            return -1;
+
+        virDomainNetDefFree(vmdef->nets[pos]);
+
+        vmdef->nets[pos] = net;
+        dev->data.net = NULL;
+
+        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
+            return -1;
+        break;
+
+    case VIR_DOMAIN_DEVICE_FS:
+    case VIR_DOMAIN_DEVICE_INPUT:
+    case VIR_DOMAIN_DEVICE_SOUND:
+    case VIR_DOMAIN_DEVICE_VIDEO:
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
+    case VIR_DOMAIN_DEVICE_HUB:
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
+    case VIR_DOMAIN_DEVICE_NVRAM:
+    case VIR_DOMAIN_DEVICE_RNG:
+    case VIR_DOMAIN_DEVICE_SHMEM:
+    case VIR_DOMAIN_DEVICE_LEASE:
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
+    case VIR_DOMAIN_DEVICE_CHR:
+    case VIR_DOMAIN_DEVICE_MEMORY:
+    case VIR_DOMAIN_DEVICE_NONE:
+    case VIR_DOMAIN_DEVICE_TPM:
+    case VIR_DOMAIN_DEVICE_PANIC:
+    case VIR_DOMAIN_DEVICE_LAST:
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+                       _("persistent update of device '%s' is not supported"),
+                       virDomainDeviceTypeToString(dev->type));
+        return -1;
+    }
+    return 0;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index dd90e67..82e3308 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -669,4 +669,21 @@ int qemuDomainSecretPrepare(virConnectPtr conn, virDomainObjPtr vm)
 int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
     ATTRIBUTE_NONNULL(1);
 
+int
+qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
+                             virDomainDefPtr vmdef,
+                             virDomainDeviceDefPtr dev,
+                             virConnectPtr conn);
+
+int
+qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
+                             virDomainDeviceDefPtr dev);
+
+
+int
+qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps,
+                             virDomainDefPtr vmdef,
+                             virDomainDeviceDefPtr dev);
+
+
 #endif /* __QEMU_DOMAIN_H__ */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 37d970e..832aa17 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7790,407 +7790,6 @@ qemuDomainUpdateDeviceLive(virConnectPtr conn,
     return ret;
 }
 
-static int
-qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
-                             virDomainDefPtr vmdef,
-                             virDomainDeviceDefPtr dev,
-                             virConnectPtr conn)
-{
-    virDomainDiskDefPtr disk;
-    virDomainNetDefPtr net;
-    virDomainHostdevDefPtr hostdev;
-    virDomainLeaseDefPtr lease;
-    virDomainControllerDefPtr controller;
-    virDomainFSDefPtr fs;
-
-    switch ((virDomainDeviceType) dev->type) {
-    case VIR_DOMAIN_DEVICE_DISK:
-        disk = dev->data.disk;
-        if (virDomainDiskIndexByName(vmdef, disk->dst, true) >= 0) {
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           _("target %s already exists"), disk->dst);
-            return -1;
-        }
-        if (virStorageTranslateDiskSourcePool(conn, disk) < 0)
-            return -1;
-        if (qemuCheckDiskConfig(disk) < 0)
-            return -1;
-        if (virDomainDiskInsert(vmdef, disk))
-            return -1;
-        /* vmdef has the pointer. Generic codes for vmdef will do all jobs */
-        dev->data.disk = NULL;
-        if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO)
-            if (virDomainDefAddImplicitDevices(vmdef) < 0)
-                return -1;
-        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
-            return -1;
-        break;
-
-    case VIR_DOMAIN_DEVICE_NET:
-        net = dev->data.net;
-        if (virDomainNetInsert(vmdef, net))
-            return -1;
-        dev->data.net = NULL;
-        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
-            return -1;
-        break;
-
-    case VIR_DOMAIN_DEVICE_HOSTDEV:
-        hostdev = dev->data.hostdev;
-        if (virDomainHostdevFind(vmdef, hostdev, NULL) >= 0) {
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("device is already in the domain configuration"));
-            return -1;
-        }
-        if (virDomainHostdevInsert(vmdef, hostdev))
-            return -1;
-        dev->data.hostdev = NULL;
-        if (virDomainDefAddImplicitDevices(vmdef) < 0)
-            return -1;
-        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
-            return -1;
-        break;
-
-    case VIR_DOMAIN_DEVICE_LEASE:
-        lease = dev->data.lease;
-        if (virDomainLeaseIndex(vmdef, lease) >= 0) {
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           _("Lease %s in lockspace %s already exists"),
-                           lease->key, NULLSTR(lease->lockspace));
-            return -1;
-        }
-        if (virDomainLeaseInsert(vmdef, lease) < 0)
-            return -1;
-
-        /* vmdef has the pointer. Generic codes for vmdef will do all jobs */
-        dev->data.lease = NULL;
-        break;
-
-    case VIR_DOMAIN_DEVICE_CONTROLLER:
-        controller = dev->data.controller;
-        if (virDomainControllerFind(vmdef, controller->type,
-                                    controller->idx) >= 0) {
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("Target already exists"));
-            return -1;
-        }
-
-        if (virDomainControllerInsert(vmdef, controller) < 0)
-            return -1;
-        dev->data.controller = NULL;
-
-        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
-            return -1;
-        break;
-
-    case VIR_DOMAIN_DEVICE_CHR:
-        if (qemuDomainChrInsert(vmdef, dev->data.chr) < 0)
-            return -1;
-        dev->data.chr = NULL;
-        if (virDomainDefAddImplicitDevices(vmdef) < 0)
-            return -1;
-        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
-            return -1;
-        break;
-
-    case VIR_DOMAIN_DEVICE_FS:
-        fs = dev->data.fs;
-        if (virDomainFSIndexByName(vmdef, fs->dst) >= 0) {
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                         "%s", _("Target already exists"));
-            return -1;
-        }
-
-        if (virDomainFSInsert(vmdef, fs) < 0)
-            return -1;
-        dev->data.fs = NULL;
-        break;
-
-    case VIR_DOMAIN_DEVICE_RNG:
-        if (dev->data.rng->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
-            virDomainDefHasDeviceAddress(vmdef, &dev->data.rng->info)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("a device with the same address already exists "));
-            return -1;
-        }
-
-        if (virDomainRNGInsert(vmdef, dev->data.rng, false) < 0)
-            return -1;
-        dev->data.rng = NULL;
-
-        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
-            return -1;
-        break;
-
-    case VIR_DOMAIN_DEVICE_MEMORY:
-        if (vmdef->nmems == vmdef->mem.memory_slots) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("no free memory device slot available"));
-            return -1;
-        }
-
-        if (vmdef->mem.cur_balloon == virDomainDefGetMemoryActual(vmdef))
-            vmdef->mem.cur_balloon += dev->data.memory->size;
-
-        if (virDomainMemoryInsert(vmdef, dev->data.memory) < 0)
-            return -1;
-        dev->data.memory = NULL;
-        break;
-
-    case VIR_DOMAIN_DEVICE_INPUT:
-    case VIR_DOMAIN_DEVICE_SOUND:
-    case VIR_DOMAIN_DEVICE_VIDEO:
-    case VIR_DOMAIN_DEVICE_WATCHDOG:
-    case VIR_DOMAIN_DEVICE_GRAPHICS:
-    case VIR_DOMAIN_DEVICE_HUB:
-    case VIR_DOMAIN_DEVICE_SMARTCARD:
-    case VIR_DOMAIN_DEVICE_MEMBALLOON:
-    case VIR_DOMAIN_DEVICE_NVRAM:
-    case VIR_DOMAIN_DEVICE_SHMEM:
-    case VIR_DOMAIN_DEVICE_REDIRDEV:
-    case VIR_DOMAIN_DEVICE_NONE:
-    case VIR_DOMAIN_DEVICE_TPM:
-    case VIR_DOMAIN_DEVICE_PANIC:
-    case VIR_DOMAIN_DEVICE_LAST:
-         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
-                        _("persistent attach of device '%s' is not supported"),
-                        virDomainDeviceTypeToString(dev->type));
-         return -1;
-    }
-    return 0;
-}
-
-
-static int
-qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
-                             virDomainDeviceDefPtr dev)
-{
-    virDomainDiskDefPtr disk, det_disk;
-    virDomainNetDefPtr net;
-    virDomainHostdevDefPtr hostdev, det_hostdev;
-    virDomainLeaseDefPtr lease, det_lease;
-    virDomainControllerDefPtr cont, det_cont;
-    virDomainChrDefPtr chr;
-    virDomainFSDefPtr fs;
-    int idx;
-
-    switch ((virDomainDeviceType) dev->type) {
-    case VIR_DOMAIN_DEVICE_DISK:
-        disk = dev->data.disk;
-        if (!(det_disk = virDomainDiskRemoveByName(vmdef, disk->dst))) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("no target device %s"), disk->dst);
-            return -1;
-        }
-        virDomainDiskDefFree(det_disk);
-        break;
-
-    case VIR_DOMAIN_DEVICE_NET:
-        net = dev->data.net;
-        if ((idx = virDomainNetFindIdx(vmdef, net)) < 0)
-            return -1;
-
-        /* this is guaranteed to succeed */
-        virDomainNetDefFree(virDomainNetRemove(vmdef, idx));
-        break;
-
-    case VIR_DOMAIN_DEVICE_HOSTDEV: {
-        hostdev = dev->data.hostdev;
-        if ((idx = virDomainHostdevFind(vmdef, hostdev, &det_hostdev)) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
-                           _("device not present in domain configuration"));
-            return -1;
-        }
-        virDomainHostdevRemove(vmdef, idx);
-        virDomainHostdevDefFree(det_hostdev);
-        break;
-    }
-
-    case VIR_DOMAIN_DEVICE_LEASE:
-        lease = dev->data.lease;
-        if (!(det_lease = virDomainLeaseRemove(vmdef, lease))) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Lease %s in lockspace %s does not exist"),
-                           lease->key, NULLSTR(lease->lockspace));
-            return -1;
-        }
-        virDomainLeaseDefFree(det_lease);
-        break;
-
-    case VIR_DOMAIN_DEVICE_CONTROLLER:
-        cont = dev->data.controller;
-        if ((idx = virDomainControllerFind(vmdef, cont->type,
-                                           cont->idx)) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
-                           _("device not present in domain configuration"));
-            return -1;
-        }
-        det_cont = virDomainControllerRemove(vmdef, idx);
-        virDomainControllerDefFree(det_cont);
-
-        break;
-
-    case VIR_DOMAIN_DEVICE_CHR:
-        if (!(chr = qemuDomainChrRemove(vmdef, dev->data.chr)))
-            return -1;
-
-        virDomainChrDefFree(chr);
-        virDomainChrDefFree(dev->data.chr);
-        dev->data.chr = NULL;
-        break;
-
-    case VIR_DOMAIN_DEVICE_FS:
-        fs = dev->data.fs;
-        idx = virDomainFSIndexByName(vmdef, fs->dst);
-        if (idx < 0) {
-            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                           _("no matching filesystem device was found"));
-            return -1;
-        }
-
-        fs = virDomainFSRemove(vmdef, idx);
-        virDomainFSDefFree(fs);
-        break;
-
-    case VIR_DOMAIN_DEVICE_RNG:
-        if ((idx = virDomainRNGFind(vmdef, dev->data.rng)) < 0) {
-            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                           _("no matching RNG device was found"));
-            return -1;
-        }
-
-        virDomainRNGDefFree(virDomainRNGRemove(vmdef, idx));
-        break;
-
-    case VIR_DOMAIN_DEVICE_MEMORY:
-        if ((idx = virDomainMemoryFindInactiveByDef(vmdef,
-                                                    dev->data.memory)) < 0) {
-            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                           _("matching memory device was not found"));
-            return -1;
-        }
-
-        virDomainMemoryDefFree(virDomainMemoryRemove(vmdef, idx));
-        break;
-
-    case VIR_DOMAIN_DEVICE_INPUT:
-    case VIR_DOMAIN_DEVICE_SOUND:
-    case VIR_DOMAIN_DEVICE_VIDEO:
-    case VIR_DOMAIN_DEVICE_WATCHDOG:
-    case VIR_DOMAIN_DEVICE_GRAPHICS:
-    case VIR_DOMAIN_DEVICE_HUB:
-    case VIR_DOMAIN_DEVICE_SMARTCARD:
-    case VIR_DOMAIN_DEVICE_MEMBALLOON:
-    case VIR_DOMAIN_DEVICE_NVRAM:
-    case VIR_DOMAIN_DEVICE_SHMEM:
-    case VIR_DOMAIN_DEVICE_REDIRDEV:
-    case VIR_DOMAIN_DEVICE_NONE:
-    case VIR_DOMAIN_DEVICE_TPM:
-    case VIR_DOMAIN_DEVICE_PANIC:
-    case VIR_DOMAIN_DEVICE_LAST:
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
-                       _("persistent detach of device '%s' is not supported"),
-                       virDomainDeviceTypeToString(dev->type));
-        return -1;
-    }
-    return 0;
-}
-
-static int
-qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps,
-                             virDomainDefPtr vmdef,
-                             virDomainDeviceDefPtr dev)
-{
-    virDomainDiskDefPtr orig, disk;
-    virDomainGraphicsDefPtr newGraphics;
-    virDomainNetDefPtr net;
-    int pos;
-
-    switch ((virDomainDeviceType) dev->type) {
-    case VIR_DOMAIN_DEVICE_DISK:
-        disk = dev->data.disk;
-        if (!(orig = virDomainDiskByName(vmdef, disk->dst, false))) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("target %s doesn't exist."), disk->dst);
-            return -1;
-        }
-        if (!(orig->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
-            !(orig->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)) {
-            virReportError(VIR_ERR_INVALID_ARG, "%s",
-                           _("this disk doesn't support update"));
-            return -1;
-        }
-        /*
-         * Update 'orig'
-         * We allow updating src/type//driverType/cachemode/
-         */
-        orig->cachemode = disk->cachemode;
-        orig->startupPolicy = disk->startupPolicy;
-
-        virStorageSourceFree(orig->src);
-        orig->src = disk->src;
-        disk->src = NULL;
-        break;
-
-    case VIR_DOMAIN_DEVICE_GRAPHICS:
-        newGraphics = dev->data.graphics;
-        pos = qemuDomainFindGraphicsIndex(vmdef, newGraphics);
-        if (pos < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("cannot find existing graphics type '%s' device to modify"),
-                           virDomainGraphicsTypeToString(newGraphics->type));
-            return -1;
-        }
-
-        virDomainGraphicsDefFree(vmdef->graphics[pos]);
-
-        vmdef->graphics[pos] = newGraphics;
-        dev->data.graphics = NULL;
-        break;
-
-    case VIR_DOMAIN_DEVICE_NET:
-        net = dev->data.net;
-        if ((pos = virDomainNetFindIdx(vmdef, net)) < 0)
-            return -1;
-
-        virDomainNetDefFree(vmdef->nets[pos]);
-
-        vmdef->nets[pos] = net;
-        dev->data.net = NULL;
-
-        if (qemuDomainAssignAddresses(vmdef, qemuCaps, NULL) < 0)
-            return -1;
-        break;
-
-    case VIR_DOMAIN_DEVICE_FS:
-    case VIR_DOMAIN_DEVICE_INPUT:
-    case VIR_DOMAIN_DEVICE_SOUND:
-    case VIR_DOMAIN_DEVICE_VIDEO:
-    case VIR_DOMAIN_DEVICE_WATCHDOG:
-    case VIR_DOMAIN_DEVICE_HUB:
-    case VIR_DOMAIN_DEVICE_SMARTCARD:
-    case VIR_DOMAIN_DEVICE_MEMBALLOON:
-    case VIR_DOMAIN_DEVICE_NVRAM:
-    case VIR_DOMAIN_DEVICE_RNG:
-    case VIR_DOMAIN_DEVICE_SHMEM:
-    case VIR_DOMAIN_DEVICE_LEASE:
-    case VIR_DOMAIN_DEVICE_HOSTDEV:
-    case VIR_DOMAIN_DEVICE_CONTROLLER:
-    case VIR_DOMAIN_DEVICE_REDIRDEV:
-    case VIR_DOMAIN_DEVICE_CHR:
-    case VIR_DOMAIN_DEVICE_MEMORY:
-    case VIR_DOMAIN_DEVICE_NONE:
-    case VIR_DOMAIN_DEVICE_TPM:
-    case VIR_DOMAIN_DEVICE_PANIC:
-    case VIR_DOMAIN_DEVICE_LAST:
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
-                       _("persistent update of device '%s' is not supported"),
-                       virDomainDeviceTypeToString(dev->type));
-        return -1;
-    }
-    return 0;
-}
-
 
 static int qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
                                        unsigned int flags)


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