]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: iterate past lower extents during punch
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 6 Feb 2014 20:29:15 +0000 (15:29 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 6 Feb 2014 20:29:33 +0000 (15:29 -0500)
When we're iterating extents during a punch operation, the loop exits
if the punch region is entirely to the right of the extent we're
looking at.  This can happen if the punch region starts in the middle
of a hole and covers mapped extents.  When this happens, we want to
skip to the next extent, because it might be punchable.

Also, if we've totally passed the punch range, stop.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/punch.c

index 25d79532bef6adf98674945d317119015deab655..657cb53d555187d4e407dd857f899ee7d07df298 100644 (file)
@@ -288,8 +288,12 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino,
                           (unsigned long long) end,
                           (unsigned long long) next);
                if (start <= extent.e_lblk) {
+                       /*
+                        * Have we iterated past the end of the punch region?
+                        * If so, we can stop.
+                        */
                        if (end < extent.e_lblk)
-                               goto next_extent;
+                               break;
                        dbg_printf("Case #%d\n", 1);
                        /* Start of deleted region before extent; 
                           adjust beginning of extent */
@@ -303,8 +307,13 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino,
                        extent.e_lblk += free_count;
                        extent.e_pblk += free_count;
                } else if (end >= next-1) {
+                       /*
+                        * Is the punch region beyond this extent?  This can
+                        * happen if start is already inside a hole.  Try to
+                        * advance to the next extent if this is the case.
+                        */
                        if (start >= next)
-                               break;
+                               goto next_extent;
                        /* End of deleted region after extent;
                           adjust end of extent */
                        dbg_printf("Case #%d\n", 2);