qemu: Create NVMe disk in domain namespace
If a domain has an NVMe disk configured, then we need to create /dev/vfio/* paths in domain's namespace so that qemu can open them. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
d3f06dcdb5
commit
a80ebd2a2a
@ -14391,9 +14391,21 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED,
|
|||||||
{
|
{
|
||||||
virStorageSourcePtr next;
|
virStorageSourcePtr next;
|
||||||
char *dst = NULL;
|
char *dst = NULL;
|
||||||
|
bool hasNVMe = false;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
for (next = disk->src; virStorageSourceIsBacking(next); next = next->backingStore) {
|
for (next = disk->src; virStorageSourceIsBacking(next); next = next->backingStore) {
|
||||||
|
if (next->type == VIR_STORAGE_TYPE_NVME) {
|
||||||
|
g_autofree char *nvmePath = NULL;
|
||||||
|
|
||||||
|
hasNVMe = true;
|
||||||
|
|
||||||
|
if (!(nvmePath = virPCIDeviceAddressGetIOMMUGroupDev(&next->nvme->pciAddr)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (qemuDomainCreateDevice(nvmePath, data, false) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
if (!next->path || !virStorageSourceIsLocalStorage(next)) {
|
if (!next->path || !virStorageSourceIsLocalStorage(next)) {
|
||||||
/* Not creating device. Just continue. */
|
/* Not creating device. Just continue. */
|
||||||
continue;
|
continue;
|
||||||
@ -14402,12 +14414,17 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED,
|
|||||||
if (qemuDomainCreateDevice(next->path, data, false) < 0)
|
if (qemuDomainCreateDevice(next->path, data, false) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* qemu-pr-helper might require access to /dev/mapper/control. */
|
/* qemu-pr-helper might require access to /dev/mapper/control. */
|
||||||
if (disk->src->pr &&
|
if (disk->src->pr &&
|
||||||
qemuDomainCreateDevice(QEMU_DEVICE_MAPPER_CONTROL_PATH, data, true) < 0)
|
qemuDomainCreateDevice(QEMU_DEVICE_MAPPER_CONTROL_PATH, data, true) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (hasNVMe &&
|
||||||
|
qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(dst);
|
VIR_FREE(dst);
|
||||||
@ -15422,19 +15439,32 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm,
|
|||||||
virStorageSourcePtr src)
|
virStorageSourcePtr src)
|
||||||
{
|
{
|
||||||
virStorageSourcePtr next;
|
virStorageSourcePtr next;
|
||||||
const char **paths = NULL;
|
char **paths = NULL;
|
||||||
size_t npaths = 0;
|
size_t npaths = 0;
|
||||||
char *dmPath = NULL;
|
bool hasNVMe = false;
|
||||||
|
g_autofree char *dmPath = NULL;
|
||||||
|
g_autofree char *vfioPath = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
for (next = src; virStorageSourceIsBacking(next); next = next->backingStore) {
|
for (next = src; virStorageSourceIsBacking(next); next = next->backingStore) {
|
||||||
|
g_autofree char *tmpPath = NULL;
|
||||||
|
|
||||||
|
if (next->type == VIR_STORAGE_TYPE_NVME) {
|
||||||
|
hasNVMe = true;
|
||||||
|
|
||||||
|
if (!(tmpPath = virPCIDeviceAddressGetIOMMUGroupDev(&next->nvme->pciAddr)))
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
if (virStorageSourceIsEmpty(next) ||
|
if (virStorageSourceIsEmpty(next) ||
|
||||||
!virStorageSourceIsLocalStorage(next)) {
|
!virStorageSourceIsLocalStorage(next)) {
|
||||||
/* Not creating device. Just continue. */
|
/* Not creating device. Just continue. */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT_COPY(paths, npaths, next->path) < 0)
|
tmpPath = g_strdup(next->path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_APPEND_ELEMENT(paths, npaths, tmpPath) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15445,13 +15475,18 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuDomainNamespaceMknodPaths(vm, paths, npaths) < 0)
|
if (hasNVMe) {
|
||||||
|
vfioPath = g_strdup(QEMU_DEV_VFIO);
|
||||||
|
if (VIR_APPEND_ELEMENT(paths, npaths, vfioPath) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemuDomainNamespaceMknodPaths(vm, (const char **) paths, npaths) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(dmPath);
|
virStringListFreeCount(paths, npaths);
|
||||||
VIR_FREE(paths);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user