2008-08-06 00:57:45 +04:00
|
|
|
/* $NetBSD: mount_lfs.c,v 1.33 2008/08/05 20:57:45 pooka Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1993, 1994
|
|
|
|
* 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.
|
2003-08-07 14:04:22 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-06-08 22:57:30 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-09-15 08:47:17 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#ifndef lint
|
2008-07-20 05:20:21 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1993, 1994\
|
|
|
|
The Regents of the University of California. All rights reserved.");
|
1994-06-08 22:57:30 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
1997-09-16 16:26:56 +04:00
|
|
|
static char sccsid[] = "@(#)mount_lfs.c 8.4 (Berkeley) 4/26/95";
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
2008-08-06 00:57:45 +04:00
|
|
|
__RCSID("$NetBSD: mount_lfs.c,v 1.33 2008/08/05 20:57:45 pooka Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1994-06-08 22:57:30 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <ufs/ufs/ufsmount.h>
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <err.h>
|
1999-06-25 23:28:35 +04:00
|
|
|
#include <errno.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2000-11-14 01:12:49 +03:00
|
|
|
#include <paths.h>
|
|
|
|
|
|
|
|
#include <signal.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2003-03-22 14:15:45 +03:00
|
|
|
#include <mntopts.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include "pathnames.h"
|
2008-08-06 00:57:45 +04:00
|
|
|
#include "mountprog.h"
|
|
|
|
#include "mount_lfs.h"
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
static const struct mntopt mopts[] = {
|
1994-06-08 22:57:30 +04:00
|
|
|
MOPT_STDOPTS,
|
|
|
|
MOPT_UPDATE,
|
2002-09-21 22:43:31 +04:00
|
|
|
MOPT_GETARGS,
|
2003-02-18 16:16:48 +03:00
|
|
|
MOPT_NOATIME,
|
2006-10-16 07:37:42 +04:00
|
|
|
MOPT_NULL,
|
1994-06-08 22:57:30 +04:00
|
|
|
};
|
|
|
|
|
2005-02-09 17:31:29 +03:00
|
|
|
static void usage(void);
|
2008-08-06 00:57:45 +04:00
|
|
|
|
|
|
|
#ifdef WANT_CLEANER
|
|
|
|
static void invoke_cleaner(char *);
|
2005-02-09 17:31:29 +03:00
|
|
|
static void kill_daemon(char *);
|
|
|
|
static void kill_cleaner(char *);
|
2008-08-06 00:57:45 +04:00
|
|
|
#endif /* WANT_CLEANER */
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2008-08-06 00:57:45 +04:00
|
|
|
static int short_rds, cleaner_debug, cleaner_bytes, fs_idle, noclean;
|
2005-06-27 06:56:20 +04:00
|
|
|
static const char *nsegs;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
#ifndef MOUNT_NOMAIN
|
1994-06-08 22:57:30 +04:00
|
|
|
int
|
2005-02-09 17:31:29 +03:00
|
|
|
main(int argc, char **argv)
|
2000-10-30 23:56:57 +03:00
|
|
|
{
|
2008-08-06 00:57:45 +04:00
|
|
|
|
|
|
|
setprogname(argv[0]);
|
2000-10-30 23:56:57 +03:00
|
|
|
return mount_lfs(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-06 00:57:45 +04:00
|
|
|
void
|
|
|
|
mount_lfs_parseargs(int argc, char *argv[],
|
|
|
|
struct ufs_args *args, int *mntflags,
|
|
|
|
char *canon_dev, char *canon_dir)
|
1994-06-08 22:57:30 +04:00
|
|
|
{
|
2008-08-06 00:57:45 +04:00
|
|
|
int ch;
|
2005-01-31 08:19:18 +03:00
|
|
|
char *options;
|
2006-03-22 00:11:41 +03:00
|
|
|
mntoptparse_t mp;
|
2000-11-14 01:12:49 +03:00
|
|
|
|
2008-08-06 00:57:45 +04:00
|
|
|
memset(args, 0, sizeof(*args));
|
1994-06-08 22:57:30 +04:00
|
|
|
options = NULL;
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
nsegs = "4";
|
2008-08-06 00:57:45 +04:00
|
|
|
*mntflags = noclean = 0;
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
cleaner_bytes = 1;
|
2005-03-31 07:07:38 +04:00
|
|
|
while ((ch = getopt(argc, argv, "bdiN:no:s")) != -1)
|
1994-06-08 22:57:30 +04:00
|
|
|
switch (ch) {
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
case 'b':
|
|
|
|
cleaner_bytes = !cleaner_bytes;
|
|
|
|
break;
|
1994-06-08 22:57:30 +04:00
|
|
|
case 'd':
|
|
|
|
cleaner_debug = 1;
|
|
|
|
break;
|
2005-03-31 19:55:57 +04:00
|
|
|
case 'i':
|
|
|
|
fs_idle = 1;
|
|
|
|
break;
|
1994-06-08 22:57:30 +04:00
|
|
|
case 'n':
|
|
|
|
noclean = 1;
|
|
|
|
break;
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
case 'N':
|
|
|
|
nsegs = optarg;
|
|
|
|
break;
|
1994-06-08 22:57:30 +04:00
|
|
|
case 'o':
|
2008-08-06 00:57:45 +04:00
|
|
|
mp = getmntopts(optarg, mopts, mntflags, 0);
|
2006-03-22 00:11:41 +03:00
|
|
|
if (mp == NULL)
|
|
|
|
err(1, "getmntopts");
|
|
|
|
freemntopts(mp);
|
1994-06-08 22:57:30 +04:00
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
short_rds = 1;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
usage();
|
|
|
|
|
2008-08-06 00:57:45 +04:00
|
|
|
pathadj(argv[0], canon_dev);
|
|
|
|
args->fspec = canon_dev;
|
2005-01-31 08:19:18 +03:00
|
|
|
|
2008-08-06 00:57:45 +04:00
|
|
|
pathadj(argv[1], canon_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mount_lfs(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct ufs_args args;
|
|
|
|
int mntflags;
|
|
|
|
int mntsize, oldflags, i;
|
|
|
|
char fs_name[MAXPATHLEN], canon_dev[MAXPATHLEN];
|
|
|
|
struct statvfs *mntbuf;
|
|
|
|
const char *errcause;
|
|
|
|
|
|
|
|
mount_lfs_parseargs(argc, argv, &args, &mntflags, canon_dev, fs_name);
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2000-11-14 01:12:49 +03:00
|
|
|
/*
|
|
|
|
* Record the previous status of this filesystem (if any) before
|
|
|
|
* performing the mount, so we can know whether to start or
|
|
|
|
* kill the cleaner process below.
|
|
|
|
*/
|
|
|
|
oldflags = MNT_RDONLY; /* If not mounted, pretend r/o */
|
|
|
|
if (mntflags & MNT_UPDATE) {
|
|
|
|
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
|
|
|
|
err(1, "getmntinfo");
|
|
|
|
for (i = 0; i < mntsize; i++) {
|
|
|
|
if (strcmp(mntbuf[i].f_mntfromname, args.fspec) == 0) {
|
2004-04-21 05:05:31 +04:00
|
|
|
oldflags = mntbuf[i].f_flag;
|
2000-11-14 01:12:49 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-16 21:06:52 +04:00
|
|
|
if (mount(MOUNT_LFS, fs_name, mntflags, &args, sizeof args) == -1) {
|
1999-06-25 23:28:35 +04:00
|
|
|
switch (errno) {
|
|
|
|
case EMFILE:
|
|
|
|
errcause = "mount table full";
|
|
|
|
break;
|
|
|
|
case EINVAL:
|
|
|
|
if (mntflags & MNT_UPDATE)
|
|
|
|
errcause =
|
|
|
|
"specified device does not match mounted device";
|
|
|
|
else
|
|
|
|
errcause = "incorrect super block";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errcause = strerror(errno);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
errx(1, "%s on %s: %s", args.fspec, fs_name, errcause);
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2008-08-06 00:57:45 +04:00
|
|
|
#ifdef WANT_CLEANER
|
2000-11-14 01:12:49 +03:00
|
|
|
/* Not mounting fresh or upgrading to r/w; don't start the cleaner */
|
2007-07-17 16:39:24 +04:00
|
|
|
if (!(oldflags & MNT_RDONLY) || (mntflags & MNT_RDONLY)
|
|
|
|
|| (mntflags & MNT_GETARGS))
|
2000-11-14 01:12:49 +03:00
|
|
|
noclean = 1;
|
1994-06-08 22:57:30 +04:00
|
|
|
if (!noclean)
|
|
|
|
invoke_cleaner(fs_name);
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
2000-11-14 01:12:49 +03:00
|
|
|
/* Downgrade to r/o; kill the cleaner */
|
|
|
|
if ((mntflags & MNT_RDONLY) && !(oldflags & MNT_RDONLY))
|
|
|
|
kill_cleaner(fs_name);
|
2008-08-06 00:57:45 +04:00
|
|
|
#endif /* WANT_CLEANER */
|
2000-11-14 01:12:49 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2008-08-06 00:57:45 +04:00
|
|
|
#ifdef WANT_CLEANER
|
2000-11-14 01:12:49 +03:00
|
|
|
static void
|
2005-02-09 17:31:29 +03:00
|
|
|
kill_daemon(char *pidname)
|
2000-11-14 01:12:49 +03:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char s[80];
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
fp = fopen(pidname, "r");
|
|
|
|
if (fp) {
|
|
|
|
fgets(s, 80, fp);
|
|
|
|
pid = atoi(s);
|
|
|
|
if (pid)
|
|
|
|
kill(pid, SIGINT);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-02-09 17:31:29 +03:00
|
|
|
kill_cleaner(char *name)
|
2000-11-14 01:12:49 +03:00
|
|
|
{
|
|
|
|
char *pidname;
|
|
|
|
char *cp;
|
|
|
|
int off;
|
|
|
|
|
|
|
|
/* Parent first */
|
2003-07-13 11:44:33 +04:00
|
|
|
asprintf(&pidname, "%slfs_cleanerd:m:%s.pid", _PATH_VARRUN, name);
|
|
|
|
if (!pidname)
|
|
|
|
err(1, "malloc");
|
2000-11-14 01:12:49 +03:00
|
|
|
off = strlen(_PATH_VARRUN);
|
|
|
|
while((cp = strchr(pidname + off, '/')) != NULL)
|
|
|
|
*cp = '|';
|
|
|
|
kill_daemon(pidname);
|
2003-07-13 11:44:33 +04:00
|
|
|
free(pidname);
|
2000-11-14 01:12:49 +03:00
|
|
|
|
|
|
|
/* Then child */
|
2003-07-13 11:44:33 +04:00
|
|
|
asprintf(&pidname, "%slfs_cleanerd:s:%s.pid", _PATH_VARRUN, name);
|
|
|
|
if (!pidname)
|
|
|
|
err(1, "malloc");
|
2000-11-14 01:12:49 +03:00
|
|
|
off = strlen(_PATH_VARRUN);
|
|
|
|
while((cp = strchr(pidname + off, '/')) != NULL)
|
|
|
|
*cp = '|';
|
|
|
|
kill_daemon(pidname);
|
2003-07-13 11:44:33 +04:00
|
|
|
free(pidname);
|
2000-11-14 01:12:49 +03:00
|
|
|
}
|
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
static void
|
2005-02-09 17:31:29 +03:00
|
|
|
invoke_cleaner(char *name)
|
1994-06-08 22:57:30 +04:00
|
|
|
{
|
2005-06-27 06:56:20 +04:00
|
|
|
const char *args[7], **ap = args;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
/* Build the argument list. */
|
|
|
|
*ap++ = _PATH_LFS_CLEANERD;
|
Various bug-fixes to LFS, to wit:
Kernel:
* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.
If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.
* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.
* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.
* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().
lfs_cleanerd:
* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.
* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.
* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.
* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).
fsck_lfs:
* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.
newfs_lfs:
* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.
* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).
* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.
mount_lfs:
* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.
* Default to calling lfs_cleanerd with "-b -n 4".
[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
2000-09-09 08:49:54 +04:00
|
|
|
if (cleaner_bytes)
|
|
|
|
*ap++ = "-b";
|
|
|
|
if (nsegs) {
|
|
|
|
*ap++ = "-n";
|
|
|
|
*ap++ = nsegs;
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
if (short_rds)
|
|
|
|
*ap++ = "-s";
|
|
|
|
if (cleaner_debug)
|
|
|
|
*ap++ = "-d";
|
2005-03-31 19:55:57 +04:00
|
|
|
if (fs_idle)
|
|
|
|
*ap++ = "-f";
|
1994-06-08 22:57:30 +04:00
|
|
|
*ap++ = name;
|
|
|
|
*ap = NULL;
|
|
|
|
|
2005-06-27 06:56:20 +04:00
|
|
|
execv(args[0], __UNCONST(args));
|
1994-06-08 22:57:30 +04:00
|
|
|
err(1, "exec %s", _PATH_LFS_CLEANERD);
|
|
|
|
}
|
2008-08-06 00:57:45 +04:00
|
|
|
#endif /* WANT_CLEANER */
|
1994-06-08 22:57:30 +04:00
|
|
|
|
2000-10-30 23:56:57 +03:00
|
|
|
static void
|
2005-02-09 17:31:29 +03:00
|
|
|
usage(void)
|
1994-06-08 22:57:30 +04:00
|
|
|
{
|
|
|
|
(void)fprintf(stderr,
|
2005-03-31 07:07:38 +04:00
|
|
|
"usage: %s [-bdins] [-N nsegs] [-o options] special node\n",
|
2004-07-06 20:39:37 +04:00
|
|
|
getprogname());
|
1994-06-08 22:57:30 +04:00
|
|
|
exit(1);
|
|
|
|
}
|