Skip to contentSkip to conversation

add a qemu-ifup script on NetBSD

PATCH In review Manuel Bouyer 5 participants 14 messages Feb 3, 2021 – Feb 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add a qemu-ifup script on NetBSD

On NetBSD, qemu-xen will use a qemu-ifup script to setup the tap interfaces (as qemu-xen-traditional used to). Copy the script from qemu-xen-traditional, and install it on NetBSD. While there document parameters and environnement variables.

---
 tools/hotplug/NetBSD/Makefile  | 1 +
 tools/hotplug/NetBSD/qemu-ifup | 9 +++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 tools/hotplug/NetBSD/qemu-ifup
tools/hotplug/NetBSD/Makefile +1 -0
index 114b223207..f909ffa367 100644
@@ -7,6 +7,7 @@ XEN_SCRIPTS += locking.sh
 XEN_SCRIPTS += block
 XEN_SCRIPTS += vif-bridge
 XEN_SCRIPTS += vif-ip
+XEN_SCRIPTS += qemu-ifup
 
 XEN_SCRIPT_DATA =
 XEN_RCD_PROG = rc.d/xencommons rc.d/xendomains rc.d/xen-watchdog rc.d/xendriverdomain
tools/hotplug/NetBSD/qemu-ifup new file +9 -0
new file mode 100644
index 0000000000..4305419f44
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+#called by qemu when a HVM domU is started.
+# first parameter is tap interface, second is the bridge name
+# environement variable $XEN_DOMAIN_ID contains the domU's ID,
+# which can be used to retrieve extra parameters from the xenstore.
+
+ifconfig $1 up
+exec /sbin/brconfig $2 add $1
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/1 xenstored: close socket connections on error

On error, don't keep socket connection in ignored state but close them. When the remote end of a socket is closed, xenstored will flag it as an error and switch the connection to ignored. But on some OSes (e.g. NetBSD), poll(2) will return only POLLIN in this case, so sockets in ignored state will stay open forever in xenstored (and it will loop with CPU 100% busy).

Fixes d2fa370d3ef9cbe22d7256c608671cdcdf6e0083
---
 tools/xenstore/xenstored_core.c | 3 +++
 1 file changed, 3 insertions(+)
tools/xenstore/xenstored_core.c +3 -0
index 1ab6f162cb..0fea598352 100644
@@ -1440,6 +1440,9 @@ static void ignore_connection(struct connection *conn)
 
 	talloc_free(conn->in);
 	conn->in = NULL;
+	/* if this is a socket connection, drop it now */
+	if (conn->fd >= 0)
+		talloc_free(conn);
 }
 
 static const char *sockmsg_string(enum xsd_sockmsg_type type)
Signature · 1 line
2.29.2
#2 lore raw

Re: [PATCH] xenstored: close socket connections on error

Manuel Bouyer writes ("[PATCH] xenstored: close socket connections on error"):

Quoted 6 lines

On error, don't keep socket connection in ignored state but close them. When the remote end of a socket is closed, xenstored will flag it as an error and switch the connection to ignored. But on some OSes (e.g. NetBSD), poll(2) will return only POLLIN in this case, so sockets in ignored state will stay open forever in xenstored (and it will loop with CPU 100% busy).

Juergen, I think you probably know this code the best. Would you be able to review this ?

I'm not sure I understand what the specific behaviour on NetBSD is that is upsetting xenstored. Or rather, what it is that xenstored is using to tell when the socket should be closed.

I grepped for POLLERR and nothing came up.

Or to put it another way, is this commit

Quoted 1 line
Fixes d2fa370d3ef9cbe22d7256c608671cdcdf6e0083

broken on Linux too ?

Ian.

#3 lore raw

Re: [PATCH] xenstored: close socket connections on error

Ian Jackson writes ("Re: [PATCH] xenstored: close socket connections on error"):

Quoted 15 lines

Manuel Bouyer writes ("[PATCH] xenstored: close socket connections on error"):

Quoted 6 lines

On error, don't keep socket connection in ignored state but close them. When the remote end of a socket is closed, xenstored will flag it as an error and switch the connection to ignored. But on some OSes (e.g. NetBSD), poll(2) will return only POLLIN in this case, so sockets in ignored state will stay open forever in xenstored (and it will loop with CPU 100% busy).

Juergen, I think you probably know this code the best. Would you be able to review this ?

I'm not sure I understand what the specific behaviour on NetBSD is that is upsetting xenstored. Or rather, what it is that xenstored is using to tell when the socket should be closed.

