f2fs: convert inc/dec_valid_node_count to inc/dec one count
Gu Zheng [Tue, 19 Nov 2013 10:03:38 +0000 (18:03 +0800)]
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>

Conflicts:
fs/f2fs/f2fs.h
fs/f2fs/node.c

Change-Id: Ie7634dca89856a2b4c2442e8e5af0e52fe39f7c6

fs/f2fs/f2fs.h
fs/f2fs/node.c

index 7ad3674..e684d99 100644 (file)
@@ -745,68 +745,64 @@ static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
 }
 
 static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
-                                               struct inode *inode,
-                                               unsigned int count)
+                                               struct inode *inode)
 {
        block_t valid_block_count;
        unsigned int valid_node_count;
 
        spin_lock(&sbi->stat_lock);
 
-       valid_block_count = sbi->total_valid_block_count + (block_t)count;
-       valid_node_count = sbi->total_valid_node_count + count;
-
+       valid_block_count = sbi->total_valid_block_count + 1;
        if (valid_block_count > sbi->user_block_count) {
                spin_unlock(&sbi->stat_lock);
                return false;
        }
 
+       valid_node_count = sbi->total_valid_node_count + 1;
        if (valid_node_count > sbi->total_node_count) {
                spin_unlock(&sbi->stat_lock);
                return false;
        }
 
        if (inode)
-               inode->i_blocks += count;
-       sbi->alloc_valid_block_count += (block_t)count;
-       sbi->total_valid_node_count = valid_node_count;
-       sbi->total_valid_block_count = valid_block_count;
+               inode->i_blocks++;
+
+       sbi->alloc_valid_block_count++;
+       sbi->total_valid_node_count++;
+       sbi->total_valid_block_count++;
        spin_unlock(&sbi->stat_lock);
 
        return true;
 }
 
 static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
-                                               struct inode *inode,
-                                               unsigned int count)
+                                               struct inode *inode)
 {
        spin_lock(&sbi->stat_lock);
 
-       if (sbi->total_valid_block_count < count) {
-               pr_crit("F2FS-fs (%s): block accounting error: %llu < %u\n",
+       if (sbi->total_valid_block_count < 1) {
+               pr_crit("F2FS-fs (%s): block accounting error: %llu < 1\n",
                        sbi->sb->s_id,
-                       (unsigned long long)sbi->total_valid_block_count,
-                       count);
+                       (unsigned long long)sbi->total_valid_block_count);
                f2fs_handle_error(sbi);
-               sbi->total_valid_block_count = count;
+               sbi->total_valid_block_count = 1;
        }
-       if (sbi->total_valid_node_count < count) {
-               pr_crit("F2FS-fs (%s): node accounting error: %u < %u\n",
-                       sbi->sb->s_id, sbi->total_valid_node_count, count);
+       if (sbi->total_valid_node_count < 1) {
+               pr_crit("F2FS-fs (%s): node accounting error: %u < 1\n",
+                       sbi->sb->s_id, sbi->total_valid_node_count);
                f2fs_handle_error(sbi);
-               sbi->total_valid_node_count = count;
+               sbi->total_valid_node_count = 1;
        }
-       if (inode->i_blocks < count) {
-               pr_crit("F2FS-fs (%s): inode accounting error: %llu < %u\n",
-                       sbi->sb->s_id, (unsigned long long)inode->i_blocks,
-                       count);
+       if (inode->i_blocks < 1) {
+               pr_crit("F2FS-fs (%s): inode accounting error: %llu < 1\n",
+                       sbi->sb->s_id, (unsigned long long)inode->i_blocks);
                f2fs_handle_error(sbi);
-               inode->i_blocks = count;
+               inode->i_blocks = 1;
        }
 
-       inode->i_blocks -= count;
-       sbi->total_valid_node_count -= count;
-       sbi->total_valid_block_count -= (block_t)count;
+       inode->i_blocks--;
+       sbi->total_valid_node_count--;
+       sbi->total_valid_block_count--;
 
        spin_unlock(&sbi->stat_lock);
 }
index 60fbbd6..7bda30a 100644 (file)
@@ -515,7 +515,7 @@ static void truncate_node(struct dnode_of_data *dn)
 
        /* Deallocate node address */
        invalidate_blocks(sbi, ni.blk_addr);
-       dec_valid_node_count(sbi, dn->inode, 1);
+       dec_valid_node_count(sbi, dn->inode);
        set_node_addr(sbi, &ni, NULL_ADDR);
 
        if (dn->nid == dn->inode->i_ino) {
@@ -868,7 +868,7 @@ struct page *new_node_page(struct dnode_of_data *dn,
        if (!page)
                return ERR_PTR(-ENOMEM);
 
-       if (!inc_valid_node_count(sbi, dn->inode, 1)) {
+       if (!inc_valid_node_count(sbi, dn->inode)) {
                err = -ENOSPC;
                goto fail;
        }
@@ -1585,7 +1585,7 @@ int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page)
 
        err = set_node_addr(sbi, &new_ni, NEW_ADDR);
        if (!err)
-               if (!inc_valid_node_count(sbi, NULL, 1))
+               if (!inc_valid_node_count(sbi, NULL))
                        err = -ENOSPC;
        if (!err)
                inc_valid_inode_count(sbi);