Skip to contentSkip to conversation

ext4: enable FITRIM ioctl on bigalloc file system

PATCH Applied Lukas Czerner 3 participants 6 messages Jul 3, 2012 – Sep 27, 2012 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: enable FITRIM ioctl on bigalloc file system

With a minor tweaks regarding minimum extent size to discard and discarded bytes reporting the FITRIM can be enabled on bigalloc file system and it works without any problem.

This patch fixes minlen handling and discarded bytes reporting to take into consideration bigalloc enabled file systems and finally removes the restriction and allow FITRIM to be used on file system with bigalloc feature enabled.

---
 fs/ext4/ioctl.c   |    7 -------
 fs/ext4/mballoc.c |    5 +++--
 2 files changed, 3 insertions(+), 9 deletions(-)
fs/ext4/ioctl.c +0 -7
index e34deac..9d6e0bc 100644
@@ -420,13 +420,6 @@ resizefs_out:
 		if (!blk_queue_discard(q))
 			return -EOPNOTSUPP;
 
-		if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
-			       EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
-			ext4_msg(sb, KERN_ERR,
-				 "FITRIM not supported with bigalloc");
-			return -EOPNOTSUPP;
-		}
-
 		if (copy_from_user(&range, (struct fstrim_range __user *)arg,
 		    sizeof(range)))
 			return -EFAULT;
fs/ext4/mballoc.c +3 -2
index 1cd6994..c4bd0a6 100644
@@ -4984,7 +4984,8 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 
 	start = range->start >> sb->s_blocksize_bits;
 	end = start + (range->len >> sb->s_blocksize_bits) - 1;
-	minlen = range->minlen >> sb->s_blocksize_bits;
+	minlen = EXT4_NUM_B2C(EXT4_SB(sb),
+			      range->minlen >> sb->s_blocksize_bits);
 
 	if (unlikely(minlen > EXT4_CLUSTERS_PER_GROUP(sb)) ||
 	    unlikely(start >= max_blks))
@@ -5044,6 +5045,6 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 		atomic_set(&EXT4_SB(sb)->s_last_trim_minblks, minlen);
 
 out:
-	range->len = trimmed * sb->s_blocksize;
+	range->len = EXT4_C2B(EXT4_SB(sb), trimmed) << sb->s_blocksize_bits;
 	return ret;
 }
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 6 lines · Lukas Czerner

Date: Tue, 3 Jul 2012 21:10:42 +0200
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], Lukas Czerner <[email protected]>
Subject: [PATCH] ext4: enable FITRIM ioctl on bigalloc file system

Quoted 8 lines

With a minor tweaks regarding minimum extent size to discard and discarded bytes reporting the FITRIM can be enabled on bigalloc file system and it works without any problem.

This patch fixes minlen handling and discarded bytes reporting to take into consideration bigalloc enabled file systems and finally removes the restriction and allow FITRIM to be used on file system with bigalloc feature enabled.

any comments on this ?

Thanks!
-Lukas

Quoted 48 lines
---
 fs/ext4/ioctl.c   |    7 -------
 fs/ext4/mballoc.c |    5 +++--
 2 files changed, 3 insertions(+), 9 deletions(-)
fs/ext4/ioctl.c +0 -7
index e34deac..9d6e0bc 100644
@@ -420,13 +420,6 @@ resizefs_out:
 		if (!blk_queue_discard(q))
 			return -EOPNOTSUPP;
 
-		if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
-			       EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
-			ext4_msg(sb, KERN_ERR,
-				 "FITRIM not supported with bigalloc");
-			return -EOPNOTSUPP;
-		}
-
 		if (copy_from_user(&range, (struct fstrim_range __user *)arg,
 		    sizeof(range)))
 			return -EFAULT;
fs/ext4/mballoc.c +3 -2
index 1cd6994..c4bd0a6 100644
@@ -4984,7 +4984,8 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 
 	start = range->start >> sb->s_blocksize_bits;
 	end = start + (range->len >> sb->s_blocksize_bits) - 1;
-	minlen = range->minlen >> sb->s_blocksize_bits;
+	minlen = EXT4_NUM_B2C(EXT4_SB(sb),
+			      range->minlen >> sb->s_blocksize_bits);
 
 	if (unlikely(minlen > EXT4_CLUSTERS_PER_GROUP(sb)) ||
 	    unlikely(start >= max_blks))
@@ -5044,6 +5045,6 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 		atomic_set(&EXT4_SB(sb)->s_last_trim_minblks, minlen);
 
 out:
