]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/rt.c
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
14 #include "err_protos.h"
17 #define xfs_highbit64 libxfs_highbit64 /* for XFS_RTBLOCKLOG macro */
20 rtinit(xfs_mount_t
*mp
)
22 if (mp
->m_sb
.sb_rblocks
== 0)
26 * realtime init -- blockmap initialization is
27 * handled by incore_init()
30 sumfile = calloc(mp->m_rsumsize, 1);
32 if ((btmcompute
= calloc(mp
->m_sb
.sb_rbmblocks
*
33 mp
->m_sb
.sb_blocksize
, 1)) == NULL
)
35 _("couldn't allocate memory for incore realtime bitmap.\n"));
37 if ((sumcompute
= calloc(mp
->m_rsumsize
, 1)) == NULL
)
39 _("couldn't allocate memory for incore realtime summary info.\n"));
43 * generate the real-time bitmap and summary info based on the
44 * incore realtime extent map.
47 generate_rtinfo(xfs_mount_t
*mp
,
49 xfs_suminfo_t
*sumcompute
)
52 xfs_rtblock_t start_ext
;
64 ASSERT(mp
->m_rbmip
== NULL
);
66 bitsperblock
= mp
->m_sb
.sb_blocksize
* NBBY
;
67 extno
= start_ext
= 0;
68 bmbno
= in_extent
= start_bmbno
= 0;
71 * slower but simple, don't play around with trying to set
72 * things one word at a time, just set bit as required.
73 * Have to * track start and end (size) of each range of
74 * free extents to set the summary info properly.
76 while (extno
< mp
->m_sb
.sb_rextents
) {
80 for (i
= 0; i
< sizeof(xfs_rtword_t
) * NBBY
&&
81 extno
< mp
->m_sb
.sb_rextents
; i
++, extno
++) {
82 if (get_rtbmap(extno
) == XR_E_FREE
) {
91 } else if (in_extent
== 1) {
92 len
= (int) (extno
- start_ext
);
93 log
= XFS_RTBLOCKLOG(len
);
94 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
104 if (extno
% bitsperblock
== 0)
107 if (in_extent
== 1) {
108 len
= (int) (extno
- start_ext
);
109 log
= XFS_RTBLOCKLOG(len
);
110 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
119 * returns 1 if bad, 0 if good
122 check_summary(xfs_mount_t
*mp
)
133 for (log
= 0; log
< mp
->m_rsumlevels
; log
++) {
135 bno
< mp
->m_sb
.sb_rbmblocks
;
136 bno
++, csp
++, fsp
++) {
139 _("rt summary mismatch, size %d block %llu, file: %d, computed: %d\n"),
140 log
, bno
, *fsp
, *csp
);
150 * examine the real-time bitmap file and compute summary
151 * info off it. Should probably be changed to compute
152 * the summary information off the incore computed bitmap
153 * instead of the realtime bitmap file
156 process_rtbitmap(xfs_mount_t
*mp
,
177 ASSERT(mp
->m_rbmip
== NULL
);
179 bitsperblock
= mp
->m_sb
.sb_blocksize
* NBBY
;
184 end_bmbno
= howmany(be64_to_cpu(dino
->di_size
),
185 mp
->m_sb
.sb_blocksize
);
187 for (bmbno
= 0; bmbno
< end_bmbno
; bmbno
++) {
188 bno
= blkmap_get(blkmap
, bmbno
);
190 if (bno
== NULLFSBLOCK
) {
191 do_warn(_("can't find block %d for rtbitmap inode\n"),
196 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, bno
),
197 XFS_FSB_TO_BB(mp
, 1), NULL
);
199 do_warn(_("can't read block %d for rtbitmap inode\n"),
204 words
= (xfs_rtword_t
*)bp
->b_un
.b_addr
;
206 bit
< bitsperblock
&& extno
< mp
->m_sb
.sb_rextents
;
208 if (xfs_isset(words
, bit
)) {
209 set_rtbmap(extno
, XR_E_FREE
);
216 } else if (prevbit
== 1) {
217 len
= (bmbno
- start_bmbno
) * bitsperblock
+
219 log
= XFS_RTBLOCKLOG(len
);
220 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
226 if (extno
== mp
->m_sb
.sb_rextents
)
230 len
= (bmbno
- start_bmbno
) * bitsperblock
+ (bit
- start_bit
);
231 log
= XFS_RTBLOCKLOG(len
);
232 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
238 * copy the real-time summary file data into memory
241 process_rtsummary(xfs_mount_t
*mp
,
250 for (sumbno
= 0; sumbno
< blkmap
->count
; sumbno
++) {
251 bno
= blkmap_get(blkmap
, sumbno
);
252 if (bno
== NULLFSBLOCK
) {
253 do_warn(_("block %d for rtsummary inode is missing\n"),
258 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, bno
),
259 XFS_FSB_TO_BB(mp
, 1), NULL
);
261 do_warn(_("can't read block %d for rtsummary inode\n"),
266 bytes
= bp
->b_un
.b_addr
;
267 memmove((char *)sumfile
+ sumbno
* mp
->m_sb
.sb_blocksize
, bytes
,
268 mp
->m_sb
.sb_blocksize
);