f2fs: do not allow partial truncation on pinned file
authorJaegeuk Kim <jaegeuk@kernel.org>
Sat, 8 Jan 2022 04:08:45 +0000 (20:08 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 10 Jan 2022 17:05:09 +0000 (09:05 -0800)
If the pinned file has a hole by partial truncation, application that has
the block map will be broken.

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/file.c

index f540c1cbddca40581965256cf58f28636e9d573c..3c98ef6af97d139db476e060afb35514d8e18d58 100644 (file)
@@ -1750,7 +1750,11 @@ static long f2fs_fallocate(struct file *file, int mode,
                (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)))
                return -EOPNOTSUPP;
 
-       if (f2fs_compressed_file(inode) &&
+       /*
+        * Pinned file should not support partial trucation since the block
+        * can be used by applications.
+        */
+       if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) &&
                (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
                        FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE)))
                return -EOPNOTSUPP;