Module Name: src Committed By: hannken Date: Mon Dec 27 18:49:42 UTC 2010
Modified Files: src/sys/fs/msdosfs: msdosfs_vfsops.c src/sys/miscfs/genfs: genfs_vnops.c src/sys/ufs/ffs: ffs_vfsops.c Log Message: Extend the range of fstrans transactions to a sequence of vnode operations on a locked vnode. This leaves a suspended file system and therefore a snapshot with either all or no operations of such a sequence done. To generate a diff of this commit: cvs rdiff -u -r1.88 -r1.89 src/sys/fs/msdosfs/msdosfs_vfsops.c cvs rdiff -u -r1.185 -r1.186 src/sys/miscfs/genfs/genfs_vnops.c cvs rdiff -u -r1.262 -r1.263 src/sys/ufs/ffs/ffs_vfsops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/fs/msdosfs/msdosfs_vfsops.c diff -u src/sys/fs/msdosfs/msdosfs_vfsops.c:1.88 src/sys/fs/msdosfs/msdosfs_vfsops.c:1.89 --- src/sys/fs/msdosfs/msdosfs_vfsops.c:1.88 Tue Dec 14 17:17:02 2010 +++ src/sys/fs/msdosfs/msdosfs_vfsops.c Mon Dec 27 18:49:42 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: msdosfs_vfsops.c,v 1.88 2010/12/14 17:17:02 hannken Exp $ */ +/* $NetBSD: msdosfs_vfsops.c,v 1.89 2010/12/27 18:49:42 hannken Exp $ */ /*- * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. @@ -48,7 +48,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.88 2010/12/14 17:17:02 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.89 2010/12/27 18:49:42 hannken Exp $"); #if defined(_KERNEL_OPT) #include "opt_compat_netbsd.h" @@ -938,8 +938,7 @@ struct vnode *vp, *mvp; struct denode *dep; struct msdosfsmount *pmp = VFSTOMSDOSFS(mp); - int lk_flags, error, allerror = 0; - bool is_suspending; + int error, allerror = 0; /* * If we ever switch to not updating all of the fats all the time, @@ -956,15 +955,6 @@ if ((mvp = vnalloc(mp)) == NULL) return ENOMEM; fstrans_start(mp, FSTRANS_SHARED); - is_suspending = (fstrans_getstate(mp) == FSTRANS_SUSPENDING); - /* - * We can't lock vnodes while the file system is suspending because - * threads waiting on fstrans may have locked vnodes. - */ - if (is_suspending) - lk_flags = 0; - else - lk_flags = LK_EXCLUSIVE | LK_NOWAIT; /* * Write back each (modified) denode. */ @@ -985,7 +975,7 @@ continue; } mutex_exit(&mntvnode_lock); - error = vget(vp, lk_flags); + error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT); if (error) { mutex_enter(&mntvnode_lock); if (error == ENOENT) { @@ -997,10 +987,7 @@ if ((error = VOP_FSYNC(vp, cred, waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0)) != 0) allerror = error; - if (is_suspending) - vrele(vp); - else - vput(vp); + vput(vp); mutex_enter(&mntvnode_lock); } mutex_exit(&mntvnode_lock); Index: src/sys/miscfs/genfs/genfs_vnops.c diff -u src/sys/miscfs/genfs/genfs_vnops.c:1.185 src/sys/miscfs/genfs/genfs_vnops.c:1.186 --- src/sys/miscfs/genfs/genfs_vnops.c:1.185 Tue Nov 30 10:43:05 2010 +++ src/sys/miscfs/genfs/genfs_vnops.c Mon Dec 27 18:49:42 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: genfs_vnops.c,v 1.185 2010/11/30 10:43:05 dholland Exp $ */ +/* $NetBSD: genfs_vnops.c,v 1.186 2010/12/27 18:49:42 hannken Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -57,13 +57,14 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.185 2010/11/30 10:43:05 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.186 2010/12/27 18:49:42 hannken Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/proc.h> #include <sys/kernel.h> #include <sys/mount.h> +#include <sys/fstrans.h> #include <sys/namei.h> #include <sys/vnode.h> #include <sys/fcntl.h> @@ -293,10 +294,17 @@ KASSERT((flags & ~(LK_EXCLUSIVE | LK_SHARED | LK_NOWAIT)) == 0); op = ((flags & LK_EXCLUSIVE) != 0 ? RW_WRITER : RW_READER); + if ((flags & LK_NOWAIT) != 0) { + if (fstrans_start_nowait(vp->v_mount, FSTRANS_SHARED)) + return EBUSY; + if (! rw_tryenter(&vp->v_lock, op)) { + fstrans_done(vp->v_mount); + return EBUSY; + } + return 0; + } - if ((flags & LK_NOWAIT) != 0) - return (rw_tryenter(&vp->v_lock, op) ? 0 : EBUSY); - + fstrans_start(vp->v_mount, FSTRANS_SHARED); rw_enter(&vp->v_lock, op); return 0; @@ -314,6 +322,7 @@ struct vnode *vp = ap->a_vp; rw_exit(&vp->v_lock); + fstrans_done(vp->v_mount); return 0; } Index: src/sys/ufs/ffs/ffs_vfsops.c diff -u src/sys/ufs/ffs/ffs_vfsops.c:1.262 src/sys/ufs/ffs/ffs_vfsops.c:1.263 --- src/sys/ufs/ffs/ffs_vfsops.c:1.262 Mon Aug 9 17:12:18 2010 +++ src/sys/ufs/ffs/ffs_vfsops.c Mon Dec 27 18:49:42 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ffs_vfsops.c,v 1.262 2010/08/09 17:12:18 pooka Exp $ */ +/* $NetBSD: ffs_vfsops.c,v 1.263 2010/12/27 18:49:42 hannken Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.262 2010/08/09 17:12:18 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.263 2010/12/27 18:49:42 hannken Exp $"); #if defined(_KERNEL_OPT) #include "opt_ffs.h" @@ -1547,7 +1547,7 @@ struct inode *ip; struct ufsmount *ump = VFSTOUFS(mp); struct fs *fs; - int lk_flags, error, allerror = 0; + int error, allerror = 0; bool is_suspending; fs = ump->um_fs; @@ -1563,14 +1563,6 @@ fstrans_start(mp, FSTRANS_SHARED); is_suspending = (fstrans_getstate(mp) == FSTRANS_SUSPENDING); /* - * We can't lock vnodes while the file system is suspending because - * threads waiting on fstrans may have locked vnodes. - */ - if (is_suspending) - lk_flags = 0; - else - lk_flags = LK_EXCLUSIVE | LK_NOWAIT; - /* * Write back each (modified) inode. */ mutex_enter(&mntvnode_lock); @@ -1632,7 +1624,7 @@ } vmark(mvp, vp); mutex_exit(&mntvnode_lock); - error = vget(vp, lk_flags); + error = vget(vp, LK_EXCLUSIVE | LK_NOWAIT); if (error) { mutex_enter(&mntvnode_lock); nvp = vunmark(mvp); @@ -1654,10 +1646,7 @@ } if (error) allerror = error; - if (is_suspending) - vrele(vp); - else - vput(vp); + vput(vp); mutex_enter(&mntvnode_lock); nvp = vunmark(mvp); }