/* * THIS SHOULD BE REWRITTEN TO USE xfs_trans_next_item(). * * This is typically called by the LM when a transaction has been fully * committed to disk. It needs to unpin the items which have * been logged by the transaction and update their positions * in the AIL if necessary. * This also gets called when the transactions didn't get written out * because of an I/O error. Abortflag & XFS_LI_ABORTED is set then. * * Call xfs_trans_chunk_committed() to process the items in * each chunk. */ STATIC void xfs_trans_committed( xfs_trans_t *tp, int abortflag) { xfs_log_item_chunk_t *licp; xfs_log_item_chunk_t *next_licp; xfs_log_busy_chunk_t *lbcp; xfs_log_busy_slot_t *lbsp; int i; /* * Call the transaction's completion callback if there * is one. */ if (tp->t_callback != NULL) { tp->t_callback(tp, tp->t_callarg); } /* * Special case the chunk embedded in the transaction. */ licp = &(tp->t_items); if (!(XFS_LIC_ARE_ALL_FREE(licp))) { xfs_trans_chunk_committed(licp, tp->t_lsn, abortflag); } /* * Process the items in each chunk in turn. */ licp = licp->lic_next; while (licp != NULL) { ASSERT(!XFS_LIC_ARE_ALL_FREE(licp)); xfs_trans_chunk_committed(licp, tp->t_lsn, abortflag); next_licp = licp->lic_next; kmem_free(licp, sizeof(xfs_log_item_chunk_t)); licp = next_licp; } /* * Clear all the per-AG busy list items listed in this transaction */ lbcp = &tp->t_busy; while (lbcp != NULL) { for (i = 0, lbsp = lbcp->lbc_busy; i < lbcp->lbc_unused; i++, lbsp++) { if (!XFS_LBC_ISFREE(lbcp, i)) { xfs_alloc_clear_busy(tp, lbsp->lbc_ag, lbsp->lbc_idx); } } lbcp = lbcp->lbc_next; } xfs_trans_free_busy(tp); /* * That's it for the transaction structure. Free it. */ xfs_trans_free(tp); }
/* * This is called to unlock the items associated with a transaction. * Items which were not logged should be freed. * Those which were logged must still be tracked so they can be unpinned * when the transaction commits. */ void xfs_trans_unlock_items(xfs_trans_t *tp, xfs_lsn_t commit_lsn) { xfs_log_item_chunk_t *licp; xfs_log_item_chunk_t *next_licp; xfs_log_item_chunk_t **licpp; int freed; freed = 0; licp = &tp->t_items; /* * Special case the embedded chunk so we don't free. */ if (!XFS_LIC_ARE_ALL_FREE(licp)) { freed = xfs_trans_unlock_chunk(licp, 0, 0, commit_lsn); } licpp = &(tp->t_items.lic_next); licp = licp->lic_next; /* * Unlock each item in each chunk, free non-dirty descriptors, * and free empty chunks. */ while (licp != NULL) { ASSERT(!XFS_LIC_ARE_ALL_FREE(licp)); freed += xfs_trans_unlock_chunk(licp, 0, 0, commit_lsn); next_licp = licp->lic_next; if (XFS_LIC_ARE_ALL_FREE(licp)) { *licpp = next_licp; kmem_free(licp, sizeof(xfs_log_item_chunk_t)); freed -= XFS_LIC_NUM_SLOTS; } else { licpp = &(licp->lic_next); } ASSERT(*licpp == next_licp); licp = next_licp; } /* * Fix the free descriptor count in the transaction. */ tp->t_items_free += freed; }
/* * This is called to unlock all of the items of a transaction and to free * all the descriptors of that transaction. * * It walks the list of descriptors and unlocks each item. It frees * each chunk except that embedded in the transaction as it goes along. */ void xfs_trans_free_items( xfs_trans_t *tp, int flags) { xfs_log_item_chunk_t *licp; xfs_log_item_chunk_t *next_licp; int abort; abort = flags & XFS_TRANS_ABORT; licp = &tp->t_items; /* * Special case the embedded chunk so we don't free it below. */ if (!XFS_LIC_ARE_ALL_FREE(licp)) { (void) xfs_trans_unlock_chunk(licp, 1, abort, NULLCOMMITLSN); XFS_LIC_ALL_FREE(licp); licp->lic_unused = 0; } licp = licp->lic_next; /* * Unlock each item in each chunk and free the chunks. */ while (licp != NULL) { ASSERT(!XFS_LIC_ARE_ALL_FREE(licp)); (void) xfs_trans_unlock_chunk(licp, 1, abort, NULLCOMMITLSN); next_licp = licp->lic_next; kmem_free(licp, sizeof(xfs_log_item_chunk_t)); licp = next_licp; } /* * Reset the transaction structure's free item count. */ tp->t_items_free = XFS_LIC_NUM_SLOTS; tp->t_items.lic_next = NULL; }
/*ARGSUSED*/ xfs_log_item_desc_t * xfs_trans_next_item(xfs_trans_t *tp, xfs_log_item_desc_t *lidp) { xfs_log_item_chunk_t *licp; int i; licp = XFS_LIC_DESC_TO_CHUNK(lidp); /* * First search the rest of the chunk. The for loop keeps us * from referencing things beyond the end of the chunk. */ for (i = (int)XFS_LIC_DESC_TO_SLOT(lidp) + 1; i < licp->lic_unused; i++) { if (XFS_LIC_ISFREE(licp, i)) { continue; } return XFS_LIC_SLOT(licp, i); } /* * Now search the next chunk. It must be there, because the * next chunk would have been freed if it were empty. * If there is no next chunk, return NULL. */ if (licp->lic_next == NULL) { return NULL; } licp = licp->lic_next; ASSERT(!XFS_LIC_ARE_ALL_FREE(licp)); for (i = 0; i < licp->lic_unused; i++) { if (XFS_LIC_ISFREE(licp, i)) { continue; } return XFS_LIC_SLOT(licp, i); } ASSERT(0); /* NOTREACHED */ return NULL; /* keep gcc quite */ }
/* * Free the given descriptor. * * This requires setting the bit in the chunk's free mask corresponding * to the given slot. */ void xfs_trans_free_item(xfs_trans_t *tp, xfs_log_item_desc_t *lidp) { uint slot; xfs_log_item_chunk_t *licp; xfs_log_item_chunk_t **licpp; slot = XFS_LIC_DESC_TO_SLOT(lidp); licp = XFS_LIC_DESC_TO_CHUNK(lidp); XFS_LIC_RELSE(licp, slot); lidp->lid_item->li_desc = NULL; tp->t_items_free++; /* * If there are no more used items in the chunk and this is not * the chunk embedded in the transaction structure, then free * the chunk. First pull it from the chunk list and then * free it back to the heap. We didn't bother with a doubly * linked list here because the lists should be very short * and this is not a performance path. It's better to save * the memory of the extra pointer. * * Also decrement the transaction structure's count of free items * by the number in a chunk since we are freeing an empty chunk. */ if (XFS_LIC_ARE_ALL_FREE(licp) && (licp != &(tp->t_items))) { licpp = &(tp->t_items.lic_next); while (*licpp != licp) { ASSERT(*licpp != NULL); licpp = &((*licpp)->lic_next); } *licpp = licp->lic_next; kmem_free(licp, sizeof(xfs_log_item_chunk_t)); tp->t_items_free -= XFS_LIC_NUM_SLOTS; } }
int xfs_lic_are_all_free(xfs_log_item_chunk_t *cp) { return XFS_LIC_ARE_ALL_FREE(cp); }