linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: add error handling when discarding is fail in FITRIM ioctl
@ 2012-01-21  7:56 Namjae Jeon
  2012-01-24 14:13 ` Jan Kara
  0 siblings, 1 reply; 4+ messages in thread
From: Namjae Jeon @ 2012-01-21  7:56 UTC (permalink / raw)
  To: tytso, adilger.kernel
  Cc: linux-ext4, linux-kernel, Namjae Jeon, Amit Sahrawat

Although free extents is proper not trimmed(mmc driver return error code while sending trim command), currently FITRIM ioctl return success.
I tried to add exception routine to inform user error code.

#> ./fitrim_test 
end_request: I/O error, dev mmcblk0, sector 27232
EXT4-fs warning (device mmcblk0): ext4_trim_all_free:4857: Discard command returned error -5
#>

Signed-off-by: Namjae Jeon <linkinjeon@gmail.com>
Signed-off-by: Amit Sahrawat <amit.sahrawat83@gmail.com>
---
 fs/ext4/mballoc.c |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index cb990b2..09cc09a 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4901,10 +4901,11 @@ error_return:
  * one will allocate those blocks, mark it as used in buddy bitmap. This must
  * be called with under the group lock.
  */
-static void ext4_trim_extent(struct super_block *sb, int start, int count,
+static int ext4_trim_extent(struct super_block *sb, int start, int count,
 			     ext4_group_t group, struct ext4_buddy *e4b)
 {
 	struct ext4_free_extent ex;
+	int err;
 
 	trace_ext4_trim_extent(sb, group, start, count);
 
@@ -4920,9 +4921,10 @@ static void ext4_trim_extent(struct super_block *sb, int start, int count,
 	 */
 	mb_mark_used(e4b, &ex);
 	ext4_unlock_group(sb, group);
-	ext4_issue_discard(sb, group, start, count);
+	err = ext4_issue_discard(sb, group, start, count);
 	ext4_lock_group(sb, group);
 	mb_free_blocks(NULL, e4b, start, ex.fe_len);
+	return err;
 }
 
 /**
@@ -4978,15 +4980,21 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
 		next = mb_find_next_bit(bitmap, max, start);
 
 		if ((next - start) >= minblocks) {
-			ext4_trim_extent(sb, start,
-					 next - start, group, &e4b);
-			count += next - start;
+			ret = ext4_trim_extent(sb, start,
+						next - start, group, &e4b);
+			if (ret < 0) {
+				if (ret != -EOPNOTSUPP)
+					ext4_warning(sb, "Discard command "
+						 "returned error %d\n", ret);
+				break;
+			} else
+				count += next - start;
 		}
 		free_count += next - start;
 		start = next + 1;
 
 		if (fatal_signal_pending(current)) {
-			count = -ERESTARTSYS;
+			ret = -ERESTARTSYS;
 			break;
 		}
 
@@ -5009,7 +5017,7 @@ out:
 	ext4_debug("trimmed %d blocks in the group %d\n",
 		count, group);
 
-	return count;
+	return (ret < 0) ? ret : count;
 }
 
 /**
-- 
1.7.5.4


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

* Re: [PATCH] ext4: add error handling when discarding is fail in FITRIM ioctl
  2012-01-21  7:56 [PATCH] ext4: add error handling when discarding is fail in FITRIM ioctl Namjae Jeon
@ 2012-01-24 14:13 ` Jan Kara
  2012-01-24 22:42   ` Namjae Jeon
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2012-01-24 14:13 UTC (permalink / raw)
  To: Namjae Jeon
  Cc: tytso, adilger.kernel, linux-ext4, linux-kernel, Amit Sahrawat

On Sat 21-01-12 02:56:12, Namjae Jeon wrote:
> Although free extents is proper not trimmed(mmc driver return error code while sending trim command), currently FITRIM ioctl return success.
> I tried to add exception routine to inform user error code.
> 
> #> ./fitrim_test 
> end_request: I/O error, dev mmcblk0, sector 27232
> EXT4-fs warning (device mmcblk0): ext4_trim_all_free:4857: Discard command returned error -5
> #>
> 
> Signed-off-by: Namjae Jeon <linkinjeon@gmail.com>
> Signed-off-by: Amit Sahrawat <amit.sahrawat83@gmail.com>
> ---
>  fs/ext4/mballoc.c |   22 +++++++++++++++-------
>  1 files changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index cb990b2..09cc09a 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -4901,10 +4901,11 @@ error_return:
>   * one will allocate those blocks, mark it as used in buddy bitmap. This must
>   * be called with under the group lock.
>   */
> -static void ext4_trim_extent(struct super_block *sb, int start, int count,
> +static int ext4_trim_extent(struct super_block *sb, int start, int count,
>  			     ext4_group_t group, struct ext4_buddy *e4b)
>  {
>  	struct ext4_free_extent ex;
> +	int err;
>  
>  	trace_ext4_trim_extent(sb, group, start, count);
>  
> @@ -4920,9 +4921,10 @@ static void ext4_trim_extent(struct super_block *sb, int start, int count,
>  	 */
>  	mb_mark_used(e4b, &ex);
>  	ext4_unlock_group(sb, group);
> -	ext4_issue_discard(sb, group, start, count);
> +	err = ext4_issue_discard(sb, group, start, count);
>  	ext4_lock_group(sb, group);
>  	mb_free_blocks(NULL, e4b, start, ex.fe_len);
> +	return err;
>  }
>  
>  /**
> @@ -4978,15 +4980,21 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
>  		next = mb_find_next_bit(bitmap, max, start);
>  
>  		if ((next - start) >= minblocks) {
> -			ext4_trim_extent(sb, start,
> -					 next - start, group, &e4b);
> -			count += next - start;
> +			ret = ext4_trim_extent(sb, start,
> +						next - start, group, &e4b);
> +			if (ret < 0) {
> +				if (ret != -EOPNOTSUPP)
> +					ext4_warning(sb, "Discard command "
> +						 "returned error %d\n", ret);
> +				break;
> +			} else
> +				count += next - start;
>  		}
>  		free_count += next - start;
>  		start = next + 1;
>  
>  		if (fatal_signal_pending(current)) {
> -			count = -ERESTARTSYS;
> +			ret = -ERESTARTSYS;
>  			break;
>  		}
>  
> @@ -5009,7 +5017,7 @@ out:
>  	ext4_debug("trimmed %d blocks in the group %d\n",
>  		count, group);
>  
> -	return count;
> +	return (ret < 0) ? ret : count;
  I think you need to initialize ret to 0 at the beginning of the function.
Otherwise you could use it uninitialized. Otherwise the patch looks good to
me and makes things consistent with ext3 so after fixing that bug you can add:
  Reviewed-by: Jan Kara <jack@suse.cz>

								Honza
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

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

* Re: [PATCH] ext4: add error handling when discarding is fail in FITRIM ioctl
  2012-01-24 14:13 ` Jan Kara
