Message ID | 20140124204709.85C895A4203@corp2gmr1-2.hot.corp.google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Fri, Jan 24, 2014 at 12:47:09PM -0800, akpm@linux-foundation.org wrote: > From: Jensen <shencanquan@huawei.com> > Subject: ocfs2: llseek requires ocfs2 inode lock for the file in SEEK_END > > llseek requires ocfs2 inode lock for updating the file size in SEEK_END. > because the file size maybe update on another node. > > This bug can be reproduce the following scenario: at first, we dd a test > fileA, the file size is 10k. Basically, you want to amke SEEK_END cluster-aware. This patch would be the right way to do it. Reviewed-by: Mark Fasheh <mfasheh@suse.de> --Mark -- Mark Fasheh
diff -puN fs/ocfs2/file.c~ocfs2-llseek-requires-ocfs2-inode-lock-for-the-file-in-seek_end fs/ocfs2/file.c --- a/fs/ocfs2/file.c~ocfs2-llseek-requires-ocfs2-inode-lock-for-the-file-in-seek_end +++ a/fs/ocfs2/file.c @@ -2626,7 +2626,16 @@ static loff_t ocfs2_file_llseek(struct f case SEEK_SET: break; case SEEK_END: - offset += inode->i_size; + /* 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 += i_size_read(inode); + ocfs2_inode_unlock(inode, 0); break; case SEEK_CUR: if (offset == 0) {