Quoted 7 lines

I grepped for POLLERR and nothing came up.

Or to put it another way, is this commit

Quoted 1 line
Fixes d2fa370d3ef9cbe22d7256c608671cdcdf6e0083

broken on Linux too ?

Andy pointed me to the recent thread "xenstored file descriptor leak" which answers all these questions. I think it would have been nice if some tools maintainer(s) had been CC'd on that :-).

Juergen, I guess I will get a formal R-b from you ?

Manuel, in response to this:

Quoted 2 lines

When I started, I looked at the wiki for instructions about patches, but didn't find any ...

Earlier I offered you help with git, in private email. I agree that git is confusing and sometimes impenetrable. But it seems that what you are doing now is worse! Please take me up on my offer of help.

Our wiki doesn't give instructions on how to use git to maintain a patch series. Those instructions would not be Xen-specific. Perhaps we could have a pointer or two, but everyone has their own pet methods and tooling so the result would perhaps be more confusing than helpful.

Regards,
Ian.

#4 lore raw

Re: [PATCH] xenstored: close socket connections on error

Quoted 6 lines · Ian Jackson
Quoted 2 lines

[...]
broken on Linux too ?

Andy pointed me to the recent thread "xenstored file descriptor leak" which answers all these questions. I think it would have been nice if some tools maintainer(s) had been CC'd on that :-).

I did use add_maintainers.pl against it (or at last it was my intent)

Quoted 6 lines

Juergen, I guess I will get a formal R-b from you ?

Quoted 8 lines

Manuel, in response to this:

Quoted 2 lines

When I started, I looked at the wiki for instructions about patches, but didn't find any ...

Earlier I offered you help with git, in private email. I agree that git is confusing and sometimes impenetrable. But it seems that what you are doing now is worse! Please take me up on my offer of help.

I didn't forget. It's just that I don't even know what to ask to start with. It seems that StGit will help a lot though.

Quoted 6 lines

Our wiki doesn't give instructions on how to use git to maintain a patch series. Those instructions would not be Xen-specific. Perhaps we could have a pointer or two, but everyone has their own pet methods and tooling so the result would perhaps be more confusing than helpful.

a howto is alwaus helpfull. Even if it's not the one and only way to do, at last it gives a start point.

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
Reviewed-by on v1 1/1
#5 lore raw

Re: [PATCH] xenstored: close socket connections on error

In reply to Manuel Bouyer
Quoted 9 lines · Manuel Bouyer

On error, don't keep socket connection in ignored state but close them. When the remote end of a socket is closed, xenstored will flag it as an error and switch the connection to ignored. But on some OSes (e.g. NetBSD), poll(2) will return only POLLIN in this case, so sockets in ignored state will stay open forever in xenstored (and it will loop with CPU 100% busy).

Fixes d2fa370d3ef9cbe22d7256c608671cdcdf6e0083

Juergen

#6 lore raw

Re: [PATCH] xenstored: close socket connections on error

Quoted 8 lines · Jürgen Groß
Quoted 7 lines · Manuel Bouyer

On error, don't keep socket connection in ignored state but close them. When the remote end of a socket is closed, xenstored will flag it as an error and switch the connection to ignored. But on some OSes (e.g. NetBSD), poll(2) will return only POLLIN in this case, so sockets in ignored state will stay open forever in xenstored (and it will loop with CPU 100% busy).

Quoted 4 lines
Quoted 2 lines
Fixes d2fa370d3ef9cbe22d7256c608671cdcdf6e0083

thanks.
I still don't know if I'm supposed to send a new version of the patch with these tags, even if the patch itself doesn't change, or if the commiter will handle them ?

Signature · 3 lines
Manuel Bouyer <[email protected]>
     NetBSD: 26 ans d'experience feront toujours la difference
--
#7 lore raw

Re: [PATCH] xenstored: close socket connections on error

Quoted 12 lines · Manuel Bouyer
Quoted 11 lines · Jürgen Groß
Quoted 9 lines · Manuel Bouyer

On error, don't keep socket connection in ignored state but close them. When the remote end of a socket is closed, xenstored will flag it as an error and switch the connection to ignored. But on some OSes (e.g. NetBSD), poll(2) will return only POLLIN in this case, so sockets in ignored state will stay open forever in xenstored (and it will loop with CPU 100% busy).

Fixes d2fa370d3ef9cbe22d7256c608671cdcdf6e0083
Quoted 7 lines
Quoted 1 line

thanks.
I still don't know if I'm supposed to send a new version of the patch with these tags, even if the patch itself doesn't change, or if the commiter will handle them ?

