]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/rt.c
2 * Copyright (c) 2000-2001 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/
40 #include "err_protos.h"
43 #define xfs_highbit64 libxfs_highbit64 /* for XFS_RTBLOCKLOG macro */
46 rtinit(xfs_mount_t
*mp
)
48 if (mp
->m_sb
.sb_rblocks
== 0)
52 * realtime init -- blockmap initialization is
53 * handled by incore_init()
56 sumfile = calloc(mp->m_rsumsize, 1);
58 if ((btmcompute
= calloc(mp
->m_sb
.sb_rbmblocks
*
59 mp
->m_sb
.sb_blocksize
, 1)) == NULL
)
61 _("couldn't allocate memory for incore realtime bitmap.\n"));
63 if ((sumcompute
= calloc(mp
->m_rsumsize
, 1)) == NULL
)
65 _("couldn't allocate memory for incore realtime summary info.\n"));
69 * generate the real-time bitmap and summary info based on the
70 * incore realtime extent map.
73 generate_rtinfo(xfs_mount_t
*mp
,
75 xfs_suminfo_t
*sumcompute
)
78 xfs_drtbno_t start_ext
;
90 ASSERT(mp
->m_rbmip
== NULL
);
92 bitsperblock
= mp
->m_sb
.sb_blocksize
* NBBY
;
93 extno
= start_ext
= 0;
94 bmbno
= in_extent
= start_bmbno
= 0;
97 * slower but simple, don't play around with trying to set
98 * things one word at a time, just set bit as required.
99 * Have to * track start and end (size) of each range of
100 * free extents to set the summary info properly.
102 while (extno
< mp
->m_sb
.sb_rextents
) {
106 for (i
= 0; i
< sizeof(xfs_rtword_t
) * NBBY
&&
107 extno
< mp
->m_sb
.sb_rextents
; i
++, extno
++) {
108 if (get_rtbno_state(mp
, extno
) == XR_E_FREE
) {
112 if (in_extent
== 0) {
117 } else if (in_extent
== 1) {
118 len
= (int) (extno
- start_ext
);
119 log
= XFS_RTBLOCKLOG(len
);
120 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
130 if (extno
% bitsperblock
== 0)
133 if (in_extent
== 1) {
134 len
= (int) (extno
- start_ext
);
135 log
= XFS_RTBLOCKLOG(len
);
136 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
145 * returns 1 if bad, 0 if good
148 check_summary(xfs_mount_t
*mp
)
159 for (log
= 0; log
< mp
->m_rsumlevels
; log
++) {
161 bno
< mp
->m_sb
.sb_rbmblocks
;
162 bno
++, csp
++, fsp
++) {
165 _("rt summary mismatch, size %d block %llu, file: %d, computed: %d\n"),
166 log
, bno
, *fsp
, *csp
);
176 * examine the real-time bitmap file and compute summary
177 * info off it. Should probably be changed to compute
178 * the summary information off the incore computed bitmap
179 * instead of the realtime bitmap file
182 process_rtbitmap(xfs_mount_t
*mp
,
203 ASSERT(mp
->m_rbmip
== NULL
);
205 bitsperblock
= mp
->m_sb
.sb_blocksize
* NBBY
;
210 end_bmbno
= howmany(INT_GET(dino
->di_core
.di_size
, ARCH_CONVERT
), mp
->m_sb
.sb_blocksize
);
212 for (bmbno
= 0; bmbno
< end_bmbno
; bmbno
++) {
213 bno
= blkmap_get(blkmap
, bmbno
);
215 if (bno
== NULLDFSBNO
) {
216 do_warn(_("can't find block %d for rtbitmap inode\n"),
221 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, bno
),
222 XFS_FSB_TO_BB(mp
, 1));
224 do_warn(_("can't read block %d for rtbitmap inode\n"),
229 words
= (xfs_rtword_t
*)bp
->b_un
.b_addr
;
231 bit
< bitsperblock
&& extno
< mp
->m_sb
.sb_rextents
;
233 if (isset(words
, bit
)) {
234 set_rtbno_state(mp
, extno
, XR_E_FREE
);
241 } else if (prevbit
== 1) {
242 len
= (bmbno
- start_bmbno
) * bitsperblock
+
244 log
= XFS_RTBLOCKLOG(len
);
245 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
251 if (extno
== mp
->m_sb
.sb_rextents
)
255 len
= (bmbno
- start_bmbno
) * bitsperblock
+ (bit
- start_bit
);
256 log
= XFS_RTBLOCKLOG(len
);
257 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
263 * copy the real-time summary file data into memory
266 process_rtsummary(xfs_mount_t
*mp
,
275 for (sumbno
= 0; sumbno
< blkmap
->count
; sumbno
++) {
276 bno
= blkmap_get(blkmap
, sumbno
);
277 if (bno
== NULLDFSBNO
) {
278 do_warn(_("block %d for rtsummary inode is missing\n"),
283 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, bno
),
284 XFS_FSB_TO_BB(mp
, 1));
286 do_warn(_("can't read block %d for rtsummary inode\n"),
291 bytes
= bp
->b_un
.b_addr
;
292 bcopy(bytes
, (char *)sumfile
+ sumbno
* mp
->m_sb
.sb_blocksize
,
293 mp
->m_sb
.sb_blocksize
);