Skip to contentSkip to conversation

xfs: fix the extent count when allocating an new indirection array entry

PATCH Superseded Jeff Liu 2 participants 3 messages Sep 21, 2013 – Sep 25, 2013 XFS filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jeff Liu

author
#0 lore raw

PATCH 1/1 xfs: fix the extent count when allocating an new indirection array entry

From: Jie Liu <[email protected]>

At xfs_iext_add(), if extent(s) are being appended to the last page in the indirection array and the new extent(s) don't fit in the page, the number of extents(erp->er_extcount) in a new allocated entry should be the minimum value between count and XFS_LINEAR_EXTS, instead of count.

---
 fs/xfs/xfs_inode_fork.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/xfs_inode_fork.c +4 -4
index 02f1083..dfb4226 100644
@@ -1035,11 +1035,11 @@ xfs_iext_add(
 
 			while (count) {
 				erp = xfs_iext_irec_new(ifp, erp_idx);
-				erp->er_extcount = count;
-				count -= MIN(count, (int)XFS_LINEAR_EXTS);
-				if (count) {
+				erp->er_extcount = MIN(count,
+						       (int)XFS_LINEAR_EXTS);
+				count -= erp->er_extcount;
+				if (count)
 					erp_idx++;
-				}
 			}
 		}
 	}
Signature · 6 lines
1.7.9.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 7 lines · Jeff Liu

From: Jie Liu <[email protected]>

At xfs_iext_add(), if extent(s) are being appended to the last page in the indirection array and the new extent(s) don't fit in the page, the number of extents(erp->er_extcount) in a new allocated entry should be the minimum value between count and XFS_LINEAR_EXTS, instead of count.

Definitely looks like a bug, but what are the symptoms of it and how did you find the problem? Is there any test case that demonstrates a problem with the er_extcount being set incorrectly here?

Quoted 10 lines
---
 fs/xfs/xfs_inode_fork.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/xfs_inode_fork.c +0 -0
index 02f1083..dfb4226 100644

fs/xfs/xfs_inode_fork.c xfs_iext_add( · line 1040

Quoted 9 lines
fs/xfs/xfs_inode_fork.c +3 -3
@@ -1035,11 +1035,11 @@ xfs_iext_add(
 
 			while (count) {
 				erp = xfs_iext_irec_new(ifp, erp_idx);
-				erp->er_extcount = count;
-				count -= MIN(count, (int)XFS_LINEAR_EXTS);
-				if (count) {
+				erp->er_extcount = MIN(count,
+						       (int)XFS_LINEAR_EXTS);
+				count -= erp->er_extcount;

count is declared as an int, whereas XFS_LINEAR_EXTS probably ends up with a type of uint because of a cast in the macro. because we are decrementing to zero, the count can be declared as a uint, too, and the cast in the MIN() can go away. Indeed, MIN() should be converted to min() seeing as we are touching the code here, and if you want to retain the current types, the min_t() is appropriate, not min(x, (some cast)y)....

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#2 lore raw
Quoted 9 lines · Dave Chinner
Quoted 7 lines · Jeff Liu

From: Jie Liu <[email protected]>

At xfs_iext_add(), if extent(s) are being appended to the last page in the indirection array and the new extent(s) don't fit in the page, the number of extents(erp->er_extcount) in a new allocated entry should be the minimum value between count and XFS_LINEAR_EXTS, instead of count.

Quoted 3 lines

Definitely looks like a bug, but what are the symptoms of it and how did you find the problem? Is there any test case that demonstrates a problem with the er_extcount being set incorrectly here?

Sorry for the too late response, I found this problem while reading the code. However, I can not figure out a test case to break the kernel until now. :(

Quoted 12 lines
Quoted 12 lines
---
 fs/xfs/xfs_inode_fork.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/xfs_inode_fork.c +0 -0
index 02f1083..dfb4226 100644
@@ -1035,11 +1035,11 @@ xfs_iext_add(
 
Quoted 16 lines

fs/xfs/xfs_inode_fork.c xfs_iext_add( · line 1040

Quoted 8 lines
fs/xfs/xfs_inode_fork.c +3 -3
 			while (count) {
 				erp = xfs_iext_irec_new(ifp, erp_idx);
-				erp->er_extcount = count;
-				count -= MIN(count, (int)XFS_LINEAR_EXTS);
-				if (count) {
+				erp->er_extcount = MIN(count,
+						       (int)XFS_LINEAR_EXTS);
+				count -= erp->er_extcount;

count is declared as an int, whereas XFS_LINEAR_EXTS probably ends up with a type of uint because of a cast in the macro. because we are decrementing to zero, the count can be declared as a uint, too, and the cast in the MIN() can go away. Indeed, MIN() should be converted to min() seeing as we are touching the code here, and if you want to retain the current types, the min_t() is appropriate, not min(x, (some cast)y)....

Ok, will fix it.

Thanks,
-Jeff

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