Skip to contentSkip to conversation

NetBSD: minor fixes and hotplug execution

PATCH Applied Roger Pau Monne 5 participants 23 messages Jul 26, 2012 – Aug 2, 2012

lore
Share & tools
lore
#0 lore raw

v2 cover NetBSD: minor fixes and hotplug execution

This series contains minor fixes to build xen on NetBSD and adds hotplug support to NetBSD. After this, xen-unstable should build and work out-of-the-box on NetBSD.

Changes are available in the git repository at:
git://xenbits.xen.org/people/royger/xen.git netbsd.v2

Roger Pau Monne (5):
tools/build: fix pygrub linking
libxl: react correctly to POLLHUP
*hotplug/NetBSD: check type of file to attach from params *libxl: call hotplug scripts from xl for NetBSD
init/NetBSD: move xenbackendd to xend init script

*Acked

#1 lore raw

PATCH v2 1/5 tools/build: fix pygrub linking

Prevent creating a symlink to $(DESTDIR)/$(BINDIR) if it is the same as $(PRIVATE_BINDIR)

This fixes NetBSD install, where $(DESTDIR)/$(BINDIR) == $(PRIVATE_BINDIR).

Changes since v1:

* Do the check in shell instead of Makefile.

Cc Ian Jackson <[email protected]>
Cc Christoph Egger <[email protected]>
---
 tools/pygrub/Makefile |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
tools/pygrub/Makefile +4 -1
index bd22dd4..8c99e11 100644
@@ -14,7 +14,10 @@ install: all
 		$(PYTHON_PREFIX_ARG) --root="$(DESTDIR)" \
 		--install-scripts=$(PRIVATE_BINDIR) --force
 	$(INSTALL_DIR) $(DESTDIR)/var/run/xend/boot
-	ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR)
+	set -e; if [ `readlink -f $(DESTDIR)/$(BINDIR)` != \
+	             `readlink -f $(PRIVATE_BINDIR)` ]; then \
+	    ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR); \
+	fi
 
 .PHONY: clean
 clean:
Signature · 1 line
1.7.7.5 (Apple Git-26)
#6 lore raw

PATCH v2 2/5 libxl: react correctly to POLLHUP

In reply to Roger Pau Monne

When received POLLHUP on datacopier_readable/writable, kill the datacopier and call the callback with onwrite=-2. On the bootloader callback kill the bootloader process and wait for the callback, but without setting the bl->rc error code.

This is because NetBSD returns POLLHUP when the process on the other end of the pty exits (even when exiting normally).

---
 tools/libxl/libxl_aoutils.c    |   16 ++++++++++++++++
 tools/libxl/libxl_bootloader.c |    9 ++++++---
 tools/libxl/libxl_internal.h   |    1 +
 3 files changed, 23 insertions(+), 3 deletions(-)
tools/libxl/libxl_aoutils.c +16 -0
index 99972a2..2ea9b2c 100644
@@ -102,6 +102,14 @@ static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev,
     libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, toread);
     STATE_AO_GC(dc->ao);
 
+    if (revents & POLLHUP) {
+        LOG(DEBUG, "received POLLHUP on %s during copy of %s, "
+                   "killing the bootloader process",
+                   dc->readwhat, dc->copywhat);
+        datacopier_callback(egc, dc, -2, 0);
+        return;
+    }
+
     if (revents & ~POLLIN) {
         LOG(ERROR, "unexpected poll event 0x%x (should be POLLIN)"
             " on %s during copy of %s", revents, dc->readwhat, dc->copywhat);
@@ -163,6 +171,14 @@ static void datacopier_writable(libxl__egc *egc, libxl__ev_fd *ev,
     libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, towrite);
     STATE_AO_GC(dc->ao);
 
+    if (revents & POLLHUP) {
+        LOG(DEBUG, "received POLLHUP on %s during copy of %s, "
+                   "killing the bootloader process",
+                   dc->writewhat, dc->copywhat);
+        datacopier_callback(egc, dc, -2, 0);
+        return;
+    }
+
     if (revents & ~POLLOUT) {
         LOG(ERROR, "unexpected poll event 0x%x (should be POLLOUT)"
             " on %s during copy of %s", revents, dc->writewhat, dc->copywhat);
tools/libxl/libxl_bootloader.c +6 -3
index ef5a91b..f3d92e2 100644
@@ -285,8 +285,8 @@ static void bootloader_abort(libxl__egc *egc,
     libxl__datacopier_kill(&bl->display);
     if (libxl__ev_child_inuse(&bl->child)) {
         r = kill(bl->child.pid, SIGTERM);
-        if (r) LOGE(WARN, "after failure, failed to kill bootloader [%lu]",
-                    (unsigned long)bl->child.pid);
+        if (r) LOGE(WARN, "%sfailed to kill bootloader [%lu]",
+                    rc ? "after failure, " : "", (unsigned long)bl->child.pid);
     }
     bl->rc = rc;
 }
@@ -567,7 +567,10 @@ static void bootloader_copyfail(libxl__egc *egc, const char *which,
     STATE_AO_GC(bl->ao);
     if (!onwrite && !errnoval)
         LOG(ERROR, "unexpected eof copying %s", which);
-    bootloader_abort(egc, bl, ERROR_FAIL);
+    if (onwrite == -2)
+        bootloader_abort(egc, bl, 0);
+    else
+        bootloader_abort(egc, bl, ERROR_FAIL);
 }
 static void bootloader_keystrokes_copyfail(libxl__egc *egc,
        libxl__datacopier_state *dc, int onwrite, int errnoval)
tools/libxl/libxl_internal.h +1 -0
index 3ee3a09..286aa19 100644
@@ -2073,6 +2073,7 @@ typedef struct libxl__datacopier_buf libxl__datacopier_buf;
  *     errnoval==0 means we got eof and all data was written
  *     errnoval!=0 means we had a read error, logged
  * onwrite==-1 means some other internal failure, errnoval not valid, logged
+ * onwrite==-2 means we got a POLLHUP, errnoval not valid, logged
  * in all cases copier is killed before calling this callback */
 typedef void libxl__datacopier_callback(libxl__egc *egc,
      libxl__datacopier_state *dc, int onwrite, int errnoval);
Signature · 1 line
1.7.7.5 (Apple Git-26)
#13 lore raw

PATCH v2 3/5 hotplug/NetBSD: check type of file to attach from params

In reply to Roger Pau Monne

xend used to set the xenbus backend entry "type" to either "phy" or "file", but now libxl sets it to "phy" for both file and block device. We have to manually check for the type of the "param" filed in order to detect if we are trying to attach a file or a block device.

Changes since v1:

* Check that file is either a block special file or a regular file and report error otherwise.

---
 tools/hotplug/NetBSD/block |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
tools/hotplug/NetBSD/block +7 -1
index cf5ff3a..31d9998 100644
@@ -19,8 +19,14 @@ error() {
 
 xpath=$1
 xstatus=$2
-xtype=$(xenstore-read "$xpath/type")
 xparams=$(xenstore-read "$xpath/params")
+if [ -b $xparams ]; then
+	xtype="phy"
+elif [ -f $xparams ]; then
+	xtype="file"
+else
+	error "invalid file type"
+fi
 
 case $xstatus in
 6)
Signature · 1 line
1.7.7.5 (Apple Git-26)
#15 lore raw

PATCH v2 4/5 libxl: call hotplug scripts from xl for NetBSD

In reply to Roger Pau Monne

Add the missing NetBSD functions to call hotplug scripts, and disable xenbackendd if libxl/disable_udev is not set.

---
 tools/libxl/libxl_netbsd.c      |   57 ++++++++++++++++++++++++++++++++++++++-
 tools/xenbackendd/xenbackendd.c |    8 +++++-
 2 files changed, 63 insertions(+), 2 deletions(-)
tools/libxl/libxl_netbsd.c +56 -1
index 28cdf21..9587833 100644
@@ -32,10 +32,65 @@ char *libxl__devid_to_localdev(libxl__gc *gc, int devid)
 }
 
 /* Hotplug scripts caller functions */
+static int libxl__hotplug(libxl__gc *gc, libxl__device *dev, char ***args,
+                          libxl__device_action action)
+{
+    char *be_path = libxl__device_backend_path(gc, dev);
+    char *script;
+    int nr = 0, rc = 0, arraysize = 4;
+
+    script = libxl__xs_read(gc, XBT_NULL,
+                            GCSPRINTF("%s/%s", be_path, "script"));
+    if (!script) {
+        LOGEV(ERROR, errno, "unable to read script from %s", be_path);
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    GCNEW_ARRAY(*args, arraysize);
+    (*args)[nr++] = script;
+    (*args)[nr++] = be_path;
+    (*args)[nr++] = GCSPRINTF("%d", action == DEVICE_CONNECT ?
+                                    XenbusStateInitWait : XenbusStateClosed);
+    (*args)[nr++] = NULL;
+    assert(nr == arraysize);
+
+out:
+    return rc;
+}
+
 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                    char ***args, char ***env,
                                    libxl__device_action action,
                                    int num_exec)
 {
-    return 0;
+    char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
+    int rc;
+
+    /* Check if we have to run hotplug scripts */
+    if (!disable_udev || num_exec > 0) {
+        rc = 0;
+        goto out;
+    }
+
+    switch (dev->backend_kind) {
+    case LIBXL__DEVICE_KIND_VBD:
+    case LIBXL__DEVICE_KIND_VIF:
+        if (num_exec != 0) {
+            rc = 0;
+            goto out;
+        }
+        rc = libxl__hotplug(gc, dev, args, action);
+        if (!rc) rc = 1;
+        break;
+    default:
+        /* If no need to execute any hotplug scripts,
+         * call the callback manually
+         */
+        rc = 0;
+        break;
+    }
+
+out:
+    return rc;
 }
tools/xenbackendd/xenbackendd.c +7 -1
index 6b5bb8e..5381a2a 100644
@@ -33,6 +33,7 @@
 #define DEVTYPE_UNKNOWN 0
 #define DEVTYPE_VIF 1
 #define DEVTYPE_VBD 2
+#define DISABLE_EXEC "libxl/disable_udev"
 
 #define DOMAIN_PATH "/local/domain/0"
 
@@ -149,7 +150,7 @@ main(int argc, char * const argv[])
 	unsigned int num;
 	char *s;
 	int state;
-	char *sstate;
+	char *sstate, *sdisable;
 	char *p;
 	char buf[80];
 	int type;
@@ -245,6 +246,10 @@ main(int argc, char * const argv[])
 			continue;
 		}
 
