f2fs: adjust readahead block number during recovery
[linux-2.6-microblaze.git] / fs / f2fs / checkpoint.c
index 982f017..a13b6b4 100644 (file)
@@ -282,18 +282,22 @@ out:
        return blkno - start;
 }
 
-void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index)
+void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index,
+                                                       unsigned int ra_blocks)
 {
        struct page *page;
        bool readahead = false;
 
+       if (ra_blocks == RECOVERY_MIN_RA_BLOCKS)
+               return;
+
        page = find_get_page(META_MAPPING(sbi), index);
        if (!page || !PageUptodate(page))
                readahead = true;
        f2fs_put_page(page, 0);
 
        if (readahead)
-               f2fs_ra_meta_pages(sbi, index, BIO_MAX_VECS, META_POR, true);
+               f2fs_ra_meta_pages(sbi, index, ra_blocks, META_POR, true);
 }
 
 static int __f2fs_write_meta_page(struct page *page,
@@ -351,13 +355,13 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
                goto skip_write;
 
        /* if locked failed, cp will flush dirty pages instead */
-       if (!down_write_trylock(&sbi->cp_global_sem))
+       if (!f2fs_down_write_trylock(&sbi->cp_global_sem))
                goto skip_write;
 
        trace_f2fs_writepages(mapping->host, wbc, META);
        diff = nr_pages_to_write(sbi, META, wbc);
        written = f2fs_sync_meta_pages(sbi, META, wbc->nr_to_write, FS_META_IO);
-       up_write(&sbi->cp_global_sem);
+       f2fs_up_write(&sbi->cp_global_sem);
        wbc->nr_to_write = max((long)0, wbc->nr_to_write - written - diff);
        return 0;
 
@@ -1159,7 +1163,7 @@ static bool __need_flush_quota(struct f2fs_sb_info *sbi)
        if (!is_journalled_quota(sbi))
                return false;
 
-       if (!down_write_trylock(&sbi->quota_sem))
+       if (!f2fs_down_write_trylock(&sbi->quota_sem))
                return true;
        if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH)) {
                ret = false;
@@ -1171,7 +1175,7 @@ static bool __need_flush_quota(struct f2fs_sb_info *sbi)
        } else if (get_pages(sbi, F2FS_DIRTY_QDATA)) {
                ret = true;
        }
-       up_write(&sbi->quota_sem);
+       f2fs_up_write(&sbi->quota_sem);
        return ret;
 }
 
@@ -1228,10 +1232,10 @@ retry_flush_dents:
         * POR: we should ensure that there are no dirty node pages
         * until finishing nat/sit flush. inode->i_blocks can be updated.
         */
-       down_write(&sbi->node_change);
+       f2fs_down_write(&sbi->node_change);
 
        if (get_pages(sbi, F2FS_DIRTY_IMETA)) {
-               up_write(&sbi->node_change);
+               f2fs_up_write(&sbi->node_change);
                f2fs_unlock_all(sbi);
                err = f2fs_sync_inode_meta(sbi);
                if (err)
@@ -1241,15 +1245,15 @@ retry_flush_dents:
        }
 
 retry_flush_nodes:
-       down_write(&sbi->node_write);
+       f2fs_down_write(&sbi->node_write);
 
        if (get_pages(sbi, F2FS_DIRTY_NODES)) {
-               up_write(&sbi->node_write);
+               f2fs_up_write(&sbi->node_write);
                atomic_inc(&sbi->wb_sync_req[NODE]);
                err = f2fs_sync_node_pages(sbi, &wbc, false, FS_CP_NODE_IO);
                atomic_dec(&sbi->wb_sync_req[NODE]);
                if (err) {
-                       up_write(&sbi->node_change);
+                       f2fs_up_write(&sbi->node_change);
                        f2fs_unlock_all(sbi);
                        return err;
                }
@@ -1262,13 +1266,13 @@ retry_flush_nodes:
         * dirty node blocks and some checkpoint values by block allocation.
         */
        __prepare_cp_block(sbi);
-       up_write(&sbi->node_change);
+       f2fs_up_write(&sbi->node_change);
        return err;
 }
 
 static void unblock_operations(struct f2fs_sb_info *sbi)
 {
-       up_write(&sbi->node_write);
+       f2fs_up_write(&sbi->node_write);
        f2fs_unlock_all(sbi);
 }
 
@@ -1612,7 +1616,7 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
                f2fs_warn(sbi, "Start checkpoint disabled!");
        }
        if (cpc->reason != CP_RESIZE)
-               down_write(&sbi->cp_global_sem);
+               f2fs_down_write(&sbi->cp_global_sem);
 
        if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
                ((cpc->reason & CP_FASTBOOT) || (cpc->reason & CP_SYNC) ||
@@ -1693,7 +1697,7 @@ stop:
        trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish checkpoint");
 out:
        if (cpc->reason != CP_RESIZE)
-               up_write(&sbi->cp_global_sem);
+               f2fs_up_write(&sbi->cp_global_sem);
        return err;
 }
 
@@ -1741,9 +1745,9 @@ static int __write_checkpoint_sync(struct f2fs_sb_info *sbi)
        struct cp_control cpc = { .reason = CP_SYNC, };
        int err;
 
-       down_write(&sbi->gc_lock);
+       f2fs_down_write(&sbi->gc_lock);
        err = f2fs_write_checkpoint(sbi, &cpc);
-       up_write(&sbi->gc_lock);
+       f2fs_up_write(&sbi->gc_lock);
 
        return err;
 }
@@ -1831,9 +1835,9 @@ int f2fs_issue_checkpoint(struct f2fs_sb_info *sbi)
        if (!test_opt(sbi, MERGE_CHECKPOINT) || cpc.reason != CP_SYNC) {
                int ret;
 
-               down_write(&sbi->gc_lock);
+               f2fs_down_write(&sbi->gc_lock);
                ret = f2fs_write_checkpoint(sbi, &cpc);
-               up_write(&sbi->gc_lock);
+               f2fs_up_write(&sbi->gc_lock);
 
                return ret;
        }