Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/sbin/mount_lfs Pull up revision 1.12 (via patch, reques...
details: https://anonhg.NetBSD.org/src/rev/fabe28edb5cb
branches: netbsd-1-5
changeset: 490621:fabe28edb5cb
user: he <he%NetBSD.org@localhost>
date: Sat Feb 03 21:43:18 2001 +0000
description:
Pull up revision 1.12 (via patch, requested by perseant):
Don't spawn more cleaners when using "mount -u", unless
upgrading from r/o to r/w; when downgrading, kill the cleaner.
diffstat:
sbin/mount_lfs/mount_lfs.c | 88 ++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 81 insertions(+), 7 deletions(-)
diffs (146 lines):
diff -r d738f61eaeb5 -r fabe28edb5cb sbin/mount_lfs/mount_lfs.c
--- a/sbin/mount_lfs/mount_lfs.c Sat Feb 03 21:42:27 2001 +0000
+++ b/sbin/mount_lfs/mount_lfs.c Sat Feb 03 21:43:18 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mount_lfs.c,v 1.9.4.1 2000/09/14 18:53:21 perseant Exp $ */
+/* $NetBSD: mount_lfs.c,v 1.9.4.2 2001/02/03 21:43:18 he Exp $ */
/*-
* Copyright (c) 1993, 1994
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)mount_lfs.c 8.4 (Berkeley) 4/26/95";
#else
-__RCSID("$NetBSD: mount_lfs.c,v 1.9.4.1 2000/09/14 18:53:21 perseant Exp $");
+__RCSID("$NetBSD: mount_lfs.c,v 1.9.4.2 2001/02/03 21:43:18 he Exp $");
#endif
#endif /* not lint */
@@ -58,6 +58,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <paths.h>
+
+#include <signal.h>
#include "mntopts.h"
#include "pathnames.h"
@@ -68,9 +71,12 @@
{ NULL }
};
-int main __P((int, char *[]));
-void invoke_cleaner __P((char *));
-void usage __P((void));
+int main __P((int, char *[]));
+int mount_lfs __P((int, char *[]));
+static void invoke_cleaner __P((char *));
+static void usage __P((void));
+static void kill_daemon __P((char *));
+static void kill_cleaner __P((char *));
int short_rds, cleaner_debug, cleaner_bytes;
char *nsegs;
@@ -81,9 +87,11 @@
char *argv[];
{
struct ufs_args args;
- int ch, mntflags, noclean;
+ int ch, mntflags, noclean, mntsize, oldflags, i;
char *fs_name, *options;
+
const char *errcause;
+ struct statfs *mntbuf;
options = NULL;
nsegs = "4";
@@ -130,6 +138,23 @@
} else
args.export.ex_flags = 0;
+ /*
+ * 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) {
+ oldflags = mntbuf[i].f_flags;
+ break;
+ }
+ }
+ }
+
if (mount(MOUNT_LFS, fs_name, mntflags, &args)) {
switch (errno) {
case EMFILE:
@@ -149,14 +174,63 @@
errx(1, "%s on %s: %s", args.fspec, fs_name, errcause);
}
+ /* Not mounting fresh or upgrading to r/w; don't start the cleaner */
+ if (!(oldflags & MNT_RDONLY) || (mntflags & MNT_RDONLY))
+ noclean = 1;
if (!noclean)
invoke_cleaner(fs_name);
/* NOTREACHED */
+ /* Downgrade to r/o; kill the cleaner */
+ if ((mntflags & MNT_RDONLY) && !(oldflags & MNT_RDONLY))
+ kill_cleaner(fs_name);
+
exit(0);
}
-void
+static void
+kill_daemon(pidname)
+ char *pidname;
+{
+ 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
+kill_cleaner(name)
+ char *name;
+{
+ char *pidname;
+ char *cp;
+ int off;
+
+ /* Parent first */
+ pidname = malloc(strlen(name) + 20 + strlen(_PATH_VARRUN));
+ sprintf(pidname, "%slfs_cleanerd:m:%s.pid", _PATH_VARRUN, name);
+ off = strlen(_PATH_VARRUN);
+ while((cp = strchr(pidname + off, '/')) != NULL)
+ *cp = '|';
+ kill_daemon(pidname);
+
+ /* Then child */
+ sprintf(pidname, "%slfs_cleanerd:s:%s.pid", _PATH_VARRUN, name);
+ off = strlen(_PATH_VARRUN);
+ while((cp = strchr(pidname + off, '/')) != NULL)
+ *cp = '|';
+ kill_daemon(pidname);
+}
+
+static void
invoke_cleaner(name)
char *name;
{
Home |
Main Index |
Thread Index |
Old Index