Make background fsck based summary adjustments actually work by

initializing the sysctl mibs data before actually using them.

The original patchset (which is the actual version that is running
on my testboxes) have checked whether all of these sysctls and
refuses to do background fsck if we don't have them.  Kirk has
pointed out that refusing running fsck on old kernels is pointless,
as old kernels will recompute the summary at mount time, so I
have removed these checks.

Unfortunatelly, as the checks will initialize the mib values of
those sysctl's, and which are vital for the runtime summary
adjustment to work, we can not simply remove the check, which
will lead to problem when running background fsck over a dirty
volume.  Add these checks in a different way: give a warning rather
than refusing to work, and complain if the functionality is not
available when adjustments are necessary.

Noticed by:	A power failure at my lab
Pointy hat:	me
MFC After:	3 days
This commit is contained in:
Xin LI 2005-03-07 08:42:49 +00:00
parent b0c2130963
commit c0ed8991fb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=143235
3 changed files with 24 additions and 5 deletions

View File

@ -272,6 +272,7 @@ int bflag; /* location of alternate super block */
int debug; /* output debugging info */
int cvtlevel; /* convert to newer file system format */
int bkgrdcheck; /* determine if background check is possible */
int bkgrdsumadj; /* whether the kernel have ability to adjust superblock summary */
char usedsoftdep; /* just fix soft dependency inconsistencies */
char preen; /* just fix normal inconsistencies */
char rerun; /* rerun fsck. Only used in non-preen mode */

View File

@ -358,7 +358,7 @@ pass5(void)
if (cmd.value != 0) {
if (debug)
printf("adjndir by %+" PRIi64 "\n", cmd.value);
if (sysctl(adjndir, MIBSIZE, 0, 0,
if (bkgrdsumadj == 0 || sysctl(adjndir, MIBSIZE, 0, 0,
&cmd, sizeof cmd) == -1)
rwerror("ADJUST NUMBER OF DIRECTORIES", cmd.value);
}
@ -367,7 +367,7 @@ pass5(void)
if (cmd.value != 0) {
if (debug)
printf("adjnbfree by %+" PRIi64 "\n", cmd.value);
if (sysctl(adjnbfree, MIBSIZE, 0, 0,
if (bkgrdsumadj == 0 || sysctl(adjnbfree, MIBSIZE, 0, 0,
&cmd, sizeof cmd) == -1)
rwerror("ADJUST NUMBER OF FREE BLOCKS", cmd.value);
}
@ -376,7 +376,7 @@ pass5(void)
if (cmd.value != 0) {
if (debug)
printf("adjnifree by %+" PRIi64 "\n", cmd.value);
if (sysctl(adjnifree, MIBSIZE, 0, 0,
if (bkgrdsumadj == 0 || sysctl(adjnifree, MIBSIZE, 0, 0,
&cmd, sizeof cmd) == -1)
rwerror("ADJUST NUMBER OF FREE INODES", cmd.value);
}
@ -385,7 +385,7 @@ pass5(void)
if (cmd.value != 0) {
if (debug)
printf("adjnffree by %+" PRIi64 "\n", cmd.value);
if (sysctl(adjnffree, MIBSIZE, 0, 0,
if (bkgrdsumadj == 0 || sysctl(adjnffree, MIBSIZE, 0, 0,
&cmd, sizeof cmd) == -1)
rwerror("ADJUST NUMBER OF FREE FRAGS", cmd.value);
}
@ -394,7 +394,7 @@ pass5(void)
if (cmd.value != 0) {
if (debug)
printf("adjnumclusters by %+" PRIi64 "\n", cmd.value);
if (sysctl(adjnumclusters, MIBSIZE, 0, 0,
if (bkgrdsumadj == 0 || sysctl(adjnumclusters, MIBSIZE, 0, 0,
&cmd, sizeof cmd) == -1)
rwerror("ADJUST NUMBER OF FREE CLUSTERS", cmd.value);
}

View File

@ -140,6 +140,24 @@ setup(char *dev)
pfatal("kernel lacks background fsck support\n");
exit(EEXIT);
}
/*
* When kernel is lack of runtime bgfsck superblock summary
* adjustment functionality, it does not mean we can not
* continue, as old kernels will recompute the summary at
* mount time. However, it will be an unexpected softupdates
* inconsistency if it turns out that the summary is still
* incorrect. Set a flag so subsequent operation can know
* this.
*/
bkgrdsumadj = 1;
if (sysctlnametomib("vfs.ffs.adjndir", adjndir, &size) < 0 ||
sysctlnametomib("vfs.ffs.adjnbfree", adjnbfree, &size) < 0 ||
sysctlnametomib("vfs.ffs.adjnifree", adjnifree, &size) < 0 ||
sysctlnametomib("vfs.ffs.adjnffree", adjnffree, &size) < 0 ||
sysctlnametomib("vfs.ffs.adjnumclusters", adjnumclusters, &size) < 0) {
bkgrdsumadj = 0;
pwarn("kernel lacks runtime superblock summary adjustment support");
}
cmd.version = FFS_CMD_VERSION;
cmd.handle = fsreadfd;
fswritefd = -1;