chiark / gitweb /
* Locking: <play>.lock (unlinkable fcntl style) plus <play>/good
authorIan Jackson <ian@liberator>
Thu, 12 Jul 2007 14:01:47 +0000 (15:01 +0100)
committerIan Jackson <ian@liberator>
Thu, 12 Jul 2007 14:01:47 +0000 (15:01 +0100)
  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.

debian/changelog
xen/README
xen/cleanup
xen/justconfig
xen/purge
xen/readconfig.in
xen/setup
xen/userv-target
xen/with-testbed

index 63db39e00476a866c36be2edb12468d94fac8763..3383baa8dc778a4750cd704ea4428b8f077af18b 100644 (file)
@@ -1,9 +1,19 @@
-autopkgtest (0.9.2) unstable; urgency=low
+autopkgtest (1.0.0~) unstable; urgency=low
+
+  * Locking: <play>.lock (unlinkable fcntl style) plus <play>/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 <ian@davenant.greenend.org.uk>  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 <ian@davenant.greenend.org.uk>  Thu, 12 Jul 2007 14:31:20 +0100
 
 autopkgtest (0.9.1) gutsy; urgency=low
 
index 2e146d8c1cdf7acf9f40b7d17ef539e4a78967cd..1212187aecf71db6f4b66c2443720a9d187ba519 100644 (file)
@@ -57,12 +57,6 @@ where <config-var> 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           <playbase>/<nominum>_<distro>
        Playground area for this particular testbed construction and
        data.
 
+adt_lock               <playbase>.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 <playbase> because the setup
+       process erases the whole of <playbase> but ought to hold the
+       lock continuously.
+
 adt_xmconfig           <play>/xmconfig
        Xen virtual machine creation configuration for xm create.
        This file will be (over)written during testbed setup.
index 9ef71636328e5c888d9a6b51c1bd2ad348deaf6b..379f7642f3bb339d4541b130f13d3a9fe6d1488e 100755 (executable)
@@ -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"
 
index d217a664baaa9be25d86b6cda3c2893da16c6d5b..42dabf367905ee4b419c4da12367c2165466f9b0 100644 (file)
@@ -1,3 +1,4 @@
 exec 8>&1 >/dev/null
+adt_whenlock_replumb81=y
 . ${ADT_XENLVM_SHARE:=/usr/share/autopkgtest/xenlvm}/readconfig
 exec >&8 8>&-
index 9e03d0ea0f51b9b76d0a5fcacbe30da72e33b393..02bcee6a0b1d65a7557a9fc76105197295ec617e 100755 (executable)
--- 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}"
index 6bb353ba32a0ea0fd1f18d3841d5aa32543ce02a..62d4cbe28b4b3aba56b0bc0315f523d51b8dfaa3 100644 (file)
@@ -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}
index 521bd99176d502f83f8aac333e502e7ffc06c584..d73358c7f9086ec3306f06154d43018e2a0207bf 100755 (executable)
--- 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"
index 362d5cf5f0e827223795e33e3a0555cb8de4230d..c6a80c55b884a164ca6d77c5fd66a34768fe30c2 100755 (executable)
@@ -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
index c472cd0eed09fd1856af61db12058ed610bbf23c..5d207db57977eb78a07e1727dab8ec94fc2e8b33 100755 (executable)
@@ -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="<with-adtxenlvm_$adt_nominum>$debian_chroot" $SHELL -i ;;