Merge tag 'for-5.8-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 12 Jul 2020 17:58:35 +0000 (10:58 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 12 Jul 2020 17:58:35 +0000 (10:58 -0700)
Pull btrfs fixes from David Sterba:
 "Two refcounting fixes and one prepartory patch for upcoming splice
  cleanup:

   - fix double put of block group with nodatacow

   - fix missing block group put when remounting with discard=async

   - explicitly set splice callback (no functional change), to ease
     integrating splice cleanup patches"

* tag 'for-5.8-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
  btrfs: wire up iter_file_splice_write
  btrfs: fix double put of block group with nocow
  btrfs: discard: add missing put when grabbing block group from unused list

1  2 
fs/btrfs/inode.c

diff --combined fs/btrfs/inode.c
@@@ -1690,12 -1690,8 +1690,8 @@@ out_check
                        ret = fallback_to_cow(inode, locked_page, cow_start,
                                              found_key.offset - 1,
                                              page_started, nr_written);
-                       if (ret) {
-                               if (nocow)
-                                       btrfs_dec_nocow_writers(fs_info,
-                                                               disk_bytenr);
+                       if (ret)
                                goto error;
-                       }
                        cow_start = (u64)-1;
                }
  
                                          ram_bytes, BTRFS_COMPRESS_NONE,
                                          BTRFS_ORDERED_PREALLOC);
                        if (IS_ERR(em)) {
-                               if (nocow)
-                                       btrfs_dec_nocow_writers(fs_info,
-                                                               disk_bytenr);
                                ret = PTR_ERR(em);
                                goto error;
                        }
@@@ -4932,8 -4925,8 +4925,8 @@@ static void evict_inode_truncate_pages(
  
        /*
         * Keep looping until we have no more ranges in the io tree.
 -       * We can have ongoing bios started by readpages (called from readahead)
 -       * that have their endio callback (extent_io.c:end_bio_extent_readpage)
 +       * We can have ongoing bios started by readahead that have
 +       * their endio callback (extent_io.c:end_bio_extent_readpage)
         * still in progress (unlocked the pages in the bio but did not yet
         * unlocked the ranges in the io tree). Therefore this means some
         * ranges can still be locked and eviction started because before
@@@ -7128,11 -7121,11 +7121,11 @@@ static int lock_extent_direct(struct in
                         * for it to complete) and then invalidate the pages for
                         * this range (through invalidate_inode_pages2_range()),
                         * but that can lead us to a deadlock with a concurrent
 -                       * call to readpages() (a buffered read or a defrag call
 +                       * call to readahead (a buffered read or a defrag call
                         * triggered a readahead) on a page lock due to an
                         * ordered dio extent we created before but did not have
                         * yet a corresponding bio submitted (whence it can not
 -                       * complete), which makes readpages() wait for that
 +                       * complete), which makes readahead wait for that
                         * ordered extent to complete while holding a lock on
                         * that page.
                         */
        return ret;
  }
  
 -#define BTRFS_FIEMAP_FLAGS    (FIEMAP_FLAG_SYNC)
 -
  static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
                __u64 start, __u64 len)
  {
        int     ret;
  
 -      ret = fiemap_check_flags(fieinfo, BTRFS_FIEMAP_FLAGS);
 +      ret = fiemap_prep(inode, fieinfo, start, &len, 0);
        if (ret)
                return ret;
  
@@@ -8000,16 -7995,21 +7993,16 @@@ static int btrfs_writepages(struct addr
        return extent_writepages(mapping, wbc);
  }
  
 -static int
 -btrfs_readpages(struct file *file, struct address_space *mapping,
 -              struct list_head *pages, unsigned nr_pages)
 +static void btrfs_readahead(struct readahead_control *rac)
  {
 -      return extent_readpages(mapping, pages, nr_pages);
 +      extent_readahead(rac);
  }
  
  static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags)
  {
        int ret = try_release_extent_mapping(page, gfp_flags);
 -      if (ret == 1) {
 -              ClearPagePrivate(page);
 -              set_page_private(page, 0);
 -              put_page(page);
 -      }
 +      if (ret == 1)
 +              detach_page_private(page);
        return ret;
  }
  
@@@ -8031,8 -8031,14 +8024,8 @@@ static int btrfs_migratepage(struct add
        if (ret != MIGRATEPAGE_SUCCESS)
                return ret;
  
 -      if (page_has_private(page)) {
 -              ClearPagePrivate(page);
 -              get_page(newpage);
 -              set_page_private(newpage, page_private(page));
 -              set_page_private(page, 0);
 -              put_page(page);
 -              SetPagePrivate(newpage);
 -      }
 +      if (page_has_private(page))
 +              attach_page_private(newpage, detach_page_private(page));
  
        if (PagePrivate2(page)) {
                ClearPagePrivate2(page);
@@@ -8154,7 -8160,11 +8147,7 @@@ again
        }
  
        ClearPageChecked(page);
 -      if (PagePrivate(page)) {
 -              ClearPagePrivate(page);
 -              set_page_private(page, 0);
 -              put_page(page);
 -      }
 +      detach_page_private(page);
  }
  
  /*
@@@ -10245,7 -10255,7 +10238,7 @@@ static const struct address_space_opera
        .readpage       = btrfs_readpage,
        .writepage      = btrfs_writepage,
        .writepages     = btrfs_writepages,
 -      .readpages      = btrfs_readpages,
 +      .readahead      = btrfs_readahead,
        .direct_IO      = btrfs_direct_IO,
        .invalidatepage = btrfs_invalidatepage,
        .releasepage    = btrfs_releasepage,