Skip to contentSkip to conversation

XFS: Ensure we force all busy extents in range to disk

PATCH In review Dave Chinner 2 participants 3 messages Jan 2, 2010 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 XFS: Ensure we force all busy extents in range to disk

When we search for and find a busy extent during allocation we force the log out to ensure the extent free transaction is on disk before the allocation transaction. The curret implementation has a subtle bug in it - it does not handle multiple overlapping ranges.

That is, if we free lots of little extents into a single contiguous extent, then allocate the contiguous extent, the busy search code stops searching at the first extent it finds that overlaps the allocated range. It then uses the commit LSN of the transaction to force the log out to.

Unfortunately, the other busy ranges might have more recent commit LSNs than the first busy extent that is found, and this results in xfs_alloc_search_busy() returning before all the extent free transactions are on disk for the range being allocated. This can lead to potential metadata corruption or stale data exposure after a crash because log replay won't replay all the extent free transactions that cover the allocation range.

---
 fs/xfs/linux-2.6/xfs_trace.h |    9 +++++--
 fs/xfs/xfs_alloc.c           |   44 ++++++++++++++++++++---------------------
 2 files changed, 27 insertions(+), 26 deletions(-)
fs/xfs/linux-2.6/xfs_trace.h +6 -3
index 5ec1475..2b0819a 100644
@@ -1064,14 +1064,15 @@ TRACE_EVENT(xfs_alloc_unbusy,
 
 TRACE_EVENT(xfs_alloc_busysearch,
 	TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno,
-		 xfs_extlen_t len, int found),
-	TP_ARGS(mp, agno, agbno, len, found),
+		 xfs_extlen_t len, int found, xfs_lsn_t lsn),
+	TP_ARGS(mp, agno, agbno, len, found, lsn),
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(xfs_agnumber_t, agno)
 		__field(xfs_agblock_t, agbno)
 		__field(xfs_extlen_t, len)
 		__field(int, found)
