Skip to contentSkip to conversation

f2fs: move the conditional statement after holding the inode lock in f2fs_fallocate()

PATCH Superseded Yangtao Li 2 participants 2 messages May 6, 2023 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 2/2 f2fs: move the conditional statement after holding the inode lock in f2fs_fallocate()

For judging the inode flag state, the inode lock must be held.

Fixes fcc85a4d86b5 ("f2fs crypto: activate encryption support for fs APIs")
---
 fs/f2fs/file.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
fs/f2fs/file.c +7 -7
index 850e745ecf88..0837c500b990 100644
@@ -1801,6 +1801,13 @@ static long f2fs_fallocate(struct file *file, int mode,
 	if (!S_ISREG(inode->i_mode))
 		return -EINVAL;
 
+	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
+			FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
+			FALLOC_FL_INSERT_RANGE))
+		return -EOPNOTSUPP;
+
+	inode_lock(inode);
+
 	if (IS_ENCRYPTED(inode) &&
 		(mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)))
 		return -EOPNOTSUPP;
@@ -1814,13 +1821,6 @@ static long f2fs_fallocate(struct file *file, int mode,
 			FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE)))
 		return -EOPNOTSUPP;
 
-	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
-			FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
-			FALLOC_FL_INSERT_RANGE))
-		return -EOPNOTSUPP;
-
-	inode_lock(inode);
-
 	ret = file_modified(file);
 	if (ret)
 		goto out;
Signature · 1 line
2.39.0
#1 lore raw

Le 06/05/2023 à 13:40, Yangtao Li a écrit :

Quoted 16 lines

For judging the inode flag state, the inode lock must be held.

Fixes fcc85a4d86b5 ("f2fs crypto: activate encryption support for fs APIs")
---
  fs/f2fs/file.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
fs/f2fs/file.c +0 -0
index 850e745ecf88..0837c500b990 100644
@@ -1801,6 +1801,13 @@ static long f2fs_fallocate(struct file *file, int mode,
  	if (!S_ISREG(inode->i_mode))
  		return -EINVAL;
 

fs/f2fs/file.c static long f2fs_fallocate(struct file *file, int mode, · line 1813

Quoted 10 lines
fs/f2fs/file.c +7 -0
+	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
+			FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
+			FALLOC_FL_INSERT_RANGE))
+		return -EOPNOTSUPP;
+
+	inode_lock(inode);
+
  	if (IS_ENCRYPTED(inode) &&
  		(mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)))
  		return -EOPNOTSUPP;

ret = -EOPNOTSUPP;
goto out;

here and in some other places below.

Maybe the code should de rearranged another way if trace_f2fs_fallocate() should not be called in such cases.

CJ

Quoted 14 lines
fs/f2fs/file.c +0 -7
@@ -1814,13 +1821,6 @@ static long f2fs_fallocate(struct file *file, int mode,
  			FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE)))
  		return -EOPNOTSUPP;
 
-	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
-			FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
-			FALLOC_FL_INSERT_RANGE))
-		return -EOPNOTSUPP;
-
-	inode_lock(inode);
-
  	ret = file_modified(file);
  	if (ret)
  		goto out;