/* * Return a pointer to the first descriptor in the chunk list. * This does not return NULL if there are none, it panics. * * The first descriptor must be in either the first or second chunk. * This is because the only chunk allowed to be empty is the first. * All others are freed when they become empty. * * At some point this and xfs_trans_next_item() should be optimized * to quickly look at the mask to determine if there is anything to * look at. */ xfs_log_item_desc_t * xfs_trans_first_item(xfs_trans_t *tp) { xfs_log_item_chunk_t *licp; int i; licp = &tp->t_items; /* * If it's not in the first chunk, skip to the second. */ if (XFS_LIC_ARE_ALL_FREE(licp)) { licp = licp->lic_next; } /* * Return the first non-free descriptor in the chunk. */ 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); } cmn_err(CE_WARN, "xfs_trans_first_item() -- no first item"); return 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 */ }
xfs_log_item_desc_t * xfs_lic_slot(xfs_log_item_chunk_t *cp, int slot) { return XFS_LIC_SLOT(cp, slot); }
/* * This is called to add the given log item to the transaction's * list of log items. It must find a free log item descriptor * or allocate a new one and add the item to that descriptor. * The function returns a pointer to item descriptor used to point * to the new item. The log item will now point to its new descriptor * with its li_desc field. */ xfs_log_item_desc_t * xfs_trans_add_item(xfs_trans_t *tp, xfs_log_item_t *lip) { xfs_log_item_desc_t *lidp; xfs_log_item_chunk_t *licp; int i=0; /* * If there are no free descriptors, allocate a new chunk * of them and put it at the front of the chunk list. */ if (tp->t_items_free == 0) { licp = (xfs_log_item_chunk_t*) kmem_alloc(sizeof(xfs_log_item_chunk_t), KM_SLEEP); ASSERT(licp != NULL); /* * Initialize the chunk, and then * claim the first slot in the newly allocated chunk. */ XFS_LIC_INIT(licp); XFS_LIC_CLAIM(licp, 0); licp->lic_unused = 1; XFS_LIC_INIT_SLOT(licp, 0); lidp = XFS_LIC_SLOT(licp, 0); /* * Link in the new chunk and update the free count. */ licp->lic_next = tp->t_items.lic_next; tp->t_items.lic_next = licp; tp->t_items_free = XFS_LIC_NUM_SLOTS - 1; /* * Initialize the descriptor and the generic portion * of the log item. * * Point the new slot at this item and return it. * Also point the log item at its currently active * descriptor and set the item's mount pointer. */ lidp->lid_item = lip; lidp->lid_flags = 0; lidp->lid_size = 0; lip->li_desc = lidp; lip->li_mountp = tp->t_mountp; return lidp; } /* * Find the free descriptor. It is somewhere in the chunklist * of descriptors. */ licp = &tp->t_items; while (licp != NULL) { if (XFS_LIC_VACANCY(licp)) { if (licp->lic_unused <= XFS_LIC_MAX_SLOT) { i = licp->lic_unused; ASSERT(XFS_LIC_ISFREE(licp, i)); break; } for (i = 0; i <= XFS_LIC_MAX_SLOT; i++) { if (XFS_LIC_ISFREE(licp, i)) break; } ASSERT(i <= XFS_LIC_MAX_SLOT); break; } licp = licp->lic_next; } ASSERT(licp != NULL); /* * If we find a free descriptor, claim it, * initialize it, and return it. */ XFS_LIC_CLAIM(licp, i); if (licp->lic_unused <= i) { licp->lic_unused = i + 1; XFS_LIC_INIT_SLOT(licp, i); } lidp = XFS_LIC_SLOT(licp, i); tp->t_items_free--; lidp->lid_item = lip; lidp->lid_flags = 0; lidp->lid_size = 0; lip->li_desc = lidp; lip->li_mountp = tp->t_mountp; return lidp; }