+		__field(xfs_lsn_t, lsn)
 	),
 	TP_fast_assign(
 		__entry->dev = mp->m_super->s_dev;
@@ -1079,12 +1080,14 @@ TRACE_EVENT(xfs_alloc_busysearch,
 		__entry->agbno = agbno;
 		__entry->len = len;
 		__entry->found = found;
+		__entry->lsn = lsn;
 	),
-	TP_printk("dev %d:%d agno %u agbno %u len %u %s",
+	TP_printk("dev %d:%d agno %u agbno %u len %u force lsn 0x%llx %s",
 		  MAJOR(__entry->dev), MINOR(__entry->dev),
 		  __entry->agno,
 		  __entry->agbno,
 		  __entry->len,
+		  __entry->lsn,
 		  __print_symbolic(__entry->found, XFS_BUSY_STATES))
 );
 
fs/xfs/xfs_alloc.c +21 -23

62 lines not on this page · raw message

Signature · 6 lines
1.6.5

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

Looks good, and quite interestin that we never could it before.

Some nipicks below:

fs/xfs/xfs_alloc.c xfs_alloc_search_busy(xfs_trans_t *tp, · line 2583

Quoted 7 lines
fs/xfs/xfs_alloc.c +7 -0
+	/*
+	 * search pagb_list for this slot, skipping open slots. We have to
+	 * search the entire array as there may be multiple overlaps and
+	 * we have to get the most recent LSN for the log force to push out
+	 * all the transactions that span the range.
+	 */
+	for (bsy = pag->pagb_list; cnt; bsy++, cnt--) {

Maybe you coult convert this to a more standard loop idiom while you're at it:

	for (cnt = 0; cnt < pag->pagb_count; cnt++) {
		bsy = &pag->pagb_list[cnt];

fs/xfs/xfs_alloc.c xfs_alloc_search_busy(xfs_trans_t *tp, · line 2588

Quoted 5 lines
fs/xfs/xfs_alloc.c +4 -0
+		if (!bsy->busy_tp)
+			continue;
 
+		bend = bsy->busy_start + bsy->busy_length - 1;
+		if ((bno > bend) || (uend < bsy->busy_start))

no need for the inner braces here.

And btw, the standard subsystem prefix is all lower case, xfs:, not XFS:.

Also it seems like this patch requires your perag-lookup fixes first. Time to get them into the for-2.6.34 git tree ASAP as a base to work against. That might also make it easier to work on the lockless patch separately.

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

#2 lore raw
Quoted 15 lines · Christoph Hellwig

Looks good, and quite interestin that we never could it before.

Some nipicks below:

Review

Quoted 7 lines
(quoted diff) +7 -0
+	/*
+	 * search pagb_list for this slot, skipping open slots. We have to
+	 * search the entire array as there may be multiple overlaps and
+	 * we have to get the most recent LSN for the log force to push out
+	 * all the transactions that span the range.
+	 */
+	for (bsy = pag->pagb_list; cnt; bsy++, cnt--) {

Maybe you coult convert this to a more standard loop idiom while you're at it:

Quoted 2 lines
	for (cnt = 0; cnt < pag->pagb_count; cnt++) {
		bsy = &pag->pagb_list[cnt];

Done.

Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +4 -0
+		if (!bsy->busy_tp)
+			continue;
 
+		bend = bsy->busy_start + bsy->busy_length - 1;
+		if ((bno > bend) || (uend < bsy->busy_start))

no need for the inner braces here.

And done. Patch below.

Quoted 2 lines

And btw, the standard subsystem prefix is all lower case, xfs:, not XFS:.

One of these days I'll get it right ;)

Quoted 1 line

Also it seems like this patch requires your perag-lookup fixes first.

Yes. I've kind of been assuming that they will go in after reviews and fixups are completed.

Quoted 3 lines

Time to get them into the for-2.6.34 git tree ASAP as a base to work against. That might also make it easier to work on the lockless patch separately.

Agreed.

Cheers,

Dave.

Signature · 30 lines
Dave Chinner
[email protected]


xfs: Ensure we force all busy extents in range to disk

When we search for and find a busy extent during allocation we force
the log out to ensure the extent free transaction is on disk before
the allocation transaction. The curret implementation has a subtle
bug in it - it does not handle multiple overlapping ranges.

That is, if we free lots of little extents into a single contiguous
extent, then allocate the contiguous extent, the busy search code
stops searching at the first extent it finds that overlaps the
allocated range. It then uses the commit LSN of the transaction to
force the log out to.

Unfortunately, the other busy ranges might have more recent commit
LSNs than the first busy extent that is found, and this results in
xfs_alloc_search_busy() returning before all the extent free
transactions are on disk for the range being allocated. This can
lead to potential metadata corruption or stale data exposure after
a crash because log replay won't replay all the extent free
transactions that cover the allocation range.

Signed-off-by: Dave Chinner <[email protected]>
---
 fs/xfs/linux-2.6/xfs_trace.h |    9 +++++--
 fs/xfs/xfs_alloc.c           |   47 +++++++++++++++++++----------------------
 2 files changed, 28 insertions(+), 28 deletions(-)
fs/xfs/linux-2.6/xfs_trace.h +6 -3
index 5ec1475..2b0819a 100644
@@ -1064,14 +1064,15 @@ TRACE_EVENT(xfs_alloc_unbusy,
 
 TRACE_EVENT(xfs_alloc_busysearch,
 	TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno,
-		 xfs_extlen_t len, int found),
-	TP_ARGS(mp, agno, agbno, len, found),
+		 xfs_extlen_t len, int found, xfs_lsn_t lsn),
+	TP_ARGS(mp, agno, agbno, len, found, lsn),
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(xfs_agnumber_t, agno)
 		__field(xfs_agblock_t, agbno)
 		__field(xfs_extlen_t, len)
 		__field(int, found)
+		__field(xfs_lsn_t, lsn)
 	),
 	TP_fast_assign(
 		__entry->dev = mp->m_super->s_dev;
@@ -1079,12 +1080,14 @@ TRACE_EVENT(xfs_alloc_busysearch,
 		__entry->agbno = agbno;
 		__entry->len = len;
 		__entry->found = found;
+		__entry->lsn = lsn;
 	),
-	TP_printk("dev %d:%d agno %u agbno %u len %u %s",
+	TP_printk("dev %d:%d agno %u agbno %u len %u force lsn 0x%llx %s",
 		  MAJOR(__entry->dev), MINOR(__entry->dev),
 		  __entry->agno,
 		  __entry->agbno,
 		  __entry->len,
+		  __entry->lsn,
 		  __print_symbolic(__entry->found, XFS_BUSY_STATES))
 );
 
fs/xfs/xfs_alloc.c +22 -25

65 lines not on this page · raw message

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