Merge branch 'xfs-misc-fixes-for-3.18-2' into for-next
authorDave Chinner <david@fromorbit.com>
Tue, 23 Sep 2014 12:55:51 +0000 (22:55 +1000)
committerDave Chinner <david@fromorbit.com>
Tue, 23 Sep 2014 12:55:51 +0000 (22:55 +1000)
1  2 
fs/xfs/xfs_bmap_util.c

diff --combined fs/xfs/xfs_bmap_util.c
index 809ae7d395c3c244f479da92af33acac5f1b4d6d,1cb345e7c1819936f9517dd76cc428077208a593..d8b77b5bf4d9750c7258d536338d5559b2699e44
@@@ -1205,7 -1205,6 +1205,7 @@@ xfs_free_file_space
        xfs_bmap_free_t         free_list;
        xfs_bmbt_irec_t         imap;
        xfs_off_t               ioffset;
 +      xfs_off_t               iendoffset;
        xfs_extlen_t            mod=0;
        xfs_mount_t             *mp;
        int                     nimap;
        inode_dio_wait(VFS_I(ip));
  
        rounding = max_t(xfs_off_t, 1 << mp->m_sb.sb_blocklog, PAGE_CACHE_SIZE);
 -      ioffset = offset & ~(rounding - 1);
 -      error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
 -                                            ioffset, -1);
 +      ioffset = round_down(offset, rounding);
 +      iendoffset = round_up(offset + len, rounding) - 1;
 +      error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, ioffset,
 +                                           iendoffset);
        if (error)
                goto out;
 -      truncate_pagecache_range(VFS_I(ip), ioffset, -1);
 +      truncate_pagecache_range(VFS_I(ip), ioffset, iendoffset);
  
        /*
         * Need to zero the stuff we're not freeing, on disk.
@@@ -1458,50 -1456,24 +1458,50 @@@ xfs_collapse_file_space
        struct xfs_mount        *mp = ip->i_mount;
        struct xfs_trans        *tp;
        int                     error;
 -      xfs_extnum_t            current_ext = 0;
        struct xfs_bmap_free    free_list;
        xfs_fsblock_t           first_block;
        int                     committed;
        xfs_fileoff_t           start_fsb;
 +      xfs_fileoff_t           next_fsb;
        xfs_fileoff_t           shift_fsb;
  
        ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
  
        trace_xfs_collapse_file_space(ip);
  
 -      start_fsb = XFS_B_TO_FSB(mp, offset + len);
 +      next_fsb = XFS_B_TO_FSB(mp, offset + len);
        shift_fsb = XFS_B_TO_FSB(mp, len);
  
        error = xfs_free_file_space(ip, offset, len);
        if (error)
                return error;
  
 +      /*
 +       * Trim eofblocks to avoid shifting uninitialized post-eof preallocation
 +       * into the accessible region of the file.
 +       */
 +      if (xfs_can_free_eofblocks(ip, true)) {
 +              error = xfs_free_eofblocks(mp, ip, false);
 +              if (error)
 +                      return error;
 +      }
 +
 +      /*
 +       * Writeback and invalidate cache for the remainder of the file as we're
 +       * about to shift down every extent from the collapse range to EOF. The
 +       * free of the collapse range above might have already done some of
 +       * this, but we shouldn't rely on it to do anything outside of the range
 +       * that was freed.
 +       */
 +      error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
 +                                           offset + len, -1);
 +      if (error)
 +              return error;
 +      error = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping,
 +                                      (offset + len) >> PAGE_CACHE_SHIFT, -1);
 +      if (error)
 +              return error;
 +
        while (!error && !done) {
                tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT);
                /*
                 * We are using the write transaction in which max 2 bmbt
                 * updates are allowed
                 */
 -              error = xfs_bmap_shift_extents(tp, ip, &done, start_fsb,
 -                                             shift_fsb, &current_ext,
 -                                             &first_block, &free_list,
 -                                             XFS_BMAP_MAX_SHIFT_EXTENTS);
 +              start_fsb = next_fsb;
 +              error = xfs_bmap_shift_extents(tp, ip, start_fsb, shift_fsb,
 +                              &done, &next_fsb, &first_block, &free_list,
 +                              XFS_BMAP_MAX_SHIFT_EXTENTS);
                if (error)
                        goto out;
  
@@@ -1646,7 -1618,7 +1646,7 @@@ xfs_swap_extents_check_format
        return 0;
  }
  
- int
static int
  xfs_swap_extent_flush(
        struct xfs_inode        *ip)
  {