From 1f9235152b2f44c7bd64c5c021066f1984f341e6 Mon Sep 17 00:00:00 2001 From: Vladimir Saveliev Date: Sat, 2 Nov 2013 19:44:11 +0400 Subject: [PATCH] LU-4030 tests: use free_fd() to allocate file descriptor 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 Change-Id: Ie13da99e4a758d7169454c7a6b3b58c594b30ecc Reviewed-on: http://review.whamcloud.com/8181 Reviewed-by: Andreas Dilger Reviewed-by: Bob Glossman Tested-by: Jenkins Tested-by: Maloo --- lustre/tests/sanity.sh | 24 +++++++++++++++--------- lustre/tests/test-framework.sh | 12 ++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 00da642..b4eea62 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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 diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 41f3095..c0632b3 100644 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -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 +} -- 1.8.3.1