1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

qemu: Namespaces for NVDIMM

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2017-02-22 17:37:39 +01:00
parent 6e95abb446
commit 7b89f857d9
3 changed files with 95 additions and 0 deletions

View File

@ -7542,6 +7542,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->nvdimmPath, 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,
@ -7797,6 +7828,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;
@ -8282,6 +8316,48 @@ qemuDomainNamespaceTeardownHostdev(virQEMUDriverPtr driver,
}
int
qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainMemoryDefPtr mem)
{
int ret = -1;
if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM)
return 0;
if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
return 0;
if (qemuDomainAttachDeviceMknod(driver, vm, mem->nvdimmPath) < 0)
goto cleanup;
ret = 0;
cleanup:
return ret;
}
int
qemuDomainNamespaceTeardownMemory(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainMemoryDefPtr mem)
{
int ret = -1;
if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM)
return 0;
if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
return 0;
if (qemuDomainDetachDeviceUnlink(driver, vm, mem->nvdimmPath) < 0)
goto cleanup;
ret = 0;
cleanup:
return ret;
}
int
qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
virDomainObjPtr vm,

View File

@ -837,6 +837,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);

View File

@ -2217,6 +2217,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
bool objAdded = false;
bool teardownlabel = false;
bool teardowncgroup = false;
bool teardowndevice = false;
virJSONValuePtr props = NULL;
virObjectEventPtr event;
int id;
@ -2246,6 +2247,10 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
priv->qemuCaps, vm->def, mem, NULL, true) < 0)
goto cleanup;
if (qemuDomainNamespaceSetupMemory(driver, vm, mem) < 0)
goto cleanup;
teardowndevice = true;
if (qemuSetupMemoryDevicesCgroup(vm, mem) < 0)
goto cleanup;
teardowncgroup = true;
@ -2299,6 +2304,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");
}
virJSONValueFree(props);
@ -3768,6 +3776,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 */