Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Allow vfs_write_suspend() to wait if the file system is already



details:   https://anonhg.NetBSD.org/src/rev/6526b0e96180
branches:  trunk
changeset: 557503:6526b0e96180
user:      hannken <hannken%NetBSD.org@localhost>
date:      Sat Jan 10 17:16:38 2004 +0000

description:
Allow vfs_write_suspend() to wait if the file system is already
suspending.

Move vfs_write_suspend() and vfs_write_resume() from kern/vfs_vnops.c
to kern/vfs_subr.c.

Change vnode write gating in ufs/ffs/ffs_softdep.c (from FreeBSD).

When vnodes are throttled in softdep_trackbufs() check for
file system suspension every 10 msecs to avoid a deadlock.

diffstat:

 share/man/man9/vfssubr.9  |  22 +++++++++++++++---
 sys/dev/fss.c             |   6 ++--
 sys/kern/vfs_subr.c       |  52 +++++++++++++++++++++++++++++++++++++++++++-
 sys/kern/vfs_vnops.c      |  42 +----------------------------------
 sys/sys/vnode.h           |   6 ++--
 sys/ufs/ffs/ffs_softdep.c |  54 +++++++++++++++++++++++++++-------------------
 6 files changed, 108 insertions(+), 74 deletions(-)

diffs (truncated from 413 to 300 lines):

diff -r a30dea40b269 -r 6526b0e96180 share/man/man9/vfssubr.9
--- a/share/man/man9/vfssubr.9  Sat Jan 10 17:04:44 2004 +0000
+++ b/share/man/man9/vfssubr.9  Sat Jan 10 17:16:38 2004 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: vfssubr.9,v 1.7 2003/12/04 23:57:44 wiz Exp $
+.\"     $NetBSD: vfssubr.9,v 1.8 2004/01/10 17:16:38 hannken Exp $
 .\"
 .\" Copyright (c) 2003 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -34,7 +34,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 5, 2003
+.Dd January 10, 2004
 .Dt VFSSUBR 9
 .Os
 .Sh NAME
@@ -103,7 +103,7 @@
 .Ft struct vfsops *
 .Fn vfs_getopsbyname "const char *name"
 .Ft int
-.Fn vfs_write_suspend "struct mount *mp"
+.Fn vfs_write_suspend "struct mount *mp" "int slpflag" "int slptimeo"
 .Ft void
 .Fn vfs_write_resume "struct mount *mp"
 .Sh DESCRIPTION
@@ -189,11 +189,25 @@
 or return
 .Dv NULL
 if file system isn't present in the kernel.
-.It Fn vfs_write_suspend "mp"
+.It Fn vfs_write_suspend "mp" "slpflag" "slptimeo"
 Request a mounted file system to suspend write operations.
 All new write operations to the file system are stopped.
 After all write operations in progress have completed, the
 file system is synced to disk and the function returns.
+If the file system is currently suspended the
+.Xr sleep 9
+flag and timeout are specified by the arguments
+.Fa slpflag
+and
+.Fa slptimeo
+respectively.
+If
+.Fa slptimeo
+is less than zero
+.Er EWOULDBLOCK
+is returned.
+If the operation is successful zero is returned, otherwise an
+appropriate error code is returned.
 .It Fn vfs_write_resume "mp"
 Request a mounted file system to resume write operations.
 .El
diff -r a30dea40b269 -r 6526b0e96180 sys/dev/fss.c
--- a/sys/dev/fss.c     Sat Jan 10 17:04:44 2004 +0000
+++ b/sys/dev/fss.c     Sat Jan 10 17:16:38 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fss.c,v 1.2 2003/12/13 18:59:29 hannken Exp $  */
+/*     $NetBSD: fss.c,v 1.3 2004/01/10 17:16:38 hannken Exp $  */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.2 2003/12/13 18:59:29 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.3 2004/01/10 17:16:38 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -632,7 +632,7 @@
         * Activate the snapshot.
         */
 
-       if ((error = vfs_write_suspend(sc->sc_mount)) != 0)
+       if ((error = vfs_write_suspend(sc->sc_mount, PUSER|PCATCH, 0)) != 0)
                goto bad;
 
        microtime(&sc->sc_time);
