]> git.karo-electronics.de Git - linux-beck.git/commitdiff
xfs: factor rmap btree size into the indlen calculations
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 9 Jan 2017 15:38:40 +0000 (16:38 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Jan 2017 10:39:40 +0000 (11:39 +0100)
commit fd26a88093bab6529ea2de819114ca92dbd1d71d upstream.

When we're estimating the amount of space it's going to take to satisfy
a delalloc reservation, we need to include the space that we might need
to grow the rmapbt.  This helps us to avoid running out of space later
when _iomap_write_allocate needs more space than we reserved.  Eryu Guan
observed this happening on generic/224 when sunit/swidth were set.

Reported-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/xfs/libxfs/xfs_bmap.c

index 5c3c4dd1473564ba33eb98aeeae1d560d6da4b80..00188f559c8d75fd0d51fa463287df7f8be2fd52 100644 (file)
@@ -49,6 +49,7 @@
 #include "xfs_rmap.h"
 #include "xfs_ag_resv.h"
 #include "xfs_refcount.h"
+#include "xfs_rmap_btree.h"
 
 
 kmem_zone_t            *xfs_bmap_free_item_zone;
@@ -190,8 +191,12 @@ xfs_bmap_worst_indlen(
        int             maxrecs;        /* maximum record count at this level */
        xfs_mount_t     *mp;            /* mount structure */
        xfs_filblks_t   rval;           /* return value */
+       xfs_filblks_t   orig_len;
 
        mp = ip->i_mount;
+
+       /* Calculate the worst-case size of the bmbt. */
+       orig_len = len;
        maxrecs = mp->m_bmap_dmxr[0];
        for (level = 0, rval = 0;
             level < XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK);
@@ -199,12 +204,20 @@ xfs_bmap_worst_indlen(
                len += maxrecs - 1;
                do_div(len, maxrecs);
                rval += len;
-               if (len == 1)
-                       return rval + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) -
+               if (len == 1) {
+                       rval += XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) -
                                level - 1;
+                       break;
+               }
                if (level == 0)
                        maxrecs = mp->m_bmap_dmxr[1];
        }
+
+       /* Calculate the worst-case size of the rmapbt. */
+       if (xfs_sb_version_hasrmapbt(&mp->m_sb))
+               rval += 1 + xfs_rmapbt_calc_size(mp, orig_len) +
+                               mp->m_rmap_maxlevels;
+
        return rval;
 }