[libvirt] [PATCH] qemu_domain: Drop namespace check from top level functions

Michal Privoznik posted 1 patch 5 years, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/a74d9befc716bd7a84d454e0abba524575c76a9e.1536321954.git.mprivozn@redhat.com
Test syntax-check passed
src/qemu/qemu_domain.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
[libvirt] [PATCH] qemu_domain: Drop namespace check from top level functions
Posted by Michal Privoznik 5 years, 7 months ago
In some cases we are checking if the mount namespace is enabled
at two places: one is at the beginning of exported function (e.g.
qemuDomainNamespaceSetupDisk()) and the other is at the beginning
of qemuDomainNamespaceMknodPaths() which is called from the
former function anyway. Then we have some other functions which
rely on the later check solely.

In order to compensate for possibly needles function call,
qemuDomainNamespaceMknodPaths() returns early if @npaths is zero.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 5329899b13..15325aa4c1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -12428,7 +12428,8 @@ qemuDomainNamespaceMknodPaths(virDomainObjPtr vm,
     int ret = -1;
     size_t i;
 
-    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
+    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT) ||
+        !npaths)
         return 0;
 
     cfg = virQEMUDriverGetConfig(driver);
@@ -12521,9 +12522,6 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm,
     char *dmPath = NULL;
     int ret = -1;
 
-    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
-        return 0;
-
     for (next = src; virStorageSourceIsBacking(next); next = next->backingStore) {
         if (virStorageSourceIsEmpty(next) ||
             !virStorageSourceIsLocalStorage(next)) {
@@ -12574,9 +12572,6 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm,
     char **paths = NULL;
     size_t i, npaths = 0;
 
-    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
-        return 0;
-
     if (qemuDomainGetHostdevPath(NULL, hostdev, false, &npaths, &paths, NULL) < 0)
         goto cleanup;
 
@@ -12600,9 +12595,6 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm,
     char **paths = NULL;
     size_t i, npaths = 0;
 
-    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
-        return 0;
-
     if (qemuDomainGetHostdevPath(vm->def, hostdev, true,
                                  &npaths, &paths, NULL) < 0)
         goto cleanup;
-- 
2.16.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu_domain: Drop namespace check from top level functions
Posted by John Ferlan 5 years, 7 months ago

On 09/07/2018 08:05 AM, Michal Privoznik wrote:
> In some cases we are checking if the mount namespace is enabled
> at two places: one is at the beginning of exported function (e.g.
> qemuDomainNamespaceSetupDisk()) and the other is at the beginning
> of qemuDomainNamespaceMknodPaths() which is called from the
> former function anyway. Then we have some other functions which
> rely on the later check solely.
> 
> In order to compensate for possibly needles function call,

needless

> qemuDomainNamespaceMknodPaths() returns early if @npaths is zero.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_domain.c | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 

Even though my personal preference for npaths == 0, what's here is
consistent with the same check in qemuDomainNamespaceUnlinkPaths.

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list