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_mount.h"
29 #include "xfs_bmap_btree.h"
30 #include "xfs_alloc_btree.h"
31 #include "xfs_ialloc_btree.h"
32 #include "xfs_dir2_sf.h"
33 #include "xfs_attr_sf.h"
34 #include "xfs_dinode.h"
35 #include "xfs_inode.h"
36 #include "xfs_buf_item.h"
37 #include "xfs_trans_priv.h"
38 #include "xfs_error.h"
40 #include "xfs_trace.h"
43 * Check to see if a buffer matching the given parameters is already
44 * a part of the given transaction.
46 STATIC struct xfs_buf *
47 xfs_trans_buf_item_match(
49 struct xfs_buftarg *target,
53 xfs_log_item_chunk_t *licp;
54 xfs_log_item_desc_t *lidp;
55 xfs_buf_log_item_t *blip;
59 for (licp = &tp->t_items; licp != NULL; licp = licp->lic_next) {
60 if (xfs_lic_are_all_free(licp)) {
61 ASSERT(licp == &tp->t_items);
62 ASSERT(licp->lic_next == NULL);
66 for (i = 0; i < licp->lic_unused; i++) {
68 * Skip unoccupied slots.
70 if (xfs_lic_isfree(licp, i))
73 lidp = xfs_lic_slot(licp, i);
74 blip = (xfs_buf_log_item_t *)lidp->lid_item;
75 if (blip->bli_item.li_type != XFS_LI_BUF)
78 if (XFS_BUF_TARGET(blip->bli_buf) == target &&
79 XFS_BUF_ADDR(blip->bli_buf) == blkno &&
80 XFS_BUF_COUNT(blip->bli_buf) == len)
89 * Add the locked buffer to the transaction.
91 * The buffer must be locked, and it cannot be associated with any
94 * If the buffer does not yet have a buf log item associated with it,
95 * then allocate one for it. Then add the buf item to the transaction.
103 struct xfs_buf_log_item *bip;
105 ASSERT(XFS_BUF_ISBUSY(bp));
106 ASSERT(XFS_BUF_FSPRIVATE2(bp, void *) == NULL);
109 * The xfs_buf_log_item pointer is stored in b_fsprivate. If
110 * it doesn't have one yet, then allocate one and initialize it.
111 * The checks to see if one is there are in xfs_buf_item_init().
113 xfs_buf_item_init(bp, tp->t_mountp);
114 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
115 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
116 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_CANCEL));
117 ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
122 * Take a reference for this transaction on the buf item.
124 atomic_inc(&bip->bli_refcount);
127 * Get a log_item_desc to point at the new item.
129 (void) xfs_trans_add_item(tp, (xfs_log_item_t *)bip);
132 * Initialize b_fsprivate2 so we can find it with incore_match()
133 * in xfs_trans_get_buf() and friends above.
135 XFS_BUF_SET_FSPRIVATE2(bp, tp);
141 struct xfs_trans *tp,
144 _xfs_trans_bjoin(tp, bp, 0);
145 trace_xfs_trans_bjoin(bp->b_fspriv);
149 * Get and lock the buffer for the caller if it is not already
150 * locked within the given transaction. If it is already locked
151 * within the transaction, just increment its lock recursion count
152 * and return a pointer to it.
154 * If the transaction pointer is NULL, make this just a normal
158 xfs_trans_get_buf(xfs_trans_t *tp,
159 xfs_buftarg_t *target_dev,
165 xfs_buf_log_item_t *bip;
168 flags = XBF_LOCK | XBF_MAPPED;
171 * Default to a normal get_buf() call if the tp is NULL.
174 return xfs_buf_get(target_dev, blkno, len,
175 flags | XBF_DONT_BLOCK);
178 * If we find the buffer in the cache with this transaction
179 * pointer in its b_fsprivate2 field, then we know we already
180 * have it locked. In this case we just increment the lock
181 * recursion count and return the buffer to the caller.
183 bp = xfs_trans_buf_item_match(tp, target_dev, blkno, len);
185 ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
186 if (XFS_FORCED_SHUTDOWN(tp->t_mountp))
187 XFS_BUF_SUPER_STALE(bp);
190 * If the buffer is stale then it was binval'ed
191 * since last read. This doesn't matter since the
192 * caller isn't allowed to use the data anyway.
194 else if (XFS_BUF_ISSTALE(bp))
195 ASSERT(!XFS_BUF_ISDELAYWRITE(bp));
197 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
198 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
200 ASSERT(atomic_read(&bip->bli_refcount) > 0);
202 trace_xfs_trans_get_buf_recur(bip);
207 * We always specify the XBF_DONT_BLOCK flag within a transaction
208 * so that get_buf does not try to push out a delayed write buffer
209 * which might cause another transaction to take place (if the
210 * buffer was delayed alloc). Such recursive transactions can
211 * easily deadlock with our current transaction as well as cause
212 * us to run out of stack space.
214 bp = xfs_buf_get(target_dev, blkno, len, flags | XBF_DONT_BLOCK);
219 ASSERT(!XFS_BUF_GETERROR(bp));
221 _xfs_trans_bjoin(tp, bp, 1);
222 trace_xfs_trans_get_buf(bp->b_fspriv);
227 * Get and lock the superblock buffer of this file system for the
230 * We don't need to use incore_match() here, because the superblock
231 * buffer is a private buffer which we keep a pointer to in the
235 xfs_trans_getsb(xfs_trans_t *tp,
236 struct xfs_mount *mp,
240 xfs_buf_log_item_t *bip;
243 * Default to just trying to lock the superblock buffer
247 return (xfs_getsb(mp, flags));
251 * If the superblock buffer already has this transaction
252 * pointer in its b_fsprivate2 field, then we know we already
253 * have it locked. In this case we just increment the lock
254 * recursion count and return the buffer to the caller.
257 if (XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp) {
258 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t*);
260 ASSERT(atomic_read(&bip->bli_refcount) > 0);
262 trace_xfs_trans_getsb_recur(bip);
266 bp = xfs_getsb(mp, flags);
270 _xfs_trans_bjoin(tp, bp, 1);
271 trace_xfs_trans_getsb(bp->b_fspriv);
276 xfs_buftarg_t *xfs_error_target;
279 int xfs_error_mod = 33;
283 * Get and lock the buffer for the caller if it is not already
284 * locked within the given transaction. If it has not yet been
285 * read in, read it from disk. If it is already locked
286 * within the transaction and already read in, just increment its
287 * lock recursion count and return a pointer to it.
289 * If the transaction pointer is NULL, make this just a normal
296 xfs_buftarg_t *target,
303 xfs_buf_log_item_t *bip;
307 flags = XBF_LOCK | XBF_MAPPED;
310 * Default to a normal get_buf() call if the tp is NULL.
313 bp = xfs_buf_read(target, blkno, len, flags | XBF_DONT_BLOCK);
315 return (flags & XBF_TRYLOCK) ?
316 EAGAIN : XFS_ERROR(ENOMEM);
318 if (XFS_BUF_GETERROR(bp) != 0) {
319 xfs_ioerror_alert("xfs_trans_read_buf", mp,
321 error = XFS_BUF_GETERROR(bp);
327 if (xfs_error_target == target) {
328 if (((xfs_req_num++) % xfs_error_mod) == 0) {
330 cmn_err(CE_DEBUG, "Returning error!\n");
331 return XFS_ERROR(EIO);
336 if (XFS_FORCED_SHUTDOWN(mp))
343 * If we find the buffer in the cache with this transaction
344 * pointer in its b_fsprivate2 field, then we know we already
345 * have it locked. If it is already read in we just increment
346 * the lock recursion count and return the buffer to the caller.
347 * If the buffer is not yet read in, then we read it in, increment
348 * the lock recursion count, and return it to the caller.
350 bp = xfs_trans_buf_item_match(tp, target, blkno, len);
352 ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
353 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
354 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
355 ASSERT((XFS_BUF_ISERROR(bp)) == 0);
356 if (!(XFS_BUF_ISDONE(bp))) {
357 trace_xfs_trans_read_buf_io(bp, _RET_IP_);
358 ASSERT(!XFS_BUF_ISASYNC(bp));
360 xfsbdstrat(tp->t_mountp, bp);
361 error = xfs_iowait(bp);
363 xfs_ioerror_alert("xfs_trans_read_buf", mp,
367 * We can gracefully recover from most read
368 * errors. Ones we can't are those that happen
369 * after the transaction's already dirty.
371 if (tp->t_flags & XFS_TRANS_DIRTY)
372 xfs_force_shutdown(tp->t_mountp,
373 SHUTDOWN_META_IO_ERROR);
378 * We never locked this buf ourselves, so we shouldn't
379 * brelse it either. Just get out.
381 if (XFS_FORCED_SHUTDOWN(mp)) {
382 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
384 return XFS_ERROR(EIO);
388 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t*);
391 ASSERT(atomic_read(&bip->bli_refcount) > 0);
392 trace_xfs_trans_read_buf_recur(bip);
398 * We always specify the XBF_DONT_BLOCK flag within a transaction
399 * so that get_buf does not try to push out a delayed write buffer
400 * which might cause another transaction to take place (if the
401 * buffer was delayed alloc). Such recursive transactions can
402 * easily deadlock with our current transaction as well as cause
403 * us to run out of stack space.
405 bp = xfs_buf_read(target, blkno, len, flags | XBF_DONT_BLOCK);
410 if (XFS_BUF_GETERROR(bp) != 0) {
411 XFS_BUF_SUPER_STALE(bp);
412 error = XFS_BUF_GETERROR(bp);
414 xfs_ioerror_alert("xfs_trans_read_buf", mp,
416 if (tp->t_flags & XFS_TRANS_DIRTY)
417 xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR);
422 if (xfs_do_error && !(tp->t_flags & XFS_TRANS_DIRTY)) {
423 if (xfs_error_target == target) {
424 if (((xfs_req_num++) % xfs_error_mod) == 0) {
425 xfs_force_shutdown(tp->t_mountp,
426 SHUTDOWN_META_IO_ERROR);
428 cmn_err(CE_DEBUG, "Returning trans error!\n");
429 return XFS_ERROR(EIO);
434 if (XFS_FORCED_SHUTDOWN(mp))
437 _xfs_trans_bjoin(tp, bp, 1);
438 trace_xfs_trans_read_buf(bp->b_fspriv);
445 * the theory here is that buffer is good but we're
446 * bailing out because the filesystem is being forcibly
447 * shut down. So we should leave the b_flags alone since
448 * the buffer's not staled and just get out.
451 if (XFS_BUF_ISSTALE(bp) && XFS_BUF_ISDELAYWRITE(bp))
452 cmn_err(CE_NOTE, "about to pop assert, bp == 0x%p", bp);
454 ASSERT((XFS_BUF_BFLAGS(bp) & (XBF_STALE|XBF_DELWRI)) !=
455 (XBF_STALE|XBF_DELWRI));
457 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
460 return XFS_ERROR(EIO);
465 * Release the buffer bp which was previously acquired with one of the
466 * xfs_trans_... buffer allocation routines if the buffer has not
467 * been modified within this transaction. If the buffer is modified
468 * within this transaction, do decrement the recursion count but do
469 * not release the buffer even if the count goes to 0. If the buffer is not
470 * modified within the transaction, decrement the recursion count and
471 * release the buffer if the recursion count goes to 0.
473 * If the buffer is to be released and it was not modified before
474 * this transaction began, then free the buf_log_item associated with it.
476 * If the transaction pointer is NULL, make this just a normal
480 xfs_trans_brelse(xfs_trans_t *tp,
483 xfs_buf_log_item_t *bip;
485 xfs_log_item_desc_t *lidp;
488 * Default to a normal brelse() call if the tp is NULL.
491 ASSERT(XFS_BUF_FSPRIVATE2(bp, void *) == NULL);
493 * If there's a buf log item attached to the buffer,
494 * then let the AIL know that the buffer is being
497 if (XFS_BUF_FSPRIVATE(bp, void *) != NULL) {
498 lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
499 if (lip->li_type == XFS_LI_BUF) {
500 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
501 xfs_trans_unlocked_item(bip->bli_item.li_ailp,
509 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
510 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
511 ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
512 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
513 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_CANCEL));
514 ASSERT(atomic_read(&bip->bli_refcount) > 0);
517 * Find the item descriptor pointing to this buffer's
518 * log item. It must be there.
520 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
521 ASSERT(lidp != NULL);
523 trace_xfs_trans_brelse(bip);
526 * If the release is just for a recursive lock,
527 * then decrement the count and return.
529 if (bip->bli_recur > 0) {
535 * If the buffer is dirty within this transaction, we can't
536 * release it until we commit.
538 if (lidp->lid_flags & XFS_LID_DIRTY)
542 * If the buffer has been invalidated, then we can't release
543 * it until the transaction commits to disk unless it is re-dirtied
544 * as part of this transaction. This prevents us from pulling
545 * the item from the AIL before we should.
547 if (bip->bli_flags & XFS_BLI_STALE)
550 ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
553 * Free up the log item descriptor tracking the released item.
555 xfs_trans_free_item(tp, lidp);
558 * Clear the hold flag in the buf log item if it is set.
559 * We wouldn't want the next user of the buffer to
562 if (bip->bli_flags & XFS_BLI_HOLD) {
563 bip->bli_flags &= ~XFS_BLI_HOLD;
567 * Drop our reference to the buf log item.
569 atomic_dec(&bip->bli_refcount);
572 * If the buf item is not tracking data in the log, then
573 * we must free it before releasing the buffer back to the
574 * free pool. Before releasing the buffer to the free pool,
575 * clear the transaction pointer in b_fsprivate2 to dissolve
576 * its relation to this transaction.
578 if (!xfs_buf_item_dirty(bip)) {
580 ASSERT(bp->b_pincount == 0);
582 ASSERT(atomic_read(&bip->bli_refcount) == 0);
583 ASSERT(!(bip->bli_item.li_flags & XFS_LI_IN_AIL));
584 ASSERT(!(bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF));
585 xfs_buf_item_relse(bp);
588 XFS_BUF_SET_FSPRIVATE2(bp, NULL);
591 * If we've still got a buf log item on the buffer, then
592 * tell the AIL that the buffer is being unlocked.
595 xfs_trans_unlocked_item(bip->bli_item.li_ailp,
596 (xfs_log_item_t*)bip);
604 * Mark the buffer as not needing to be unlocked when the buf item's
605 * IOP_UNLOCK() routine is called. The buffer must already be locked
606 * and associated with the given transaction.
610 xfs_trans_bhold(xfs_trans_t *tp,
613 xfs_buf_log_item_t *bip;
615 ASSERT(XFS_BUF_ISBUSY(bp));
616 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
617 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
619 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
620 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
621 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_CANCEL));
622 ASSERT(atomic_read(&bip->bli_refcount) > 0);
623 bip->bli_flags |= XFS_BLI_HOLD;
624 trace_xfs_trans_bhold(bip);
628 * Cancel the previous buffer hold request made on this buffer
629 * for this transaction.
632 xfs_trans_bhold_release(xfs_trans_t *tp,
635 xfs_buf_log_item_t *bip;
637 ASSERT(XFS_BUF_ISBUSY(bp));
638 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
639 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
641 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
642 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
643 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_CANCEL));
644 ASSERT(atomic_read(&bip->bli_refcount) > 0);
645 ASSERT(bip->bli_flags & XFS_BLI_HOLD);
646 bip->bli_flags &= ~XFS_BLI_HOLD;
648 trace_xfs_trans_bhold_release(bip);
652 * This is called to mark bytes first through last inclusive of the given
653 * buffer as needing to be logged when the transaction is committed.
654 * The buffer must already be associated with the given transaction.
656 * First and last are numbers relative to the beginning of this buffer,
657 * so the first byte in the buffer is numbered 0 regardless of the
661 xfs_trans_log_buf(xfs_trans_t *tp,
666 xfs_buf_log_item_t *bip;
667 xfs_log_item_desc_t *lidp;
669 ASSERT(XFS_BUF_ISBUSY(bp));
670 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
671 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
672 ASSERT((first <= last) && (last < XFS_BUF_COUNT(bp)));
673 ASSERT((XFS_BUF_IODONE_FUNC(bp) == NULL) ||
674 (XFS_BUF_IODONE_FUNC(bp) == xfs_buf_iodone_callbacks));
677 * Mark the buffer as needing to be written out eventually,
678 * and set its iodone function to remove the buffer's buf log
679 * item from the AIL and free it when the buffer is flushed
680 * to disk. See xfs_buf_attach_iodone() for more details
681 * on li_cb and xfs_buf_iodone_callbacks().
682 * If we end up aborting this transaction, we trap this buffer
683 * inside the b_bdstrat callback so that this won't get written to
686 XFS_BUF_DELAYWRITE(bp);
689 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
690 ASSERT(atomic_read(&bip->bli_refcount) > 0);
691 XFS_BUF_SET_IODONE_FUNC(bp, xfs_buf_iodone_callbacks);
692 bip->bli_item.li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*))xfs_buf_iodone;
694 trace_xfs_trans_log_buf(bip);
697 * If we invalidated the buffer within this transaction, then
698 * cancel the invalidation now that we're dirtying the buffer
699 * again. There are no races with the code in xfs_buf_item_unpin(),
700 * because we have a reference to the buffer this entire time.
702 if (bip->bli_flags & XFS_BLI_STALE) {
703 bip->bli_flags &= ~XFS_BLI_STALE;
704 ASSERT(XFS_BUF_ISSTALE(bp));
706 bip->bli_format.blf_flags &= ~XFS_BLF_CANCEL;
709 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
710 ASSERT(lidp != NULL);
712 tp->t_flags |= XFS_TRANS_DIRTY;
713 lidp->lid_flags |= XFS_LID_DIRTY;
714 bip->bli_flags |= XFS_BLI_LOGGED;
715 xfs_buf_item_log(bip, first, last);
720 * This called to invalidate a buffer that is being used within
721 * a transaction. Typically this is because the blocks in the
722 * buffer are being freed, so we need to prevent it from being
723 * written out when we're done. Allowing it to be written again
724 * might overwrite data in the free blocks if they are reallocated
727 * We prevent the buffer from being written out by clearing the
728 * B_DELWRI flag. We can't always
729 * get rid of the buf log item at this point, though, because
730 * the buffer may still be pinned by another transaction. If that
731 * is the case, then we'll wait until the buffer is committed to
732 * disk for the last time (we can tell by the ref count) and
733 * free it in xfs_buf_item_unpin(). Until it is cleaned up we
734 * will keep the buffer locked so that the buffer and buf log item
742 xfs_log_item_desc_t *lidp;
743 xfs_buf_log_item_t *bip;
745 ASSERT(XFS_BUF_ISBUSY(bp));
746 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
747 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
749 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
750 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
751 ASSERT(lidp != NULL);
752 ASSERT(atomic_read(&bip->bli_refcount) > 0);
754 trace_xfs_trans_binval(bip);
756 if (bip->bli_flags & XFS_BLI_STALE) {
758 * If the buffer is already invalidated, then
761 ASSERT(!(XFS_BUF_ISDELAYWRITE(bp)));
762 ASSERT(XFS_BUF_ISSTALE(bp));
763 ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY)));
764 ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_INODE_BUF));
765 ASSERT(bip->bli_format.blf_flags & XFS_BLF_CANCEL);
766 ASSERT(lidp->lid_flags & XFS_LID_DIRTY);
767 ASSERT(tp->t_flags & XFS_TRANS_DIRTY);
772 * Clear the dirty bit in the buffer and set the STALE flag
773 * in the buf log item. The STALE flag will be used in
774 * xfs_buf_item_unpin() to determine if it should clean up
775 * when the last reference to the buf item is given up.
776 * We set the XFS_BLF_CANCEL flag in the buf log format structure
777 * and log the buf item. This will be used at recovery time
778 * to determine that copies of the buffer in the log before
779 * this should not be replayed.
780 * We mark the item descriptor and the transaction dirty so
781 * that we'll hold the buffer until after the commit.
783 * Since we're invalidating the buffer, we also clear the state
784 * about which parts of the buffer have been logged. We also
785 * clear the flag indicating that this is an inode buffer since
786 * the data in the buffer will no longer be valid.
788 * We set the stale bit in the buffer as well since we're getting
791 XFS_BUF_UNDELAYWRITE(bp);
793 bip->bli_flags |= XFS_BLI_STALE;
794 bip->bli_flags &= ~(XFS_BLI_INODE_BUF | XFS_BLI_LOGGED | XFS_BLI_DIRTY);
795 bip->bli_format.blf_flags &= ~XFS_BLF_INODE_BUF;
796 bip->bli_format.blf_flags |= XFS_BLF_CANCEL;
797 memset((char *)(bip->bli_format.blf_data_map), 0,
798 (bip->bli_format.blf_map_size * sizeof(uint)));
799 lidp->lid_flags |= XFS_LID_DIRTY;
800 tp->t_flags |= XFS_TRANS_DIRTY;
804 * This call is used to indicate that the buffer contains on-disk inodes which
805 * must be handled specially during recovery. They require special handling
806 * because only the di_next_unlinked from the inodes in the buffer should be
807 * recovered. The rest of the data in the buffer is logged via the inodes
810 * All we do is set the XFS_BLI_INODE_BUF flag in the items flags so it can be
811 * transferred to the buffer's log format structure so that we'll know what to
812 * do at recovery time.
819 xfs_buf_log_item_t *bip;
821 ASSERT(XFS_BUF_ISBUSY(bp));
822 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
823 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
825 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
826 ASSERT(atomic_read(&bip->bli_refcount) > 0);
828 bip->bli_flags |= XFS_BLI_INODE_BUF;
832 * This call is used to indicate that the buffer is going to
833 * be staled and was an inode buffer. This means it gets
834 * special processing during unpin - where any inodes
835 * associated with the buffer should be removed from ail.
836 * There is also special processing during recovery,
837 * any replay of the inodes in the buffer needs to be
838 * prevented as the buffer may have been reused.
841 xfs_trans_stale_inode_buf(
845 xfs_buf_log_item_t *bip;
847 ASSERT(XFS_BUF_ISBUSY(bp));
848 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
849 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
851 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
852 ASSERT(atomic_read(&bip->bli_refcount) > 0);
854 bip->bli_flags |= XFS_BLI_STALE_INODE;
855 bip->bli_item.li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*))
862 * Mark the buffer as being one which contains newly allocated
863 * inodes. We need to make sure that even if this buffer is
864 * relogged as an 'inode buf' we still recover all of the inode
865 * images in the face of a crash. This works in coordination with
866 * xfs_buf_item_committed() to ensure that the buffer remains in the
867 * AIL at its original location even after it has been relogged.
871 xfs_trans_inode_alloc_buf(
875 xfs_buf_log_item_t *bip;
877 ASSERT(XFS_BUF_ISBUSY(bp));
878 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
879 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
881 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
882 ASSERT(atomic_read(&bip->bli_refcount) > 0);
884 bip->bli_flags |= XFS_BLI_INODE_ALLOC_BUF;
889 * Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of
890 * dquots. However, unlike in inode buffer recovery, dquot buffers get
891 * recovered in their entirety. (Hence, no XFS_BLI_DQUOT_ALLOC_BUF flag).
892 * The only thing that makes dquot buffers different from regular
893 * buffers is that we must not replay dquot bufs when recovering
894 * if a _corresponding_ quotaoff has happened. We also have to distinguish
895 * between usr dquot bufs and grp dquot bufs, because usr and grp quotas
896 * can be turned off independently.
905 xfs_buf_log_item_t *bip;
907 ASSERT(XFS_BUF_ISBUSY(bp));
908 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
909 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
910 ASSERT(type == XFS_BLF_UDQUOT_BUF ||
911 type == XFS_BLF_PDQUOT_BUF ||
912 type == XFS_BLF_GDQUOT_BUF);
914 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
915 ASSERT(atomic_read(&bip->bli_refcount) > 0);
917 bip->bli_format.blf_flags |= type;