All of lore.kernel.org
 help / color / mirror / Atom feed
From: shencanquan <shencanquan@huawei.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH] ocfs2: llseek requires to ocfs2 inode lock for the file in SEEK_END
Date: Thu, 27 Jun 2013 09:19:52 +0800	[thread overview]
Message-ID: <51CB9338.3050408@huawei.com> (raw)
In-Reply-To: <20130626141803.a67cb8e4ca38a9ef2967a448@linux-foundation.org>

On 2013/6/27 5:18, Andrew Morton wrote:

> On Thu, 20 Jun 2013 16:23:59 +0800 shencanquan <shencanquan@huawei.com> wrote:
> 
>> 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.
>>
>> ...
>>
>> --- 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;
> 
> I don't understand this.  The lock for inode->i_size is inode->i_mutex,
> and we're already holding i_mutex here.  The current mainline code
> looks correct.
> 
> My guess is that there is some other code path which is modifying
> inode->i_size without holding inode->i_mutex, and while holding
> ocfs2_inode_lock().  If so, that code is surely wrong - it should hold
> i_mutex while modifying i_size.


inode->i_mutex lock only protect the inode size on the same machine.
because ocfs2 is cluster file system. so other machine maybe append the file.
and modify the file size.
and so before get the inode size, it need cluster lock, when other node unlock
cluster lock it will write the inode size to disk. and this machine acquire the lock
it will read the inode size from disk.

> 
> Also, safely reading i_size should be performed via i_size_read(), and
> modifications to i_size should use i_size_write().
> 

ok, thanks for your comments, I will modify this and resent the patch.

> And all this is only really applicable to 32-bit CPUs, which you
> probably aren't using.

I don't understand this.

> 
> So.... please let's take a second look at this.
> 
> .
> 

  reply	other threads:[~2013-06-27  1:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51CB9338.3050408@huawei.com \
    --to=shencanquan@huawei.com \
    --cc=ocfs2-devel@oss.oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.