diff -r a30dea40b269 -r 6526b0e96180 sys/kern/vfs_subr.c
--- a/sys/kern/vfs_subr.c       Sat Jan 10 17:04:44 2004 +0000
+++ b/sys/kern/vfs_subr.c       Sat Jan 10 17:16:38 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_subr.c,v 1.213 2003/12/30 12:33:24 pk Exp $        */
+/*     $NetBSD: vfs_subr.c,v 1.214 2004/01/10 17:16:38 hannken Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.213 2003/12/30 12:33:24 pk Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.214 2004/01/10 17:16:38 hannken Exp $");
 
 #include "opt_inet.h"
 #include "opt_ddb.h"
@@ -2828,6 +2828,54 @@
        }
 }
 
+/*
+ * Request a filesystem to suspend write operations.
+ */
+int
+vfs_write_suspend(struct mount *mp, int slpflag, int slptimeo)
+{
+       struct proc *p = curproc;       /* XXX */
+       int error;
+
+       while ((mp->mnt_iflag & IMNT_SUSPEND)) {
+               if (slptimeo < 0)
+                       return EWOULDBLOCK;
+               error = tsleep(&mp->mnt_flag, slpflag, "suspwt1", slptimeo);
+               if (error)
+                       return error;
+       }
+       mp->mnt_iflag |= IMNT_SUSPEND;
+
+       if (mp->mnt_writeopcountupper > 0)
+               tsleep(&mp->mnt_writeopcountupper, PUSER - 1, "suspwt", 0);
+
+       error = VFS_SYNC(mp, MNT_WAIT, p->p_ucred, p);
+       if (error) {
+               vfs_write_resume(mp);
+               return error;
+       }
+       mp->mnt_iflag |= IMNT_SUSPENDLOW;
+
+       if (mp->mnt_writeopcountlower > 0)
+               tsleep(&mp->mnt_writeopcountlower, PUSER - 1, "suspwt", 0);
+       mp->mnt_iflag |= IMNT_SUSPENDED;
+
+       return 0;
+}
+
+/*
+ * Request a filesystem to resume write operations.
+ */
+void
+vfs_write_resume(struct mount *mp)
+{
+
+       if ((mp->mnt_iflag & IMNT_SUSPEND) == 0)
+               return;
+       mp->mnt_iflag &= ~(IMNT_SUSPEND | IMNT_SUSPENDLOW | IMNT_SUSPENDED);
+       wakeup(&mp->mnt_flag);
+}
+
 void
 copy_statfs_info(struct statfs *sbp, const struct mount *mp)
 {
diff -r a30dea40b269 -r 6526b0e96180 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c      Sat Jan 10 17:04:44 2004 +0000
+++ b/sys/kern/vfs_vnops.c      Sat Jan 10 17:16:38 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnops.c,v 1.75 2003/10/15 11:29:01 hannken Exp $   */
+/*     $NetBSD: vfs_vnops.c,v 1.76 2004/01/10 17:16:38 hannken Exp $   */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.75 2003/10/15 11:29:01 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.76 2004/01/10 17:16:38 hannken Exp $");
 
 #include "fs_union.h"
 
@@ -825,41 +825,3 @@
        lkp->lk_flags &= ~LK_CANRECURSE;
        lkp->lk_flags |= flags;
 }
-
-/*
- * Request a filesystem to suspend write operations.
- */
-int
-vfs_write_suspend(struct mount *mp)
-{
-       struct proc *p = curproc;       /* XXX */
-       int error;
-
-       if (mp->mnt_iflag & IMNT_SUSPEND)
-               return (0);
-       mp->mnt_iflag |= IMNT_SUSPEND;
-       if (mp->mnt_writeopcountupper > 0)
-               tsleep(&mp->mnt_writeopcountupper, PUSER - 1, "suspwt", 0);
-       if ((error = VFS_SYNC(mp, MNT_WAIT, p->p_ucred, p)) != 0) {
-               vfs_write_resume(mp);
-               return (error);
-       }
-       mp->mnt_iflag |= IMNT_SUSPENDLOW;
-       if (mp->mnt_writeopcountlower > 0)
-               tsleep(&mp->mnt_writeopcountlower, PUSER - 1, "suspwt", 0);
-       mp->mnt_iflag |= IMNT_SUSPENDED;
-       return (0);
-}
-
-/*
- * Request a filesystem to resume write operations.
- */
-void
-vfs_write_resume(struct mount *mp)
-{
-
-       if ((mp->mnt_iflag & IMNT_SUSPEND) == 0)
-               return;
-       mp->mnt_iflag &= ~(IMNT_SUSPEND | IMNT_SUSPENDLOW | IMNT_SUSPENDED);
-       wakeup(&mp->mnt_flag);
-}
diff -r a30dea40b269 -r 6526b0e96180 sys/sys/vnode.h
--- a/sys/sys/vnode.h   Sat Jan 10 17:04:44 2004 +0000
+++ b/sys/sys/vnode.h   Sat Jan 10 17:16:38 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vnode.h,v 1.118 2003/11/18 18:26:18 dbj Exp $  */
+/*     $NetBSD: vnode.h,v 1.119 2004/01/10 17:16:38 hannken Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -678,12 +678,12 @@
 /* see vfssubr(9) */
 void   vfs_getnewfsid(struct mount *);
 int    vfs_drainvnodes(long target, struct proc *);
