diff options
author | bad <bad@pkgsrc.org> | 2016-04-04 15:13:15 +0000 |
---|---|---|
committer | bad <bad@pkgsrc.org> | 2016-04-04 15:13:15 +0000 |
commit | 814e828a9073ff9386204a532cf924bd5d37bade (patch) | |
tree | 43645fb77c18ead81972a3d3f06a8762dd9fd573 /sysutils | |
parent | 4fe56c81bcc275b2c8d0e43195247e7ef3269b90 (diff) | |
download | pkgsrc-814e828a9073ff9386204a532cf924bd5d37bade.tar.gz |
Guard the NetBSD block device hotplug script against concurrent execution.
xl(1) runs the hotplug scripts in parallel. This causes failures when the
next free vnd device is selected.
Locking modeled after the Linux block hotplug script.
Diffstat (limited to 'sysutils')
-rw-r--r-- | sysutils/xentools42/Makefile | 5 | ||||
-rw-r--r-- | sysutils/xentools42/PLIST | 3 | ||||
-rw-r--r-- | sysutils/xentools42/distinfo | 5 | ||||
-rw-r--r-- | sysutils/xentools42/files/locking.sh | 72 | ||||
-rw-r--r-- | sysutils/xentools42/patches/patch-hotplug_NetBSD_Makefile | 14 | ||||
-rw-r--r-- | sysutils/xentools42/patches/patch-hotplug_NetBSD_block | 57 |
6 files changed, 147 insertions, 9 deletions
diff --git a/sysutils/xentools42/Makefile b/sysutils/xentools42/Makefile index c7b8e19d2aa..24ff4a7a840 100644 --- a/sysutils/xentools42/Makefile +++ b/sysutils/xentools42/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.43 2016/04/04 15:03:14 bad Exp $ +# $NetBSD: Makefile,v 1.44 2016/04/04 15:13:15 bad Exp $ VERSION= 4.2.5 VERSION_IPXE= 1.0.0 @@ -145,7 +145,7 @@ SUBST_FILES.conf+= libxl/xl_cmdtable.c SUBST_FILES.conf+= ../docs/misc/xl-disk-configuration.txt SUBST_SED.conf= -e "s,@XENDCONFDIR@,${PKG_SYSCONFDIR},g" -XEND_SCRIPTS= block vif-bridge vif-ip qemu-ifup hotplugpath.sh +XEND_SCRIPTS= block vif-bridge vif-ip qemu-ifup hotplugpath.sh locking.sh SUBST_CLASSES.NetBSD+= proc SUBST_STAGE.proc= pre-configure @@ -200,6 +200,7 @@ pre-build: .for s in ${BLKTAP_FILES} ${CP} -f ${FILESDIR}/${s} ${WRKSRC}/blktap/drivers/ .endfor + ${CP} -f ${FILESDIR}/locking.sh ${WRKSRC}/hotplug/NetBSD/ ${SED} -e "s,@XENDCONFDIR@,${PKG_SYSCONFDIR},g" \ ${XENTOP}/docs/man/xl.pod.1 |\ pod2man >${WRKDIR}/xl.1 diff --git a/sysutils/xentools42/PLIST b/sysutils/xentools42/PLIST index b9fe9ede9fc..d579cc288cf 100644 --- a/sysutils/xentools42/PLIST +++ b/sysutils/xentools42/PLIST @@ -1,4 +1,4 @@ -@comment $NetBSD: PLIST,v 1.6 2014/03/11 14:05:17 jperkin Exp $ +@comment $NetBSD: PLIST,v 1.7 2016/04/04 15:13:15 bad Exp $ bin/libxl-save-helper bin/lsevtchn bin/pygrub @@ -682,6 +682,7 @@ share/examples/xen/formats share/examples/xen/oxenstored.conf share/examples/xen/scripts/block share/examples/xen/scripts/hotplugpath.sh +share/examples/xen/scripts/locking.sh share/examples/xen/scripts/qemu-ifup share/examples/xen/scripts/vif-bridge share/examples/xen/scripts/vif-ip diff --git a/sysutils/xentools42/distinfo b/sysutils/xentools42/distinfo index fe05d4ab364..34624db2977 100644 --- a/sysutils/xentools42/distinfo +++ b/sysutils/xentools42/distinfo @@ -1,4 +1,4 @@ -$NetBSD: distinfo,v 1.24 2016/04/04 15:03:14 bad Exp $ +$NetBSD: distinfo,v 1.25 2016/04/04 15:13:15 bad Exp $ SHA1 (ipxe-git-v1.0.0.tar.gz) = da052c8de5f3485fe0253c19cf52ed6d72528485 RMD160 (ipxe-git-v1.0.0.tar.gz) = dcd9b6eaafa1ce05c1ebf2a15f2f73ad7a8c5547 @@ -48,7 +48,8 @@ SHA1 (patch-firmware_etherboot_patches_boot__prompt__option.patch) = 95d6e140643 SHA1 (patch-firmware_etherboot_patches_series) = 2ced4e380f436a0287744e0a817ff24b91a43e7c SHA1 (patch-firmware_hvmloader_Makefile) = d4d9f34335a178f50e7fda52747cf6551ceeccc6 SHA1 (patch-firmware_hvmloader_util.h) = 8ec0efdf56b9f2ea66cac7e90cba4abf727d4605 -SHA1 (patch-hotplug_NetBSD_Makefile) = 7b14179d0d00dc1b6f9a85fff706d82ce9b0cd66 +SHA1 (patch-hotplug_NetBSD_Makefile) = efc7c4d5b2f4aa5d3de2c7f77427db77fd95898a +SHA1 (patch-hotplug_NetBSD_block) = 61a1d5188abd280aa0960fffb6f43fd17bd6fb07 SHA1 (patch-hotplug_NetBSD_vif-bridge) = 7d01f15273c983c2cfe125e75800f9719961427c SHA1 (patch-hotplug_NetBSD_vif-ip) = d3b0555f5ba0bfcbf0f7027eb5f74a84d0cf7c80 SHA1 (patch-hotplug_common_Makefile) = 3ee2fec5c4cb171c35c7e73379da4235b5ddca99 diff --git a/sysutils/xentools42/files/locking.sh b/sysutils/xentools42/files/locking.sh new file mode 100644 index 00000000000..88257f62b7b --- /dev/null +++ b/sysutils/xentools42/files/locking.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# +# Copyright (c) 2016, Christoph Badura. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +LOCK_BASEDIR="$XEN_LOCK_DIR/xen-hotplug" + +_lockfd=9 +_have_lock=0 # lock not taken yet. + +SHLOCK="shlock ${_shlock_debug-}" + +_lock_set_vars() { + _lockfile="$LOCK_BASEDIR/$1.lock" + _lockfifo="$LOCK_BASEDIR/$1.fifo" +} + +_lock_init() { + mkdir -p "$LOCK_BASEDIR" 2>/dev/null || true + mkfifo $_lockfifo 2>/dev/null || true +} + +# +# use a named pipe as condition variable +# opening for read-only blocks when there's no writer. +# opening for read-write never blocks but unblocks any waiting readers. +# +_lock_wait_cv() { + eval "exec $_lockfd< $_lockfifo ; exec $_lockfd<&-" +} +_lock_signal_cv() { + eval "exec $_lockfd<> $_lockfifo ; exec $_lockfd<&-" +} + +claim_lock() { + _lock_set_vars $1 + _lock_init + until $SHLOCK -f $_lockfile -p $$; do + _lock_wait_cv + done + _have_lock=1 + # be sure to release the lock when the shell exits + trap "release_lock $1" 0 1 2 15 +} + +release_lock() { + _lock_set_vars $1 + [ "$_have_lock" != 0 -a -f $_lockfile ] && rm $_lockfile + _have_lock=0 + _lock_signal_cv; +} diff --git a/sysutils/xentools42/patches/patch-hotplug_NetBSD_Makefile b/sysutils/xentools42/patches/patch-hotplug_NetBSD_Makefile index 023f95d75d1..6701ba3cbd6 100644 --- a/sysutils/xentools42/patches/patch-hotplug_NetBSD_Makefile +++ b/sysutils/xentools42/patches/patch-hotplug_NetBSD_Makefile @@ -1,8 +1,14 @@ -$NetBSD: patch-hotplug_NetBSD_Makefile,v 1.2 2015/08/23 16:17:12 spz Exp $ +$NetBSD: patch-hotplug_NetBSD_Makefile,v 1.3 2016/04/04 15:13:15 bad Exp $ --- hotplug/NetBSD/Makefile.orig 2014-09-02 06:22:57.000000000 +0000 +++ hotplug/NetBSD/Makefile -@@ -8,7 +8,7 @@ XEN_SCRIPTS += vif-bridge +@@ -3,12 +3,13 @@ include $(XEN_ROOT)/tools/Rules.mk + + # Xen script dir and scripts to go there. + XEN_SCRIPTS = ++XEN_SCRIPTS += locking.sh + XEN_SCRIPTS += block + XEN_SCRIPTS += vif-bridge XEN_SCRIPTS += vif-ip XEN_SCRIPT_DATA = @@ -11,7 +17,7 @@ $NetBSD: patch-hotplug_NetBSD_Makefile,v 1.2 2015/08/23 16:17:12 spz Exp $ .PHONY: all all: -@@ -21,10 +21,11 @@ install: all install-scripts install-rcd +@@ -21,10 +22,11 @@ install: all install-scripts install-rcd .PHONY: install-scripts install-scripts: @@ -25,7 +31,7 @@ $NetBSD: patch-hotplug_NetBSD_Makefile,v 1.2 2015/08/23 16:17:12 spz Exp $ done set -e; for i in $(XEN_SCRIPT_DATA); \ do \ -@@ -33,12 +34,6 @@ install-scripts: +@@ -33,12 +35,6 @@ install-scripts: .PHONY: install-rcd install-rcd: diff --git a/sysutils/xentools42/patches/patch-hotplug_NetBSD_block b/sysutils/xentools42/patches/patch-hotplug_NetBSD_block new file mode 100644 index 00000000000..5095cc42656 --- /dev/null +++ b/sysutils/xentools42/patches/patch-hotplug_NetBSD_block @@ -0,0 +1,57 @@ +$NetBSD: patch-hotplug_NetBSD_block,v 1.1 2016/04/04 15:13:15 bad Exp $ + +--- hotplug/NetBSD/block.orig 2014-09-02 06:22:57.000000000 +0000 ++++ hotplug/NetBSD/block +@@ -6,6 +6,7 @@ + + DIR=$(dirname "$0") + . "${DIR}/hotplugpath.sh" ++. "${DIR}/locking.sh" + + PATH=${BINDIR}:${SBINDIR}:${LIBEXEC}:${PRIVATE_BINDIR}:/bin:/usr/bin:/sbin:/usr/sbin + export PATH +@@ -14,6 +15,7 @@ error() { + echo "$@" >&2 + xenstore-write $xpath/hotplug-status error \ + $xpath/hotplug-error "$@" ++ release_lock block + exit 1 + } + +@@ -37,10 +39,12 @@ case $xstatus in + # device removed + case $xtype in + file) ++ claim_lock block + vnd=$(xenstore-read "$xpath/vnd" || echo none) + if [ $vnd != none ]; then + vnconfig -u $vnd + fi ++ release_lock block + ;; + phy) + ;; +@@ -52,6 +56,7 @@ case $xstatus in + exit 0 + ;; + 2) ++ claim_lock block + case $xtype in + file) + # Store the list of available vnd(4) devices in +@@ -78,6 +83,7 @@ case $xstatus in + fi + done + if [ x$device = x ] ; then ++ release_lock block + error "no available vnd device" + fi + xenstore-write $xpath/vnd $device +@@ -89,6 +95,7 @@ case $xstatus in + physical_device=$(stat -f '%r' "$device") + xenstore-write $xpath/physical-device $physical_device + xenstore-write $xpath/hotplug-status connected ++ release_lock block + exit 0 + ;; + *) |