Whamcloud - gitweb
LU-4030 tests: use free_fd() to allocate file descriptor 81/8181/2
authorVladimir Saveliev <vladimir_saveliev@xyratex.com>
Sat, 2 Nov 2013 15:44:11 +0000 (19:44 +0400)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 19 Nov 2013 13:59:05 +0000 (13:59 +0000)
free_fd() lists /proc/self/fd to find the smallest unused file
descriptor
sanity test_31n is changed to use free_fd() instead of using hardcoded
173
sanity test_236 is changed to use free_fd() instead of using "{FD}<>"
which is not available on eariler bash

Signed-off-by: Vladimir Saveliev <vladimir_saveliev@xyratex.com>
Change-Id: Ie13da99e4a758d7169454c7a6b3b58c594b30ecc
Reviewed-on: http://review.whamcloud.com/8181
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
lustre/tests/sanity.sh
lustre/tests/test-framework.sh

index 00da642..b4eea62 100644 (file)
@@ -2124,14 +2124,17 @@ test_31n() {
        touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
        nlink=$(stat --format=%h $DIR/$tfile)
        [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
-       exec 173<$DIR/$tfile
-       trap "exec 173<&-" EXIT
-       nlink=$(stat --dereference --format=%h /proc/self/fd/173)
+       local fd=$(free_fd)
+       local cmd="exec $fd<$DIR/$tfile"
+       eval $cmd
+       cmd="exec $fd<&-"
+       trap "eval $cmd" EXIT
+       nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
        [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
        rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
-       nlink=$(stat --dereference --format=%h /proc/self/fd/173)
+       nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
        [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
-       exec 173<&-
+       eval $cmd
 }
 run_test 31n "check link count of unlinked file"
 
@@ -11790,11 +11793,14 @@ test_236() {
        cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
        $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
        cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
-       exec {FD}<>$file2
+       local fd=$(free_fd)
+       local cmd="exec $fd<>$file2"
+       eval $cmd
        rm $file2
-       $LFS swap_layouts $file1 /proc/self/fd/${FD} ||
-               error "cannot swap layouts of '$file1' and /proc/self/fd/${FD}"
-       exec {FD}>&-
+       $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
+               error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
+       cmd="exec $fd>&-"
+       eval $cmd
        cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
 
        #cleanup
index 41f3095..c0632b3 100644 (file)
@@ -6617,3 +6617,15 @@ test_mkdir() {
        fi
        return $rc
 }
+
+# find the smallest and not in use file descriptor
+free_fd()
+{
+        local max_fd=$(ulimit -n)
+        local fd=3
+        while [[ $fd -le $max_fd && -e /proc/self/fd/$fd ]]; do
+                ((++fd))
+        done
+        [ $fd -lt $max_fd ] || error "finding free file descriptor failed"
+        echo $fd
+}