[PATCH] Re: Softupdates a mount option?

From: Stefan Eßer <se_at_FreeBSD.org>
Date: Sat, 29 May 2004 00:12:59 +0200
On 2004-05-26 21:15 +0200, Ivan Voras <ivoras_at_fer.hr> wrote:
> This has been really nagging me for a long time: Why aren't softupdates 
> made a mount option (like 'sync' and 'async')? Do I remember correctly that 
> it is done so in NetBSD (where it's called softdeps), so it's doable?

It definitely is doable, you may want to give the following patches a try.
I just generated on a -CURRENT system as of today. I've been running a 
number of FreeBSD systems with softdep as a mount option over some 4 years
now, and I think it is very convenient. The only change I did consider (but
did not bother to implement before generating the attached diffs was to make
softdep the default, with these patches applied you need to have "rw,softdep"
in column 4 of /etc/fstab, instead of just "rw").

With these patches applied (and a new kernel and mount command), you can even
enable soft-updates on a running system. Just remount the filesystem R/O and
the immediately remount R/W with -o softdep (or the other way around: both
are supported on a R/O filesystem). There is no risk involved in using these
patches. The effect of mounting a filesystem with "-o softdep" is identical to
performing a "tunefs -n enable" immediately before the mount, "-o nosoftdep" 
clears that flag. You can use "tunefs -p" to check the current softdep setting,
but you also get it from "mount -v" and "mount -p" with the modified mount 
command. All other commands (including fsck) are unaffected and work as before.

Just give it a try, you'll like it ;-)

Regards, STefan




List of modified files (most have just one line added or changed):

/usr/src/sys/sys/mount.h
/usr/src/sys/ufs/ffs/ffs_vfsops.c
/usr/src/sys/ufs/ffs/ffs_softdep.c
/usr/src/sys/ufs/ffs/ffs_softdep_stub.c

/usr/src/sbin/mount/mntopts.h
/usr/src/sbin/mount/mount.c
/usr/src/sbin/mount/mount_ufs.c


Index: /usr/src/sys/sys/mount.h
--- /usr/src/sys/sys/mount.h	11 Apr 2004 21:36:31 -0000	1.161
+++ /usr/src/sys/sys/mount.h	12 Apr 2004 09:51:01 -0000
_at__at_ -232,6 +232,7 _at__at_
 			MNT_SYNCHRONOUS	| MNT_UNION	| MNT_ASYNC	| \
 			MNT_NOATIME | \
 			MNT_NOSYMFOLLOW	| MNT_IGNORE	| MNT_JAILDEVFS	| \
+			MNT_SOFTDEP | \
 			MNT_NOCLUSTERR	| MNT_NOCLUSTERW | MNT_SUIDDIR	| \
 			MNT_ACLS	| MNT_USER)
 
Index: /usr/src/sys/ufs/ffs/ffs_vfsops.c
--- /usr/src/sys/ufs/ffs/ffs_vfsops.c	29 Apr 2004 15:10:42 -0000	1.232
+++ /usr/src/sys/ufs/ffs/ffs_vfsops.c	28 May 2004 20:52:43 -0000
_at__at_ -189,6 +189,17 _at__at_
 		ump = VFSTOUFS(mp);
 		fs = ump->um_fs;
 		devvp = ump->um_devvp;
+		if (fs->fs_ronly == 0) {
+			/*
+			 * preserve current softdep status,
+			 * unless mounted read-only
+			 */
+			if (fs->fs_flags & FS_DOSOFTDEP) {
+				mp->mnt_flag |= MNT_SOFTDEP;
+			} else {
+				mp->mnt_flag &= ~MNT_SOFTDEP;
+			}
+		}
 		if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
 			if ((error = vn_start_write(NULL, &mp, V_WAIT)) != 0)
 				return (error);
_at__at_ -277,7 +288,7 _at__at_
 				return (error);
 			}
 			/* check to see if we need to start softdep */
-			if ((fs->fs_flags & FS_DOSOFTDEP) &&
+			if ((mp->mnt_flag & MNT_SOFTDEP) &&
 			    (error = softdep_mount(devvp, mp, fs, td->td_ucred))){
 				vn_finished_write(mp);
 				return (error);
_at__at_ -674,6 +685,9 _at__at_
 		fs->fs_pendingblocks = 0;
 		fs->fs_pendinginodes = 0;
 	}
+	/* clear softdep flag in superblock, if not a softdep mount */
+	if ((mp->mnt_flag & MNT_SOFTDEP) == 0)
+		fs->fs_flags &= ~FS_DOSOFTDEP;
 	ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK | M_ZERO);
 	ump->um_fs = malloc((u_long)fs->fs_sbsize, M_UFSMNT,
 	    M_WAITOK);
