2008-09-26 04:53:25

by 홍신 shin hong

[permalink] [raw]
Subject: a question for i_inode's i_size in ext2

Thank you for the answering.

In ext2, it seems to me that inode's i_size field can be accessed
without holding i_mutex
nor thorugh i_size_read function.

For example, in ext2_update_inode() can be invoked without holding i_mutex.
However, it freely access i_size field.

Are these accesses can race with each others?


Sincerely
Shin Hong


2008-09-26 14:41:58

by Theodore Ts'o

[permalink] [raw]
Subject: Re: a question for i_inode's i_size in ext2

On Fri, Sep 26, 2008 at 01:52:13PM +0900, 홍신 shin hong wrote:
> Thank you for the answering.
>
> In ext2, it seems to me that inode's i_size field can be accessed without
> holding i_mutex
> nor thorugh i_size_read function.
>
> For example, in ext2_update_inode() can be invoked without holding
> i_mutex.
> However, it freely access i_size field.
>
> Are these accesses can race with each others?
>

ext2_update_inode() is responsible for writing the contents of the
inode to disk. So it simply saves the current version of the object
to persistent storage. If the inode happens to be in the middle of
being modified, the inode will be redirtied (the rule for modifying
objects like inodes is you modify them first, *then* set the dirty bit
after you are done modifying the object). So if another kernel thread
is in the middle of updating the object, it's not a big deal; the
updated version of the inode will get written to disk later.

Ext2 has no guarantees about filesystem consistency after a crash (you
have to run fsck after a crash), so this is OK.

- Ted