2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "libxfs_priv.h"
20 #include "xfs_shared.h"
21 #include "xfs_format.h"
22 #include "xfs_log_format.h"
23 #include "xfs_trans_resv.h"
25 #include "xfs_mount.h"
26 #include "xfs_inode.h"
28 #include "xfs_bmap_btree.h"
29 #include "xfs_alloc.h"
30 #include "xfs_trans.h"
31 #include "xfs_trans_space.h"
32 #include "xfs_trace.h"
36 * Realtime allocator bitmap functions shared with userspace.
40 * Real time buffers need verifiers to avoid runtime warnings during IO.
41 * We don't have anything to verify, however, so these are just dummy
45 xfs_rtbuf_verify_read(
52 xfs_rtbuf_verify_write(
58 const struct xfs_buf_ops xfs_rtbuf_ops
= {
60 .verify_read
= xfs_rtbuf_verify_read
,
61 .verify_write
= xfs_rtbuf_verify_write
,
65 * Get a buffer for the bitmap or summary file block specified.
66 * The buffer is returned read and locked.
70 xfs_mount_t
*mp
, /* file system mount structure */
71 xfs_trans_t
*tp
, /* transaction pointer */
72 xfs_rtblock_t block
, /* block number in bitmap or summary */
73 int issum
, /* is summary not bitmap */
74 xfs_buf_t
**bpp
) /* output: buffer for the block */
76 xfs_buf_t
*bp
; /* block buffer, result */
77 xfs_inode_t
*ip
; /* bitmap or summary inode */
80 int error
; /* error value */
82 ip
= issum
? mp
->m_rsumip
: mp
->m_rbmip
;
84 error
= xfs_bmapi_read(ip
, block
, 1, &map
, &nmap
, XFS_DATA_FORK
);
88 ASSERT(map
.br_startblock
!= NULLFSBLOCK
);
89 error
= xfs_trans_read_buf(mp
, tp
, mp
->m_ddev_targp
,
90 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
91 mp
->m_bsize
, 0, &bp
, &xfs_rtbuf_ops
);
95 xfs_trans_buf_set_type(tp
, bp
, issum
? XFS_BLFT_RTSUMMARY_BUF
96 : XFS_BLFT_RTBITMAP_BUF
);
102 * Searching backward from start to limit, find the first block whose
103 * allocated/free state is different from start's.
107 xfs_mount_t
*mp
, /* file system mount point */
108 xfs_trans_t
*tp
, /* transaction pointer */
109 xfs_rtblock_t start
, /* starting block to look at */
110 xfs_rtblock_t limit
, /* last block to look at */
111 xfs_rtblock_t
*rtblock
) /* out: start block found */
113 xfs_rtword_t
*b
; /* current word in buffer */
114 int bit
; /* bit number in the word */
115 xfs_rtblock_t block
; /* bitmap block number */
116 xfs_buf_t
*bp
; /* buf for the block */
117 xfs_rtword_t
*bufp
; /* starting word in buffer */
118 int error
; /* error value */
119 xfs_rtblock_t firstbit
; /* first useful bit in the word */
120 xfs_rtblock_t i
; /* current bit number rel. to start */
121 xfs_rtblock_t len
; /* length of inspected area */
122 xfs_rtword_t mask
; /* mask of relevant bits for value */
123 xfs_rtword_t want
; /* mask for "good" values */
124 xfs_rtword_t wdiff
; /* difference from wanted value */
125 int word
; /* word number in the buffer */
128 * Compute and read in starting bitmap block for starting block.
130 block
= XFS_BITTOBLOCK(mp
, start
);
131 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
137 * Get the first word's index & point to it.
139 word
= XFS_BITTOWORD(mp
, start
);
141 bit
= (int)(start
& (XFS_NBWORD
- 1));
142 len
= start
- limit
+ 1;
144 * Compute match value, based on the bit at start: if 1 (free)
145 * then all-ones, else all-zeroes.
147 want
= (*b
& ((xfs_rtword_t
)1 << bit
)) ? -1 : 0;
149 * If the starting position is not word-aligned, deal with the
152 if (bit
< XFS_NBWORD
- 1) {
154 * Calculate first (leftmost) bit number to look at,
155 * and mask for all the relevant bits in this word.
157 firstbit
= XFS_RTMAX((xfs_srtblock_t
)(bit
- len
+ 1), 0);
158 mask
= (((xfs_rtword_t
)1 << (bit
- firstbit
+ 1)) - 1) <<
161 * Calculate the difference between the value there
162 * and what we're looking for.
164 if ((wdiff
= (*b
^ want
) & mask
)) {
166 * Different. Mark where we are and return.
168 xfs_trans_brelse(tp
, bp
);
169 i
= bit
- XFS_RTHIBIT(wdiff
);
170 *rtblock
= start
- i
+ 1;
173 i
= bit
- firstbit
+ 1;
175 * Go on to previous block if that's where the previous word is
176 * and we need the previous word.
178 if (--word
== -1 && i
< len
) {
180 * If done with this block, get the previous one.
182 xfs_trans_brelse(tp
, bp
);
183 error
= xfs_rtbuf_get(mp
, tp
, --block
, 0, &bp
);
188 word
= XFS_BLOCKWMASK(mp
);
192 * Go on to the previous word in the buffer.
198 * Starting on a word boundary, no partial word.
203 * Loop over whole words in buffers. When we use up one buffer
204 * we move on to the previous one.
206 while (len
- i
>= XFS_NBWORD
) {
208 * Compute difference between actual and desired value.
210 if ((wdiff
= *b
^ want
)) {
212 * Different, mark where we are and return.
214 xfs_trans_brelse(tp
, bp
);
215 i
+= XFS_NBWORD
- 1 - XFS_RTHIBIT(wdiff
);
216 *rtblock
= start
- i
+ 1;
221 * Go on to previous block if that's where the previous word is
222 * and we need the previous word.
224 if (--word
== -1 && i
< len
) {
226 * If done with this block, get the previous one.
228 xfs_trans_brelse(tp
, bp
);
229 error
= xfs_rtbuf_get(mp
, tp
, --block
, 0, &bp
);
234 word
= XFS_BLOCKWMASK(mp
);
238 * Go on to the previous word in the buffer.
244 * If not ending on a word boundary, deal with the last
249 * Calculate first (leftmost) bit number to look at,
250 * and mask for all the relevant bits in this word.
252 firstbit
= XFS_NBWORD
- (len
- i
);
253 mask
= (((xfs_rtword_t
)1 << (len
- i
)) - 1) << firstbit
;
255 * Compute difference between actual and desired value.
257 if ((wdiff
= (*b
^ want
) & mask
)) {
259 * Different, mark where we are and return.
261 xfs_trans_brelse(tp
, bp
);
262 i
+= XFS_NBWORD
- 1 - XFS_RTHIBIT(wdiff
);
263 *rtblock
= start
- i
+ 1;
269 * No match, return that we scanned the whole area.
271 xfs_trans_brelse(tp
, bp
);
272 *rtblock
= start
- i
+ 1;
277 * Searching forward from start to limit, find the first block whose
278 * allocated/free state is different from start's.
282 xfs_mount_t
*mp
, /* file system mount point */
283 xfs_trans_t
*tp
, /* transaction pointer */
284 xfs_rtblock_t start
, /* starting block to look at */
285 xfs_rtblock_t limit
, /* last block to look at */
286 xfs_rtblock_t
*rtblock
) /* out: start block found */
288 xfs_rtword_t
*b
; /* current word in buffer */
289 int bit
; /* bit number in the word */
290 xfs_rtblock_t block
; /* bitmap block number */
291 xfs_buf_t
*bp
; /* buf for the block */
292 xfs_rtword_t
*bufp
; /* starting word in buffer */
293 int error
; /* error value */
294 xfs_rtblock_t i
; /* current bit number rel. to start */
295 xfs_rtblock_t lastbit
; /* last useful bit in the word */
296 xfs_rtblock_t len
; /* length of inspected area */
297 xfs_rtword_t mask
; /* mask of relevant bits for value */
298 xfs_rtword_t want
; /* mask for "good" values */
299 xfs_rtword_t wdiff
; /* difference from wanted value */
300 int word
; /* word number in the buffer */
303 * Compute and read in starting bitmap block for starting block.
305 block
= XFS_BITTOBLOCK(mp
, start
);
306 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
312 * Get the first word's index & point to it.
314 word
= XFS_BITTOWORD(mp
, start
);
316 bit
= (int)(start
& (XFS_NBWORD
- 1));
317 len
= limit
- start
+ 1;
319 * Compute match value, based on the bit at start: if 1 (free)
320 * then all-ones, else all-zeroes.
322 want
= (*b
& ((xfs_rtword_t
)1 << bit
)) ? -1 : 0;
324 * If the starting position is not word-aligned, deal with the
329 * Calculate last (rightmost) bit number to look at,
330 * and mask for all the relevant bits in this word.
332 lastbit
= XFS_RTMIN(bit
+ len
, XFS_NBWORD
);
333 mask
= (((xfs_rtword_t
)1 << (lastbit
- bit
)) - 1) << bit
;
335 * Calculate the difference between the value there
336 * and what we're looking for.
338 if ((wdiff
= (*b
^ want
) & mask
)) {
340 * Different. Mark where we are and return.
342 xfs_trans_brelse(tp
, bp
);
343 i
= XFS_RTLOBIT(wdiff
) - bit
;
344 *rtblock
= start
+ i
- 1;
349 * Go on to next block if that's where the next word is
350 * and we need the next word.
352 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
354 * If done with this block, get the previous one.
356 xfs_trans_brelse(tp
, bp
);
357 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
361 b
= bufp
= bp
->b_addr
;
365 * Go on to the previous word in the buffer.
371 * Starting on a word boundary, no partial word.
376 * Loop over whole words in buffers. When we use up one buffer
377 * we move on to the next one.
379 while (len
- i
>= XFS_NBWORD
) {
381 * Compute difference between actual and desired value.
383 if ((wdiff
= *b
^ want
)) {
385 * Different, mark where we are and return.
387 xfs_trans_brelse(tp
, bp
);
388 i
+= XFS_RTLOBIT(wdiff
);
389 *rtblock
= start
+ i
- 1;
394 * Go on to next block if that's where the next word is
395 * and we need the next word.
397 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
399 * If done with this block, get the next one.
401 xfs_trans_brelse(tp
, bp
);
402 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
406 b
= bufp
= bp
->b_addr
;
410 * Go on to the next word in the buffer.
416 * If not ending on a word boundary, deal with the last
419 if ((lastbit
= len
- i
)) {
421 * Calculate mask for all the relevant bits in this word.
423 mask
= ((xfs_rtword_t
)1 << lastbit
) - 1;
425 * Compute difference between actual and desired value.
427 if ((wdiff
= (*b
^ want
) & mask
)) {
429 * Different, mark where we are and return.
431 xfs_trans_brelse(tp
, bp
);
432 i
+= XFS_RTLOBIT(wdiff
);
433 *rtblock
= start
+ i
- 1;
439 * No match, return that we scanned the whole area.
441 xfs_trans_brelse(tp
, bp
);
442 *rtblock
= start
+ i
- 1;
447 * Read and/or modify the summary information for a given extent size,
448 * bitmap block combination.
449 * Keeps track of a current summary block, so we don't keep reading
450 * it from the buffer cache.
452 * Summary information is returned in *sum if specified.
453 * If no delta is specified, returns summary only.
456 xfs_rtmodify_summary_int(
457 xfs_mount_t
*mp
, /* file system mount structure */
458 xfs_trans_t
*tp
, /* transaction pointer */
459 int log
, /* log2 of extent size */
460 xfs_rtblock_t bbno
, /* bitmap block number */
461 int delta
, /* change to make to summary info */
462 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
463 xfs_fsblock_t
*rsb
, /* in/out: summary block number */
464 xfs_suminfo_t
*sum
) /* out: summary info for this block */
466 xfs_buf_t
*bp
; /* buffer for the summary block */
467 int error
; /* error value */
468 xfs_fsblock_t sb
; /* summary fsblock */
469 int so
; /* index into the summary file */
470 xfs_suminfo_t
*sp
; /* pointer to returned data */
473 * Compute entry number in the summary file.
475 so
= XFS_SUMOFFS(mp
, log
, bbno
);
477 * Compute the block number in the summary file.
479 sb
= XFS_SUMOFFSTOBLOCK(mp
, so
);
481 * If we have an old buffer, and the block number matches, use that.
483 if (*rbpp
&& *rsb
== sb
)
486 * Otherwise we have to get the buffer.
490 * If there was an old one, get rid of it first.
493 xfs_trans_brelse(tp
, *rbpp
);
494 error
= xfs_rtbuf_get(mp
, tp
, sb
, 1, &bp
);
499 * Remember this buffer and block for the next call.
505 * Point to the summary information, modify/log it, and/or copy it out.
507 sp
= XFS_SUMPTR(mp
, bp
, so
);
509 uint first
= (uint
)((char *)sp
- (char *)bp
->b_addr
);
512 xfs_trans_log_buf(tp
, bp
, first
, first
+ sizeof(*sp
) - 1);
520 xfs_rtmodify_summary(
521 xfs_mount_t
*mp
, /* file system mount structure */
522 xfs_trans_t
*tp
, /* transaction pointer */
523 int log
, /* log2 of extent size */
524 xfs_rtblock_t bbno
, /* bitmap block number */
525 int delta
, /* change to make to summary info */
526 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
527 xfs_fsblock_t
*rsb
) /* in/out: summary block number */
529 return xfs_rtmodify_summary_int(mp
, tp
, log
, bbno
,
530 delta
, rbpp
, rsb
, NULL
);
534 * Set the given range of bitmap bits to the given value.
535 * Do whatever I/O and logging is required.
539 xfs_mount_t
*mp
, /* file system mount point */
540 xfs_trans_t
*tp
, /* transaction pointer */
541 xfs_rtblock_t start
, /* starting block to modify */
542 xfs_extlen_t len
, /* length of extent to modify */
543 int val
) /* 1 for free, 0 for allocated */
545 xfs_rtword_t
*b
; /* current word in buffer */
546 int bit
; /* bit number in the word */
547 xfs_rtblock_t block
; /* bitmap block number */
548 xfs_buf_t
*bp
; /* buf for the block */
549 xfs_rtword_t
*bufp
; /* starting word in buffer */
550 int error
; /* error value */
551 xfs_rtword_t
*first
; /* first used word in the buffer */
552 int i
; /* current bit number rel. to start */
553 int lastbit
; /* last useful bit in word */
554 xfs_rtword_t mask
; /* mask o frelevant bits for value */
555 int word
; /* word number in the buffer */
558 * Compute starting bitmap block number.
560 block
= XFS_BITTOBLOCK(mp
, start
);
562 * Read the bitmap block, and point to its data.
564 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
570 * Compute the starting word's address, and starting bit.
572 word
= XFS_BITTOWORD(mp
, start
);
573 first
= b
= &bufp
[word
];
574 bit
= (int)(start
& (XFS_NBWORD
- 1));
576 * 0 (allocated) => all zeroes; 1 (free) => all ones.
580 * If not starting on a word boundary, deal with the first
585 * Compute first bit not changed and mask of relevant bits.
587 lastbit
= XFS_RTMIN(bit
+ len
, XFS_NBWORD
);
588 mask
= (((xfs_rtword_t
)1 << (lastbit
- bit
)) - 1) << bit
;
590 * Set/clear the active bits.
598 * Go on to the next block if that's where the next word is
599 * and we need the next word.
601 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
603 * Log the changed part of this block.
606 xfs_trans_log_buf(tp
, bp
,
607 (uint
)((char *)first
- (char *)bufp
),
608 (uint
)((char *)b
- (char *)bufp
));
609 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
613 first
= b
= bufp
= bp
->b_addr
;
617 * Go on to the next word in the buffer
623 * Starting on a word boundary, no partial word.
628 * Loop over whole words in buffers. When we use up one buffer
629 * we move on to the next one.
631 while (len
- i
>= XFS_NBWORD
) {
633 * Set the word value correctly.
638 * Go on to the next block if that's where the next word is
639 * and we need the next word.
641 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
643 * Log the changed part of this block.
646 xfs_trans_log_buf(tp
, bp
,
647 (uint
)((char *)first
- (char *)bufp
),
648 (uint
)((char *)b
- (char *)bufp
));
649 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
653 first
= b
= bufp
= bp
->b_addr
;
657 * Go on to the next word in the buffer
663 * If not ending on a word boundary, deal with the last
666 if ((lastbit
= len
- i
)) {
668 * Compute a mask of relevant bits.
671 mask
= ((xfs_rtword_t
)1 << lastbit
) - 1;
673 * Set/clear the active bits.
682 * Log any remaining changed bytes.
685 xfs_trans_log_buf(tp
, bp
, (uint
)((char *)first
- (char *)bufp
),
686 (uint
)((char *)b
- (char *)bufp
- 1));
691 * Mark an extent specified by start and len freed.
692 * Updates all the summary information as well as the bitmap.
696 xfs_mount_t
*mp
, /* file system mount point */
697 xfs_trans_t
*tp
, /* transaction pointer */
698 xfs_rtblock_t start
, /* starting block to free */
699 xfs_extlen_t len
, /* length to free */
700 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
701 xfs_fsblock_t
*rsb
) /* in/out: summary block number */
703 xfs_rtblock_t end
; /* end of the freed extent */
704 int error
; /* error value */
705 xfs_rtblock_t postblock
; /* first block freed > end */
706 xfs_rtblock_t preblock
; /* first block freed < start */
708 end
= start
+ len
- 1;
710 * Modify the bitmap to mark this extent freed.
712 error
= xfs_rtmodify_range(mp
, tp
, start
, len
, 1);
717 * Assume we're freeing out of the middle of an allocated extent.
718 * We need to find the beginning and end of the extent so we can
719 * properly update the summary.
721 error
= xfs_rtfind_back(mp
, tp
, start
, 0, &preblock
);
726 * Find the next allocated block (end of allocated extent).
728 error
= xfs_rtfind_forw(mp
, tp
, end
, mp
->m_sb
.sb_rextents
- 1,
733 * If there are blocks not being freed at the front of the
734 * old extent, add summary data for them to be allocated.
736 if (preblock
< start
) {
737 error
= xfs_rtmodify_summary(mp
, tp
,
738 XFS_RTBLOCKLOG(start
- preblock
),
739 XFS_BITTOBLOCK(mp
, preblock
), -1, rbpp
, rsb
);
745 * If there are blocks not being freed at the end of the
746 * old extent, add summary data for them to be allocated.
748 if (postblock
> end
) {
749 error
= xfs_rtmodify_summary(mp
, tp
,
750 XFS_RTBLOCKLOG(postblock
- end
),
751 XFS_BITTOBLOCK(mp
, end
+ 1), -1, rbpp
, rsb
);
757 * Increment the summary information corresponding to the entire
760 error
= xfs_rtmodify_summary(mp
, tp
,
761 XFS_RTBLOCKLOG(postblock
+ 1 - preblock
),
762 XFS_BITTOBLOCK(mp
, preblock
), 1, rbpp
, rsb
);
767 * Check that the given range is either all allocated (val = 0) or
768 * all free (val = 1).
772 xfs_mount_t
*mp
, /* file system mount point */
773 xfs_trans_t
*tp
, /* transaction pointer */
774 xfs_rtblock_t start
, /* starting block number of extent */
775 xfs_extlen_t len
, /* length of extent */
776 int val
, /* 1 for free, 0 for allocated */
777 xfs_rtblock_t
*new, /* out: first block not matching */
778 int *stat
) /* out: 1 for matches, 0 for not */
780 xfs_rtword_t
*b
; /* current word in buffer */
781 int bit
; /* bit number in the word */
782 xfs_rtblock_t block
; /* bitmap block number */
783 xfs_buf_t
*bp
; /* buf for the block */
784 xfs_rtword_t
*bufp
; /* starting word in buffer */
785 int error
; /* error value */
786 xfs_rtblock_t i
; /* current bit number rel. to start */
787 xfs_rtblock_t lastbit
; /* last useful bit in word */
788 xfs_rtword_t mask
; /* mask of relevant bits for value */
789 xfs_rtword_t wdiff
; /* difference from wanted value */
790 int word
; /* word number in the buffer */
793 * Compute starting bitmap block number
795 block
= XFS_BITTOBLOCK(mp
, start
);
797 * Read the bitmap block.
799 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
805 * Compute the starting word's address, and starting bit.
807 word
= XFS_BITTOWORD(mp
, start
);
809 bit
= (int)(start
& (XFS_NBWORD
- 1));
811 * 0 (allocated) => all zero's; 1 (free) => all one's.
815 * If not starting on a word boundary, deal with the first
820 * Compute first bit not examined.
822 lastbit
= XFS_RTMIN(bit
+ len
, XFS_NBWORD
);
824 * Mask of relevant bits.
826 mask
= (((xfs_rtword_t
)1 << (lastbit
- bit
)) - 1) << bit
;
828 * Compute difference between actual and desired value.
830 if ((wdiff
= (*b
^ val
) & mask
)) {
832 * Different, compute first wrong bit and return.
834 xfs_trans_brelse(tp
, bp
);
835 i
= XFS_RTLOBIT(wdiff
) - bit
;
842 * Go on to next block if that's where the next word is
843 * and we need the next word.
845 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
847 * If done with this block, get the next one.
849 xfs_trans_brelse(tp
, bp
);
850 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
854 b
= bufp
= bp
->b_addr
;
858 * Go on to the next word in the buffer.
864 * Starting on a word boundary, no partial word.
869 * Loop over whole words in buffers. When we use up one buffer
870 * we move on to the next one.
872 while (len
- i
>= XFS_NBWORD
) {
874 * Compute difference between actual and desired value.
876 if ((wdiff
= *b
^ val
)) {
878 * Different, compute first wrong bit and return.
880 xfs_trans_brelse(tp
, bp
);
881 i
+= XFS_RTLOBIT(wdiff
);
888 * Go on to next block if that's where the next word is
889 * and we need the next word.
891 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
893 * If done with this block, get the next one.
895 xfs_trans_brelse(tp
, bp
);
896 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
900 b
= bufp
= bp
->b_addr
;
904 * Go on to the next word in the buffer.
910 * If not ending on a word boundary, deal with the last
913 if ((lastbit
= len
- i
)) {
915 * Mask of relevant bits.
917 mask
= ((xfs_rtword_t
)1 << lastbit
) - 1;
919 * Compute difference between actual and desired value.
921 if ((wdiff
= (*b
^ val
) & mask
)) {
923 * Different, compute first wrong bit and return.
925 xfs_trans_brelse(tp
, bp
);
926 i
+= XFS_RTLOBIT(wdiff
);
934 * Successful, return.
936 xfs_trans_brelse(tp
, bp
);
944 * Check that the given extent (block range) is allocated already.
946 STATIC
int /* error */
947 xfs_rtcheck_alloc_range(
948 xfs_mount_t
*mp
, /* file system mount point */
949 xfs_trans_t
*tp
, /* transaction pointer */
950 xfs_rtblock_t bno
, /* starting block number of extent */
951 xfs_extlen_t len
) /* length of extent */
953 xfs_rtblock_t
new; /* dummy for xfs_rtcheck_range */
957 error
= xfs_rtcheck_range(mp
, tp
, bno
, len
, 0, &new, &stat
);
964 #define xfs_rtcheck_alloc_range(m,t,b,l) (0)
967 * Free an extent in the realtime subvolume. Length is expressed in
968 * realtime extents, as is the block number.
972 xfs_trans_t
*tp
, /* transaction pointer */
973 xfs_rtblock_t bno
, /* starting block number to free */
974 xfs_extlen_t len
) /* length of extent freed */
976 int error
; /* error value */
977 xfs_mount_t
*mp
; /* file system mount structure */
978 xfs_fsblock_t sb
; /* summary file block number */
979 xfs_buf_t
*sumbp
= NULL
; /* summary file block buffer */
983 ASSERT(mp
->m_rbmip
->i_itemp
!= NULL
);
984 ASSERT(xfs_isilocked(mp
->m_rbmip
, XFS_ILOCK_EXCL
));
986 error
= xfs_rtcheck_alloc_range(mp
, tp
, bno
, len
);
991 * Free the range of realtime blocks.
993 error
= xfs_rtfree_range(mp
, tp
, bno
, len
, &sumbp
, &sb
);
998 * Mark more blocks free in the superblock.
1000 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_FREXTENTS
, (long)len
);
1002 * If we've now freed all the blocks, reset the file sequence
1005 if (tp
->t_frextents_delta
+ mp
->m_sb
.sb_frextents
==
1006 mp
->m_sb
.sb_rextents
) {
1007 if (!(mp
->m_rbmip
->i_d
.di_flags
& XFS_DIFLAG_NEWRTBM
))
1008 mp
->m_rbmip
->i_d
.di_flags
|= XFS_DIFLAG_NEWRTBM
;
1009 *(uint64_t *)&VFS_I(mp
->m_rbmip
)->i_atime
= 0;
1010 xfs_trans_log_inode(tp
, mp
->m_rbmip
, XFS_ILOG_CORE
);
1015 /* Find all the free records within a given range. */
1017 xfs_rtalloc_query_range(
1018 struct xfs_trans
*tp
,
1019 struct xfs_rtalloc_rec
*low_rec
,
1020 struct xfs_rtalloc_rec
*high_rec
,
1021 xfs_rtalloc_query_range_fn fn
,
1024 struct xfs_rtalloc_rec rec
;
1025 struct xfs_mount
*mp
= tp
->t_mountp
;
1026 xfs_rtblock_t rtstart
;
1027 xfs_rtblock_t rtend
;
1032 if (low_rec
->ar_startblock
> high_rec
->ar_startblock
)
1034 else if (low_rec
->ar_startblock
== high_rec
->ar_startblock
)
1037 /* Iterate the bitmap, looking for discrepancies. */
1038 rtstart
= low_rec
->ar_startblock
;
1039 rem
= high_rec
->ar_startblock
- rtstart
;
1041 /* Is the first block free? */
1042 error
= xfs_rtcheck_range(mp
, tp
, rtstart
, 1, 1, &rtend
,
1047 /* How long does the extent go for? */
1048 error
= xfs_rtfind_forw(mp
, tp
, rtstart
,
1049 high_rec
->ar_startblock
- 1, &rtend
);
1054 rec
.ar_startblock
= rtstart
;
1055 rec
.ar_blockcount
= rtend
- rtstart
+ 1;
1057 error
= fn(tp
, &rec
, priv
);
1062 rem
-= rtend
- rtstart
+ 1;
1063 rtstart
= rtend
+ 1;
1069 /* Find all the free records. */
1071 xfs_rtalloc_query_all(
1072 struct xfs_trans
*tp
,
1073 xfs_rtalloc_query_range_fn fn
,
1076 struct xfs_rtalloc_rec keys
[2];
1078 keys
[0].ar_startblock
= 0;
1079 keys
[1].ar_startblock
= tp
->t_mountp
->m_sb
.sb_rblocks
;
1080 keys
[0].ar_blockcount
= keys
[1].ar_blockcount
= 0;
1082 return xfs_rtalloc_query_range(tp
, &keys
[0], &keys
[1], fn
, priv
);
1086 * Verify that an realtime block number pointer doesn't point off the
1087 * end of the realtime device.
1091 struct xfs_mount
*mp
,
1092 xfs_rtblock_t rtbno
)
1094 return rtbno
< mp
->m_sb
.sb_rblocks
;