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 lidp
->lid_flags
&= ~XFS_LID_BUF_STALE
;
700 bip
->bli_flags
|= XFS_BLI_LOGGED
;
701 xfs_buf_item_log(bip
, first
, last
);
706 * This called to invalidate a buffer that is being used within
707 * a transaction. Typically this is because the blocks in the
708 * buffer are being freed, so we need to prevent it from being
709 * written out when we're done. Allowing it to be written again
710 * might overwrite data in the free blocks if they are reallocated
713 * We prevent the buffer from being written out by clearing the
714 * B_DELWRI flag. We can't always
715 * get rid of the buf log item at this point, though, because
716 * the buffer may still be pinned by another transaction. If that
717 * is the case, then we'll wait until the buffer is committed to
718 * disk for the last time (we can tell by the ref count) and
719 * free it in xfs_buf_item_unpin(). Until it is cleaned up we
720 * will keep the buffer locked so that the buffer and buf log item
728 xfs_log_item_desc_t
*lidp
;
729 xfs_buf_log_item_t
*bip
;
731 ASSERT(XFS_BUF_ISBUSY(bp
));
732 ASSERT(XFS_BUF_FSPRIVATE2(bp
, xfs_trans_t
*) == tp
);
733 ASSERT(XFS_BUF_FSPRIVATE(bp
, void *) != NULL
);
735 bip
= XFS_BUF_FSPRIVATE(bp
, xfs_buf_log_item_t
*);
736 lidp
= xfs_trans_find_item(tp
, (xfs_log_item_t
*)bip
);
737 ASSERT(lidp
!= NULL
);
738 ASSERT(atomic_read(&bip
->bli_refcount
) > 0);
740 trace_xfs_trans_binval(bip
);
742 if (bip
->bli_flags
& XFS_BLI_STALE
) {
744 * If the buffer is already invalidated, then
747 ASSERT(!(XFS_BUF_ISDELAYWRITE(bp
)));
748 ASSERT(XFS_BUF_ISSTALE(bp
));
749 ASSERT(!(bip
->bli_flags
& (XFS_BLI_LOGGED
| XFS_BLI_DIRTY
)));
750 ASSERT(!(bip
->bli_format
.blf_flags
& XFS_BLI_INODE_BUF
));
751 ASSERT(bip
->bli_format
.blf_flags
& XFS_BLI_CANCEL
);
752 ASSERT(lidp
->lid_flags
& XFS_LID_DIRTY
);
753 ASSERT(tp
->t_flags
& XFS_TRANS_DIRTY
);
758 * Clear the dirty bit in the buffer and set the STALE flag
759 * in the buf log item. The STALE flag will be used in
760 * xfs_buf_item_unpin() to determine if it should clean up
761 * when the last reference to the buf item is given up.
762 * We set the XFS_BLI_CANCEL flag in the buf log format structure
763 * and log the buf item. This will be used at recovery time
764 * to determine that copies of the buffer in the log before
765 * this should not be replayed.
766 * We mark the item descriptor and the transaction dirty so
767 * that we'll hold the buffer until after the commit.
769 * Since we're invalidating the buffer, we also clear the state
770 * about which parts of the buffer have been logged. We also
771 * clear the flag indicating that this is an inode buffer since
772 * the data in the buffer will no longer be valid.
774 * We set the stale bit in the buffer as well since we're getting
777 XFS_BUF_UNDELAYWRITE(bp
);
779 bip
->bli_flags
|= XFS_BLI_STALE
;
780 bip
->bli_flags
&= ~(XFS_BLI_LOGGED
| XFS_BLI_DIRTY
);
781 bip
->bli_format
.blf_flags
&= ~XFS_BLI_INODE_BUF
;
782 bip
->bli_format
.blf_flags
|= XFS_BLI_CANCEL
;
783 memset((char *)(bip
->bli_format
.blf_data_map
), 0,
784 (bip
->bli_format
.blf_map_size
* sizeof(uint
)));
785 lidp
->lid_flags
|= XFS_LID_DIRTY
|XFS_LID_BUF_STALE
;
786 tp
->t_flags
|= XFS_TRANS_DIRTY
;
790 * This call is used to indicate that the buffer contains on-disk
791 * inodes which must be handled specially during recovery. They
792 * require special handling because only the di_next_unlinked from
793 * the inodes in the buffer should be recovered. The rest of the
794 * data in the buffer is logged via the inodes themselves.
796 * All we do is set the XFS_BLI_INODE_BUF flag in the buffer's log
797 * format structure so that we'll know what to do at recovery time.
805 xfs_buf_log_item_t
*bip
;
807 ASSERT(XFS_BUF_ISBUSY(bp
));
808 ASSERT(XFS_BUF_FSPRIVATE2(bp
, xfs_trans_t
*) == tp
);
809 ASSERT(XFS_BUF_FSPRIVATE(bp
, void *) != NULL
);
811 bip
= XFS_BUF_FSPRIVATE(bp
, xfs_buf_log_item_t
*);
812 ASSERT(atomic_read(&bip
->bli_refcount
) > 0);
814 bip
->bli_format
.blf_flags
|= XFS_BLI_INODE_BUF
;
818 * This call is used to indicate that the buffer is going to
819 * be staled and was an inode buffer. This means it gets
820 * special processing during unpin - where any inodes
821 * associated with the buffer should be removed from ail.
822 * There is also special processing during recovery,
823 * any replay of the inodes in the buffer needs to be
824 * prevented as the buffer may have been reused.
827 xfs_trans_stale_inode_buf(
831 xfs_buf_log_item_t
*bip
;
833 ASSERT(XFS_BUF_ISBUSY(bp
));
834 ASSERT(XFS_BUF_FSPRIVATE2(bp
, xfs_trans_t
*) == tp
);
835 ASSERT(XFS_BUF_FSPRIVATE(bp
, void *) != NULL
);
837 bip
= XFS_BUF_FSPRIVATE(bp
, xfs_buf_log_item_t
*);
838 ASSERT(atomic_read(&bip
->bli_refcount
) > 0);
840 bip
->bli_flags
|= XFS_BLI_STALE_INODE
;
841 bip
->bli_item
.li_cb
= (void(*)(xfs_buf_t
*,xfs_log_item_t
*))
848 * Mark the buffer as being one which contains newly allocated
849 * inodes. We need to make sure that even if this buffer is
850 * relogged as an 'inode buf' we still recover all of the inode
851 * images in the face of a crash. This works in coordination with
852 * xfs_buf_item_committed() to ensure that the buffer remains in the
853 * AIL at its original location even after it has been relogged.
857 xfs_trans_inode_alloc_buf(
861 xfs_buf_log_item_t
*bip
;
863 ASSERT(XFS_BUF_ISBUSY(bp
));
864 ASSERT(XFS_BUF_FSPRIVATE2(bp
, xfs_trans_t
*) == tp
);
865 ASSERT(XFS_BUF_FSPRIVATE(bp
, void *) != NULL
);
867 bip
= XFS_BUF_FSPRIVATE(bp
, xfs_buf_log_item_t
*);
868 ASSERT(atomic_read(&bip
->bli_refcount
) > 0);
870 bip
->bli_flags
|= XFS_BLI_INODE_ALLOC_BUF
;
875 * Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of
876 * dquots. However, unlike in inode buffer recovery, dquot buffers get
877 * recovered in their entirety. (Hence, no XFS_BLI_DQUOT_ALLOC_BUF flag).
878 * The only thing that makes dquot buffers different from regular
879 * buffers is that we must not replay dquot bufs when recovering
880 * if a _corresponding_ quotaoff has happened. We also have to distinguish
881 * between usr dquot bufs and grp dquot bufs, because usr and grp quotas
882 * can be turned off independently.
891 xfs_buf_log_item_t
*bip
;
893 ASSERT(XFS_BUF_ISBUSY(bp
));
894 ASSERT(XFS_BUF_FSPRIVATE2(bp
, xfs_trans_t
*) == tp
);
895 ASSERT(XFS_BUF_FSPRIVATE(bp
, void *) != NULL
);
896 ASSERT(type
== XFS_BLI_UDQUOT_BUF
||
897 type
== XFS_BLI_PDQUOT_BUF
||
898 type
== XFS_BLI_GDQUOT_BUF
);
900 bip
= XFS_BUF_FSPRIVATE(bp
, xfs_buf_log_item_t
*);
901 ASSERT(atomic_read(&bip
->bli_refcount
) > 0);
903 bip
->bli_format
.blf_flags
|= type
;
907 * Check to see if a buffer matching the given parameters is already
908 * a part of the given transaction. Only check the first, embedded
909 * chunk, since we don't want to spend all day scanning large transactions.
912 xfs_trans_buf_item_match(
914 xfs_buftarg_t
*target
,
918 xfs_log_item_chunk_t
*licp
;
919 xfs_log_item_desc_t
*lidp
;
920 xfs_buf_log_item_t
*blip
;
927 if (!xfs_lic_are_all_free(licp
)) {
928 for (i
= 0; i
< licp
->lic_unused
; i
++) {
930 * Skip unoccupied slots.
932 if (xfs_lic_isfree(licp
, i
)) {
936 lidp
= xfs_lic_slot(licp
, i
);
937 blip
= (xfs_buf_log_item_t
*)lidp
->lid_item
;
938 if (blip
->bli_item
.li_type
!= XFS_LI_BUF
) {
943 if ((XFS_BUF_TARGET(bp
) == target
) &&
944 (XFS_BUF_ADDR(bp
) == blkno
) &&
945 (XFS_BUF_COUNT(bp
) == len
)) {
947 * We found it. Break out and
948 * return the pointer to the buffer.
960 * Check to see if a buffer matching the given parameters is already
961 * a part of the given transaction. Check all the chunks, we
962 * want to be thorough.
965 xfs_trans_buf_item_match_all(
967 xfs_buftarg_t
*target
,
971 xfs_log_item_chunk_t
*licp
;
972 xfs_log_item_desc_t
*lidp
;
973 xfs_buf_log_item_t
*blip
;
979 for (licp
= &tp
->t_items
; licp
!= NULL
; licp
= licp
->lic_next
) {
980 if (xfs_lic_are_all_free(licp
)) {
981 ASSERT(licp
== &tp
->t_items
);
982 ASSERT(licp
->lic_next
== NULL
);
985 for (i
= 0; i
< licp
->lic_unused
; i
++) {
987 * Skip unoccupied slots.
989 if (xfs_lic_isfree(licp
, i
)) {
993 lidp
= xfs_lic_slot(licp
, i
);
994 blip
= (xfs_buf_log_item_t
*)lidp
->lid_item
;
995 if (blip
->bli_item
.li_type
!= XFS_LI_BUF
) {
1000 if ((XFS_BUF_TARGET(bp
) == target
) &&
1001 (XFS_BUF_ADDR(bp
) == blkno
) &&
1002 (XFS_BUF_COUNT(bp
) == len
)) {
1004 * We found it. Break out and
1005 * return the pointer to the buffer.