-	range->len = trimmed * sb->s_blocksize;
+	range->len = EXT4_C2B(EXT4_SB(sb), trimmed) << sb->s_blocksize_bits;
 	return ret;
 }
#2 lore raw
Quoted 23 lines · Lukáš Czerner

Date: Tue, 21 Aug 2012 11:48:27 +0200 (CEST)
From: Lukáš Czerner <[email protected]>
To: Lukas Czerner <[email protected]>
Cc: [email protected], [email protected]
Subject: Re: [PATCH] ext4: enable FITRIM ioctl on bigalloc file system

Quoted 6 lines · Lukas Czerner

Date: Tue, 3 Jul 2012 21:10:42 +0200
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], Lukas Czerner <[email protected]>
Subject: [PATCH] ext4: enable FITRIM ioctl on bigalloc file system

Quoted 8 lines

With a minor tweaks regarding minimum extent size to discard and discarded bytes reporting the FITRIM can be enabled on bigalloc file system and it works without any problem.

This patch fixes minlen handling and discarded bytes reporting to take into consideration bigalloc enabled file systems and finally removes the restriction and allow FITRIM to be used on file system with bigalloc feature enabled.

Quoted 4 lines

any comments on this ?

Thanks!
-Lukas

ping^2

Quoted 49 lines
Quoted 48 lines
---
 fs/ext4/ioctl.c   |    7 -------
 fs/ext4/mballoc.c |    5 +++--
 2 files changed, 3 insertions(+), 9 deletions(-)
fs/ext4/ioctl.c +0 -7
index e34deac..9d6e0bc 100644
@@ -420,13 +420,6 @@ resizefs_out:
 		if (!blk_queue_discard(q))
 			return -EOPNOTSUPP;
 
-		if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
-			       EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
-			ext4_msg(sb, KERN_ERR,
-				 "FITRIM not supported with bigalloc");
-			return -EOPNOTSUPP;
-		}
-
 		if (copy_from_user(&range, (struct fstrim_range __user *)arg,
 		    sizeof(range)))
 			return -EFAULT;
fs/ext4/mballoc.c +3 -2
index 1cd6994..c4bd0a6 100644
@@ -4984,7 +4984,8 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 
 	start = range->start >> sb->s_blocksize_bits;
 	end = start + (range->len >> sb->s_blocksize_bits) - 1;
-	minlen = range->minlen >> sb->s_blocksize_bits;
+	minlen = EXT4_NUM_B2C(EXT4_SB(sb),
+			      range->minlen >> sb->s_blocksize_bits);
 
 	if (unlikely(minlen > EXT4_CLUSTERS_PER_GROUP(sb)) ||
 	    unlikely(start >= max_blks))
@@ -5044,6 +5045,6 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 		atomic_set(&EXT4_SB(sb)->s_last_trim_minblks, minlen);
 
 out:
-	range->len = trimmed * sb->s_blocksize;
+	range->len = EXT4_C2B(EXT4_SB(sb), trimmed) << sb->s_blocksize_bits;
 	return ret;
 }
#3 lore raw
Quoted 31 lines · Lukáš Czerner

Date: Wed, 12 Sep 2012 11:31:46 -0400 (EDT)
From: Lukáš Czerner <[email protected]>
To: Lukáš Czerner <[email protected]>
Cc: [email protected], [email protected]
Subject: Re: [PATCH] ext4: enable FITRIM ioctl on bigalloc file system

Quoted 23 lines · Lukáš Czerner

Date: Tue, 21 Aug 2012 11:48:27 +0200 (CEST)
From: Lukáš Czerner <[email protected]>
To: Lukas Czerner <[email protected]>
Cc: [email protected], [email protected]
Subject: Re: [PATCH] ext4: enable FITRIM ioctl on bigalloc file system

Quoted 14 lines · Lukas Czerner

Date: Tue, 3 Jul 2012 21:10:42 +0200
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: [email protected], Lukas Czerner <[email protected]>
Subject: [PATCH] ext4: enable FITRIM ioctl on bigalloc file system

With a minor tweaks regarding minimum extent size to discard and discarded bytes reporting the FITRIM can be enabled on bigalloc file system and it works without any problem.

This patch fixes minlen handling and discarded bytes reporting to take into consideration bigalloc enabled file systems and finally removes the restriction and allow FITRIM to be used on file system with bigalloc feature enabled.

Quoted 6 lines
Quoted 4 lines

any comments on this ?

Thanks!
-Lukas

ping^2

ping^3