_at__at_ -785,7 +799,7 _at__at_
 	}
 
 	if (ronly == 0) {
-		if ((fs->fs_flags & FS_DOSOFTDEP) &&
+		if ((mp->mnt_flag & MNT_SOFTDEP) &&
 		    (error = softdep_mount(devvp, mp, fs, cred)) != 0) {
 			free(fs->fs_csp, M_UFSMNT);
 			goto out;
Index: /usr/src/sys/ufs/ffs/ffs_softdep.c
--- /usr/src/sys/ufs/ffs/ffs_softdep.c	6 Apr 2004 19:20:24 -0000	1.153
+++ /usr/src/sys/ufs/ffs/ffs_softdep.c	26 May 2004 21:57:29 -0000
_at__at_ -1193,7 +1193,7 _at__at_
 	int error, cyl;
 
 	mp->mnt_flag &= ~MNT_ASYNC;
-	mp->mnt_flag |= MNT_SOFTDEP;
+	fs->fs_flags |= FS_DOSOFTDEP;
 	/*
 	 * When doing soft updates, the counters in the
 	 * superblock may have gotten out of sync, so we have
Index: /usr/src/sys/ufs/ffs/ffs_softdep_stub.c
--- /usr/src/sys/ufs/ffs/ffs_softdep_stub.c	11 Jun 2003 06:31:28 -0000	1.27
+++ /usr/src/sys/ufs/ffs/ffs_softdep_stub.c	26 May 2004 21:57:29 -0000
_at__at_ -72,6 +72,7 _at__at_
 	struct fs *fs;
 	struct ucred *cred;
 {
+	mp->mnt_flag &= ~MNT_SOFTDEP;
 
 	return (0);
 }
Index: /usr/src/sbin/mount/mount.c
--- /usr/src/sbin/mount/mount.c	26 Apr 2004 15:13:45 -0000	1.66
+++ /usr/src/sbin/mount/mount.c	28 May 2004 21:36:50 -0000
_at__at_ -758,6 +758,7 _at__at_
 	if (flags & MNT_NOCLUSTERW)	res = catopt(res, "noclusterw");
 	if (flags & MNT_NOSYMFOLLOW)	res = catopt(res, "nosymfollow");
 	if (flags & MNT_SUIDDIR)	res = catopt(res, "suiddir");
+	if (flags & MNT_SOFTDEP)	res = catopt(res, "softdep");
 	if (flags & MNT_MULTILABEL)	res = catopt(res, "multilabel");
 	if (flags & MNT_ACLS)		res = catopt(res, "acls");
 
Index: /usr/src/sbin/mount/mount_ufs.c
--- /usr/src/sbin/mount/mount_ufs.c	9 Apr 2004 19:58:31 -0000	1.24
+++ /usr/src/sbin/mount/mount_ufs.c	28 May 2004 21:37:24 -0000
_at__at_ -64,6 +64,7 _at__at_
 	MOPT_SYNC,
 	MOPT_UPDATE,
 	MOPT_SNAPSHOT,
+	MOPT_SOFTDEP,
 	{ NULL }
 };
 
Index: /usr/src/sbin/mount/mntopts.h
--- /usr/src/sbin/mount/mntopts.h	9 Apr 2004 19:58:30 -0000	1.21
+++ /usr/src/sbin/mount/mntopts.h	28 May 2004 21:35:56 -0000
_at__at_ -53,6 +53,7 _at__at_
 #define MOPT_NOCLUSTERW		{ "clusterw",	1, MNT_NOCLUSTERW, 0 }
 #define MOPT_SUIDDIR		{ "suiddir",	0, MNT_SUIDDIR, 0 }
 #define MOPT_SNAPSHOT		{ "snapshot",	0, MNT_SNAPSHOT, 0 }
+#define MOPT_SOFTDEP		{ "softdep",	0, MNT_SOFTDEP, 0 }
 #define MOPT_MULTILABEL		{ "multilabel",	0, MNT_MULTILABEL, 0 }
 #define MOPT_ACLS		{ "acls",	0, MNT_ACLS, 0 }
 
Received on Fri May 28 2004 - 13:13:30 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:55 UTC