The end of this function could use some cleanup -- the EAGAIN conditionals make it harder to figure out what's going on with the disposal of xattri_leaf_bp, and the dual error/ret variables aren't needed. Turn the EAGAIN case into a separate block documenting all the subtleties of recovering in the middle of an xattr update chain, which makes the rest of the prologue much simpler.
Unified · Split
| @@ -582,7 +582,7 @@ xfs_attri_item_recover( · 581 unmodified lines | |||
| 582 | struct xfs_trans_res tres; | 582 | struct xfs_trans_res tres; |
| 583 | struct xfs_attri_log_format *attrp; | 583 | struct xfs_attri_log_format *attrp; |
| 584 | struct xfs_attri_log_nameval *nv = attrip->attri_nameval; | 584 | struct xfs_attri_log_nameval *nv = attrip->attri_nameval; |
| 585 | int error, ret = 0; | 585 | int error; |
| 586 | int total; | 586 | int total; |
| 587 | int local; | 587 | int local; |
| 588 | struct xfs_attrd_log_item *done_item = NULL; | 588 | struct xfs_attrd_log_item *done_item = NULL; |
| @@ -661,13 +661,31 @@ xfs_attri_item_recover( · 72 unmodified lines | |||
| 661 | xfs_ilock(ip, XFS_ILOCK_EXCL); | 661 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 662 | xfs_trans_ijoin(tp, ip, 0); | 662 | xfs_trans_ijoin(tp, ip, 0); |
| 663 | 663 | ||
| 664 | ret = xfs_xattri_finish_update(attr, done_item); | 664 | error = xfs_xattri_finish_update(attr, done_item); |
| 665 | if (ret == -EAGAIN) { | 665 | if (error == -EAGAIN) { |
| 666 | /* There's more work to do, so add it to this transaction */ | 666 | /* |
| 667 | * There's more work to do, so add the intent item to this | ||
| 668 | * transaction so that we can continue it later. | ||
| 669 | */ | ||
| 667 | xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_ATTR, &attr->xattri_list); | 670 | xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_ATTR, &attr->xattri_list); |
| 668 | } else | 671 | error = xfs_defer_ops_capture_and_commit(tp, capture_list); |
| 669 | error = ret; | 672 | if (error) |
| 673 | goto out_unlock; | ||
| 674 | |||
| 675 | /* | ||
| 676 | * The defer capture structure took its own reference to the | ||
| 677 | * attr leaf buffer and will give that to the continuation | ||
| 678 | * transaction. The attr intent struct drives the continuation | ||
| 679 | * work, so release our refcount on the attr leaf buffer but | ||
| 680 | * retain the pointer in the intent structure. | ||
| 681 | */ | ||
| 682 | if (attr->xattri_leaf_bp) | ||
| 683 | xfs_buf_relse(attr->xattri_leaf_bp); | ||
| 670 | 684 | ||
| 685 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | ||
| 686 | xfs_irele(ip); | ||
| 687 | return 0; | ||
| 688 | } | ||
| 671 | if (error) { | 689 | if (error) { |
| 672 | xfs_trans_cancel(tp); | 690 | xfs_trans_cancel(tp); |
| 673 | goto out_unlock; | 691 | goto out_unlock; |
| @@ -678,24 +696,13 @@ xfs_attri_item_recover( · 4 unmodified lines | |||
| 678 | out_unlock: | 696 | out_unlock: |
| 679 | if (attr->xattri_leaf_bp) { | 697 | if (attr->xattri_leaf_bp) { |
| 680 | xfs_buf_relse(attr->xattri_leaf_bp); | 698 | xfs_buf_relse(attr->xattri_leaf_bp); |
| 681 | 699 | attr->xattri_leaf_bp = NULL; | |
| 682 | /* | ||
| 683 | * If there's more work to do to complete the attr intent, the | ||
| 684 | * defer capture structure will have taken its own reference to | ||
| 685 | * the attr leaf buffer and will give that to the continuation | ||
| 686 | * transaction. The attr intent struct drives the continuation | ||
| 687 | * work, so release our refcount on the attr leaf buffer but | ||
| 688 | * retain the pointer in the intent structure. | ||
| 689 | */ | ||
| 690 | if (ret != -EAGAIN) | ||
| 691 | attr->xattri_leaf_bp = NULL; | ||
| 692 | } | 700 | } |
| 693 | 701 | ||
| 694 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | 702 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 695 | xfs_irele(ip); | 703 | xfs_irele(ip); |
| 696 | out: | 704 | out: |
| 697 | if (ret != -EAGAIN) | 705 | xfs_attr_free_item(attr); |
| 698 | xfs_attr_free_item(attr); | ||
| 699 | return error; | 706 | return error; |
| 700 | } | 707 | } |
| 701 | 708 | ||