Punching hole with a length which far larger than file size will
cause a long time looping in truncate_hole after lock_op, it can
be reproduced as the following:

        $ echo "abc" > file
        $ xfs_io -c "fpunch 0 HUGE_LENGTH" file

This may cause other I/Os blocked a long time. Let's fix this case
by setting the hole to end after the page that contains i_size.

Signed-off-by: Weichao Guo <[email protected]>
---
 fs/f2fs/file.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 517e112..1b44d26 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -873,6 +873,14 @@ static int punch_hole(struct inode *inode, loff_t offset, 
loff_t len)
        if (ret)
                return ret;
 
+       /*
+        * If the hole extends beyond i_size, set the hole
+        * to end after the page that contains i_size
+        */
+       if (offset + len > inode->i_size)
+               len = inode->i_size + PAGE_CACHE_SIZE -
+                       (inode->i_size & (PAGE_CACHE_SIZE - 1)) - offset;
+
        pg_start = ((unsigned long long) offset) >> PAGE_SHIFT;
        pg_end = ((unsigned long long) offset + len) >> PAGE_SHIFT;
 
-- 
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to