From d05388cfed71f5fb981907826efba6c9e56f22f3 Mon Sep 17 00:00:00 2001 From: Joseph Herring Date: Mon, 24 Jan 2011 13:58:03 +0100 Subject: [PATCH] b=22660 Return kernel's locking return code to when lustre reports success i=johann i=andrew --- lustre/ChangeLog | 4 ++++ lustre/llite/file.c | 8 ++++---- lustre/tests/flocks_test.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lustre/tests/sanity.sh | 8 ++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/lustre/ChangeLog b/lustre/ChangeLog index 4e74ea2..a16d95e 100644 --- a/lustre/ChangeLog +++ b/lustre/ChangeLog @@ -81,6 +81,10 @@ Severity : normal Bugzilla : 23352 Description: Modified value of at_min is not taken into account +Severity : normal +Bugzilla : 22660 +Description: lustre grants flock exclusive locks to two fd's in the same process + ------------------------------------------------------------------------------- 2010-10-29 Oracle, Inc. diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 6acf7f5..a0ed244 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -3169,7 +3169,7 @@ int ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock) struct lustre_handle lockh = {0}; ldlm_policy_data_t flock; int flags = 0; - int rc; + int rc, rc2 = 0; ENTRY; CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu file_lock=%p\n", @@ -3253,15 +3253,15 @@ int ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock) &flock, &flags, NULL, 0, NULL, &lockh, 0); if ((file_lock->fl_flags & FL_FLOCK) && (rc == 0 || file_lock->fl_type == F_UNLCK)) - ll_flock_lock_file_wait(file, file_lock, (cmd == F_SETLKW)); + rc2 = ll_flock_lock_file_wait(file, file_lock, (cmd == F_SETLKW)); #ifdef HAVE_F_OP_FLOCK if ((file_lock->fl_flags & FL_POSIX) && (rc == 0 || file_lock->fl_type == F_UNLCK) && !(flags & LDLM_FL_TEST_LOCK)) - posix_lock_file_wait(file, file_lock); + rc2 = posix_lock_file_wait(file, file_lock); #endif - RETURN(rc); + RETURN(rc ? rc : rc2); } int ll_file_noflock(struct file *file, int cmd, struct file_lock *file_lock) diff --git a/lustre/tests/flocks_test.c b/lustre/tests/flocks_test.c index f3feac6..3a55f54 100644 --- a/lustre/tests/flocks_test.c +++ b/lustre/tests/flocks_test.c @@ -268,6 +268,47 @@ out: return rc; } +/** ================================================================= + * test number 3 + * + * Bug 22660: Two conflicting flocks from same process. + */ +int t3(int argc, char *argv[]) +{ + int fd, fd2; + int rc = EXIT_SUCCESS; + + if (argc != 3) { + fprintf(stderr, "Usage: ./flock_test 3 filename\n"); + return EXIT_FAILURE; + } + + if ((fd = open(argv[2], O_RDWR)) < 0) { + fprintf(stderr, "Couldn't open file: %s\n", argv[1]); + return EXIT_FAILURE; + } + if (flock(fd, LOCK_EX | LOCK_NB) < 0) { + perror("first flock failed"); + rc = EXIT_FAILURE; + goto out; + } + if ((fd2 = open(argv[2], O_RDWR)) < 0) { + fprintf(stderr, "Couldn't open file: %s\n", argv[1]); + rc = EXIT_FAILURE; + goto out; + } + if (flock(fd2, LOCK_EX | LOCK_NB) >= 0) { + fprintf(stderr, "Second flock succeeded - FAIL\n"); + rc = EXIT_FAILURE; + } + + close(fd2); +out: + close(fd); + return rc; +} + + /** ============================================================== * program entry */ @@ -294,6 +335,9 @@ int main(int argc, char* argv[]) case 2: rc = t2(argc, argv); break; + case 3: + rc = t3(argc, argv); + break; default: fprintf(stderr, "unknow test number %s\n", argv[1]); break; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 8da8ac4..0daff74 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -4604,6 +4604,14 @@ test_105d() { # bug 15924 } run_test 105d "flock race (should not freeze) ========" +test_105e() { # bug 22660 + [ -z "`mount | grep \"$DIR.*flock\" | grep -v noflock`" ] && \ + skip "mount w/o flock enabled" && return + touch $DIR/$tfile + flocks_test 3 $DIR/$tfile +} +run_test 105e "Two conflicting flocks from same process =======" + test_106() { #bug 10921 mkdir -p $DIR/$tdir $DIR/$tdir && error "exec $DIR/$tdir succeeded" -- 1.8.3.1