/* Release dabuf from a transaction. Have to free up the dabuf before the buffers are released, since the synchronization on the dabuf is really the lock on the buffer.  */
void xfs_da_brelse(xfs_trans_t *tp, xfs_dabuf_t *dabuf)
/* Release dabuf from a transaction. Have to free up the dabuf before the buffers are released, since the synchronization on the dabuf is really the lock on the buffer.  */
void xfs_da_brelse(xfs_trans_t *tp, xfs_dabuf_t *dabuf)
{
	xfs_buf_t	*bp;
	xfs_buf_t	**bplist;
	int		i;
	int		nbuf;
	ASSERT(dabuf->nbuf && dabuf->data && dabuf->bbcount && dabuf->bps[0]);
	if ((nbuf = dabuf->nbuf) == 1) {
		bplist = &bp;
		bp = dabuf->bps[0];
	} else {
		bplist = kmem_alloc(nbuf * sizeof(*bplist), KM_SLEEP);
		memcpy(bplist, dabuf->bps, nbuf * sizeof(*bplist));
	}
	xfs_da_buf_done(dabuf);
	for (i = 0; i < nbuf; i++)
		xfs_trans_brelse(tp, bplist[i]);
	if (bplist != &bp)
		kmem_free(bplist);
}