Subject: Re: Patch to disallow mounts of unclean FFS unless forced
To: Jason Thorpe <thorpej@wasabisystems.com>
From: Jason Thorpe <thorpej@wasabisystems.com>
List: tech-kern
Date: 10/13/2003 11:49:45
--Apple-Mail-10--283043562
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed


On Monday, October 13, 2003, at 11:09  AM, Jason Thorpe wrote:

> Comments?

Darrin pointed out to me that it should be allowed to mount an unclean 
FFS that was softdep-enabled, since the only inconsistencies in that 
case should be lost file system blocks.

Attached is an updated patch that implements that suggestion.

         -- Jason R. Thorpe <thorpej@wasabisystems.com>

--Apple-Mail-10--283043562
Content-Disposition: attachment;
	filename=ffs-force-patch.txt
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	x-unix-mode=0644;
	name="ffs-force-patch.txt"

Index: ffs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ffs/ffs_vfsops.c,v
retrieving revision 1.123
diff -u -p -r1.123 ffs_vfsops.c
--- ffs_vfsops.c	25 Sep 2003 23:39:17 -0000	1.123
+++ ffs_vfsops.c	13 Oct 2003 18:45:33 -0000
@@ -151,6 +151,11 @@ ffs_mountroot()
 		vrele(rootvp);
 		return (error);
 	}
+
+	/*
+	 * We always need to be able to mount the root file system.
+	 */
+	mp->mnt_flag |= MNT_FORCE;
 	if ((error = ffs_mountfs(rootvp, mp, p)) != 0) {
 		mp->mnt_op->vfs_refcount--;
 		vfs_unbusy(mp);
@@ -158,6 +163,7 @@ ffs_mountroot()
 		vrele(rootvp);
 		return (error);
 	}
+	mp->mnt_flag &= ~MNT_FORCE;
 	simple_lock(&mountlist_slock);
 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
 	simple_unlock(&mountlist_slock);
@@ -827,6 +833,18 @@ next_sblock:
 		goto out;
 	}
 #endif
+
+	/*
+	 * If the file system is not clean, don't allow it to be mounted
+	 * unless MNT_FORCE is specified.  (Note: MNT_FORCE is always set
+	 * for the root file system.)
+	 */
+	if ((fs->fs_clean & FS_ISCLEAN) == 0 &&
+	    (mp->mnt_flag & MNT_FORCE) == 0 &&
+	    (fs->fs_flags & FS_DOSOFTDEP) == 0) {
+		error = EPERM;
+		goto out2;
+	}
 
 	/*
 	 * verify that we can access the last block in the fs

--Apple-Mail-10--283043562--