1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
8 #include "xfs_shared.h"
9 #include "xfs_format.h"
10 #include "xfs_log_format.h"
11 #include "xfs_trans_resv.h"
13 #include "xfs_mount.h"
14 #include "xfs_trans.h"
15 #include "xfs_trans_priv.h"
16 #include "xfs_buf_item.h"
17 #include "xfs_inode.h"
18 #include "xfs_inode_item.h"
19 #include "xfs_quota.h"
20 #include "xfs_dquot_item.h"
21 #include "xfs_dquot.h"
22 #include "xfs_trace.h"
26 kmem_zone_t *xfs_buf_item_zone;
28 static inline struct xfs_buf_log_item *BUF_ITEM(struct xfs_log_item *lip)
30 return container_of(lip, struct xfs_buf_log_item, bli_item);
33 /* Is this log iovec plausibly large enough to contain the buffer log format? */
35 xfs_buf_log_check_iovec(
36 struct xfs_log_iovec *iovec)
38 struct xfs_buf_log_format *blfp = iovec->i_addr;
42 if (offsetof(struct xfs_buf_log_format, blf_data_map) > iovec->i_len)
45 item_end = (char *)iovec->i_addr + iovec->i_len;
46 bmp_end = (char *)&blfp->blf_data_map[blfp->blf_map_size];
47 return bmp_end <= item_end;
51 xfs_buf_log_format_size(
52 struct xfs_buf_log_format *blfp)
54 return offsetof(struct xfs_buf_log_format, blf_data_map) +
55 (blfp->blf_map_size * sizeof(blfp->blf_data_map[0]));
59 * Return the number of log iovecs and space needed to log the given buf log
62 * It calculates this as 1 iovec for the buf log format structure and 1 for each
63 * stretch of non-contiguous chunks to be logged. Contiguous chunks are logged
67 xfs_buf_item_size_segment(
68 struct xfs_buf_log_item *bip,
69 struct xfs_buf_log_format *blfp,
73 struct xfs_buf *bp = bip->bli_buf;
77 last_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size, 0);
82 * initial count for a dirty buffer is 2 vectors - the format structure
83 * and the first dirty region.
86 *nbytes += xfs_buf_log_format_size(blfp) + XFS_BLF_CHUNK;
88 while (last_bit != -1) {
90 * This takes the bit number to start looking from and
91 * returns the next set bit from there. It returns -1
92 * if there are no more bits set or the start bit is
93 * beyond the end of the bitmap.
95 next_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size,
98 * If we run out of bits, leave the loop,
99 * else if we find a new set of bits bump the number of vecs,
100 * else keep scanning the current set of bits.
102 if (next_bit == -1) {
104 } else if (next_bit != last_bit + 1) {
107 } else if (xfs_buf_offset(bp, next_bit * XFS_BLF_CHUNK) !=
108 (xfs_buf_offset(bp, last_bit * XFS_BLF_CHUNK) +
115 *nbytes += XFS_BLF_CHUNK;
120 * Return the number of log iovecs and space needed to log the given buf log
123 * Discontiguous buffers need a format structure per region that is being
124 * logged. This makes the changes in the buffer appear to log recovery as though
125 * they came from separate buffers, just like would occur if multiple buffers
126 * were used instead of a single discontiguous buffer. This enables
127 * discontiguous buffers to be in-memory constructs, completely transparent to
128 * what ends up on disk.
130 * If the XFS_BLI_STALE flag has been set, then log nothing but the buf log
131 * format structures. If the item has previously been logged and has dirty
132 * regions, we do not relog them in stale buffers. This has the effect of
133 * reducing the size of the relogged item by the amount of dirty data tracked
134 * by the log item. This can result in the committing transaction reducing the
135 * amount of space being consumed by the CIL.
139 struct xfs_log_item *lip,
143 struct xfs_buf_log_item *bip = BUF_ITEM(lip);
146 ASSERT(atomic_read(&bip->bli_refcount) > 0);
147 if (bip->bli_flags & XFS_BLI_STALE) {
149 * The buffer is stale, so all we need to log is the buf log
150 * format structure with the cancel flag in it as we are never
151 * going to replay the changes tracked in the log item.
153 trace_xfs_buf_item_size_stale(bip);
154 ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
155 *nvecs += bip->bli_format_count;
156 for (i = 0; i < bip->bli_format_count; i++) {
157 *nbytes += xfs_buf_log_format_size(&bip->bli_formats[i]);
162 ASSERT(bip->bli_flags & XFS_BLI_LOGGED);
164 if (bip->bli_flags & XFS_BLI_ORDERED) {
166 * The buffer has been logged just to order it. It is not being
167 * included in the transaction commit, so no vectors are used at
170 trace_xfs_buf_item_size_ordered(bip);
171 *nvecs = XFS_LOG_VEC_ORDERED;
176 * the vector count is based on the number of buffer vectors we have
177 * dirty bits in. This will only be greater than one when we have a
178 * compound buffer with more than one segment dirty. Hence for compound
179 * buffers we need to track which segment the dirty bits correspond to,
180 * and when we move from one segment to the next increment the vector
181 * count for the extra buf log format structure that will need to be
184 for (i = 0; i < bip->bli_format_count; i++) {
185 xfs_buf_item_size_segment(bip, &bip->bli_formats[i],
188 trace_xfs_buf_item_size(bip);
192 xfs_buf_item_copy_iovec(
193 struct xfs_log_vec *lv,
194 struct xfs_log_iovec **vecp,
200 offset += first_bit * XFS_BLF_CHUNK;
201 xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_BCHUNK,
202 xfs_buf_offset(bp, offset),
203 nbits * XFS_BLF_CHUNK);
207 xfs_buf_item_straddle(
213 return xfs_buf_offset(bp, offset + (next_bit << XFS_BLF_SHIFT)) !=
214 (xfs_buf_offset(bp, offset + (last_bit << XFS_BLF_SHIFT)) +
219 xfs_buf_item_format_segment(
220 struct xfs_buf_log_item *bip,
221 struct xfs_log_vec *lv,
222 struct xfs_log_iovec **vecp,
224 struct xfs_buf_log_format *blfp)
226 struct xfs_buf *bp = bip->bli_buf;
233 /* copy the flags across from the base format item */
234 blfp->blf_flags = bip->__bli_format.blf_flags;
237 * Base size is the actual size of the ondisk structure - it reflects
238 * the actual size of the dirty bitmap rather than the size of the in
241 base_size = xfs_buf_log_format_size(blfp);
243 first_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size, 0);
244 if (!(bip->bli_flags & XFS_BLI_STALE) && first_bit == -1) {
246 * If the map is not be dirty in the transaction, mark
247 * the size as zero and do not advance the vector pointer.
252 blfp = xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_BFORMAT, blfp, base_size);
255 if (bip->bli_flags & XFS_BLI_STALE) {
257 * The buffer is stale, so all we need to log
258 * is the buf log format structure with the
261 trace_xfs_buf_item_format_stale(bip);
262 ASSERT(blfp->blf_flags & XFS_BLF_CANCEL);
268 * Fill in an iovec for each set of contiguous chunks.
270 last_bit = first_bit;
274 * This takes the bit number to start looking from and
275 * returns the next set bit from there. It returns -1
276 * if there are no more bits set or the start bit is
277 * beyond the end of the bitmap.
279 next_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size,
282 * If we run out of bits fill in the last iovec and get out of
283 * the loop. Else if we start a new set of bits then fill in
284 * the iovec for the series we were looking at and start
285 * counting the bits in the new one. Else we're still in the
286 * same set of bits so just keep counting and scanning.
288 if (next_bit == -1) {
289 xfs_buf_item_copy_iovec(lv, vecp, bp, offset,
293 } else if (next_bit != last_bit + 1 ||
294 xfs_buf_item_straddle(bp, offset, next_bit, last_bit)) {
295 xfs_buf_item_copy_iovec(lv, vecp, bp, offset,
298 first_bit = next_bit;
309 * This is called to fill in the vector of log iovecs for the
310 * given log buf item. It fills the first entry with a buf log
311 * format structure, and the rest point to contiguous chunks
316 struct xfs_log_item *lip,
317 struct xfs_log_vec *lv)
319 struct xfs_buf_log_item *bip = BUF_ITEM(lip);
320 struct xfs_buf *bp = bip->bli_buf;
321 struct xfs_log_iovec *vecp = NULL;
325 ASSERT(atomic_read(&bip->bli_refcount) > 0);
326 ASSERT((bip->bli_flags & XFS_BLI_LOGGED) ||
327 (bip->bli_flags & XFS_BLI_STALE));
328 ASSERT((bip->bli_flags & XFS_BLI_STALE) ||
329 (xfs_blft_from_flags(&bip->__bli_format) > XFS_BLFT_UNKNOWN_BUF
330 && xfs_blft_from_flags(&bip->__bli_format) < XFS_BLFT_MAX_BUF));
331 ASSERT(!(bip->bli_flags & XFS_BLI_ORDERED) ||
332 (bip->bli_flags & XFS_BLI_STALE));
336 * If it is an inode buffer, transfer the in-memory state to the
337 * format flags and clear the in-memory state.
339 * For buffer based inode allocation, we do not transfer
340 * this state if the inode buffer allocation has not yet been committed
341 * to the log as setting the XFS_BLI_INODE_BUF flag will prevent
342 * correct replay of the inode allocation.
344 * For icreate item based inode allocation, the buffers aren't written
345 * to the journal during allocation, and hence we should always tag the
346 * buffer as an inode buffer so that the correct unlinked list replay
347 * occurs during recovery.
349 if (bip->bli_flags & XFS_BLI_INODE_BUF) {
350 if (xfs_sb_version_has_v3inode(&lip->li_mountp->m_sb) ||
351 !((bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF) &&
352 xfs_log_item_in_current_chkpt(lip)))
353 bip->__bli_format.blf_flags |= XFS_BLF_INODE_BUF;
354 bip->bli_flags &= ~XFS_BLI_INODE_BUF;
357 for (i = 0; i < bip->bli_format_count; i++) {
358 xfs_buf_item_format_segment(bip, lv, &vecp, offset,
359 &bip->bli_formats[i]);
360 offset += BBTOB(bp->b_maps[i].bm_len);
364 * Check to make sure everything is consistent.
366 trace_xfs_buf_item_format(bip);
370 * This is called to pin the buffer associated with the buf log item in memory
371 * so it cannot be written out.
373 * We also always take a reference to the buffer log item here so that the bli
374 * is held while the item is pinned in memory. This means that we can
375 * unconditionally drop the reference count a transaction holds when the
376 * transaction is completed.
380 struct xfs_log_item *lip)
382 struct xfs_buf_log_item *bip = BUF_ITEM(lip);
384 ASSERT(atomic_read(&bip->bli_refcount) > 0);
385 ASSERT((bip->bli_flags & XFS_BLI_LOGGED) ||
386 (bip->bli_flags & XFS_BLI_ORDERED) ||
387 (bip->bli_flags & XFS_BLI_STALE));
389 trace_xfs_buf_item_pin(bip);
391 atomic_inc(&bip->bli_refcount);
392 atomic_inc(&bip->bli_buf->b_pin_count);
396 * This is called to unpin the buffer associated with the buf log item which
397 * was previously pinned with a call to xfs_buf_item_pin().
401 struct xfs_log_item *lip,
404 struct xfs_buf_log_item *bip = BUF_ITEM(lip);
405 xfs_buf_t *bp = bip->bli_buf;
406 int stale = bip->bli_flags & XFS_BLI_STALE;
409 ASSERT(bp->b_log_item == bip);
410 ASSERT(atomic_read(&bip->bli_refcount) > 0);
412 trace_xfs_buf_item_unpin(bip);
415 * Drop the bli ref associated with the pin and grab the hold required
416 * for the I/O simulation failure in the abort case. We have to do this
417 * before the pin count drops because the AIL doesn't acquire a bli
418 * reference. Therefore if the refcount drops to zero, the bli could
419 * still be AIL resident and the buffer submitted for I/O (and freed on
420 * completion) at any point before we return. This can be removed once
421 * the AIL properly holds a reference on the bli.
423 freed = atomic_dec_and_test(&bip->bli_refcount);
424 if (freed && !stale && remove)
426 if (atomic_dec_and_test(&bp->b_pin_count))
427 wake_up_all(&bp->b_waiters);
429 /* nothing to do but drop the pin count if the bli is active */
434 ASSERT(bip->bli_flags & XFS_BLI_STALE);
435 ASSERT(xfs_buf_islocked(bp));
436 ASSERT(bp->b_flags & XBF_STALE);
437 ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
438 ASSERT(list_empty(&lip->li_trans));
439 ASSERT(!bp->b_transp);
441 trace_xfs_buf_item_unpin_stale(bip);
444 * If we get called here because of an IO error, we may or may
445 * not have the item on the AIL. xfs_trans_ail_delete() will
446 * take care of that situation. xfs_trans_ail_delete() drops
449 if (bip->bli_flags & XFS_BLI_STALE_INODE) {
450 xfs_buf_item_done(bp);
451 xfs_buf_inode_iodone(bp);
452 ASSERT(list_empty(&bp->b_li_list));
454 xfs_trans_ail_delete(lip, SHUTDOWN_LOG_IO_ERROR);
455 xfs_buf_item_relse(bp);
456 ASSERT(bp->b_log_item == NULL);
461 * The buffer must be locked and held by the caller to simulate
462 * an async I/O failure. We acquired the hold for this case
463 * before the buffer was unpinned.
466 bp->b_flags |= XBF_ASYNC;
467 xfs_buf_ioend_fail(bp);
473 struct xfs_log_item *lip,
474 struct list_head *buffer_list)
476 struct xfs_buf_log_item *bip = BUF_ITEM(lip);
477 struct xfs_buf *bp = bip->bli_buf;
478 uint rval = XFS_ITEM_SUCCESS;
480 if (xfs_buf_ispinned(bp))
481 return XFS_ITEM_PINNED;
482 if (!xfs_buf_trylock(bp)) {
484 * If we have just raced with a buffer being pinned and it has
485 * been marked stale, we could end up stalling until someone else
486 * issues a log force to unpin the stale buffer. Check for the
487 * race condition here so xfsaild recognizes the buffer is pinned
488 * and queues a log force to move it along.
490 if (xfs_buf_ispinned(bp))
491 return XFS_ITEM_PINNED;
492 return XFS_ITEM_LOCKED;
495 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
497 trace_xfs_buf_item_push(bip);
499 /* has a previous flush failed due to IO errors? */
500 if (bp->b_flags & XBF_WRITE_FAIL) {
501 xfs_buf_alert_ratelimited(bp, "XFS: Failing async write",
502 "Failing async write on buffer block 0x%llx. Retrying async write.",
503 (long long)bp->b_bn);
506 if (!xfs_buf_delwri_queue(bp, buffer_list))
507 rval = XFS_ITEM_FLUSHING;
513 * Drop the buffer log item refcount and take appropriate action. This helper
514 * determines whether the bli must be freed or not, since a decrement to zero
515 * does not necessarily mean the bli is unused.
517 * Return true if the bli is freed, false otherwise.
521 struct xfs_buf_log_item *bip)
523 struct xfs_log_item *lip = &bip->bli_item;
527 /* drop the bli ref and return if it wasn't the last one */
528 if (!atomic_dec_and_test(&bip->bli_refcount))
532 * We dropped the last ref and must free the item if clean or aborted.
533 * If the bli is dirty and non-aborted, the buffer was clean in the
534 * transaction but still awaiting writeback from previous changes. In
535 * that case, the bli is freed on buffer writeback completion.
537 aborted = test_bit(XFS_LI_ABORTED, &lip->li_flags) ||
538 XFS_FORCED_SHUTDOWN(lip->li_mountp);
539 dirty = bip->bli_flags & XFS_BLI_DIRTY;
540 if (dirty && !aborted)
544 * The bli is aborted or clean. An aborted item may be in the AIL
545 * regardless of dirty state. For example, consider an aborted
546 * transaction that invalidated a dirty bli and cleared the dirty
550 xfs_trans_ail_delete(lip, 0);
551 xfs_buf_item_relse(bip->bli_buf);
556 * Release the buffer associated with the buf log item. If there is no dirty
557 * logged data associated with the buffer recorded in the buf log item, then
558 * free the buf log item and remove the reference to it in the buffer.
560 * This call ignores the recursion count. It is only called when the buffer
561 * should REALLY be unlocked, regardless of the recursion count.
563 * We unconditionally drop the transaction's reference to the log item. If the
564 * item was logged, then another reference was taken when it was pinned, so we
565 * can safely drop the transaction reference now. This also allows us to avoid
566 * potential races with the unpin code freeing the bli by not referencing the
567 * bli after we've dropped the reference count.
569 * If the XFS_BLI_HOLD flag is set in the buf log item, then free the log item
570 * if necessary but do not unlock the buffer. This is for support of
571 * xfs_trans_bhold(). Make sure the XFS_BLI_HOLD field is cleared if we don't
575 xfs_buf_item_release(
576 struct xfs_log_item *lip)
578 struct xfs_buf_log_item *bip = BUF_ITEM(lip);
579 struct xfs_buf *bp = bip->bli_buf;
581 bool hold = bip->bli_flags & XFS_BLI_HOLD;
582 bool stale = bip->bli_flags & XFS_BLI_STALE;
583 #if defined(DEBUG) || defined(XFS_WARN)
584 bool ordered = bip->bli_flags & XFS_BLI_ORDERED;
585 bool dirty = bip->bli_flags & XFS_BLI_DIRTY;
586 bool aborted = test_bit(XFS_LI_ABORTED,
590 trace_xfs_buf_item_release(bip);
593 * The bli dirty state should match whether the blf has logged segments
594 * except for ordered buffers, where only the bli should be dirty.
596 ASSERT((!ordered && dirty == xfs_buf_item_dirty_format(bip)) ||
597 (ordered && dirty && !xfs_buf_item_dirty_format(bip)));
598 ASSERT(!stale || (bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
601 * Clear the buffer's association with this transaction and
602 * per-transaction state from the bli, which has been copied above.
605 bip->bli_flags &= ~(XFS_BLI_LOGGED | XFS_BLI_HOLD | XFS_BLI_ORDERED);
608 * Unref the item and unlock the buffer unless held or stale. Stale
609 * buffers remain locked until final unpin unless the bli is freed by
610 * the unref call. The latter implies shutdown because buffer
611 * invalidation dirties the bli and transaction.
613 released = xfs_buf_item_put(bip);
614 if (hold || (stale && !released))
616 ASSERT(!stale || aborted);
621 xfs_buf_item_committing(
622 struct xfs_log_item *lip,
625 return xfs_buf_item_release(lip);
629 * This is called to find out where the oldest active copy of the
630 * buf log item in the on disk log resides now that the last log
631 * write of it completed at the given lsn.
632 * We always re-log all the dirty data in a buffer, so usually the
633 * latest copy in the on disk log is the only one that matters. For
634 * those cases we simply return the given lsn.
636 * The one exception to this is for buffers full of newly allocated
637 * inodes. These buffers are only relogged with the XFS_BLI_INODE_BUF
638 * flag set, indicating that only the di_next_unlinked fields from the
639 * inodes in the buffers will be replayed during recovery. If the
640 * original newly allocated inode images have not yet been flushed
641 * when the buffer is so relogged, then we need to make sure that we
642 * keep the old images in the 'active' portion of the log. We do this
643 * by returning the original lsn of that transaction here rather than
647 xfs_buf_item_committed(
648 struct xfs_log_item *lip,
651 struct xfs_buf_log_item *bip = BUF_ITEM(lip);
653 trace_xfs_buf_item_committed(bip);
655 if ((bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF) && lip->li_lsn != 0)
660 static const struct xfs_item_ops xfs_buf_item_ops = {
661 .iop_size = xfs_buf_item_size,
662 .iop_format = xfs_buf_item_format,
663 .iop_pin = xfs_buf_item_pin,
664 .iop_unpin = xfs_buf_item_unpin,
665 .iop_release = xfs_buf_item_release,
666 .iop_committing = xfs_buf_item_committing,
667 .iop_committed = xfs_buf_item_committed,
668 .iop_push = xfs_buf_item_push,
672 xfs_buf_item_get_format(
673 struct xfs_buf_log_item *bip,
676 ASSERT(bip->bli_formats == NULL);
677 bip->bli_format_count = count;
680 bip->bli_formats = &bip->__bli_format;
684 bip->bli_formats = kmem_zalloc(count * sizeof(struct xfs_buf_log_format),
689 xfs_buf_item_free_format(
690 struct xfs_buf_log_item *bip)
692 if (bip->bli_formats != &bip->__bli_format) {
693 kmem_free(bip->bli_formats);
694 bip->bli_formats = NULL;
699 * Allocate a new buf log item to go with the given buffer.
700 * Set the buffer's b_log_item field to point to the new
706 struct xfs_mount *mp)
708 struct xfs_buf_log_item *bip = bp->b_log_item;
714 * Check to see if there is already a buf log item for
715 * this buffer. If we do already have one, there is
716 * nothing to do here so return.
718 ASSERT(bp->b_mount == mp);
720 ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
721 ASSERT(!bp->b_transp);
722 ASSERT(bip->bli_buf == bp);
726 bip = kmem_cache_zalloc(xfs_buf_item_zone, GFP_KERNEL | __GFP_NOFAIL);
727 xfs_log_item_init(mp, &bip->bli_item, XFS_LI_BUF, &xfs_buf_item_ops);
731 * chunks is the number of XFS_BLF_CHUNK size pieces the buffer
732 * can be divided into. Make sure not to truncate any pieces.
733 * map_size is the size of the bitmap needed to describe the
734 * chunks of the buffer.
736 * Discontiguous buffer support follows the layout of the underlying
737 * buffer. This makes the implementation as simple as possible.
739 xfs_buf_item_get_format(bip, bp->b_map_count);
741 for (i = 0; i < bip->bli_format_count; i++) {
742 chunks = DIV_ROUND_UP(BBTOB(bp->b_maps[i].bm_len),
744 map_size = DIV_ROUND_UP(chunks, NBWORD);
746 if (map_size > XFS_BLF_DATAMAP_SIZE) {
747 kmem_cache_free(xfs_buf_item_zone, bip);
749 "buffer item dirty bitmap (%u uints) too small to reflect %u bytes!",
751 BBTOB(bp->b_maps[i].bm_len));
752 return -EFSCORRUPTED;
755 bip->bli_formats[i].blf_type = XFS_LI_BUF;
756 bip->bli_formats[i].blf_blkno = bp->b_maps[i].bm_bn;
757 bip->bli_formats[i].blf_len = bp->b_maps[i].bm_len;
758 bip->bli_formats[i].blf_map_size = map_size;
761 bp->b_log_item = bip;
768 * Mark bytes first through last inclusive as dirty in the buf
772 xfs_buf_item_log_segment(
787 ASSERT(first < XFS_BLF_DATAMAP_SIZE * XFS_BLF_CHUNK * NBWORD);
788 ASSERT(last < XFS_BLF_DATAMAP_SIZE * XFS_BLF_CHUNK * NBWORD);
791 * Convert byte offsets to bit numbers.
793 first_bit = first >> XFS_BLF_SHIFT;
794 last_bit = last >> XFS_BLF_SHIFT;
797 * Calculate the total number of bits to be set.
799 bits_to_set = last_bit - first_bit + 1;
802 * Get a pointer to the first word in the bitmap
805 word_num = first_bit >> BIT_TO_WORD_SHIFT;
806 wordp = &map[word_num];
809 * Calculate the starting bit in the first word.
811 bit = first_bit & (uint)(NBWORD - 1);
814 * First set any bits in the first word of our range.
815 * If it starts at bit 0 of the word, it will be
816 * set below rather than here. That is what the variable
817 * bit tells us. The variable bits_set tracks the number
818 * of bits that have been set so far. End_bit is the number
819 * of the last bit to be set in this word plus one.
822 end_bit = min(bit + bits_to_set, (uint)NBWORD);
823 mask = ((1U << (end_bit - bit)) - 1) << bit;
826 bits_set = end_bit - bit;
832 * Now set bits a whole word at a time that are between
833 * first_bit and last_bit.
835 while ((bits_to_set - bits_set) >= NBWORD) {
842 * Finally, set any bits left to be set in one last partial word.
844 end_bit = bits_to_set - bits_set;
846 mask = (1U << end_bit) - 1;
852 * Mark bytes first through last inclusive as dirty in the buf
857 struct xfs_buf_log_item *bip,
864 struct xfs_buf *bp = bip->bli_buf;
867 * walk each buffer segment and mark them dirty appropriately.
870 for (i = 0; i < bip->bli_format_count; i++) {
873 end = start + BBTOB(bp->b_maps[i].bm_len) - 1;
875 /* skip to the map that includes the first byte to log */
877 start += BBTOB(bp->b_maps[i].bm_len);
882 * Trim the range to this segment and mark it in the bitmap.
883 * Note that we must convert buffer offsets to segment relative
884 * offsets (e.g., the first byte of each segment is byte 0 of
891 xfs_buf_item_log_segment(first - start, end - start,
892 &bip->bli_formats[i].blf_data_map[0]);
894 start += BBTOB(bp->b_maps[i].bm_len);
900 * Return true if the buffer has any ranges logged/dirtied by a transaction,
904 xfs_buf_item_dirty_format(
905 struct xfs_buf_log_item *bip)
909 for (i = 0; i < bip->bli_format_count; i++) {
910 if (!xfs_bitmap_empty(bip->bli_formats[i].blf_data_map,
911 bip->bli_formats[i].blf_map_size))
920 struct xfs_buf_log_item *bip)
922 xfs_buf_item_free_format(bip);
923 kmem_free(bip->bli_item.li_lv_shadow);
924 kmem_cache_free(xfs_buf_item_zone, bip);
928 * xfs_buf_item_relse() is called when the buf log item is no longer needed.
934 struct xfs_buf_log_item *bip = bp->b_log_item;
936 trace_xfs_buf_item_relse(bp, _RET_IP_);
937 ASSERT(!test_bit(XFS_LI_IN_AIL, &bip->bli_item.li_flags));
939 bp->b_log_item = NULL;
941 xfs_buf_item_free(bip);
949 * If we are forcibly shutting down, this may well be off the AIL
950 * already. That's because we simulate the log-committed callbacks to
951 * unpin these buffers. Or we may never have put this item on AIL
952 * because of the transaction was aborted forcibly.
953 * xfs_trans_ail_delete() takes care of these.
955 * Either way, AIL is useless if we're forcing a shutdown.
957 * Note that log recovery writes might have buffer items that are not on
958 * the AIL even when the file system is not shut down.
960 xfs_trans_ail_delete(&bp->b_log_item->bli_item,
961 (bp->b_flags & _XBF_LOGRECOVERY) ? 0 :
962 SHUTDOWN_CORRUPT_INCORE);
963 xfs_buf_item_relse(bp);