Skip to contentSkip to conversation

xfs: fix up EFI/EFD error handling

RFC PATCH In review Brian Foster 3 participants 10 messages Jul 23, 2015 – Aug 10, 2015 XFS filesystem

lore
Share & tools
lore
#0 lore raw

cover xfs: fix up EFI/EFD error handling

Hi all,

This is another quick RFC related to testing issues I'm hitting with my previously posted log recovery fixes. Patch 1 is a small refactor to support patch 2. Patch 2 describes the issues I'm hitting in repeated shutdown and log recovery testing.

This passes some spot testing and seems to resolve the hang from the test sequence described in the commit log description, but more testing is definitely required. I _think_ I follow the log callbacks and how the EFI/EFD are expected to be managed, but I could easily be missing something. As it is, I'm off for a long weekend after today so I'm sending this to hopefully get some eyes to sanity check before I get too deep into testing this along with the previous fixes next week...

Brian

Brian Foster (2):
xfs: return committed status from xfs_trans_roll()
xfs: fix efi/efd error handling to avoid fs shutdown hangs

 fs/xfs/xfs_bmap_util.c    | 35 ++++++++++++++++++++--------
 fs/xfs/xfs_extfree_item.c | 59 +++++++++++++++++++++++++----------------------
 fs/xfs/xfs_trans.c        | 15 ++++++++++--
 fs/xfs/xfs_trans.h        |  1 +
 4 files changed, 71 insertions(+), 39 deletions(-)
Signature · 6 lines
2.1.0

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

RFC PATCH 1/2 xfs: return committed status from xfs_trans_roll()

Some callers need to make error handling decisions based on whether the current transaction successfully committed or not. Rename xfs_trans_roll(), add a new parameter and provide a wrapper to preserve existing callers.

---
 fs/xfs/xfs_trans.c | 15 +++++++++++++--
 fs/xfs/xfs_trans.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)
