All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] btrfs: add goto in btrfs_defrag_file for error handling
@ 2021-05-05  1:26 Tian Tao
  2021-05-05 22:40 ` Boris Burkov
  0 siblings, 1 reply; 3+ messages in thread
From: Tian Tao @ 2021-05-05  1:26 UTC (permalink / raw)
  To: dsterba, josef, clm; +Cc: linux-btrfs, Tian Tao

ret is assigned -EAGAIN at line 1455 and then reassigned defrag_count
at line 1547 after exiting the while loop.this causes the
btrfs_defrag_file function to not return the correct value in the event
of an error, this patch fixed this issue.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
---

v2: rewrite the patch, patch name and commit message.
---
 fs/btrfs/ioctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index ee1dbab..5713450 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1453,7 +1453,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 		if (btrfs_defrag_cancelled(fs_info)) {
 			btrfs_debug(fs_info, "defrag_file cancelled");
 			ret = -EAGAIN;
-			break;
+			goto error;
 		}
 
 		if (!should_defrag_range(inode, (u64)i << PAGE_SHIFT,
@@ -1531,6 +1531,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 		}
 	}
 
+	ret = defrag_count;
+error:
 	if ((range->flags & BTRFS_DEFRAG_RANGE_START_IO)) {
 		filemap_flush(inode->i_mapping);
 		if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
@@ -1544,8 +1546,6 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 		btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
 	}
 
-	ret = defrag_count;
-
 out_ra:
 	if (do_compress) {
 		btrfs_inode_lock(inode, 0);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-17 13:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05  1:26 [PATCH v2] btrfs: add goto in btrfs_defrag_file for error handling Tian Tao
2021-05-05 22:40 ` Boris Burkov
2021-05-17 13:00   ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.