+		sdisable = xs_read(xs, XBT_NULL, DISABLE_EXEC, 0);
+		if (sdisable)
+			goto next1;
+
 		if (strlen(vec[XS_WATCH_PATH]) < sizeof("state"))
 			goto next1;
 
@@ -314,6 +319,7 @@ next2:
 		free(sstate);
 
 next1:
+		free(sdisable);
 		free(vec);
 	}
 
Signature · 1 line
1.7.7.5 (Apple Git-26)
#18 lore raw

PATCH v2 5/5 init/NetBSD: move xenbackendd to xend init script

In reply to Roger Pau Monne

xenbackendd is not needed by the xl toolstack, so move it's launch to the xend script.

We have to iterate until we are sure there are no xend processes left, since doing a single pkill usually leaves xend processes running.

Changes since v1:

* Use pgrep and pkill instead of the convoluted shell expression.

Cc Ian Jackson <[email protected]>
Cc Christoph Egger <[email protected]>
---
 tools/hotplug/NetBSD/rc.d/xencommons |   29 ++---------------
 tools/hotplug/NetBSD/rc.d/xend       |   55 +++++++++++++++++++++++++++++++--
 2 files changed, 55 insertions(+), 29 deletions(-)
tools/hotplug/NetBSD/rc.d/xencommons +4 -25
index c0d87bf..fe4c9ac 100644
@@ -29,8 +29,6 @@ XENBACKENDD_PIDFILE="/var/run/xenbackendd.pid"
 
 xen_precmd()
 {
-	mkdir -p /var/run/xend || exit 1
-	mkdir -p /var/run/xend/boot || exit 1
 	mkdir -p /var/run/xenstored || exit 1
 }
 
@@ -46,7 +44,7 @@ xen_startcmd()
 			XENSTORED_ROOTDIR="/var/lib/xenstored"
 		fi
 		rm -f ${XENSTORED_ROOTDIR}/tdb* >/dev/null 2>&1
-		printf "Starting xenservices: xenstored, xenconsoled, xenbackendd."
+		printf "Starting xenservices: xenstored, xenconsoled."
 		XENSTORED_ARGS=" --pid-file ${XENSTORED_PIDFILE}"
 		if [ -n "${XENSTORED_TRACE}" ]; then
 			XENSTORED_ARGS="${XENSTORED_ARGS} -T /var/log/xen/xenstored-trace.log"
@@ -58,7 +56,7 @@ xen_startcmd()
 			sleep 1
 		done
 	else
-		printf "Starting xenservices: xenconsoled, xenbackendd."
+		printf "Starting xenservices: xenconsoled."
 	fi
 
 	XENCONSOLED_ARGS=""
@@ -68,13 +66,6 @@ xen_startcmd()
 
 	${SBINDIR}/xenconsoled ${XENCONSOLED_ARGS}
 
-	XENBACKENDD_ARGS=""
-	if [ -n "${XENBACKENDD_DEBUG}" ]; then
-		XENBACKENDD_ARGS="${XENBACKENDD_ARGS} -d"
-	fi
-
-	${SBINDIR}/xenbackendd ${XENBACKENDD_ARGS}
-
 	printf "\n"
 
 	printf "Setting domain 0 name.\n"
@@ -87,8 +78,6 @@ xen_stop()
 	printf "Stopping xencommons.\n"
 	printf "WARNING: Not stopping xenstored, as it cannot be restarted.\n"
 
-	rc_pid=$(check_pidfile ${XENBACKENDD_PIDFILE} ${SBINDIR}/xenbackendd)
-	pids="$pids $rc_pid"
 	rc_pid=$(check_pidfile ${XENCONSOLED_PIDFILE} ${SBINDIR}/xenconsoled)
 	pids="$pids $rc_pid"
 
@@ -108,17 +97,12 @@ xen_status()
 		pids="$pids $xenconsoled_pid"
 	fi
 
-	xenbackend_pid=$(check_pidfile ${XENBACKENDD_PIDFILE} ${SBINDIR}/xenbackendd)
-	if test -n ${xenbackend_pid}; then
-		pids="$pids $xenbackend_pid"
-	fi
-
-	if test -n "$xenbackend_pid" -a -n "$xenconsoled_pid" -a -n "$xenstored_pid";
+	if test -n "$xenconsoled_pid" -a -n "$xenstored_pid";
 	then
 		echo "xencommons are running as pids $pids."
 		return 0
 	fi
-	if test -z "$xenbackend_pid" -a -z "$xenconsoled_pid" -a -z "$xenstored_pid";
+	if test -z "$xenconsoled_pid" -a -z "$xenstored_pid";
 	then
 		echo "xencommons are not running."
 		return 0
@@ -134,11 +118,6 @@ xen_status()
 	else
 		echo "xenconsoled is not running."
 	fi
-	if test -n $xenbackend_pid; then
-		echo "xenbackendd is running as pid $xenbackend_pid."
-	else
-		echo "xenbackendd is not running."
-	fi
 }
 
 load_rc_config $name
tools/hotplug/NetBSD/rc.d/xend +51 -4

61 lines not on this page · raw message

Signature · 1 line
1.7.7.5 (Apple Git-26)
Acked-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] tools/build: fix pygrub linking

In reply to Roger Pau Monne
Quoted 5 lines · Roger Pau Monne

Prevent creating a symlink to $(DESTDIR)/$(BINDIR) if it is the same as $(PRIVATE_BINDIR)

This fixes NetBSD install, where $(DESTDIR)/$(BINDIR) == $(PRIVATE_BINDIR).

OOI why does netbsd install these internal utilities, which includes things like libxl-save-helper (which absolutely is no use to call as a user) in the regular bin dir rather than libexec or some other acceptable place?

I'm sure there are some things which are wrongly in PRIVATE_BINDIR instead of BINDIR but the right answer there would be to move them.

Quoted 7 lines

Changes since v1:

* Do the check in shell instead of Makefile.

Cc Ian Jackson <[email protected]>
Cc Christoph Egger <[email protected]>
Quoted 20 lines
---
 tools/pygrub/Makefile |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
tools/pygrub/Makefile +4 -1
index bd22dd4..8c99e11 100644
@@ -14,7 +14,10 @@ install: all
 		$(PYTHON_PREFIX_ARG) --root="$(DESTDIR)" \
 		--install-scripts=$(PRIVATE_BINDIR) --force
 	$(INSTALL_DIR) $(DESTDIR)/var/run/xend/boot
-	ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR)
+	set -e; if [ `readlink -f $(DESTDIR)/$(BINDIR)` != \
+	             `readlink -f $(PRIVATE_BINDIR)` ]; then \
+	    ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR); \
+	fi
 
 .PHONY: clean
 clean:
#7 lore raw

Re: [PATCH v2 2/5] libxl: react correctly to POLLHUP

In reply to Roger Pau Monne
Quoted 21 lines · Roger Pau Monne

When received POLLHUP on datacopier_readable/writable, kill the datacopier and call the callback with onwrite=-2. On the bootloader callback kill the bootloader process and wait for the callback, but without setting the bl->rc error code.

This is because NetBSD returns POLLHUP when the process on the other end of the pty exits (even when exiting normally).

---
 tools/libxl/libxl_aoutils.c    |   16 ++++++++++++++++
 tools/libxl/libxl_bootloader.c |    9 ++++++---
 tools/libxl/libxl_internal.h   |    1 +
 3 files changed, 23 insertions(+), 3 deletions(-)
tools/libxl/libxl_aoutils.c +0 -0
index 99972a2..2ea9b2c 100644

tools/libxl/libxl_aoutils.c static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev, · line 107

Quoted 6 lines
tools/libxl/libxl_aoutils.c +3 -0
@@ -102,6 +102,14 @@ static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev,
     libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, toread);
     STATE_AO_GC(dc->ao);
 
+    if (revents & POLLHUP) {
+        LOG(DEBUG, "received POLLHUP on %s during copy of %s, "
+                   "killing the bootloader process",

The datacopier module is completely independent from the bootloader one, so mentioning bootloader in this message is inappropriate. Especially since nothing in the immediate vicinity of this code is actually killing anything.

I'll leave commenting on the semantics of treating POLLHUP this way for Ian to think about.

Acked-by on v2 4/5
#16 lore raw

Re: [PATCH v2 4/5] libxl: call hotplug scripts from xl for NetBSD

In reply to Roger Pau Monne
Quoted 6 lines · Roger Pau Monne

Add the missing NetBSD functions to call hotplug scripts, and disable xenbackendd if libxl/disable_udev is not set.

Cc Christoph Egger <[email protected]>
Cc Ian Jackson <[email protected]>
Quoted 117 lines
---
 tools/libxl/libxl_netbsd.c      |   57 ++++++++++++++++++++++++++++++++++++++-
 tools/xenbackendd/xenbackendd.c |    8 +++++-
 2 files changed, 63 insertions(+), 2 deletions(-)
tools/libxl/libxl_netbsd.c +56 -1
index 28cdf21..9587833 100644
@@ -32,10 +32,65 @@ char *libxl__devid_to_localdev(libxl__gc *gc, int devid)
 }
 
 /* Hotplug scripts caller functions */
+static int libxl__hotplug(libxl__gc *gc, libxl__device *dev, char ***args,
+                          libxl__device_action action)
+{
+    char *be_path = libxl__device_backend_path(gc, dev);
+    char *script;
+    int nr = 0, rc = 0, arraysize = 4;
+
+    script = libxl__xs_read(gc, XBT_NULL,
+                            GCSPRINTF("%s/%s", be_path, "script"));
+    if (!script) {
+        LOGEV(ERROR, errno, "unable to read script from %s", be_path);
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    GCNEW_ARRAY(*args, arraysize);
+    (*args)[nr++] = script;
+    (*args)[nr++] = be_path;
+    (*args)[nr++] = GCSPRINTF("%d", action == DEVICE_CONNECT ?
+                                    XenbusStateInitWait : XenbusStateClosed);
+    (*args)[nr++] = NULL;
+    assert(nr == arraysize);
+
+out:
+    return rc;
+}
+
 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                    char ***args, char ***env,
                                    libxl__device_action action,
                                    int num_exec)
 {
-    return 0;
+    char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
+    int rc;
+
+    /* Check if we have to run hotplug scripts */
+    if (!disable_udev || num_exec > 0) {
+        rc = 0;
+        goto out;
+    }
+
+    switch (dev->backend_kind) {
+    case LIBXL__DEVICE_KIND_VBD:
+    case LIBXL__DEVICE_KIND_VIF:
+        if (num_exec != 0) {
+            rc = 0;
+            goto out;
+        }
+        rc = libxl__hotplug(gc, dev, args, action);
+        if (!rc) rc = 1;
+        break;
+    default:
+        /* If no need to execute any hotplug scripts,
+         * call the callback manually
+         */
+        rc = 0;
+        break;
+    }
+
+out:
+    return rc;
 }
tools/xenbackendd/xenbackendd.c +7 -1
index 6b5bb8e..5381a2a 100644
@@ -33,6 +33,7 @@
 #define DEVTYPE_UNKNOWN 0
 #define DEVTYPE_VIF 1
 #define DEVTYPE_VBD 2
+#define DISABLE_EXEC "libxl/disable_udev"
 
 #define DOMAIN_PATH "/local/domain/0"
 
@@ -149,7 +150,7 @@ main(int argc, char * const argv[])
 	unsigned int num;
 	char *s;
 	int state;
-	char *sstate;
+	char *sstate, *sdisable;
 	char *p;
 	char buf[80];
 	int type;
@@ -245,6 +246,10 @@ main(int argc, char * const argv[])
 			continue;
 		}
 
+		sdisable = xs_read(xs, XBT_NULL, DISABLE_EXEC, 0);
+		if (sdisable)
+			goto next1;
+
 		if (strlen(vec[XS_WATCH_PATH]) < sizeof("state"))
 			goto next1;
 
@@ -314,6 +319,7 @@ next2:
 		free(sstate);
 
 next1:
