1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1998-12-03 02:41:11 +00:00
|
|
|
#if 0
|
2002-08-25 13:10:45 +00:00
|
|
|
#ifndef lint
|
1997-03-11 12:20:21 +00:00
|
|
|
static const char sccsid[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95";
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
2002-08-25 13:10:45 +00:00
|
|
|
#endif
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2001-03-21 09:48:03 +00:00
|
|
|
#include <sys/sysctl.h>
|
1997-03-11 12:20:21 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
1997-03-12 17:01:11 +00:00
|
|
|
|
1997-03-11 12:20:21 +00:00
|
|
|
#include <err.h>
|
The recomputation of file system summary at mount time can be a
very slow process, especially for large file systems that is just
recovered from a crash.
Since the summary is already re-sync'ed every 30 second, we will
not lag behind too much after a crash. With this consideration
in mind, it is more reasonable to transfer the responsibility to
background fsck, to reduce the delay after a crash.
Add a new sysctl variable, vfs.ffs.compute_summary_at_mount, to
control this behavior. When set to nonzero, we will get the
"old" behavior, that the summary is computed immediately at mount
time.
Add five new sysctl variables to adjust ndir, nbfree, nifree,
nffree and numclusters respectively. Teach fsck_ffs about these
API, however, intentionally not to check the existence, since
kernels without these sysctls must have recomputed the summary
and hence no adjustments are necessary.
This change has eliminated the usual tens of minutes of delay of
mounting large dirty volumes.
Reviewed by: mckusick
MFC After: 1 week
2005-02-20 08:02:15 +00:00
|
|
|
#include <inttypes.h>
|
2002-09-25 04:06:37 +00:00
|
|
|
#include <limits.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <string.h>
|
2010-04-24 07:05:35 +00:00
|
|
|
#include <libufs.h>
|
1997-03-11 12:20:21 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#include "fsck.h"
|
|
|
|
|
2011-07-15 15:43:40 +00:00
|
|
|
static void check_maps(u_char *, u_char *, int, ufs2_daddr_t, const char *,
|
|
|
|
int *, int, int, int);
|
2011-04-29 23:00:23 +00:00
|
|
|
static void clear_blocks(ufs2_daddr_t start, ufs2_daddr_t end);
|
|
|
|
|
1995-04-02 14:52:29 +00:00
|
|
|
void
|
2002-03-20 22:57:10 +00:00
|
|
|
pass5(void)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
int c, i, j, blk, frags, basesize, mapsize;
|
2001-03-21 09:48:03 +00:00
|
|
|
int inomapsize, blkmapsize;
|
1997-03-11 12:20:21 +00:00
|
|
|
struct fs *fs = &sblock;
|
2011-04-29 23:00:23 +00:00
|
|
|
ufs2_daddr_t d, dbase, dmax, start;
|
2011-07-15 15:43:40 +00:00
|
|
|
int rewritecg = 0;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct csum *cs;
|
2002-06-21 06:18:05 +00:00
|
|
|
struct csum_total cstotal;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct inodesc idesc[3];
|
|
|
|
char buf[MAXBSIZE];
|
2013-03-23 20:00:02 +00:00
|
|
|
struct cg *cg, *newcg = (struct cg *)buf;
|
|
|
|
struct bufarea *cgbp;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2017-02-15 19:50:26 +00:00
|
|
|
inoinfo(UFS_WINO)->ino_state = USTATE;
|
1997-03-11 12:20:21 +00:00
|
|
|
memset(newcg, 0, (size_t)fs->fs_cgsize);
|
1994-05-26 06:35:07 +00:00
|
|
|
newcg->cg_niblk = fs->fs_ipg;
|
1997-03-11 12:20:21 +00:00
|
|
|
if (cvtlevel >= 3) {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (fs->fs_maxcontig < 2 && fs->fs_contigsumsize > 0) {
|
|
|
|
if (preen)
|
|
|
|
pwarn("DELETING CLUSTERING MAPS\n");
|
|
|
|
if (preen || reply("DELETE CLUSTERING MAPS")) {
|
|
|
|
fs->fs_contigsumsize = 0;
|
2002-05-12 23:44:15 +00:00
|
|
|
rewritecg = 1;
|
1994-05-26 06:35:07 +00:00
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fs->fs_maxcontig > 1) {
|
2016-04-12 22:55:47 +00:00
|
|
|
const char *doit = NULL;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
if (fs->fs_contigsumsize < 1) {
|
|
|
|
doit = "CREAT";
|
|
|
|
} else if (fs->fs_contigsumsize < fs->fs_maxcontig &&
|
|
|
|
fs->fs_contigsumsize < FS_MAXCONTIG) {
|
|
|
|
doit = "EXPAND";
|
|
|
|
}
|
|
|
|
if (doit) {
|
|
|
|
i = fs->fs_contigsumsize;
|
|
|
|
fs->fs_contigsumsize =
|
|
|
|
MIN(fs->fs_maxcontig, FS_MAXCONTIG);
|
2001-03-21 09:48:03 +00:00
|
|
|
if (CGSIZE(fs) > (u_int)fs->fs_bsize) {
|
1994-05-26 06:35:07 +00:00
|
|
|
pwarn("CANNOT %s CLUSTER MAPS\n", doit);
|
|
|
|
fs->fs_contigsumsize = i;
|
|
|
|
} else if (preen ||
|
|
|
|
reply("CREATE CLUSTER MAPS")) {
|
|
|
|
if (preen)
|
|
|
|
pwarn("%sING CLUSTER MAPS\n",
|
|
|
|
doit);
|
|
|
|
fs->fs_cgsize =
|
|
|
|
fragroundup(fs, CGSIZE(fs));
|
2002-05-12 23:44:15 +00:00
|
|
|
rewritecg = 1;
|
1994-05-26 06:35:07 +00:00
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
basesize = &newcg->cg_space[0] - (u_char *)(&newcg->cg_firstfield);
|
|
|
|
if (sblock.fs_magic == FS_UFS2_MAGIC) {
|
|
|
|
newcg->cg_iusedoff = basesize;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We reserve the space for the old rotation summary
|
|
|
|
* tables for the benefit of old kernels, but do not
|
|
|
|
* maintain them in modern kernels. In time, they can
|
|
|
|
* go away.
|
|
|
|
*/
|
|
|
|
newcg->cg_old_btotoff = basesize;
|
|
|
|
newcg->cg_old_boff = newcg->cg_old_btotoff +
|
|
|
|
fs->fs_old_cpg * sizeof(int32_t);
|
|
|
|
newcg->cg_iusedoff = newcg->cg_old_boff +
|
|
|
|
fs->fs_old_cpg * fs->fs_old_nrpos * sizeof(u_int16_t);
|
|
|
|
memset(&newcg->cg_space[0], 0, newcg->cg_iusedoff - basesize);
|
|
|
|
}
|
2002-09-25 04:06:37 +00:00
|
|
|
inomapsize = howmany(fs->fs_ipg, CHAR_BIT);
|
2002-06-21 06:18:05 +00:00
|
|
|
newcg->cg_freeoff = newcg->cg_iusedoff + inomapsize;
|
2002-09-25 04:06:37 +00:00
|
|
|
blkmapsize = howmany(fs->fs_fpg, CHAR_BIT);
|
2002-06-21 06:18:05 +00:00
|
|
|
newcg->cg_nextfreeoff = newcg->cg_freeoff + blkmapsize;
|
|
|
|
if (fs->fs_contigsumsize > 0) {
|
|
|
|
newcg->cg_clustersumoff = newcg->cg_nextfreeoff -
|
|
|
|
sizeof(u_int32_t);
|
|
|
|
newcg->cg_clustersumoff =
|
|
|
|
roundup(newcg->cg_clustersumoff, sizeof(u_int32_t));
|
|
|
|
newcg->cg_clusteroff = newcg->cg_clustersumoff +
|
|
|
|
(fs->fs_contigsumsize + 1) * sizeof(u_int32_t);
|
|
|
|
newcg->cg_nextfreeoff = newcg->cg_clusteroff +
|
2002-09-25 04:06:37 +00:00
|
|
|
howmany(fragstoblks(fs, fs->fs_fpg), CHAR_BIT);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
newcg->cg_magic = CG_MAGIC;
|
|
|
|
mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff;
|
1997-03-11 12:20:21 +00:00
|
|
|
memset(&idesc[0], 0, sizeof idesc);
|
2002-05-12 23:44:15 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
1994-05-26 06:35:07 +00:00
|
|
|
idesc[i].id_type = ADDR;
|
2002-06-21 06:18:05 +00:00
|
|
|
memset(&cstotal, 0, sizeof(struct csum_total));
|
|
|
|
dmax = blknum(fs, fs->fs_size + fs->fs_frag - 1);
|
|
|
|
for (d = fs->fs_size; d < dmax; d++)
|
|
|
|
setbmap(d);
|
1994-05-26 06:35:07 +00:00
|
|
|
for (c = 0; c < fs->fs_ncg; c++) {
|
2000-12-15 14:23:55 +00:00
|
|
|
if (got_siginfo) {
|
|
|
|
printf("%s: phase 5: cyl group %d of %d (%d%%)\n",
|
|
|
|
cdevname, c, sblock.fs_ncg,
|
|
|
|
c * 100 / sblock.fs_ncg);
|
|
|
|
got_siginfo = 0;
|
|
|
|
}
|
2004-02-28 07:50:42 +00:00
|
|
|
if (got_sigalarm) {
|
2004-03-30 20:01:25 +00:00
|
|
|
setproctitle("%s p5 %d%%", cdevname,
|
2004-02-28 07:50:42 +00:00
|
|
|
c * 100 / sblock.fs_ncg);
|
|
|
|
got_sigalarm = 0;
|
|
|
|
}
|
2013-03-23 20:00:02 +00:00
|
|
|
cgbp = cgget(c);
|
|
|
|
cg = cgbp->b_un.b_cg;
|
1994-05-26 06:35:07 +00:00
|
|
|
if (!cg_chkmagic(cg))
|
|
|
|
pfatal("CG %d: BAD MAGIC NUMBER\n", c);
|
2002-06-21 06:18:05 +00:00
|
|
|
newcg->cg_time = cg->cg_time;
|
|
|
|
newcg->cg_old_time = cg->cg_old_time;
|
2006-10-31 22:06:56 +00:00
|
|
|
newcg->cg_unrefs = cg->cg_unrefs;
|
2002-06-21 06:18:05 +00:00
|
|
|
newcg->cg_cgx = c;
|
1994-05-26 06:35:07 +00:00
|
|
|
dbase = cgbase(fs, c);
|
|
|
|
dmax = dbase + fs->fs_fpg;
|
|
|
|
if (dmax > fs->fs_size)
|
|
|
|
dmax = fs->fs_size;
|
|
|
|
newcg->cg_ndblk = dmax - dbase;
|
2002-06-21 06:18:05 +00:00
|
|
|
if (fs->fs_magic == FS_UFS1_MAGIC) {
|
|
|
|
if (c == fs->fs_ncg - 1)
|
|
|
|
newcg->cg_old_ncyl = howmany(newcg->cg_ndblk,
|
|
|
|
fs->fs_fpg / fs->fs_old_cpg);
|
|
|
|
else
|
|
|
|
newcg->cg_old_ncyl = fs->fs_old_cpg;
|
|
|
|
newcg->cg_old_niblk = fs->fs_ipg;
|
|
|
|
newcg->cg_niblk = 0;
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
if (fs->fs_contigsumsize > 0)
|
|
|
|
newcg->cg_nclusterblks = newcg->cg_ndblk / fs->fs_frag;
|
|
|
|
newcg->cg_cs.cs_ndir = 0;
|
|
|
|
newcg->cg_cs.cs_nffree = 0;
|
|
|
|
newcg->cg_cs.cs_nbfree = 0;
|
|
|
|
newcg->cg_cs.cs_nifree = fs->fs_ipg;
|
2002-12-13 19:47:07 +00:00
|
|
|
if (cg->cg_rotor >= 0 && cg->cg_rotor < newcg->cg_ndblk)
|
1994-05-26 06:35:07 +00:00
|
|
|
newcg->cg_rotor = cg->cg_rotor;
|
|
|
|
else
|
|
|
|
newcg->cg_rotor = 0;
|
2002-12-13 19:47:07 +00:00
|
|
|
if (cg->cg_frotor >= 0 && cg->cg_frotor < newcg->cg_ndblk)
|
1994-05-26 06:35:07 +00:00
|
|
|
newcg->cg_frotor = cg->cg_frotor;
|
|
|
|
else
|
|
|
|
newcg->cg_frotor = 0;
|
2002-12-13 19:47:07 +00:00
|
|
|
if (cg->cg_irotor >= 0 && cg->cg_irotor < fs->fs_ipg)
|
1994-05-26 06:35:07 +00:00
|
|
|
newcg->cg_irotor = cg->cg_irotor;
|
|
|
|
else
|
|
|
|
newcg->cg_irotor = 0;
|
2002-06-21 06:18:05 +00:00
|
|
|
if (fs->fs_magic == FS_UFS1_MAGIC) {
|
|
|
|
newcg->cg_initediblk = 0;
|
|
|
|
} else {
|
|
|
|
if ((unsigned)cg->cg_initediblk > fs->fs_ipg)
|
|
|
|
newcg->cg_initediblk = fs->fs_ipg;
|
|
|
|
else
|
|
|
|
newcg->cg_initediblk = cg->cg_initediblk;
|
|
|
|
}
|
1997-03-11 12:20:21 +00:00
|
|
|
memset(&newcg->cg_frsum[0], 0, sizeof newcg->cg_frsum);
|
2002-06-21 06:18:05 +00:00
|
|
|
memset(cg_inosused(newcg), 0, (size_t)(mapsize));
|
1994-05-26 06:35:07 +00:00
|
|
|
j = fs->fs_ipg * c;
|
1998-12-03 02:27:35 +00:00
|
|
|
for (i = 0; i < inostathead[c].il_numalloced; j++, i++) {
|
|
|
|
switch (inoinfo(j)->ino_state) {
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
case USTATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSTATE:
|
|
|
|
case DCLEAR:
|
|
|
|
case DFOUND:
|
2004-10-08 20:44:47 +00:00
|
|
|
case DZLINK:
|
1994-05-26 06:35:07 +00:00
|
|
|
newcg->cg_cs.cs_ndir++;
|
2002-08-25 13:10:45 +00:00
|
|
|
/* FALLTHROUGH */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
case FSTATE:
|
|
|
|
case FCLEAR:
|
2004-10-08 20:44:47 +00:00
|
|
|
case FZLINK:
|
1994-05-26 06:35:07 +00:00
|
|
|
newcg->cg_cs.cs_nifree--;
|
|
|
|
setbit(cg_inosused(newcg), i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-02-15 19:50:26 +00:00
|
|
|
if (j < (int)UFS_ROOTINO)
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
2001-11-17 23:48:21 +00:00
|
|
|
errx(EEXIT, "BAD STATE %d FOR INODE I=%d",
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(j)->ino_state, j);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c == 0)
|
2017-02-15 19:50:26 +00:00
|
|
|
for (i = 0; i < (int)UFS_ROOTINO; i++) {
|
1994-05-26 06:35:07 +00:00
|
|
|
setbit(cg_inosused(newcg), i);
|
|
|
|
newcg->cg_cs.cs_nifree--;
|
|
|
|
}
|
2011-04-29 23:00:23 +00:00
|
|
|
start = -1;
|
1994-05-26 06:35:07 +00:00
|
|
|
for (i = 0, d = dbase;
|
|
|
|
d < dmax;
|
|
|
|
d += fs->fs_frag, i += fs->fs_frag) {
|
|
|
|
frags = 0;
|
|
|
|
for (j = 0; j < fs->fs_frag; j++) {
|
2011-04-29 23:00:23 +00:00
|
|
|
if (testbmap(d + j)) {
|
2013-04-29 20:13:09 +00:00
|
|
|
if ((Eflag || Zflag) && start != -1) {
|
2011-04-29 23:00:23 +00:00
|
|
|
clear_blocks(start, d + j - 1);
|
|
|
|
start = -1;
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
continue;
|
2011-04-29 23:00:23 +00:00
|
|
|
}
|
|
|
|
if (start == -1)
|
|
|
|
start = d + j;
|
1994-05-26 06:35:07 +00:00
|
|
|
setbit(cg_blksfree(newcg), i + j);
|
|
|
|
frags++;
|
|
|
|
}
|
|
|
|
if (frags == fs->fs_frag) {
|
|
|
|
newcg->cg_cs.cs_nbfree++;
|
|
|
|
if (fs->fs_contigsumsize > 0)
|
|
|
|
setbit(cg_clustersfree(newcg),
|
|
|
|
i / fs->fs_frag);
|
|
|
|
} else if (frags > 0) {
|
|
|
|
newcg->cg_cs.cs_nffree += frags;
|
|
|
|
blk = blkmap(fs, cg_blksfree(newcg), i);
|
|
|
|
ffs_fragacct(fs, blk, newcg->cg_frsum, 1);
|
|
|
|
}
|
|
|
|
}
|
2013-04-29 20:13:09 +00:00
|
|
|
if ((Eflag || Zflag) && start != -1)
|
2011-04-29 23:00:23 +00:00
|
|
|
clear_blocks(start, d - 1);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (fs->fs_contigsumsize > 0) {
|
1997-03-11 12:20:21 +00:00
|
|
|
int32_t *sump = cg_clustersum(newcg);
|
1994-05-26 06:35:07 +00:00
|
|
|
u_char *mapp = cg_clustersfree(newcg);
|
|
|
|
int map = *mapp++;
|
|
|
|
int bit = 1;
|
|
|
|
int run = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < newcg->cg_nclusterblks; i++) {
|
|
|
|
if ((map & bit) != 0) {
|
|
|
|
run++;
|
|
|
|
} else if (run != 0) {
|
|
|
|
if (run > fs->fs_contigsumsize)
|
|
|
|
run = fs->fs_contigsumsize;
|
|
|
|
sump[run]++;
|
|
|
|
run = 0;
|
|
|
|
}
|
2002-09-25 04:06:37 +00:00
|
|
|
if ((i & (CHAR_BIT - 1)) != (CHAR_BIT - 1)) {
|
1994-05-26 06:35:07 +00:00
|
|
|
bit <<= 1;
|
|
|
|
} else {
|
|
|
|
map = *mapp++;
|
|
|
|
bit = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (run != 0) {
|
|
|
|
if (run > fs->fs_contigsumsize)
|
|
|
|
run = fs->fs_contigsumsize;
|
|
|
|
sump[run]++;
|
|
|
|
}
|
|
|
|
}
|
2008-10-13 14:01:05 +00:00
|
|
|
if (bkgrdflag != 0) {
|
|
|
|
cstotal.cs_nffree += cg->cg_cs.cs_nffree;
|
|
|
|
cstotal.cs_nbfree += cg->cg_cs.cs_nbfree;
|
|
|
|
cstotal.cs_nifree += cg->cg_cs.cs_nifree;
|
|
|
|
cstotal.cs_ndir += cg->cg_cs.cs_ndir;
|
|
|
|
} else {
|
|
|
|
cstotal.cs_nffree += newcg->cg_cs.cs_nffree;
|
|
|
|
cstotal.cs_nbfree += newcg->cg_cs.cs_nbfree;
|
|
|
|
cstotal.cs_nifree += newcg->cg_cs.cs_nifree;
|
|
|
|
cstotal.cs_ndir += newcg->cg_cs.cs_ndir;
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
cs = &fs->fs_cs(fs, c);
|
2001-03-21 09:48:03 +00:00
|
|
|
if (cursnapshot == 0 &&
|
|
|
|
memcmp(&newcg->cg_cs, cs, sizeof *cs) != 0 &&
|
1994-05-26 06:35:07 +00:00
|
|
|
dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
|
1997-03-11 12:20:21 +00:00
|
|
|
memmove(cs, &newcg->cg_cs, sizeof *cs);
|
1994-05-26 06:35:07 +00:00
|
|
|
sbdirty();
|
|
|
|
}
|
2002-05-12 23:44:15 +00:00
|
|
|
if (rewritecg) {
|
1997-03-11 12:20:21 +00:00
|
|
|
memmove(cg, newcg, (size_t)fs->fs_cgsize);
|
2013-03-23 20:00:02 +00:00
|
|
|
dirty(cgbp);
|
1994-05-26 06:35:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-03-21 09:48:03 +00:00
|
|
|
if (cursnapshot == 0 &&
|
2002-06-21 06:18:05 +00:00
|
|
|
memcmp(newcg, cg, basesize) != 0 &&
|
1994-05-26 06:35:07 +00:00
|
|
|
dofix(&idesc[2], "SUMMARY INFORMATION BAD")) {
|
1997-03-11 12:20:21 +00:00
|
|
|
memmove(cg, newcg, (size_t)basesize);
|
2013-03-23 20:00:02 +00:00
|
|
|
dirty(cgbp);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2011-07-15 15:43:40 +00:00
|
|
|
if (bkgrdflag != 0 || usedsoftdep || debug)
|
|
|
|
update_maps(cg, newcg, bkgrdflag);
|
2001-03-21 09:48:03 +00:00
|
|
|
if (cursnapshot == 0 &&
|
|
|
|
memcmp(cg_inosused(newcg), cg_inosused(cg), mapsize) != 0 &&
|
1998-03-08 09:59:44 +00:00
|
|
|
dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) {
|
|
|
|
memmove(cg_inosused(cg), cg_inosused(newcg),
|
|
|
|
(size_t)mapsize);
|
2013-03-23 20:00:02 +00:00
|
|
|
dirty(cgbp);
|
1998-03-08 09:59:44 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2001-03-21 09:48:03 +00:00
|
|
|
if (cursnapshot == 0 &&
|
2002-06-21 06:18:05 +00:00
|
|
|
memcmp(&cstotal, &fs->fs_cstotal, sizeof cstotal) != 0
|
|
|
|
&& dofix(&idesc[0], "SUMMARY BLK COUNT(S) WRONG IN SUPERBLK")) {
|
|
|
|
memmove(&fs->fs_cstotal, &cstotal, sizeof cstotal);
|
1994-05-26 06:35:07 +00:00
|
|
|
fs->fs_ronly = 0;
|
1998-12-03 02:27:35 +00:00
|
|
|
fs->fs_fmod = 0;
|
1994-05-26 06:35:07 +00:00
|
|
|
sbdirty();
|
|
|
|
}
|
The recomputation of file system summary at mount time can be a
very slow process, especially for large file systems that is just
recovered from a crash.
Since the summary is already re-sync'ed every 30 second, we will
not lag behind too much after a crash. With this consideration
in mind, it is more reasonable to transfer the responsibility to
background fsck, to reduce the delay after a crash.
Add a new sysctl variable, vfs.ffs.compute_summary_at_mount, to
control this behavior. When set to nonzero, we will get the
"old" behavior, that the summary is computed immediately at mount
time.
Add five new sysctl variables to adjust ndir, nbfree, nifree,
nffree and numclusters respectively. Teach fsck_ffs about these
API, however, intentionally not to check the existence, since
kernels without these sysctls must have recomputed the summary
and hence no adjustments are necessary.
This change has eliminated the usual tens of minutes of delay of
mounting large dirty volumes.
Reviewed by: mckusick
MFC After: 1 week
2005-02-20 08:02:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When doing background fsck on a snapshot, figure out whether
|
|
|
|
* the superblock summary is inaccurate and correct it when
|
|
|
|
* necessary.
|
|
|
|
*/
|
|
|
|
if (cursnapshot != 0) {
|
|
|
|
cmd.size = 1;
|
|
|
|
|
|
|
|
cmd.value = cstotal.cs_ndir - fs->fs_cstotal.cs_ndir;
|
|
|
|
if (cmd.value != 0) {
|
|
|
|
if (debug)
|
|
|
|
printf("adjndir by %+" PRIi64 "\n", cmd.value);
|
2005-03-07 08:42:49 +00:00
|
|
|
if (bkgrdsumadj == 0 || sysctl(adjndir, MIBSIZE, 0, 0,
|
The recomputation of file system summary at mount time can be a
very slow process, especially for large file systems that is just
recovered from a crash.
Since the summary is already re-sync'ed every 30 second, we will
not lag behind too much after a crash. With this consideration
in mind, it is more reasonable to transfer the responsibility to
background fsck, to reduce the delay after a crash.
Add a new sysctl variable, vfs.ffs.compute_summary_at_mount, to
control this behavior. When set to nonzero, we will get the
"old" behavior, that the summary is computed immediately at mount
time.
Add five new sysctl variables to adjust ndir, nbfree, nifree,
nffree and numclusters respectively. Teach fsck_ffs about these
API, however, intentionally not to check the existence, since
kernels without these sysctls must have recomputed the summary
and hence no adjustments are necessary.
This change has eliminated the usual tens of minutes of delay of
mounting large dirty volumes.
Reviewed by: mckusick
MFC After: 1 week
2005-02-20 08:02:15 +00:00
|
|
|
&cmd, sizeof cmd) == -1)
|
|
|
|
rwerror("ADJUST NUMBER OF DIRECTORIES", cmd.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.value = cstotal.cs_nbfree - fs->fs_cstotal.cs_nbfree;
|
|
|
|
if (cmd.value != 0) {
|
|
|
|
if (debug)
|
|
|
|
printf("adjnbfree by %+" PRIi64 "\n", cmd.value);
|
2005-03-07 08:42:49 +00:00
|
|
|
if (bkgrdsumadj == 0 || sysctl(adjnbfree, MIBSIZE, 0, 0,
|
The recomputation of file system summary at mount time can be a
very slow process, especially for large file systems that is just
recovered from a crash.
Since the summary is already re-sync'ed every 30 second, we will
not lag behind too much after a crash. With this consideration
in mind, it is more reasonable to transfer the responsibility to
background fsck, to reduce the delay after a crash.
Add a new sysctl variable, vfs.ffs.compute_summary_at_mount, to
control this behavior. When set to nonzero, we will get the
"old" behavior, that the summary is computed immediately at mount
time.
Add five new sysctl variables to adjust ndir, nbfree, nifree,
nffree and numclusters respectively. Teach fsck_ffs about these
API, however, intentionally not to check the existence, since
kernels without these sysctls must have recomputed the summary
and hence no adjustments are necessary.
This change has eliminated the usual tens of minutes of delay of
mounting large dirty volumes.
Reviewed by: mckusick
MFC After: 1 week
2005-02-20 08:02:15 +00:00
|
|
|
&cmd, sizeof cmd) == -1)
|
|
|
|
rwerror("ADJUST NUMBER OF FREE BLOCKS", cmd.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.value = cstotal.cs_nifree - fs->fs_cstotal.cs_nifree;
|
|
|
|
if (cmd.value != 0) {
|
|
|
|
if (debug)
|
|
|
|
printf("adjnifree by %+" PRIi64 "\n", cmd.value);
|
2005-03-07 08:42:49 +00:00
|
|
|
if (bkgrdsumadj == 0 || sysctl(adjnifree, MIBSIZE, 0, 0,
|
The recomputation of file system summary at mount time can be a
very slow process, especially for large file systems that is just
recovered from a crash.
Since the summary is already re-sync'ed every 30 second, we will
not lag behind too much after a crash. With this consideration
in mind, it is more reasonable to transfer the responsibility to
background fsck, to reduce the delay after a crash.
Add a new sysctl variable, vfs.ffs.compute_summary_at_mount, to
control this behavior. When set to nonzero, we will get the
"old" behavior, that the summary is computed immediately at mount
time.
Add five new sysctl variables to adjust ndir, nbfree, nifree,
nffree and numclusters respectively. Teach fsck_ffs about these
API, however, intentionally not to check the existence, since
kernels without these sysctls must have recomputed the summary
and hence no adjustments are necessary.
This change has eliminated the usual tens of minutes of delay of
mounting large dirty volumes.
Reviewed by: mckusick
MFC After: 1 week
2005-02-20 08:02:15 +00:00
|
|
|
&cmd, sizeof cmd) == -1)
|
|
|
|
rwerror("ADJUST NUMBER OF FREE INODES", cmd.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.value = cstotal.cs_nffree - fs->fs_cstotal.cs_nffree;
|
|
|
|
if (cmd.value != 0) {
|
|
|
|
if (debug)
|
|
|
|
printf("adjnffree by %+" PRIi64 "\n", cmd.value);
|
2005-03-07 08:42:49 +00:00
|
|
|
if (bkgrdsumadj == 0 || sysctl(adjnffree, MIBSIZE, 0, 0,
|
The recomputation of file system summary at mount time can be a
very slow process, especially for large file systems that is just
recovered from a crash.
Since the summary is already re-sync'ed every 30 second, we will
not lag behind too much after a crash. With this consideration
in mind, it is more reasonable to transfer the responsibility to
background fsck, to reduce the delay after a crash.
Add a new sysctl variable, vfs.ffs.compute_summary_at_mount, to
control this behavior. When set to nonzero, we will get the
"old" behavior, that the summary is computed immediately at mount
time.
Add five new sysctl variables to adjust ndir, nbfree, nifree,
nffree and numclusters respectively. Teach fsck_ffs about these
API, however, intentionally not to check the existence, since
kernels without these sysctls must have recomputed the summary
and hence no adjustments are necessary.
This change has eliminated the usual tens of minutes of delay of
mounting large dirty volumes.
Reviewed by: mckusick
MFC After: 1 week
2005-02-20 08:02:15 +00:00
|
|
|
&cmd, sizeof cmd) == -1)
|
|
|
|
rwerror("ADJUST NUMBER OF FREE FRAGS", cmd.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.value = cstotal.cs_numclusters - fs->fs_cstotal.cs_numclusters;
|
|
|
|
if (cmd.value != 0) {
|
|
|
|
if (debug)
|
|
|
|
printf("adjnumclusters by %+" PRIi64 "\n", cmd.value);
|
2005-03-07 08:42:49 +00:00
|
|
|
if (bkgrdsumadj == 0 || sysctl(adjnumclusters, MIBSIZE, 0, 0,
|
The recomputation of file system summary at mount time can be a
very slow process, especially for large file systems that is just
recovered from a crash.
Since the summary is already re-sync'ed every 30 second, we will
not lag behind too much after a crash. With this consideration
in mind, it is more reasonable to transfer the responsibility to
background fsck, to reduce the delay after a crash.
Add a new sysctl variable, vfs.ffs.compute_summary_at_mount, to
control this behavior. When set to nonzero, we will get the
"old" behavior, that the summary is computed immediately at mount
time.
Add five new sysctl variables to adjust ndir, nbfree, nifree,
nffree and numclusters respectively. Teach fsck_ffs about these
API, however, intentionally not to check the existence, since
kernels without these sysctls must have recomputed the summary
and hence no adjustments are necessary.
This change has eliminated the usual tens of minutes of delay of
mounting large dirty volumes.
Reviewed by: mckusick
MFC After: 1 week
2005-02-20 08:02:15 +00:00
|
|
|
&cmd, sizeof cmd) == -1)
|
|
|
|
rwerror("ADJUST NUMBER OF FREE CLUSTERS", cmd.value);
|
|
|
|
}
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2001-03-21 09:48:03 +00:00
|
|
|
|
2011-07-15 15:43:40 +00:00
|
|
|
/*
|
|
|
|
* Compare the original cylinder group inode and block bitmaps with the
|
|
|
|
* updated cylinder group inode and block bitmaps. Free inodes and blocks
|
|
|
|
* that have been added. Complain if any previously freed inodes blocks
|
|
|
|
* are now allocated.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
update_maps(
|
|
|
|
struct cg *oldcg, /* cylinder group of claimed allocations */
|
|
|
|
struct cg *newcg, /* cylinder group of determined allocations */
|
|
|
|
int usesysctl) /* 1 => use sysctl interface to update maps */
|
|
|
|
{
|
|
|
|
int inomapsize, excessdirs;
|
|
|
|
struct fs *fs = &sblock;
|
|
|
|
|
|
|
|
inomapsize = howmany(fs->fs_ipg, CHAR_BIT);
|
|
|
|
excessdirs = oldcg->cg_cs.cs_ndir - newcg->cg_cs.cs_ndir;
|
|
|
|
if (excessdirs < 0) {
|
|
|
|
pfatal("LOST %d DIRECTORIES\n", -excessdirs);
|
|
|
|
excessdirs = 0;
|
|
|
|
}
|
|
|
|
if (excessdirs > 0)
|
|
|
|
check_maps(cg_inosused(newcg), cg_inosused(oldcg), inomapsize,
|
|
|
|
oldcg->cg_cgx * (ufs2_daddr_t)fs->fs_ipg, "DIR", freedirs,
|
|
|
|
0, excessdirs, usesysctl);
|
|
|
|
check_maps(cg_inosused(newcg), cg_inosused(oldcg), inomapsize,
|
|
|
|
oldcg->cg_cgx * (ufs2_daddr_t)fs->fs_ipg, "FILE", freefiles,
|
|
|
|
excessdirs, fs->fs_ipg, usesysctl);
|
|
|
|
check_maps(cg_blksfree(oldcg), cg_blksfree(newcg),
|
|
|
|
howmany(fs->fs_fpg, CHAR_BIT),
|
|
|
|
oldcg->cg_cgx * (ufs2_daddr_t)fs->fs_fpg, "FRAG",
|
|
|
|
freeblks, 0, fs->fs_fpg, usesysctl);
|
|
|
|
}
|
|
|
|
|
2001-03-21 09:48:03 +00:00
|
|
|
static void
|
2002-03-20 22:57:10 +00:00
|
|
|
check_maps(
|
|
|
|
u_char *map1, /* map of claimed allocations */
|
|
|
|
u_char *map2, /* map of determined allocations */
|
|
|
|
int mapsize, /* size of above two maps */
|
2008-10-13 13:56:23 +00:00
|
|
|
ufs2_daddr_t startvalue, /* resource value for first element in map */
|
2002-07-30 13:01:25 +00:00
|
|
|
const char *name, /* name of resource found in maps */
|
2002-03-20 22:57:10 +00:00
|
|
|
int *opcode, /* sysctl opcode to free resource */
|
|
|
|
int skip, /* number of entries to skip before starting to free */
|
2011-07-15 15:43:40 +00:00
|
|
|
int limit, /* limit on number of entries to free */
|
|
|
|
int usesysctl) /* 1 => use sysctl interface to update maps */
|
2001-03-21 09:48:03 +00:00
|
|
|
{
|
|
|
|
# define BUFSIZE 16
|
|
|
|
char buf[BUFSIZE];
|
2008-10-13 13:56:23 +00:00
|
|
|
long i, j, k, l, m, size;
|
|
|
|
ufs2_daddr_t n, astart, aend, ustart, uend;
|
2002-03-20 22:57:10 +00:00
|
|
|
void (*msg)(const char *fmt, ...);
|
2001-03-21 09:48:03 +00:00
|
|
|
|
2011-07-15 15:43:40 +00:00
|
|
|
if (usesysctl)
|
2001-04-16 22:22:21 +00:00
|
|
|
msg = pfatal;
|
|
|
|
else
|
|
|
|
msg = pwarn;
|
2001-03-21 09:48:03 +00:00
|
|
|
astart = ustart = aend = uend = -1;
|
|
|
|
for (i = 0; i < mapsize; i++) {
|
|
|
|
j = *map1++;
|
|
|
|
k = *map2++;
|
|
|
|
if (j == k)
|
|
|
|
continue;
|
2002-09-25 04:06:37 +00:00
|
|
|
for (m = 0, l = 1; m < CHAR_BIT; m++, l <<= 1) {
|
2001-03-21 09:48:03 +00:00
|
|
|
if ((j & l) == (k & l))
|
|
|
|
continue;
|
2002-09-25 04:06:37 +00:00
|
|
|
n = startvalue + i * CHAR_BIT + m;
|
2001-03-21 09:48:03 +00:00
|
|
|
if ((j & l) != 0) {
|
|
|
|
if (astart == -1) {
|
|
|
|
astart = aend = n;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (aend + 1 == n) {
|
|
|
|
aend = n;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (astart == aend)
|
2008-10-13 13:56:23 +00:00
|
|
|
(*msg)("ALLOCATED %s %" PRId64
|
|
|
|
" MARKED FREE\n",
|
2001-03-21 09:48:03 +00:00
|
|
|
name, astart);
|
|
|
|
else
|
2008-10-13 13:56:23 +00:00
|
|
|
(*msg)("%s %sS %" PRId64 "-%" PRId64
|
|
|
|
" MARKED FREE\n",
|
2001-03-21 09:48:03 +00:00
|
|
|
"ALLOCATED", name, astart, aend);
|
|
|
|
astart = aend = n;
|
|
|
|
} else {
|
|
|
|
if (ustart == -1) {
|
|
|
|
ustart = uend = n;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (uend + 1 == n) {
|
|
|
|
uend = n;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
size = uend - ustart + 1;
|
|
|
|
if (size <= skip) {
|
|
|
|
skip -= size;
|
|
|
|
ustart = uend = n;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (skip > 0) {
|
|
|
|
ustart += skip;
|
|
|
|
size -= skip;
|
|
|
|
skip = 0;
|
|
|
|
}
|
|
|
|
if (size > limit)
|
|
|
|
size = limit;
|
|
|
|
if (debug && size == 1)
|
2008-10-13 13:56:23 +00:00
|
|
|
pwarn("%s %s %" PRId64
|
|
|
|
" MARKED USED\n",
|
2001-03-21 09:48:03 +00:00
|
|
|
"UNALLOCATED", name, ustart);
|
|
|
|
else if (debug)
|
2008-10-13 13:56:23 +00:00
|
|
|
pwarn("%s %sS %" PRId64 "-%" PRId64
|
|
|
|
" MARKED USED\n",
|
2001-03-21 09:48:03 +00:00
|
|
|
"UNALLOCATED", name, ustart,
|
|
|
|
ustart + size - 1);
|
2011-07-15 15:43:40 +00:00
|
|
|
if (usesysctl != 0) {
|
2001-03-21 09:48:03 +00:00
|
|
|
cmd.value = ustart;
|
|
|
|
cmd.size = size;
|
|
|
|
if (sysctl(opcode, MIBSIZE, 0, 0,
|
|
|
|
&cmd, sizeof cmd) == -1) {
|
|
|
|
snprintf(buf, BUFSIZE,
|
|
|
|
"FREE %s", name);
|
|
|
|
rwerror(buf, cmd.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
limit -= size;
|
|
|
|
if (limit <= 0)
|
|
|
|
return;
|
|
|
|
ustart = uend = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-11-17 23:48:21 +00:00
|
|
|
if (astart != -1) {
|
2001-03-21 09:48:03 +00:00
|
|
|
if (astart == aend)
|
2008-10-13 13:56:23 +00:00
|
|
|
(*msg)("ALLOCATED %s %" PRId64
|
|
|
|
" MARKED FREE\n", name, astart);
|
2001-03-21 09:48:03 +00:00
|
|
|
else
|
2008-10-13 13:56:23 +00:00
|
|
|
(*msg)("ALLOCATED %sS %" PRId64 "-%" PRId64
|
|
|
|
" MARKED FREE\n",
|
2001-03-21 09:48:03 +00:00
|
|
|
name, astart, aend);
|
2001-11-17 23:48:21 +00:00
|
|
|
}
|
2001-03-21 09:48:03 +00:00
|
|
|
if (ustart != -1) {
|
|
|
|
size = uend - ustart + 1;
|
|
|
|
if (size <= skip)
|
|
|
|
return;
|
|
|
|
if (skip > 0) {
|
|
|
|
ustart += skip;
|
|
|
|
size -= skip;
|
|
|
|
}
|
|
|
|
if (size > limit)
|
|
|
|
size = limit;
|
|
|
|
if (debug) {
|
|
|
|
if (size == 1)
|
2008-10-13 13:56:23 +00:00
|
|
|
pwarn("UNALLOCATED %s %" PRId64
|
|
|
|
" MARKED USED\n",
|
2001-03-21 09:48:03 +00:00
|
|
|
name, ustart);
|
|
|
|
else
|
2008-10-13 13:56:23 +00:00
|
|
|
pwarn("UNALLOCATED %sS %" PRId64 "-%" PRId64
|
|
|
|
" MARKED USED\n",
|
2001-03-21 09:48:03 +00:00
|
|
|
name, ustart, ustart + size - 1);
|
|
|
|
}
|
2011-07-15 15:43:40 +00:00
|
|
|
if (usesysctl != 0) {
|
2001-03-21 09:48:03 +00:00
|
|
|
cmd.value = ustart;
|
|
|
|
cmd.size = size;
|
|
|
|
if (sysctl(opcode, MIBSIZE, 0, 0, &cmd,
|
|
|
|
sizeof cmd) == -1) {
|
|
|
|
snprintf(buf, BUFSIZE, "FREE %s", name);
|
|
|
|
rwerror(buf, cmd.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-29 23:00:23 +00:00
|
|
|
|
2013-04-29 20:14:11 +00:00
|
|
|
static void
|
|
|
|
clear_blocks(ufs2_daddr_t start, ufs2_daddr_t end)
|
2011-04-29 23:00:23 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
printf("Zero frags %jd to %jd\n", start, end);
|
2013-04-29 20:13:09 +00:00
|
|
|
if (Zflag)
|
|
|
|
blzero(fswritefd, fsbtodb(&sblock, start),
|
|
|
|
lfragtosize(&sblock, end - start + 1));
|
|
|
|
if (Eflag)
|
|
|
|
blerase(fswritefd, fsbtodb(&sblock, start),
|
|
|
|
lfragtosize(&sblock, end - start + 1));
|
2011-04-29 23:00:23 +00:00
|
|
|
}
|