1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-13 10:02:38 +00:00

Implemented filesystem clean bit via:

machdep.c:
	Changed printf's a little and call vfs_unmountall() if the sync was
	successful.

cd9660_vfsops.c, ffs_vfsops.c, nfs_vfsops.c, lfs_vfsops.c:
	Allow dismount of root FS. It is now disallowed at a higher level.

vfs_conf.c:
	Removed unused rootfs global.

vfs_subr.c:
	Added new routines vfs_unmountall and vfs_unmountroot. Filesystems
	are now dismounted if the machine is properly rebooted.

ffs_vfsops.c:
	Toggle clean bit at the appropriate places. Print warning if an
	unclean FS is mounted.

ffs_vfsops.c, lfs_vfsops.c:
	Fix bug in selecting proper flags for VOP_CLOSE().

vfs_syscalls.c:
	Disallow dismounting root FS via umount syscall.
This commit is contained in:
David Greenman 1994-08-20 16:03:26 +00:00
parent d90963f5e4
commit e0e9c42112
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=2152
15 changed files with 209 additions and 65 deletions

View File

@ -35,7 +35,7 @@
* SUCH DAMAGE.
*
* from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
* $Id: machdep.c,v 1.53 1994/08/18 22:34:40 wollman Exp $
* $Id: machdep.c,v 1.54 1994/08/19 11:45:15 davidg Exp $
*/
#include "npx.h"
@ -676,7 +676,6 @@ boot(arghowto)
register int howto; /* r11 == how to boot */
register int devtype; /* r10 == major of root dev */
extern int cold;
int nomsg = 1;
if (cold) {
printf("hit reset please");
@ -689,20 +688,13 @@ boot(arghowto)
waittime = 0;
(void) splnet();
printf("syncing disks... ");
printf("\nsyncing disks... ");
/*
* Release inodes held by texts before update.
*/
if (panicstr == 0)
vnode_pager_umount(NULL);
sync(curproc, NULL, NULL);
/*
* Unmount filesystems
*/
#if 0
if (panicstr == 0)
vfs_unmountall();
#endif
for (iter = 0; iter < 20; iter++) {
nbusy = 0;
@ -711,18 +703,24 @@ boot(arghowto)
nbusy++;
if (nbusy == 0)
break;
if (nomsg) {
printf("updating disks before rebooting... ");
nomsg = 0;
}
printf("%d ", nbusy);
DELAY(40000 * iter);
}
if (nbusy)
if (nbusy) {
/*
* Failed to sync all blocks. Indicate this and don't
* unmount filesystems (thus forcing an fsck on reboot).
*/
printf("giving up\n");
else
} else {
printf("done\n");
DELAY(10000); /* wait for printf to finish */
/*
* Unmount filesystems
*/
if (panicstr == 0)
vfs_unmountall();
}
DELAY(100000); /* wait for console output to finish */
}
splhigh();
devtype = major(rootdev);

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)cd9660_vfsops.c 8.3 (Berkeley) 1/31/94
* $Id: cd9660_vfsops.c,v 1.3 1994/08/02 07:41:33 davidg Exp $
* $Id: cd9660_vfsops.c,v 1.4 1994/08/20 03:48:45 davidg Exp $
*/
#include <sys/param.h>
@ -403,7 +403,7 @@ cd9660_unmount(mp, mntflags, p)
int i, error, ronly, flags = 0;
if (mntflags & MNT_FORCE) {
if (!iso_doforce || (mp->mnt_flag & MNT_ROOTFS))
if (!iso_doforce)
return (EINVAL);
flags |= FORCECLOSE;
}

View File