Quoted 50 lines
Quoted 50 lines
Quoted 49 lines
---
 fs/ext4/ioctl.c   |    7 -------
 fs/ext4/mballoc.c |    5 +++--
 2 files changed, 3 insertions(+), 9 deletions(-)
fs/ext4/ioctl.c +0 -7
index e34deac..9d6e0bc 100644
@@ -420,13 +420,6 @@ resizefs_out:
 		if (!blk_queue_discard(q))
 			return -EOPNOTSUPP;
 
-		if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
-			       EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
-			ext4_msg(sb, KERN_ERR,
-				 "FITRIM not supported with bigalloc");
-			return -EOPNOTSUPP;
-		}
-
 		if (copy_from_user(&range, (struct fstrim_range __user *)arg,
 		    sizeof(range)))
 			return -EFAULT;
fs/ext4/mballoc.c +3 -2
index 1cd6994..c4bd0a6 100644
@@ -4984,7 +4984,8 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 
 	start = range->start >> sb->s_blocksize_bits;
 	end = start + (range->len >> sb->s_blocksize_bits) - 1;
-	minlen = range->minlen >> sb->s_blocksize_bits;
+	minlen = EXT4_NUM_B2C(EXT4_SB(sb),
+			      range->minlen >> sb->s_blocksize_bits);
 
 	if (unlikely(minlen > EXT4_CLUSTERS_PER_GROUP(sb)) ||
 	    unlikely(start >= max_blks))
@@ -5044,6 +5045,6 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 		atomic_set(&EXT4_SB(sb)->s_last_trim_minblks, minlen);
 
 out:
-	range->len = trimmed * sb->s_blocksize;
+	range->len = EXT4_C2B(EXT4_SB(sb), trimmed) << sb->s_blocksize_bits;
 	return ret;
 }
Reviewed-by on v1 1/1
#4 lore raw
In reply to Lukas Czerner
Quoted 48 lines · Lukas Czerner

With a minor tweaks regarding minimum extent size to discard and discarded bytes reporting the FITRIM can be enabled on bigalloc file system and it works without any problem.

This patch fixes minlen handling and discarded bytes reporting to take into consideration bigalloc enabled file systems and finally removes the restriction and allow FITRIM to be used on file system with bigalloc feature enabled.

---
 fs/ext4/ioctl.c   |    7 -------
 fs/ext4/mballoc.c |    5 +++--
 2 files changed, 3 insertions(+), 9 deletions(-)
fs/ext4/ioctl.c +0 -7
index e34deac..9d6e0bc 100644
@@ -420,13 +420,6 @@ resizefs_out:
 		if (!blk_queue_discard(q))
 			return -EOPNOTSUPP;
 
-		if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
-			       EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
-			ext4_msg(sb, KERN_ERR,
-				 "FITRIM not supported with bigalloc");
-			return -EOPNOTSUPP;
-		}
-
 		if (copy_from_user(&range, (struct fstrim_range __user *)arg,
 		    sizeof(range)))
 			return -EFAULT;
fs/ext4/mballoc.c +2 -1
index 1cd6994..c4bd0a6 100644
@@ -4984,7 +4984,8 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 
 	start = range->start >> sb->s_blocksize_bits;
 	end = start + (range->len >> sb->s_blocksize_bits) - 1;
-	minlen = range->minlen >> sb->s_blocksize_bits;
+	minlen = EXT4_NUM_B2C(EXT4_SB(sb),
+			      range->minlen >> sb->s_blocksize_bits);
 
 	if (unlikely(minlen > EXT4_CLUSTERS_PER_GROUP(sb)) ||
 	    unlikely(start >= max_blks))

fs/ext4/mballoc.c int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) · line 5050

Quoted 7 lines
fs/ext4/mballoc.c +1 -1
@@ -5044,6 +5045,6 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
 		atomic_set(&EXT4_SB(sb)->s_last_trim_minblks, minlen);
 
 out:
-	range->len = trimmed * sb->s_blocksize;
+	range->len = EXT4_C2B(EXT4_SB(sb), trimmed) << sb->s_blocksize_bits;
 	return ret;
 }

Looks good to me,

Signature · 1 line
--Carlos
maintainer Applied
#5 lore raw
In reply to Lukas Czerner
Quoted 10 lines · Lukas Czerner

With a minor tweaks regarding minimum extent size to discard and discarded bytes reporting the FITRIM can be enabled on bigalloc file system and it works without any problem.

This patch fixes minlen handling and discarded bytes reporting to take into consideration bigalloc enabled file systems and finally removes the restriction and allow FITRIM to be used on file system with bigalloc feature enabled.

Applied, thanks!

- Ted