+		free(sdisable);
 		free(vec);
 	}
 
Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
Acked-by on v2 5/5
#19 lore raw

Re: [PATCH v2 5/5] init/NetBSD: move xenbackendd to xend init script

In reply to Roger Pau Monne
Quoted 6 lines · Roger Pau Monne

xenbackendd is not needed by the xl toolstack, so move it's launch to the xend script.

We have to iterate until we are sure there are no xend processes left, since doing a single pkill usually leaves xend processes running.

Quoted 6 lines

Changes since v1:

* Use pgrep and pkill instead of the convoluted shell expression.

Cc Ian Jackson <[email protected]>
Cc Christoph Egger <[email protected]>
Quoted 158 lines
---
 tools/hotplug/NetBSD/rc.d/xencommons |   29 ++---------------
 tools/hotplug/NetBSD/rc.d/xend       |   55 +++++++++++++++++++++++++++++++--
 2 files changed, 55 insertions(+), 29 deletions(-)
tools/hotplug/NetBSD/rc.d/xencommons +4 -25
index c0d87bf..fe4c9ac 100644
@@ -29,8 +29,6 @@ XENBACKENDD_PIDFILE="/var/run/xenbackendd.pid"
 
 xen_precmd()
 {
-	mkdir -p /var/run/xend || exit 1
-	mkdir -p /var/run/xend/boot || exit 1
 	mkdir -p /var/run/xenstored || exit 1
 }
 
@@ -46,7 +44,7 @@ xen_startcmd()
 			XENSTORED_ROOTDIR="/var/lib/xenstored"
 		fi
 		rm -f ${XENSTORED_ROOTDIR}/tdb* >/dev/null 2>&1
-		printf "Starting xenservices: xenstored, xenconsoled, xenbackendd."
+		printf "Starting xenservices: xenstored, xenconsoled."
 		XENSTORED_ARGS=" --pid-file ${XENSTORED_PIDFILE}"
 		if [ -n "${XENSTORED_TRACE}" ]; then
 			XENSTORED_ARGS="${XENSTORED_ARGS} -T /var/log/xen/xenstored-trace.log"
@@ -58,7 +56,7 @@ xen_startcmd()
 			sleep 1
 		done
 	else
-		printf "Starting xenservices: xenconsoled, xenbackendd."
+		printf "Starting xenservices: xenconsoled."
 	fi
 
 	XENCONSOLED_ARGS=""
@@ -68,13 +66,6 @@ xen_startcmd()
 
 	${SBINDIR}/xenconsoled ${XENCONSOLED_ARGS}
 
-	XENBACKENDD_ARGS=""
-	if [ -n "${XENBACKENDD_DEBUG}" ]; then
-		XENBACKENDD_ARGS="${XENBACKENDD_ARGS} -d"
-	fi
-
-	${SBINDIR}/xenbackendd ${XENBACKENDD_ARGS}
-
 	printf "\n"
 
 	printf "Setting domain 0 name.\n"
@@ -87,8 +78,6 @@ xen_stop()
 	printf "Stopping xencommons.\n"
 	printf "WARNING: Not stopping xenstored, as it cannot be restarted.\n"
 
-	rc_pid=$(check_pidfile ${XENBACKENDD_PIDFILE} ${SBINDIR}/xenbackendd)
-	pids="$pids $rc_pid"
 	rc_pid=$(check_pidfile ${XENCONSOLED_PIDFILE} ${SBINDIR}/xenconsoled)
 	pids="$pids $rc_pid"
 
@@ -108,17 +97,12 @@ xen_status()
 		pids="$pids $xenconsoled_pid"
 	fi
 
-	xenbackend_pid=$(check_pidfile ${XENBACKENDD_PIDFILE} ${SBINDIR}/xenbackendd)
-	if test -n ${xenbackend_pid}; then
-		pids="$pids $xenbackend_pid"
-	fi
-
-	if test -n "$xenbackend_pid" -a -n "$xenconsoled_pid" -a -n "$xenstored_pid";
+	if test -n "$xenconsoled_pid" -a -n "$xenstored_pid";
 	then
 		echo "xencommons are running as pids $pids."
 		return 0
 	fi
-	if test -z "$xenbackend_pid" -a -z "$xenconsoled_pid" -a -z "$xenstored_pid";
+	if test -z "$xenconsoled_pid" -a -z "$xenstored_pid";
 	then
 		echo "xencommons are not running."
 		return 0
@@ -134,11 +118,6 @@ xen_status()
 	else
 		echo "xenconsoled is not running."
 	fi
-	if test -n $xenbackend_pid; then
-		echo "xenbackendd is running as pid $xenbackend_pid."
-	else
-		echo "xenbackendd is not running."
-	fi
 }
 
 load_rc_config $name
tools/hotplug/NetBSD/rc.d/xend +51 -4
index ead9ee0..ac5f2ca 100644
@@ -15,10 +15,57 @@ export PATH
 
 name="xend"
 rcvar=$name
-command="${SBINDIR}/xend"
-command_args="start"
-command_interpreter=`head -n 1 ${command} | awk '{ print substr($0,3) }'`
-sig_stop="SIGKILL"
+start_precmd="xend_precmd"
+start_cmd="xend_startcmd"
+stop_cmd="xend_stop"
+status_cmd="xend_status"
+extra_commands="status"
+required_files="/kern/xen/privcmd"
+
+XENBACKENDD_PIDFILE="/var/run/xenbackendd.pid"
+#XENBACKENDD_DEBUG=1
+
+xend_precmd()
+{
+	mkdir -p /var/run/xend || exit 1
+	mkdir -p /var/run/xend/boot || exit 1
+}
+
+xend_startcmd()
+{
+	printf "Starting xenbackendd.\n"
+
+	XENBACKENDD_ARGS=""
+	if [ -n "${XENBACKENDD_DEBUG}" ]; then
+		XENBACKENDD_ARGS="${XENBACKENDD_ARGS} -d"
+	fi
+
+	${SBINDIR}/xenbackendd ${XENBACKENDD_ARGS}
+
+	printf "Starting xend.\n"
+	${SBINDIR}/xend start >/dev/null 2>&1
+}
+
+xend_stop()
+{
+	printf "Stopping xenbackendd, xend\n"
+	xb_pid=$(check_pidfile ${XENBACKENDD_PIDFILE} ${SBINDIR}/xenbackendd)
+	if test -n "$xb_pid";
+	then
+		kill -${sig_stop:-TERM} $xb_pid
+	fi
+	while pgrep -f ${SBINDIR}/xend >/dev/null 2>&1; do
+		pkill -${sig_stop:-KILL} -f ${SBINDIR}/xend
+	done
+	wait_for_pids $xb_pid
+	rm -f /var/lock/subsys/xend /var/lock/xend /var/run/xenbackendd.pid
+}
+
+xend_status()
+{
+	${SBINDIR}/xend status
+}
 
 load_rc_config $name
 run_rc_command "$1"
+
Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#8 lore raw

Re: [PATCH v2 2/5] libxl: react correctly to POLLHUP

In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH v2 2/5] libxl: react correctly to POLLHUP"):

Quoted 4 lines

When received POLLHUP on datacopier_readable/writable, kill the datacopier and call the callback with onwrite=-2. On the bootloader callback kill the bootloader process and wait for the callback, but without setting the bl->rc error code.

...

tools/libxl/libxl_aoutils.c static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev, · line 108

