[Top] [All Lists]

[PATCH v2] xfs: fix the extent count when allocating an new indirection

To: "xfs@xxxxxxxxxxx" <xfs@xxxxxxxxxxx>
Subject: [PATCH v2] xfs: fix the extent count when allocating an new indirection array entry
From: Jeff Liu <jeff.liu@xxxxxxxxxx>
Date: Fri, 25 Oct 2013 14:52:44 +0800
Delivered-to: xfs@xxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1
From: Jie Liu <jeff.liu@xxxxxxxxxx>

At xfs_iext_add(), if extent(s) are being appended to the last page in
the indirection array and the new extent(s) don't fit in the page, the
number of extents(erp->er_extcount) in a new allocated entry should be
the minimum value between count and XFS_LINEAR_EXTS, instead of count.

For now, there is no existing test case can demonstrates a problem with
the er_extcount being set incorrectly here, but it obviously like a bug.

Signed-off-by: Jie Liu <jeff.liu@xxxxxxxxxx>
v2: * Declare count to uint as it will be decreased to 0 and XFS_LINEAR_EXTS
      can be uint because of a case in the macro.
    * Convert MIN() to min().
    * Revise the commits log to indicate there is no existing test case can
      reflect this issue for future tracking up.

 fs/xfs/xfs_inode_fork.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/xfs/xfs_inode_fork.c b/fs/xfs/xfs_inode_fork.c
index 22c9837..cfee14a 100644
--- a/fs/xfs/xfs_inode_fork.c
+++ b/fs/xfs/xfs_inode_fork.c
@@ -1021,15 +1021,14 @@ xfs_iext_add(
                 * the next index needed in the indirection array.
                else {
-                       int     count = ext_diff;
+                       uint    count = ext_diff;
                        while (count) {
                                erp = xfs_iext_irec_new(ifp, erp_idx);
-                               erp->er_extcount = count;
-                               count -= MIN(count, (int)XFS_LINEAR_EXTS);
-                               if (count) {
+                               erp->er_extcount = min(count, XFS_LINEAR_EXTS);
+                               count -= erp->er_extcount;
+                               if (count)
-                               }

<Prev in Thread] Current Thread [Next in Thread>