fs/xfs/xfs_trans.c +13 -2
index 0582a27..a0ab1da 100644
@@ -1019,9 +1019,10 @@ xfs_trans_cancel(
  * chunk we've been working on and get a new transaction to continue.
  */
 int
-xfs_trans_roll(
+__xfs_trans_roll(
 	struct xfs_trans	**tpp,
-	struct xfs_inode	*dp)
+	struct xfs_inode	*dp,
+	int			*committed)
 {
 	struct xfs_trans	*trans;
 	struct xfs_trans_res	tres;
@@ -1052,6 +1053,7 @@ xfs_trans_roll(
 	if (error)
 		return error;
 
+	*committed = 1;
 	trans = *tpp;
 
 	/*
@@ -1074,3 +1076,12 @@ xfs_trans_roll(
 		xfs_trans_ijoin(trans, dp, 0);
 	return 0;
 }
+
+int
+xfs_trans_roll(
+	struct xfs_trans	**tpp,
+	struct xfs_inode	*dp)
+{
+	int			committed = 0;
+	return __xfs_trans_roll(tpp, dp, &committed);
+}
fs/xfs/xfs_trans.h +1 -0
index 3b21b4e..518ae5c 100644
@@ -226,6 +226,7 @@ void		xfs_trans_log_efd_extent(xfs_trans_t *,
 					 xfs_fsblock_t,
 					 xfs_extlen_t);
 int		xfs_trans_commit(struct xfs_trans *);
+int		__xfs_trans_roll(struct xfs_trans **, struct xfs_inode *, int *);
 int		xfs_trans_roll(struct xfs_trans **, struct xfs_inode *);
 void		xfs_trans_cancel(xfs_trans_t *);
 int		xfs_trans_ail_init(struct xfs_mount *);
Signature · 6 lines
2.1.0

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

RFC PATCH 2/2 xfs: fix efi/efd error handling to avoid fs shutdown hangs

In reply to Brian Foster

Freeing an extent in XFS involves logging an EFI (extent free intention), freeing the actual extent, and logging an EFD (extent free done). The EFI object is created with a reference count of 2: one for the current transaction and one for the subsequently created EFD. Under normal circumstances, the first reference is dropped when the EFI is unpinned and the second reference is dropped when the EFD is committed to the on-disk log.

In event of errors or filesystem shutdown, there are various potential cleanup scenarios depending on the state of the EFI/EFD. The cleanup scenarios are confusing and racy, as demonstrated by the following test sequence:

	# mount $dev $mnt
	# fsstress -d $mnt -n 99999 -p 16 -z -f fallocate=1 \
		-f punch=1 -f creat=1 -f unlink=1 &
	# sleep 5
	# killall -9 fsstress; wait
	# godown -f $mnt
	# umount

... in which the final umount can hang due to the AIL being pinned indefinitely by one or more EFI items. This can occur due to several conditions. For example, if the shutdown occurs after the EFI is committed to the on-disk log and the EFD committed to the CIL, but before the EFD committed to the log, the EFD iop_committed() abort handler does not drop its reference to the EFI. Alternatively, manual error injection in the xfs_bmap_finish() codepath shows that if an error occurs after the EFI transaction is committed but before the EFD is constructed and logged, the EFI is never released from the AIL.

Update the EFI/EFD item handling code to use a more straightforward and reliable approach to error handling. If the EFI transaction is cancelled, the EFI is freed when the log item is unlocked. If the EFI transaction is committed successfully, from that point forward it is the responsibility of the EFD to drop its EFI reference. This means that the EFI unpin callback only ever drops the log reference to the EFI. It does not free the EFI in the event of log I/O error. This also means that the EFD item must drop its EFI reference either if the EFD transaction is cancelled, committed or itself aborted due to log I/O error. Finally, update xfs_bmap_finish() to ensure that once an EFI transaction is committed, we are guaranteed to construct and log the associated EFD. This ensures that the EFD is aborted and drops the reference to the EFI.

---
 fs/xfs/xfs_bmap_util.c    | 35 ++++++++++++++++++++--------
 fs/xfs/xfs_extfree_item.c | 59 +++++++++++++++++++++++++----------------------
 2 files changed, 57 insertions(+), 37 deletions(-)
fs/xfs/xfs_bmap_util.c +25 -10
index 0f34886c..878b33a 100644
@@ -88,20 +88,36 @@ xfs_bmap_finish(
 		xfs_trans_log_efi_extent(*tp, efi, free->xbfi_startblock,
 			free->xbfi_blockcount);
 
-	error = xfs_trans_roll(tp, NULL);
-	*committed = 1;
+	error = __xfs_trans_roll(tp, NULL, committed);
+
 	/*
-	 * We have a new transaction, so we should return committed=1,
-	 * even though we're returning an error.
+	 * We have a new transaction, so we should return committed=1, even
+	 * though we're returning an error. If an error was returned after the
+	 * original transaction was committed, defer the error handling until
+	 * the EFD is logged. We do this because a committed EFI requires an EFD
+	 * transaction to be processed to ensure the EFI is released.
 	 */
-	if (error)
+	if (error && *committed == 0) {
+		*committed = 1;
 		return error;
+	}
 
 	efd = xfs_trans_get_efd(*tp, efi, flist->xbf_count);
 	for (free = flist->xbf_first; free != NULL; free = next) {
 		next = free->xbfi_next;
-		if ((error = xfs_free_extent(*tp, free->xbfi_startblock,
-				free->xbfi_blockcount))) {
+
+		/*
+		 * Free the extent if the above trans roll hasn't failed and log
+		 * the EFD before handling errors from either call to ensure the
+		 * EFI reference is accounted for in the tp. Otherwise, the EFI
+		 * is never released on abort and pins the AIL indefinitely.
+		 */
+		if (!error)
+			error = xfs_free_extent(*tp, free->xbfi_startblock,
+						free->xbfi_blockcount);
+		xfs_trans_log_efd_extent(*tp, efd, free->xbfi_startblock,
+					 free->xbfi_blockcount);
+		if (error) {
 			/*
 			 * The bmap free list will be cleaned up at a
 			 * higher level.  The EFI will be canceled when
@@ -118,11 +134,10 @@ xfs_bmap_finish(
 						   SHUTDOWN_META_IO_ERROR);
 			return error;
 		}
-		xfs_trans_log_efd_extent(*tp, efd, free->xbfi_startblock,
-			free->xbfi_blockcount);
 		xfs_bmap_del_free(flist, NULL, free);
 	}
-	return 0;
+
+	return error;
 }
 
 int
fs/xfs/xfs_extfree_item.c +32 -27

98 lines not on this page · raw message

Signature · 6 lines
2.1.0

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

Re: [PATCH RFC 1/2] xfs: return committed status from xfs_trans_roll()

[ reply to both patches in one reply, because it's related. ]

Quoted 29 lines · Brian Foster

Some callers need to make error handling decisions based on whether the current transaction successfully committed or not. Rename xfs_trans_roll(), add a new parameter and provide a wrapper to preserve existing callers.

---
 fs/xfs/xfs_trans.c | 15 +++++++++++++--
 fs/xfs/xfs_trans.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)
fs/xfs/xfs_trans.c +3 -2
index 0582a27..a0ab1da 100644
@@ -1019,9 +1019,10 @@ xfs_trans_cancel(
  * chunk we've been working on and get a new transaction to continue.
  */
 int
-xfs_trans_roll(
+__xfs_trans_roll(
 	struct xfs_trans	**tpp,
-	struct xfs_inode	*dp)
+	struct xfs_inode	*dp,
+	int			*committed)
 {
 	struct xfs_trans	*trans;
 	struct xfs_trans_res	tres;

fs/xfs/xfs_trans.c xfs_trans_roll( · line 1054

Quoted 2 lines
fs/xfs/xfs_trans.c +0 -0
@@ -1052,6 +1053,7 @@ xfs_trans_roll(
 	if (error)
 		return error;

So here we return committed = 0, error != 0.

fs/xfs/xfs_trans.c xfs_trans_roll( · line 1056

Quoted 3 lines
fs/xfs/xfs_trans.c +1 -0
+	*committed = 1;
 	trans = *tpp;

And from here on in we return committed = 1 regardless of the error.

So looking at the next patch in xfs_bmap_finish():

Quoted 10 lines
fs/xfs/xfs_trans.c +3 -4
 			free->xbfi_blockcount);
 
-	error = xfs_trans_roll(tp, NULL);
-	*committed = 1;
+	error = __xfs_trans_roll(tp, NULL, committed);
+
 	/*
-	 * We have a new transaction, so we should return committed=1,
-	 * even though we're returning an error.
+	 * We have a new transaction, so we should return committed=1, even

fs/xfs/xfs_trans.c xfs_trans_roll(

Quoted 10 lines
fs/xfs/xfs_trans.c +7 -1
+	 * though we're returning an error. If an error was returned after the
+	 * original transaction was committed, defer the error handling until
+	 * the EFD is logged. We do this because a committed EFI requires an EFD
+	 * transaction to be processed to ensure the EFI is released.
 	 */
-	if (error)
+	if (error && *committed == 0) {
+		*committed = 1;
 		return error;
+	}

So if we failed to commit the EFI, we say we did and then return. Why do we need to do that?

/me goes an looks at all the callers.

Hmm - only xfs_itruncate_extents() relies on that behaviour, but it could just as easily do an inode join on error, because on success the inode has already been joined to the new transaction by xfs_trans_roll().

Looking further, we have quite a bit of inconsistency in the error handling of xfs_bmap_finish() - some callers issue a xfs_bmap_cancel() in the error path, and some don't. failing to cancel the freelist on error looks to me like a memory leak, because we don't free the extents from the free list until the EFD for the extent has been logged. If we error out earlier, we still have items on the free list that haven't been processed.

So it looks to me like we need fixes there.

Further, it appears to me that there is really one xfs_bmap_finish() caller that requires the committed flag: xfs_qm_dqalloc(). All the others either use it for an assert or joining the inode to the transaction when committed = 1, which xfs_trans_roll() will have already done if we return committed = 1....

So xfs_qm_dqalloc(), on error, simply cancels the freelist and returns the error - it ignores the committed flag. So the committed flag is used to determine how to handle the dquot buffer:

        xfs_trans_bhold(tp, bp);

        if ((error = xfs_bmap_finish(tpp, &flist, &committed))) {
                goto error1;
        }

        if (committed) {
                tp = *tpp;
                xfs_trans_bjoin(tp, bp);
        } else {
                xfs_trans_bhold_release(tp, bp);
        }

Now, xfs_trans_bhold() simply sets the BLI_HOLD flag on the buffer, and transaction commit clears it. That means we could call it unconditionally, and all we have to do is remove an assert(BLI_HOLD) from xfs_trans_bhold_release() to enable that. Given this is the only caller of xfs_trans_bhold_release(), I don't see a problem with doing that. Nor is there a problem with multiple joins of an object to a transaction, so we could simply make this:

	xfs_trans_bhold(tp, bp);
	error = xfs_bmap_finish(tpp, &flist, &committed);
	if (error)
		goto error1;
	tp = *tpp;
	xfs_trans_bjoin(tp, bp);
	xfs_trans_bhold_release(tp, bp);

And the committed flag is not necessary. With this, we can hide everything to do with error on commit vs error after commit inside xfs_bmap_finish()...

Quoted 22 lines
fs/xfs/xfs_trans.c +13 -2
 	efd = xfs_trans_get_efd(*tp, efi, flist->xbf_count);
 	for (free = flist->xbf_first; free != NULL; free = next) {
 		next = free->xbfi_next;
-		if ((error = xfs_free_extent(*tp, free->xbfi_startblock,
-				free->xbfi_blockcount))) {
+
+		/*
+		 * Free the extent if the above trans roll hasn't failed and log
+		 * the EFD before handling errors from either call to ensure the
+		 * EFI reference is accounted for in the tp. Otherwise, the EFI
+		 * is never released on abort and pins the AIL indefinitely.
+		 */
+		if (!error)
+			error = xfs_free_extent(*tp, free->xbfi_startblock,
+						free->xbfi_blockcount);
+		xfs_trans_log_efd_extent(*tp, efd, free->xbfi_startblock,
+					 free->xbfi_blockcount);
+		if (error) {
 			/*
 			 * The bmap free list will be cleaned up at a
 			 * higher level.  The EFI will be canceled when

fs/xfs/xfs_trans.c xfs_bmap_finish( · line 140

Quoted 10 lines
fs/xfs/xfs_trans.c +2 -3
@@ -118,11 +134,10 @@ xfs_bmap_finish(
 						   SHUTDOWN_META_IO_ERROR);
 			return error;
 		}
-		xfs_trans_log_efd_extent(*tp, efd, free->xbfi_startblock,
-			free->xbfi_blockcount);
 		xfs_bmap_del_free(flist, NULL, free);
 	}
-	return 0;
+
+	return error;

This loop doesn't obviously do the right thing now. It will log the first extent into the EFD and then trigger a shutdown and return. The extent count in the EFD may not match the extent count on the EFI, so releasing the EFD at this point may not release all the extents in the EFI and hence not release the EFI.

I think I'd prefer to see a xfs_trans_cancel_efi() call to handle this error path rather than having to go through the efd to release the reference on the EFI. i.e.

	error = __xfs_trans_roll(tp, NULL, &committed);
	if (error) {
		if (committed) {
			if (!XFS_FORCED_SHUTDOWN(mp))
				xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
			xfs_efi_cancel(tp, efi);
		}
		return error;
	}

/*
* Cancel a committed EFI after triggering a shutdown. We need to do
* this so that the committed EFI is removed from the AIL and freed,
* otherwise unmount will hang due to a non-empty AIL.
*/
xfs_efi_cancel()

{
	ASSERT(XFS_FORCED_SHUTDOWN(mp));
	xfs_efi_release(efi, efi->nextents);
}

Doing this means there's less complexity on the EFD abort side of things, as we don't have to now handle this failure case via transaction completion callback interface.

Hmmm - something I just noticed: if we only have one EFD per EFI, why do we do we have that layer of extent counting before dropping real references?

fs/xfs/xfs_trans.c xfs_bmap_finish(

Quoted 12 lines
fs/xfs/xfs_trans.c +6 -2
 xfs_efd_item_unlock(
 	struct xfs_log_item	*lip)
 {
-	if (lip->li_flags & XFS_LI_ABORTED)
-		xfs_efd_item_free(EFD_ITEM(lip));
+	struct xfs_efd_log_item	*efdp = EFD_ITEM(lip);
+
+	if (lip->li_flags & XFS_LI_ABORTED) {
+		xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents);
+		xfs_efd_item_free(efdp);
+	}
 }

i.e. we always call xfs_efi_release() with efi_nextents or efd_nextents, which are always the same, and so we never partially complete an EFI. Should we just kill that layer, as it does tend to complicate the EFI release code?

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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

Re: [PATCH RFC 1/2] xfs: return committed status from xfs_trans_roll()

Quoted 69 lines · Dave Chinner

[ reply to both patches in one reply, because it's related. ]

Quoted 29 lines · Brian Foster

Some callers need to make error handling decisions based on whether the current transaction successfully committed or not. Rename xfs_trans_roll(), add a new parameter and provide a wrapper to preserve existing callers.

---
 fs/xfs/xfs_trans.c | 15 +++++++++++++--
 fs/xfs/xfs_trans.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)
fs/xfs/xfs_trans.c +3 -2
index 0582a27..a0ab1da 100644
@@ -1019,9 +1019,10 @@ xfs_trans_cancel(
  * chunk we've been working on and get a new transaction to continue.
  */
 int
-xfs_trans_roll(
+__xfs_trans_roll(
 	struct xfs_trans	**tpp,
-	struct xfs_inode	*dp)
+	struct xfs_inode	*dp,
+	int			*committed)
 {
 	struct xfs_trans	*trans;
 	struct xfs_trans_res	tres;

fs/xfs/xfs_trans.c xfs_trans_roll( · line 1054

Quoted 2 lines
fs/xfs/xfs_trans.c +0 -0
@@ -1052,6 +1053,7 @@ xfs_trans_roll(
 	if (error)
 		return error;

So here we return committed = 0, error != 0.

fs/xfs/xfs_trans.c xfs_trans_roll( · line 1056

Quoted 3 lines
fs/xfs/xfs_trans.c +1 -0
+	*committed = 1;
 	trans = *tpp;

And from here on in we return committed = 1 regardless of the error.

So looking at the next patch in xfs_bmap_finish():

Quoted 10 lines
fs/xfs/xfs_trans.c +3 -4
 			free->xbfi_blockcount);
 
-	error = xfs_trans_roll(tp, NULL);
-	*committed = 1;
+	error = __xfs_trans_roll(tp, NULL, committed);
+
 	/*
-	 * We have a new transaction, so we should return committed=1,
-	 * even though we're returning an error.
+	 * We have a new transaction, so we should return committed=1, even

fs/xfs/xfs_trans.c xfs_trans_roll(

Quoted 10 lines
fs/xfs/xfs_trans.c +7 -1
+	 * though we're returning an error. If an error was returned after the
+	 * original transaction was committed, defer the error handling until
+	 * the EFD is logged. We do this because a committed EFI requires an EFD
+	 * transaction to be processed to ensure the EFI is released.
 	 */
-	if (error)
+	if (error && *committed == 0) {
+		*committed = 1;
 		return error;
+	}

So if we failed to commit the EFI, we say we did and then return. Why do we need to do that?

Quoted 7 lines

/me goes an looks at all the callers.

Hmm - only xfs_itruncate_extents() relies on that behaviour, but it could just as easily do an inode join on error, because on success the inode has already been joined to the new transaction by xfs_trans_roll().

Interesting, though I don't follow why this caller even depends on it. It doesn't transfer lock ownership to the transaction. What difference does it make in the error path if the inode is joined?

Quoted 10 lines

Looking further, we have quite a bit of inconsistency in the error handling of xfs_bmap_finish() - some callers issue a xfs_bmap_cancel() in the error path, and some don't. failing to cancel the freelist on error looks to me like a memory leak, because we don't free the extents from the free list until the EFD for the extent has been logged. If we error out earlier, we still have items on the free list that haven't been processed.

So it looks to me like we need fixes there.

Heh, not too surprising. I'll make a note to make a pass through these.

Quoted 6 lines

Further, it appears to me that there is really one xfs_bmap_finish() caller that requires the committed flag: xfs_qm_dqalloc(). All the others either use it for an assert or joining the inode to the transaction when committed = 1, which xfs_trans_roll() will have already done if we return committed = 1....

Assuming xfs_trans_reserve() hasn't failed, which could cause *committed == 1 without the inode joined. We could probably change this in __xfs_trans_roll() since the inode is presumably already locked.

Quoted 34 lines

So xfs_qm_dqalloc(), on error, simply cancels the freelist and returns the error - it ignores the committed flag. So the committed flag is used to determine how to handle the dquot buffer:

        xfs_trans_bhold(tp, bp);

        if ((error = xfs_bmap_finish(tpp, &flist, &committed))) {
                goto error1;
        }

        if (committed) {
                tp = *tpp;
                xfs_trans_bjoin(tp, bp);
        } else {
                xfs_trans_bhold_release(tp, bp);
        }

Now, xfs_trans_bhold() simply sets the BLI_HOLD flag on the buffer, and transaction commit clears it. That means we could call it unconditionally, and all we have to do is remove an assert(BLI_HOLD) from xfs_trans_bhold_release() to enable that. Given this is the only caller of xfs_trans_bhold_release(), I don't see a problem with doing that. Nor is there a problem with multiple joins of an object to a transaction, so we could simply make this:

	xfs_trans_bhold(tp, bp);
	error = xfs_bmap_finish(tpp, &flist, &committed);
	if (error)
		goto error1;
	tp = *tpp;
	xfs_trans_bjoin(tp, bp);
	xfs_trans_bhold_release(tp, bp);
Quoted 4 lines

And the committed flag is not necessary. With this, we can hide everything to do with error on commit vs error after commit inside xfs_bmap_finish()...

Seems reasonable at a glance.

Quoted 30 lines
Quoted 30 lines
fs/xfs/xfs_trans.c +13 -5
 	efd = xfs_trans_get_efd(*tp, efi, flist->xbf_count);
 	for (free = flist->xbf_first; free != NULL; free = next) {
 		next = free->xbfi_next;
-		if ((error = xfs_free_extent(*tp, free->xbfi_startblock,
-				free->xbfi_blockcount))) {
+
+		/*
+		 * Free the extent if the above trans roll hasn't failed and log
+		 * the EFD before handling errors from either call to ensure the
+		 * EFI reference is accounted for in the tp. Otherwise, the EFI
+		 * is never released on abort and pins the AIL indefinitely.
+		 */
+		if (!error)
+			error = xfs_free_extent(*tp, free->xbfi_startblock,
+						free->xbfi_blockcount);
+		xfs_trans_log_efd_extent(*tp, efd, free->xbfi_startblock,
+					 free->xbfi_blockcount);
+		if (error) {
 			/*
 			 * The bmap free list will be cleaned up at a
 			 * higher level.  The EFI will be canceled when
@@ -118,11 +134,10 @@ xfs_bmap_finish(
 						   SHUTDOWN_META_IO_ERROR);
 			return error;
 		}
-		xfs_trans_log_efd_extent(*tp, efd, free->xbfi_startblock,
-			free->xbfi_blockcount);
 		xfs_bmap_del_free(flist, NULL, free);
 	}
-	return 0;
Quoted 9 lines

fs/xfs/xfs_trans.c xfs_bmap_finish( · line 140

Quoted 2 lines
fs/xfs/xfs_trans.c +2 -0
+
+	return error;

This loop doesn't obviously do the right thing now. It will log the first extent into the EFD and then trigger a shutdown and return. The extent count in the EFD may not match the extent count on the EFI, so releasing the EFD at this point may not release all the extents in the EFI and hence not release the EFI.

The EFD unlock handler forcibly releases the EFI on abort. It drops the EFI extent count reference by whatever the extent count on the EFD is, and that is determined on EFD initialization (xfs_trans_get_efd()) regardless of how many extents were logged to the EFD.

That said, the error handling here is certainly not obvious because it depends on the lifecycle of the associated log items. The broader goal is to reduce that dependency so the code here is more straightforward...

Quoted 4 lines

I think I'd prefer to see a xfs_trans_cancel_efi() call to handle this error path rather than having to go through the efd to release the reference on the EFI. i.e.

Quoted 10 lines
	error = __xfs_trans_roll(tp, NULL, &committed);
	if (error) {
		if (committed) {
			if (!XFS_FORCED_SHUTDOWN(mp))
				xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
			xfs_efi_cancel(tp, efi);
		}
		return error;
	}

That's a nice idea. It pulls some error handling out of the log item handling code explicitly. An EFD version might be useful for the unlogged EFD error case as well. IMO, the more of these cases that are handled explicitly in xfs_bmap_finish() rather than implicitly via the transaction management code, the more reliable and robust to future change it will be. I'll explore it further...

Quoted 6 lines

/*
* Cancel a committed EFI after triggering a shutdown. We need to do
* this so that the committed EFI is removed from the AIL and freed,
* otherwise unmount will hang due to a non-empty AIL.
*/
xfs_efi_cancel()

Quoted 9 lines
{
	ASSERT(XFS_FORCED_SHUTDOWN(mp));
	xfs_efi_release(efi, efi->nextents);
}

Doing this means there's less complexity on the EFD abort side of things, as we don't have to now handle this failure case via transaction completion callback interface.

Indeed.

Quoted 4 lines

Hmmm - something I just noticed: if we only have one EFD per EFI, why do we do we have that layer of extent counting before dropping real references?

I wondered this myself, but hadn't made it deep enough to see if we used the reference count elsewhere.

Quoted 9 lines
Quoted 9 lines
fs/xfs/xfs_trans.c +4 -2
 xfs_efd_item_unlock(
 	struct xfs_log_item	*lip)
 {
-	if (lip->li_flags & XFS_LI_ABORTED)
-		xfs_efd_item_free(EFD_ITEM(lip));
+	struct xfs_efd_log_item	*efdp = EFD_ITEM(lip);
+
+	if (lip->li_flags & XFS_LI_ABORTED) {
+		xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents);
Quoted 9 lines

fs/xfs/xfs_trans.c

Quoted 3 lines
fs/xfs/xfs_trans.c +2 -0
+		xfs_efd_item_free(efdp);
+	}
 }

i.e. we always call xfs_efi_release() with efi_nextents or efd_nextents, which are always the same, and so we never partially complete an EFI. Should we just kill that layer, as it does tend to complicate the EFI release code?

Yeah, that might be a good idea if we don't use the reference count elsewhere. I'll look into that as a subsequent cleanup as well.

Brian

Quoted 11 lines

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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

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

#5 lore raw

Re: [PATCH RFC 1/2] xfs: return committed status from xfs_trans_roll()

Quoted 78 lines · Brian Foster
Quoted 69 lines · Dave Chinner

[ reply to both patches in one reply, because it's related. ]

Quoted 29 lines · Brian Foster

Some callers need to make error handling decisions based on whether the current transaction successfully committed or not. Rename xfs_trans_roll(), add a new parameter and provide a wrapper to preserve existing callers.

---
 fs/xfs/xfs_trans.c | 15 +++++++++++++--
 fs/xfs/xfs_trans.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)
fs/xfs/xfs_trans.c +3 -2
index 0582a27..a0ab1da 100644
@@ -1019,9 +1019,10 @@ xfs_trans_cancel(
  * chunk we've been working on and get a new transaction to continue.
  */
 int
-xfs_trans_roll(
+__xfs_trans_roll(
 	struct xfs_trans	**tpp,
-	struct xfs_inode	*dp)
+	struct xfs_inode	*dp,
+	int			*committed)
 {
 	struct xfs_trans	*trans;
 	struct xfs_trans_res	tres;

fs/xfs/xfs_trans.c xfs_trans_roll( · line 1054

Quoted 2 lines
fs/xfs/xfs_trans.c +0 -0
@@ -1052,6 +1053,7 @@ xfs_trans_roll(
 	if (error)
 		return error;

So here we return committed = 0, error != 0.

fs/xfs/xfs_trans.c xfs_trans_roll( · line 1056

Quoted 3 lines
fs/xfs/xfs_trans.c +1 -0
+	*committed = 1;
 	trans = *tpp;

And from here on in we return committed = 1 regardless of the error.

So looking at the next patch in xfs_bmap_finish():

Quoted 10 lines
fs/xfs/xfs_trans.c +3 -4
 			free->xbfi_blockcount);
 
-	error = xfs_trans_roll(tp, NULL);
-	*committed = 1;
+	error = __xfs_trans_roll(tp, NULL, committed);
+
 	/*
-	 * We have a new transaction, so we should return committed=1,
-	 * even though we're returning an error.
+	 * We have a new transaction, so we should return committed=1, even

fs/xfs/xfs_trans.c xfs_trans_roll(

Quoted 10 lines
fs/xfs/xfs_trans.c +7 -1
+	 * though we're returning an error. If an error was returned after the
+	 * original transaction was committed, defer the error handling until
+	 * the EFD is logged. We do this because a committed EFI requires an EFD
+	 * transaction to be processed to ensure the EFI is released.
 	 */
-	if (error)
+	if (error && *committed == 0) {
+		*committed = 1;
 		return error;
+	}

So if we failed to commit the EFI, we say we did and then return. Why do we need to do that?

Quoted 7 lines

/me goes an looks at all the callers.

Hmm - only xfs_itruncate_extents() relies on that behaviour, but it could just as easily do an inode join on error, because on success the inode has already been joined to the new transaction by xfs_trans_roll().

Quoted 3 lines

Interesting, though I don't follow why this caller even depends on it. It doesn't transfer lock ownership to the transaction. What difference does it make in the error path if the inode is joined?

Callers of xfs_itruncate_extents() expect it to be locked and joined on return, even on error.

Quoted 20 lines
Quoted 10 lines

Looking further, we have quite a bit of inconsistency in the error handling of xfs_bmap_finish() - some callers issue a xfs_bmap_cancel() in the error path, and some don't. failing to cancel the freelist on error looks to me like a memory leak, because we don't free the extents from the free list until the EFD for the extent has been logged. If we error out earlier, we still have items on the free list that haven't been processed.

So it looks to me like we need fixes there.

Heh, not too surprising. I'll make a note to make a pass through these.

Quoted 6 lines

Further, it appears to me that there is really one xfs_bmap_finish() caller that requires the committed flag: xfs_qm_dqalloc(). All the others either use it for an assert or joining the inode to the transaction when committed = 1, which xfs_trans_roll() will have already done if we return committed = 1....

Quoted 3 lines

Assuming xfs_trans_reserve() hasn't failed, which could cause *committed == 1 without the inode joined. We could probably change this in __xfs_trans_roll() since the inode is presumably already locked.

I don't think we can join the inode until after the reservation is done. It could still be done in __xfs_trans_roll() regardless.

Quoted 9 lines
Quoted 8 lines

fs/xfs/xfs_trans.c

Quoted 1 line
fs/xfs/xfs_trans.c +1 -0
+	return error;

This loop doesn't obviously do the right thing now. It will log the first extent into the EFD and then trigger a shutdown and return. The extent count in the EFD may not match the extent count on the EFI, so releasing the EFD at this point may not release all the extents in the EFI and hence not release the EFI.

Quoted 8 lines

The EFD unlock handler forcibly releases the EFI on abort. It drops the EFI extent count reference by whatever the extent count on the EFD is, and that is determined on EFD initialization (xfs_trans_get_efd()) regardless of how many extents were logged to the EFD.

That said, the error handling here is certainly not obvious because it depends on the lifecycle of the associated log items. The broader goal is to reduce that dependency so the code here is more straightforward...

*nod*

Quoted 15 lines
Quoted 4 lines

I think I'd prefer to see a xfs_trans_cancel_efi() call to handle this error path rather than having to go through the efd to release the reference on the EFI. i.e.

Quoted 10 lines
	error = __xfs_trans_roll(tp, NULL, &committed);
	if (error) {
		if (committed) {
			if (!XFS_FORCED_SHUTDOWN(mp))
				xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
			xfs_efi_cancel(tp, efi);
		}
		return error;
	}
Quoted 6 lines

That's a nice idea. It pulls some error handling out of the log item handling code explicitly. An EFD version might be useful for the unlogged EFD error case as well. IMO, the more of these cases that are handled explicitly in xfs_bmap_finish() rather than implicitly via the transaction management code, the more reliable and robust to future change it will be. I'll explore it further...

Yes, that mirrors my thinking exactly - the EFI/EFD error handling has always been problematic with the reliance on reference counting via transaction commit/abort callbacks to handle it.

Quoted 27 lines
Quoted 4 lines

Hmmm - something I just noticed: if we only have one EFD per EFI, why do we do we have that layer of extent counting before dropping real references?

I wondered this myself, but hadn't made it deep enough to see if we used the reference count elsewhere.

Quoted 9 lines
Quoted 9 lines

xfs_efd_item_unlock(

fs/xfs/xfs_trans.c +4 -2
 	struct xfs_log_item	*lip)
 {
-	if (lip->li_flags & XFS_LI_ABORTED)
-		xfs_efd_item_free(EFD_ITEM(lip));
+	struct xfs_efd_log_item	*efdp = EFD_ITEM(lip);
+
+	if (lip->li_flags & XFS_LI_ABORTED) {
+		xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents);
Quoted 9 lines

fs/xfs/xfs_trans.c

Quoted 3 lines
fs/xfs/xfs_trans.c +2 -0
+		xfs_efd_item_free(efdp);
+	}
 }

i.e. we always call xfs_efi_release() with efi_nextents or efd_nextents, which are always the same, and so we never partially complete an EFI. Should we just kill that layer, as it does tend to complicate the EFI release code?

Quoted 2 lines

Yeah, that might be a good idea if we don't use the reference count elsewhere. I'll look into that as a subsequent cleanup as well.

Excellent!

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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

Re: [PATCH RFC 1/2] xfs: return committed status from xfs_trans_roll()

Quoted 5 lines · Dave Chinner
Quoted 4 lines · Brian Foster
Quoted 3 lines · Dave Chinner

[ reply to both patches in one reply, because it's related. ]

On Thu, Jul 23, 2015 at 04:13:29PM -0400, Brian Foster wrote:

...

Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 10 lines
fs/xfs/xfs_bmap_util.c +3 -4
 			free->xbfi_blockcount);
 
-	error = xfs_trans_roll(tp, NULL);
-	*committed = 1;
+	error = __xfs_trans_roll(tp, NULL, committed);
+
 	/*
-	 * We have a new transaction, so we should return committed=1,
-	 * even though we're returning an error.
+	 * We have a new transaction, so we should return committed=1, even

fs/xfs/xfs_bmap_util.c xfs_bmap_finish( · line 103

Quoted 10 lines
fs/xfs/xfs_bmap_util.c +7 -1
+	 * though we're returning an error. If an error was returned after the
+	 * original transaction was committed, defer the error handling until
+	 * the EFD is logged. We do this because a committed EFI requires an EFD
+	 * transaction to be processed to ensure the EFI is released.
 	 */
-	if (error)
+	if (error && *committed == 0) {
+		*committed = 1;
 		return error;
+	}

So if we failed to commit the EFI, we say we did and then return. Why do we need to do that?

/me goes an looks at all the callers.

Hmm - only xfs_itruncate_extents() relies on that behaviour, but it could just as easily do an inode join on error, because on success the inode has already been joined to the new transaction by xfs_trans_roll().

Quoted 7 lines
Quoted 3 lines

Interesting, though I don't follow why this caller even depends on it. It doesn't transfer lock ownership to the transaction. What difference does it make in the error path if the inode is joined?

Callers of xfs_itruncate_extents() expect it to be locked and joined on return, even on error.

All of the callers I see cancel the transaction and unlock the inode separately on error. I could be glossing over some obvious point here, but so far I'm not seeing it...

Quoted 20 lines
Quoted 20 lines
Quoted 10 lines

Looking further, we have quite a bit of inconsistency in the error handling of xfs_bmap_finish() - some callers issue a xfs_bmap_cancel() in the error path, and some don't. failing to cancel the freelist on error looks to me like a memory leak, because we don't free the extents from the free list until the EFD for the extent has been logged. If we error out earlier, we still have items on the free list that haven't been processed.

So it looks to me like we need fixes there.

Heh, not too surprising. I'll make a note to make a pass through these.

Quoted 6 lines

Further, it appears to me that there is really one xfs_bmap_finish() caller that requires the committed flag: xfs_qm_dqalloc(). All the others either use it for an assert or joining the inode to the transaction when committed = 1, which xfs_trans_roll() will have already done if we return committed = 1....

Quoted 7 lines
Quoted 3 lines

Assuming xfs_trans_reserve() hasn't failed, which could cause *committed == 1 without the inode joined. We could probably change this in __xfs_trans_roll() since the inode is presumably already locked.

I don't think we can join the inode until after the reservation is done. It could still be done in __xfs_trans_roll() regardless.

Hmm, I don't see anything obvious that prevents it. It probably defies convention though. Anyways, we're probably a few levels of indirection away from the bug fixes and work that we know needs to happen at this point. I'll try to get the EFI/EFD stuff worked out, along with some of the other issues I'm reproducing, then we can go from there...

Brian

Quoted 73 lines
Quoted 9 lines
Quoted 8 lines

fs/xfs/xfs_bmap_util.c xfs_bmap_finish( · line 140

Quoted 1 line
fs/xfs/xfs_bmap_util.c +1 -0
+	return error;

This loop doesn't obviously do the right thing now. It will log the first extent into the EFD and then trigger a shutdown and return. The extent count in the EFD may not match the extent count on the EFI, so releasing the EFD at this point may not release all the extents in the EFI and hence not release the EFI.

Quoted 8 lines

The EFD unlock handler forcibly releases the EFI on abort. It drops the EFI extent count reference by whatever the extent count on the EFD is, and that is determined on EFD initialization (xfs_trans_get_efd()) regardless of how many extents were logged to the EFD.

That said, the error handling here is certainly not obvious because it depends on the lifecycle of the associated log items. The broader goal is to reduce that dependency so the code here is more straightforward...

*nod*

Quoted 15 lines
Quoted 4 lines

I think I'd prefer to see a xfs_trans_cancel_efi() call to handle this error path rather than having to go through the efd to release the reference on the EFI. i.e.

Quoted 10 lines
	error = __xfs_trans_roll(tp, NULL, &committed);
	if (error) {
		if (committed) {
			if (!XFS_FORCED_SHUTDOWN(mp))
				xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
			xfs_efi_cancel(tp, efi);
		}
		return error;
	}
Quoted 6 lines

That's a nice idea. It pulls some error handling out of the log item handling code explicitly. An EFD version might be useful for the unlogged EFD error case as well. IMO, the more of these cases that are handled explicitly in xfs_bmap_finish() rather than implicitly via the transaction management code, the more reliable and robust to future change it will be. I'll explore it further...

Yes, that mirrors my thinking exactly - the EFI/EFD error handling has always been problematic with the reliance on reference counting via transaction commit/abort callbacks to handle it.

Quoted 27 lines
Quoted 4 lines

Hmmm - something I just noticed: if we only have one EFD per EFI, why do we do we have that layer of extent counting before dropping real references?

I wondered this myself, but hadn't made it deep enough to see if we used the reference count elsewhere.

Quoted 18 lines

fs/xfs/xfs_extfree_item.c xfs_efd_item_push( · line 429

Quoted 12 lines

xfs_efd_item_unlock(

fs/xfs/xfs_extfree_item.c +6 -2
 	struct xfs_log_item	*lip)
 {
-	if (lip->li_flags & XFS_LI_ABORTED)
-		xfs_efd_item_free(EFD_ITEM(lip));
+	struct xfs_efd_log_item	*efdp = EFD_ITEM(lip);
+
+	if (lip->li_flags & XFS_LI_ABORTED) {
+		xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents);
+		xfs_efd_item_free(efdp);
+	}
 }

i.e. we always call xfs_efi_release() with efi_nextents or efd_nextents, which are always the same, and so we never partially complete an EFI. Should we just kill that layer, as it does tend to complicate the EFI release code?

Quoted 11 lines
Quoted 2 lines

Yeah, that might be a good idea if we don't use the reference count elsewhere. I'll look into that as a subsequent cleanup as well.

Excellent!

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]

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

#9 lore raw

Re: [PATCH RFC 2/2] xfs: fix efi/efd error handling to avoid fs shutdown hangs

In reply to Brian Foster
Quoted 44 lines · Brian Foster

Freeing an extent in XFS involves logging an EFI (extent free intention), freeing the actual extent, and logging an EFD (extent free done). The EFI object is created with a reference count of 2: one for the current transaction and one for the subsequently created EFD. Under normal circumstances, the first reference is dropped when the EFI is unpinned and the second reference is dropped when the EFD is committed to the on-disk log.

In event of errors or filesystem shutdown, there are various potential cleanup scenarios depending on the state of the EFI/EFD. The cleanup scenarios are confusing and racy, as demonstrated by the following test sequence:

	# mount $dev $mnt
	# fsstress -d $mnt -n 99999 -p 16 -z -f fallocate=1 \
		-f punch=1 -f creat=1 -f unlink=1 &
	# sleep 5
	# killall -9 fsstress; wait
	# godown -f $mnt
	# umount

... in which the final umount can hang due to the AIL being pinned indefinitely by one or more EFI items. This can occur due to several conditions. For example, if the shutdown occurs after the EFI is committed to the on-disk log and the EFD committed to the CIL, but before the EFD committed to the log, the EFD iop_committed() abort handler does not drop its reference to the EFI. Alternatively, manual error injection in the xfs_bmap_finish() codepath shows that if an error occurs after the EFI transaction is committed but before the EFD is constructed and logged, the EFI is never released from the AIL.

Update the EFI/EFD item handling code to use a more straightforward and reliable approach to error handling. If the EFI transaction is cancelled, the EFI is freed when the log item is unlocked. If the EFI transaction is committed successfully, from that point forward it is the responsibility of the EFD to drop its EFI reference. This means that the EFI unpin callback only ever drops the log reference to the EFI. It does not free the EFI in the event of log I/O error. This also means that the EFD item must drop its EFI reference either if the EFD transaction is cancelled, committed or itself aborted due to log I/O error. Finally, update xfs_bmap_finish() to ensure that once an EFI transaction is committed, we are guaranteed to construct and log the associated EFD. This ensures that the EFD is aborted and drops the reference to the EFI.

Quoted 1 line

FWIW, we have the same hang problems in log recovery when xfs_free_extent fails - the efd is not logged and the filesystem is not shut down, so the EFI being processed is not released or removed from the AIL. We also abort the processing of EFIs on the first error, leaving the AIL full of EFIs that will never be removed and so the unmount will hang trying to empty the AIL...

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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

Re: [PATCH RFC 1/2] xfs: return committed status from xfs_trans_roll()

In reply to Brian Foster
Quoted 7 lines · Brian Foster
Quoted 4 lines

Hmmm - something I just noticed: if we only have one EFD per EFI, why do we do we have that layer of extent counting before dropping real references?

I wondered this myself, but hadn't made it deep enough to see if we used the reference count elsewhere.

Because the elders (no pun on Alex, sorry :)) didn't realize we

a) don't even ever look at at the logged extents in EFD
b) have a 1:1 relationship between EFIs and EFDs

I tried to sort some of that out about a year ago, but I didn't manage to get far.
have just one. Note that not having to log these

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

#8 lore raw

Re: [PATCH RFC 1/2] xfs: return committed status from xfs_trans_roll()

In reply to Dave Chinner
Quoted 24 lines · Dave Chinner

[ reply to both patches in one reply, because it's related. ]

Quoted 21 lines · Brian Foster

Some callers need to make error handling decisions based on whether the current transaction successfully committed or not. Rename xfs_trans_roll(), add a new parameter and provide a wrapper to preserve existing callers.

---
 fs/xfs/xfs_trans.c | 15 +++++++++++++--
 fs/xfs/xfs_trans.h |  1 +
 2 files changed, 14 insertions(+), 2 deletions(-)
fs/xfs/xfs_trans.c +1 -1
index 0582a27..a0ab1da 100644
@@ -1019,9 +1019,10 @@ xfs_trans_cancel(
  * chunk we've been working on and get a new transaction to continue.
  */
 int
-xfs_trans_roll(
+__xfs_trans_roll(

...

Quoted 33 lines

So xfs_qm_dqalloc(), on error, simply cancels the freelist and returns the error - it ignores the committed flag. So the committed flag is used to determine how to handle the dquot buffer:

        xfs_trans_bhold(tp, bp);

        if ((error = xfs_bmap_finish(tpp, &flist, &committed))) {
                goto error1;
        }

        if (committed) {
                tp = *tpp;
                xfs_trans_bjoin(tp, bp);
        } else {
                xfs_trans_bhold_release(tp, bp);
        }

Now, xfs_trans_bhold() simply sets the BLI_HOLD flag on the buffer, and transaction commit clears it. That means we could call it unconditionally, and all we have to do is remove an assert(BLI_HOLD) from xfs_trans_bhold_release() to enable that. Given this is the only caller of xfs_trans_bhold_release(), I don't see a problem with doing that. Nor is there a problem with multiple joins of an object to a transaction, so we could simply make this:

	xfs_trans_bhold(tp, bp);
	error = xfs_bmap_finish(tpp, &flist, &committed);
	if (error)
		goto error1;
	tp = *tpp;
	xfs_trans_bjoin(tp, bp);
	xfs_trans_bhold_release(tp, bp);
Quoted 4 lines

And the committed flag is not necessary. With this, we can hide everything to do with error on commit vs error after commit inside xfs_bmap_finish()...

I'm starting to look back at this and try to understand the intent here (FYI, I've appended some of the xfs_bmap_cancel() fixes to v3 of the EFI/EFD series, to be posted shortly). Is the proposition that we should be able to remove the committed parameter from xfs_bmap_finish() entirely?

If so, the buffer hold technique makes some sense here, but not necessarily the potential for multiple joins of the object to the transaction that this kind of usage introduces. At least, there are currently assertions to protect against that kind of thing in the buffer/inode join handlers that would have to be removed. In the case of a buffer join, it looks like there's some reference counting that would have to be rectified against this type of usage (I take it there is some appropriate use for this that I'm not familiar with). Both the buffer and inode cases also look like they'd introduce multiple calls to xfs_trans_add_item(), which I'm not sure is totally safe at a glance. The fact that an xfs_log_item points to a single xfs_log_item_desc looks a bit suspicious to me, but I'd have to take a harder look at that.

Even if it were completely safe, IMO we obfuscate the context of code as shown above because the object could be added to the new transaction or re-added to the original depending on whether the previous transaction freed some blocks or not. In other words, I think a multiple join of an object has to be made completely idempotent in order to justify use of a pattern like that shown above. I'm not sure it's worth doing that just to kill a flag. Thoughts?

Brian

Quoted 90 lines
Quoted 22 lines
fs/xfs/xfs_trans.c +13 -2
 	efd = xfs_trans_get_efd(*tp, efi, flist->xbf_count);
 	for (free = flist->xbf_first; free != NULL; free = next) {
 		next = free->xbfi_next;
-		if ((error = xfs_free_extent(*tp, free->xbfi_startblock,
-				free->xbfi_blockcount))) {
+
+		/*
+		 * Free the extent if the above trans roll hasn't failed and log
+		 * the EFD before handling errors from either call to ensure the
+		 * EFI reference is accounted for in the tp. Otherwise, the EFI
+		 * is never released on abort and pins the AIL indefinitely.
+		 */
+		if (!error)
+			error = xfs_free_extent(*tp, free->xbfi_startblock,
+						free->xbfi_blockcount);
+		xfs_trans_log_efd_extent(*tp, efd, free->xbfi_startblock,
+					 free->xbfi_blockcount);
+		if (error) {
 			/*
 			 * The bmap free list will be cleaned up at a
 			 * higher level.  The EFI will be canceled when

fs/xfs/xfs_trans.c xfs_bmap_finish( · line 140

Quoted 10 lines
fs/xfs/xfs_trans.c +2 -3
@@ -118,11 +134,10 @@ xfs_bmap_finish(
 						   SHUTDOWN_META_IO_ERROR);
 			return error;
 		}
-		xfs_trans_log_efd_extent(*tp, efd, free->xbfi_startblock,
-			free->xbfi_blockcount);
 		xfs_bmap_del_free(flist, NULL, free);
 	}
-	return 0;
+
+	return error;

This loop doesn't obviously do the right thing now. It will log the first extent into the EFD and then trigger a shutdown and return. The extent count in the EFD may not match the extent count on the EFI, so releasing the EFD at this point may not release all the extents in the EFI and hence not release the EFI.

I think I'd prefer to see a xfs_trans_cancel_efi() call to handle this error path rather than having to go through the efd to release the reference on the EFI. i.e.

	error = __xfs_trans_roll(tp, NULL, &committed);
	if (error) {
		if (committed) {
			if (!XFS_FORCED_SHUTDOWN(mp))
				xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
			xfs_efi_cancel(tp, efi);
		}
		return error;
	}

/*
* Cancel a committed EFI after triggering a shutdown. We need to do
* this so that the committed EFI is removed from the AIL and freed,
* otherwise unmount will hang due to a non-empty AIL.
*/
xfs_efi_cancel()

{
	ASSERT(XFS_FORCED_SHUTDOWN(mp));
	xfs_efi_release(efi, efi->nextents);
}

Doing this means there's less complexity on the EFD abort side of things, as we don't have to now handle this failure case via transaction completion callback interface.

Hmmm - something I just noticed: if we only have one EFD per EFI, why do we do we have that layer of extent counting before dropping real references?

fs/xfs/xfs_trans.c xfs_bmap_finish(

Quoted 12 lines
fs/xfs/xfs_trans.c +6 -2
 xfs_efd_item_unlock(
 	struct xfs_log_item	*lip)
 {
-	if (lip->li_flags & XFS_LI_ABORTED)
-		xfs_efd_item_free(EFD_ITEM(lip));
+	struct xfs_efd_log_item	*efdp = EFD_ITEM(lip);
+
+	if (lip->li_flags & XFS_LI_ABORTED) {
+		xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents);
+		xfs_efd_item_free(efdp);
+	}
 }

i.e. we always call xfs_efi_release() with efi_nextents or efd_nextents, which are always the same, and so we never partially complete an EFI. Should we just kill that layer, as it does tend to complicate the EFI release code?

Quoted 11 lines

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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

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