2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_alloc_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_dir2_sf.h"
34 #include "xfs_attr_sf.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_buf_item.h"
38 #include "xfs_trans_priv.h"
39 #include "xfs_error.h"
41 #include "xfs_trace.h"
44 * Check to see if a buffer matching the given parameters is already
45 * a part of the given transaction.
47 STATIC struct xfs_buf *
48 xfs_trans_buf_item_match(
50 struct xfs_buftarg *target,
54 xfs_log_item_chunk_t *licp;
55 xfs_log_item_desc_t *lidp;
56 xfs_buf_log_item_t *blip;
60 for (licp = &tp->t_items; licp != NULL; licp = licp->lic_next) {
61 if (xfs_lic_are_all_free(licp)) {
62 ASSERT(licp == &tp->t_items);
63 ASSERT(licp->lic_next == NULL);
67 for (i = 0; i < licp->lic_unused; i++) {
69 * Skip unoccupied slots.
71 if (xfs_lic_isfree(licp, i))
74 lidp = xfs_lic_slot(licp, i);
75 blip = (xfs_buf_log_item_t *)lidp->lid_item;
76 if (blip->bli_item.li_type != XFS_LI_BUF)
79 if (XFS_BUF_TARGET(blip->bli_buf) == target &&
80 XFS_BUF_ADDR(blip->bli_buf) == blkno &&
81 XFS_BUF_COUNT(blip->bli_buf) == len)
90 * Add the locked buffer to the transaction.
92 * The buffer must be locked, and it cannot be associated with any
95 * If the buffer does not yet have a buf log item associated with it,
96 * then allocate one for it. Then add the buf item to the transaction.
100 struct xfs_trans *tp,
104 struct xfs_buf_log_item *bip;
106 ASSERT(XFS_BUF_ISBUSY(bp));
107 ASSERT(XFS_BUF_FSPRIVATE2(bp, void *) == NULL);
110 * The xfs_buf_log_item pointer is stored in b_fsprivate. If
111 * it doesn't have one yet, then allocate one and initialize it.
112 * The checks to see if one is there are in xfs_buf_item_init().
114 xfs_buf_item_init(bp, tp->t_mountp);
115 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
116 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
117 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_CANCEL));
118 ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
123 * Take a reference for this transaction on the buf item.
125 atomic_inc(&bip->bli_refcount);
128 * Get a log_item_desc to point at the new item.
130 (void) xfs_trans_add_item(tp, (xfs_log_item_t *)bip);
133 * Initialize b_fsprivate2 so we can find it with incore_match()
134 * in xfs_trans_get_buf() and friends above.
136 XFS_BUF_SET_FSPRIVATE2(bp, tp);
142 struct xfs_trans *tp,
145 _xfs_trans_bjoin(tp, bp, 0);
146 trace_xfs_trans_bjoin(bp->b_fspriv);
150 * Get and lock the buffer for the caller if it is not already
151 * locked within the given transaction. If it is already locked
152 * within the transaction, just increment its lock recursion count
153 * and return a pointer to it.
155 * If the transaction pointer is NULL, make this just a normal
159 xfs_trans_get_buf(xfs_trans_t *tp,
160 xfs_buftarg_t *target_dev,
166 xfs_buf_log_item_t *bip;
169 flags = XBF_LOCK | XBF_MAPPED;
172 * Default to a normal get_buf() call if the tp is NULL.
175 return xfs_buf_get(target_dev, blkno, len,
176 flags | XBF_DONT_BLOCK);
179 * If we find the buffer in the cache with this transaction
180 * pointer in its b_fsprivate2 field, then we know we already
181 * have it locked. In this case we just increment the lock
182 * recursion count and return the buffer to the caller.
184 bp = xfs_trans_buf_item_match(tp, target_dev, blkno, len);
186 ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
187 if (XFS_FORCED_SHUTDOWN(tp->t_mountp))
188 XFS_BUF_SUPER_STALE(bp);
191 * If the buffer is stale then it was binval'ed
192 * since last read. This doesn't matter since the
193 * caller isn't allowed to use the data anyway.
195 else if (XFS_BUF_ISSTALE(bp))
196 ASSERT(!XFS_BUF_ISDELAYWRITE(bp));
198 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
199 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
201 ASSERT(atomic_read(&bip->bli_refcount) > 0);
203 trace_xfs_trans_get_buf_recur(bip);
208 * We always specify the XBF_DONT_BLOCK flag within a transaction
209 * so that get_buf does not try to push out a delayed write buffer
210 * which might cause another transaction to take place (if the
211 * buffer was delayed alloc). Such recursive transactions can
212 * easily deadlock with our current transaction as well as cause
213 * us to run out of stack space.
215 bp = xfs_buf_get(target_dev, blkno, len, flags | XBF_DONT_BLOCK);
220 ASSERT(!XFS_BUF_GETERROR(bp));
222 _xfs_trans_bjoin(tp, bp, 1);
223 trace_xfs_trans_get_buf(bp->b_fspriv);
228 * Get and lock the superblock buffer of this file system for the
231 * We don't need to use incore_match() here, because the superblock
232 * buffer is a private buffer which we keep a pointer to in the
236 xfs_trans_getsb(xfs_trans_t *tp,
237 struct xfs_mount *mp,
241 xfs_buf_log_item_t *bip;
244 * Default to just trying to lock the superblock buffer
248 return (xfs_getsb(mp, flags));
252 * If the superblock buffer already has this transaction
253 * pointer in its b_fsprivate2 field, then we know we already
254 * have it locked. In this case we just increment the lock
255 * recursion count and return the buffer to the caller.
258 if (XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp) {
259 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t*);
261 ASSERT(atomic_read(&bip->bli_refcount) > 0);
263 trace_xfs_trans_getsb_recur(bip);
267 bp = xfs_getsb(mp, flags);
271 _xfs_trans_bjoin(tp, bp, 1);
272 trace_xfs_trans_getsb(bp->b_fspriv);
277 xfs_buftarg_t *xfs_error_target;
280 int xfs_error_mod = 33;
284 * Get and lock the buffer for the caller if it is not already
285 * locked within the given transaction. If it has not yet been
286 * read in, read it from disk. If it is already locked
287 * within the transaction and already read in, just increment its
288 * lock recursion count and return a pointer to it.
290 * If the transaction pointer is NULL, make this just a normal
297 xfs_buftarg_t *target,
304 xfs_buf_log_item_t *bip;
308 flags = XBF_LOCK | XBF_MAPPED;
311 * Default to a normal get_buf() call if the tp is NULL.
314 bp = xfs_buf_read(target, blkno, len, flags | XBF_DONT_BLOCK);
316 return (flags & XBF_TRYLOCK) ?
317 EAGAIN : XFS_ERROR(ENOMEM);
319 if (XFS_BUF_GETERROR(bp) != 0) {
320 xfs_ioerror_alert("xfs_trans_read_buf", mp,
322 error = XFS_BUF_GETERROR(bp);
328 if (xfs_error_target == target) {
329 if (((xfs_req_num++) % xfs_error_mod) == 0) {
331 cmn_err(CE_DEBUG, "Returning error!\n");
332 return XFS_ERROR(EIO);
337 if (XFS_FORCED_SHUTDOWN(mp))
344 * If we find the buffer in the cache with this transaction
345 * pointer in its b_fsprivate2 field, then we know we already
346 * have it locked. If it is already read in we just increment
347 * the lock recursion count and return the buffer to the caller.
348 * If the buffer is not yet read in, then we read it in, increment
349 * the lock recursion count, and return it to the caller.
351 bp = xfs_trans_buf_item_match(tp, target, blkno, len);
353 ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
354 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
355 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
356 ASSERT((XFS_BUF_ISERROR(bp)) == 0);
357 if (!(XFS_BUF_ISDONE(bp))) {
358 trace_xfs_trans_read_buf_io(bp, _RET_IP_);
359 ASSERT(!XFS_BUF_ISASYNC(bp));
361 xfsbdstrat(tp->t_mountp, bp);
362 error = xfs_iowait(bp);
364 xfs_ioerror_alert("xfs_trans_read_buf", mp,
368 * We can gracefully recover from most read
369 * errors. Ones we can't are those that happen
370 * after the transaction's already dirty.
372 if (tp->t_flags & XFS_TRANS_DIRTY)
373 xfs_force_shutdown(tp->t_mountp,
374 SHUTDOWN_META_IO_ERROR);
379 * We never locked this buf ourselves, so we shouldn't
380 * brelse it either. Just get out.
382 if (XFS_FORCED_SHUTDOWN(mp)) {
383 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
385 return XFS_ERROR(EIO);
389 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t*);
392 ASSERT(atomic_read(&bip->bli_refcount) > 0);
393 trace_xfs_trans_read_buf_recur(bip);
399 * We always specify the XBF_DONT_BLOCK flag within a transaction
400 * so that get_buf does not try to push out a delayed write buffer
401 * which might cause another transaction to take place (if the
402 * buffer was delayed alloc). Such recursive transactions can
403 * easily deadlock with our current transaction as well as cause
404 * us to run out of stack space.
406 bp = xfs_buf_read(target, blkno, len, flags | XBF_DONT_BLOCK);
411 if (XFS_BUF_GETERROR(bp) != 0) {
412 XFS_BUF_SUPER_STALE(bp);
413 error = XFS_BUF_GETERROR(bp);
415 xfs_ioerror_alert("xfs_trans_read_buf", mp,
417 if (tp->t_flags & XFS_TRANS_DIRTY)
418 xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR);
423 if (xfs_do_error && !(tp->t_flags & XFS_TRANS_DIRTY)) {
424 if (xfs_error_target == target) {
425 if (((xfs_req_num++) % xfs_error_mod) == 0) {
426 xfs_force_shutdown(tp->t_mountp,
427 SHUTDOWN_META_IO_ERROR);
429 cmn_err(CE_DEBUG, "Returning trans error!\n");
430 return XFS_ERROR(EIO);
435 if (XFS_FORCED_SHUTDOWN(mp))
438 _xfs_trans_bjoin(tp, bp, 1);
439 trace_xfs_trans_read_buf(bp->b_fspriv);
446 * the theory here is that buffer is good but we're
447 * bailing out because the filesystem is being forcibly
448 * shut down. So we should leave the b_flags alone since
449 * the buffer's not staled and just get out.
452 if (XFS_BUF_ISSTALE(bp) && XFS_BUF_ISDELAYWRITE(bp))
453 cmn_err(CE_NOTE, "about to pop assert, bp == 0x%p", bp);
455 ASSERT((XFS_BUF_BFLAGS(bp) & (XBF_STALE|XBF_DELWRI)) !=
456 (XBF_STALE|XBF_DELWRI));
458 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
461 return XFS_ERROR(EIO);
466 * Release the buffer bp which was previously acquired with one of the
467 * xfs_trans_... buffer allocation routines if the buffer has not
468 * been modified within this transaction. If the buffer is modified
469 * within this transaction, do decrement the recursion count but do
470 * not release the buffer even if the count goes to 0. If the buffer is not
471 * modified within the transaction, decrement the recursion count and
472 * release the buffer if the recursion count goes to 0.
474 * If the buffer is to be released and it was not modified before
475 * this transaction began, then free the buf_log_item associated with it.
477 * If the transaction pointer is NULL, make this just a normal
481 xfs_trans_brelse(xfs_trans_t *tp,
484 xfs_buf_log_item_t *bip;
486 xfs_log_item_desc_t *lidp;
489 * Default to a normal brelse() call if the tp is NULL.
492 ASSERT(XFS_BUF_FSPRIVATE2(bp, void *) == NULL);
494 * If there's a buf log item attached to the buffer,
495 * then let the AIL know that the buffer is being
498 if (XFS_BUF_FSPRIVATE(bp, void *) != NULL) {
499 lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
500 if (lip->li_type == XFS_LI_BUF) {
501 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
502 xfs_trans_unlocked_item(bip->bli_item.li_ailp,
510 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
511 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
512 ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
513 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
514 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_CANCEL));
515 ASSERT(atomic_read(&bip->bli_refcount) > 0);
518 * Find the item descriptor pointing to this buffer's
519 * log item. It must be there.
521 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
522 ASSERT(lidp != NULL);
524 trace_xfs_trans_brelse(bip);
527 * If the release is just for a recursive lock,
528 * then decrement the count and return.
530 if (bip->bli_recur > 0) {
536 * If the buffer is dirty within this transaction, we can't
537 * release it until we commit.
539 if (lidp->lid_flags & XFS_LID_DIRTY)
543 * If the buffer has been invalidated, then we can't release
544 * it until the transaction commits to disk unless it is re-dirtied
545 * as part of this transaction. This prevents us from pulling
546 * the item from the AIL before we should.
548 if (bip->bli_flags & XFS_BLI_STALE)
551 ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
554 * Free up the log item descriptor tracking the released item.
556 xfs_trans_free_item(tp, lidp);
559 * Clear the hold flag in the buf log item if it is set.
560 * We wouldn't want the next user of the buffer to
563 if (bip->bli_flags & XFS_BLI_HOLD) {
564 bip->bli_flags &= ~XFS_BLI_HOLD;
568 * Drop our reference to the buf log item.
570 atomic_dec(&bip->bli_refcount);
573 * If the buf item is not tracking data in the log, then
574 * we must free it before releasing the buffer back to the
575 * free pool. Before releasing the buffer to the free pool,
576 * clear the transaction pointer in b_fsprivate2 to dissolve
577 * its relation to this transaction.
579 if (!xfs_buf_item_dirty(bip)) {
581 ASSERT(bp->b_pincount == 0);
583 ASSERT(atomic_read(&bip->bli_refcount) == 0);
584 ASSERT(!(bip->bli_item.li_flags & XFS_LI_IN_AIL));
585 ASSERT(!(bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF));
586 xfs_buf_item_relse(bp);
589 XFS_BUF_SET_FSPRIVATE2(bp, NULL);
592 * If we've still got a buf log item on the buffer, then
593 * tell the AIL that the buffer is being unlocked.
596 xfs_trans_unlocked_item(bip->bli_item.li_ailp,
597 (xfs_log_item_t*)bip);
605 * Mark the buffer as not needing to be unlocked when the buf item's
606 * IOP_UNLOCK() routine is called. The buffer must already be locked
607 * and associated with the given transaction.
611 xfs_trans_bhold(xfs_trans_t *tp,
614 xfs_buf_log_item_t *bip;
616 ASSERT(XFS_BUF_ISBUSY(bp));
617 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
618 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
620 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
621 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
622 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_CANCEL));
623 ASSERT(atomic_read(&bip->bli_refcount) > 0);
624 bip->bli_flags |= XFS_BLI_HOLD;
625 trace_xfs_trans_bhold(bip);
629 * Cancel the previous buffer hold request made on this buffer
630 * for this transaction.
633 xfs_trans_bhold_release(xfs_trans_t *tp,
636 xfs_buf_log_item_t *bip;
638 ASSERT(XFS_BUF_ISBUSY(bp));
639 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
640 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
642 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
643 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
644 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_CANCEL));
645 ASSERT(atomic_read(&bip->bli_refcount) > 0);
646 ASSERT(bip->bli_flags & XFS_BLI_HOLD);
647 bip->bli_flags &= ~XFS_BLI_HOLD;
649 trace_xfs_trans_bhold_release(bip);
653 * This is called to mark bytes first through last inclusive of the given
654 * buffer as needing to be logged when the transaction is committed.
655 * The buffer must already be associated with the given transaction.
657 * First and last are numbers relative to the beginning of this buffer,
658 * so the first byte in the buffer is numbered 0 regardless of the
662 xfs_trans_log_buf(xfs_trans_t *tp,
667 xfs_buf_log_item_t *bip;
668 xfs_log_item_desc_t *lidp;
670 ASSERT(XFS_BUF_ISBUSY(bp));
671 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
672 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
673 ASSERT((first <= last) && (last < XFS_BUF_COUNT(bp)));
674 ASSERT((XFS_BUF_IODONE_FUNC(bp) == NULL) ||
675 (XFS_BUF_IODONE_FUNC(bp) == xfs_buf_iodone_callbacks));
678 * Mark the buffer as needing to be written out eventually,
679 * and set its iodone function to remove the buffer's buf log
680 * item from the AIL and free it when the buffer is flushed
681 * to disk. See xfs_buf_attach_iodone() for more details
682 * on li_cb and xfs_buf_iodone_callbacks().
683 * If we end up aborting this transaction, we trap this buffer
684 * inside the b_bdstrat callback so that this won't get written to
687 XFS_BUF_DELAYWRITE(bp);
690 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
691 ASSERT(atomic_read(&bip->bli_refcount) > 0);
692 XFS_BUF_SET_IODONE_FUNC(bp, xfs_buf_iodone_callbacks);
693 bip->bli_item.li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*))xfs_buf_iodone;
695 trace_xfs_trans_log_buf(bip);
698 * If we invalidated the buffer within this transaction, then
699 * cancel the invalidation now that we're dirtying the buffer
700 * again. There are no races with the code in xfs_buf_item_unpin(),
701 * because we have a reference to the buffer this entire time.
703 if (bip->bli_flags & XFS_BLI_STALE) {
704 bip->bli_flags &= ~XFS_BLI_STALE;
705 ASSERT(XFS_BUF_ISSTALE(bp));
707 bip->bli_format.blf_flags &= ~XFS_BLF_CANCEL;
710 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
711 ASSERT(lidp != NULL);
713 tp->t_flags |= XFS_TRANS_DIRTY;
714 lidp->lid_flags |= XFS_LID_DIRTY;
715 bip->bli_flags |= XFS_BLI_LOGGED;
716 xfs_buf_item_log(bip, first, last);
721 * This called to invalidate a buffer that is being used within
722 * a transaction. Typically this is because the blocks in the
723 * buffer are being freed, so we need to prevent it from being
724 * written out when we're done. Allowing it to be written again
725 * might overwrite data in the free blocks if they are reallocated
728 * We prevent the buffer from being written out by clearing the
729 * B_DELWRI flag. We can't always
730 * get rid of the buf log item at this point, though, because
731 * the buffer may still be pinned by another transaction. If that
732 * is the case, then we'll wait until the buffer is committed to
733 * disk for the last time (we can tell by the ref count) and
734 * free it in xfs_buf_item_unpin(). Until it is cleaned up we
735 * will keep the buffer locked so that the buffer and buf log item
743 xfs_log_item_desc_t *lidp;
744 xfs_buf_log_item_t *bip;
746 ASSERT(XFS_BUF_ISBUSY(bp));
747 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
748 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
750 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
751 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
752 ASSERT(lidp != NULL);
753 ASSERT(atomic_read(&bip->bli_refcount) > 0);
755 trace_xfs_trans_binval(bip);
757 if (bip->bli_flags & XFS_BLI_STALE) {
759 * If the buffer is already invalidated, then
762 ASSERT(!(XFS_BUF_ISDELAYWRITE(bp)));
763 ASSERT(XFS_BUF_ISSTALE(bp));
764 ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY)));
765 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_INODE_BUF));
766 ASSERT(bip->bli_format.blf_flags & XFS_BLF_CANCEL);
767 ASSERT(lidp->lid_flags & XFS_LID_DIRTY);
768 ASSERT(tp->t_flags & XFS_TRANS_DIRTY);
773 * Clear the dirty bit in the buffer and set the STALE flag
774 * in the buf log item. The STALE flag will be used in
775 * xfs_buf_item_unpin() to determine if it should clean up
776 * when the last reference to the buf item is given up.
777 * We set the XFS_BLF_CANCEL flag in the buf log format structure
778 * and log the buf item. This will be used at recovery time
779 * to determine that copies of the buffer in the log before
780 * this should not be replayed.
781 * We mark the item descriptor and the transaction dirty so
782 * that we'll hold the buffer until after the commit.
784 * Since we're invalidating the buffer, we also clear the state
785 * about which parts of the buffer have been logged. We also
786 * clear the flag indicating that this is an inode buffer since
787 * the data in the buffer will no longer be valid.
789 * We set the stale bit in the buffer as well since we're getting
792 XFS_BUF_UNDELAYWRITE(bp);
794 bip->bli_flags |= XFS_BLI_STALE;
795 bip->bli_flags &= ~(XFS_BLI_INODE_BUF | XFS_BLI_LOGGED | XFS_BLI_DIRTY);
796 bip->bli_format.blf_flags &= ~XFS_BLF_INODE_BUF;
797 bip->bli_format.blf_flags |= XFS_BLF_CANCEL;
798 memset((char *)(bip->bli_format.blf_data_map), 0,
799 (bip->bli_format.blf_map_size * sizeof(uint)));
800 lidp->lid_flags |= XFS_LID_DIRTY;
801 tp->t_flags |= XFS_TRANS_DIRTY;
805 * This call is used to indicate that the buffer contains on-disk inodes which
806 * must be handled specially during recovery. They require special handling
807 * because only the di_next_unlinked from the inodes in the buffer should be
808 * recovered. The rest of the data in the buffer is logged via the inodes
811 * All we do is set the XFS_BLI_INODE_BUF flag in the items flags so it can be
812 * transferred to the buffer's log format structure so that we'll know what to
813 * do at recovery time.
820 xfs_buf_log_item_t *bip;
822 ASSERT(XFS_BUF_ISBUSY(bp));
823 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
824 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
826 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
827 ASSERT(atomic_read(&bip->bli_refcount) > 0);
829 bip->bli_flags |= XFS_BLI_INODE_BUF;
833 * This call is used to indicate that the buffer is going to
834 * be staled and was an inode buffer. This means it gets
835 * special processing during unpin - where any inodes
836 * associated with the buffer should be removed from ail.
837 * There is also special processing during recovery,
838 * any replay of the inodes in the buffer needs to be
839 * prevented as the buffer may have been reused.
842 xfs_trans_stale_inode_buf(
846 xfs_buf_log_item_t *bip;
848 ASSERT(XFS_BUF_ISBUSY(bp));
849 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
850 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
852 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
853 ASSERT(atomic_read(&bip->bli_refcount) > 0);
855 bip->bli_flags |= XFS_BLI_STALE_INODE;
856 bip->bli_item.li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*))
863 * Mark the buffer as being one which contains newly allocated
864 * inodes. We need to make sure that even if this buffer is
865 * relogged as an 'inode buf' we still recover all of the inode
866 * images in the face of a crash. This works in coordination with
867 * xfs_buf_item_committed() to ensure that the buffer remains in the
868 * AIL at its original location even after it has been relogged.
872 xfs_trans_inode_alloc_buf(
876 xfs_buf_log_item_t *bip;
878 ASSERT(XFS_BUF_ISBUSY(bp));
879 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
880 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
882 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
883 ASSERT(atomic_read(&bip->bli_refcount) > 0);
885 bip->bli_flags |= XFS_BLI_INODE_ALLOC_BUF;
890 * Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of
891 * dquots. However, unlike in inode buffer recovery, dquot buffers get
892 * recovered in their entirety. (Hence, no XFS_BLI_DQUOT_ALLOC_BUF flag).
893 * The only thing that makes dquot buffers different from regular
894 * buffers is that we must not replay dquot bufs when recovering
895 * if a _corresponding_ quotaoff has happened. We also have to distinguish
896 * between usr dquot bufs and grp dquot bufs, because usr and grp quotas
897 * can be turned off independently.
906 xfs_buf_log_item_t *bip;
908 ASSERT(XFS_BUF_ISBUSY(bp));
909 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
910 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
911 ASSERT(type == XFS_BLF_UDQUOT_BUF ||
912 type == XFS_BLF_PDQUOT_BUF ||
913 type == XFS_BLF_GDQUOT_BUF);
915 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
916 ASSERT(atomic_read(&bip->bli_refcount) > 0);
918 bip->bli_format.blf_flags |= type;