Whamcloud - gitweb
LU-649 io: DIO doesn't need lock i_mutex
authorLai Siyao <laisiyao@whamcloud.com>
Mon, 12 Dec 2011 15:12:42 +0000 (07:12 -0800)
committerJohann Lombardi <johann@whamcloud.com>
Wed, 4 Jan 2012 17:21:27 +0000 (12:21 -0500)
There is a dead lock if a file is written with with normal IO, and
read with DIO at the mean time:
regular write: extent lock -> i_mutex
DIO read: i_mutex -> server take extent lock

i_mutex taken at DIO read is redundant, because server will take
extent lock to serialize with write and truncate. Removing it can
avoid the deadlock.

Change-Id: I280559cebae5d04e4fd943bf3fbe82d67e07834b
Signed-off-by: Lai Siyao <laisiyao@whamcloud.com>
Reviewed-on: http://review.whamcloud.com/1829
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Niu Yawei <niu@whamcloud.com>
Reviewed-by: Johann Lombardi <johann@whamcloud.com>
lustre/llite/rw26.c

index f6a3da6..2455212 100644 (file)
@@ -260,10 +260,6 @@ ssize_t ll_direct_IO(int rw, struct file *file,
         oinfo.oi_oa = &oa;
         oinfo.oi_md = lsm;
 
-        /* need locking between buffered and direct access. and race with 
-         *size changing by concurrent truncates and writes. */
-        if (rw == READ)
-                LOCK_INODE_MUTEX(inode);
         for (seg = 0; seg < nr_segs; seg++) {
                 size_t iov_left = iov[seg].iov_len;
                 unsigned long user_addr = (unsigned long)iov[seg].iov_base;
@@ -343,9 +339,9 @@ out:
                 int rc;
 
                 rc = ptlrpc_set_wait(set);
-                if (unlikely(rc != 0))
-                        GOTO(unlock_mutex, tot_bytes = rc);
-                if (rw == WRITE && locked) {
+                if (unlikely(rc != 0)) {
+                        tot_bytes = rc;
+                } else if (rw == WRITE && locked) {
                         lov_stripe_lock(lsm);
                         obd_adjust_kms(ll_i2obdexp(inode),
                                        lsm, file_offset, 0);
@@ -354,10 +350,6 @@ out:
         } else {
                 tot_bytes = result;
         }
-unlock_mutex:
-        if (rw == READ)
-                UNLOCK_INODE_MUTEX(inode);
-
         ptlrpc_set_destroy(set);
         RETURN(tot_bytes);
 }