Whamcloud - gitweb
b=22660 Return kernel's locking return code to when lustre reports success
authorJoseph Herring <herring3@llnl.gov>
Mon, 24 Jan 2011 12:58:03 +0000 (13:58 +0100)
committerJohann Lombardi <johann.lombardi@oracle.com>
Mon, 24 Jan 2011 12:58:03 +0000 (13:58 +0100)
i=johann
i=andrew

lustre/ChangeLog
lustre/llite/file.c
lustre/tests/flocks_test.c
lustre/tests/sanity.sh

index 4e74ea2..a16d95e 100644 (file)
@@ -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.
index 6acf7f5..a0ed244 100644 (file)
@@ -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)
index f3feac6..3a55f54 100644 (file)
@@ -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;
index 8da8ac4..0daff74 100644 (file)
@@ -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"