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 xfs_trans_log_buf(tp
, bp
, first
, first
+ sizeof(*sp
) - 1);
516 xfs_rtmodify_summary(
517 xfs_mount_t
*mp
, /* file system mount structure */
518 xfs_trans_t
*tp
, /* transaction pointer */
519 int log
, /* log2 of extent size */
520 xfs_rtblock_t bbno
, /* bitmap block number */
521 int delta
, /* change to make to summary info */
522 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
523 xfs_fsblock_t
*rsb
) /* in/out: summary block number */
525 return xfs_rtmodify_summary_int(mp
, tp
, log
, bbno
,
526 delta
, rbpp
, rsb
, NULL
);
530 * Set the given range of bitmap bits to the given value.
531 * Do whatever I/O and logging is required.
535 xfs_mount_t
*mp
, /* file system mount point */
536 xfs_trans_t
*tp
, /* transaction pointer */
537 xfs_rtblock_t start
, /* starting block to modify */
538 xfs_extlen_t len
, /* length of extent to modify */
539 int val
) /* 1 for free, 0 for allocated */
541 xfs_rtword_t
*b
; /* current word in buffer */
542 int bit
; /* bit number in the word */
543 xfs_rtblock_t block
; /* bitmap block number */
544 xfs_buf_t
*bp
; /* buf for the block */
545 xfs_rtword_t
*bufp
; /* starting word in buffer */
546 int error
; /* error value */
547 xfs_rtword_t
*first
; /* first used word in the buffer */
548 int i
; /* current bit number rel. to start */
549 int lastbit
; /* last useful bit in word */
550 xfs_rtword_t mask
; /* mask o frelevant bits for value */
551 int word
; /* word number in the buffer */
554 * Compute starting bitmap block number.
556 block
= XFS_BITTOBLOCK(mp
, start
);
558 * Read the bitmap block, and point to its data.
560 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
566 * Compute the starting word's address, and starting bit.
568 word
= XFS_BITTOWORD(mp
, start
);
569 first
= b
= &bufp
[word
];
570 bit
= (int)(start
& (XFS_NBWORD
- 1));
572 * 0 (allocated) => all zeroes; 1 (free) => all ones.
576 * If not starting on a word boundary, deal with the first
581 * Compute first bit not changed and mask of relevant bits.
583 lastbit
= XFS_RTMIN(bit
+ len
, XFS_NBWORD
);
584 mask
= (((xfs_rtword_t
)1 << (lastbit
- bit
)) - 1) << bit
;
586 * Set/clear the active bits.
594 * Go on to the next block if that's where the next word is
595 * and we need the next word.
597 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
599 * Log the changed part of this block.
602 xfs_trans_log_buf(tp
, bp
,
603 (uint
)((char *)first
- (char *)bufp
),
604 (uint
)((char *)b
- (char *)bufp
));
605 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
609 first
= b
= bufp
= bp
->b_addr
;
613 * Go on to the next word in the buffer
619 * Starting on a word boundary, no partial word.
624 * Loop over whole words in buffers. When we use up one buffer
625 * we move on to the next one.
627 while (len
- i
>= XFS_NBWORD
) {
629 * Set the word value correctly.
634 * Go on to the next block if that's where the next word is
635 * and we need the next word.
637 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
639 * Log the changed part of this block.
642 xfs_trans_log_buf(tp
, bp
,
643 (uint
)((char *)first
- (char *)bufp
),
644 (uint
)((char *)b
- (char *)bufp
));
645 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
649 first
= b
= bufp
= bp
->b_addr
;
653 * Go on to the next word in the buffer
659 * If not ending on a word boundary, deal with the last
662 if ((lastbit
= len
- i
)) {
664 * Compute a mask of relevant bits.
666 mask
= ((xfs_rtword_t
)1 << lastbit
) - 1;
668 * Set/clear the active bits.
677 * Log any remaining changed bytes.
680 xfs_trans_log_buf(tp
, bp
, (uint
)((char *)first
- (char *)bufp
),
681 (uint
)((char *)b
- (char *)bufp
- 1));
686 * Mark an extent specified by start and len freed.
687 * Updates all the summary information as well as the bitmap.
691 xfs_mount_t
*mp
, /* file system mount point */
692 xfs_trans_t
*tp
, /* transaction pointer */
693 xfs_rtblock_t start
, /* starting block to free */
694 xfs_extlen_t len
, /* length to free */
695 xfs_buf_t
**rbpp
, /* in/out: summary block buffer */
696 xfs_fsblock_t
*rsb
) /* in/out: summary block number */
698 xfs_rtblock_t end
; /* end of the freed extent */
699 int error
; /* error value */
700 xfs_rtblock_t postblock
; /* first block freed > end */
701 xfs_rtblock_t preblock
; /* first block freed < start */
703 end
= start
+ len
- 1;
705 * Modify the bitmap to mark this extent freed.
707 error
= xfs_rtmodify_range(mp
, tp
, start
, len
, 1);
712 * Assume we're freeing out of the middle of an allocated extent.
713 * We need to find the beginning and end of the extent so we can
714 * properly update the summary.
716 error
= xfs_rtfind_back(mp
, tp
, start
, 0, &preblock
);
721 * Find the next allocated block (end of allocated extent).
723 error
= xfs_rtfind_forw(mp
, tp
, end
, mp
->m_sb
.sb_rextents
- 1,
728 * If there are blocks not being freed at the front of the
729 * old extent, add summary data for them to be allocated.
731 if (preblock
< start
) {
732 error
= xfs_rtmodify_summary(mp
, tp
,
733 XFS_RTBLOCKLOG(start
- preblock
),
734 XFS_BITTOBLOCK(mp
, preblock
), -1, rbpp
, rsb
);
740 * If there are blocks not being freed at the end of the
741 * old extent, add summary data for them to be allocated.
743 if (postblock
> end
) {
744 error
= xfs_rtmodify_summary(mp
, tp
,
745 XFS_RTBLOCKLOG(postblock
- end
),
746 XFS_BITTOBLOCK(mp
, end
+ 1), -1, rbpp
, rsb
);
752 * Increment the summary information corresponding to the entire
755 error
= xfs_rtmodify_summary(mp
, tp
,
756 XFS_RTBLOCKLOG(postblock
+ 1 - preblock
),
757 XFS_BITTOBLOCK(mp
, preblock
), 1, rbpp
, rsb
);
762 * Check that the given range is either all allocated (val = 0) or
763 * all free (val = 1).
767 xfs_mount_t
*mp
, /* file system mount point */
768 xfs_trans_t
*tp
, /* transaction pointer */
769 xfs_rtblock_t start
, /* starting block number of extent */
770 xfs_extlen_t len
, /* length of extent */
771 int val
, /* 1 for free, 0 for allocated */
772 xfs_rtblock_t
*new, /* out: first block not matching */
773 int *stat
) /* out: 1 for matches, 0 for not */
775 xfs_rtword_t
*b
; /* current word in buffer */
776 int bit
; /* bit number in the word */
777 xfs_rtblock_t block
; /* bitmap block number */
778 xfs_buf_t
*bp
; /* buf for the block */
779 xfs_rtword_t
*bufp
; /* starting word in buffer */
780 int error
; /* error value */
781 xfs_rtblock_t i
; /* current bit number rel. to start */
782 xfs_rtblock_t lastbit
; /* last useful bit in word */
783 xfs_rtword_t mask
; /* mask of relevant bits for value */
784 xfs_rtword_t wdiff
; /* difference from wanted value */
785 int word
; /* word number in the buffer */
788 * Compute starting bitmap block number
790 block
= XFS_BITTOBLOCK(mp
, start
);
792 * Read the bitmap block.
794 error
= xfs_rtbuf_get(mp
, tp
, block
, 0, &bp
);
800 * Compute the starting word's address, and starting bit.
802 word
= XFS_BITTOWORD(mp
, start
);
804 bit
= (int)(start
& (XFS_NBWORD
- 1));
806 * 0 (allocated) => all zero's; 1 (free) => all one's.
810 * If not starting on a word boundary, deal with the first
815 * Compute first bit not examined.
817 lastbit
= XFS_RTMIN(bit
+ len
, XFS_NBWORD
);
819 * Mask of relevant bits.
821 mask
= (((xfs_rtword_t
)1 << (lastbit
- bit
)) - 1) << bit
;
823 * Compute difference between actual and desired value.
825 if ((wdiff
= (*b
^ val
) & mask
)) {
827 * Different, compute first wrong bit and return.
829 xfs_trans_brelse(tp
, bp
);
830 i
= XFS_RTLOBIT(wdiff
) - bit
;
837 * Go on to next block if that's where the next word is
838 * and we need the next word.
840 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
842 * If done with this block, get the next one.
844 xfs_trans_brelse(tp
, bp
);
845 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
849 b
= bufp
= bp
->b_addr
;
853 * Go on to the next word in the buffer.
859 * Starting on a word boundary, no partial word.
864 * Loop over whole words in buffers. When we use up one buffer
865 * we move on to the next one.
867 while (len
- i
>= XFS_NBWORD
) {
869 * Compute difference between actual and desired value.
871 if ((wdiff
= *b
^ val
)) {
873 * Different, compute first wrong bit and return.
875 xfs_trans_brelse(tp
, bp
);
876 i
+= XFS_RTLOBIT(wdiff
);
883 * Go on to next block if that's where the next word is
884 * and we need the next word.
886 if (++word
== XFS_BLOCKWSIZE(mp
) && i
< len
) {
888 * If done with this block, get the next one.
890 xfs_trans_brelse(tp
, bp
);
891 error
= xfs_rtbuf_get(mp
, tp
, ++block
, 0, &bp
);
895 b
= bufp
= bp
->b_addr
;
899 * Go on to the next word in the buffer.
905 * If not ending on a word boundary, deal with the last
908 if ((lastbit
= len
- i
)) {
910 * Mask of relevant bits.
912 mask
= ((xfs_rtword_t
)1 << lastbit
) - 1;
914 * Compute difference between actual and desired value.
916 if ((wdiff
= (*b
^ val
) & mask
)) {
918 * Different, compute first wrong bit and return.
920 xfs_trans_brelse(tp
, bp
);
921 i
+= XFS_RTLOBIT(wdiff
);
929 * Successful, return.
931 xfs_trans_brelse(tp
, bp
);
939 * Check that the given extent (block range) is allocated already.
941 STATIC
int /* error */
942 xfs_rtcheck_alloc_range(
943 xfs_mount_t
*mp
, /* file system mount point */
944 xfs_trans_t
*tp
, /* transaction pointer */
945 xfs_rtblock_t bno
, /* starting block number of extent */
946 xfs_extlen_t len
) /* length of extent */
948 xfs_rtblock_t
new; /* dummy for xfs_rtcheck_range */
952 error
= xfs_rtcheck_range(mp
, tp
, bno
, len
, 0, &new, &stat
);
959 #define xfs_rtcheck_alloc_range(m,t,b,l) (0)
962 * Free an extent in the realtime subvolume. Length is expressed in
963 * realtime extents, as is the block number.
967 xfs_trans_t
*tp
, /* transaction pointer */
968 xfs_rtblock_t bno
, /* starting block number to free */
969 xfs_extlen_t len
) /* length of extent freed */
971 int error
; /* error value */
972 xfs_mount_t
*mp
; /* file system mount structure */
973 xfs_fsblock_t sb
; /* summary file block number */
974 xfs_buf_t
*sumbp
= NULL
; /* summary file block buffer */
978 ASSERT(mp
->m_rbmip
->i_itemp
!= NULL
);
979 ASSERT(xfs_isilocked(mp
->m_rbmip
, XFS_ILOCK_EXCL
));
981 error
= xfs_rtcheck_alloc_range(mp
, tp
, bno
, len
);
986 * Free the range of realtime blocks.
988 error
= xfs_rtfree_range(mp
, tp
, bno
, len
, &sumbp
, &sb
);
993 * Mark more blocks free in the superblock.
995 xfs_trans_mod_sb(tp
, XFS_TRANS_SB_FREXTENTS
, (long)len
);
997 * If we've now freed all the blocks, reset the file sequence
1000 if (tp
->t_frextents_delta
+ mp
->m_sb
.sb_frextents
==
1001 mp
->m_sb
.sb_rextents
) {
1002 if (!(mp
->m_rbmip
->i_d
.di_flags
& XFS_DIFLAG_NEWRTBM
))
1003 mp
->m_rbmip
->i_d
.di_flags
|= XFS_DIFLAG_NEWRTBM
;
1004 *(uint64_t *)&VFS_I(mp
->m_rbmip
)->i_atime
= 0;
1005 xfs_trans_log_inode(tp
, mp
->m_rbmip
, XFS_ILOG_CORE
);
1010 /* Find all the free records within a given range. */
1012 xfs_rtalloc_query_range(
1013 struct xfs_trans
*tp
,
1014 struct xfs_rtalloc_rec
*low_rec
,
1015 struct xfs_rtalloc_rec
*high_rec
,
1016 xfs_rtalloc_query_range_fn fn
,
1019 struct xfs_rtalloc_rec rec
;
1020 struct xfs_mount
*mp
= tp
->t_mountp
;
1021 xfs_rtblock_t rtstart
;
1022 xfs_rtblock_t rtend
;
1027 if (low_rec
->ar_startext
> high_rec
->ar_startext
)
1029 if (low_rec
->ar_startext
>= mp
->m_sb
.sb_rextents
||
1030 low_rec
->ar_startext
== high_rec
->ar_startext
)
1032 if (high_rec
->ar_startext
> mp
->m_sb
.sb_rextents
)
1033 high_rec
->ar_startext
= mp
->m_sb
.sb_rextents
;
1035 /* Iterate the bitmap, looking for discrepancies. */
1036 rtstart
= low_rec
->ar_startext
;
1037 rem
= high_rec
->ar_startext
- rtstart
;
1039 /* Is the first block free? */
1040 error
= xfs_rtcheck_range(mp
, tp
, rtstart
, 1, 1, &rtend
,
1045 /* How long does the extent go for? */
1046 error
= xfs_rtfind_forw(mp
, tp
, rtstart
,
1047 high_rec
->ar_startext
- 1, &rtend
);
1052 rec
.ar_startext
= rtstart
;
1053 rec
.ar_extcount
= rtend
- rtstart
+ 1;
1055 error
= fn(tp
, &rec
, priv
);
1060 rem
-= rtend
- rtstart
+ 1;
1061 rtstart
= rtend
+ 1;
1067 /* Find all the free records. */
1069 xfs_rtalloc_query_all(
1070 struct xfs_trans
*tp
,
1071 xfs_rtalloc_query_range_fn fn
,
1074 struct xfs_rtalloc_rec keys
[2];
1076 keys
[0].ar_startext
= 0;
1077 keys
[1].ar_startext
= tp
->t_mountp
->m_sb
.sb_rextents
- 1;
1078 keys
[0].ar_extcount
= keys
[1].ar_extcount
= 0;
1080 return xfs_rtalloc_query_range(tp
, &keys
[0], &keys
[1], fn
, priv
);
1083 /* Is the given extent all free? */
1085 xfs_rtalloc_extent_is_free(
1086 struct xfs_mount
*mp
,
1087 struct xfs_trans
*tp
,
1088 xfs_rtblock_t start
,
1096 error
= xfs_rtcheck_range(mp
, tp
, start
, len
, 1, &end
, &matches
);