diff options
author | Mingming Cao <cmm@us.ibm.com> | 2008-07-11 19:27:31 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2008-07-11 19:27:31 -0400 |
commit | 3e3398a08d6e516675d5af853d625dc7dd90eab1 (patch) | |
tree | d8a37dbaea105cd36e02827b057a0f9fcad62adc /fs/ext4/inode.c | |
parent | 632eaeab1feb5d78c1e2bfb1d2dfc0ebb8ac187f (diff) |
ext4: delayed allocation i_blocks fix for stat
Right now i_blocks is not getting updated until the blocks are actually
allocaed on disk. This means with delayed allocation, right after files
are copied, "ls -sF" shoes the file as taking 0 blocks on disk. "du"
also shows the files taking zero space, which is highly confusing to the
user.
Since delayed allocation already keeps track of per-inode total
number of blocks that are subject to delayed allocation, this patch fix
this by using that to adjust the value returned by stat(2). When real
block allocation is done, the i_blocks will get updated. Since the
reserved blocks for delayed allocation will be decreased, this will be
keep value returned by stat(2) consistent.
Signed-off-by: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 0fbe678d40bb..8ca2763df091 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -4231,6 +4231,32 @@ err_out: | |||
4231 | return error; | 4231 | return error; |
4232 | } | 4232 | } |
4233 | 4233 | ||
4234 | int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry, | ||
4235 | struct kstat *stat) | ||
4236 | { | ||
4237 | struct inode *inode; | ||
4238 | unsigned long delalloc_blocks; | ||
4239 | |||
4240 | inode = dentry->d_inode; | ||
4241 | generic_fillattr(inode, stat); | ||
4242 | |||
4243 | /* | ||
4244 | * We can't update i_blocks if the block allocation is delayed | ||
4245 | * otherwise in the case of system crash before the real block | ||
4246 | * allocation is done, we will have i_blocks inconsistent with | ||
4247 | * on-disk file blocks. | ||
4248 | * We always keep i_blocks updated together with real | ||
4249 | * allocation. But to not confuse with user, stat | ||
4250 | * will return the blocks that include the delayed allocation | ||
4251 | * blocks for this file. | ||
4252 | */ | ||
4253 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | ||
4254 | delalloc_blocks = EXT4_I(inode)->i_reserved_data_blocks; | ||
4255 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
4256 | |||
4257 | stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9; | ||
4258 | return 0; | ||
4259 | } | ||
4234 | 4260 | ||
4235 | /* | 4261 | /* |
4236 | * How many blocks doth make a writepage()? | 4262 | * How many blocks doth make a writepage()? |