Quoted 4 lines
tools/libxl/libxl_aoutils.c +4 -0
+    if (revents & POLLHUP) {
+        LOG(DEBUG, "received POLLHUP on %s during copy of %s, "
+                   "killing the bootloader process",
+                   dc->readwhat, dc->copywhat);

The datacopier logic is correct here as far as it goes I think, but as Ian says, the message is wrong.

However I think you need also to check for POLLHUP on reading the pty. There are four fd events registered:
- reading bootloader pty master, POLLHUP expected
- writing bootloader pty master, POLLHUP expected
- reading xenconsole client pty master, POLLHUP not expected
- writing xenconsole client pty master, POLLHUP not expected
(The writing events may not always be registered.)

When the POLLHUP occurs on the bootloader pty master it should be handled the same way whether we first notice it with respect to the reading or writing event. (These correspond to different poll slots and there is no particular reason why it we would process one of these before the other - although of course we the writing one is only present if we have data to write.)

I'm assuming that libxl doesn't get a POLLHUP on the xenconsole pty master when the client disconnects, because (a) if it did that would be impossible for libxl to handle properly and (b) xenconsoled doesn't have any code for this - although it uses select so it's not 100% analogous. So in this case I think the POLLHUP should be an error, as before.

So having thought about it this way, I don't think this interface:

tools/libxl/libxl_internal.h typedef struct libxl__datacopier_buf libxl__datacopier_buf; · line 2079

Quoted 10 lines
tools/libxl/libxl_internal.h +1 -0
@@ -2073,6 +2073,7 @@ typedef struct libxl__datacopier_buf libxl__datacopier_buf;
  *     errnoval==0 means we got eof and all data was written
  *     errnoval!=0 means we had a read error, logged
  * onwrite==-1 means some other internal failure, errnoval not valid, logged
+ * onwrite==-2 means we got a POLLHUP, errnoval not valid, logged
  * in all cases copier is killed before calling this callback */
 typedef void libxl__datacopier_callback(libxl__egc *egc,
      libxl__datacopier_state *dc, int onwrite, int errnoval);

is suitable. We need to be able to distinguish POLLHUP on the writing fd from POLLHUP on the reading fd. That means that you shouldn't abuse "onwrite" like this.

I can see two possible options:

1. Since we have "int errnoval" and errno values are always positive you could signal this with a specific -ve value for errnoval. That is, call datacopier's callers must now be prepared to deal with this `magic' value of errnoval which is not a proper errno value. That is going to be annoying for other users who will need special error handling behaviour.

2. Provide a new callback function pointer for POLLHUP:

    struct libxl__datacopier_state {
        ...
        libxl__datacopier_callback *callback;
        libxl__datacopier_callback *callback_pollhup;
        ...
    }

with something like the following spec:
/* If callback_pollhup!=NULL, POLLHUP will be reported
* by calling callback_pollhup->(..., onwrite, -1).
* If callback_pollhup==NULL, POLLHUP will be reported
* as an internal failure.
* in all cases copier is killed before calling these callbacks */
and make sure that the other users have callback_pollhup==0.

Thanks,
Ian.

#12 lore raw

Re: [PATCH v2 2/5] libxl: react correctly to POLLHUP

In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH v2 2/5] libxl: react correctly to POLLHUP"):

Quoted 4 lines

When received POLLHUP on datacopier_readable/writable, kill the datacopier and call the callback with onwrite=-2. On the bootloader callback kill the bootloader process and wait for the callback, but without setting the bl->rc error code.

...al)

tools/libxl/libxl_internal.h typedef struct libxl__datacopier_buf libxl__datacopier_buf; · line 2079

Quoted 12 lines
tools/libxl/libxl_internal.h +1 -0
index 3ee3a09..286aa19 100644
@@ -2073,6 +2073,7 @@ typedef struct libxl__datacopier_buf libxl__datacopier_buf;
  *     errnoval==0 means we got eof and all data was written
  *     errnoval!=0 means we had a read error, logged
  * onwrite==-1 means some other internal failure, errnoval not valid, logged
+ * onwrite==-2 means we got a POLLHUP, errnoval not valid, logged
  * in all cases copier is killed before calling this callback */
 typedef void libxl__datacopier_callback(libxl__egc *egc,
      libxl__datacopier_state *dc, int onwrite, int errnoval);

Also, when you added this you obviously didn't search for callers which needed to be updated, or you would have found one.

Ian.

#14 lore raw

Re: [PATCH v2 3/5] hotplug/NetBSD: check type of file to attach from params

In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH v2 3/5] hotplug/NetBSD: check type of file to attach from params"):

Quoted 4 lines

xend used to set the xenbus backend entry "type" to either "phy" or "file", but now libxl sets it to "phy" for both file and block device. We have to manually check for the type of the "param" filed in order to detect if we are trying to attach a file or a block device.

...

Quoted 7 lines
tools/hotplug/NetBSD/block +0 -0
index cf5ff3a..31d9998 100644
@@ -19,8 +19,14 @@ error() {
 
 xpath=$1

tools/hotplug/NetBSD/block error() { · line 29

Quoted 10 lines
tools/hotplug/NetBSD/block +7 -1
 xstatus=$2
-xtype=$(xenstore-read "$xpath/type")
 xparams=$(xenstore-read "$xpath/params")
+if [ -b $xparams ]; then
+	xtype="phy"
+elif [ -f $xparams ]; then
+	xtype="file"
+else
+	error "invalid file type"
+fi

This seems to be likely to print strange messages as well as the intended message if xparams=''. And you should print the type you are complaining about in the error message.

Ian.

Acked-by
#20 lore raw

Re: [PATCH v2 5/5] init/NetBSD: move xenbackendd to xend init script

In reply to Christoph Egger

Christoph Egger writes ("Re: [PATCH v2 5/5] init/NetBSD: move xenbackendd to xend init script"):

Quoted 10 lines · Roger Pau Monne
Quoted 9 lines

xenbackendd is not needed by the xl toolstack, so move it's launch to the xend script.

We have to iterate until we are sure there are no xend processes left, since doing a single pkill usually leaves xend processes running.

Changes since v1:

Quoted 7 lines
Quoted 4 lines

* Use pgrep and pkill instead of the convoluted shell expression.

Cc Ian Jackson <[email protected]>
Cc Christoph Egger <[email protected]>

Thanks for the review.

Tested-by
#21 lore raw

Re: [PATCH v2 5/5] init/NetBSD: move xenbackendd to xend init script

Quoted 17 lines · Ian Jackson

Christoph Egger writes ("Re: [PATCH v2 5/5] init/NetBSD: move xenbackendd to xend init script"):

Quoted 16 lines · Roger Pau Monne
Quoted 13 lines

xenbackendd is not needed by the xl toolstack, so move it's launch to the xend script.

We have to iterate until we are sure there are no xend processes left, since doing a single pkill usually leaves xend processes running.

Changes since v1:

* Use pgrep and pkill instead of the convoluted shell expression.

Cc Ian Jackson <[email protected]>
Cc Christoph Egger <[email protected]>
Quoted 5 lines
Quoted 1 line

Thanks for the review.

I can also give a

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
#9 lore raw

Re: [PATCH v2 2/5] libxl: react correctly to POLLHUP

In reply to Ian Jackson

Ian Jackson writes ("Re: [PATCH v2 2/5] libxl: react correctly to POLLHUP"):

Quoted 7 lines

2. Provide a new callback function pointer for POLLHUP:

    struct libxl__datacopier_state {
        ...
        libxl__datacopier_callback *callback;
        libxl__datacopier_callback *callback_pollhup;
        ...
    }

I have done this. The result (untested, but compiles) is below. This should not be applied until someone has been able to test it on NetBSD.

From: Ian Jackson <[email protected]>
Subject: [PATCH v3] libxl: react correctly to bootloader pty master POLLHUP

Receive POLLHUP on the bootloader master pty is not an error. Hopefully it means that the bootloader has exited and therefore the pty slave side has no process group any more. (At least NetBSD indicates POLLHUP on the master in this case.)

So send the bootloader SIGKILL; if it has already exited then this has no effect (except that on some versions of NetBSD it erroneously returns ESRCH and we print a harmless warning) and we will then collect the bootloader's exit status and be satisfied.

In order to implement this we need to provide a way for users of datacopier to handle POLLHUP rather than treating it as fatal.

We rename bootloader_abort to bootloader_stop since it now no longer only applies to error situations.

-
Changes in v3:
* datacopier provides new interface for handling POLLHUP
* Do not ignore errors on the xenconsole pty
* Rename bootloader_abort.

---
 tools/libxl/libxl_aoutils.c    |   23 +++++++++++++++++++++++
 tools/libxl/libxl_bootloader.c |   34 ++++++++++++++++++++++++----------
 tools/libxl/libxl_internal.h   |    5 ++++-
 3 files changed, 51 insertions(+), 11 deletions(-)
tools/libxl/libxl_aoutils.c +23 -0
index 99972a2..4bd5484 100644
@@ -97,11 +97,31 @@ void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc,
     LIBXL_TAILQ_INSERT_TAIL(&dc->bufs, buf, entry);
 }
 
+static int datacopier_pollhup_handled(libxl__egc *egc,
+                                      libxl__datacopier_state *dc,
+                                      short revents, int onwrite)
+{
+    STATE_AO_GC(dc->ao);
+
+    if (dc->callback_pollhup && (revents & POLLHUP)) {
+        LOG(DEBUG, "received POLLHUP on %s during copy of %s",
+            onwrite ? dc->writewhat : dc->readwhat,
+            dc->copywhat);
+        libxl__datacopier_kill(dc);
+        dc->callback(egc, dc, onwrite, -1);
+        return 1;
+    }
+    return 0;
+}
+
 static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev,
                                 int fd, short events, short revents) {
     libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, toread);
     STATE_AO_GC(dc->ao);
 
