Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_domain.c | 58 +++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_hostdev.c | 22 ++++++++++++++++
src/qemu/qemu_hostdev.h | 6 +++++
3 files changed, 86 insertions(+)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3fe0004cab..cb94840d5f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -10537,6 +10537,54 @@ typedef enum {
} qemuDomainStorageSourceAccessFlags;
+static int
+qemuDomainStorageSourceAccessModifyNVMe(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virStorageSourcePtr src,
+ bool revoke)
+{
+ bool revoke_maxmemlock = false;
+ bool revoke_hostdev = false;
+ int ret = -1;
+
+ if (!virStorageSourceChainHasNVMe(src))
+ return 0;
+
+ VIR_DEBUG("Modifying access for a NVMe disk src=%p revoke=%d",
+ src, revoke);
+
+ if (revoke) {
+ revoke_maxmemlock = true;
+ revoke_hostdev = true;
+ ret = 0;
+ goto revoke;
+ }
+
+ if (qemuDomainAdjustMaxMemLock(vm, true) < 0)
+ goto revoke;
+
+ revoke_maxmemlock = true;
+
+ if (qemuHostdevPrepareOneNVMeDisk(driver, vm->def->name, src) < 0)
+ goto revoke;
+
+ revoke_hostdev = true;
+
+ return 0;
+
+ revoke:
+ if (revoke_maxmemlock) {
+ if (qemuDomainAdjustMaxMemLock(vm, false) < 0)
+ VIR_WARN("Unable to change max memlock limit");
+ }
+
+ if (revoke_hostdev)
+ qemuHostdevReAttachOneNVMeDisk(driver, vm->def->name, src);
+
+ return ret;
+}
+
+
/**
* qemuDomainStorageSourceAccessModify:
* @driver: qemu driver struct
@@ -10568,6 +10616,7 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPtr driver,
bool revoke_cgroup = false;
bool revoke_label = false;
bool revoke_namespace = false;
+ bool revoke_nvme = false;
bool revoke_lockspace = false;
VIR_DEBUG("src='%s' readonly=%d force_ro=%d force_rw=%d revoke=%d
chain=%d",
@@ -10585,6 +10634,7 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPtr driver,
revoke_cgroup = true;
revoke_label = true;
revoke_namespace = true;
+ revoke_nvme = true;
revoke_lockspace = true;
ret = 0;
goto revoke;
@@ -10595,6 +10645,11 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPtr driver,
revoke_lockspace = true;
+ if (qemuDomainStorageSourceAccessModifyNVMe(driver, vm, src, false) < 0)
+ goto revoke;
+
+ revoke_nvme = true;
+
/* When modifying access of existing @src namespace does not need update */
if (!(flags & QEMU_DOMAIN_STORAGE_SOURCE_ACCESS_MODIFY_ACCESS)) {
if (qemuDomainNamespaceSetupDisk(vm, src) < 0)
@@ -10645,6 +10700,9 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPtr driver,
VIR_WARN("Unable to remove /dev entry for %s", srcstr);
}
+ if (revoke_nvme)
+ qemuDomainStorageSourceAccessModifyNVMe(driver, vm, src, true);
+
if (revoke_lockspace) {
if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0)
VIR_WARN("Unable to release lock on %s", srcstr);
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 5ab0217858..6ab052724a 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -212,6 +212,17 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDefPtr
*hostdevs,
return true;
}
+int
+qemuHostdevPrepareOneNVMeDisk(virQEMUDriverPtr driver,
+ const char *name,
+ virStorageSourcePtr src)
+{
+ return virHostdevPrepareOneNVMeDevice(driver->hostdevMgr,
+ QEMU_DRIVER_NAME,
+ name,
+ src);
+}
+
int
qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver,
const char *name,
@@ -369,6 +380,17 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
return 0;
}
+void
+qemuHostdevReAttachOneNVMeDisk(virQEMUDriverPtr driver,
+ const char *name,
+ virStorageSourcePtr src)
+{
+ virHostdevReAttachOneNVMeDevice(driver->hostdevMgr,
+ QEMU_DRIVER_NAME,
+ name,
+ src);
+}
+
void
qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver,
const char *name,
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 735414b6aa..23df925529 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -41,6 +41,9 @@ int qemuHostdevUpdateActiveSCSIDevices(virQEMUDriverPtr driver,
int qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver,
virDomainDefPtr def);
+int qemuHostdevPrepareOneNVMeDisk(virQEMUDriverPtr driver,
+ const char *name,
+ virStorageSourcePtr src);
int qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver,
const char *name,
virDomainDiskDefPtr *disks,
@@ -74,6 +77,9 @@ int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
virQEMUCapsPtr qemuCaps,
unsigned int flags);
+void qemuHostdevReAttachOneNVMeDisk(virQEMUDriverPtr driver,
+ const char *name,
+ virStorageSourcePtr src);
void qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver,
const char *name,
virDomainDiskDefPtr *disks,
--
2.21.0