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 STATIC xfs_buf_t *xfs_trans_buf_item_match(xfs_trans_t *, xfs_buftarg_t *,
46 STATIC xfs_buf_t *xfs_trans_buf_item_match_all(xfs_trans_t *, xfs_buftarg_t *,
50 * Add the locked buffer to the transaction.
52 * The buffer must be locked, and it cannot be associated with any
55 * If the buffer does not yet have a buf log item associated with it,
56 * then allocate one for it. Then add the buf item to the transaction.
64 struct xfs_buf_log_item *bip;
66 ASSERT(XFS_BUF_ISBUSY(bp));
67 ASSERT(XFS_BUF_FSPRIVATE2(bp, void *) == NULL);
70 * The xfs_buf_log_item pointer is stored in b_fsprivate. If
71 * it doesn't have one yet, then allocate one and initialize it.
72 * The checks to see if one is there are in xfs_buf_item_init().
74 xfs_buf_item_init(bp, tp->t_mountp);
75 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
76 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
77 ASSERT(!(bip->bli_format.blf_flags & XFS_BLI_CANCEL));
78 ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
83 * Take a reference for this transaction on the buf item.
85 atomic_inc(&bip->bli_refcount);
88 * Get a log_item_desc to point at the new item.
90 (void) xfs_trans_add_item(tp, (xfs_log_item_t *)bip);
93 * Initialize b_fsprivate2 so we can find it with incore_match()
94 * in xfs_trans_get_buf() and friends above.
96 XFS_BUF_SET_FSPRIVATE2(bp, tp);
102 struct xfs_trans *tp,
105 _xfs_trans_bjoin(tp, bp, 0);
106 trace_xfs_trans_bjoin(bp->b_fspriv);
110 * Get and lock the buffer for the caller if it is not already
111 * locked within the given transaction. If it is already locked
112 * within the transaction, just increment its lock recursion count
113 * and return a pointer to it.
115 * Use the fast path function xfs_trans_buf_item_match() or the buffer
116 * cache routine incore_match() to find the buffer
117 * if it is already owned by this transaction.
119 * If we don't already own the buffer, use get_buf() to get it.
120 * If it doesn't yet have an associated xfs_buf_log_item structure,
121 * then allocate one and add the item to this transaction.
123 * If the transaction pointer is NULL, make this just a normal
127 xfs_trans_get_buf(xfs_trans_t *tp,
128 xfs_buftarg_t *target_dev,
134 xfs_buf_log_item_t *bip;
137 flags = XBF_LOCK | XBF_MAPPED;
140 * Default to a normal get_buf() call if the tp is NULL.
143 return xfs_buf_get(target_dev, blkno, len,
144 flags | XBF_DONT_BLOCK);
147 * If we find the buffer in the cache with this transaction
148 * pointer in its b_fsprivate2 field, then we know we already
149 * have it locked. In this case we just increment the lock
150 * recursion count and return the buffer to the caller.
152 if (tp->t_items.lic_next == NULL) {
153 bp = xfs_trans_buf_item_match(tp, target_dev, blkno, len);
155 bp = xfs_trans_buf_item_match_all(tp, target_dev, blkno, len);
158 ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
159 if (XFS_FORCED_SHUTDOWN(tp->t_mountp))
160 XFS_BUF_SUPER_STALE(bp);
163 * If the buffer is stale then it was binval'ed
164 * since last read. This doesn't matter since the
165 * caller isn't allowed to use the data anyway.
167 else if (XFS_BUF_ISSTALE(bp))
168 ASSERT(!XFS_BUF_ISDELAYWRITE(bp));
170 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
171 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
173 ASSERT(atomic_read(&bip->bli_refcount) > 0);
175 trace_xfs_trans_get_buf_recur(bip);
180 * We always specify the XBF_DONT_BLOCK flag within a transaction
181 * so that get_buf does not try to push out a delayed write buffer
182 * which might cause another transaction to take place (if the
183 * buffer was delayed alloc). Such recursive transactions can
184 * easily deadlock with our current transaction as well as cause
185 * us to run out of stack space.
187 bp = xfs_buf_get(target_dev, blkno, len, flags | XBF_DONT_BLOCK);
192 ASSERT(!XFS_BUF_GETERROR(bp));
194 _xfs_trans_bjoin(tp, bp, 1);
195 trace_xfs_trans_get_buf(bp->b_fspriv);
200 * Get and lock the superblock buffer of this file system for the
203 * We don't need to use incore_match() here, because the superblock
204 * buffer is a private buffer which we keep a pointer to in the
208 xfs_trans_getsb(xfs_trans_t *tp,
209 struct xfs_mount *mp,
213 xfs_buf_log_item_t *bip;
216 * Default to just trying to lock the superblock buffer
220 return (xfs_getsb(mp, flags));
224 * If the superblock buffer already has this transaction
225 * pointer in its b_fsprivate2 field, then we know we already
226 * have it locked. In this case we just increment the lock
227 * recursion count and return the buffer to the caller.
230 if (XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp) {
231 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t*);
233 ASSERT(atomic_read(&bip->bli_refcount) > 0);
235 trace_xfs_trans_getsb_recur(bip);
239 bp = xfs_getsb(mp, flags);
243 _xfs_trans_bjoin(tp, bp, 1);
244 trace_xfs_trans_getsb(bp->b_fspriv);
249 xfs_buftarg_t *xfs_error_target;
252 int xfs_error_mod = 33;
256 * Get and lock the buffer for the caller if it is not already
257 * locked within the given transaction. If it has not yet been
258 * read in, read it from disk. If it is already locked
259 * within the transaction and already read in, just increment its
260 * lock recursion count and return a pointer to it.
262 * Use the fast path function xfs_trans_buf_item_match() or the buffer
263 * cache routine incore_match() to find the buffer
264 * if it is already owned by this transaction.
266 * If we don't already own the buffer, use read_buf() to get it.
267 * If it doesn't yet have an associated xfs_buf_log_item structure,
268 * then allocate one and add the item to this transaction.
270 * If the transaction pointer is NULL, make this just a normal
277 xfs_buftarg_t *target,
284 xfs_buf_log_item_t *bip;
288 flags = XBF_LOCK | XBF_MAPPED;
291 * Default to a normal get_buf() call if the tp is NULL.
294 bp = xfs_buf_read(target, blkno, len, flags | XBF_DONT_BLOCK);
296 return (flags & XBF_TRYLOCK) ?
297 EAGAIN : XFS_ERROR(ENOMEM);
299 if (XFS_BUF_GETERROR(bp) != 0) {
300 xfs_ioerror_alert("xfs_trans_read_buf", mp,
302 error = XFS_BUF_GETERROR(bp);
308 if (xfs_error_target == target) {
309 if (((xfs_req_num++) % xfs_error_mod) == 0) {
311 cmn_err(CE_DEBUG, "Returning error!\n");
312 return XFS_ERROR(EIO);
317 if (XFS_FORCED_SHUTDOWN(mp))
324 * If we find the buffer in the cache with this transaction
325 * pointer in its b_fsprivate2 field, then we know we already
326 * have it locked. If it is already read in we just increment
327 * the lock recursion count and return the buffer to the caller.
328 * If the buffer is not yet read in, then we read it in, increment
329 * the lock recursion count, and return it to the caller.
331 if (tp->t_items.lic_next == NULL) {
332 bp = xfs_trans_buf_item_match(tp, target, blkno, len);
334 bp = xfs_trans_buf_item_match_all(tp, target, blkno, len);
337 ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
338 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
339 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
340 ASSERT((XFS_BUF_ISERROR(bp)) == 0);
341 if (!(XFS_BUF_ISDONE(bp))) {
342 trace_xfs_trans_read_buf_io(bp, _RET_IP_);
343 ASSERT(!XFS_BUF_ISASYNC(bp));
345 xfsbdstrat(tp->t_mountp, bp);
346 error = xfs_iowait(bp);
348 xfs_ioerror_alert("xfs_trans_read_buf", mp,
352 * We can gracefully recover from most read
353 * errors. Ones we can't are those that happen
354 * after the transaction's already dirty.
356 if (tp->t_flags & XFS_TRANS_DIRTY)
357 xfs_force_shutdown(tp->t_mountp,
358 SHUTDOWN_META_IO_ERROR);
363 * We never locked this buf ourselves, so we shouldn't
364 * brelse it either. Just get out.
366 if (XFS_FORCED_SHUTDOWN(mp)) {
367 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
369 return XFS_ERROR(EIO);
373 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t*);
376 ASSERT(atomic_read(&bip->bli_refcount) > 0);
377 trace_xfs_trans_read_buf_recur(bip);
383 * We always specify the XBF_DONT_BLOCK flag within a transaction
384 * so that get_buf does not try to push out a delayed write buffer
385 * which might cause another transaction to take place (if the
386 * buffer was delayed alloc). Such recursive transactions can
387 * easily deadlock with our current transaction as well as cause
388 * us to run out of stack space.
390 bp = xfs_buf_read(target, blkno, len, flags | XBF_DONT_BLOCK);
395 if (XFS_BUF_GETERROR(bp) != 0) {
396 XFS_BUF_SUPER_STALE(bp);
397 error = XFS_BUF_GETERROR(bp);
399 xfs_ioerror_alert("xfs_trans_read_buf", mp,
401 if (tp->t_flags & XFS_TRANS_DIRTY)
402 xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR);
407 if (xfs_do_error && !(tp->t_flags & XFS_TRANS_DIRTY)) {
408 if (xfs_error_target == target) {
409 if (((xfs_req_num++) % xfs_error_mod) == 0) {
410 xfs_force_shutdown(tp->t_mountp,
411 SHUTDOWN_META_IO_ERROR);
413 cmn_err(CE_DEBUG, "Returning trans error!\n");
414 return XFS_ERROR(EIO);
419 if (XFS_FORCED_SHUTDOWN(mp))
422 _xfs_trans_bjoin(tp, bp, 1);
423 trace_xfs_trans_read_buf(bp->b_fspriv);
430 * the theory here is that buffer is good but we're
431 * bailing out because the filesystem is being forcibly
432 * shut down. So we should leave the b_flags alone since
433 * the buffer's not staled and just get out.
436 if (XFS_BUF_ISSTALE(bp) && XFS_BUF_ISDELAYWRITE(bp))
437 cmn_err(CE_NOTE, "about to pop assert, bp == 0x%p", bp);
439 ASSERT((XFS_BUF_BFLAGS(bp) & (XBF_STALE|XBF_DELWRI)) !=
440 (XBF_STALE|XBF_DELWRI));
442 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
445 return XFS_ERROR(EIO);
450 * Release the buffer bp which was previously acquired with one of the
451 * xfs_trans_... buffer allocation routines if the buffer has not
452 * been modified within this transaction. If the buffer is modified
453 * within this transaction, do decrement the recursion count but do
454 * not release the buffer even if the count goes to 0. If the buffer is not
455 * modified within the transaction, decrement the recursion count and
456 * release the buffer if the recursion count goes to 0.
458 * If the buffer is to be released and it was not modified before
459 * this transaction began, then free the buf_log_item associated with it.
461 * If the transaction pointer is NULL, make this just a normal
465 xfs_trans_brelse(xfs_trans_t *tp,
468 xfs_buf_log_item_t *bip;
470 xfs_log_item_desc_t *lidp;
473 * Default to a normal brelse() call if the tp is NULL.
476 ASSERT(XFS_BUF_FSPRIVATE2(bp, void *) == NULL);
478 * If there's a buf log item attached to the buffer,
479 * then let the AIL know that the buffer is being
482 if (XFS_BUF_FSPRIVATE(bp, void *) != NULL) {
483 lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
484 if (lip->li_type == XFS_LI_BUF) {
485 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
486 xfs_trans_unlocked_item(bip->bli_item.li_ailp,
494 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
495 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
496 ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
497 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
498 ASSERT(!(bip->bli_format.blf_flags & XFS_BLI_CANCEL));
499 ASSERT(atomic_read(&bip->bli_refcount) > 0);
502 * Find the item descriptor pointing to this buffer's
503 * log item. It must be there.
505 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
506 ASSERT(lidp != NULL);
508 trace_xfs_trans_brelse(bip);
511 * If the release is just for a recursive lock,
512 * then decrement the count and return.
514 if (bip->bli_recur > 0) {
520 * If the buffer is dirty within this transaction, we can't
521 * release it until we commit.
523 if (lidp->lid_flags & XFS_LID_DIRTY)
527 * If the buffer has been invalidated, then we can't release
528 * it until the transaction commits to disk unless it is re-dirtied
529 * as part of this transaction. This prevents us from pulling
530 * the item from the AIL before we should.
532 if (bip->bli_flags & XFS_BLI_STALE)
535 ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
538 * Free up the log item descriptor tracking the released item.
540 xfs_trans_free_item(tp, lidp);
543 * Clear the hold flag in the buf log item if it is set.
544 * We wouldn't want the next user of the buffer to
547 if (bip->bli_flags & XFS_BLI_HOLD) {
548 bip->bli_flags &= ~XFS_BLI_HOLD;
552 * Drop our reference to the buf log item.
554 atomic_dec(&bip->bli_refcount);
557 * If the buf item is not tracking data in the log, then
558 * we must free it before releasing the buffer back to the
559 * free pool. Before releasing the buffer to the free pool,
560 * clear the transaction pointer in b_fsprivate2 to dissolve
561 * its relation to this transaction.
563 if (!xfs_buf_item_dirty(bip)) {
565 ASSERT(bp->b_pincount == 0);
567 ASSERT(atomic_read(&bip->bli_refcount) == 0);
568 ASSERT(!(bip->bli_item.li_flags & XFS_LI_IN_AIL));
569 ASSERT(!(bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF));
570 xfs_buf_item_relse(bp);
573 XFS_BUF_SET_FSPRIVATE2(bp, NULL);
576 * If we've still got a buf log item on the buffer, then
577 * tell the AIL that the buffer is being unlocked.
580 xfs_trans_unlocked_item(bip->bli_item.li_ailp,
581 (xfs_log_item_t*)bip);
589 * Mark the buffer as not needing to be unlocked when the buf item's
590 * IOP_UNLOCK() routine is called. The buffer must already be locked
591 * and associated with the given transaction.
595 xfs_trans_bhold(xfs_trans_t *tp,
598 xfs_buf_log_item_t *bip;
600 ASSERT(XFS_BUF_ISBUSY(bp));
601 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
602 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
604 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
605 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
606 ASSERT(!(bip->bli_format.blf_flags & XFS_BLI_CANCEL));
607 ASSERT(atomic_read(&bip->bli_refcount) > 0);
608 bip->bli_flags |= XFS_BLI_HOLD;
609 trace_xfs_trans_bhold(bip);
613 * Cancel the previous buffer hold request made on this buffer
614 * for this transaction.
617 xfs_trans_bhold_release(xfs_trans_t *tp,
620 xfs_buf_log_item_t *bip;
622 ASSERT(XFS_BUF_ISBUSY(bp));
623 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
624 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
626 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
627 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
628 ASSERT(!(bip->bli_format.blf_flags & XFS_BLI_CANCEL));
629 ASSERT(atomic_read(&bip->bli_refcount) > 0);
630 ASSERT(bip->bli_flags & XFS_BLI_HOLD);
631 bip->bli_flags &= ~XFS_BLI_HOLD;
633 trace_xfs_trans_bhold_release(bip);
637 * This is called to mark bytes first through last inclusive of the given
638 * buffer as needing to be logged when the transaction is committed.
639 * The buffer must already be associated with the given transaction.
641 * First and last are numbers relative to the beginning of this buffer,
642 * so the first byte in the buffer is numbered 0 regardless of the
646 xfs_trans_log_buf(xfs_trans_t *tp,
651 xfs_buf_log_item_t *bip;
652 xfs_log_item_desc_t *lidp;
654 ASSERT(XFS_BUF_ISBUSY(bp));
655 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
656 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
657 ASSERT((first <= last) && (last < XFS_BUF_COUNT(bp)));
658 ASSERT((XFS_BUF_IODONE_FUNC(bp) == NULL) ||
659 (XFS_BUF_IODONE_FUNC(bp) == xfs_buf_iodone_callbacks));
662 * Mark the buffer as needing to be written out eventually,
663 * and set its iodone function to remove the buffer's buf log
664 * item from the AIL and free it when the buffer is flushed
665 * to disk. See xfs_buf_attach_iodone() for more details
666 * on li_cb and xfs_buf_iodone_callbacks().
667 * If we end up aborting this transaction, we trap this buffer
668 * inside the b_bdstrat callback so that this won't get written to
671 XFS_BUF_DELAYWRITE(bp);
674 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
675 ASSERT(atomic_read(&bip->bli_refcount) > 0);
676 XFS_BUF_SET_IODONE_FUNC(bp, xfs_buf_iodone_callbacks);
677 bip->bli_item.li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*))xfs_buf_iodone;
679 trace_xfs_trans_log_buf(bip);
682 * If we invalidated the buffer within this transaction, then
683 * cancel the invalidation now that we're dirtying the buffer
684 * again. There are no races with the code in xfs_buf_item_unpin(),
685 * because we have a reference to the buffer this entire time.
687 if (bip->bli_flags & XFS_BLI_STALE) {
688 bip->bli_flags &= ~XFS_BLI_STALE;
689 ASSERT(XFS_BUF_ISSTALE(bp));
691 bip->bli_format.blf_flags &= ~XFS_BLI_CANCEL;
694 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
695 ASSERT(lidp != NULL);
697 tp->t_flags |= XFS_TRANS_DIRTY;
698 lidp->lid_flags |= XFS_LID_DIRTY;
699 bip->bli_flags |= XFS_BLI_LOGGED;
700 xfs_buf_item_log(bip, first, last);
705 * This called to invalidate a buffer that is being used within
706 * a transaction. Typically this is because the blocks in the
707 * buffer are being freed, so we need to prevent it from being
708 * written out when we're done. Allowing it to be written again
709 * might overwrite data in the free blocks if they are reallocated
712 * We prevent the buffer from being written out by clearing the
713 * B_DELWRI flag. We can't always
714 * get rid of the buf log item at this point, though, because
715 * the buffer may still be pinned by another transaction. If that
716 * is the case, then we'll wait until the buffer is committed to
717 * disk for the last time (we can tell by the ref count) and
718 * free it in xfs_buf_item_unpin(). Until it is cleaned up we
719 * will keep the buffer locked so that the buffer and buf log item
727 xfs_log_item_desc_t *lidp;
728 xfs_buf_log_item_t *bip;
730 ASSERT(XFS_BUF_ISBUSY(bp));
731 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
732 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
734 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
735 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
736 ASSERT(lidp != NULL);
737 ASSERT(atomic_read(&bip->bli_refcount) > 0);
739 trace_xfs_trans_binval(bip);
741 if (bip->bli_flags & XFS_BLI_STALE) {
743 * If the buffer is already invalidated, then
746 ASSERT(!(XFS_BUF_ISDELAYWRITE(bp)));
747 ASSERT(XFS_BUF_ISSTALE(bp));
748 ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY)));
749 ASSERT(!(bip->bli_format.blf_flags & XFS_BLI_INODE_BUF));
750 ASSERT(bip->bli_format.blf_flags & XFS_BLI_CANCEL);
751 ASSERT(lidp->lid_flags & XFS_LID_DIRTY);
752 ASSERT(tp->t_flags & XFS_TRANS_DIRTY);
757 * Clear the dirty bit in the buffer and set the STALE flag
758 * in the buf log item. The STALE flag will be used in
759 * xfs_buf_item_unpin() to determine if it should clean up
760 * when the last reference to the buf item is given up.
761 * We set the XFS_BLI_CANCEL flag in the buf log format structure
762 * and log the buf item. This will be used at recovery time
763 * to determine that copies of the buffer in the log before
764 * this should not be replayed.
765 * We mark the item descriptor and the transaction dirty so
766 * that we'll hold the buffer until after the commit.
768 * Since we're invalidating the buffer, we also clear the state
769 * about which parts of the buffer have been logged. We also
770 * clear the flag indicating that this is an inode buffer since
771 * the data in the buffer will no longer be valid.
773 * We set the stale bit in the buffer as well since we're getting
776 XFS_BUF_UNDELAYWRITE(bp);
778 bip->bli_flags |= XFS_BLI_STALE;
779 bip->bli_flags &= ~(XFS_BLI_LOGGED | XFS_BLI_DIRTY);
780 bip->bli_format.blf_flags &= ~XFS_BLI_INODE_BUF;
781 bip->bli_format.blf_flags |= XFS_BLI_CANCEL;
782 memset((char *)(bip->bli_format.blf_data_map), 0,
783 (bip->bli_format.blf_map_size * sizeof(uint)));
784 lidp->lid_flags |= XFS_LID_DIRTY;
785 tp->t_flags |= XFS_TRANS_DIRTY;
789 * This call is used to indicate that the buffer contains on-disk
790 * inodes which must be handled specially during recovery. They
791 * require special handling because only the di_next_unlinked from
792 * the inodes in the buffer should be recovered. The rest of the
793 * data in the buffer is logged via the inodes themselves.
795 * All we do is set the XFS_BLI_INODE_BUF flag in the buffer's log
796 * format structure so that we'll know what to do at recovery time.
804 xfs_buf_log_item_t *bip;
806 ASSERT(XFS_BUF_ISBUSY(bp));
807 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
808 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
810 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
811 ASSERT(atomic_read(&bip->bli_refcount) > 0);
813 bip->bli_format.blf_flags |= XFS_BLI_INODE_BUF;
817 * This call is used to indicate that the buffer is going to
818 * be staled and was an inode buffer. This means it gets
819 * special processing during unpin - where any inodes
820 * associated with the buffer should be removed from ail.
821 * There is also special processing during recovery,
822 * any replay of the inodes in the buffer needs to be
823 * prevented as the buffer may have been reused.
826 xfs_trans_stale_inode_buf(
830 xfs_buf_log_item_t *bip;
832 ASSERT(XFS_BUF_ISBUSY(bp));
833 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
834 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
836 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
837 ASSERT(atomic_read(&bip->bli_refcount) > 0);
839 bip->bli_flags |= XFS_BLI_STALE_INODE;
840 bip->bli_item.li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*))
847 * Mark the buffer as being one which contains newly allocated
848 * inodes. We need to make sure that even if this buffer is
849 * relogged as an 'inode buf' we still recover all of the inode
850 * images in the face of a crash. This works in coordination with
851 * xfs_buf_item_committed() to ensure that the buffer remains in the
852 * AIL at its original location even after it has been relogged.
856 xfs_trans_inode_alloc_buf(
860 xfs_buf_log_item_t *bip;
862 ASSERT(XFS_BUF_ISBUSY(bp));
863 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
864 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
866 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
867 ASSERT(atomic_read(&bip->bli_refcount) > 0);
869 bip->bli_flags |= XFS_BLI_INODE_ALLOC_BUF;
874 * Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of
875 * dquots. However, unlike in inode buffer recovery, dquot buffers get
876 * recovered in their entirety. (Hence, no XFS_BLI_DQUOT_ALLOC_BUF flag).
877 * The only thing that makes dquot buffers different from regular
878 * buffers is that we must not replay dquot bufs when recovering
879 * if a _corresponding_ quotaoff has happened. We also have to distinguish
880 * between usr dquot bufs and grp dquot bufs, because usr and grp quotas
881 * can be turned off independently.
890 xfs_buf_log_item_t *bip;
892 ASSERT(XFS_BUF_ISBUSY(bp));
893 ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
894 ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
895 ASSERT(type == XFS_BLI_UDQUOT_BUF ||
896 type == XFS_BLI_PDQUOT_BUF ||
897 type == XFS_BLI_GDQUOT_BUF);
899 bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
900 ASSERT(atomic_read(&bip->bli_refcount) > 0);
902 bip->bli_format.blf_flags |= type;
906 * Check to see if a buffer matching the given parameters is already
907 * a part of the given transaction. Only check the first, embedded
908 * chunk, since we don't want to spend all day scanning large transactions.
911 xfs_trans_buf_item_match(
913 xfs_buftarg_t *target,
917 xfs_log_item_chunk_t *licp;
918 xfs_log_item_desc_t *lidp;
919 xfs_buf_log_item_t *blip;
926 if (!xfs_lic_are_all_free(licp)) {
927 for (i = 0; i < licp->lic_unused; i++) {
929 * Skip unoccupied slots.
931 if (xfs_lic_isfree(licp, i)) {
935 lidp = xfs_lic_slot(licp, i);
936 blip = (xfs_buf_log_item_t *)lidp->lid_item;
937 if (blip->bli_item.li_type != XFS_LI_BUF) {
942 if ((XFS_BUF_TARGET(bp) == target) &&
943 (XFS_BUF_ADDR(bp) == blkno) &&
944 (XFS_BUF_COUNT(bp) == len)) {
946 * We found it. Break out and
947 * return the pointer to the buffer.
959 * Check to see if a buffer matching the given parameters is already
960 * a part of the given transaction. Check all the chunks, we
961 * want to be thorough.
964 xfs_trans_buf_item_match_all(
966 xfs_buftarg_t *target,
970 xfs_log_item_chunk_t *licp;
971 xfs_log_item_desc_t *lidp;
972 xfs_buf_log_item_t *blip;
978 for (licp = &tp->t_items; licp != NULL; licp = licp->lic_next) {
979 if (xfs_lic_are_all_free(licp)) {
980 ASSERT(licp == &tp->t_items);
981 ASSERT(licp->lic_next == NULL);
984 for (i = 0; i < licp->lic_unused; i++) {
986 * Skip unoccupied slots.
988 if (xfs_lic_isfree(licp, i)) {
992 lidp = xfs_lic_slot(licp, i);
993 blip = (xfs_buf_log_item_t *)lidp->lid_item;
994 if (blip->bli_item.li_type != XFS_LI_BUF) {
999 if ((XFS_BUF_TARGET(bp) == target) &&
1000 (XFS_BUF_ADDR(bp) == blkno) &&
1001 (XFS_BUF_COUNT(bp) == len)) {
1003 * We found it. Break out and
1004 * return the pointer to the buffer.