fat: add i_disksize to represent uninitialized size
Subsystems (2)
PATCH v3 1/6 fat: add i_disksize to represent uninitialized size
From: Namjae Jeon <[email protected]>
Add i_disksize to represent uninitialized allocated size. And mmu_private represent initialized allocated size.
--- fs/fat/cache.c | 6 +++--- fs/fat/fat.h | 3 ++- fs/fat/file.c | 4 +++- fs/fat/inode.c | 4 ++++ 4 files changed, 12 insertions(+), 5 deletions(-)
fs/fat/cache.c +3 -3
@@ -329,10 +329,10 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,return 0 ;/* -* ->mmu_private can access on only allocation path. -* (caller must hold ->i_mutex) +* Both ->mmu_private and ->i_disksize can access +* on only allocation path. (caller must hold ->i_mutex) */ - last_block = (MSDOS_I (inode)->mmu_private + (blocksize -1 )) + last_block = (MSDOS_I (inode)->i_disksize + (blocksize -1 )) >> blocksize_bits;if (sector >= last_block)return 0 ;
fs/fat/fat.h +2 -1
@@ -118,7 +118,8 @@ struct msdos_inode_info {unsigned int cache_valid_id;/* NOTE: mmu_private is 64bits, so must hold ->i_mutex to access */ -loff_t mmu_private;/* physically allocated size */ +loff_t mmu_private;/* physically allocated size (initialized) */ +loff_t i_disksize;/* physically allocated size (uninitialized) */ int i_start;/* first cluster or 0 */ int i_logstart;/* logical first cluster */
fs/fat/file.c +3 -1
@@ -300,8 +300,10 @@ void fat_truncate_blocks(struct inode *inode, loff_t offset)* This protects against truncating a file bigger than it was then * trying to write into the hole. */ -if (MSDOS_I (inode)->mmu_private > offset) +if (MSDOS_I (inode)->i_disksize > offset) {MSDOS_I (inode)->mmu_private = offset; +MSDOS_I (inode)->i_disksize = offset; + } nr_clusters = (offset + (cluster_size -1 )) >> sbi->cluster_bits;
fs/fat/inode.c +4 -0
@@ -93,6 +93,7 @@ static inline int __fat_get_block(struct inode *inode, sector_t iblock, *max_blocks =min (mapped_blocks, *max_blocks);MSDOS_I (inode)->mmu_private += *max_blocks << sb->s_blocksize_bits; +MSDOS_I (inode)->i_disksize =MSDOS_I (inode)->mmu_private; err =fat_bmap (inode, iblock, &phys, &mapped_blocks, create);if (err)
@@ -408,6 +409,7 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)if (error <0 )return error;MSDOS_I (inode)->mmu_private = inode->i_size; +MSDOS_I (inode)->i_disksize = inode->i_size;set_nlink (inode,fat_subdirs (inode)); }else {/* not a directory */
@@ -423,6 +425,7 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) inode->i_fop = &fat_file_operations; inode->i_mapping->a_ops = &fat_aops;MSDOS_I (inode)->mmu_private = inode->i_size; +MSDOS_I (inode)->i_disksize = inode->i_size; }if (de->attr &ATTR_SYS ) {if (sbi->options.sys_immutable)
@@ -1223,6 +1226,7 @@ static int fat_read_root(struct inode *inode) & ~((loff_t)sbi->cluster_size - 1)) >> 9;MSDOS_I (inode)->i_logstart =0 ;MSDOS_I (inode)->mmu_private = inode->i_size; +MSDOS_I (inode)->i_disksize = inode->i_size;fat_save_attrs (inode,ATTR_DIR ); inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec =0 ;
Signature · 1 line
1.7.9.5
OGAWA Hirofumi
maintainerQuoted 4 lines · Namjae Jeon
From: Namjae Jeon <[email protected]>
Add
i_disksizeto represent uninitialized allocated size. Andmmu_privaterepresent initialized allocated size.
Don't we need to update ->i_disksize after cont_write_begin()?
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2014-02-03, OGAWA Hirofumi <[email protected]>:
Quoted 8 lines
Quoted 4 lines · Namjae Jeon
From: Namjae Jeon <[email protected]>
Add
i_disksizeto represent uninitialized allocated size. Andmmu_privaterepresent initialized allocated size.Don't we need to update ->i_disksize after
cont_write_begin()?
We don't need to update i_disksize after cont_write_begin. It is taken care by the fat_get_block after the allocation. For all write paths we align the mmu_private and i_disksize from fat_fill_inode and fat_get_block.
Thanks.
Quoted 3 lines
--
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 5 lines · Namjae Jeon
2014-02-03, OGAWA Hirofumi <[email protected]>:
Quoted 4 lines
Quoted 2 lines · Namjae Jeon
From: Namjae Jeon <[email protected]>
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Add
i_disksizeto represent uninitialized allocated size. Andmmu_privaterepresent initialized allocated size.Don't we need to update ->i_disksize after
cont_write_begin()?We don't need to update
i_disksizeaftercont_write_begin. It is taken care by thefat_get_blockafter the allocation. For all write paths we align themmu_privateandi_disksizefromfat_fill_inodeandfat_get_block.
fat_fill_inode() just set i_disksize to i_size. So, it is not aligned by cluster size or block size.
E.g. ->mmu_private = 500. Then, cont_write_begin() can set ->mmu_private to 512 on some case. In this case, fat_get_block() will not be called, because no new allocation.
If this is true, it would be possible to have ->mmu_private == 512 and ->i_disksize == 500.
I'm missing something?
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 9 lines · OGAWA Hirofumi
Quoted 5 lines
Quoted 1 line
Don't we need to update ->i_disksize after
cont_write_begin()?We don't need to update
i_disksizeaftercont_write_begin. It is taken care by thefat_get_blockafter the allocation. For all write paths we align themmu_privateandi_disksizefromfat_fill_inodeandfat_get_block.
fat_fill_inode()just seti_disksizetoi_size. So, it is not aligned by cluster size or block size.
Quoted 8 lines
E.g. ->mmu_private = 500. Then,
cont_write_begin()can set ->mmu_private to 512 on some case. In this case,fat_get_block()will not be called, because no new allocation.If this is true, it would be possible to have ->mmu_private == 512 and ->i_disksize == 500.
I'm missing something?
BTW, even if above was right, I'm not checking whether updating ->i_disksize after cont_write_begin() is right fix or not.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2014-02-04, OGAWA Hirofumi <[email protected]>:
Quoted 15 lines
Quoted 13 lines · OGAWA Hirofumi
Quoted 5 lines
Quoted 1 line
Don't we need to update ->i_disksize after
cont_write_begin()?We don't need to update
i_disksizeaftercont_write_begin. It is taken care by thefat_get_blockafter the allocation. For all write paths we align themmu_privateandi_disksizefromfat_fill_inodeandfat_get_block.
fat_fill_inode()just seti_disksizetoi_size. So, it is not aligned by cluster size or block size.E.g. ->mmu_private = 500. Then,
cont_write_begin()can set ->mmu_private to 512 on some case. In this case,fat_get_block()will not be called, because no new allocation.
Quoted 7 lines
Quoted 4 lines
If this is true, it would be possible to have ->mmu_private == 512 and ->i_disksize == 500.
I'm missing something?
BTW, even if above was right, I'm not checking whether updating ->i_disksize after
cont_write_begin()is right fix or not.
I understand your concern. these can be mismatched.
But, when checking your doubt, I can not find any side effect. I think that there is no issue regardless of alignment of two value, in the cont_write_begin.
Could you please share any point I am missing ?
If you suggest checking point or test method, I can check more and share the result.
Thanks OGAWA.
Quoted 3 lines
--
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 12 lines · Namjae Jeon
Quoted 12 lines
Quoted 11 lines
fat_fill_inode()just seti_disksizetoi_size. So, it is not aligned by cluster size or block size.E.g. ->mmu_private = 500. Then,
cont_write_begin()can set ->mmu_private to 512 on some case. In this case,fat_get_block()will not be called, because no new allocation.If this is true, it would be possible to have ->mmu_private == 512 and ->i_disksize == 500.
I'm missing something?
Quoted 8 lines
Quoted 2 lines
BTW, even if above was right, I'm not checking whether updating ->i_disksize after
cont_write_begin()is right fix or not.I understand your concern. these can be mismatched. But, when checking your doubt, I can not find any side effect. I think that there is no issue regardless of alignment of two value, in the
cont_write_begin. Could you please share any point I am missing ? If you suggest checking point or test method, I can check more and share the result.
I'm not checking whether it is wrong or not. But, like you said, ->mmu_private > ->i_disksize is wrong in theory.
Although, it might have no real problem.
So, how about to set ->i_disksize to aligned by blocksize at first (i.e. when initializing the inode)?
This may change the behavior when ->mmu_private is not aligned to blocksize in current patchset. But, in theory, it is right state (between ->mmu_private and ->i_disksize is uninitialized). I guess, we can do it with small adjustments, and keep state valid in theory too.
This is just a my guess, so it might be wrong though. I guess, worth to try to consider.
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2014-02-06, OGAWA Hirofumi <[email protected]>:
Quoted 25 lines
Quoted 14 lines · Namjae Jeon
Quoted 14 lines
Quoted 13 lines
fat_fill_inode()just seti_disksizetoi_size. So, it is not aligned by
cluster size or block size.E.g. ->mmu_private = 500. Then,
cont_write_begin()can set ->mmu_private
to 512 on some case. In this case,fat_get_block()will not be called, because no new allocation.If this is true, it would be possible to have ->mmu_private == 512 and ->i_disksize == 500.
I'm missing something?
Quoted 8 lines
Quoted 2 lines
BTW, even if above was right, I'm not checking whether updating ->i_disksize after
cont_write_begin()is right fix or not.I understand your concern. these can be mismatched. But, when checking your doubt, I can not find any side effect. I think that there is no issue regardless of alignment of two value, in the
cont_write_begin. Could you please share any point I am missing ? If you suggest checking point or test method, I can check more and share the result.
Quoted 7 lines
I'm not checking whether it is wrong or not. But, like you said, ->mmu_private > ->i_disksize is wrong in theory.
Although, it might have no real problem.
So, how about to set ->i_disksize to aligned by blocksize at first (i.e. when initializing the inode)?
Yes, It is good idea.
Quoted 5 lines
This may change the behavior when ->mmu_private is not aligned to blocksize in current patchset. But, in theory, it is right state (between ->mmu_private and ->i_disksize is uninitialized). I guess, we can do it with small adjustments, and keep state valid in theory too.
Right.
Quoted 3 lines
This is just a my guess, so it might be wrong though. I guess, worth to try to consider.
Okay, I will include it in next patch-set after checking.
Thanks for your review!
Quoted 5 lines
Thanks.
--
OGAWA Hirofumi <[email protected]>