All of lore.kernel.org
 help / color / mirror / Atom feed
* [Ocfs2-devel] [PATCH] ocfs2: llseek requires to ocfs2 inode lock for the file in SEEK_END
@ 2013-06-20  8:23 shencanquan
  2013-06-26 21:18 ` Andrew Morton
  2013-06-29 13:37 ` Joel Becker
  0 siblings, 2 replies; 15+ messages in thread
From: shencanquan @ 2013-06-20  8:23 UTC (permalink / raw)
  To: ocfs2-devel

llseek requires ocfs2 inode lock for updating the file size in SEEK_END.
because the file size maybe update on another node.
if it not . after call llseek in SEEK_END. the position is old.

this bug can be reproduce the following scenario:
at first ,we dd a test fileA,the file size is 10k.
on NodeA:
---------
1) open the test fileA, lseek the end of file. and print the position.
2) close the test fileA

on NodeB:
1) open the test fileA, append the 5k data to test FileA.
2) lseek the end of file. and print the position.
3) close file.

at first we run the test program1 on NodeA , the result is 10k.
and then run the test program2 on NodeB,  the result is 15k.
at last, we run the test program1 on NodeA again, the result is 10k.

after apply this patch.  the three step result is 15k.

Signed-off-by: jensen <shencanquan@huawei.com>
---
 fs/ocfs2/file.c |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index ff54014..3afd24c 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2626,7 +2626,16 @@ static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence)
 	case SEEK_SET:
 		break;
 	case SEEK_END:
+		/* SEEK_END requires the OCFS2 inode lock for the file
+		 * because it references the file's size.
+		 */
+		ret = ocfs2_inode_lock(inode, NULL, 0);
+		if (ret < 0) {
+			mlog_errno(ret);
+			goto out;
+		}
 		offset += inode->i_size;
+		ocfs2_inode_unlock(inode, 0);
 		break;
 	case SEEK_CUR:
 		if (offset == 0) {
-- 
1.7.9.7

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2013-07-02 21:19 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-20  8:23 [Ocfs2-devel] [PATCH] ocfs2: llseek requires to ocfs2 inode lock for the file in SEEK_END shencanquan
2013-06-26 21:18 ` Andrew Morton
2013-06-27  1:19   ` shencanquan
2013-06-27  1:25     ` Andrew Morton
2013-06-27  1:50       ` shencanquan
2013-06-27  3:34         ` Sunil Mushran
2013-06-27  8:56           ` Jensen
2013-06-27 22:08           ` Andrew Morton
2013-06-27 22:59             ` Sunil Mushran
2013-06-28  9:11               ` Jeff Liu
2013-06-29 13:28                 ` Joel Becker
2013-06-29 13:37 ` Joel Becker
2013-07-01  1:38   ` Jensen
2013-07-02 19:58     ` Mark Fasheh
2013-07-02 21:19       ` Joel Becker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.