Skip to contentSkip to conversation

xfs: Fix rounding in xfs_alloc_fix_len()

PATCH In review Jan Kara 3 participants 5 messages Jun 4, 2014 – Jun 16, 2014 XFS filesystem

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH v2 1/1 xfs: Fix rounding in xfs_alloc_fix_len()

Rounding in xfs_alloc_fix_len() is wrong. As the comment states, the result should be a number of a form (k*prod+mod) however due to sign mistake the result is different. As a result allocations on raid arrays could be misaligned in some cases.

This also seems to fix occasional assertion failure:
XFS_WANT_CORRUPTED_GOTO(rlen <= flen, error0)
in xfs_alloc_ag_vextent_size().

Also add an assertion that the result of xfs_alloc_fix_len() is of expected form.

---
 fs/xfs/xfs_alloc.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
fs/xfs/xfs_alloc.c +8 -10
index c1cf6a336a72..1351a24d3cdc 100644
@@ -257,16 +257,14 @@ xfs_alloc_fix_len(
 	k = rlen % args->prod;
 	if (k == args->mod)
 		return;
-	if (k > args->mod) {
-		if ((int)(rlen = rlen - k - args->mod) < (int)args->minlen)
-			return;
-	} else {
-		if ((int)(rlen = rlen - args->prod - (args->mod - k)) <
-		    (int)args->minlen)
-			return;
-	}
-	ASSERT(rlen >= args->minlen);
-	ASSERT(rlen <= args->maxlen);
+	if (k > args->mod)
+		rlen = rlen - (k - args->mod);
+	else
+		rlen = rlen - args->prod + (args->mod - k);
+	if ((int)rlen < (int)args->minlen)
+		return;
+	ASSERT(rlen >= args->minlen && rlen <= args->maxlen);
+	ASSERT(rlen % args->prod == args->mod);
 	args->len = rlen;
 }
 
Signature · 6 lines
1.8.1.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Jan Kara

Rounding in xfs_alloc_fix_len() is wrong. As the comment states, the result should be a number of a form (k*prod+mod) however due to sign mistake the result is different. As a result allocations on raid arrays could be misaligned in some cases.

This also seems to fix occasional assertion failure:
XFS_WANT_CORRUPTED_GOTO(rlen <= flen, error0)
in xfs_alloc_ag_vextent_size().

Quoted 5 lines

Also add an assertion that the result of xfs_alloc_fix_len() is of expected form.

---

Looks good to me. Thanks Jan.

Quoted 39 lines
 fs/xfs/xfs_alloc.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
fs/xfs/xfs_alloc.c +8 -10
index c1cf6a336a72..1351a24d3cdc 100644
@@ -257,16 +257,14 @@ xfs_alloc_fix_len(
 	k = rlen % args->prod;
 	if (k == args->mod)
 		return;
-	if (k > args->mod) {
-		if ((int)(rlen = rlen - k - args->mod) < (int)args->minlen)
-			return;
-	} else {
-		if ((int)(rlen = rlen - args->prod - (args->mod - k)) <
-		    (int)args->minlen)
-			return;
-	}
-	ASSERT(rlen >= args->minlen);
-	ASSERT(rlen <= args->maxlen);
+	if (k > args->mod)
+		rlen = rlen - (k - args->mod);
+	else
+		rlen = rlen - args->prod + (args->mod - k);
+	if ((int)rlen < (int)args->minlen)
+		return;
+	ASSERT(rlen >= args->minlen && rlen <= args->maxlen);
+	ASSERT(rlen % args->prod == args->mod);
 	args->len = rlen;
 }
 
Signature · 6 lines
1.8.1.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#2 lore raw
Quoted 13 lines · Brian Foster
Quoted 12 lines · Jan Kara

Rounding in xfs_alloc_fix_len() is wrong. As the comment states, the result should be a number of a form (k*prod+mod) however due to sign mistake the result is different. As a result allocations on raid arrays could be misaligned in some cases.

This also seems to fix occasional assertion failure:
XFS_WANT_CORRUPTED_GOTO(rlen <= flen, error0)
in xfs_alloc_ag_vextent_size().

Also add an assertion that the result of xfs_alloc_fix_len() is of expected form.

Quoted 6 lines
Quoted 2 lines

---

Looks good to me. Thanks Jan.

Ping Dave? Are you going to pick up this patch?

Honza

Quoted 39 lines
Quoted 39 lines
 fs/xfs/xfs_alloc.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
fs/xfs/xfs_alloc.c +8 -10
index c1cf6a336a72..1351a24d3cdc 100644
@@ -257,16 +257,14 @@ xfs_alloc_fix_len(
 	k = rlen % args->prod;
 	if (k == args->mod)
 		return;
-	if (k > args->mod) {
-		if ((int)(rlen = rlen - k - args->mod) < (int)args->minlen)
-			return;
-	} else {
-		if ((int)(rlen = rlen - args->prod - (args->mod - k)) <
-		    (int)args->minlen)
-			return;
-	}
-	ASSERT(rlen >= args->minlen);
-	ASSERT(rlen <= args->maxlen);
+	if (k > args->mod)
+		rlen = rlen - (k - args->mod);
+	else
+		rlen = rlen - args->prod + (args->mod - k);
+	if ((int)rlen < (int)args->minlen)
+		return;
+	ASSERT(rlen >= args->minlen && rlen <= args->maxlen);
+	ASSERT(rlen % args->prod == args->mod);
 	args->len = rlen;
 }
 
Signature · 6 lines
1.8.1.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Signature · 7 lines
Jan Kara <[email protected]>
SUSE Labs, CR

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#3 lore raw
Quoted 14 lines · Jan Kara
Quoted 13 lines · Brian Foster
Quoted 12 lines · Jan Kara

Rounding in xfs_alloc_fix_len() is wrong. As the comment states, the result should be a number of a form (k*prod+mod) however due to sign mistake the result is different. As a result allocations on raid arrays could be misaligned in some cases.

This also seems to fix occasional assertion failure:
XFS_WANT_CORRUPTED_GOTO(rlen <= flen, error0)
in xfs_alloc_ag_vextent_size().

Also add an assertion that the result of xfs_alloc_fix_len() is of expected form.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

---

Looks good to me. Thanks Jan.

Ping Dave? Are you going to pick up this patch?

I did - it's already in Linus' tree for 3.16:

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/xfs/xfs_alloc.c?id=30265117ee1e23fa91920f337a3ea91207f700dc

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#4 lore raw
Quoted 18 lines · Dave Chinner
Quoted 17 lines · Jan Kara
Quoted 16 lines · Brian Foster
Quoted 14 lines · Jan Kara

Rounding in xfs_alloc_fix_len() is wrong. As the comment states, the result should be a number of a form (k*prod+mod) however due to sign mistake the result is different. As a result allocations on raid arrays could be misaligned in some cases.

This also seems to fix occasional assertion failure:
XFS_WANT_CORRUPTED_GOTO(rlen <= flen, error0)
in xfs_alloc_ag_vextent_size().

Also add an assertion that the result of xfs_alloc_fix_len() is of expected form.

---

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

Looks good to me. Thanks Jan.

Ping Dave? Are you going to pick up this patch?

I did - it's already in Linus' tree for 3.16:

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/xfs/xfs_alloc.c?id=30265117ee1e23fa91920f337a3ea91207f700dc

Ah, sorry. I was expecting some email about acceptance. I'll check the git
tree next time.

Honza

Signature · 7 lines
Jan Kara <[email protected]>
SUSE Labs, CR

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs