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_inode.h"
16 #include "xfs_bmap_util.h"
17 #include "xfs_bmap_btree.h"
18 #include "xfs_alloc.h"
19 #include "xfs_error.h"
20 #include "xfs_trans.h"
21 #include "xfs_trans_space.h"
22 #include "xfs_trace.h"
24 #include "xfs_icache.h"
25 #include "xfs_rtalloc.h"
29 * Realtime allocator bitmap functions shared with userspace.
33 * Real time buffers need verifiers to avoid runtime warnings during IO.
34 * We don't have anything to verify, however, so these are just dummy
38 xfs_rtbuf_verify_read(
45 xfs_rtbuf_verify_write(
51 const struct xfs_buf_ops xfs_rtbuf_ops = {
53 .verify_read = xfs_rtbuf_verify_read,
54 .verify_write = xfs_rtbuf_verify_write,
58 * Get a buffer for the bitmap or summary file block specified.
59 * The buffer is returned read and locked.
63 xfs_mount_t *mp, /* file system mount structure */
64 xfs_trans_t *tp, /* transaction pointer */
65 xfs_rtblock_t block, /* block number in bitmap or summary */
66 int issum, /* is summary not bitmap */
67 xfs_buf_t **bpp) /* output: buffer for the block */
69 xfs_buf_t *bp; /* block buffer, result */
70 xfs_inode_t *ip; /* bitmap or summary inode */
73 int error; /* error value */
75 ip = issum ? mp->m_rsumip : mp->m_rbmip;
77 error = xfs_bmapi_read(ip, block, 1, &map, &nmap, XFS_DATA_FORK);
81 if (nmap == 0 || !xfs_bmap_is_real_extent(&map))
84 ASSERT(map.br_startblock != NULLFSBLOCK);
85 error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
86 XFS_FSB_TO_DADDR(mp, map.br_startblock),
87 mp->m_bsize, 0, &bp, &xfs_rtbuf_ops);
91 xfs_trans_buf_set_type(tp, bp, issum ? XFS_BLFT_RTSUMMARY_BUF
92 : XFS_BLFT_RTBITMAP_BUF);
98 * Searching backward from start to limit, find the first block whose
99 * allocated/free state is different from start's.
103 xfs_mount_t *mp, /* file system mount point */
104 xfs_trans_t *tp, /* transaction pointer */
105 xfs_rtblock_t start, /* starting block to look at */
106 xfs_rtblock_t limit, /* last block to look at */
107 xfs_rtblock_t *rtblock) /* out: start block found */
109 xfs_rtword_t *b; /* current word in buffer */
110 int bit; /* bit number in the word */
111 xfs_rtblock_t block; /* bitmap block number */
112 xfs_buf_t *bp; /* buf for the block */
113 xfs_rtword_t *bufp; /* starting word in buffer */
114 int error; /* error value */
115 xfs_rtblock_t firstbit; /* first useful bit in the word */
116 xfs_rtblock_t i; /* current bit number rel. to start */
117 xfs_rtblock_t len; /* length of inspected area */
118 xfs_rtword_t mask; /* mask of relevant bits for value */
119 xfs_rtword_t want; /* mask for "good" values */
120 xfs_rtword_t wdiff; /* difference from wanted value */
121 int word; /* word number in the buffer */
124 * Compute and read in starting bitmap block for starting block.
126 block = XFS_BITTOBLOCK(mp, start);
127 error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
133 * Get the first word's index & point to it.
135 word = XFS_BITTOWORD(mp, start);
137 bit = (int)(start & (XFS_NBWORD - 1));
138 len = start - limit + 1;
140 * Compute match value, based on the bit at start: if 1 (free)
141 * then all-ones, else all-zeroes.
143 want = (*b & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
145 * If the starting position is not word-aligned, deal with the
148 if (bit < XFS_NBWORD - 1) {
150 * Calculate first (leftmost) bit number to look at,
151 * and mask for all the relevant bits in this word.
153 firstbit = XFS_RTMAX((xfs_srtblock_t)(bit - len + 1), 0);
154 mask = (((xfs_rtword_t)1 << (bit - firstbit + 1)) - 1) <<
157 * Calculate the difference between the value there
158 * and what we're looking for.
160 if ((wdiff = (*b ^ want) & mask)) {
162 * Different. Mark where we are and return.
164 xfs_trans_brelse(tp, bp);
165 i = bit - XFS_RTHIBIT(wdiff);
166 *rtblock = start - i + 1;
169 i = bit - firstbit + 1;
171 * Go on to previous block if that's where the previous word is
172 * and we need the previous word.
174 if (--word == -1 && i < len) {
176 * If done with this block, get the previous one.
178 xfs_trans_brelse(tp, bp);
179 error = xfs_rtbuf_get(mp, tp, --block, 0, &bp);
184 word = XFS_BLOCKWMASK(mp);
188 * Go on to the previous word in the buffer.
194 * Starting on a word boundary, no partial word.
199 * Loop over whole words in buffers. When we use up one buffer
200 * we move on to the previous one.
202 while (len - i >= XFS_NBWORD) {
204 * Compute difference between actual and desired value.
206 if ((wdiff = *b ^ want)) {
208 * Different, mark where we are and return.
210 xfs_trans_brelse(tp, bp);
211 i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
212 *rtblock = start - i + 1;
217 * Go on to previous block if that's where the previous word is
218 * and we need the previous word.
220 if (--word == -1 && i < len) {
222 * If done with this block, get the previous one.
224 xfs_trans_brelse(tp, bp);
225 error = xfs_rtbuf_get(mp, tp, --block, 0, &bp);
230 word = XFS_BLOCKWMASK(mp);
234 * Go on to the previous word in the buffer.
240 * If not ending on a word boundary, deal with the last
245 * Calculate first (leftmost) bit number to look at,
246 * and mask for all the relevant bits in this word.
248 firstbit = XFS_NBWORD - (len - i);
249 mask = (((xfs_rtword_t)1 << (len - i)) - 1) << firstbit;
251 * Compute difference between actual and desired value.
253 if ((wdiff = (*b ^ want) & mask)) {
255 * Different, mark where we are and return.
257 xfs_trans_brelse(tp, bp);
258 i += XFS_NBWORD - 1 - XFS_RTHIBIT(wdiff);
259 *rtblock = start - i + 1;
265 * No match, return that we scanned the whole area.
267 xfs_trans_brelse(tp, bp);
268 *rtblock = start - i + 1;
273 * Searching forward from start to limit, find the first block whose
274 * allocated/free state is different from start's.
278 xfs_mount_t *mp, /* file system mount point */
279 xfs_trans_t *tp, /* transaction pointer */
280 xfs_rtblock_t start, /* starting block to look at */
281 xfs_rtblock_t limit, /* last block to look at */
282 xfs_rtblock_t *rtblock) /* out: start block found */
284 xfs_rtword_t *b; /* current word in buffer */
285 int bit; /* bit number in the word */
286 xfs_rtblock_t block; /* bitmap block number */
287 xfs_buf_t *bp; /* buf for the block */
288 xfs_rtword_t *bufp; /* starting word in buffer */
289 int error; /* error value */
290 xfs_rtblock_t i; /* current bit number rel. to start */
291 xfs_rtblock_t lastbit; /* last useful bit in the word */
292 xfs_rtblock_t len; /* length of inspected area */
293 xfs_rtword_t mask; /* mask of relevant bits for value */
294 xfs_rtword_t want; /* mask for "good" values */
295 xfs_rtword_t wdiff; /* difference from wanted value */
296 int word; /* word number in the buffer */
299 * Compute and read in starting bitmap block for starting block.
301 block = XFS_BITTOBLOCK(mp, start);
302 error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
308 * Get the first word's index & point to it.
310 word = XFS_BITTOWORD(mp, start);
312 bit = (int)(start & (XFS_NBWORD - 1));
313 len = limit - start + 1;
315 * Compute match value, based on the bit at start: if 1 (free)
316 * then all-ones, else all-zeroes.
318 want = (*b & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
320 * If the starting position is not word-aligned, deal with the
325 * Calculate last (rightmost) bit number to look at,
326 * and mask for all the relevant bits in this word.
328 lastbit = XFS_RTMIN(bit + len, XFS_NBWORD);
329 mask = (((xfs_rtword_t)1 << (lastbit - bit)) - 1) << bit;
331 * Calculate the difference between the value there
332 * and what we're looking for.
334 if ((wdiff = (*b ^ want) & mask)) {
336 * Different. Mark where we are and return.
338 xfs_trans_brelse(tp, bp);
339 i = XFS_RTLOBIT(wdiff) - bit;
340 *rtblock = start + i - 1;
345 * Go on to next block if that's where the next word is
346 * and we need the next word.
348 if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
350 * If done with this block, get the previous one.
352 xfs_trans_brelse(tp, bp);
353 error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
357 b = bufp = bp->b_addr;
361 * Go on to the previous word in the buffer.
367 * Starting on a word boundary, no partial word.
372 * Loop over whole words in buffers. When we use up one buffer
373 * we move on to the next one.
375 while (len - i >= XFS_NBWORD) {
377 * Compute difference between actual and desired value.
379 if ((wdiff = *b ^ want)) {
381 * Different, mark where we are and return.
383 xfs_trans_brelse(tp, bp);
384 i += XFS_RTLOBIT(wdiff);
385 *rtblock = start + i - 1;
390 * Go on to next block if that's where the next word is
391 * and we need the next word.
393 if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
395 * If done with this block, get the next one.
397 xfs_trans_brelse(tp, bp);
398 error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
402 b = bufp = bp->b_addr;
406 * Go on to the next word in the buffer.
412 * If not ending on a word boundary, deal with the last
415 if ((lastbit = len - i)) {
417 * Calculate mask for all the relevant bits in this word.
419 mask = ((xfs_rtword_t)1 << lastbit) - 1;
421 * Compute difference between actual and desired value.
423 if ((wdiff = (*b ^ want) & mask)) {
425 * Different, mark where we are and return.
427 xfs_trans_brelse(tp, bp);
428 i += XFS_RTLOBIT(wdiff);
429 *rtblock = start + i - 1;
435 * No match, return that we scanned the whole area.
437 xfs_trans_brelse(tp, bp);
438 *rtblock = start + i - 1;
443 * Read and/or modify the summary information for a given extent size,
444 * bitmap block combination.
445 * Keeps track of a current summary block, so we don't keep reading
446 * it from the buffer cache.
448 * Summary information is returned in *sum if specified.
449 * If no delta is specified, returns summary only.
452 xfs_rtmodify_summary_int(
453 xfs_mount_t *mp, /* file system mount structure */
454 xfs_trans_t *tp, /* transaction pointer */
455 int log, /* log2 of extent size */
456 xfs_rtblock_t bbno, /* bitmap block number */
457 int delta, /* change to make to summary info */
458 xfs_buf_t **rbpp, /* in/out: summary block buffer */
459 xfs_fsblock_t *rsb, /* in/out: summary block number */
460 xfs_suminfo_t *sum) /* out: summary info for this block */
462 xfs_buf_t *bp; /* buffer for the summary block */
463 int error; /* error value */
464 xfs_fsblock_t sb; /* summary fsblock */
465 int so; /* index into the summary file */
466 xfs_suminfo_t *sp; /* pointer to returned data */
469 * Compute entry number in the summary file.
471 so = XFS_SUMOFFS(mp, log, bbno);
473 * Compute the block number in the summary file.
475 sb = XFS_SUMOFFSTOBLOCK(mp, so);
477 * If we have an old buffer, and the block number matches, use that.
479 if (*rbpp && *rsb == sb)
482 * Otherwise we have to get the buffer.
486 * If there was an old one, get rid of it first.
489 xfs_trans_brelse(tp, *rbpp);
490 error = xfs_rtbuf_get(mp, tp, sb, 1, &bp);
495 * Remember this buffer and block for the next call.
501 * Point to the summary information, modify/log it, and/or copy it out.
503 sp = XFS_SUMPTR(mp, bp, so);
505 uint first = (uint)((char *)sp - (char *)bp->b_addr);
508 if (mp->m_rsum_cache) {
509 if (*sp == 0 && log == mp->m_rsum_cache[bbno])
510 mp->m_rsum_cache[bbno]++;
511 if (*sp != 0 && log < mp->m_rsum_cache[bbno])
512 mp->m_rsum_cache[bbno] = log;
514 xfs_trans_log_buf(tp, bp, first, first + sizeof(*sp) - 1);
522 xfs_rtmodify_summary(
523 xfs_mount_t *mp, /* file system mount structure */
524 xfs_trans_t *tp, /* transaction pointer */
525 int log, /* log2 of extent size */
526 xfs_rtblock_t bbno, /* bitmap block number */
527 int delta, /* change to make to summary info */
528 xfs_buf_t **rbpp, /* in/out: summary block buffer */
529 xfs_fsblock_t *rsb) /* in/out: summary block number */
531 return xfs_rtmodify_summary_int(mp, tp, log, bbno,
532 delta, rbpp, rsb, NULL);
536 * Set the given range of bitmap bits to the given value.
537 * Do whatever I/O and logging is required.
541 xfs_mount_t *mp, /* file system mount point */
542 xfs_trans_t *tp, /* transaction pointer */
543 xfs_rtblock_t start, /* starting block to modify */
544 xfs_extlen_t len, /* length of extent to modify */
545 int val) /* 1 for free, 0 for allocated */
547 xfs_rtword_t *b; /* current word in buffer */
548 int bit; /* bit number in the word */
549 xfs_rtblock_t block; /* bitmap block number */
550 xfs_buf_t *bp; /* buf for the block */
551 xfs_rtword_t *bufp; /* starting word in buffer */
552 int error; /* error value */
553 xfs_rtword_t *first; /* first used word in the buffer */
554 int i; /* current bit number rel. to start */
555 int lastbit; /* last useful bit in word */
556 xfs_rtword_t mask; /* mask o frelevant bits for value */
557 int word; /* word number in the buffer */
560 * Compute starting bitmap block number.
562 block = XFS_BITTOBLOCK(mp, start);
564 * Read the bitmap block, and point to its data.
566 error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
572 * Compute the starting word's address, and starting bit.
574 word = XFS_BITTOWORD(mp, start);
575 first = b = &bufp[word];
576 bit = (int)(start & (XFS_NBWORD - 1));
578 * 0 (allocated) => all zeroes; 1 (free) => all ones.
582 * If not starting on a word boundary, deal with the first
587 * Compute first bit not changed and mask of relevant bits.
589 lastbit = XFS_RTMIN(bit + len, XFS_NBWORD);
590 mask = (((xfs_rtword_t)1 << (lastbit - bit)) - 1) << bit;
592 * Set/clear the active bits.
600 * Go on to the next block if that's where the next word is
601 * and we need the next word.
603 if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
605 * Log the changed part of this block.
608 xfs_trans_log_buf(tp, bp,
609 (uint)((char *)first - (char *)bufp),
610 (uint)((char *)b - (char *)bufp));
611 error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
615 first = b = bufp = bp->b_addr;
619 * Go on to the next word in the buffer
625 * Starting on a word boundary, no partial word.
630 * Loop over whole words in buffers. When we use up one buffer
631 * we move on to the next one.
633 while (len - i >= XFS_NBWORD) {
635 * Set the word value correctly.
640 * Go on to the next block if that's where the next word is
641 * and we need the next word.
643 if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
645 * Log the changed part of this block.
648 xfs_trans_log_buf(tp, bp,
649 (uint)((char *)first - (char *)bufp),
650 (uint)((char *)b - (char *)bufp));
651 error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
655 first = b = bufp = bp->b_addr;
659 * Go on to the next word in the buffer
665 * If not ending on a word boundary, deal with the last
668 if ((lastbit = len - i)) {
670 * Compute a mask of relevant bits.
672 mask = ((xfs_rtword_t)1 << lastbit) - 1;
674 * Set/clear the active bits.
683 * Log any remaining changed bytes.
686 xfs_trans_log_buf(tp, bp, (uint)((char *)first - (char *)bufp),
687 (uint)((char *)b - (char *)bufp - 1));
692 * Mark an extent specified by start and len freed.
693 * Updates all the summary information as well as the bitmap.
697 xfs_mount_t *mp, /* file system mount point */
698 xfs_trans_t *tp, /* transaction pointer */
699 xfs_rtblock_t start, /* starting block to free */
700 xfs_extlen_t len, /* length to free */
701 xfs_buf_t **rbpp, /* in/out: summary block buffer */
702 xfs_fsblock_t *rsb) /* in/out: summary block number */
704 xfs_rtblock_t end; /* end of the freed extent */
705 int error; /* error value */
706 xfs_rtblock_t postblock; /* first block freed > end */
707 xfs_rtblock_t preblock; /* first block freed < start */
709 end = start + len - 1;
711 * Modify the bitmap to mark this extent freed.
713 error = xfs_rtmodify_range(mp, tp, start, len, 1);
718 * Assume we're freeing out of the middle of an allocated extent.
719 * We need to find the beginning and end of the extent so we can
720 * properly update the summary.
722 error = xfs_rtfind_back(mp, tp, start, 0, &preblock);
727 * Find the next allocated block (end of allocated extent).
729 error = xfs_rtfind_forw(mp, tp, end, mp->m_sb.sb_rextents - 1,
734 * If there are blocks not being freed at the front of the
735 * old extent, add summary data for them to be allocated.
737 if (preblock < start) {
738 error = xfs_rtmodify_summary(mp, tp,
739 XFS_RTBLOCKLOG(start - preblock),
740 XFS_BITTOBLOCK(mp, preblock), -1, rbpp, rsb);
746 * If there are blocks not being freed at the end of the
747 * old extent, add summary data for them to be allocated.
749 if (postblock > end) {
750 error = xfs_rtmodify_summary(mp, tp,
751 XFS_RTBLOCKLOG(postblock - end),
752 XFS_BITTOBLOCK(mp, end + 1), -1, rbpp, rsb);
758 * Increment the summary information corresponding to the entire
761 error = xfs_rtmodify_summary(mp, tp,
762 XFS_RTBLOCKLOG(postblock + 1 - preblock),
763 XFS_BITTOBLOCK(mp, preblock), 1, rbpp, rsb);
768 * Check that the given range is either all allocated (val = 0) or
769 * all free (val = 1).
773 xfs_mount_t *mp, /* file system mount point */
774 xfs_trans_t *tp, /* transaction pointer */
775 xfs_rtblock_t start, /* starting block number of extent */
776 xfs_extlen_t len, /* length of extent */
777 int val, /* 1 for free, 0 for allocated */
778 xfs_rtblock_t *new, /* out: first block not matching */
779 int *stat) /* out: 1 for matches, 0 for not */
781 xfs_rtword_t *b; /* current word in buffer */
782 int bit; /* bit number in the word */
783 xfs_rtblock_t block; /* bitmap block number */
784 xfs_buf_t *bp; /* buf for the block */
785 xfs_rtword_t *bufp; /* starting word in buffer */
786 int error; /* error value */
787 xfs_rtblock_t i; /* current bit number rel. to start */
788 xfs_rtblock_t lastbit; /* last useful bit in word */
789 xfs_rtword_t mask; /* mask of relevant bits for value */
790 xfs_rtword_t wdiff; /* difference from wanted value */
791 int word; /* word number in the buffer */
794 * Compute starting bitmap block number
796 block = XFS_BITTOBLOCK(mp, start);
798 * Read the bitmap block.
800 error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
806 * Compute the starting word's address, and starting bit.
808 word = XFS_BITTOWORD(mp, start);
810 bit = (int)(start & (XFS_NBWORD - 1));
812 * 0 (allocated) => all zero's; 1 (free) => all one's.
816 * If not starting on a word boundary, deal with the first
821 * Compute first bit not examined.
823 lastbit = XFS_RTMIN(bit + len, XFS_NBWORD);
825 * Mask of relevant bits.
827 mask = (((xfs_rtword_t)1 << (lastbit - bit)) - 1) << bit;
829 * Compute difference between actual and desired value.
831 if ((wdiff = (*b ^ val) & mask)) {
833 * Different, compute first wrong bit and return.
835 xfs_trans_brelse(tp, bp);
836 i = XFS_RTLOBIT(wdiff) - bit;
843 * Go on to next block if that's where the next word is
844 * and we need the next word.
846 if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
848 * If done with this block, get the next one.
850 xfs_trans_brelse(tp, bp);
851 error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
855 b = bufp = bp->b_addr;
859 * Go on to the next word in the buffer.
865 * Starting on a word boundary, no partial word.
870 * Loop over whole words in buffers. When we use up one buffer
871 * we move on to the next one.
873 while (len - i >= XFS_NBWORD) {
875 * Compute difference between actual and desired value.
877 if ((wdiff = *b ^ val)) {
879 * Different, compute first wrong bit and return.
881 xfs_trans_brelse(tp, bp);
882 i += XFS_RTLOBIT(wdiff);
889 * Go on to next block if that's where the next word is
890 * and we need the next word.
892 if (++word == XFS_BLOCKWSIZE(mp) && i < len) {
894 * If done with this block, get the next one.
896 xfs_trans_brelse(tp, bp);
897 error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
901 b = bufp = bp->b_addr;
905 * Go on to the next word in the buffer.
911 * If not ending on a word boundary, deal with the last
914 if ((lastbit = len - i)) {
916 * Mask of relevant bits.
918 mask = ((xfs_rtword_t)1 << lastbit) - 1;
920 * Compute difference between actual and desired value.
922 if ((wdiff = (*b ^ val) & mask)) {
924 * Different, compute first wrong bit and return.
926 xfs_trans_brelse(tp, bp);
927 i += XFS_RTLOBIT(wdiff);
935 * Successful, return.
937 xfs_trans_brelse(tp, bp);
945 * Check that the given extent (block range) is allocated already.
947 STATIC int /* error */
948 xfs_rtcheck_alloc_range(
949 xfs_mount_t *mp, /* file system mount point */
950 xfs_trans_t *tp, /* transaction pointer */
951 xfs_rtblock_t bno, /* starting block number of extent */
952 xfs_extlen_t len) /* length of extent */
954 xfs_rtblock_t new; /* dummy for xfs_rtcheck_range */
958 error = xfs_rtcheck_range(mp, tp, bno, len, 0, &new, &stat);
965 #define xfs_rtcheck_alloc_range(m,t,b,l) (0)
968 * Free an extent in the realtime subvolume. Length is expressed in
969 * realtime extents, as is the block number.
973 xfs_trans_t *tp, /* transaction pointer */
974 xfs_rtblock_t bno, /* starting block number to free */
975 xfs_extlen_t len) /* length of extent freed */
977 int error; /* error value */
978 xfs_mount_t *mp; /* file system mount structure */
979 xfs_fsblock_t sb; /* summary file block number */
980 xfs_buf_t *sumbp = NULL; /* summary file block buffer */
984 ASSERT(mp->m_rbmip->i_itemp != NULL);
985 ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL));
987 error = xfs_rtcheck_alloc_range(mp, tp, bno, len);
992 * Free the range of realtime blocks.
994 error = xfs_rtfree_range(mp, tp, bno, len, &sumbp, &sb);
999 * Mark more blocks free in the superblock.
1001 xfs_trans_mod_sb(tp, XFS_TRANS_SB_FREXTENTS, (long)len);
1003 * If we've now freed all the blocks, reset the file sequence
1006 if (tp->t_frextents_delta + mp->m_sb.sb_frextents ==
1007 mp->m_sb.sb_rextents) {
1008 if (!(mp->m_rbmip->i_d.di_flags & XFS_DIFLAG_NEWRTBM))
1009 mp->m_rbmip->i_d.di_flags |= XFS_DIFLAG_NEWRTBM;
1010 *(uint64_t *)&VFS_I(mp->m_rbmip)->i_atime = 0;
1011 xfs_trans_log_inode(tp, mp->m_rbmip, XFS_ILOG_CORE);
1016 /* Find all the free records within a given range. */
1018 xfs_rtalloc_query_range(
1019 struct xfs_trans *tp,
1020 struct xfs_rtalloc_rec *low_rec,
1021 struct xfs_rtalloc_rec *high_rec,
1022 xfs_rtalloc_query_range_fn fn,
1025 struct xfs_rtalloc_rec rec;
1026 struct xfs_mount *mp = tp->t_mountp;
1027 xfs_rtblock_t rtstart;
1028 xfs_rtblock_t rtend;
1033 if (low_rec->ar_startext > high_rec->ar_startext)
1035 if (low_rec->ar_startext >= mp->m_sb.sb_rextents ||
1036 low_rec->ar_startext == high_rec->ar_startext)
1038 if (high_rec->ar_startext > mp->m_sb.sb_rextents)
1039 high_rec->ar_startext = mp->m_sb.sb_rextents;
1041 /* Iterate the bitmap, looking for discrepancies. */
1042 rtstart = low_rec->ar_startext;
1043 rem = high_rec->ar_startext - rtstart;
1045 /* Is the first block free? */
1046 error = xfs_rtcheck_range(mp, tp, rtstart, 1, 1, &rtend,
1051 /* How long does the extent go for? */
1052 error = xfs_rtfind_forw(mp, tp, rtstart,
1053 high_rec->ar_startext - 1, &rtend);
1058 rec.ar_startext = rtstart;
1059 rec.ar_extcount = rtend - rtstart + 1;
1061 error = fn(tp, &rec, priv);
1066 rem -= rtend - rtstart + 1;
1067 rtstart = rtend + 1;
1073 /* Find all the free records. */
1075 xfs_rtalloc_query_all(
1076 struct xfs_trans *tp,
1077 xfs_rtalloc_query_range_fn fn,
1080 struct xfs_rtalloc_rec keys[2];
1082 keys[0].ar_startext = 0;
1083 keys[1].ar_startext = tp->t_mountp->m_sb.sb_rextents - 1;
1084 keys[0].ar_extcount = keys[1].ar_extcount = 0;
1086 return xfs_rtalloc_query_range(tp, &keys[0], &keys[1], fn, priv);
1089 /* Is the given extent all free? */
1091 xfs_rtalloc_extent_is_free(
1092 struct xfs_mount *mp,
1093 struct xfs_trans *tp,
1094 xfs_rtblock_t start,
1102 error = xfs_rtcheck_range(mp, tp, start, len, 1, &end, &matches);