2 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 * Free realtime space allocation for XFS.
38 #include "xfs_macros.h"
39 #include "xfs_types.h"
42 #include "xfs_trans.h"
47 #include "xfs_dmapi.h"
48 #include "xfs_mount.h"
49 #include "xfs_alloc_btree.h"
50 #include "xfs_bmap_btree.h"
51 #include "xfs_ialloc_btree.h"
52 #include "xfs_btree.h"
53 #include "xfs_ialloc.h"
54 #include "xfs_attr_sf.h"
55 #include "xfs_dir_sf.h"
56 #include "xfs_dir2_sf.h"
57 #include "xfs_dinode.h"
58 #include "xfs_inode.h"
59 #include "xfs_alloc.h"
62 #include "xfs_rtalloc.h"
63 #include "xfs_fsops.h"
64 #include "xfs_error.h"
66 #include "xfs_inode_item.h"
67 #include "xfs_trans_space.h"
71 * Prototypes for internal functions.
75 STATIC
int xfs_rtallocate_range(xfs_mount_t
*, xfs_trans_t
*, xfs_rtblock_t
,
76 xfs_extlen_t
, xfs_buf_t
**, xfs_fsblock_t
*);
77 STATIC
int xfs_rtany_summary(xfs_mount_t
*, xfs_trans_t
*, int, int,
78 xfs_rtblock_t
, xfs_buf_t
**, xfs_fsblock_t
*, int *);
79 STATIC
int xfs_rtcheck_range(xfs_mount_t
*, xfs_trans_t
*, xfs_rtblock_t
,
80 xfs_extlen_t
, int, xfs_rtblock_t
*, int *);
81 STATIC
int xfs_rtfind_back(xfs_mount_t
*, xfs_trans_t
*, xfs_rtblock_t
,
82 xfs_rtblock_t
, xfs_rtblock_t
*);
83 STATIC
int xfs_rtfind_forw(xfs_mount_t
*, xfs_trans_t
*, xfs_rtblock_t
,
84 xfs_rtblock_t
, xfs_rtblock_t
*);
85 STATIC
int xfs_rtget_summary( xfs_mount_t
*, xfs_trans_t
*, int,
86 xfs_rtblock_t
, xfs_buf_t
**, xfs_fsblock_t
*, xfs_suminfo_t
*);
87 STATIC
int xfs_rtmodify_range(xfs_mount_t
*, xfs_trans_t
*, xfs_rtblock_t
,
89 STATIC
int xfs_rtmodify_summary(xfs_mount_t
*, xfs_trans_t
*, int,
90 xfs_rtblock_t
, int, xfs_buf_t
**, xfs_fsblock_t
*);
97 * xfs_lowbit32: get low bit set out of 32-bit argument, -1 if none set.
109 * Allocate space to the bitmap or summary file, and zero it, for growfs.
111 STATIC
int /* error */
113 xfs_mount_t
*mp
, /* file system mount point */
114 xfs_extlen_t oblocks
, /* old count of blocks */
115 xfs_extlen_t nblocks
, /* new count of blocks */
116 xfs_ino_t ino
) /* inode number (bitmap/summary) */
118 xfs_fileoff_t bno
; /* block number in file */
119 xfs_buf_t
*bp
; /* temporary buffer for zeroing */
120 int cancelflags
; /* flags for xfs_trans_cancel */
121 int committed
; /* transaction committed flag */
122 xfs_daddr_t d
; /* disk block address */
123 int error
; /* error return value */
124 xfs_fsblock_t firstblock
; /* first block allocated in xaction */
125 xfs_bmap_free_t flist
; /* list of freed blocks */
126 xfs_fsblock_t fsbno
; /* filesystem block for bno */
127 xfs_inode_t
*ip
; /* pointer to incore inode */
128 xfs_bmbt_irec_t map
; /* block map output */
129 int nmap
; /* number of block maps */
130 int resblks
; /* space reservation */
131 xfs_trans_t
*tp
; /* transaction pointer */
134 * Allocate space to the file, as necessary.
136 while (oblocks
< nblocks
) {
137 tp
= xfs_trans_alloc(mp
, XFS_TRANS_GROWFSRT_ALLOC
);
138 resblks
= XFS_GROWFSRT_SPACE_RES(mp
, nblocks
- oblocks
);
141 * Reserve space & log for one extent added to the file.
143 if ((error
= xfs_trans_reserve(tp
, resblks
,
144 XFS_GROWRTALLOC_LOG_RES(mp
), 0,
145 XFS_TRANS_PERM_LOG_RES
,
146 XFS_DEFAULT_PERM_LOG_COUNT
)))
148 cancelflags
= XFS_TRANS_RELEASE_LOG_RES
;
152 if ((error
= xfs_trans_iget(mp
, tp
, ino
, 0, XFS_ILOCK_EXCL
, &ip
)))
154 XFS_BMAP_INIT(&flist
, &firstblock
);
156 * Allocate blocks to the bitmap file.
159 cancelflags
|= XFS_TRANS_ABORT
;
160 error
= xfs_bmapi(tp
, ip
, oblocks
, nblocks
- oblocks
,
161 XFS_BMAPI_WRITE
| XFS_BMAPI_METADATA
, &firstblock
,
162 resblks
, &map
, &nmap
, &flist
);
163 if (!error
&& nmap
< 1)
164 error
= XFS_ERROR(ENOSPC
);
168 * Free any blocks freed up in the transaction, then commit.
170 error
= xfs_bmap_finish(&tp
, &flist
, firstblock
, &committed
);
173 xfs_trans_commit(tp
, XFS_TRANS_RELEASE_LOG_RES
, NULL
);
175 * Now we need to clear the allocated blocks.
176 * Do this one block per transaction, to keep it simple.
179 for (bno
= map
.br_startoff
, fsbno
= map
.br_startblock
;
180 bno
< map
.br_startoff
+ map
.br_blockcount
;
182 tp
= xfs_trans_alloc(mp
, XFS_TRANS_GROWFSRT_ZERO
);
184 * Reserve log for one block zeroing.
186 if ((error
= xfs_trans_reserve(tp
, 0,
187 XFS_GROWRTZERO_LOG_RES(mp
), 0, 0, 0)))
190 * Lock the bitmap inode.
192 if ((error
= xfs_trans_iget(mp
, tp
, ino
, 0, XFS_ILOCK_EXCL
,
196 * Get a buffer for the block.
198 d
= XFS_FSB_TO_DADDR(mp
, fsbno
);
199 bp
= xfs_trans_get_buf(tp
, mp
->m_ddev_targp
, d
,
202 error
= XFS_ERROR(EIO
);
205 memset(XFS_BUF_PTR(bp
), 0, mp
->m_sb
.sb_blocksize
);
206 xfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
208 * Commit the transaction.
210 xfs_trans_commit(tp
, 0, NULL
);
213 * Go on to the next extent, if any.
215 oblocks
= map
.br_startoff
+ map
.br_blockcount
;
219 xfs_trans_cancel(tp
, cancelflags
);
224 * Attempt to allocate an extent minlen<=len<=maxlen starting from
225 * bitmap block bbno. If we don't get maxlen then use prod to trim
226 * the length, if given. Returns error; returns starting block in *rtblock.
227 * The lengths are all in rtextents.
229 STATIC
int /* error */
230 xfs_rtallocate_extent_block(
231 xfs_mount_t
*mp
, /* file system mount point */
232 xfs_trans_t
*tp
, /* transaction pointer */
233 xfs_rtblock_t bbno
, /* bitmap block number */
234 xfs_extlen_t minlen
, /* minimum length to allocate */
235 xfs_extlen_t maxlen
, /* maximum length to allocate */
236 xfs_extlen_t
*len
, /* out: actual length allocated */
237 xfs_rtblock_t
*nextp
, /* out: next block to try */
238 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
239 xfs_fsblock_t
*rsb
, /* in/out: summary block number */
240 xfs_extlen_t prod
, /* extent product factor */
241 xfs_rtblock_t
*rtblock
) /* out: start block allocated */
243 xfs_rtblock_t besti
; /* best rtblock found so far */
244 xfs_rtblock_t bestlen
; /* best length found so far */
245 xfs_rtblock_t end
; /* last rtblock in chunk */
246 int error
; /* error value */
247 xfs_rtblock_t i
; /* current rtblock trying */
248 xfs_rtblock_t next
; /* next rtblock to try */
249 int stat
; /* status from internal calls */
252 * Loop over all the extents starting in this bitmap block,
253 * looking for one that's long enough.
255 for (i
= XFS_BLOCKTOBIT(mp
, bbno
), besti
= -1, bestlen
= 0,
256 end
= XFS_BLOCKTOBIT(mp
, bbno
+ 1) - 1;
260 * See if there's a free extent of maxlen starting at i.
261 * If it's not so then next will contain the first non-free.
263 error
= xfs_rtcheck_range(mp
, tp
, i
, maxlen
, 1, &next
, &stat
);
269 * i for maxlen is all free, allocate and return that.
271 error
= xfs_rtallocate_range(mp
, tp
, i
, maxlen
, rbpp
,
281 * In the case where we have a variable-sized allocation
282 * request, figure out how big this free piece is,
283 * and if it's big enough for the minimum, and the best
284 * so far, remember it.
286 if (minlen
< maxlen
) {
287 xfs_rtblock_t thislen
; /* this extent size */
290 if (thislen
>= minlen
&& thislen
> bestlen
) {
296 * If not done yet, find the start of the next free space.
299 error
= xfs_rtfind_forw(mp
, tp
, next
, end
, &i
);
307 * Searched the whole thing & didn't find a maxlen free extent.
309 if (minlen
< maxlen
&& besti
!= -1) {
310 xfs_extlen_t p
; /* amount to trim length by */
313 * If size should be a multiple of prod, make that so.
315 if (prod
> 1 && (p
= do_mod(bestlen
, prod
)))
318 * Allocate besti for bestlen & return that.
320 error
= xfs_rtallocate_range(mp
, tp
, besti
, bestlen
, rbpp
, rsb
);
329 * Allocation failed. Set *nextp to the next block to try.
332 *rtblock
= NULLRTBLOCK
;
337 * Allocate an extent of length minlen<=len<=maxlen, starting at block
338 * bno. If we don't get maxlen then use prod to trim the length, if given.
339 * Returns error; returns starting block in *rtblock.
340 * The lengths are all in rtextents.
342 STATIC
int /* error */
343 xfs_rtallocate_extent_exact(
344 xfs_mount_t
*mp
, /* file system mount point */
345 xfs_trans_t
*tp
, /* transaction pointer */
346 xfs_rtblock_t bno
, /* starting block number to allocate */
347 xfs_extlen_t minlen
, /* minimum length to allocate */
348 xfs_extlen_t maxlen
, /* maximum length to allocate */
349 xfs_extlen_t
*len
, /* out: actual length allocated */
350 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
351 xfs_fsblock_t
*rsb
, /* in/out: summary block number */
352 xfs_extlen_t prod
, /* extent product factor */
353 xfs_rtblock_t
*rtblock
) /* out: start block allocated */
355 int error
; /* error value */
356 xfs_extlen_t i
; /* extent length trimmed due to prod */
357 int isfree
; /* extent is free */
358 xfs_rtblock_t next
; /* next block to try (dummy) */
360 ASSERT(minlen
% prod
== 0 && maxlen
% prod
== 0);
362 * Check if the range in question (for maxlen) is free.
364 error
= xfs_rtcheck_range(mp
, tp
, bno
, maxlen
, 1, &next
, &isfree
);
370 * If it is, allocate it and return success.
372 error
= xfs_rtallocate_range(mp
, tp
, bno
, maxlen
, rbpp
, rsb
);
381 * If not, allocate what there is, if it's at least minlen.
384 if (maxlen
< minlen
) {
386 * Failed, return failure status.
388 *rtblock
= NULLRTBLOCK
;
392 * Trim off tail of extent, if prod is specified.
394 if (prod
> 1 && (i
= maxlen
% prod
)) {
396 if (maxlen
< minlen
) {
398 * Now we can't do it, return failure status.
400 *rtblock
= NULLRTBLOCK
;
405 * Allocate what we can and return it.
407 error
= xfs_rtallocate_range(mp
, tp
, bno
, maxlen
, rbpp
, rsb
);
417 * Allocate an extent of length minlen<=len<=maxlen, starting as near
418 * to bno as possible. If we don't get maxlen then use prod to trim
419 * the length, if given. The lengths are all in rtextents.
421 STATIC
int /* error */
422 xfs_rtallocate_extent_near(
423 xfs_mount_t
*mp
, /* file system mount point */
424 xfs_trans_t
*tp
, /* transaction pointer */
425 xfs_rtblock_t bno
, /* starting block number to allocate */
426 xfs_extlen_t minlen
, /* minimum length to allocate */
427 xfs_extlen_t maxlen
, /* maximum length to allocate */
428 xfs_extlen_t
*len
, /* out: actual length allocated */
429 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
430 xfs_fsblock_t
*rsb
, /* in/out: summary block number */
431 xfs_extlen_t prod
, /* extent product factor */
432 xfs_rtblock_t
*rtblock
) /* out: start block allocated */
434 int any
; /* any useful extents from summary */
435 xfs_rtblock_t bbno
; /* bitmap block number */
436 int error
; /* error value */
437 int i
; /* bitmap block offset (loop control) */
438 int j
; /* secondary loop control */
439 int log2len
; /* log2 of minlen */
440 xfs_rtblock_t n
; /* next block to try */
441 xfs_rtblock_t r
; /* result block */
443 ASSERT(minlen
% prod
== 0 && maxlen
% prod
== 0);
445 * If the block number given is off the end, silently set it to
448 if (bno
>= mp
->m_sb
.sb_rextents
)
449 bno
= mp
->m_sb
.sb_rextents
- 1;
451 * Try the exact allocation first.
453 error
= xfs_rtallocate_extent_exact(mp
, tp
, bno
, minlen
, maxlen
, len
,
454 rbpp
, rsb
, prod
, &r
);
459 * If the exact allocation worked, return that.
461 if (r
!= NULLRTBLOCK
) {
465 bbno
= XFS_BITTOBLOCK(mp
, bno
);
467 log2len
= xfs_highbit32(minlen
);
469 * Loop over all bitmap blocks (bbno + i is current block).
473 * Get summary information of extents of all useful levels
474 * starting in this bitmap block.
476 error
= xfs_rtany_summary(mp
, tp
, log2len
, mp
->m_rsumlevels
- 1,
477 bbno
+ i
, rbpp
, rsb
, &any
);
482 * If there are any useful extents starting here, try
487 * On the positive side of the starting location.
491 * Try to allocate an extent starting in
494 error
= xfs_rtallocate_extent_block(mp
, tp
,
495 bbno
+ i
, minlen
, maxlen
, len
, &n
, rbpp
,
501 * If it worked, return it.
503 if (r
!= NULLRTBLOCK
) {
509 * On the negative side of the starting location.
513 * Loop backwards through the bitmap blocks from
514 * the starting point-1 up to where we are now.
515 * There should be an extent which ends in this
516 * bitmap block and is long enough.
518 for (j
= -1; j
> i
; j
--) {
520 * Grab the summary information for
523 error
= xfs_rtany_summary(mp
, tp
,
524 log2len
, mp
->m_rsumlevels
- 1,
525 bbno
+ j
, rbpp
, rsb
, &any
);
530 * If there's no extent given in the
531 * summary that means the extent we
532 * found must carry over from an
533 * earlier block. If there is an
534 * extent given, we've already tried
535 * that allocation, don't do it again.
539 error
= xfs_rtallocate_extent_block(mp
,
540 tp
, bbno
+ j
, minlen
, maxlen
,
541 len
, &n
, rbpp
, rsb
, prod
, &r
);
546 * If it works, return the extent.
548 if (r
!= NULLRTBLOCK
) {
554 * There weren't intervening bitmap blocks
555 * with a long enough extent, or the
556 * allocation didn't work for some reason
557 * (i.e. it's a little * too short).
558 * Try to allocate from the summary block
561 error
= xfs_rtallocate_extent_block(mp
, tp
,
562 bbno
+ i
, minlen
, maxlen
, len
, &n
, rbpp
,
568 * If it works, return the extent.
570 if (r
!= NULLRTBLOCK
) {
577 * Loop control. If we were on the positive side, and there's
578 * still more blocks on the negative side, go there.
580 if (i
> 0 && (int)bbno
- i
>= 0)
583 * If positive, and no more negative, but there are more
584 * positive, go there.
586 else if (i
> 0 && (int)bbno
+ i
< mp
->m_sb
.sb_rbmblocks
- 1)
589 * If negative or 0 (just started), and there are positive
590 * blocks to go, go there. The 0 case moves to block 1.
592 else if (i
<= 0 && (int)bbno
- i
< mp
->m_sb
.sb_rbmblocks
- 1)
595 * If negative or 0 and there are more negative blocks,
598 else if (i
<= 0 && (int)bbno
+ i
> 0)
601 * Must be done. Return failure.
606 *rtblock
= NULLRTBLOCK
;
611 * Allocate an extent of length minlen<=len<=maxlen, with no position
612 * specified. If we don't get maxlen then use prod to trim
613 * the length, if given. The lengths are all in rtextents.
615 STATIC
int /* error */
616 xfs_rtallocate_extent_size(
617 xfs_mount_t
*mp
, /* file system mount point */
618 xfs_trans_t
*tp
, /* transaction pointer */
619 xfs_extlen_t minlen
, /* minimum length to allocate */
620 xfs_extlen_t maxlen
, /* maximum length to allocate */
621 xfs_extlen_t
*len
, /* out: actual length allocated */
622 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
623 xfs_fsblock_t
*rsb
, /* in/out: summary block number */
624 xfs_extlen_t prod
, /* extent product factor */
625 xfs_rtblock_t
*rtblock
) /* out: start block allocated */
627 int error
; /* error value */
628 int i
; /* bitmap block number */
629 int l
; /* level number (loop control) */
630 xfs_rtblock_t n
; /* next block to be tried */
631 xfs_rtblock_t r
; /* result block number */
632 xfs_suminfo_t sum
; /* summary information for extents */
634 ASSERT(minlen
% prod
== 0 && maxlen
% prod
== 0);
636 * Loop over all the levels starting with maxlen.
637 * At each level, look at all the bitmap blocks, to see if there
638 * are extents starting there that are long enough (>= maxlen).
639 * Note, only on the initial level can the allocation fail if
640 * the summary says there's an extent.
642 for (l
= xfs_highbit32(maxlen
); l
< mp
->m_rsumlevels
; l
++) {
644 * Loop over all the bitmap blocks.
646 for (i
= 0; i
< mp
->m_sb
.sb_rbmblocks
; i
++) {
648 * Get the summary for this level/block.
650 error
= xfs_rtget_summary(mp
, tp
, l
, i
, rbpp
, rsb
,
656 * Nothing there, on to the next block.
661 * Try allocating the extent.
663 error
= xfs_rtallocate_extent_block(mp
, tp
, i
, maxlen
,
664 maxlen
, len
, &n
, rbpp
, rsb
, prod
, &r
);
669 * If it worked, return that.
671 if (r
!= NULLRTBLOCK
) {
676 * If the "next block to try" returned from the
677 * allocator is beyond the next bitmap block,
678 * skip to that bitmap block.
680 if (XFS_BITTOBLOCK(mp
, n
) > i
+ 1)
681 i
= XFS_BITTOBLOCK(mp
, n
) - 1;
685 * Didn't find any maxlen blocks. Try smaller ones, unless
686 * we're asking for a fixed size extent.
688 if (minlen
> --maxlen
) {
689 *rtblock
= NULLRTBLOCK
;
693 * Loop over sizes, from maxlen down to minlen.
694 * This time, when we do the allocations, allow smaller ones
697 for (l
= xfs_highbit32(maxlen
); l
>= xfs_highbit32(minlen
); l
--) {
699 * Loop over all the bitmap blocks, try an allocation
700 * starting in that block.
702 for (i
= 0; i
< mp
->m_sb
.sb_rbmblocks
; i
++) {
704 * Get the summary information for this level/block.
706 error
= xfs_rtget_summary(mp
, tp
, l
, i
, rbpp
, rsb
,
712 * If nothing there, go on to next.
717 * Try the allocation. Make sure the specified
718 * minlen/maxlen are in the possible range for
719 * this summary level.
721 error
= xfs_rtallocate_extent_block(mp
, tp
, i
,
722 XFS_RTMAX(minlen
, 1 << l
),
723 XFS_RTMIN(maxlen
, (1 << (l
+ 1)) - 1),
724 len
, &n
, rbpp
, rsb
, prod
, &r
);
729 * If it worked, return that extent.
731 if (r
!= NULLRTBLOCK
) {
736 * If the "next block to try" returned from the
737 * allocator is beyond the next bitmap block,
738 * skip to that bitmap block.
740 if (XFS_BITTOBLOCK(mp
, n
) > i
+ 1)
741 i
= XFS_BITTOBLOCK(mp
, n
) - 1;
745 * Got nothing, return failure.
747 *rtblock
= NULLRTBLOCK
;
752 * Mark an extent specified by start and len allocated.
753 * Updates all the summary information as well as the bitmap.
755 STATIC
int /* error */
756 xfs_rtallocate_range(
757 xfs_mount_t
*mp
, /* file system mount point */
758 xfs_trans_t
*tp
, /* transaction pointer */
759 xfs_rtblock_t start
, /* start block to allocate */
760 xfs_extlen_t len
, /* length to allocate */
761 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
762 xfs_fsblock_t
*rsb
) /* in/out: summary block number */
764 xfs_rtblock_t end
; /* end of the allocated extent */
765 int error
; /* error value */
766 xfs_rtblock_t postblock
; /* first block allocated > end */
767 xfs_rtblock_t preblock
; /* first block allocated < start */
769 end
= start
+ len
- 1;
771 * Assume we're allocating out of the middle of a free extent.
772 * We need to find the beginning and end of the extent so we can
773 * properly update the summary.
775 error
= xfs_rtfind_back(mp
, tp
, start
, 0, &preblock
);
780 * Find the next allocated block (end of free extent).
782 error
= xfs_rtfind_forw(mp
, tp
, end
, mp
->m_sb
.sb_rextents
- 1,
788 * Decrement the summary information corresponding to the entire
791 error
= xfs_rtmodify_summary(mp
, tp
,
792 XFS_RTBLOCKLOG(postblock
+ 1 - preblock
),
793 XFS_BITTOBLOCK(mp
, preblock
), -1, rbpp
, rsb
);
798 * If there are blocks not being allocated at the front of the
799 * old extent, add summary data for them to be free.
801 if (preblock
< start
) {
802 error
= xfs_rtmodify_summary(mp
, tp
,
803 XFS_RTBLOCKLOG(start
- preblock
),
804 XFS_BITTOBLOCK(mp
, preblock
), 1, rbpp
, rsb
);
810 * If there are blocks not being allocated at the end of the
811 * old extent, add summary data for them to be free.
813 if (postblock
> end
) {
814 error
= xfs_rtmodify_summary(mp
, tp
,
815 XFS_RTBLOCKLOG(postblock
- end
),
816 XFS_BITTOBLOCK(mp
, end
+ 1), 1, rbpp
, rsb
);
822 * Modify the bitmap to mark this extent allocated.
824 error
= xfs_rtmodify_range(mp
, tp
, start
, len
, 0);
829 * Return whether there are any free extents in the size range given
830 * by low and high, for the bitmap block bbno.
832 STATIC
int /* error */
834 xfs_mount_t
*mp
, /* file system mount structure */
835 xfs_trans_t
*tp
, /* transaction pointer */
836 int low
, /* low log2 extent size */
837 int high
, /* high log2 extent size */
838 xfs_rtblock_t bbno
, /* bitmap block number */
839 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
840 xfs_fsblock_t
*rsb
, /* in/out: summary block number */
841 int *stat
) /* out: any good extents here? */
843 int error
; /* error value */
844 int log
; /* loop counter, log2 of ext. size */
845 xfs_suminfo_t sum
; /* summary data */
848 * Loop over logs of extent sizes. Order is irrelevant.
850 for (log
= low
; log
<= high
; log
++) {
852 * Get one summary datum.
854 error
= xfs_rtget_summary(mp
, tp
, log
, bbno
, rbpp
, rsb
, &sum
);
859 * If there are any, return success.
867 * Found nothing, return failure.
874 * Get a buffer for the bitmap or summary file block specified.
875 * The buffer is returned read and locked.
877 STATIC
int /* error */
879 xfs_mount_t
*mp
, /* file system mount structure */
880 xfs_trans_t
*tp
, /* transaction pointer */
881 xfs_rtblock_t block
, /* block number in bitmap or summary */
882 int issum
, /* is summary not bitmap */
883 xfs_buf_t
**bpp
) /* output: buffer for the block */
885 xfs_buf_t
*bp
; /* block buffer, result */
886 xfs_daddr_t d
; /* disk addr of block */
887 int error
; /* error value */
888 xfs_fsblock_t fsb
; /* fs block number for block */
889 xfs_inode_t
*ip
; /* bitmap or summary inode */
891 ip
= issum
? mp
->m_rsumip
: mp
->m_rbmip
;
893 * Map from the file offset (block) and inode number to the
896 error
= xfs_bmapi_single(tp
, ip
, XFS_DATA_FORK
, &fsb
, block
);
900 ASSERT(fsb
!= NULLFSBLOCK
);
902 * Convert to disk address for buffer cache.
904 d
= XFS_FSB_TO_DADDR(mp
, fsb
);
908 error
= xfs_trans_read_buf(mp
, tp
, mp
->m_ddev_targp
, d
,
909 mp
->m_bsize
, 0, &bp
);
913 ASSERT(bp
&& !XFS_BUF_GETERROR(bp
));
920 * Check that the given extent (block range) is allocated already.
922 STATIC
int /* error */
923 xfs_rtcheck_alloc_range(
924 xfs_mount_t
*mp
, /* file system mount point */
925 xfs_trans_t
*tp
, /* transaction pointer */
926 xfs_rtblock_t bno
, /* starting block number of extent */
927 xfs_extlen_t len
, /* length of extent */
928 int *stat
) /* out: 1 for allocated, 0 for not */
930 xfs_rtblock_t
new; /* dummy for xfs_rtcheck_range */
932 return xfs_rtcheck_range(mp
, tp
, bno
, len
, 0, &new, stat
);
938 * Check whether the given block in the bitmap has the given value.
940 STATIC
int /* 1 for matches, 0 for not */
942 xfs_mount_t
*mp
, /* file system mount structure */
943 xfs_trans_t
*tp
, /* transaction pointer */
944 xfs_rtblock_t start
, /* bit (block) to check */
945 int val
) /* 1 for free, 0 for allocated */
947 int bit
; /* bit number in the word */
948 xfs_rtblock_t block
; /* bitmap block number */
949 xfs_buf_t
*bp
; /* buf for the block */
950 xfs_rtword_t
*bufp
; /* pointer into the buffer */
952 int error
; /* error value */
953 xfs_rtword_t wdiff
; /* difference between bit & expected */
954 int word
; /* word number in the buffer */
955 xfs_rtword_t wval
; /* word value from buffer */
957 block
= XFS_BITTOBLOCK(mp
, start
);
958 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
959 bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
960 word
= XFS_BITTOWORD(mp
, start
);
961 bit
= (int)(start
& (XFS_NBWORD
- 1));
963 xfs_trans_brelse(tp
, bp
);
964 wdiff
= (wval
^ -val
) & ((xfs_rtword_t
)1 << bit
);
971 * Check that the given extent (block range) is free already.
973 STATIC
int /* error */
974 xfs_rtcheck_free_range(
975 xfs_mount_t
*mp
, /* file system mount point */
976 xfs_trans_t
*tp
, /* transaction pointer */
977 xfs_rtblock_t bno
, /* starting block number of extent */
978 xfs_extlen_t len
, /* length of extent */
979 int *stat
) /* out: 1 for free, 0 for not */
981 xfs_rtblock_t
new; /* dummy for xfs_rtcheck_range */
983 return xfs_rtcheck_range(mp
, tp
, bno
, len
, 1, &new, stat
);
988 * Check that the given range is either all allocated (val = 0) or
989 * all free (val = 1).
991 STATIC
int /* error */
993 xfs_mount_t
*mp
, /* file system mount point */
994 xfs_trans_t
*tp
, /* transaction pointer */
995 xfs_rtblock_t start
, /* starting block number of extent */
996 xfs_extlen_t len
, /* length of extent */
997 int val
, /* 1 for free, 0 for allocated */
998 xfs_rtblock_t
*new, /* out: first block not matching */
999 int *stat
) /* out: 1 for matches, 0 for not */
1001 xfs_rtword_t
*b
; /* current word in buffer */
1002 int bit
; /* bit number in the word */
1003 xfs_rtblock_t block
; /* bitmap block number */
1004 xfs_buf_t
*bp
; /* buf for the block */
1005 xfs_rtword_t
*bufp
; /* starting word in buffer */
1006 int error
; /* error value */
1007 xfs_rtblock_t i
; /* current bit number rel. to start */
1008 xfs_rtblock_t lastbit
; /* last useful bit in word */
1009 xfs_rtword_t mask
; /* mask of relevant bits for value */
1010 xfs_rtword_t wdiff
; /* difference from wanted value */
1011 int word
; /* word number in the buffer */
1014 * Compute starting bitmap block number
1016 block
= XFS_BITTOBLOCK(mp
, start
);
1018 * Read the bitmap block.
1020 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
1024 bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1026 * Compute the starting word's address, and starting bit.
1028 word
= XFS_BITTOWORD(mp
, start
);
1030 bit
= (int)(start
& (XFS_NBWORD
- 1));
1032 * 0 (allocated) => all zero's; 1 (free) => all one's.
1036 * If not starting on a word boundary, deal with the first
1041 * Compute first bit not examined.
1043 lastbit
= XFS_RTMIN(bit
+ len
, XFS_NBWORD
);
1045 * Mask of relevant bits.
1047 mask
= (((xfs_rtword_t
)1 << (lastbit
- bit
)) - 1) << bit
;
1049 * Compute difference between actual and desired value.
1051 if ((wdiff
= (*b
^ val
) & mask
)) {
1053 * Different, compute first wrong bit and return.
1055 xfs_trans_brelse(tp
, bp
);
1056 i
= XFS_RTLOBIT(wdiff
) - bit
;
1063 * Go on to next block if that's where the next word is
1064 * and we need the next word.
1066 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
1068 * If done with this block, get the next one.
1070 xfs_trans_brelse(tp
, bp
);
1071 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
1075 b
= bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1079 * Go on to the next word in the buffer.
1085 * Starting on a word boundary, no partial word.
1090 * Loop over whole words in buffers. When we use up one buffer
1091 * we move on to the next one.
1093 while (len
- i
>= XFS_NBWORD
) {
1095 * Compute difference between actual and desired value.
1097 if ((wdiff
= *b
^ val
)) {
1099 * Different, compute first wrong bit and return.
1101 xfs_trans_brelse(tp
, bp
);
1102 i
+= XFS_RTLOBIT(wdiff
);
1109 * Go on to next block if that's where the next word is
1110 * and we need the next word.
1112 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
1114 * If done with this block, get the next one.
1116 xfs_trans_brelse(tp
, bp
);
1117 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
1121 b
= bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1125 * Go on to the next word in the buffer.
1131 * If not ending on a word boundary, deal with the last
1134 if ((lastbit
= len
- i
)) {
1136 * Mask of relevant bits.
1138 mask
= ((xfs_rtword_t
)1 << lastbit
) - 1;
1140 * Compute difference between actual and desired value.
1142 if ((wdiff
= (*b
^ val
) & mask
)) {
1144 * Different, compute first wrong bit and return.
1146 xfs_trans_brelse(tp
, bp
);
1147 i
+= XFS_RTLOBIT(wdiff
);
1155 * Successful, return.
1157 xfs_trans_brelse(tp
, bp
);
1164 * Copy and transform the summary file, given the old and new
1165 * parameters in the mount structures.
1167 STATIC
int /* error */
1169 xfs_mount_t
*omp
, /* old file system mount point */
1170 xfs_mount_t
*nmp
, /* new file system mount point */
1171 xfs_trans_t
*tp
) /* transaction pointer */
1173 xfs_rtblock_t bbno
; /* bitmap block number */
1174 xfs_buf_t
*bp
; /* summary buffer */
1175 int error
; /* error return value */
1176 int log
; /* summary level number (log length) */
1177 xfs_suminfo_t sum
; /* summary data */
1178 xfs_fsblock_t sumbno
; /* summary block number */
1181 for (log
= omp
->m_rsumlevels
- 1; log
>= 0; log
--) {
1182 for (bbno
= omp
->m_sb
.sb_rbmblocks
- 1;
1183 (xfs_srtblock_t
)bbno
>= 0;
1185 error
= xfs_rtget_summary(omp
, tp
, log
, bbno
, &bp
,
1191 error
= xfs_rtmodify_summary(omp
, tp
, log
, bbno
, -sum
,
1195 error
= xfs_rtmodify_summary(nmp
, tp
, log
, bbno
, sum
,
1206 * Searching backward from start to limit, find the first block whose
1207 * allocated/free state is different from start's.
1209 STATIC
int /* error */
1211 xfs_mount_t
*mp
, /* file system mount point */
1212 xfs_trans_t
*tp
, /* transaction pointer */
1213 xfs_rtblock_t start
, /* starting block to look at */
1214 xfs_rtblock_t limit
, /* last block to look at */
1215 xfs_rtblock_t
*rtblock
) /* out: start block found */
1217 xfs_rtword_t
*b
; /* current word in buffer */
1218 int bit
; /* bit number in the word */
1219 xfs_rtblock_t block
; /* bitmap block number */
1220 xfs_buf_t
*bp
; /* buf for the block */
1221 xfs_rtword_t
*bufp
; /* starting word in buffer */
1222 int error
; /* error value */
1223 xfs_rtblock_t firstbit
; /* first useful bit in the word */
1224 xfs_rtblock_t i
; /* current bit number rel. to start */
1225 xfs_rtblock_t len
; /* length of inspected area */
1226 xfs_rtword_t mask
; /* mask of relevant bits for value */
1227 xfs_rtword_t want
; /* mask for "good" values */
1228 xfs_rtword_t wdiff
; /* difference from wanted value */
1229 int word
; /* word number in the buffer */
1232 * Compute and read in starting bitmap block for starting block.
1234 block
= XFS_BITTOBLOCK(mp
, start
);
1235 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
1239 bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1241 * Get the first word's index & point to it.
1243 word
= XFS_BITTOWORD(mp
, start
);
1245 bit
= (int)(start
& (XFS_NBWORD
- 1));
1246 len
= start
- limit
+ 1;
1248 * Compute match value, based on the bit at start: if 1 (free)
1249 * then all-ones, else all-zeroes.
1251 want
= (*b
& ((xfs_rtword_t
)1 << bit
)) ? -1 : 0;
1253 * If the starting position is not word-aligned, deal with the
1256 if (bit
< XFS_NBWORD
- 1) {
1258 * Calculate first (leftmost) bit number to look at,
1259 * and mask for all the relevant bits in this word.
1261 firstbit
= XFS_RTMAX((xfs_srtblock_t
)(bit
- len
+ 1), 0);
1262 mask
= (((xfs_rtword_t
)1 << (bit
- firstbit
+ 1)) - 1) <<
1265 * Calculate the difference between the value there
1266 * and what we're looking for.
1268 if ((wdiff
= (*b
^ want
) & mask
)) {
1270 * Different. Mark where we are and return.
1272 xfs_trans_brelse(tp
, bp
);
1273 i
= bit
- XFS_RTHIBIT(wdiff
);
1274 *rtblock
= start
- i
+ 1;
1277 i
= bit
- firstbit
+ 1;
1279 * Go on to previous block if that's where the previous word is
1280 * and we need the previous word.
1282 if (--word
== -1 && i
< len
) {
1284 * If done with this block, get the previous one.
1286 xfs_trans_brelse(tp
, bp
);
1287 error
= xfs_rtbuf_get(mp
, tp
, --block
, 0, &bp
);
1291 bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1292 word
= XFS_BLOCKWMASK(mp
);
1296 * Go on to the previous word in the buffer.
1302 * Starting on a word boundary, no partial word.
1307 * Loop over whole words in buffers. When we use up one buffer
1308 * we move on to the previous one.
1310 while (len
- i
>= XFS_NBWORD
) {
1312 * Compute difference between actual and desired value.
1314 if ((wdiff
= *b
^ want
)) {
1316 * Different, mark where we are and return.
1318 xfs_trans_brelse(tp
, bp
);
1319 i
+= XFS_NBWORD
- 1 - XFS_RTHIBIT(wdiff
);
1320 *rtblock
= start
- i
+ 1;
1325 * Go on to previous block if that's where the previous word is
1326 * and we need the previous word.
1328 if (--word
== -1 && i
< len
) {
1330 * If done with this block, get the previous one.
1332 xfs_trans_brelse(tp
, bp
);
1333 error
= xfs_rtbuf_get(mp
, tp
, --block
, 0, &bp
);
1337 bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1338 word
= XFS_BLOCKWMASK(mp
);
1342 * Go on to the previous word in the buffer.
1348 * If not ending on a word boundary, deal with the last
1353 * Calculate first (leftmost) bit number to look at,
1354 * and mask for all the relevant bits in this word.
1356 firstbit
= XFS_NBWORD
- (len
- i
);
1357 mask
= (((xfs_rtword_t
)1 << (len
- i
)) - 1) << firstbit
;
1359 * Compute difference between actual and desired value.
1361 if ((wdiff
= (*b
^ want
) & mask
)) {
1363 * Different, mark where we are and return.
1365 xfs_trans_brelse(tp
, bp
);
1366 i
+= XFS_NBWORD
- 1 - XFS_RTHIBIT(wdiff
);
1367 *rtblock
= start
- i
+ 1;
1373 * No match, return that we scanned the whole area.
1375 xfs_trans_brelse(tp
, bp
);
1376 *rtblock
= start
- i
+ 1;
1381 * Searching forward from start to limit, find the first block whose
1382 * allocated/free state is different from start's.
1384 STATIC
int /* error */
1386 xfs_mount_t
*mp
, /* file system mount point */
1387 xfs_trans_t
*tp
, /* transaction pointer */
1388 xfs_rtblock_t start
, /* starting block to look at */
1389 xfs_rtblock_t limit
, /* last block to look at */
1390 xfs_rtblock_t
*rtblock
) /* out: start block found */
1392 xfs_rtword_t
*b
; /* current word in buffer */
1393 int bit
; /* bit number in the word */
1394 xfs_rtblock_t block
; /* bitmap block number */
1395 xfs_buf_t
*bp
; /* buf for the block */
1396 xfs_rtword_t
*bufp
; /* starting word in buffer */
1397 int error
; /* error value */
1398 xfs_rtblock_t i
; /* current bit number rel. to start */
1399 xfs_rtblock_t lastbit
; /* last useful bit in the word */
1400 xfs_rtblock_t len
; /* length of inspected area */
1401 xfs_rtword_t mask
; /* mask of relevant bits for value */
1402 xfs_rtword_t want
; /* mask for "good" values */
1403 xfs_rtword_t wdiff
; /* difference from wanted value */
1404 int word
; /* word number in the buffer */
1407 * Compute and read in starting bitmap block for starting block.
1409 block
= XFS_BITTOBLOCK(mp
, start
);
1410 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
1414 bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1416 * Get the first word's index & point to it.
1418 word
= XFS_BITTOWORD(mp
, start
);
1420 bit
= (int)(start
& (XFS_NBWORD
- 1));
1421 len
= limit
- start
+ 1;
1423 * Compute match value, based on the bit at start: if 1 (free)
1424 * then all-ones, else all-zeroes.
1426 want
= (*b
& ((xfs_rtword_t
)1 << bit
)) ? -1 : 0;
1428 * If the starting position is not word-aligned, deal with the
1433 * Calculate last (rightmost) bit number to look at,
1434 * and mask for all the relevant bits in this word.
1436 lastbit
= XFS_RTMIN(bit
+ len
, XFS_NBWORD
);
1437 mask
= (((xfs_rtword_t
)1 << (lastbit
- bit
)) - 1) << bit
;
1439 * Calculate the difference between the value there
1440 * and what we're looking for.
1442 if ((wdiff
= (*b
^ want
) & mask
)) {
1444 * Different. Mark where we are and return.
1446 xfs_trans_brelse(tp
, bp
);
1447 i
= XFS_RTLOBIT(wdiff
) - bit
;
1448 *rtblock
= start
+ i
- 1;
1453 * Go on to next block if that's where the next word is
1454 * and we need the next word.
1456 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
1458 * If done with this block, get the previous one.
1460 xfs_trans_brelse(tp
, bp
);
1461 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
1465 b
= bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1469 * Go on to the previous word in the buffer.
1475 * Starting on a word boundary, no partial word.
1480 * Loop over whole words in buffers. When we use up one buffer
1481 * we move on to the next one.
1483 while (len
- i
>= XFS_NBWORD
) {
1485 * Compute difference between actual and desired value.
1487 if ((wdiff
= *b
^ want
)) {
1489 * Different, mark where we are and return.
1491 xfs_trans_brelse(tp
, bp
);
1492 i
+= XFS_RTLOBIT(wdiff
);
1493 *rtblock
= start
+ i
- 1;
1498 * Go on to next block if that's where the next word is
1499 * and we need the next word.
1501 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
1503 * If done with this block, get the next one.
1505 xfs_trans_brelse(tp
, bp
);
1506 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
1510 b
= bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1514 * Go on to the next word in the buffer.
1520 * If not ending on a word boundary, deal with the last
1523 if ((lastbit
= len
- i
)) {
1525 * Calculate mask for all the relevant bits in this word.
1527 mask
= ((xfs_rtword_t
)1 << lastbit
) - 1;
1529 * Compute difference between actual and desired value.
1531 if ((wdiff
= (*b
^ want
) & mask
)) {
1533 * Different, mark where we are and return.
1535 xfs_trans_brelse(tp
, bp
);
1536 i
+= XFS_RTLOBIT(wdiff
);
1537 *rtblock
= start
+ i
- 1;
1543 * No match, return that we scanned the whole area.
1545 xfs_trans_brelse(tp
, bp
);
1546 *rtblock
= start
+ i
- 1;
1551 * Mark an extent specified by start and len freed.
1552 * Updates all the summary information as well as the bitmap.
1554 STATIC
int /* error */
1556 xfs_mount_t
*mp
, /* file system mount point */
1557 xfs_trans_t
*tp
, /* transaction pointer */
1558 xfs_rtblock_t start
, /* starting block to free */
1559 xfs_extlen_t len
, /* length to free */
1560 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
1561 xfs_fsblock_t
*rsb
) /* in/out: summary block number */
1563 xfs_rtblock_t end
; /* end of the freed extent */
1564 int error
; /* error value */
1565 xfs_rtblock_t postblock
; /* first block freed > end */
1566 xfs_rtblock_t preblock
; /* first block freed < start */
1568 end
= start
+ len
- 1;
1570 * Modify the bitmap to mark this extent freed.
1572 error
= xfs_rtmodify_range(mp
, tp
, start
, len
, 1);
1577 * Assume we're freeing out of the middle of an allocated extent.
1578 * We need to find the beginning and end of the extent so we can
1579 * properly update the summary.
1581 error
= xfs_rtfind_back(mp
, tp
, start
, 0, &preblock
);
1586 * Find the next allocated block (end of allocated extent).
1588 error
= xfs_rtfind_forw(mp
, tp
, end
, mp
->m_sb
.sb_rextents
- 1,
1591 * If there are blocks not being freed at the front of the
1592 * old extent, add summary data for them to be allocated.
1594 if (preblock
< start
) {
1595 error
= xfs_rtmodify_summary(mp
, tp
,
1596 XFS_RTBLOCKLOG(start
- preblock
),
1597 XFS_BITTOBLOCK(mp
, preblock
), -1, rbpp
, rsb
);
1603 * If there are blocks not being freed at the end of the
1604 * old extent, add summary data for them to be allocated.
1606 if (postblock
> end
) {
1607 error
= xfs_rtmodify_summary(mp
, tp
,
1608 XFS_RTBLOCKLOG(postblock
- end
),
1609 XFS_BITTOBLOCK(mp
, end
+ 1), -1, rbpp
, rsb
);
1615 * Increment the summary information corresponding to the entire
1616 * (new) free extent.
1618 error
= xfs_rtmodify_summary(mp
, tp
,
1619 XFS_RTBLOCKLOG(postblock
+ 1 - preblock
),
1620 XFS_BITTOBLOCK(mp
, preblock
), 1, rbpp
, rsb
);
1625 * Read and return the summary information for a given extent size,
1626 * bitmap block combination.
1627 * Keeps track of a current summary block, so we don't keep reading
1628 * it from the buffer cache.
1630 STATIC
int /* error */
1632 xfs_mount_t
*mp
, /* file system mount structure */
1633 xfs_trans_t
*tp
, /* transaction pointer */
1634 int log
, /* log2 of extent size */
1635 xfs_rtblock_t bbno
, /* bitmap block number */
1636 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
1637 xfs_fsblock_t
*rsb
, /* in/out: summary block number */
1638 xfs_suminfo_t
*sum
) /* out: summary info for this block */
1640 xfs_buf_t
*bp
; /* buffer for summary block */
1641 int error
; /* error value */
1642 xfs_fsblock_t sb
; /* summary fsblock */
1643 int so
; /* index into the summary file */
1644 xfs_suminfo_t
*sp
; /* pointer to returned data */
1647 * Compute entry number in the summary file.
1649 so
= XFS_SUMOFFS(mp
, log
, bbno
);
1651 * Compute the block number in the summary file.
1653 sb
= XFS_SUMOFFSTOBLOCK(mp
, so
);
1655 * If we have an old buffer, and the block number matches, use that.
1657 if (rbpp
&& *rbpp
&& *rsb
== sb
)
1660 * Otherwise we have to get the buffer.
1664 * If there was an old one, get rid of it first.
1667 xfs_trans_brelse(tp
, *rbpp
);
1668 error
= xfs_rtbuf_get(mp
, tp
, sb
, 1, &bp
);
1673 * Remember this buffer and block for the next call.
1681 * Point to the summary information & copy it out.
1683 sp
= XFS_SUMPTR(mp
, bp
, so
);
1686 * Drop the buffer if we're not asked to remember it.
1689 xfs_trans_brelse(tp
, bp
);
1694 * Set the given range of bitmap bits to the given value.
1695 * Do whatever I/O and logging is required.
1697 STATIC
int /* error */
1699 xfs_mount_t
*mp
, /* file system mount point */
1700 xfs_trans_t
*tp
, /* transaction pointer */
1701 xfs_rtblock_t start
, /* starting block to modify */
1702 xfs_extlen_t len
, /* length of extent to modify */
1703 int val
) /* 1 for free, 0 for allocated */
1705 xfs_rtword_t
*b
; /* current word in buffer */
1706 int bit
; /* bit number in the word */
1707 xfs_rtblock_t block
; /* bitmap block number */
1708 xfs_buf_t
*bp
; /* buf for the block */
1709 xfs_rtword_t
*bufp
; /* starting word in buffer */
1710 int error
; /* error value */
1711 xfs_rtword_t
*first
; /* first used word in the buffer */
1712 int i
; /* current bit number rel. to start */
1713 int lastbit
; /* last useful bit in word */
1714 xfs_rtword_t mask
; /* mask o frelevant bits for value */
1715 int word
; /* word number in the buffer */
1718 * Compute starting bitmap block number.
1720 block
= XFS_BITTOBLOCK(mp
, start
);
1722 * Read the bitmap block, and point to its data.
1724 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
1728 bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1730 * Compute the starting word's address, and starting bit.
1732 word
= XFS_BITTOWORD(mp
, start
);
1733 first
= b
= &bufp
[word
];
1734 bit
= (int)(start
& (XFS_NBWORD
- 1));
1736 * 0 (allocated) => all zeroes; 1 (free) => all ones.
1740 * If not starting on a word boundary, deal with the first
1745 * Compute first bit not changed and mask of relevant bits.
1747 lastbit
= XFS_RTMIN(bit
+ len
, XFS_NBWORD
);
1748 mask
= (((xfs_rtword_t
)1 << (lastbit
- bit
)) - 1) << bit
;
1750 * Set/clear the active bits.
1758 * Go on to the next block if that's where the next word is
1759 * and we need the next word.
1761 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
1763 * Log the changed part of this block.
1766 xfs_trans_log_buf(tp
, bp
,
1767 (uint
)((char *)first
- (char *)bufp
),
1768 (uint
)((char *)b
- (char *)bufp
));
1769 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
1773 first
= b
= bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1777 * Go on to the next word in the buffer
1783 * Starting on a word boundary, no partial word.
1788 * Loop over whole words in buffers. When we use up one buffer
1789 * we move on to the next one.
1791 while (len
- i
>= XFS_NBWORD
) {
1793 * Set the word value correctly.
1798 * Go on to the next block if that's where the next word is
1799 * and we need the next word.
1801 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
1803 * Log the changed part of this block.
1806 xfs_trans_log_buf(tp
, bp
,
1807 (uint
)((char *)first
- (char *)bufp
),
1808 (uint
)((char *)b
- (char *)bufp
));
1809 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
1813 first
= b
= bufp
= (xfs_rtword_t
*)XFS_BUF_PTR(bp
);
1817 * Go on to the next word in the buffer
1823 * If not ending on a word boundary, deal with the last
1826 if ((lastbit
= len
- i
)) {
1828 * Compute a mask of relevant bits.
1831 mask
= ((xfs_rtword_t
)1 << lastbit
) - 1;
1833 * Set/clear the active bits.
1842 * Log any remaining changed bytes.
1845 xfs_trans_log_buf(tp
, bp
, (uint
)((char *)first
- (char *)bufp
),
1846 (uint
)((char *)b
- (char *)bufp
- 1));
1851 * Read and modify the summary information for a given extent size,
1852 * bitmap block combination.
1853 * Keeps track of a current summary block, so we don't keep reading
1854 * it from the buffer cache.
1856 STATIC
int /* error */
1857 xfs_rtmodify_summary(
1858 xfs_mount_t
*mp
, /* file system mount point */
1859 xfs_trans_t
*tp
, /* transaction pointer */
1860 int log
, /* log2 of extent size */
1861 xfs_rtblock_t bbno
, /* bitmap block number */
1862 int delta
, /* change to make to summary info */
1863 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
1864 xfs_fsblock_t
*rsb
) /* in/out: summary block number */
1866 xfs_buf_t
*bp
; /* buffer for the summary block */
1867 int error
; /* error value */
1868 xfs_fsblock_t sb
; /* summary fsblock */
1869 int so
; /* index into the summary file */
1870 xfs_suminfo_t
*sp
; /* pointer to returned data */
1873 * Compute entry number in the summary file.
1875 so
= XFS_SUMOFFS(mp
, log
, bbno
);
1877 * Compute the block number in the summary file.
1879 sb
= XFS_SUMOFFSTOBLOCK(mp
, so
);
1881 * If we have an old buffer, and the block number matches, use that.
1883 if (rbpp
&& *rbpp
&& *rsb
== sb
)
1886 * Otherwise we have to get the buffer.
1890 * If there was an old one, get rid of it first.
1893 xfs_trans_brelse(tp
, *rbpp
);
1894 error
= xfs_rtbuf_get(mp
, tp
, sb
, 1, &bp
);
1899 * Remember this buffer and block for the next call.
1907 * Point to the summary information, modify and log it.
1909 sp
= XFS_SUMPTR(mp
, bp
, so
);
1911 xfs_trans_log_buf(tp
, bp
, (uint
)((char *)sp
- (char *)XFS_BUF_PTR(bp
)),
1912 (uint
)((char *)sp
- (char *)XFS_BUF_PTR(bp
) + sizeof(*sp
) - 1));
1917 * Visible (exported) functions.
1921 * Grow the realtime area of the filesystem.
1925 xfs_mount_t
*mp
, /* mount point for filesystem */
1926 xfs_growfs_rt_t
*in
) /* growfs rt input struct */
1928 xfs_rtblock_t bmbno
; /* bitmap block number */
1929 xfs_buf_t
*bp
; /* temporary buffer */
1930 int cancelflags
; /* flags for xfs_trans_cancel */
1931 int error
; /* error return value */
1932 xfs_inode_t
*ip
; /* bitmap inode, used as lock */
1933 xfs_mount_t
*nmp
; /* new (fake) mount structure */
1934 xfs_drfsbno_t nrblocks
; /* new number of realtime blocks */
1935 xfs_extlen_t nrbmblocks
; /* new number of rt bitmap blocks */
1936 xfs_drtbno_t nrextents
; /* new number of realtime extents */
1937 uint8_t nrextslog
; /* new log2 of sb_rextents */
1938 xfs_extlen_t nrsumblocks
; /* new number of summary blocks */
1939 uint nrsumlevels
; /* new rt summary levels */
1940 uint nrsumsize
; /* new size of rt summary, bytes */
1941 xfs_sb_t
*nsbp
; /* new superblock */
1942 xfs_extlen_t rbmblocks
; /* current number of rt bitmap blocks */
1943 xfs_extlen_t rsumblocks
; /* current number of rt summary blks */
1944 xfs_sb_t
*sbp
; /* old superblock */
1945 xfs_fsblock_t sumbno
; /* summary block number */
1946 xfs_trans_t
*tp
; /* transaction pointer */
1950 * Initial error checking.
1952 if (mp
->m_rtdev_targp
|| mp
->m_rbmip
== NULL
||
1953 (nrblocks
= in
->newblocks
) <= sbp
->sb_rblocks
||
1954 (sbp
->sb_rblocks
&& (in
->extsize
!= sbp
->sb_rextsize
)))
1955 return XFS_ERROR(EINVAL
);
1957 * Read in the last block of the device, make sure it exists.
1959 error
= xfs_read_buf(mp
, mp
->m_rtdev_targp
,
1960 XFS_FSB_TO_BB(mp
, in
->newblocks
- 1),
1961 XFS_FSB_TO_BB(mp
, 1), 0, &bp
);
1967 * Calculate new parameters. These are the final values to be reached.
1969 nrextents
= nrblocks
;
1970 do_div(nrextents
, in
->extsize
);
1971 nrbmblocks
= roundup_64(nrextents
, NBBY
* sbp
->sb_blocksize
);
1972 nrextslog
= xfs_highbit32(nrextents
);
1973 nrsumlevels
= nrextslog
+ 1;
1974 nrsumsize
= (uint
)sizeof(xfs_suminfo_t
) * nrsumlevels
* nrbmblocks
;
1975 nrsumblocks
= XFS_B_TO_FSB(mp
, nrsumsize
);
1976 nrsumsize
= XFS_FSB_TO_B(mp
, nrsumblocks
);
1978 * New summary size can't be more than half the size of
1979 * the log. This prevents us from getting a log overflow,
1980 * since we'll log basically the whole summary file at once.
1982 if (nrsumblocks
> (mp
->m_sb
.sb_logblocks
>> 1))
1983 return XFS_ERROR(EINVAL
);
1985 * Get the old block counts for bitmap and summary inodes.
1986 * These can't change since other growfs callers are locked out.
1988 rbmblocks
= XFS_B_TO_FSB(mp
, mp
->m_rbmip
->i_d
.di_size
);
1989 rsumblocks
= XFS_B_TO_FSB(mp
, mp
->m_rsumip
->i_d
.di_size
);
1991 * Allocate space to the bitmap and summary files, as necessary.
1993 if ((error
= xfs_growfs_rt_alloc(mp
, rbmblocks
, nrbmblocks
,
1994 mp
->m_sb
.sb_rbmino
)))
1996 if ((error
= xfs_growfs_rt_alloc(mp
, rsumblocks
, nrsumblocks
,
1997 mp
->m_sb
.sb_rsumino
)))
2001 * Loop over the bitmap blocks.
2002 * We will do everything one bitmap block at a time.
2003 * Skip the current block if it is exactly full.
2004 * This also deals with the case where there were no rtextents before.
2006 for (bmbno
= sbp
->sb_rbmblocks
-
2007 ((sbp
->sb_rextents
& ((1 << mp
->m_blkbit_log
) - 1)) != 0);
2011 * Allocate a new (fake) mount/sb.
2013 nmp
= kmem_alloc(sizeof(*nmp
), KM_SLEEP
);
2017 * Calculate new sb and mount fields for this round.
2019 nsbp
->sb_rextsize
= in
->extsize
;
2020 nsbp
->sb_rbmblocks
= bmbno
+ 1;
2023 nsbp
->sb_rbmblocks
* NBBY
*
2024 nsbp
->sb_blocksize
* nsbp
->sb_rextsize
);
2025 nsbp
->sb_rextents
= nsbp
->sb_rblocks
;
2026 do_div(nsbp
->sb_rextents
, nsbp
->sb_rextsize
);
2027 nsbp
->sb_rextslog
= xfs_highbit32(nsbp
->sb_rextents
);
2028 nrsumlevels
= nmp
->m_rsumlevels
= nsbp
->sb_rextslog
+ 1;
2030 (uint
)sizeof(xfs_suminfo_t
) * nrsumlevels
*
2032 nrsumblocks
= XFS_B_TO_FSB(mp
, nrsumsize
);
2033 nmp
->m_rsumsize
= nrsumsize
= XFS_FSB_TO_B(mp
, nrsumblocks
);
2035 * Start a transaction, get the log reservation.
2037 tp
= xfs_trans_alloc(mp
, XFS_TRANS_GROWFSRT_FREE
);
2039 if ((error
= xfs_trans_reserve(tp
, 0,
2040 XFS_GROWRTFREE_LOG_RES(nmp
), 0, 0, 0)))
2043 * Lock out other callers by grabbing the bitmap inode lock.
2045 if ((error
= xfs_trans_iget(mp
, tp
, 0, mp
->m_sb
.sb_rbmino
,
2046 XFS_ILOCK_EXCL
, &ip
)))
2048 ASSERT(ip
== mp
->m_rbmip
);
2050 * Update the bitmap inode's size.
2052 mp
->m_rbmip
->i_d
.di_size
=
2053 nsbp
->sb_rbmblocks
* nsbp
->sb_blocksize
;
2054 xfs_trans_log_inode(tp
, mp
->m_rbmip
, XFS_ILOG_CORE
);
2055 cancelflags
|= XFS_TRANS_ABORT
;
2057 * Get the summary inode into the transaction.
2059 if ((error
= xfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
,
2060 0, XFS_ILOCK_EXCL
, &ip
)))
2062 ASSERT(ip
== mp
->m_rsumip
);
2064 * Update the summary inode's size.
2066 mp
->m_rsumip
->i_d
.di_size
= nmp
->m_rsumsize
;
2067 xfs_trans_log_inode(tp
, mp
->m_rsumip
, XFS_ILOG_CORE
);
2069 * Copy summary data from old to new sizes.
2070 * Do this when the real size (not block-aligned) changes.
2072 if (sbp
->sb_rbmblocks
!= nsbp
->sb_rbmblocks
||
2073 mp
->m_rsumlevels
!= nmp
->m_rsumlevels
) {
2074 error
= xfs_rtcopy_summary(mp
, nmp
, tp
);
2079 * Update superblock fields.
2081 if (nsbp
->sb_rextsize
!= sbp
->sb_rextsize
)
2082 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_REXTSIZE
,
2083 nsbp
->sb_rextsize
- sbp
->sb_rextsize
);
2084 if (nsbp
->sb_rbmblocks
!= sbp
->sb_rbmblocks
)
2085 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_RBMBLOCKS
,
2086 nsbp
->sb_rbmblocks
- sbp
->sb_rbmblocks
);
2087 if (nsbp
->sb_rblocks
!= sbp
->sb_rblocks
)
2088 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_RBLOCKS
,
2089 nsbp
->sb_rblocks
- sbp
->sb_rblocks
);
2090 if (nsbp
->sb_rextents
!= sbp
->sb_rextents
)
2091 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_REXTENTS
,
2092 nsbp
->sb_rextents
- sbp
->sb_rextents
);
2093 if (nsbp
->sb_rextslog
!= sbp
->sb_rextslog
)
2094 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_REXTSLOG
,
2095 nsbp
->sb_rextslog
- sbp
->sb_rextslog
);
2100 error
= xfs_rtfree_range(nmp
, tp
, sbp
->sb_rextents
,
2101 nsbp
->sb_rextents
- sbp
->sb_rextents
, &bp
, &sumbno
);
2105 * Mark more blocks free in the superblock.
2107 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_FREXTENTS
,
2108 nsbp
->sb_rextents
- sbp
->sb_rextents
);
2110 * Free the fake mp structure.
2112 kmem_free(nmp
, sizeof(*nmp
));
2115 * Update mp values into the real mp structure.
2117 mp
->m_rsumlevels
= nrsumlevels
;
2118 mp
->m_rsumsize
= nrsumsize
;
2120 * Commit the transaction.
2122 xfs_trans_commit(tp
, 0, NULL
);
2127 * Error paths come here.
2131 kmem_free(nmp
, sizeof(*nmp
));
2132 xfs_trans_cancel(tp
, cancelflags
);
2137 * Allocate an extent in the realtime subvolume, with the usual allocation
2138 * parameters. The length units are all in realtime extents, as is the
2139 * result block number.
2142 xfs_rtallocate_extent(
2143 xfs_trans_t
*tp
, /* transaction pointer */
2144 xfs_rtblock_t bno
, /* starting block number to allocate */
2145 xfs_extlen_t minlen
, /* minimum length to allocate */
2146 xfs_extlen_t maxlen
, /* maximum length to allocate */
2147 xfs_extlen_t
*len
, /* out: actual length allocated */
2148 xfs_alloctype_t type
, /* allocation type XFS_ALLOCTYPE... */
2149 int wasdel
, /* was a delayed allocation extent */
2150 xfs_extlen_t prod
, /* extent product factor */
2151 xfs_rtblock_t
*rtblock
) /* out: start block allocated */
2153 int error
; /* error value */
2154 xfs_inode_t
*ip
; /* inode for bitmap file */
2155 xfs_mount_t
*mp
; /* file system mount structure */
2156 xfs_rtblock_t r
; /* result allocated block */
2157 xfs_fsblock_t sb
; /* summary file block number */
2158 xfs_buf_t
*sumbp
; /* summary file block buffer */
2160 ASSERT(minlen
> 0 && minlen
<= maxlen
);
2163 * If prod is set then figure out what to do to minlen and maxlen.
2168 if ((i
= maxlen
% prod
))
2170 if ((i
= minlen
% prod
))
2172 if (maxlen
< minlen
) {
2173 *rtblock
= NULLRTBLOCK
;
2178 * Lock out other callers by grabbing the bitmap inode lock.
2180 error
= xfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, XFS_ILOCK_EXCL
, &ip
);
2186 * Allocate by size, or near another block, or exactly at some block.
2189 case XFS_ALLOCTYPE_ANY_AG
:
2190 error
= xfs_rtallocate_extent_size(mp
, tp
, minlen
, maxlen
, len
,
2191 &sumbp
, &sb
, prod
, &r
);
2193 case XFS_ALLOCTYPE_NEAR_BNO
:
2194 error
= xfs_rtallocate_extent_near(mp
, tp
, bno
, minlen
, maxlen
,
2195 len
, &sumbp
, &sb
, prod
, &r
);
2197 case XFS_ALLOCTYPE_THIS_BNO
:
2198 error
= xfs_rtallocate_extent_exact(mp
, tp
, bno
, minlen
, maxlen
,
2199 len
, &sumbp
, &sb
, prod
, &r
);
2208 * If it worked, update the superblock.
2210 if (r
!= NULLRTBLOCK
) {
2211 long slen
= (long)*len
;
2213 ASSERT(*len
>= minlen
&& *len
<= maxlen
);
2215 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_RES_FREXTENTS
, -slen
);
2217 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_FREXTENTS
, -slen
);
2224 * Free an extent in the realtime subvolume. Length is expressed in
2225 * realtime extents, as is the block number.
2229 xfs_trans_t
*tp
, /* transaction pointer */
2230 xfs_rtblock_t bno
, /* starting block number to free */
2231 xfs_extlen_t len
) /* length of extent freed */
2233 int error
; /* error value */
2234 xfs_inode_t
*ip
; /* bitmap file inode */
2235 xfs_mount_t
*mp
; /* file system mount structure */
2236 xfs_fsblock_t sb
; /* summary file block number */
2237 xfs_buf_t
*sumbp
; /* summary file block buffer */
2241 * Synchronize by locking the bitmap inode.
2243 error
= xfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, XFS_ILOCK_EXCL
, &ip
);
2247 #if defined(__KERNEL__) && defined(DEBUG)
2249 * Check to see that this whole range is currently allocated.
2252 int stat
; /* result from checking range */
2254 error
= xfs_rtcheck_alloc_range(mp
, tp
, bno
, len
, &stat
);
2263 * Free the range of realtime blocks.
2265 error
= xfs_rtfree_range(mp
, tp
, bno
, len
, &sumbp
, &sb
);
2270 * Mark more blocks free in the superblock.
2272 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_FREXTENTS
, (long)len
);
2274 * If we've now freed all the blocks, reset the file sequence
2277 if (tp
->t_frextents_delta
+ mp
->m_sb
.sb_frextents
==
2278 mp
->m_sb
.sb_rextents
) {
2279 if (!(ip
->i_d
.di_flags
& XFS_DIFLAG_NEWRTBM
))
2280 ip
->i_d
.di_flags
|= XFS_DIFLAG_NEWRTBM
;
2281 *(__uint64_t
*)&ip
->i_d
.di_atime
= 0;
2282 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
2288 * Initialize realtime fields in the mount structure.
2292 xfs_mount_t
*mp
) /* file system mount structure */
2294 xfs_buf_t
*bp
; /* buffer for last block of subvolume */
2295 xfs_daddr_t d
; /* address of last block of subvolume */
2296 int error
; /* error return value */
2297 xfs_sb_t
*sbp
; /* filesystem superblock copy in mount */
2300 if (sbp
->sb_rblocks
== 0)
2302 if (mp
->m_rtdev_targp
== NULL
) {
2304 "XFS: This filesystem has a realtime volume, use rtdev=device option");
2305 return XFS_ERROR(ENODEV
);
2307 mp
->m_rsumlevels
= sbp
->sb_rextslog
+ 1;
2309 (uint
)sizeof(xfs_suminfo_t
) * mp
->m_rsumlevels
*
2311 mp
->m_rsumsize
= roundup(mp
->m_rsumsize
, sbp
->sb_blocksize
);
2312 mp
->m_rbmip
= mp
->m_rsumip
= NULL
;
2314 * Check that the realtime section is an ok size.
2316 d
= (xfs_daddr_t
)XFS_FSB_TO_BB(mp
, mp
->m_sb
.sb_rblocks
);
2317 if (XFS_BB_TO_FSB(mp
, d
) != mp
->m_sb
.sb_rblocks
) {
2318 cmn_err(CE_WARN
, "XFS: realtime mount -- %llu != %llu",
2319 (unsigned long long) XFS_BB_TO_FSB(mp
, d
),
2320 (unsigned long long) mp
->m_sb
.sb_rblocks
);
2321 return XFS_ERROR(E2BIG
);
2323 error
= xfs_read_buf(mp
, mp
->m_rtdev_targp
,
2324 d
- XFS_FSB_TO_BB(mp
, 1),
2325 XFS_FSB_TO_BB(mp
, 1), 0, &bp
);
2328 "XFS: realtime mount -- xfs_read_buf failed, returned %d", error
);
2329 if (error
== ENOSPC
)
2330 return XFS_ERROR(E2BIG
);
2338 * Get the bitmap and summary inodes into the mount structure
2343 xfs_mount_t
*mp
) /* file system mount structure */
2345 int error
; /* error return value */
2349 if (sbp
->sb_rbmino
== NULLFSINO
)
2351 error
= xfs_iget(mp
, NULL
, sbp
->sb_rbmino
, 0, 0, &mp
->m_rbmip
, 0);
2354 ASSERT(mp
->m_rbmip
!= NULL
);
2355 ASSERT(sbp
->sb_rsumino
!= NULLFSINO
);
2356 error
= xfs_iget(mp
, NULL
, sbp
->sb_rsumino
, 0, 0, &mp
->m_rsumip
, 0);
2358 VN_RELE(XFS_ITOV(mp
->m_rbmip
));
2361 ASSERT(mp
->m_rsumip
!= NULL
);
2366 * Pick an extent for allocation at the start of a new realtime file.
2367 * Use the sequence number stored in the atime field of the bitmap inode.
2368 * Translate this to a fraction of the rtextents, and return the product
2369 * of rtextents and the fraction.
2370 * The fraction sequence is 0, 1/2, 1/4, 3/4, 1/8, ..., 7/8, 1/16, ...
2374 xfs_mount_t
*mp
, /* file system mount point */
2375 xfs_trans_t
*tp
, /* transaction pointer */
2376 xfs_extlen_t len
, /* allocation length (rtextents) */
2377 xfs_rtblock_t
*pick
) /* result rt extent */
2379 xfs_rtblock_t b
; /* result block */
2380 int error
; /* error return value */
2381 xfs_inode_t
*ip
; /* bitmap incore inode */
2382 int log2
; /* log of sequence number */
2383 __uint64_t resid
; /* residual after log removed */
2384 __uint64_t seq
; /* sequence number of file creation */
2385 __uint64_t
*seqp
; /* pointer to seqno in inode */
2387 error
= xfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, XFS_ILOCK_EXCL
, &ip
);
2390 ASSERT(ip
== mp
->m_rbmip
);
2391 seqp
= (__uint64_t
*)&ip
->i_d
.di_atime
;
2392 if (!(ip
->i_d
.di_flags
& XFS_DIFLAG_NEWRTBM
)) {
2393 ip
->i_d
.di_flags
|= XFS_DIFLAG_NEWRTBM
;
2397 if ((log2
= xfs_highbit64(seq
)) == -1)
2400 resid
= seq
- (1ULL << log2
);
2401 b
= (mp
->m_sb
.sb_rextents
* ((resid
<< 1) + 1ULL)) >>
2403 if (b
>= mp
->m_sb
.sb_rextents
)
2404 b
= do_mod(b
, mp
->m_sb
.sb_rextents
);
2405 if (b
+ len
> mp
->m_sb
.sb_rextents
)
2406 b
= mp
->m_sb
.sb_rextents
- len
;
2409 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
2416 * Debug code: print out the value of a range in the bitmap.
2420 xfs_mount_t
*mp
, /* file system mount structure */
2421 xfs_trans_t
*tp
, /* transaction pointer */
2422 xfs_rtblock_t start
, /* starting block to print */
2423 xfs_extlen_t len
) /* length to print */
2425 xfs_extlen_t i
; /* block number in the extent */
2427 printk("%Ld: ", (long long)start
);
2428 for (i
= 0; i
< len
; i
++)
2429 printk("%d", xfs_rtcheck_bit(mp
, tp
, start
+ i
, 1));
2434 * Debug code: print the summary file.
2437 xfs_rtprint_summary(
2438 xfs_mount_t
*mp
, /* file system mount structure */
2439 xfs_trans_t
*tp
) /* transaction pointer */
2441 xfs_suminfo_t c
; /* summary data */
2442 xfs_rtblock_t i
; /* bitmap block number */
2443 int l
; /* summary information level */
2444 int p
; /* flag for printed anything */
2445 xfs_fsblock_t sb
; /* summary block number */
2446 xfs_buf_t
*sumbp
; /* summary block buffer */
2449 for (l
= 0; l
< mp
->m_rsumlevels
; l
++) {
2450 for (p
= 0, i
= 0; i
< mp
->m_sb
.sb_rbmblocks
; i
++) {
2451 (void)xfs_rtget_summary(mp
, tp
, l
, i
, &sumbp
, &sb
, &c
);
2454 printk("%Ld-%Ld:", 1LL << l
,
2455 XFS_RTMIN((1LL << l
) +
2457 mp
->m_sb
.sb_rextents
));
2460 printk(" %Ld:%d", (long long)i
, c
);
2467 xfs_trans_brelse(tp
, sumbp
);