diff mbox

[v3,2/3] btrfs-progs: fi defrag: do not exit if defrag range ioctl is unsupported

Message ID 20171129021225.15509-1-suy.fnst@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Su Yue Nov. 29, 2017, 2:12 a.m. UTC
If ioctl of defrag range is unsupported, defrag will exit immediately.

Since caller can handle the error, let cmd_filesystem_defrag()
close file, break the loop and return error instead of calling exit(1).

Suggested-by: David Sterba <dsterba@suse.com>
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
Changelog:
v2:	Separate the patch from commit 6e991b9161fa ("btrfs-progs: fi
	defrag: clean up duplicate code if find errors").
v3:	Call close_file_or_dir() before breaking the loop.
---
 cmds-filesystem.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Qu Wenruo Nov. 30, 2017, 6:37 a.m. UTC | #1
On 2017年11月29日 10:12, Su Yue wrote:
> If ioctl of defrag range is unsupported, defrag will exit immediately.
> 
> Since caller can handle the error, let cmd_filesystem_defrag()
> close file, break the loop and return error instead of calling exit(1).
> 
> Suggested-by: David Sterba <dsterba@suse.com>
> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
> Changelog:
> v2:	Separate the patch from commit 6e991b9161fa ("btrfs-progs: fi
> 	defrag: clean up duplicate code if find errors").
> v3:	Call close_file_or_dir() before breaking the loop.
> ---
>  cmds-filesystem.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index 17d399d58adf..232d4e88e0c0 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -1049,8 +1049,10 @@ static int cmd_filesystem_defrag(int argc, char **argv)
>  		if (recursive && S_ISDIR(st.st_mode)) {
>  			ret = nftw(argv[i], defrag_callback, 10,
>  						FTW_MOUNT | FTW_PHYS);
> -			if (ret == ENOTTY)
> -				exit(1);
> +			if (ret == ENOTTY) {
> +				close_file_or_dir(fd, dirstream);
> +				break;
> +			}
>  			/* errors are handled in the callback */
>  			ret = 0;
>  		} else {
>
Qu Wenruo Nov. 30, 2017, 6:49 a.m. UTC | #2
On 2017年11月30日 14:37, Qu Wenruo wrote:
> 
> 
> On 2017年11月29日 10:12, Su Yue wrote:
>> If ioctl of defrag range is unsupported, defrag will exit immediately.
>>
>> Since caller can handle the error, let cmd_filesystem_defrag()
>> close file, break the loop and return error instead of calling exit(1).
>>
>> Suggested-by: David Sterba <dsterba@suse.com>
>> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
> 
> Reviewed-by: Qu Wenruo <wqu@suse.com>
> 
> Thanks,
> Qu

Please ignore my tag.

The best solution is mentioned in the 1st patch.

Thanks,
Qu

>> ---
>> Changelog:
>> v2:	Separate the patch from commit 6e991b9161fa ("btrfs-progs: fi
>> 	defrag: clean up duplicate code if find errors").
>> v3:	Call close_file_or_dir() before breaking the loop.
>> ---
>>  cmds-filesystem.c | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
>> index 17d399d58adf..232d4e88e0c0 100644
>> --- a/cmds-filesystem.c
>> +++ b/cmds-filesystem.c
>> @@ -1049,8 +1049,10 @@ static int cmd_filesystem_defrag(int argc, char **argv)
>>  		if (recursive && S_ISDIR(st.st_mode)) {
>>  			ret = nftw(argv[i], defrag_callback, 10,
>>  						FTW_MOUNT | FTW_PHYS);
>> -			if (ret == ENOTTY)
>> -				exit(1);
>> +			if (ret == ENOTTY) {
>> +				close_file_or_dir(fd, dirstream);
>> +				break;
>> +			}
>>  			/* errors are handled in the callback */
>>  			ret = 0;
>>  		} else {
>>
>
diff mbox

Patch

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 17d399d58adf..232d4e88e0c0 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -1049,8 +1049,10 @@  static int cmd_filesystem_defrag(int argc, char **argv)
 		if (recursive && S_ISDIR(st.st_mode)) {
 			ret = nftw(argv[i], defrag_callback, 10,
 						FTW_MOUNT | FTW_PHYS);
-			if (ret == ENOTTY)
-				exit(1);
+			if (ret == ENOTTY) {
+				close_file_or_dir(fd, dirstream);
+				break;
+			}
 			/* errors are handled in the callback */
 			ret = 0;
 		} else {