@ -35,7 +35,7 @@
* SUCH DAMAGE.
*
* from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
* $Id: machdep.c,v 1.53 1994/08/18 22:34:40 wollman Exp $
* $Id: machdep.c,v 1.54 1994/08/19 11:45:15 davidg Exp $
*/
#include "npx.h"
@ -676,7 +676,6 @@ boot(arghowto)
register int howto; /* r11 == how to boot */
register int devtype; /* r10 == major of root dev */
extern int cold;
int nomsg = 1;
if (cold) {
printf("hit reset please");
@ -689,20 +688,13 @@ boot(arghowto)
waittime = 0;
(void) splnet();
printf("syncing disks... ");
printf("\nsyncing disks... ");
/*
* Release inodes held by texts before update.
*/
if (panicstr == 0)
vnode_pager_umount(NULL);
sync(curproc, NULL, NULL);
/*
* Unmount filesystems
*/
#if 0
if (panicstr == 0)
vfs_unmountall();
#endif
for (iter = 0; iter < 20; iter++) {
nbusy = 0;
@ -711,18 +703,24 @@ boot(arghowto)
nbusy++;
if (nbusy == 0)
break;
if (nomsg) {
printf("updating disks before rebooting... ");
nomsg = 0;
}
printf("%d ", nbusy);
DELAY(40000 * iter);
}
if (nbusy)
if (nbusy) {
/*
* Failed to sync all blocks. Indicate this and don't
* unmount filesystems (thus forcing an fsck on reboot).
*/
printf("giving up\n");
else
} else {
printf("done\n");
DELAY(10000); /* wait for printf to finish */
/*
* Unmount filesystems
*/
if (panicstr == 0)
vfs_unmountall();
}
DELAY(100000); /* wait for console output to finish */
}
splhigh();
devtype = major(rootdev);

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)cd9660_vfsops.c 8.3 (Berkeley) 1/31/94
* $Id: cd9660_vfsops.c,v 1.3 1994/08/02 07:41:33 davidg Exp $
* $Id: cd9660_vfsops.c,v 1.4 1994/08/20 03:48:45 davidg Exp $
*/
#include <sys/param.h>
@ -403,7 +403,7 @@ cd9660_unmount(mp, mntflags, p)
int i, error, ronly, flags = 0;
if (mntflags & MNT_FORCE) {
if (!iso_doforce || (mp->mnt_flag & MNT_ROOTFS))
if (!iso_doforce)
return (EINVAL);
flags |= FORCECLOSE;
}

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_conf.c 8.8 (Berkeley) 3/31/94
* $Id$
* $Id: vfs_conf.c,v 1.2 1994/08/02 07:43:19 davidg Exp $
*/
#include <sys/param.h>
@ -48,10 +48,6 @@
int (*mountroot)() = ffs_mountroot;
#endif
/*
* These define the root filesystem and device.
*/
struct mount *rootfs;
struct vnode *rootvnode;
/*

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_subr.c 8.13 (Berkeley) 4/18/94
* $Id: vfs_subr.c,v 1.3 1994/08/02 07:43:27 davidg Exp $
* $Id: vfs_subr.c,v 1.4 1994/08/18 22:35:09 wollman Exp $
*/
/*
@ -169,6 +169,70 @@ vfs_unbusy(mp)
}
}
void
vfs_unmountroot(rootfs)
struct mount *rootfs;
{
struct mount *mp = rootfs;
int error;
if (vfs_busy(mp)) {
printf("failed to unmount root\n");
return;
}
mp->mnt_flag |= MNT_UNMOUNT;
if (error = vfs_lock(mp)) {
printf("lock of root filesystem failed (%d)\n", error);
return;
}
vnode_pager_umount(mp); /* release cached vnodes */
cache_purgevfs(mp); /* remove cache entries for this file sys */
if (error = VFS_SYNC(mp, MNT_WAIT, initproc->p_ucred, initproc))
printf("sync of root filesystem failed (%d)\n", error);
if (error = VFS_UNMOUNT(mp, MNT_FORCE, initproc))
printf("unmount of root filesystem failed (%d)\n", error);
mp->mnt_flag &= ~MNT_UNMOUNT;
vfs_unbusy(mp);
}
/*
* Unmount all filesystems. Should only be called by halt().
*/
void
vfs_unmountall()
{
struct mount *mp, *mp_next, *rootfs = NULL;
int error;
/* unmount all but rootfs */
for (mp = mountlist.tqh_first; mp != NULL; mp = mp_next) {
mp_next = mp->mnt_list.tqe_next;
if (mp->mnt_flag & MNT_ROOTFS) {
rootfs = mp;
continue;
}
error = dounmount(mp, MNT_FORCE, initproc);
if (error) {
printf("unmount of %s failed (%d)\n",
mp->mnt_stat.f_mntonname, error);
}
}
/* and finally... */
if (rootfs) {
vfs_unmountroot(rootfs);
} else {
printf("no root filesystem\n");
}
}
/*
* Lookup a mount point by filesystem identifier.
*/

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
* $Id$
* $Id: vfs_syscalls.c,v 1.3 1994/08/02 07:43:31 davidg Exp $
*/
#include <sys/param.h>
@ -238,6 +238,13 @@ unmount(p, uap, retval)
}
mp = vp->v_mount;
vput(vp);
/*
* Don't allow unmount of the root filesystem
*/
if (mp->mnt_flag & MNT_ROOTFS)
return (EINVAL);
return (dounmount(mp, uap->flags, p));
}

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_conf.c 8.8 (Berkeley) 3/31/94
* $Id$
* $Id: vfs_conf.c,v 1.2 1994/08/02 07:43:19 davidg Exp $
*/
#include <sys/param.h>
@ -48,10 +48,6 @@
int (*mountroot)() = ffs_mountroot;
#endif
/*
* These define the root filesystem and device.
*/
struct mount *rootfs;
struct vnode *rootvnode;
/*

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_subr.c 8.13 (Berkeley) 4/18/94
* $Id: vfs_subr.c,v 1.3 1994/08/02 07:43:27 davidg Exp $
* $Id: vfs_subr.c,v 1.4 1994/08/18 22:35:09 wollman Exp $
*/
/*
@ -169,6 +169,70 @@ vfs_unbusy(mp)
}
}
void
vfs_unmountroot(rootfs)
struct mount *rootfs;
{
struct mount *mp = rootfs;
int error;
if (vfs_busy(mp)) {
printf("failed to unmount root\n");
return;
}
mp->mnt_flag |= MNT_UNMOUNT;
if (error = vfs_lock(mp)) {
printf("lock of root filesystem failed (%d)\n", error);
return;
}
vnode_pager_umount(mp); /* release cached vnodes */
cache_purgevfs(mp); /* remove cache entries for this file sys */
if (error = VFS_SYNC(mp, MNT_WAIT, initproc->p_ucred, initproc))
printf("sync of root filesystem failed (%d)\n", error);
if (error = VFS_UNMOUNT(mp, MNT_FORCE, initproc))
printf("unmount of root filesystem failed (%d)\n", error);
mp->mnt_flag &= ~MNT_UNMOUNT;
vfs_unbusy(mp);
}
/*
* Unmount all filesystems. Should only be called by halt().
*/
void
vfs_unmountall()
{
struct mount *mp, *mp_next, *rootfs = NULL;
int error;
/* unmount all but rootfs */
for (mp = mountlist.tqh_first; mp != NULL; mp = mp_next) {
mp_next = mp->mnt_list.tqe_next;
if (mp->mnt_flag & MNT_ROOTFS) {
rootfs = mp;
continue;
}
error = dounmount(mp, MNT_FORCE, initproc);
if (error) {
printf("unmount of %s failed (%d)\n",
mp->mnt_stat.f_mntonname, error);
}
}
/* and finally... */
if (rootfs) {
vfs_unmountroot(rootfs);
} else {
printf("no root filesystem\n");
}
}
/*
* Lookup a mount point by filesystem identifier.
*/

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94
* $Id$
* $Id: vfs_syscalls.c,v 1.3 1994/08/02 07:43:31 davidg Exp $
*/
#include <sys/param.h>
@ -238,6 +238,13 @@ unmount(p, uap, retval)
}
mp = vp->v_mount;
vput(vp);
/*
* Don't allow unmount of the root filesystem
*/
if (mp->mnt_flag & MNT_ROOTFS)
return (EINVAL);
return (dounmount(mp, uap->flags, p));
}

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs_vfsops.c 8.3 (Berkeley) 1/4/94
* $Id$
* $Id: nfs_vfsops.c,v 1.2 1994/08/02 07:52:16 davidg Exp $
*/
#include <sys/param.h>
@ -542,7 +542,7 @@ nfs_unmount(mp, mntflags, p)
extern int doforce;
if (mntflags & MNT_FORCE) {
if (!doforce || (mp->mnt_flag & MNT_ROOTFS))
if (!doforce)
return (EINVAL);
flags |= FORCECLOSE;
}

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs_vfsops.c 8.3 (Berkeley) 1/4/94
* $Id$
* $Id: nfs_vfsops.c,v 1.2 1994/08/02 07:52:16 davidg Exp $
*/
#include <sys/param.h>
@ -542,7 +542,7 @@ nfs_unmount(mp, mntflags, p)
extern int doforce;
if (mntflags & MNT_FORCE) {
if (!doforce || (mp->mnt_flag & MNT_ROOTFS))
if (!doforce)
return (EINVAL);
flags |= FORCECLOSE;
}

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)mount.h 8.13 (Berkeley) 3/27/94
* $Id$
* $Id: mount.h,v 1.2 1994/08/02 07:53:15 davidg Exp $
*/
#ifndef KERNEL
@ -407,6 +407,7 @@ extern struct vfsops *vfssw[]; /* filesystem type table */
#include <sys/cdefs.h>
__BEGIN_DECLS
int dounmount __P((struct mount *, int, struct proc *));
int fstatfs __P((int, struct statfs *));
int getfh __P((const char *, fhandle_t *));
int getfsstat __P((struct statfs *, long, int));

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)ffs_vfsops.c 8.8 (Berkeley) 4/18/94
* $Id: ffs_vfsops.c,v 1.3 1994/08/02 07:54:24 davidg Exp $
* $Id: ffs_vfsops.c,v 1.4 1994/08/18 22:35:54 wollman Exp $
*/
#include <sys/param.h>
@ -177,6 +177,10 @@ ffs_mount(mp, path, data, ndp, p)
return (error);
if (fs->fs_ronly && (mp->mnt_flag & MNT_WANTRDWR))
fs->fs_ronly = 0;
if (fs->fs_ronly == 0) {
fs->fs_clean = 0;
ffs_sbupdate(ump, MNT_WAIT);
}
if (args.fspec == 0) {
/*
* Process export requests.
@ -394,8 +398,13 @@ ffs_mountfs(devvp, mp, p)
bp = NULL;
fs = ump->um_fs;
fs->fs_ronly = ronly;
if (ronly == 0)
if (!fs->fs_clean) {
printf("WARNING: %s was not properly dismounted\n",fs->fs_fsmnt);
}
if (ronly == 0) {
fs->fs_fmod = 1;
fs->fs_clean = 0;
}
blks = howmany(fs->fs_cssize, fs->fs_fsize);
base = space = malloc((u_long)fs->fs_cssize, M_UFSMNT,
M_WAITOK);
@ -430,6 +439,8 @@ ffs_mountfs(devvp, mp, p)
ump->um_quotas[i] = NULLVP;
devvp->v_specflags |= SI_MOUNTEDON;
ffs_oldfscompat(fs);
if (ronly == 0)
ffs_sbupdate(ump, MNT_WAIT);
return (0);
out:
if (bp)
@ -487,15 +498,17 @@ ffs_unmount(mp, mntflags, p)
flags = 0;
if (mntflags & MNT_FORCE) {
if (mp->mnt_flag & MNT_ROOTFS)
return (EINVAL);
flags |= FORCECLOSE;
}
if (error = ffs_flushfiles(mp, flags, p))
return (error);
ump = VFSTOUFS(mp);
fs = ump->um_fs;
ronly = !fs->fs_ronly;
ronly = fs->fs_ronly;
if (!ronly) {
fs->fs_clean = 1;
ffs_sbupdate(ump, MNT_WAIT);
}
ump->um_devvp->v_specflags &= ~SI_MOUNTEDON;
error = VOP_CLOSE(ump->um_devvp, ronly ? FREAD : FREAD|FWRITE,
NOCRED, p);

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)lfs_vfsops.c 8.7 (Berkeley) 4/16/94
* $Id: lfs_vfsops.c,v 1.3 1994/08/02 07:54:38 davidg Exp $
* $Id: lfs_vfsops.c,v 1.4 1994/08/20 03:49:02 davidg Exp $
*/
#include <sys/param.h>
@ -326,7 +326,7 @@ lfs_unmount(mp, mntflags, p)
flags = 0;
if (mntflags & MNT_FORCE) {
if (!doforce || (mp->mnt_flag & MNT_ROOTFS))
if (!doforce)
return (EINVAL);
flags |= FORCECLOSE;
}
@ -358,7 +358,7 @@ lfs_unmount(mp, mntflags, p)
vrele(fs->lfs_ivnode);
vgone(fs->lfs_ivnode);
ronly = !fs->lfs_ronly;
ronly = fs->lfs_ronly;
ump->um_devvp->v_specflags &= ~SI_MOUNTEDON;
error = VOP_CLOSE(ump->um_devvp,
ronly ? FREAD : FREAD|FWRITE, NOCRED, p);