[libvirt PATCH] qemu: do not attempt to pass unopened vsock FD

Ján Tomko posted 1 patch 1 year, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/4161066b9f452660cefb28f81fb0d02383e984a3.1666275909.git.jtomko@redhat.com
src/qemu/qemu_command.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[libvirt PATCH] qemu: do not attempt to pass unopened vsock FD
Posted by Ján Tomko 1 year, 5 months ago
On normal vm startup, we open a file descriptor
for the vsock device in qemuProcessPrepareHost.

However, when doing domxml-to-native, no file descriptors are open.

Only pass the fd if it's not -1, to make domxml-to-native work.

https://bugzilla.redhat.com/show_bug.cgi?id=1777212

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
Technically a v2 of:
https://listman.redhat.com/archives/libvir-list/2021-July/msg00803.html

I did not look at other cases, but IIRC the ones converted to use qemuFD*
wrappers should handle missing FDs gracefully.

 src/qemu/qemu_command.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 150824f2e1..bbbde57c0f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9717,7 +9717,8 @@ qemuBuildVsockCommandLine(virCommand *cmd,
     if (!(devprops = qemuBuildVsockDevProps(def, vsock, qemuCaps, "")))
         return -1;
 
-    virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
+    if (priv->vhostfd != -1)
+        virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
     priv->vhostfd = -1;
 
     if (qemuCommandAddExtDevice(cmd, &vsock->info, def, qemuCaps) < 0)
-- 
2.37.3

Re: [libvirt PATCH] qemu: do not attempt to pass unopened vsock FD
Posted by Peter Krempa 1 year, 5 months ago
On Thu, Oct 20, 2022 at 16:27:45 +0200, Ján Tomko wrote:
> On normal vm startup, we open a file descriptor
> for the vsock device in qemuProcessPrepareHost.
> 
> However, when doing domxml-to-native, no file descriptors are open.
> 
> Only pass the fd if it's not -1, to make domxml-to-native work.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1777212
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
> Technically a v2 of:
> https://listman.redhat.com/archives/libvir-list/2021-July/msg00803.html
> 
> I did not look at other cases, but IIRC the ones converted to use qemuFD*
> wrappers should handle missing FDs gracefully.
> 
>  src/qemu/qemu_command.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 150824f2e1..bbbde57c0f 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -9717,7 +9717,8 @@ qemuBuildVsockCommandLine(virCommand *cmd,
>      if (!(devprops = qemuBuildVsockDevProps(def, vsock, qemuCaps, "")))
>          return -1;
>  
> -    virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
> +    if (priv->vhostfd != -1)
> +        virCommandPassFD(cmd, priv->vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
>      priv->vhostfd = -1;

In 'qemuBuildVsockDevProps' the 'fd' field is formated via '%u'. Please
change it to '%d' to go along with this patch.

>  
>      if (qemuCommandAddExtDevice(cmd, &vsock->info, def, qemuCaps) < 0)
> -- 
> 2.37.3

Reviewed-by: Peter Krempa <pkrempa@redhat.com>