]> err.no Git - util-linux/commitdiff
tests: cleanup blkid cache after test device deinitialization
authorKarel Zak <kzak@redhat.com>
Fri, 25 May 2007 12:53:22 +0000 (14:53 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 25 May 2007 12:53:22 +0000 (14:53 +0200)
The libblkid reuses cached information when a cache entry is younger
than 2 secs. That's wrong, because util-linux tests use devices
more quickly.

Signed-off-by: Karel Zak <kzak@redhat.com>
tests/README
tests/functions.sh

index 8eca0854441b865a6cc12ac1816be95d61bde606..783f37c6da61e6a8a18519b4d9a2a9fa071b6215 100644 (file)
@@ -14,3 +14,9 @@
 
        ./ts-<component_name>-<test_name>.sh [--verbose]
 
+
+
+ *** WARNING ***
+
+ The tests touch your /etc/fstab and /etc/blkid.tab. Please, be careful and use
+ these tests only for development and never on production system.
index ba94ad4de61376c3bf50b99c8a18d0dda9ad596a..ed435092c4a26d642ddf63ab34d26322aa53b715 100644 (file)
@@ -57,6 +57,20 @@ function ts_init {
        TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NAME"
        TS_INPUT="$TS_INPUTDIR/$TS_NAME"
        TS_MOUNTPOINT="$(pwd)/$TS_OUTDIR/${TS_NAME}_mnt"
+       TS_BLKIDCACHE=""
+       TS_HAS_VOLUMEID="no"
+
+       ldd $TS_CMD_MOUNT | grep -q 'libvolume_id' &> /dev/null
+       if [ "$?" == "0" ]; then
+               TS_HAS_VOLUMEID="yes"
+       fi
+       if [ "$TS_HAS_VOLUMEID" != "yes" ]; then
+               if [ -f "/etc/blkid/blkid.tab" ]; then
+                       TS_BLKIDCACHE="/etc/blkid/blkid.tab"
+               elif [ -f "/etc/blkid.tab" ]; then
+                       TS_BLKIDCACHE="/etc/blkid.tab"
+               fi
+       fi
 
        rm -f $TS_OUTPUT
        touch $TS_OUTPUT
@@ -101,6 +115,10 @@ function ts_device_init {
        local IMAGE_RE=$( echo "$IMAGE" | sed 's:/:\\/:g' )
        local DEV=""
 
+       if [ "$TS_HAS_VOLUMEID" != "yes" ] && [ -f "$TS_BLKIDCACHE" ]; then
+               cp $TS_BLKIDCACHE $OUTDIR/$TS_NAME.cache
+       fi
+
        dd if=/dev/zero of="$IMAGE" bs=1M count=5 &> /dev/null
 
        $TS_CMD_LOSETUP -f "$IMAGE" 2>&1 >> $TS_OUTPUT
@@ -121,15 +139,18 @@ function ts_device_deinit {
        if [ -b "$DEV" ]; then
                $TS_CMD_UMOUNT "$DEV" &> /dev/null
                $TS_CMD_LOSETUP -d "$DEV" &> /dev/null
+               if [ "$TS_HAS_VOLUMEID" !=  "yes" ] && [ -f "$TS_BLKIDCACHE" ] && [ -s "$OUTDIR/$TS_NAME.cache" ]; then
+                       # We have to remove the device from cache otherwise
+                       # libblkid will reuse cached information. The cache
+                       # refresh time is 2 seconds -- that's too long. We
+                       # re-use the same device more quickly.  --kzak
+                       mv -f $OUTDIR/$TS_NAME.cache $TS_BLKIDCACHE
+               fi      
        fi
 }
 
 function ts_udev_dev_support {
-       ldd $TS_CMD_MOUNT | grep -q 'libvolume_id' 2>&1 >> $TS_OUTPUT
-       if [ "$?" == "0" ]; then
-               local HAS_VOLUMEID="yes"
-       fi
-       if [ -n "$HAS_VOLUMEID" ] && [ ! -L "/dev/disk/$1/$2" ]; then
+       if [ "$TS_HAS_VOLUMEID" == "yes" ] && [ ! -L "/dev/disk/$1/$2" ]; then
                return 1
        fi
        return 0