aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChao Yu <yuchao0@huawei.com>2017-06-14 11:00:56 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2017-07-04 05:11:48 -0400
commit0eb0adadf2e49d82bc4ecd65ec3bb69251f7564c (patch)
treed359aa474ee6aebd7402471c0bca82af248b1cc3
parent663f387b713089463e37761bfa2561972c7f45ff (diff)
f2fs: measure inode.i_blocks as generic filesystem
Both in memory or on disk, generic filesystems record i_blocks with 512bytes sized sector count, also VFS sub module such as disk quota follows this rule, but f2fs records it with 4096bytes sized block count, this difference leads to that once we use dquota's function which inc/dec iblocks, it will make i_blocks of f2fs being inconsistent between in memory and on disk. In order to resolve this issue, this patch changes to make in-memory i_blocks of f2fs recording sector count instead of block count, meanwhile leaving on-disk i_blocks recording block count. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/f2fs.h23
-rw-r--r--fs/f2fs/file.c1
-rw-r--r--fs/f2fs/inode.c5
-rw-r--r--fs/f2fs/node.c2
4 files changed, 17 insertions, 14 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index dd5449423fd2..91db1d07f9f8 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1352,10 +1352,10 @@ static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
1352 */ 1352 */
1353static inline int F2FS_HAS_BLOCKS(struct inode *inode) 1353static inline int F2FS_HAS_BLOCKS(struct inode *inode)
1354{ 1354{
1355 if (F2FS_I(inode)->i_xattr_nid) 1355 block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0;
1356 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 1356
1357 else 1357 return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) >
1358 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 1358 (F2FS_DEFAULT_ALLOCATED_BLOCKS + xattr_block);
1359} 1359}
1360 1360
1361static inline bool f2fs_has_xattr_block(unsigned int ofs) 1361static inline bool f2fs_has_xattr_block(unsigned int ofs)
@@ -1363,7 +1363,7 @@ static inline bool f2fs_has_xattr_block(unsigned int ofs)
1363 return ofs == XATTR_NODE_OFFSET; 1363 return ofs == XATTR_NODE_OFFSET;
1364} 1364}
1365 1365
1366static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 1366static inline void f2fs_i_blocks_write(struct inode *, block_t, bool);
1367static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 1367static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
1368 struct inode *inode, blkcnt_t *count) 1368 struct inode *inode, blkcnt_t *count)
1369{ 1369{
@@ -1401,11 +1401,13 @@ static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
1401 1401
1402static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 1402static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
1403 struct inode *inode, 1403 struct inode *inode,
1404 blkcnt_t count) 1404 block_t count)
1405{ 1405{
1406 blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK;
1407
1406 spin_lock(&sbi->stat_lock); 1408 spin_lock(&sbi->stat_lock);
1407 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 1409 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
1408 f2fs_bug_on(sbi, inode->i_blocks < count); 1410 f2fs_bug_on(sbi, inode->i_blocks < sectors);
1409 sbi->total_valid_block_count -= (block_t)count; 1411 sbi->total_valid_block_count -= (block_t)count;
1410 spin_unlock(&sbi->stat_lock); 1412 spin_unlock(&sbi->stat_lock);
1411 f2fs_i_blocks_write(inode, count, false); 1413 f2fs_i_blocks_write(inode, count, false);
@@ -1856,13 +1858,14 @@ static inline void f2fs_i_links_write(struct inode *inode, bool inc)
1856} 1858}
1857 1859
1858static inline void f2fs_i_blocks_write(struct inode *inode, 1860static inline void f2fs_i_blocks_write(struct inode *inode,
1859 blkcnt_t diff, bool add) 1861 block_t diff, bool add)
1860{ 1862{
1861 bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 1863 bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
1862 bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 1864 bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
1865 blkcnt_t sectors = diff << F2FS_LOG_SECTORS_PER_BLOCK;
1863 1866
1864 inode->i_blocks = add ? inode->i_blocks + diff : 1867 inode->i_blocks = add ? inode->i_blocks + sectors :
1865 inode->i_blocks - diff; 1868 inode->i_blocks - sectors;
1866 f2fs_mark_inode_dirty_sync(inode, true); 1869 f2fs_mark_inode_dirty_sync(inode, true);
1867 if (clean || recover) 1870 if (clean || recover)
1868 set_inode_flag(inode, FI_AUTO_RECOVER); 1871 set_inode_flag(inode, FI_AUTO_RECOVER);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 61ee029d7e48..7ea63d84a699 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -665,7 +665,6 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
665 STATX_ATTR_NODUMP); 665 STATX_ATTR_NODUMP);
666 666
667 generic_fillattr(inode, stat); 667 generic_fillattr(inode, stat);
668 stat->blocks <<= 3;
669 return 0; 668 return 0;
670} 669}
671 670
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 868d71436ebc..1ff5bd418d87 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -16,6 +16,7 @@
16 16
17#include "f2fs.h" 17#include "f2fs.h"
18#include "node.h" 18#include "node.h"
19#include "segment.h"
19 20
20#include <trace/events/f2fs.h> 21#include <trace/events/f2fs.h>
21 22
@@ -129,7 +130,7 @@ static int do_read_inode(struct inode *inode)
129 i_gid_write(inode, le32_to_cpu(ri->i_gid)); 130 i_gid_write(inode, le32_to_cpu(ri->i_gid));
130 set_nlink(inode, le32_to_cpu(ri->i_links)); 131 set_nlink(inode, le32_to_cpu(ri->i_links));
131 inode->i_size = le64_to_cpu(ri->i_size); 132 inode->i_size = le64_to_cpu(ri->i_size);
132 inode->i_blocks = le64_to_cpu(ri->i_blocks); 133 inode->i_blocks = SECTOR_FROM_BLOCK(le64_to_cpu(ri->i_blocks));
133 134
134 inode->i_atime.tv_sec = le64_to_cpu(ri->i_atime); 135 inode->i_atime.tv_sec = le64_to_cpu(ri->i_atime);
135 inode->i_ctime.tv_sec = le64_to_cpu(ri->i_ctime); 136 inode->i_ctime.tv_sec = le64_to_cpu(ri->i_ctime);
@@ -267,7 +268,7 @@ int update_inode(struct inode *inode, struct page *node_page)
267 ri->i_gid = cpu_to_le32(i_gid_read(inode)); 268 ri->i_gid = cpu_to_le32(i_gid_read(inode));
268 ri->i_links = cpu_to_le32(inode->i_nlink); 269 ri->i_links = cpu_to_le32(inode->i_nlink);
269 ri->i_size = cpu_to_le64(i_size_read(inode)); 270 ri->i_size = cpu_to_le64(i_size_read(inode));
270 ri->i_blocks = cpu_to_le64(inode->i_blocks); 271 ri->i_blocks = cpu_to_le64(SECTOR_TO_BLOCK(inode->i_blocks));
271 272
272 if (et) { 273 if (et) {
273 read_lock(&et->lock); 274 read_lock(&et->lock);
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index f522378224aa..f6f46be139f4 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1011,7 +1011,7 @@ int remove_inode_page(struct inode *inode)
1011 1011
1012 /* 0 is possible, after f2fs_new_inode() has failed */ 1012 /* 0 is possible, after f2fs_new_inode() has failed */
1013 f2fs_bug_on(F2FS_I_SB(inode), 1013 f2fs_bug_on(F2FS_I_SB(inode),
1014 inode->i_blocks != 0 && inode->i_blocks != 1); 1014 inode->i_blocks != 0 && inode->i_blocks != 8);
1015 1015
1016 /* will put inode & node pages */ 1016 /* will put inode & node pages */
1017 truncate_node(&dn); 1017 truncate_node(&dn);