+    if (datacopier_pollhup_handled(egc, dc, revents, 0))
+        return;
+
     if (revents & ~POLLIN) {
         LOG(ERROR, "unexpected poll event 0x%x (should be POLLIN)"
             " on %s during copy of %s", revents, dc->readwhat, dc->copywhat);
@@ -163,6 +183,9 @@ static void datacopier_writable(libxl__egc *egc, libxl__ev_fd *ev,
     libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, towrite);
     STATE_AO_GC(dc->ao);
 
+    if (datacopier_pollhup_handled(egc, dc, revents, 1))
+        return;
+
     if (revents & ~POLLOUT) {
         LOG(ERROR, "unexpected poll event 0x%x (should be POLLOUT)"
             " on %s during copy of %s", revents, dc->writewhat, dc->copywhat);
tools/libxl/libxl_bootloader.c +24 -10
index ef5a91b..9e9a14a 100644
@@ -275,7 +275,7 @@ static void bootloader_local_detached_cb(libxl__egc *egc,
 }
 
 /* might be called at any time, provided it's init'd */
-static void bootloader_abort(libxl__egc *egc,
+static void bootloader_stop(libxl__egc *egc,
                              libxl__bootloader_state *bl, int rc)
 {
     STATE_AO_GC(bl->ao);
@@ -285,8 +285,8 @@ static void bootloader_abort(libxl__egc *egc,
     libxl__datacopier_kill(&bl->display);
     if (libxl__ev_child_inuse(&bl->child)) {
         r = kill(bl->child.pid, SIGTERM);
-        if (r) LOGE(WARN, "after failure, failed to kill bootloader [%lu]",
-                    (unsigned long)bl->child.pid);
+        if (r) LOGE(WARN, "%sfailed to kill bootloader [%lu]",
+                    rc ? "after failure, " : "", (unsigned long)bl->child.pid);
     }
     bl->rc = rc;
 }
@@ -508,7 +508,10 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
     bl->keystrokes.maxsz = BOOTLOADER_BUF_OUT;
     bl->keystrokes.copywhat =
         GCSPRINTF("bootloader input for domain %"PRIu32, bl->domid);
-    bl->keystrokes.callback = bootloader_keystrokes_copyfail;
+    bl->keystrokes.callback =         bootloader_keystrokes_copyfail;
+    bl->keystrokes.callback_pollhup = bootloader_keystrokes_copyfail;
+        /* pollhup gets called with errnoval==-1 which is not otherwise
+         * possible since errnos are nonnegative, so it's unambiguous */
     rc = libxl__datacopier_start(&bl->keystrokes);
     if (rc) goto out;
 
@@ -516,7 +519,8 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
     bl->display.maxsz = BOOTLOADER_BUF_IN;
     bl->display.copywhat =
         GCSPRINTF("bootloader output for domain %"PRIu32, bl->domid);
-    bl->display.callback = bootloader_display_copyfail;
+    bl->display.callback =         bootloader_display_copyfail;
+    bl->display.callback_pollhup = bootloader_display_copyfail;
     rc = libxl__datacopier_start(&bl->display);
     if (rc) goto out;
 
@@ -562,30 +566,40 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
 
 /* perhaps one of these will be called, but perhaps not */
 static void bootloader_copyfail(libxl__egc *egc, const char *which,
-       libxl__bootloader_state *bl, int onwrite, int errnoval)
+        libxl__bootloader_state *bl, int ondisplay, int onwrite, int errnoval)
 {
     STATE_AO_GC(bl->ao);
+    int rc = ERROR_FAIL;
+
+    if (errnoval==-1) {
+        /* POLLHUP */
+        if (!!ondisplay != !!onwrite)
+            rc = 0;
+        else
+            LOG(ERROR, "unexpected POLLHUP on %s", which);
+    }
     if (!onwrite && !errnoval)
         LOG(ERROR, "unexpected eof copying %s", which);
-    bootloader_abort(egc, bl, ERROR_FAIL);
+
+    bootloader_stop(egc, bl, rc);
 }
 static void bootloader_keystrokes_copyfail(libxl__egc *egc,
        libxl__datacopier_state *dc, int onwrite, int errnoval)
 {
     libxl__bootloader_state *bl = CONTAINER_OF(dc, *bl, keystrokes);
-    bootloader_copyfail(egc, "bootloader input", bl, onwrite, errnoval);
+    bootloader_copyfail(egc, "bootloader input", bl, 0, onwrite, errnoval);
 }
 static void bootloader_display_copyfail(libxl__egc *egc,
        libxl__datacopier_state *dc, int onwrite, int errnoval)
 {
     libxl__bootloader_state *bl = CONTAINER_OF(dc, *bl, display);
-    bootloader_copyfail(egc, "bootloader output", bl, onwrite, errnoval);
+    bootloader_copyfail(egc, "bootloader output", bl, 1, onwrite, errnoval);
 }
 
 static void bootloader_domaindeath(libxl__egc *egc, libxl__domaindeathcheck *dc)
 {
     libxl__bootloader_state *bl = CONTAINER_OF(dc, *bl, deathcheck);
-    bootloader_abort(egc, bl, ERROR_FAIL);
+    bootloader_stop(egc, bl, ERROR_FAIL);
 }
 
 static void bootloader_finished(libxl__egc *egc, libxl__ev_child *child,
tools/libxl/libxl_internal.h +4 -1
index 691b4f6..f0c94e8 100644
@@ -2070,7 +2070,9 @@ typedef struct libxl__datacopier_buf libxl__datacopier_buf;
  *     errnoval==0 means we got eof and all data was written
  *     errnoval!=0 means we had a read error, logged
  * onwrite==-1 means some other internal failure, errnoval not valid, logged
- * in all cases copier is killed before calling this callback */
+ * If we get POLLHUP, we call callback_pollhup(..., onwrite, -1);
+ * or if callback_pollhup==0 this is an internal failure, as above.
+ * In all cases copier is killed before calling this callback */
 typedef void libxl__datacopier_callback(libxl__egc *egc,
      libxl__datacopier_state *dc, int onwrite, int errnoval);
 
@@ -2089,6 +2091,7 @@ struct libxl__datacopier_state {
     const char *copywhat, *readwhat, *writewhat; /* for error msgs */
     FILE *log; /* gets a copy of everything */
     libxl__datacopier_callback *callback;
+    libxl__datacopier_callback *callback_pollhup;
     /* remaining fields are private to datacopier */
     libxl__ev_fd toread, towrite;
     ssize_t used;
Signature · 1 line
tg: (bbf53f4..) t/xen/xl.pty-pollhup (depends on: t/xen/gitignore)
#10 lore raw

Re: [PATCH v2 2/5] libxl: react correctly to POLLHUP

Quoted 56 lines · Ian Jackson

Ian Jackson writes ("Re: [PATCH v2 2/5] libxl: react correctly to POLLHUP"):

Quoted 7 lines

2. Provide a new callback function pointer for POLLHUP:

    struct libxl__datacopier_state {
        ...
        libxl__datacopier_callback *callback;
        libxl__datacopier_callback *callback_pollhup;
        ...
    }

I have done this. The result (untested, but compiles) is below. This should not be applied until someone has been able to test it on NetBSD.

From: Ian Jackson <[email protected]>
Subject: [PATCH v3] libxl: react correctly to bootloader pty master POLLHUP

Receive POLLHUP on the bootloader master pty is not an error. Hopefully it means that the bootloader has exited and therefore the pty slave side has no process group any more. (At least NetBSD indicates POLLHUP on the master in this case.)

So send the bootloader SIGKILL; if it has already exited then this has no effect (except that on some versions of NetBSD it erroneously returns ESRCH and we print a harmless warning) and we will then collect the bootloader's exit status and be satisfied.

In order to implement this we need to provide a way for users of datacopier to handle POLLHUP rather than treating it as fatal.

We rename bootloader_abort to bootloader_stop since it now no longer only applies to error situations.

-
Changes in v3:
* datacopier provides new interface for handling POLLHUP
* Do not ignore errors on the xenconsole pty
* Rename bootloader_abort.

---
 tools/libxl/libxl_aoutils.c    |   23 +++++++++++++++++++++++
 tools/libxl/libxl_bootloader.c |   34 ++++++++++++++++++++++++----------
 tools/libxl/libxl_internal.h   |    5 ++++-
 3 files changed, 51 insertions(+), 11 deletions(-)
tools/libxl/libxl_aoutils.c +2 -0
index 99972a2..4bd5484 100644
@@ -97,11 +97,31 @@ void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc,
     LIBXL_TAILQ_INSERT_TAIL(&dc->bufs, buf, entry);
 }
 
+static int datacopier_pollhup_handled(libxl__egc *egc,
+                                      libxl__datacopier_state *dc,

tools/libxl/libxl_aoutils.c void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc, · line 111

Quoted 10 lines
tools/libxl/libxl_aoutils.c +10 -0
+                                      short revents, int onwrite)
+{
+    STATE_AO_GC(dc->ao);
+
+    if (dc->callback_pollhup && (revents & POLLHUP)) {
+        LOG(DEBUG, "received POLLHUP on %s during copy of %s",
+            onwrite ? dc->writewhat : dc->readwhat,
+            dc->copywhat);
+        libxl__datacopier_kill(dc);
+        dc->callback(egc, dc, onwrite, -1);

Shouldn't this be dc->callback_poolhup?

tools/libxl/libxl_aoutils.c static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op) · line 514

Quoted 9 lines
tools/libxl/libxl_aoutils.c +4 -1
@@ -508,7 +508,10 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
     bl->keystrokes.maxsz = BOOTLOADER_BUF_OUT;
     bl->keystrokes.copywhat =
         GCSPRINTF("bootloader input for domain %"PRIu32, bl->domid);
-    bl->keystrokes.callback = bootloader_keystrokes_copyfail;
+    bl->keystrokes.callback =         bootloader_keystrokes_copyfail;
+    bl->keystrokes.callback_pollhup = bootloader_keystrokes_copyfail;
+        /* pollhup gets called with errnoval==-1 which is not otherwise
+         * possible since errnos are nonnegative, so it's unambiguous */

So the split into two callbacks is just for convenience of some future user, rather than something needed in this patch? Or have I missed somewhere which sets callback but not callback_pollhup?

Ian.

#11 lore raw

Re: [PATCH v2 2/5] libxl: react correctly to POLLHUP

Ian Campbell writes ("Re: [Xen-devel] [PATCH v2 2/5] libxl: react correctly to POLLHUP"):

Quoted 16 lines · Ian Jackson

tools/libxl/libxl_aoutils.c void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc, · line 111

Quoted 13 lines
tools/libxl/libxl_aoutils.c +12 -0
+static int datacopier_pollhup_handled(libxl__egc *egc,
+                                      libxl__datacopier_state *dc,
+                                      short revents, int onwrite)
+{
+    STATE_AO_GC(dc->ao);
+
+    if (dc->callback_pollhup && (revents & POLLHUP)) {
+        LOG(DEBUG, "received POLLHUP on %s during copy of %s",
+            onwrite ? dc->writewhat : dc->readwhat,
+            dc->copywhat);
+        libxl__datacopier_kill(dc);
+        dc->callback(egc, dc, onwrite, -1);

Shouldn't this be dc->callback_poolhup?

Yes. I did say I hadn't executed it :-).

Quoted 5 lines
Quoted 5 lines
tools/libxl/libxl_bootloader.c +0 -1
@@ -508,7 +508,10 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
     bl->keystrokes.maxsz = BOOTLOADER_BUF_OUT;
     bl->keystrokes.copywhat =
         GCSPRINTF("bootloader input for domain %"PRIu32, bl->domid);
-    bl->keystrokes.callback = bootloader_keystrokes_copyfail;
Quoted 8 lines

tools/libxl/libxl_bootloader.c static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op) · line 514

Quoted 4 lines
tools/libxl/libxl_bootloader.c +4 -0
+    bl->keystrokes.callback =         bootloader_keystrokes_copyfail;
+    bl->keystrokes.callback_pollhup = bootloader_keystrokes_copyfail;
+        /* pollhup gets called with errnoval==-1 which is not otherwise
+         * possible since errnos are nonnegative, so it's unambiguous */

So the split into two callbacks is just for convenience of some future user, rather than something needed in this patch? Or have I missed somewhere which sets callback but not callback_pollhup?

Yes, you have. datacopier is used for the qemu state file during save/restore, and naturally wants to treat pollhup as fatal.

Ian.

Applied
#22 lore raw

Re: [PATCH v2 5/5] init/NetBSD: move xenbackendd to xend init script

In reply to Christoph Egger
Quoted 21 lines · Christoph Egger
Quoted 19 lines · Ian Jackson

Christoph Egger writes ("Re: [PATCH v2 5/5] init/NetBSD: move xenbackendd to xend init script"):

Quoted 17 lines · Roger Pau Monne
Quoted 7 lines

xenbackendd is not needed by the xl toolstack, so move it's launch to the xend script.

We have to iterate until we are sure there are no xend processes left, since doing a single pkill usually leaves xend processes running.

Quoted 6 lines

Changes since v1:

* Use pgrep and pkill instead of the convoluted shell expression.

Cc Ian Jackson <[email protected]>
Cc Christoph Egger <[email protected]>
Quoted 8 lines
Quoted 3 lines

Thanks for the review.

I can also give a

Applied, thanks everyone.

Quoted 5 lines
Applied
#17 lore raw

Re: [PATCH v2 4/5] libxl: call hotplug scripts from xl for NetBSD

In reply to Christoph Egger
Quoted 11 lines · Christoph Egger
Quoted 6 lines · Roger Pau Monne

Add the missing NetBSD functions to call hotplug scripts, and disable xenbackendd if libxl/disable_udev is not set.

Cc Christoph Egger <[email protected]>
Cc Ian Jackson <[email protected]>

Applied, thanks.

Applied
#3 lore raw

Re: [PATCH v2 1/5] tools/build: fix pygrub linking

In reply to Ian Campbell
Quoted 10 lines · Ian Campbell
Quoted 5 lines · Roger Pau Monne

Prevent creating a symlink to $(DESTDIR)/$(BINDIR) if it is the same as $(PRIVATE_BINDIR)

This fixes NetBSD install, where $(DESTDIR)/$(BINDIR) == $(PRIVATE_BINDIR).

[...]

Quoted 2 lines

Changes since v1:

Quoted 7 lines
Quoted 5 lines

* Do the check in shell instead of Makefile.

Cc Ian Jackson <[email protected]>
Cc Christoph Egger <[email protected]>

Applied, thanks.

Quoted 28 lines
Quoted 11 lines
---
 tools/pygrub/Makefile |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
tools/pygrub/Makefile +0 -0
index bd22dd4..8c99e11 100644
@@ -14,7 +14,10 @@ install: all
 		$(PYTHON_PREFIX_ARG) --root="$(DESTDIR)" \

tools/pygrub/Makefile install: all · line 23

Quoted 10 lines
tools/pygrub/Makefile +4 -1
 		--install-scripts=$(PRIVATE_BINDIR) --force
 	$(INSTALL_DIR) $(DESTDIR)/var/run/xend/boot
-	ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR)
+	set -e; if [ `readlink -f $(DESTDIR)/$(BINDIR)` != \
+	             `readlink -f $(PRIVATE_BINDIR)` ]; then \
+	    ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR); \
+	fi
 
 .PHONY: clean
 clean:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH v2 1/5] tools/build: fix pygrub linking

Quoted 5 lines · Ian Campbell
Quoted 5 lines
Quoted 5 lines
tools/pygrub/Makefile +0 -0
index bd22dd4..8c99e11 100644
@@ -14,7 +14,10 @@ install: all
Quoted 8 lines
Quoted 8 lines

tools/pygrub/Makefile install: all · line 20

Quoted 8 lines
tools/pygrub/Makefile +4 -1
 		$(PYTHON_PREFIX_ARG) --root="$(DESTDIR)" \
 		--install-scripts=$(PRIVATE_BINDIR) --force
 	$(INSTALL_DIR) $(DESTDIR)/var/run/xend/boot
-	ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR)
+	set -e; if [ `readlink -f $(DESTDIR)/$(BINDIR)` != \
+	             `readlink -f $(PRIVATE_BINDIR)` ]; then \
+	    ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR); \
+	fi

This needs quoting for the shell, like shown below:

[  148s] set -e; if [ `readlink -f /home/abuild/rpmbuild/BUILD/xen-4.2.25700/non-dbg/dist/install//usr/bin` != \
[  148s]              `readlink -f /usr/lib64/xen/bin` ]; then \
[  148s]     ln -sf /usr/lib64/xen/bin/pygrub /home/abuild/rpmbuild/BUILD/xen-4.2.25700/non-dbg/dist/install//usr/bin; \
[  148s] fi
[  148s] /bin/sh: line 0: [: /home/abuild/rpmbuild/BUILD/xen-4.2.25700/non-dbg/dist/install/usr/bin: unary operator expected
tools/pygrub/Makefile +2 -2
diff -r 3d622e2c7cfb tools/pygrub/Makefile
@@ -14,8 +14,8 @@ install: all
 		$(PYTHON_PREFIX_ARG) --root="$(DESTDIR)" \
 		--install-scripts=$(PRIVATE_BINDIR) --force
 	$(INSTALL_DIR) $(DESTDIR)/var/run/xend/boot
-	set -e; if [ `readlink -f $(DESTDIR)/$(BINDIR)` != \
-	             `readlink -f $(PRIVATE_BINDIR)` ]; then \
+	set -e; if [ "`readlink -f $(DESTDIR)/$(BINDIR)`" != \
+	             "`readlink -f $(PRIVATE_BINDIR)`" ]; then \
 	    ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR); \
 	fi
 

Olaf

#5 lore raw

Re: [PATCH v2 1/5] tools/build: fix pygrub linking

Quoted 17 lines · Olaf Hering
Quoted 5 lines · Ian Campbell
Quoted 5 lines
Quoted 5 lines
tools/pygrub/Makefile +0 -0
index bd22dd4..8c99e11 100644
@@ -14,7 +14,10 @@ install: all
Quoted 8 lines
Quoted 8 lines

tools/pygrub/Makefile install: all · line 20

Quoted 8 lines
tools/pygrub/Makefile +4 -1
 		$(PYTHON_PREFIX_ARG) --root="$(DESTDIR)" \
 		--install-scripts=$(PRIVATE_BINDIR) --force
 	$(INSTALL_DIR) $(DESTDIR)/var/run/xend/boot
-	ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR)
+	set -e; if [ `readlink -f $(DESTDIR)/$(BINDIR)` != \
+	             `readlink -f $(PRIVATE_BINDIR)` ]; then \
+	    ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR); \
+	fi

