Skip to contentSkip to conversation

xfs: fix directory readahead offset off-by-one

PATCH In review Dave Chinner 2 participants 4 messages May 6, 2014 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: fix directory readahead offset off-by-one

From: Dave Chinner <[email protected]>

Directory readahead can throw loud scary but harmless warnings when multiblock directories are in use a specific pattern of discontiguous blocks are found in the directory. That is, if a hole follows a discontiguous block, it will throw a warning like:

XFS (dm-1): xfs_da_do_buf: bno 637 dir: inode 34363923462
XFS (dm-1): [00] br_startoff 637 br_startblock 1917954575 br_blockcount 1 br_state 0 XFS (dm-1): [01] br_startoff 638 br_startblock -2 br_blockcount 1 br_state 0

And dump a stack trace.

This is because the readahead offset increment loop does a double increment of the block index - it does an increment for the loop iteration as well as increase the loop counter by the number of blocks in the extent. As a result, the readahead offset does not get incremented correctly for discontiguous blocks and hence can ask for readahead of a directory block from an offset part way through a directory block. If that directory block is followed by a hole, it will trigger a mapping warning like the above.

The bad readahead will be ignored, though, because the main directory block read loop uses the correct mapping offsets rather than the readahead offset and so will ignore the bad readahead altogether.

Fix the warning by ensuring that the readahead offset is correctly incremented.

---
 fs/xfs/xfs_dir2_readdir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_dir2_readdir.c +1 -1
index 50b72f7..fe2db98 100644
@@ -456,7 +456,7 @@ xfs_dir2_leaf_readbuf(
 		/*
 		 * Advance offset through the mapping table.
 		 */
-		for (j = 0; j < mp->m_dirblkfsbs; j++) {
+		for (j = 0; j < mp->m_dirblkfsbs; ) {
 			/*
 			 * The rest of this extent but not more than a dir
 			 * block.
Signature · 6 lines
1.9.0

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

Fix the warning by ensuring that the readahead offset is correctly incremented.

---
 fs/xfs/xfs_dir2_readdir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_dir2_readdir.c +0 -0
index 50b72f7..fe2db98 100644

fs/xfs/xfs_dir2_readdir.c xfs_dir2_leaf_readbuf( · line 462

Quoted 8 lines
fs/xfs/xfs_dir2_readdir.c +1 -1
@@ -456,7 +456,7 @@ xfs_dir2_leaf_readbuf(
 		/*
 		 * Advance offset through the mapping table.
 		 */
-		for (j = 0; j < mp->m_dirblkfsbs; j++) {
+		for (j = 0; j < mp->m_dirblkfsbs; ) {
 			/*
 			 * The rest of this extent but not more than a dir
 			 * block.

This looks correct, but it would seem a little more idiomatic to write this as:

		for (j = 0; j < mp->m_dirblkfsbs; j += length) {

and remove the j increment from the body.

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

#2 lore raw
Quoted 26 lines · Christoph Hellwig
Quoted 13 lines · Dave Chinner

Fix the warning by ensuring that the readahead offset is correctly incremented.

---
 fs/xfs/xfs_dir2_readdir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_dir2_readdir.c +0 -0
index 50b72f7..fe2db98 100644

fs/xfs/xfs_dir2_readdir.c xfs_dir2_leaf_readbuf( · line 462

Quoted 8 lines
fs/xfs/xfs_dir2_readdir.c +1 -1
@@ -456,7 +456,7 @@ xfs_dir2_leaf_readbuf(
 		/*
 		 * Advance offset through the mapping table.
 		 */
-		for (j = 0; j < mp->m_dirblkfsbs; j++) {
+		for (j = 0; j < mp->m_dirblkfsbs; ) {
 			/*
 			 * The rest of this extent but not more than a dir
 			 * block.

This looks correct, but it would seem a little more idiomatic to write this as:

Quoted 3 lines
		for (j = 0; j < mp->m_dirblkfsbs; j += length) {

and remove the j increment from the body.

yeah, I can do that.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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