Merge tag 'f2fs-for-4.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeu...
[linux-2.6-block.git] / fs / f2fs / checkpoint.c
index 6b52d4b66c7b256c00609fdf38d5f3a958c7709d..dd2e73e10857a33428c6bfd35eba738d4d232e45 100644 (file)
@@ -304,25 +304,22 @@ long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
                                long nr_to_write, enum iostat_type io_type)
 {
        struct address_space *mapping = META_MAPPING(sbi);
-       pgoff_t index = 0, end = ULONG_MAX, prev = ULONG_MAX;
+       pgoff_t index = 0, prev = ULONG_MAX;
        struct pagevec pvec;
        long nwritten = 0;
+       int nr_pages;
        struct writeback_control wbc = {
                .for_reclaim = 0,
        };
        struct blk_plug plug;
 
-       pagevec_init(&pvec, 0);
+       pagevec_init(&pvec);
 
        blk_start_plug(&plug);
 
-       while (index <= end) {
-               int i, nr_pages;
-               nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
-                               PAGECACHE_TAG_DIRTY,
-                               min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
-               if (unlikely(nr_pages == 0))
-                       break;
+       while ((nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
+                               PAGECACHE_TAG_DIRTY))) {
+               int i;
 
                for (i = 0; i < nr_pages; i++) {
                        struct page *page = pvec.pages[i];
@@ -407,18 +404,16 @@ static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino,
        struct ino_entry *e, *tmp;
 
        tmp = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_NOFS);
-retry:
+
        radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
 
        spin_lock(&im->ino_lock);
        e = radix_tree_lookup(&im->ino_root, ino);
        if (!e) {
                e = tmp;
-               if (radix_tree_insert(&im->ino_root, ino, e)) {
-                       spin_unlock(&im->ino_lock);
-                       radix_tree_preload_end();
-                       goto retry;
-               }
+               if (unlikely(radix_tree_insert(&im->ino_root, ino, e)))
+                       f2fs_bug_on(sbi, 1);
+
                memset(e, 0, sizeof(struct ino_entry));
                e->ino = ino;
 
@@ -615,6 +610,9 @@ int recover_orphan_inodes(struct f2fs_sb_info *sbi)
        block_t start_blk, orphan_blocks, i, j;
        unsigned int s_flags = sbi->sb->s_flags;
        int err = 0;
+#ifdef CONFIG_QUOTA
+       int quota_enabled;
+#endif
 
        if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
                return 0;
@@ -627,8 +625,9 @@ int recover_orphan_inodes(struct f2fs_sb_info *sbi)
 #ifdef CONFIG_QUOTA
        /* Needed for iput() to work correctly and not trash data */
        sbi->sb->s_flags |= MS_ACTIVE;
+
        /* Turn on quotas so that they are updated correctly */
-       f2fs_enable_quota_files(sbi);
+       quota_enabled = f2fs_enable_quota_files(sbi, s_flags & MS_RDONLY);
 #endif
 
        start_blk = __start_cp_addr(sbi) + 1 + __cp_payload(sbi);
@@ -656,7 +655,8 @@ int recover_orphan_inodes(struct f2fs_sb_info *sbi)
 out:
 #ifdef CONFIG_QUOTA
        /* Turn quotas off */
-       f2fs_quota_off_umount(sbi->sb);
+       if (quota_enabled)
+               f2fs_quota_off_umount(sbi->sb);
 #endif
        sbi->sb->s_flags = s_flags; /* Restore MS_RDONLY status */
 
@@ -1011,7 +1011,7 @@ int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
                                update_inode_page(inode);
                        iput(inode);
                }
-       };
+       }
        return 0;
 }