+void   vfs_write_resume(struct mount *);
+int    vfs_write_suspend(struct mount *, int, int);
 #ifdef DDB
 void   vfs_vnode_print(struct vnode *, int, void (*)(const char *, ...));
 void   vfs_mount_print(struct mount *, int, void (*)(const char *, ...));
 #endif /* DDB */
-void   vfs_write_resume(struct mount *);
-int    vfs_write_suspend(struct mount *);
 #endif /* _KERNEL */
 
 #endif /* !_SYS_VNODE_H_ */
diff -r a30dea40b269 -r 6526b0e96180 sys/ufs/ffs/ffs_softdep.c
--- a/sys/ufs/ffs/ffs_softdep.c Sat Jan 10 17:04:44 2004 +0000
+++ b/sys/ufs/ffs/ffs_softdep.c Sat Jan 10 17:16:38 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs_softdep.c,v 1.54 2004/01/10 16:23:36 hannken Exp $ */
+/*     $NetBSD: ffs_softdep.c,v 1.55 2004/01/10 17:16:38 hannken Exp $ */
 
 /*
  * Copyright 1998 Marshall Kirk McKusick. All Rights Reserved.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_softdep.c,v 1.54 2004/01/10 16:23:36 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_softdep.c,v 1.55 2004/01/10 17:16:38 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -193,7 +193,7 @@
 #endif
 void softdep_pageiodone __P((struct buf *));
 void softdep_flush_vnode __P((struct vnode *, daddr_t));
-static void softdep_trackbufs(int, boolean_t);
+static void softdep_trackbufs(struct inode *, int, boolean_t);
 
 /*
  * Exported softdep operations.
@@ -692,9 +692,9 @@
                        mp = WK_DIRREM(wk)->dm_mnt;
                        if (mp == matchmnt)
                                matchcnt += 1;
-                       vn_start_write(NULL, &mp, V_WAIT);
+                       vn_start_write(NULL, &mp, V_WAIT|V_LOWER);
                        handle_workitem_remove(WK_DIRREM(wk));
-                       vn_finished_write(mp, 0);
+                       vn_finished_write(mp, V_LOWER);
                        break;
 
                case D_FREEBLKS:
@@ -702,9 +702,9 @@
                        mp = WK_FREEBLKS(wk)->fb_ump->um_mountp;
                        if (mp == matchmnt)
                                matchcnt += 1;
-                       vn_start_write(NULL, &mp, V_WAIT);
+                       vn_start_write(NULL, &mp, V_WAIT|V_LOWER);
                        handle_workitem_freeblocks(WK_FREEBLKS(wk));
-                       vn_finished_write(mp, 0);
+                       vn_finished_write(mp, V_LOWER);
                        break;
 
                case D_FREEFRAG:
@@ -712,9 +712,9 @@
                        mp = WK_FREEFRAG(wk)->ff_mnt;
                        if (mp == matchmnt)
                                matchcnt += 1;
-                       vn_start_write(NULL, &mp, V_WAIT);
+                       vn_start_write(NULL, &mp, V_WAIT|V_LOWER);
                        handle_workitem_freefrag(WK_FREEFRAG(wk));
-                       vn_finished_write(mp, 0);
+                       vn_finished_write(mp, V_LOWER);
                        break;
 



Home | Main Index | Thread Index | Old Index