Skip to contentSkip to conversation

f2fs: Add offset check routine before punch_hole() in f2fs_fallocate()

PATCH Superseded Taehee Yoo 2 participants 3 messages Apr 20, 2015 – Apr 21, 2015 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH 1/1 f2fs: Add offset check routine before punch_hole() in f2fs_fallocate()

In the punch_hole(), if offset bigger than inode size, it returns SUCCESS. Then f2fs_fallocate() will update time and dirty mark.
In that case, inode has not been modified actually.
So I have added offset check routine that prevent to call the punch_hole().

---
 fs/f2fs/file.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/f2fs/file.c +7 -2
index a6f3f61..6470831 100644
@@ -830,15 +830,19 @@ static long f2fs_fallocate(struct file *file, int mode,
 				loff_t offset, loff_t len)
 {
 	struct inode *inode = file_inode(file);
-	long ret;
+	long ret = 0;
 
 	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
 		return -EOPNOTSUPP;
 
 	mutex_lock(&inode->i_mutex);
 
-	if (mode & FALLOC_FL_PUNCH_HOLE)
+	if (mode & FALLOC_FL_PUNCH_HOLE) {
+		if (offset >= inode->i_size)
+			goto out;
+
 		ret = punch_hole(inode, offset, len);
+	}
 	else
 		ret = expand_inode_data(inode, offset, len, mode);
 
@@ -847,6 +851,7 @@ static long f2fs_fallocate(struct file *file, int mode,
 		mark_inode_dirty(inode);
 	}
 
+out:
 	mutex_unlock(&inode->i_mutex);
 
 	trace_f2fs_fallocate(inode, mode, offset, len, ret);
Signature · 9 lines
1.9.1


------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
#1 lore raw

Hi Taehee,

Quoted 11 lines

-----Original Message-----
From: Taehee Yoo [mailto:[email protected]]
Sent: Monday, April 20, 2015 4:46 PM
To: [email protected]; [email protected]; [email protected]
Subject: [f2fs-dev] [PATCH] f2fs: Add offset check routine before punch_hole() in f2fs_fallocate()

In the punch_hole(), if offset bigger than inode size, it returns SUCCESS. Then f2fs_fallocate() will update time and dirty mark.
In that case, inode has not been modified actually.
So I have added offset check routine that prevent to call the punch_hole().

Nice catch!

This patch makes size verification in punch_hole() redundant, how about removing it?

Thanks,

Quoted 41 lines
---
 fs/f2fs/file.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/f2fs/file.c +7 -3
index a6f3f61..6470831 100644
@@ -830,15 +830,19 @@ static long f2fs_fallocate(struct file *file, int mode,
 				loff_t offset, loff_t len)
 {
 	struct inode *inode = file_inode(file);
-	long ret;
+	long ret = 0;
 
 	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
 		return -EOPNOTSUPP;
 
 	mutex_lock(&inode->i_mutex);
 
-	if (mode & FALLOC_FL_PUNCH_HOLE)
+	if (mode & FALLOC_FL_PUNCH_HOLE) {
+		if (offset >= inode->i_size)
+			goto out;
+
 		ret = punch_hole(inode, offset, len);
+	}
 	else
 		ret = expand_inode_data(inode, offset, len, mode);
 
@@ -847,6 +851,7 @@ static long f2fs_fallocate(struct file *file, int mode,
 		mark_inode_dirty(inode);
 	}
 
+out:
 	mutex_unlock(&inode->i_mutex);
 
 	trace_f2fs_fallocate(inode, mode, offset, len, ret);
--
Quoted 2 lines

1.9.1

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF

author
#2 lore raw

2015-04-21 14:38 GMT+09:00 Chao Yu <[email protected]>:

Quoted 57 lines

Hi Taehee,

Quoted 11 lines

-----Original Message-----
From: Taehee Yoo [mailto:[email protected]]
Sent: Monday, April 20, 2015 4:46 PM
To: [email protected]; [email protected]; [email protected]
Subject: [f2fs-dev] [PATCH] f2fs: Add offset check routine before punch_hole() in f2fs_fallocate()

In the punch_hole(), if offset bigger than inode size, it returns SUCCESS. Then f2fs_fallocate() will update time and dirty mark.
In that case, inode has not been modified actually.
So I have added offset check routine that prevent to call the punch_hole().

Nice catch!

This patch makes size verification in punch_hole() redundant, how about removing it?

Thanks,

Quoted 36 lines
---
 fs/f2fs/file.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/f2fs/file.c +6 -2
index a6f3f61..6470831 100644
@@ -830,15 +830,19 @@ static long f2fs_fallocate(struct file *file, int mode,
                              loff_t offset, loff_t len)
 {
      struct inode *inode = file_inode(file);
-     long ret;
+     long ret = 0;
 
      if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
              return -EOPNOTSUPP;
 
      mutex_lock(&inode->i_mutex);
 
-     if (mode & FALLOC_FL_PUNCH_HOLE)
+     if (mode & FALLOC_FL_PUNCH_HOLE) {
+             if (offset >= inode->i_size)
+                     goto out;
+
              ret = punch_hole(inode, offset, len);
+     }
      else
              ret = expand_inode_data(inode, offset, len, mode);
 
@@ -847,6 +851,7 @@ static long f2fs_fallocate(struct file *file, int mode,
              mark_inode_dirty(inode);
      }
 
Quoted 9 lines
Quoted 7 lines
fs/f2fs/file.c +1 -1
+out:
      mutex_unlock(&inode->i_mutex);
 
      trace_f2fs_fallocate(inode, mode, offset, len, ret);
--

1.9.1

I agree with your idea. and I will send V2 patch soon.

Thanks a lot for your review!

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF