Skip to contentSkip to conversation

ocfs2-1.4: fix sendfile locking

PATCH New Mark Fasheh 2 participants 2 messages Dec 4, 2009 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2-1.4: fix sendfile locking

ocfs2_sendfile() was duplicating locking which happens later on in ocfs2_readpage(). The double locking would sometimes cause a lockup in nfsd, which uses ->sendfile() for fast read support. An easy way to see this is to mount an exported ocfs2 fs on a client and initiate two parallel read/write dd commands to the same file when there is low memory on the server.

Fix ocfs2_sendfile() so that it only takes and immediately drops the cluster lock. This is consistent with the locking in ocfs2_file_splice_read().

fs/ocfs2/file.c +5 -6
Index: linux/fs/ocfs2/file.c
===================================================================
@@ -2511,15 +2511,14 @@ static ssize_t ocfs2_file_sendfile(struc
 		mlog_errno(ret);
 		goto bail;
 	}
+	ocfs2_inode_unlock(inode, 0);
 
-	down_read(&OCFS2_I(inode)->ip_alloc_sem);
-
+	/*
+	 * This uses ->readpage, so we don't want to hold any cluster
+	 * locks before the call.
+	 */
 	ret = generic_file_sendfile(in_file, ppos, count, actor, target);
 
-	up_read(&OCFS2_I(inode)->ip_alloc_sem);
-
-	ocfs2_inode_unlock(inode, 0);
-
 bail:
 	mlog_exit(ret);
 	return ret;
#1 lore raw

PATCH 1/1 ocfs2-1.4: fix sendfile locking

Quoted 36 lines · Mark Fasheh

ocfs2_sendfile() was duplicating locking which happens later on in ocfs2_readpage(). The double locking would sometimes cause a lockup in nfsd, which uses ->sendfile() for fast read support. An easy way to see this is to mount an exported ocfs2 fs on a client and initiate two parallel read/write dd commands to the same file when there is low memory on the server.

Fix ocfs2_sendfile() so that it only takes and immediately drops the cluster lock. This is consistent with the locking in ocfs2_file_splice_read().

Index: linux/fs/ocfs2/file.c
===================================================================

fs/ocfs2/file.c +5 -6
@@ -2511,15 +2511,14 @@ static ssize_t ocfs2_file_sendfile(struc
 		mlog_errno(ret);
 		goto bail;
 	}
+	ocfs2_inode_unlock(inode, 0);
 
-	down_read(&OCFS2_I(inode)->ip_alloc_sem);
-
+	/*
+	 * This uses ->readpage, so we don't want to hold any cluster
+	 * locks before the call.
+	 */
 	ret = generic_file_sendfile(in_file, ppos, count, actor, target);
 
-	up_read(&OCFS2_I(inode)->ip_alloc_sem);
-
-	ocfs2_inode_unlock(inode, 0);
-
 bail:
 	mlog_exit(ret);
 	return ret;