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

[libvirt] [PATCH 14/14] qemu: Namespaces for NVDIMM



Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 src/qemu/qemu_domain.c  | 76 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h  |  8 ++++++
 src/qemu/qemu_hotplug.c | 11 +++++++
 3 files changed, 95 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f585e6f25..1f6627005 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7478,6 +7478,37 @@ qemuDomainSetupAllHostdevs(virQEMUDriverConfigPtr cfg,
 }
 
 
+static int
+qemuDomainSetupMemory(virQEMUDriverConfigPtr cfg ATTRIBUTE_UNUSED,
+                      virDomainMemoryDefPtr mem,
+                      const char *devPath)
+{
+    if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM)
+        return 0;
+
+    return qemuDomainCreateDevice(mem->path, devPath, false);
+}
+
+
+static int
+qemuDomainSetupAllMemories(virQEMUDriverConfigPtr cfg,
+                           virDomainObjPtr vm,
+                           const char *devPath)
+{
+    size_t i;
+
+    VIR_DEBUG("Setting up memories");
+    for (i = 0; i < vm->def->nmems; i++) {
+        if (qemuDomainSetupMemory(cfg,
+                                  vm->def->mems[i],
+                                  devPath) < 0)
+            return -1;
+    }
+    VIR_DEBUG("Setup all memories");
+    return 0;
+}
+
+
 static int
 qemuDomainSetupChardev(virDomainDefPtr def ATTRIBUTE_UNUSED,
                        virDomainChrDefPtr dev,
@@ -7722,6 +7753,9 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
     if (qemuDomainSetupAllHostdevs(cfg, vm, devPath) < 0)
         goto cleanup;
 
+    if (qemuDomainSetupAllMemories(cfg, vm, devPath) < 0)
+        goto cleanup;
+
     if (qemuDomainSetupAllChardevs(cfg, vm, devPath) < 0)
         goto cleanup;
 
@@ -8180,6 +8214,48 @@ qemuDomainNamespaceTeardownHostdev(virQEMUDriverPtr driver,
 }
 
 
+int
+qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver,
+                               virDomainObjPtr vm,
+                               virDomainMemoryDefPtr mem)
+{
+    int ret = -1;
+
+    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
+        return 0;
+
+    if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM)
+        return 0;
+
+    if (qemuDomainAttachDeviceMknod(driver, vm, mem->path) < 0)
+        goto cleanup;
+    ret = 0;
+ cleanup:
+    return ret;
+}
+
+
+int
+qemuDomainNamespaceTeardownMemory(virQEMUDriverPtr driver,
+                                  virDomainObjPtr vm,
+                                  virDomainMemoryDefPtr mem)
+{
+    int ret = -1;
+
+    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
+        return 0;
+
+    if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM)
+        return 0;
+
+    if (qemuDomainDetachDeviceUnlink(driver, vm, mem->path) < 0)
+        goto cleanup;
+    ret = 0;
+ cleanup:
+    return ret;
+}
+
+
 int
 qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 72efa3336..2c4ba487a 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -834,6 +834,14 @@ int qemuDomainNamespaceTeardownHostdev(virQEMUDriverPtr driver,
                                        virDomainObjPtr vm,
                                        virDomainHostdevDefPtr hostdev);
 
+int qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver,
+                                   virDomainObjPtr vm,
+                                   virDomainMemoryDefPtr memory);
+
+int qemuDomainNamespaceTeardownMemory(virQEMUDriverPtr driver,
+                                      virDomainObjPtr vm,
+                                      virDomainMemoryDefPtr memory);
+
 int qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     virDomainChrDefPtr chr);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e821596bf..1f85b154d 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2193,6 +2193,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
     bool objAdded = false;
     bool teardownlabel = false;
     bool teardowncgroup = false;
+    bool teardowndevice = false;
     virJSONValuePtr props = NULL;
     virObjectEventPtr event;
     int id;
@@ -2234,6 +2235,10 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
         goto removedef;
     }
 
+    if (qemuDomainNamespaceSetupMemory(driver, vm, mem) < 0)
+        goto removedef;
+    teardowndevice = true;
+
     if (qemuSetupMemoryDevicesCgroup(vm, mem) < 0)
         goto removedef;
     teardowncgroup = true;
@@ -2281,6 +2286,9 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
             VIR_WARN("Unable to remove memory device cgroup ACL on hotplug fail");
         if (teardownlabel && qemuSecurityRestoreMemoryLabel(driver, vm, mem) < 0)
             VIR_WARN("Unable to restore security label on memdev");
+        if (teardowndevice &&
+            qemuDomainNamespaceTeardownMemory(driver, vm, mem) <  0)
+            VIR_WARN("Unable to remove memory device from /dev");
     }
 
     virObjectUnref(cfg);
@@ -3749,6 +3757,9 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
     if (qemuTeardownMemoryDevicesCgroup(vm, mem) < 0)
         VIR_WARN("Unable to remove memory device cgroup ACL");
 
+    if (qemuDomainNamespaceTeardownMemory(driver, vm, mem) <  0)
+        VIR_WARN("Unable to remove memory device from /dev");
+
     virDomainMemoryDefFree(mem);
 
     /* fix the balloon size */
-- 
2.11.0


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