From: Ian Jackson Date: Thu, 12 Jul 2007 14:01:47 +0000 (+0100) Subject: * Locking: .lock (unlinkable fcntl style) plus /good X-Git-Tag: converted-from-bzr~46^2~1 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=b2d01ad507b17862e28cf282fbfb77034bae266d;p=autopkgtest.git * Locking: .lock (unlinkable fcntl style) plus /good sentinel file. This will avoid conflicts between simultaneous calls to with-testbed and setup (and others). The `with' mode of the userv target is enhanced so that the caller can take out the lock and hold it will starting and discarding the testbed more than once. --- diff --git a/debian/changelog b/debian/changelog index 63db39e..3383baa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,19 @@ -autopkgtest (0.9.2) unstable; urgency=low +autopkgtest (1.0.0~) unstable; urgency=low + + * Locking: .lock (unlinkable fcntl style) plus /good + sentinel file. This will avoid conflicts between simultaneous calls + to with-testbed and setup (and others). The `with' mode of the userv + target is enhanced so that the caller can take out the lock and hold + it will starting and discarding the testbed more than once. + + -- Ian Jackson Thu, 12 Jul 2007 15:01:35 +0100 + +autopkgtest (0.9.2~) unstable; urgency=low * Really discard stderr from our ought-to-be-unnecessary modprobe dm-snapshot. - -- + -- Ian Jackson Thu, 12 Jul 2007 14:31:20 +0100 autopkgtest (0.9.1) gutsy; urgency=low diff --git a/xen/README b/xen/README index 2e146d8..1212187 100644 --- a/xen/README +++ b/xen/README @@ -57,12 +57,6 @@ where is one of the configuration items listed below. either hyphens or underscores.) Also, `--' may be used to indicate the end of the config vars. -Note that there is NO LOCKING. If you run more than one of either -adt-xenlvm-with-testbed or adt-xenlvm-setup (or one of each) -simultaneously, the behaviour is not defined, except that the host -will definitely not be trashed, and just two or more copies of -adt-xenlvm-with-testbed at once has no bad effects that -adt-xenlvm-cleanup won't fix. ========== Configuration ========== @@ -265,6 +259,15 @@ adt_play /_ Playground area for this particular testbed construction and data. +adt_lock .lock + Lockfile. Used to prevent multiple simultaneous runs of + setup, purge, clean, with-testbed, etc. The lock is held + according to the rules for with-lock-ex from chiark-utils-bin. + Set adt_lock to "none" to disable locking. Note that the + lockfile ought not to be in because the setup + process erases the whole of but ought to hold the + lock continuously. + adt_xmconfig /xmconfig Xen virtual machine creation configuration for xm create. This file will be (over)written during testbed setup. diff --git a/xen/cleanup b/xen/cleanup index 9ef7163..379f764 100755 --- a/xen/cleanup +++ b/xen/cleanup @@ -1,5 +1,6 @@ #!/bin/bash set -e +adt_readconfig_needlock=y . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig test $nonoptargs = 0 || fail "non-option arguments not allowed" diff --git a/xen/justconfig b/xen/justconfig index d217a66..42dabf3 100644 --- a/xen/justconfig +++ b/xen/justconfig @@ -1,3 +1,4 @@ exec 8>&1 >/dev/null +adt_whenlock_replumb81=y . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig exec >&8 8>&- diff --git a/xen/purge b/xen/purge index 9e03d0e..02bcee6 100755 --- a/xen/purge +++ b/xen/purge @@ -1,12 +1,15 @@ #!/bin/bash set -e + +adt_readconfig_needlock=y . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig test $nonoptargs = 0 || fail "non-option arguments not allowed" +rm -f $adt_play/good $ADT_XENLVM_SHARE/cleanup -x lvchange -a n $lvm_baselv_namepath ||: -x lvchange -a n $lvm_cowdata_namepath ||: -x lvremove $lvm_baselv_namepath ||: -x lvremove $lvm_cowdata_namepath ||: +xl lvchange -a n $lvm_baselv_namepath ||: +xl lvchange -a n $lvm_cowdata_namepath ||: +xl lvremove $lvm_baselv_namepath ||: +xl lvremove $lvm_cowdata_namepath ||: rm -rf -- "${adt_play}" diff --git a/xen/readconfig.in b/xen/readconfig.in index 6bb353b..62d4cbe 100644 --- a/xen/readconfig.in +++ b/xen/readconfig.in @@ -12,6 +12,7 @@ fail () { } x () { echo "x $*"; "$@"; } +xl () { echo "xl $*"; 3>&- "$@"; } case "$BASH_VERSION" in '') fail 'scripts using adtxenlvm readconfig must be bash scripts' ;; @@ -83,13 +84,42 @@ cmdline_args "$@" test ! -e "${adt_config}" || . "${adt_config}" cmdline_args "$@" +#---------- settings needed for locking ---------- + +# In-host-file-system playground +: ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}} +: ${adt_xmconfig:=${adt_play}/xmconfig} +: ${adt_lock:=${adt_play}.lock} + +if [ ! "${adt_readconfig_initscript}" ]; then + case "$adt_distro" in + '') + printf "considering which distro to use ... " + test -e /etc/lsb-release || \ + fail 'no /etc/lsb-version, config must specify adt_distro' + . /etc/lsb-release + adt_distro=$DISTRIB_CODENAME + echo "using same distro as host: $adt_distro" + ;; + esac +fi + +if [ "${adt_readconfig_needlock}" ] && + [ "x${adt_lock}" != xnone ] && \ + [ "x${ADT_LOCKED}" != "x$adt_lock" ]; then + if [ "${adt_whenlock_replumb81}" ]; then + exec >&8 8>&- + fi + ADT_LOCKED="$adt_lock" exec with-lock-ex -w "$adt_lock" "$0" "$@" +fi + #---------- calculated defaults for complex settings ---------- if [ ! "${adt_readconfig_initscript}" ]; then case "$adt_lvm_vg" in '') printf "searching for default volume group ... " - vgdisplay_out=`vgdisplay -c 8>&-` + vgdisplay_out=`vgdisplay -c 3>&- 8>&-` case "$vgdisplay_out" in "") fail 'no volume groups found';; *" @@ -158,19 +188,6 @@ case "$adt_modules" in *) ;; esac -if [ ! "${adt_readconfig_initscript}" ]; then - case "$adt_distro" in - '') - printf "considering which distro to use ... " - test -e /etc/lsb-release || \ - fail 'no /etc/lsb-version, config must specify adt_distro' - . /etc/lsb-release - adt_distro=$DISTRIB_CODENAME - echo "using same distro as host: $adt_distro" - ;; - esac -fi - hostname_from_ipaddr () { eval ' if [ x"$adt_'$1'_hostname" = x ] && \ @@ -281,11 +298,6 @@ boolean_config () { # Xen : ${adt_xmname:=${adt_nominum}_${adt_distro}} -# In-host-file-system playground -: ${adt_play:=${adt_playbase}/${adt_nominum}_${adt_distro}} -: ${adt_xmconfig:=${adt_play}/xmconfig} -: ${adt_lock:=${adt_play}/lock} - # LVM boolean_config lvm_erasebase true : ${adt_lvm_baselv:=${adt_nominum}_${adt_distro}_base} diff --git a/xen/setup b/xen/setup index 521bd99..d73358c 100755 --- a/xen/setup +++ b/xen/setup @@ -1,16 +1,17 @@ #!/bin/bash set -e adt_readconfig_needkernel=y +adt_readconfig_needlock=y . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig test $nonoptargs = 0 || fail "non-option arguments not allowed" $ADT_XENLVM_SHARE/purge -x lvcreate -L $adt_fs_size -n $adt_lvm_baselv $adt_lvm_vg -x lvcreate -L $adt_fs_snapsize -n $adt_lvm_cowdatalv $adt_lvm_vg +xl lvcreate -L $adt_fs_size -n $adt_lvm_baselv $adt_lvm_vg +xl lvcreate -L $adt_fs_snapsize -n $adt_lvm_cowdatalv $adt_lvm_vg if $adt_lvm_erasebase; then - basesize=`lvdisplay -c $lvm_baselv_namepath 8>&-` + basesize=`lvdisplay -c $lvm_baselv_namepath 8>&- 3>&-` basesize="${basesize#*:*:*:*:*:*:}" basesize="${basesize%%:*}" x dd if=/dev/zero of=$lvm_baselv_namepath bs=512 count="$basesize" @@ -103,3 +104,4 @@ done x xm save $adt_xmname $adt_play/xen-save rm ${lvm_fslink_ptr} +touch "$adt_play/good" diff --git a/xen/userv-target b/xen/userv-target index 362d5cf..c6a80c5 100755 --- a/xen/userv-target +++ b/xen/userv-target @@ -40,8 +40,17 @@ run () { } case "$1" in -with) run adt-xenlvm-with-testbed sh -c 'echo y && exec cat' ;; pon0) run adt-xenlvm-on-testbed -- --print0-command ;; console) xm console "$nd" ;; +with) + ADT_LOCKED="$nddir/lock" with-lock-ex -w "$nddir/lock" sh -ec ' + while adt-xenlvm-with-testbed \ + --adt-distro="$1" --adt-nominum="$2" \ + sh -c "echo y && read again" && \ + echo n && read again; do + : + done + ' locked-fragment "$d" "$n" +;; *) fail 'unknown mode' esac diff --git a/xen/with-testbed b/xen/with-testbed index c472cd0..5d207db 100755 --- a/xen/with-testbed +++ b/xen/with-testbed @@ -2,9 +2,15 @@ set -e trap 'exit 127' 0 +adt_readconfig_needlock=y . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/justconfig while test $# -gt $nonoptargs; do shift; done +if ! test -f "$adt_play/good"; then + echo >&2 'testbed not in good state' + exit 127 +fi + ${ADT_XENLVM_SHARE}/cleanup >/dev/null modprobe dm-snapshot >/dev/null 2>&1 ||: @@ -21,6 +27,8 @@ xm restore $adt_play/xen-save xm mem-set $adt_xmname $adt_testbed_ram udevsettle +unset ADT_LOCKED + set +e case $# in 0) debian_chroot="$debian_chroot" $SHELL -i ;;