This needs quoting for the shell, like shown below:

Right, thanks.

Can you provide a S-o-b and I'll fabricate up a changelog as I commit it.

Quoted 22 lines
[  148s] set -e; if [ `readlink -f /home/abuild/rpmbuild/BUILD/xen-4.2.25700/non-dbg/dist/install//usr/bin` != \
[  148s]              `readlink -f /usr/lib64/xen/bin` ]; then \
[  148s]     ln -sf /usr/lib64/xen/bin/pygrub /home/abuild/rpmbuild/BUILD/xen-4.2.25700/non-dbg/dist/install//usr/bin; \
[  148s] fi
[  148s] /bin/sh: line 0: [: /home/abuild/rpmbuild/BUILD/xen-4.2.25700/non-dbg/dist/install/usr/bin: unary operator expected

diff -r 3d622e2c7cfb tools/pygrub/Makefile

tools/pygrub/Makefile +2 -2
@@ -14,8 +14,8 @@ install: all
 		$(PYTHON_PREFIX_ARG) --root="$(DESTDIR)" \
 		--install-scripts=$(PRIVATE_BINDIR) --force
 	$(INSTALL_DIR) $(DESTDIR)/var/run/xend/boot
-	set -e; if [ `readlink -f $(DESTDIR)/$(BINDIR)` != \
-	             `readlink -f $(PRIVATE_BINDIR)` ]; then \
+	set -e; if [ "`readlink -f $(DESTDIR)/$(BINDIR)`" != \
+	             "`readlink -f $(PRIVATE_BINDIR)`" ]; then \
 	    ln -sf $(PRIVATE_BINDIR)/pygrub $(DESTDIR)/$(BINDIR); \
 	fi
 

Olaf