Skip to contentSkip to conversation

ext4: add error handling when discarding is fail in FITRIM ioctl.

PATCH RESEND In review Namjae Jeon 2 participants 2 messages Mar 4, 2012 – Mar 28, 2012 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 ext4: add error handling when discarding is fail in FITRIM ioctl.

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 #>

---
 fs/ext4/mballoc.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)
fs/ext4/mballoc.c +16 -8
index cb990b2..94182d4 100644
@@ -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;
 }
 
 /**
@@ -4951,7 +4953,7 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
 	void *bitmap;
 	ext4_grpblk_t next, count = 0, free_count = 0;
 	struct ext4_buddy e4b;
-	int ret;
+	int ret = 0;
 
 	trace_ext4_trim_all_free(sb, group, start, max);
 
@@ -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;
 }
 
 /**
Signature · 1 line
1.7.5.4
#1 lore raw

Hi Ted,

Can you please update us about the status of this patch? Please let us know in case there are any suggestions about this.
Looking forward to hear your opinion about the same.

Thanks & Regards,
Amit Sahrawat

Quoted 89 lines · Namjae Jeon

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 #>

---
 fs/ext4/mballoc.c |   24 ++++++++++++++++--------

 1 files changed, 16 insertions(+), 8 deletions(-)
fs/ext4/mballoc.c +16 -9
index cb990b2..94182d4 100644
@@ -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;
  }
 
  /**
@@ -4951,7 +4953,7 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
        void *bitmap;
        ext4_grpblk_t next, count = 0, free_count = 0;
        struct ext4_buddy e4b;
-       int ret;
+       int ret = 0;
 
        trace_ext4_trim_all_free(sb, group, start, max);
 
@@ -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;
  }
 
  /**
--
Quoted 2 lines

1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html