Functions that create a device node after domain startup (used from hotplug) will get a list of paths they want to create and eventually call qemuDomainNamespaceMknodPaths() which then checks whether domain mount namespace is enabled in the first place. Alternatively, on device hotunplug, we might want to delete a path inside domain namespace in which case qemuDomainNamespaceUnlinkPaths() checks whether the namespace is enabled. While this is not dangerous, it certainly burns a couple of CPU cycles needlessly. Check whether mount namespace is enabled upfront. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_domain_namespace.c | 39 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_domain_namespace.c b/src/qemu/qemu_domain_namespace.c index 6d8faa79fb..41451bec9f 100644 --- a/src/qemu/qemu_domain_namespace.c +++ b/src/qemu/qemu_domain_namespace.c @@ -1481,8 +1481,7 @@ qemuDomainNamespaceMknodPaths(virDomainObjPtr vm, int ret = -1; size_t i; - if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT) || - !npaths) + if (!npaths) return 0; cfg = virQEMUDriverGetConfig(driver); @@ -1529,8 +1528,7 @@ qemuDomainNamespaceUnlinkPaths(virDomainObjPtr vm, size_t i; int ret = -1; - if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT) || - !npaths) + if (!npaths) return 0; cfg = virQEMUDriverGetConfig(driver); @@ -1572,6 +1570,9 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, size_t npaths = 0; bool hasNVMe = false; + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + for (next = src; virStorageSourceIsBacking(next); next = next->backingStore) { g_autofree char *tmpPath = NULL; @@ -1655,6 +1656,9 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, { g_autofree char *path = NULL; + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) return -1; @@ -1687,6 +1691,9 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm, { g_autofree char *path = NULL; + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) return -1; @@ -1706,6 +1713,9 @@ int qemuDomainNamespaceSetupMemory(virDomainObjPtr vm, virDomainMemoryDefPtr mem) { + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM) return 0; @@ -1720,6 +1730,9 @@ int qemuDomainNamespaceTeardownMemory(virDomainObjPtr vm, virDomainMemoryDefPtr mem) { + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM) return 0; @@ -1736,6 +1749,9 @@ qemuDomainNamespaceSetupChardev(virDomainObjPtr vm, { const char *path; + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + if (!(path = virDomainChrSourceDefGetPath(chr->source))) return 0; @@ -1757,6 +1773,9 @@ qemuDomainNamespaceTeardownChardev(virDomainObjPtr vm, { const char *path = NULL; + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + if (chr->source->type != VIR_DOMAIN_CHR_TYPE_DEV) return 0; @@ -1775,6 +1794,9 @@ qemuDomainNamespaceSetupRNG(virDomainObjPtr vm, { const char *path = NULL; + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + switch ((virDomainRNGBackend) rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: path = rng->source.file; @@ -1799,6 +1821,9 @@ qemuDomainNamespaceTeardownRNG(virDomainObjPtr vm, { const char *path = NULL; + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + switch ((virDomainRNGBackend) rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: path = rng->source.file; @@ -1823,6 +1848,9 @@ qemuDomainNamespaceSetupInput(virDomainObjPtr vm, { const char *path = NULL; + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + if (!(path = virDomainInputDefGetPath(input))) return 0; @@ -1838,6 +1866,9 @@ qemuDomainNamespaceTeardownInput(virDomainObjPtr vm, { const char *path = NULL; + if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) + return 0; + if (!(path = virDomainInputDefGetPath(input))) return 0; -- 2.26.2