[Devel] [PATCH rh7 1/3] vfs: fix fallocate(FALLOC_FL_CONVERT_AND_EXTEND)

Maxim Patlasov mpatlasov at virtuozzo.com
Wed Mar 9 16:15:12 PST 2016


Modern vfs_fallocate() checks flags for sanity. To avoid EOPNOTSUPP error,
we have to list FALLOC_FL_CONVERT_AND_EXTEND among other valid flags. Also,
to keep checks uniform, the patch also enforces exclusiveness of the flag.

https://jira.sw.ru/browse/PSBM-22381

Signed-off-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
---
 fs/open.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/open.c b/fs/open.c
index 75b9d8e..22b9699 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -232,7 +232,8 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 
 	/* Return error if mode is not supported */
 	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
-		     FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE))
+		     FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
+		     FALLOC_FL_CONVERT_AND_EXTEND))
 		return -EOPNOTSUPP;
 
 	/* Punch hole and zero range are mutually exclusive */
@@ -250,6 +251,11 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	    (mode & ~FALLOC_FL_COLLAPSE_RANGE))
 		return -EINVAL;
 
+	/* Convert-and-extend should only be used exclusively. */
+	if ((mode & FALLOC_FL_CONVERT_AND_EXTEND) &&
+	    (mode & ~FALLOC_FL_CONVERT_AND_EXTEND))
+		return -EINVAL;
+
 	if (!(file->f_mode & FMODE_WRITE))
 		return -EBADF;
 



More information about the Devel mailing list