/* * Freeing the BUI requires that we remove it from the AIL if it has already * been placed there. However, the BUI may not yet have been placed in the AIL * when called by xfs_bui_release() from BUD processing due to the ordering of * committed vs unpin operations in bulk insert operations. Hence the reference * count to ensure only the last caller frees the BUI.
*/ STATICvoid
xfs_bui_release( struct xfs_bui_log_item *buip)
{
ASSERT(atomic_read(&buip->bui_refcount) > 0); if (!atomic_dec_and_test(&buip->bui_refcount)) return;
/* * This is called to fill in the vector of log iovecs for the * given bui log item. We use only 1 iovec, and we point that * at the bui_log_format structure embedded in the bui item. * It is at this point that we assert that all of the extent * slots in the bui item have been filled.
*/ STATICvoid
xfs_bui_item_format( struct xfs_log_item *lip, struct xfs_log_vec *lv)
{ struct xfs_bui_log_item *buip = BUI_ITEM(lip); struct xfs_log_iovec *vecp = NULL;
/* * The unpin operation is the last place an BUI is manipulated in the log. It is * either inserted in the AIL or aborted in the event of a log I/O error. In * either case, the BUI transaction has been successfully committed to make it * this far. Therefore, we expect whoever committed the BUI to either construct * and commit the BUD or drop the BUD's reference in the event of error. Simply * drop the log's BUI reference now that the log is done with it.
*/ STATICvoid
xfs_bui_item_unpin( struct xfs_log_item *lip, int remove)
{ struct xfs_bui_log_item *buip = BUI_ITEM(lip);
xfs_bui_release(buip);
}
/* * The BUI has been either committed or aborted if the transaction has been * cancelled. If the transaction was cancelled, an BUD isn't going to be * constructed and thus we free the BUI here directly.
*/ STATICvoid
xfs_bui_item_release( struct xfs_log_item *lip)
{
xfs_bui_release(BUI_ITEM(lip));
}
/* * Allocate and initialize an bui item with the given number of extents.
*/ STATICstruct xfs_bui_log_item *
xfs_bui_init( struct xfs_mount *mp)
/* * This is called to fill in the vector of log iovecs for the * given bud log item. We use only 1 iovec, and we point that * at the bud_log_format structure embedded in the bud item. * It is at this point that we assert that all of the extent * slots in the bud item have been filled.
*/ STATICvoid
xfs_bud_item_format( struct xfs_log_item *lip, struct xfs_log_vec *lv)
{ struct xfs_bud_log_item *budp = BUD_ITEM(lip); struct xfs_log_iovec *vecp = NULL;
/* * The BUD is either committed or aborted if the transaction is cancelled. If * the transaction is cancelled, drop our reference to the BUI and free the * BUD.
*/ STATICvoid
xfs_bud_item_release( struct xfs_log_item *lip)
{ struct xfs_bud_log_item *budp = BUD_ITEM(lip);
/* * atomic_inc_return gives us the value after the increment; * we want to use it as an array index so we need to subtract 1 from * it.
*/
next_extent = atomic_inc_return(&buip->bui_next_extent) - 1;
ASSERT(next_extent < buip->bui_format.bui_nextents);
map = &buip->bui_format.bui_extents[next_extent];
map->me_owner = bi->bi_owner->i_ino;
map->me_startblock = bi->bi_bmap.br_startblock;
map->me_startoff = bi->bi_bmap.br_startoff;
map->me_len = bi->bi_bmap.br_blockcount;
switch (bi->bi_type) { case XFS_BMAP_MAP: case XFS_BMAP_UNMAP:
map->me_flags = bi->bi_type; break; default:
ASSERT(0);
} if (bi->bi_bmap.br_state == XFS_EXT_UNWRITTEN)
map->me_flags |= XFS_BMAP_EXTENT_UNWRITTEN; if (bi->bi_whichfork == XFS_ATTR_FORK)
map->me_flags |= XFS_BMAP_EXTENT_ATTR_FORK; if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork))
map->me_flags |= XFS_BMAP_EXTENT_REALTIME;
}
/* Get an BUD so we can process all the deferred bmap updates. */ staticstruct xfs_log_item *
xfs_bmap_update_create_done( struct xfs_trans *tp, struct xfs_log_item *intent, unsignedint count)
{ struct xfs_bui_log_item *buip = BUI_ITEM(intent); struct xfs_bud_log_item *budp;
/* Take a passive ref to the group containing the space we're mapping. */ staticinlinevoid
xfs_bmap_update_get_group( struct xfs_mount *mp, struct xfs_bmap_intent *bi)
{ enum xfs_group_type type = XG_TYPE_AG;
if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork))
type = XG_TYPE_RTG;
/* * Bump the intent count on behalf of the deferred rmap and refcount * intent items that that we can queue when we finish this bmap work. * This new intent item will bump the intent count before the bmap * intent drops the intent count, ensuring that the intent count * remains nonzero across the transaction roll.
*/
bi->bi_group = xfs_group_intent_get(mp, bi->bi_bmap.br_startblock,
type);
}
/* Add this deferred BUI to the transaction. */ void
xfs_bmap_defer_add( struct xfs_trans *tp, struct xfs_bmap_intent *bi)
{
xfs_bmap_update_get_group(tp->t_mountp, bi);
/* * Ensure the deferred mapping is pre-recorded in i_delayed_blks. * * Otherwise stat can report zero blocks for an inode that actually has * data when the entire mapping is in the process of being overwritten * using the out of place write path. This is undone in xfs_bmapi_remap * after it has incremented di_nblocks for a successful operation.
*/ if (bi->bi_type == XFS_BMAP_MAP)
bi->bi_owner->i_delayed_blks += bi->bi_bmap.br_blockcount;
error = xfs_iext_count_extend(tp, ip, work->bi_whichfork, iext_delta); if (error) goto err_cancel;
error = xlog_recover_finish_intent(tp, dfp); if (error == -EFSCORRUPTED)
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
&buip->bui_format, sizeof(buip->bui_format)); if (error) goto err_cancel;
/* * Commit transaction, which frees the transaction and saves the inode * for later replay activities.
*/
error = xfs_defer_ops_capture_and_commit(tp, capture_list); if (error) goto err_unlock;
for (i = 0; i < src->bui_nextents; i++)
memcpy(&dst->bui_extents[i], &src->bui_extents[i], sizeof(struct xfs_map_extent));
}
/* * This routine is called to create an in-core extent bmap update * item from the bui format structure which was logged on disk. * It allocates an in-core bui, copies the extents from the format * structure into it, and adds the bui to the AIL with the given * LSN.
*/ STATICint
xlog_recover_bui_commit_pass2( struct xlog *log, struct list_head *buffer_list, struct xlog_recover_item *item,
xfs_lsn_t lsn)
{ struct xfs_mount *mp = log->l_mp; struct xfs_bui_log_item *buip; struct xfs_bui_log_format *bui_formatp;
size_t len;
/* * This routine is called when an BUD format structure is found in a committed * transaction in the log. Its purpose is to cancel the corresponding BUI if it * was still in the log. To do this it searches the AIL for the BUI with an id * equal to that in the BUD format structure. If we find it we drop the BUD * reference, which removes the BUI from the AIL and frees it.
*/ STATICint
xlog_recover_bud_commit_pass2( struct xlog *log, struct list_head *buffer_list, struct xlog_recover_item *item,
xfs_lsn_t lsn)
{ struct xfs_bud_log_format *bud_formatp;