Will be done by the committer.

Juergen

#8 lore raw

Re: [PATCH] xenstored: close socket connections on error

In reply to Manuel Bouyer

Manuel Bouyer writes ("Re: [PATCH] xenstored: close socket connections on error"):

Quoted 12 lines · Jürgen Groß
Quoted 11 lines · Manuel Bouyer
Quoted 9 lines

On error, don't keep socket connection in ignored state but close them. When the remote end of a socket is closed, xenstored will flag it as an error and switch the connection to ignored. But on some OSes (e.g. NetBSD), poll(2) will return only POLLIN in this case, so sockets in ignored state will stay open forever in xenstored (and it will loop with CPU 100% busy).

Fixes d2fa370d3ef9cbe22d7256c608671cdcdf6e0083
Quoted 6 lines
Quoted 1 line

thanks.
I still don't know if I'm supposed to send a new version of the patch with these tags, even if the patch itself doesn't change, or if the commiter will handle them ?

The committer will handle them.

Thanks,
Ian.

#9 lore raw

PATCH v3 1/1 Document qemu-ifup on NetBSD

In reply to Manuel Bouyer

Document that on NetBSD, the tap interface will be configured by the qemu-ifup script.

---
 docs/man/xl-network-configuration.5.pod | 3 +++
 1 file changed, 3 insertions(+)
docs/man/xl-network-configuration.5.pod +3 -0
index af058d4d3c..8e5fd909fa 100644
@@ -172,6 +172,9 @@ add it to the relevant bridge). Defaults to
 C<XEN_SCRIPT_DIR/vif-bridge> but can be set to any script. Some example
 scripts are installed in C<XEN_SCRIPT_DIR>.
 
+Note on NetBSD HVM guests will ignore the script option for tap
+(emulated) interfaces and always use
+C<XEN_SCRIPT_DIR/qemu-ifup> to configure the interface in bridged mode.
 
 =head2 ip
 
Signature · 1 line
2.29.2
#10 lore raw

PATCH v3 1/1 NetBSD: use system-provided headers

In reply to Manuel Bouyer

On NetBSD use the system-provided headers for ioctl and related definitions, they are up to date and have more chances to match the kernel's idea of the ioctls and structures.
Remove now-unused NetBSD/evtchn.h and NetBSD/privcmd.h.
Don't fail install if xen/sys/*.h are not present.

---
 tools/debugger/gdbsx/xg/xg_main.c      |   4 +
 tools/include/Makefile                 |   2 +
 tools/include/xen-sys/NetBSD/evtchn.h  |  86 --------------------
 tools/include/xen-sys/NetBSD/privcmd.h | 106 -------------------------
 tools/libs/call/private.h              |   4 +
 tools/libs/ctrl/xc_private.h           |   4 +
 tools/libs/foreignmemory/private.h     |   6 ++
 7 files changed, 20 insertions(+), 192 deletions(-)
 delete mode 100644 tools/include/xen-sys/NetBSD/evtchn.h
 delete mode 100644 tools/include/xen-sys/NetBSD/privcmd.h
tools/debugger/gdbsx/xg/xg_main.c +4 -0
index 4576c762af..903d60baed 100644
@@ -49,7 +49,11 @@
 #include "xg_public.h"
 #include <xen/version.h>
 #include <xen/domctl.h>
+#ifdef __NetBSD__
+#include <xen/xenio.h>
+#else
 #include <xen/sys/privcmd.h>
+#endif
 #include <xen/foreign/x86_32.h>
 #include <xen/foreign/x86_64.h>
 
tools/include/Makefile +2 -0
index 4d4ec5f974..65fb67a771 100644
@@ -68,7 +68,9 @@ install: all
 	$(INSTALL_DATA) xen/foreign/*.h $(DESTDIR)$(includedir)/xen/foreign
 	$(INSTALL_DATA) xen/hvm/*.h $(DESTDIR)$(includedir)/xen/hvm
 	$(INSTALL_DATA) xen/io/*.h $(DESTDIR)$(includedir)/xen/io
+ifneq ($(wildcard xen/sys/*.h),)
 	$(INSTALL_DATA) xen/sys/*.h $(DESTDIR)$(includedir)/xen/sys
+endif
 	$(INSTALL_DATA) xen/xsm/*.h $(DESTDIR)$(includedir)/xen/xsm
 
 .PHONY: uninstall
tools/include/xen-sys/NetBSD/evtchn.h deleted +0 -86

86 lines not on this page · raw message

tools/include/xen-sys/NetBSD/privcmd.h deleted +0 -106

106 lines not on this page · raw message

tools/libs/call/private.h +4 -0
index 7944ac5baf..96922e03d5 100644
@@ -7,7 +7,11 @@
 #include <xencall.h>
 
 #include <xen/xen.h>
+#ifdef __NetBSD__
+#include <xen/xenio.h>
+#else
 #include <xen/sys/privcmd.h>
+#endif
 
 #ifndef PAGE_SHIFT /* Mini-os, Yukk */
 #define PAGE_SHIFT           12