@ 2012-01-24 22:42   ` Namjae Jeon
  2012-02-09  4:26     ` Namjae Jeon
  0 siblings, 1 reply; 4+ messages in thread
From: Namjae Jeon @ 2012-01-24 22:42 UTC (permalink / raw)
  To: Jan Kara; +Cc: tytso, adilger.kernel, linux-ext4, linux-kernel, Amit Sahrawat

2012/1/24 Jan Kara <jack@suse.cz>:
> On Sat 21-01-12 02:56:12, Namjae Jeon wrote:
>> Although free extents is proper not trimmed(mmc driver return error code while sending trim command), currently FITRIM ioctl return success.
>> I tried to add exception routine to inform user error code.
>>
>> #> ./fitrim_test
>> end_request: I/O error, dev mmcblk0, sector 27232
>> EXT4-fs warning (device mmcblk0): ext4_trim_all_free:4857: Discard command returned error -5
>> #>
>>
>> Signed-off-by: Namjae Jeon <linkinjeon@gmail.com>
>> Signed-off-by: Amit Sahrawat <amit.sahrawat83@gmail.com>
>> ---
>>  fs/ext4/mballoc.c |   22 +++++++++++++++-------
>>  1 files changed, 15 insertions(+), 7 deletions(-)
>>
>> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
>> index cb990b2..09cc09a 100644
>> --- a/fs/ext4/mballoc.c
>> +++ b/fs/ext4/mballoc.c
>> @@ -4901,10 +4901,11 @@ error_return:
>>   * one will allocate those blocks, mark it as used in buddy bitmap. This must
>>   * be called with under the group lock.
>>   */
>> -static void ext4_trim_extent(struct super_block *sb, int start, int count,
>> +static int ext4_trim_extent(struct super_block *sb, int start, int count,
>>                            ext4_group_t group, struct ext4_buddy *e4b)
>>  {
>>       struct ext4_free_extent ex;
>> +     int err;
>>
>>       trace_ext4_trim_extent(sb, group, start, count);
>>
>> @@ -4920,9 +4921,10 @@ static void ext4_trim_extent(struct super_block *sb, int start, int count,
>>        */
>>       mb_mark_used(e4b, &ex);
>>       ext4_unlock_group(sb, group);
>> -     ext4_issue_discard(sb, group, start, count);
>> +     err = ext4_issue_discard(sb, group, start, count);
>>       ext4_lock_group(sb, group);
>>       mb_free_blocks(NULL, e4b, start, ex.fe_len);
>> +     return err;
>>  }
>>
>>  /**
>> @@ -4978,15 +4980,21 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
>>               next = mb_find_next_bit(bitmap, max, start);
>>
>>               if ((next - start) >= minblocks) {
>> -                     ext4_trim_extent(sb, start,
>> -                                      next - start, group, &e4b);
>> -                     count += next - start;
>> +                     ret = ext4_trim_extent(sb, start,
>> +                                             next - start, group, &e4b);
>> +                     if (ret < 0) {
>> +                             if (ret != -EOPNOTSUPP)
>> +                                     ext4_warning(sb, "Discard command "
>> +                                              "returned error %d\n", ret);
>> +                             break;
>> +                     } else
>> +                             count += next - start;
>>               }
>>               free_count += next - start;
>>               start = next + 1;
>>
>>               if (fatal_signal_pending(current)) {
>> -                     count = -ERESTARTSYS;
>> +                     ret = -ERESTARTSYS;
>>                       break;
>>               }
>>
>> @@ -5009,7 +5017,7 @@ out:
>>       ext4_debug("trimmed %d blocks in the group %d\n",
>>               count, group);
>>
>> -     return count;
>> +     return (ret < 0) ? ret : count;
>  I think you need to initialize ret to 0 at the beginning of the function.
> Otherwise you could use it uninitialized. Otherwise the patch looks good to
> me and makes things consistent with ext3 so after fixing that bug you can add:
>  Reviewed-by: Jan Kara <jack@suse.cz>
Hi. Jan.
Thanks for your review.~
>
>                                                                Honza
> --
> Jan Kara <jack@suse.cz>
> SUSE Labs, CR

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

* Re: [PATCH] ext4: add error handling when discarding is fail in FITRIM ioctl
  2012-01-24 22:42   ` Namjae Jeon
@ 2012-02-09  4:26     ` Namjae Jeon
  0 siblings, 0 replies; 4+ messages in thread
From: Namjae Jeon @ 2012-02-09  4:26 UTC (permalink / raw)
  To: tytso; +Cc: adilger.kernel, linux-ext4, linux-kernel, Jan Kara

Hi. Ted.

Would you check this patch ? maybe, this patch was posted during your vacation.

Thanks.

2012/1/25 Namjae Jeon <linkinjeon@gmail.com>:
> 2012/1/24 Jan Kara <jack@suse.cz>:
>> On Sat 21-01-12 02:56:12, Namjae Jeon wrote:
>>> Although free extents is proper not trimmed(mmc driver return error code while sending trim command), currently FITRIM ioctl return success.
>>> I tried to add exception routine to inform user error code.
>>>
>>> #> ./fitrim_test
>>> end_request: I/O error, dev mmcblk0, sector 27232
>>> EXT4-fs warning (device mmcblk0): ext4_trim_all_free:4857: Discard command returned error -5
>>> #>
>>>
>>> Signed-off-by: Namjae Jeon <linkinjeon@gmail.com>
>>> Signed-off-by: Amit Sahrawat <amit.sahrawat83@gmail.com>
>>> ---
>>>  fs/ext4/mballoc.c |   22 +++++++++++++++-------
>>>  1 files changed, 15 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
>>> index cb990b2..09cc09a 100644
>>> --- a/fs/ext4/mballoc.c
>>> +++ b/fs/ext4/mballoc.c
>>> @@ -4901,10 +4901,11 @@ error_return:
>>>   * one will allocate those blocks, mark it as used in buddy bitmap. This must
>>>   * be called with under the group lock.
>>>   */
>>> -static void ext4_trim_extent(struct super_block *sb, int start, int count,
>>> +static int ext4_trim_extent(struct super_block *sb, int start, int count,
>>>                            ext4_group_t group, struct ext4_buddy *e4b)
>>>  {
>>>       struct ext4_free_extent ex;
>>> +     int err;
>>>
>>>       trace_ext4_trim_extent(sb, group, start, count);
>>>
>>> @@ -4920,9 +4921,10 @@ static void ext4_trim_extent(struct super_block *sb, int start, int count,
>>>        */
>>>       mb_mark_used(e4b, &ex);
>>>       ext4_unlock_group(sb, group);
>>> -     ext4_issue_discard(sb, group, start, count);
>>> +     err = ext4_issue_discard(sb, group, start, count);
>>>       ext4_lock_group(sb, group);
>>>       mb_free_blocks(NULL, e4b, start, ex.fe_len);
>>> +     return err;
>>>  }
>>>
>>>  /**
>>> @@ -4978,15 +4980,21 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
>>>               next = mb_find_next_bit(bitmap, max, start);
>>>
>>>               if ((next - start) >= minblocks) {
>>> -                     ext4_trim_extent(sb, start,
>>> -                                      next - start, group, &e4b);
>>> -                     count += next - start;
>>> +                     ret = ext4_trim_extent(sb, start,
>>> +                                             next - start, group, &e4b);
>>> +                     if (ret < 0) {
>>> +                             if (ret != -EOPNOTSUPP)
>>> +                                     ext4_warning(sb, "Discard command "
>>> +                                              "returned error %d\n", ret);
>>> +                             break;
>>> +                     } else
>>> +                             count += next - start;
>>>               }
>>>               free_count += next - start;
>>>               start = next + 1;
>>>
>>>               if (fatal_signal_pending(current)) {
>>> -                     count = -ERESTARTSYS;
>>> +                     ret = -ERESTARTSYS;
>>>                       break;
>>>               }
>>>
>>> @@ -5009,7 +5017,7 @@ out:
>>>       ext4_debug("trimmed %d blocks in the group %d\n",
>>>               count, group);
>>>
>>> -     return count;
>>> +     return (ret < 0) ? ret : count;
>>  I think you need to initialize ret to 0 at the beginning of the function.
>> Otherwise you could use it uninitialized. Otherwise the patch looks good to
>> me and makes things consistent with ext3 so after fixing that bug you can add:
>>  Reviewed-by: Jan Kara <jack@suse.cz>
> Hi. Jan.
> Thanks for your review.~
>>
>>                                                                Honza
>> --
>> Jan Kara <jack@suse.cz>
>> SUSE Labs, CR

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

end of thread, other threads:[~2012-02-09  4:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-21  7:56 [PATCH] ext4: add error handling when discarding is fail in FITRIM ioctl Namjae Jeon
2012-01-24 14:13 ` Jan Kara
2012-01-24 22:42   ` Namjae Jeon
2012-02-09  4:26     ` Namjae Jeon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).