Skip to contentSkip to conversation

f2fs: ignore when len of range in f2fs_sec_trim_file is zero

PATCH In review Daeho Jeong 3 participants 5 messages Jul 9, 2020 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: ignore when len of range in f2fs_sec_trim_file is zero

From: Daeho Jeong <[email protected]>

When end_addr comes to zero, it'll trigger different behaviour. To prevent this, we need to ignore the case of that range.len is zero in the function.

---
 fs/f2fs/file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/f2fs/file.c +3 -4
index 368c80f8e2a1..98b0a8dbf669 100644
@@ -3813,15 +3813,14 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
 	file_start_write(filp);
 	inode_lock(inode);
 
-	if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode)) {
+	if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) ||
+			range.start >= inode->i_size) {
 		ret = -EINVAL;
 		goto err;
 	}
 
-	if (range.start >= inode->i_size) {
-		ret = -EINVAL;
+	if (range.len == 0)
 		goto err;
-	}
 
 	if (inode->i_size - range.start < range.len) {
 		ret = -E2BIG;
Signature · 1 line
2.27.0.383.g050319c2ae-goog
#1 lore raw
Quoted 24 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

When end_addr comes to zero, it'll trigger different behaviour. To prevent this, we need to ignore the case of that range.len is zero in the function.

---
 fs/f2fs/file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/f2fs/file.c +2 -1
index 368c80f8e2a1..98b0a8dbf669 100644
@@ -3813,15 +3813,14 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
 	file_start_write(filp);
 	inode_lock(inode);
 
-	if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode)) {
+	if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) ||
+			range.start >= inode->i_size) {
 		ret = -EINVAL;
 		goto err;

fs/f2fs/file.c static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) · line 3826

Quoted 10 lines
fs/f2fs/file.c +1 -3
 	}
 
-	if (range.start >= inode->i_size) {
-		ret = -EINVAL;
+	if (range.len == 0)
 		goto err;
-	}
 
 	if (inode->i_size - range.start < range.len) {
 		ret = -E2BIG;

How about the case trimming last partial written block?

i_size = 8000
range.start = 4096
range.len = 4096

Do we need to roundup(isize, PAGE_SIZE) before comparison?

Thanks,

Quoted 1 line
#2 lore raw

I thought it's better to treat this as the error case, since the range already passed out of the i_size range.
If we allow that, the user needs to send the range parameter being aligned like start:0 and len: roundup(i_size, PAGE_SIZE), even if he or she wants to erase the whole file.

2020년 7월 9일 (목) 오후 12:05, Chao Yu <[email protected]>님이 작성:

Quoted 48 lines · Daeho Jeong
Quoted 24 lines

From: Daeho Jeong <[email protected]>

When end_addr comes to zero, it'll trigger different behaviour. To prevent this, we need to ignore the case of that range.len is zero in the function.

---
 fs/f2fs/file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/f2fs/file.c +2 -1
index 368c80f8e2a1..98b0a8dbf669 100644
@@ -3813,15 +3813,14 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
      file_start_write(filp);
      inode_lock(inode);
 
-     if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode)) {
+     if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) ||
+                     range.start >= inode->i_size) {
              ret = -EINVAL;
              goto err;

fs/f2fs/file.c static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) · line 3826

Quoted 10 lines
fs/f2fs/file.c +1 -3
      }
 
-     if (range.start >= inode->i_size) {
-             ret = -EINVAL;
+     if (range.len == 0)
              goto err;
-     }
 
      if (inode->i_size - range.start < range.len) {
              ret = -E2BIG;

How about the case trimming last partial written block?

i_size = 8000
range.start = 4096
range.len = 4096

Do we need to roundup(isize, PAGE_SIZE) before comparison?

Thanks,

Quoted 1 line
maintainer
#3 lore raw
In reply to Chao Yu
Quoted 38 lines · Chao Yu
Quoted 24 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

When end_addr comes to zero, it'll trigger different behaviour. To prevent this, we need to ignore the case of that range.len is zero in the function.

---
 fs/f2fs/file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/f2fs/file.c +2 -1
index 368c80f8e2a1..98b0a8dbf669 100644
@@ -3813,15 +3813,14 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
 	file_start_write(filp);
 	inode_lock(inode);
 
-	if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode)) {
+	if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) ||
+			range.start >= inode->i_size) {
 		ret = -EINVAL;
 		goto err;

fs/f2fs/file.c static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) · line 3826

Quoted 10 lines
fs/f2fs/file.c +1 -3
 	}
 
-	if (range.start >= inode->i_size) {
-		ret = -EINVAL;
+	if (range.len == 0)
 		goto err;
-	}
 
 	if (inode->i_size - range.start < range.len) {
 		ret = -E2BIG;

How about the case trimming last partial written block?

Quoted 5 lines

i_size = 8000
range.start = 4096
range.len = 4096

Do we need to roundup(isize, PAGE_SIZE) before comparison?

If we want to trim whole file, do we need to give the exact i_size? Wouldn't it be better to give trim(0, -1)?

Quoted 10 lines

Thanks,

Quoted 1 line

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw

I can add it~

2020년 7월 9일 (목) 오후 2:39, Jaegeuk Kim <[email protected]>님이 작성:

Quoted 59 lines · Chao Yu
Quoted 38 lines · Daeho Jeong
Quoted 24 lines

From: Daeho Jeong <[email protected]>

When end_addr comes to zero, it'll trigger different behaviour. To prevent this, we need to ignore the case of that range.len is zero in the function.

---
 fs/f2fs/file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/f2fs/file.c +2 -1
index 368c80f8e2a1..98b0a8dbf669 100644
@@ -3813,15 +3813,14 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
    file_start_write(filp);
    inode_lock(inode);
 
-   if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode)) {
+   if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) ||
+                   range.start >= inode->i_size) {
            ret = -EINVAL;
            goto err;

fs/f2fs/file.c static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) · line 3826

Quoted 10 lines
fs/f2fs/file.c +1 -3
    }
 
-   if (range.start >= inode->i_size) {
-           ret = -EINVAL;
+   if (range.len == 0)
            goto err;
-   }
 
    if (inode->i_size - range.start < range.len) {
            ret = -E2BIG;

How about the case trimming last partial written block?

Quoted 5 lines

i_size = 8000
range.start = 4096
range.len = 4096

Do we need to roundup(isize, PAGE_SIZE) before comparison?

If we want to trim whole file, do we need to give the exact i_size? Wouldn't it be better to give trim(0, -1)?

Quoted 10 lines

Thanks,

Quoted 1 line

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel