[PATCH] qemuNamespaceMknodPaths: Don't fork needlessly

Michal Privoznik posted 1 patch 1 year, 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/b5e1c36337af7a9d93e5fb2ef6c1e1cb6faae740.1664451488.git.mprivozn@redhat.com
src/qemu/qemu_namespace.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] qemuNamespaceMknodPaths: Don't fork needlessly
Posted by Michal Privoznik 1 year, 7 months ago
The qemuNamespaceMknodPaths() function is responsible for
creating files/directories in QEMU's mount namespace. When
called, it is given list of paths that have to be created in the
namespace. It processes this list and removes items that are not
directly under /dev, but on a 'shared' filesystem (note that all
other mount points are preserved). And it may so happen that
after this pre-process no files/directories need to be created in
the namespace. If that's the case, exit early and avoid
fork()-ing only to find out the same.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_namespace.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c
index 09e235e120..a2c31310d9 100644
--- a/src/qemu/qemu_namespace.c
+++ b/src/qemu/qemu_namespace.c
@@ -1293,6 +1293,9 @@ qemuNamespaceMknodPaths(virDomainObj *vm,
             goto cleanup;
     }
 
+    if (data.nitems == 0)
+        return 0;
+
     for (i = 0; i < data.nitems; i++) {
         qemuNamespaceMknodItem *item = &data.items[i];
         if (item->target &&
-- 
2.35.1
Re: [PATCH] qemuNamespaceMknodPaths: Don't fork needlessly
Posted by Ján Tomko 1 year, 7 months ago
On a Thursday in 2022, Michal Privoznik wrote:
>The qemuNamespaceMknodPaths() function is responsible for
>creating files/directories in QEMU's mount namespace. When
>called, it is given list of paths that have to be created in the
>namespace. It processes this list and removes items that are not
>directly under /dev, but on a 'shared' filesystem (note that all
>other mount points are preserved). And it may so happen that
>after this pre-process no files/directories need to be created in
>the namespace. If that's the case, exit early and avoid
>fork()-ing only to find out the same.
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/qemu/qemu_namespace.c | 3 +++
> 1 file changed, 3 insertions(+)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano