[PATCH 08/10] qemu: Implement share memory device hot-plug

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

 



Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c  | 10 ++++++++-
 src/qemu/qemu_hotplug.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_hotplug.h |  3 +++
 3 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 932928f..b5a0be0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7789,6 +7789,15 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm,
         dev->data.memory = NULL;
         break;
 
+    case VIR_DOMAIN_DEVICE_SHMEM:
+        ret = qemuDomainAttachShmemDevice(driver, vm,
+                                          dev->data.shmem);
+        if (!ret) {
+            alias = dev->data.shmem->info.alias;
+            dev->data.shmem = NULL;
+        }
+        break;
+
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_FS:
     case VIR_DOMAIN_DEVICE_INPUT:
@@ -7800,7 +7809,6 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm,
     case VIR_DOMAIN_DEVICE_SMARTCARD:
     case VIR_DOMAIN_DEVICE_MEMBALLOON:
     case VIR_DOMAIN_DEVICE_NVRAM:
-    case VIR_DOMAIN_DEVICE_SHMEM:
     case VIR_DOMAIN_DEVICE_TPM:
     case VIR_DOMAIN_DEVICE_PANIC:
     case VIR_DOMAIN_DEVICE_LAST:
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index cc86a3b..188807e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1832,6 +1832,66 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
 }
 
 
+int
+qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
+                            virDomainObjPtr vm,
+                            virDomainShmemDefPtr shmem)
+{
+    int ret = -1;
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    char *devstr = NULL;
+    char *charAlias = NULL;
+
+    if (virAsprintf(&shmem->info.alias, "shmem%zu", vm->def->nshmems) < 0)
+        return -1;
+
+    if (VIR_REALLOC_N(vm->def->shmems, vm->def->nshmems + 1) < 0)
+        return -1;
+
+    if ((shmem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
+         shmem->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) &&
+         (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &shmem->info) < 0))
+        return -1;
+
+    if (!(devstr = qemuBuildShmemDevStr(vm->def, shmem, priv->qemuCaps)))
+        goto cleanup;
+
+    if (virAsprintf(&charAlias, "char%s", shmem->info.alias) < 0)
+        goto cleanup;
+
+    qemuDomainObjEnterMonitor(driver, vm);
+
+    if (shmem->server.enabled &&
+        qemuMonitorAttachCharDev(priv->mon, charAlias,
+                                 &shmem->server.chr) < 0) {
+        ignore_value(qemuDomainObjExitMonitor(driver, vm));
+        goto audit;
+    }
+
+    if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
+        if (shmem->server.enabled)
+            ignore_value(qemuMonitorDetachCharDev(priv->mon, charAlias));
+        ignore_value(qemuDomainObjExitMonitor(driver, vm));
+        goto audit;
+    }
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        goto audit;
+
+    if (virDomainShmemInsert(vm->def, shmem) < 0)
+        goto audit;
+
+    ret = 0;
+ audit:
+    virDomainAuditShmem(vm, NULL, shmem, "attach", ret == 0);
+ cleanup:
+    if (ret < 0)
+        qemuDomainReleaseDeviceAddress(vm, &shmem->info, NULL);
+    VIR_FREE(charAlias);
+    VIR_FREE(devstr);
+    return ret;
+}
+
+
 static int
 qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 4140da3..60137a6 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -109,6 +109,9 @@ int qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
 int qemuDomainDetachRNGDevice(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               virDomainRNGDefPtr rng);
+int qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
+                                virDomainObjPtr vm,
+                                virDomainShmemDefPtr shmem);
 
 int
 qemuDomainChrInsert(virDomainDefPtr vmdef,
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]