tools/libs/ctrl/xc_private.h +4 -0
index f0b5f83ac8..68e388f488 100644
@@ -39,7 +39,11 @@
 #include <xenforeignmemory.h>
 #include <xendevicemodel.h>
 
+#ifdef __NetBSD__
+#include <xen/xenio.h>
+#else
 #include <xen/sys/privcmd.h>
+#endif
 
 #include <xen-tools/libs.h>
 
tools/libs/foreignmemory/private.h +6 -0
index 1ee3626dd2..581d8b1eef 100644
@@ -8,7 +8,13 @@
 #include <xentoolcore_internal.h>
 
 #include <xen/xen.h>
+
+#ifdef __NetBSD__
+#include <xen/xen.h>
+#include <xen/xenio.h>
+#else
 #include <xen/sys/privcmd.h>
+#endif
 
 #ifndef PAGE_SHIFT /* Mini-os, Yukk */
 #define PAGE_SHIFT           12
Signature · 1 line
2.29.2
#11 lore raw

Re: [PATCH v3] NetBSD: use system-provided headers

Manuel Bouyer writes ("[PATCH v3] NetBSD: use system-provided headers"):

tools/debugger/gdbsx/xg/xg_main.c line 58

Quoted 7 lines
tools/debugger/gdbsx/xg/xg_main.c +4 -0
+#ifdef __NetBSD__
+#include <xen/xenio.h>
+#else
 #include <xen/sys/privcmd.h>
+#endif
 #include <xen/foreign/x86_32.h>
 #include <xen/foreign/x86_64.h>

Maneul, thanks. I think this is a bugfix and ought in principle to go in but I think we probably want to do this with configure rather than ad-hoc ifdefs.

Roger, what do you think ? Were you going to add a configure test for the #ifdef that we put in earlier ?

Thanks,
Ian.

#12 lore raw

Re: [PATCH v3] NetBSD: use system-provided headers

Quoted 12 lines · Ian Jackson

Manuel Bouyer writes ("[PATCH v3] NetBSD: use system-provided headers"):

tools/debugger/gdbsx/xg/xg_main.c line 58

Quoted 7 lines
tools/debugger/gdbsx/xg/xg_main.c +4 -0
+#ifdef __NetBSD__
+#include <xen/xenio.h>
+#else
 #include <xen/sys/privcmd.h>
+#endif
 #include <xen/foreign/x86_32.h>
 #include <xen/foreign/x86_64.h>

Maneul, thanks. I think this is a bugfix and ought in principle to go in but I think we probably want to do this with configure rather than ad-hoc ifdefs.

Quoted 2 lines

Roger, what do you think ? Were you going to add a configure test for the #ifdef that we put in earlier ?

Yes, sorry, I owe you that patch. Will try to do tomorrow so that we can have a model for other headers. AFAICT I will have to build something around AC_CHECK_HEADER so that we can get a define that contains a path that can be used with an #include directive.

Thanks, Roger.

Acked-by on v1 1/1
#13 lore raw
In reply to Manuel Bouyer

Manuel Bouyer writes ("[PATCH] add a qemu-ifup script on NetBSD"):

Quoted 4 lines

On NetBSD, qemu-xen will use a qemu-ifup script to setup the tap interfaces (as qemu-xen-traditional used to). Copy the script from qemu-xen-traditional, and install it on NetBSD. While there document parameters and environnement variables.

tools/hotplug/NetBSD/qemu-ifup line 9

Quoted 11 lines

+++ b/tools/hotplug/NetBSD/qemu-ifup

tools/hotplug/NetBSD/qemu-ifup new file +9 -0
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+#called by qemu when a HVM domU is started.
+# first parameter is tap interface, second is the bridge name
+# environement variable $XEN_DOMAIN_ID contains the domU's ID,
+# which can be used to retrieve extra parameters from the xenstore.
+
+ifconfig $1 up
+exec /sbin/brconfig $2 add $1

Ian.