Mon Apr 20 21:39:05 2020 UTC ()
Rename buf_syncwait() to vfs_syncwait(), and have it wait on v_numoutput
rather than BC_BUSY.  Removes the dependency on bufhash.


(ad)
diff -r1.41 -r1.42 src/sys/kern/kern_pmf.c
diff -r1.293 -r1.294 src/sys/kern/vfs_bio.c
diff -r1.79 -r1.80 src/sys/kern/vfs_mount.c
diff -r1.545 -r1.546 src/sys/kern/vfs_syscalls.c
diff -r1.91 -r1.92 src/sys/rump/librump/rumpvfs/rump_vfs.c
diff -r1.132 -r1.133 src/sys/sys/buf.h
diff -r1.27 -r1.28 src/sys/sys/vfs_syscalls.h

cvs diff -r1.41 -r1.42 src/sys/kern/kern_pmf.c (expand / switch to unified diff)

--- src/sys/kern/kern_pmf.c 2020/02/23 20:08:35 1.41
+++ src/sys/kern/kern_pmf.c 2020/04/20 21:39:05 1.42
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_pmf.c,v 1.41 2020/02/23 20:08:35 ad Exp $ */ 1/* $NetBSD: kern_pmf.c,v 1.42 2020/04/20 21:39:05 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: kern_pmf.c,v 1.41 2020/02/23 20:08:35 ad Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: kern_pmf.c,v 1.42 2020/04/20 21:39:05 ad Exp $");
31 31
32#include <sys/types.h> 32#include <sys/types.h>
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/kmem.h> 34#include <sys/kmem.h>
35#include <sys/buf.h> 35#include <sys/buf.h>
36#include <sys/callout.h> 36#include <sys/callout.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/device.h> 38#include <sys/device.h>
39#include <sys/pmf.h> 39#include <sys/pmf.h>
40#include <sys/queue.h> 40#include <sys/queue.h>
41#include <sys/sched.h> 41#include <sys/sched.h>
42#include <sys/workqueue.h> 42#include <sys/workqueue.h>
43#include <prop/proplib.h> 43#include <prop/proplib.h>
@@ -307,27 +307,27 @@ pmf_system_suspend(const pmf_qual_t *qua @@ -307,27 +307,27 @@ pmf_system_suspend(const pmf_qual_t *qua
307#if NWSDISPLAY > 0 307#if NWSDISPLAY > 0
308 if (wsdisplay_handlex(0)) 308 if (wsdisplay_handlex(0))
309 return false; 309 return false;
310#endif 310#endif
311 KERNEL_LOCK(1, NULL); 311 KERNEL_LOCK(1, NULL);
312 312
313 /* 313 /*
314 * Flush buffers only if the shutdown didn't do so 314 * Flush buffers only if the shutdown didn't do so
315 * already and if there was no panic. 315 * already and if there was no panic.
316 */ 316 */
317 if (doing_shutdown == 0 && panicstr == NULL) { 317 if (doing_shutdown == 0 && panicstr == NULL) {
318 printf("Flushing disk caches: "); 318 printf("Flushing disk caches: ");
319 do_sys_sync(&lwp0); 319 do_sys_sync(&lwp0);
320 if (buf_syncwait() != 0) 320 if (vfs_syncwait() != 0)
321 printf("giving up\n"); 321 printf("giving up\n");
322 else 322 else
323 printf("done\n"); 323 printf("done\n");
324 } 324 }
325 325
326 aprint_debug("Suspending devices:"); 326 aprint_debug("Suspending devices:");
327 327
328 for (curdev = deviter_first(&di, DEVITER_F_LEAVES_FIRST); 328 for (curdev = deviter_first(&di, DEVITER_F_LEAVES_FIRST);
329 curdev != NULL; 329 curdev != NULL;
330 curdev = deviter_next(&di)) { 330 curdev = deviter_next(&di)) {
331 if (!device_is_active(curdev)) 331 if (!device_is_active(curdev))
332 continue; 332 continue;
333 333

cvs diff -r1.293 -r1.294 src/sys/kern/vfs_bio.c (expand / switch to unified diff)

--- src/sys/kern/vfs_bio.c 2020/04/11 14:48:19 1.293
+++ src/sys/kern/vfs_bio.c 2020/04/20 21:39:05 1.294
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_bio.c,v 1.293 2020/04/11 14:48:19 jdolecek Exp $ */ 1/* $NetBSD: vfs_bio.c,v 1.294 2020/04/20 21:39:05 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007, 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran, and by Wasabi Systems, Inc. 8 * by Andrew Doran, and by Wasabi Systems, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -113,27 +113,27 @@ @@ -113,27 +113,27 @@
113 * - bufcache_lock: protects global buffer cache state. 113 * - bufcache_lock: protects global buffer cache state.
114 * - BC_BUSY: a long term per-buffer lock. 114 * - BC_BUSY: a long term per-buffer lock.
115 * - buf_t::b_objlock: lock on completion (biowait vs biodone). 115 * - buf_t::b_objlock: lock on completion (biowait vs biodone).
116 * 116 *
117 * For buffers associated with vnodes (a most common case) b_objlock points 117 * For buffers associated with vnodes (a most common case) b_objlock points
118 * to the vnode_t::v_interlock. Otherwise, it points to generic buffer_lock. 118 * to the vnode_t::v_interlock. Otherwise, it points to generic buffer_lock.
119 * 119 *
120 * Lock order: 120 * Lock order:
121 * bufcache_lock -> 121 * bufcache_lock ->
122 * buf_t::b_objlock 122 * buf_t::b_objlock
123 */ 123 */
124 124
125#include <sys/cdefs.h> 125#include <sys/cdefs.h>
126__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.293 2020/04/11 14:48:19 jdolecek Exp $"); 126__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.294 2020/04/20 21:39:05 ad Exp $");
127 127
128#ifdef _KERNEL_OPT 128#ifdef _KERNEL_OPT
129#include "opt_bufcache.h" 129#include "opt_bufcache.h"
130#include "opt_dtrace.h" 130#include "opt_dtrace.h"
131#include "opt_biohist.h" 131#include "opt_biohist.h"
132#endif 132#endif
133 133
134#include <sys/param.h> 134#include <sys/param.h>
135#include <sys/systm.h> 135#include <sys/systm.h>
136#include <sys/kernel.h> 136#include <sys/kernel.h>
137#include <sys/proc.h> 137#include <sys/proc.h>
138#include <sys/buf.h> 138#include <sys/buf.h>
139#include <sys/vnode.h> 139#include <sys/vnode.h>
@@ -1698,77 +1698,26 @@ biointr(void *cookie) @@ -1698,77 +1698,26 @@ biointr(void *cookie)
1698 1698
1699 bp = TAILQ_FIRST(&ci->ci_data.cpu_biodone); 1699 bp = TAILQ_FIRST(&ci->ci_data.cpu_biodone);
1700 TAILQ_REMOVE(&ci->ci_data.cpu_biodone, bp, b_actq); 1700 TAILQ_REMOVE(&ci->ci_data.cpu_biodone, bp, b_actq);
1701 splx(s); 1701 splx(s);
1702 1702
1703 BIOHIST_LOG(biohist, "bp=%#jx", (uintptr_t)bp, 0, 0, 0); 1703 BIOHIST_LOG(biohist, "bp=%#jx", (uintptr_t)bp, 0, 0, 0);
1704 biodone2(bp); 1704 biodone2(bp);
1705 1705
1706 s = splvm(); 1706 s = splvm();
1707 } 1707 }
1708 splx(s); 1708 splx(s);
1709} 1709}
1710 1710
1711/* 
1712 * Wait for all buffers to complete I/O 
1713 * Return the number of "stuck" buffers. 
1714 */ 
1715int 
1716buf_syncwait(void) 
1717{ 
1718 buf_t *bp; 
1719 int iter, nbusy, nbusy_prev = 0, ihash; 
1720 
1721 BIOHIST_FUNC(__func__); BIOHIST_CALLED(biohist); 
1722 
1723 for (iter = 0; iter < 20;) { 
1724 mutex_enter(&bufcache_lock); 
1725 nbusy = 0; 
1726 for (ihash = 0; ihash < bufhash+1; ihash++) { 
1727 LIST_FOREACH(bp, &bufhashtbl[ihash], b_hash) { 
1728 if ((bp->b_cflags & (BC_BUSY|BC_INVAL)) == BC_BUSY) 
1729 nbusy += ((bp->b_flags & B_READ) == 0); 
1730 } 
1731 } 
1732 mutex_exit(&bufcache_lock); 
1733 
1734 if (nbusy == 0) 
1735 break; 
1736 if (nbusy_prev == 0) 
1737 nbusy_prev = nbusy; 
1738 printf("%d ", nbusy); 
1739 kpause("bflush", false, MAX(1, hz / 25 * iter), NULL); 
1740 if (nbusy >= nbusy_prev) /* we didn't flush anything */ 
1741 iter++; 
1742 else 
1743 nbusy_prev = nbusy; 
1744 } 
1745 
1746 if (nbusy) { 
1747#if defined(DEBUG) || defined(DEBUG_HALT_BUSY) 
1748 printf("giving up\nPrinting vnodes for busy buffers\n"); 
1749 for (ihash = 0; ihash < bufhash+1; ihash++) { 
1750 LIST_FOREACH(bp, &bufhashtbl[ihash], b_hash) { 
1751 if ((bp->b_cflags & (BC_BUSY|BC_INVAL)) == BC_BUSY && 
1752 (bp->b_flags & B_READ) == 0) 
1753 vprint(NULL, bp->b_vp); 
1754 } 
1755 } 
1756#endif 
1757 } 
1758 
1759 return nbusy; 
1760} 
1761 
1762static void 1711static void
1763sysctl_fillbuf(const buf_t *i, struct buf_sysctl *o) 1712sysctl_fillbuf(const buf_t *i, struct buf_sysctl *o)
1764{ 1713{
1765 const bool allowaddr = get_expose_address(curproc); 1714 const bool allowaddr = get_expose_address(curproc);
1766 1715
1767 memset(o, 0, sizeof(*o)); 1716 memset(o, 0, sizeof(*o));
1768 1717
1769 o->b_flags = i->b_flags | i->b_cflags | i->b_oflags; 1718 o->b_flags = i->b_flags | i->b_cflags | i->b_oflags;
1770 o->b_error = i->b_error; 1719 o->b_error = i->b_error;
1771 o->b_prio = i->b_prio; 1720 o->b_prio = i->b_prio;
1772 o->b_dev = i->b_dev; 1721 o->b_dev = i->b_dev;
1773 o->b_bufsize = i->b_bufsize; 1722 o->b_bufsize = i->b_bufsize;
1774 o->b_bcount = i->b_bcount; 1723 o->b_bcount = i->b_bcount;

cvs diff -r1.79 -r1.80 src/sys/kern/vfs_mount.c (expand / switch to unified diff)

--- src/sys/kern/vfs_mount.c 2020/04/19 13:26:17 1.79
+++ src/sys/kern/vfs_mount.c 2020/04/20 21:39:05 1.80
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_mount.c,v 1.79 2020/04/19 13:26:17 hannken Exp $ */ 1/* $NetBSD: vfs_mount.c,v 1.80 2020/04/20 21:39:05 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997-2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran. 9 * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -57,27 +57,27 @@ @@ -57,27 +57,27 @@
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE. 64 * SUCH DAMAGE.
65 * 65 *
66 * @(#)vfs_subr.c 8.13 (Berkeley) 4/18/94 66 * @(#)vfs_subr.c 8.13 (Berkeley) 4/18/94
67 */ 67 */
68 68
69#include <sys/cdefs.h> 69#include <sys/cdefs.h>
70__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.79 2020/04/19 13:26:17 hannken Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.80 2020/04/20 21:39:05 ad Exp $");
71 71
72#include <sys/param.h> 72#include <sys/param.h>
73#include <sys/kernel.h> 73#include <sys/kernel.h>
74 74
75#include <sys/atomic.h> 75#include <sys/atomic.h>
76#include <sys/buf.h> 76#include <sys/buf.h>
77#include <sys/conf.h> 77#include <sys/conf.h>
78#include <sys/fcntl.h> 78#include <sys/fcntl.h>
79#include <sys/filedesc.h> 79#include <sys/filedesc.h>
80#include <sys/device.h> 80#include <sys/device.h>
81#include <sys/kauth.h> 81#include <sys/kauth.h>
82#include <sys/kmem.h> 82#include <sys/kmem.h>
83#include <sys/module.h> 83#include <sys/module.h>
@@ -1083,27 +1083,27 @@ vfs_sync_all(struct lwp *l) @@ -1083,27 +1083,27 @@ vfs_sync_all(struct lwp *l)
1083{ 1083{
1084 printf("syncing disks... "); 1084 printf("syncing disks... ");
1085 1085
1086 /* remove user processes from run queue */ 1086 /* remove user processes from run queue */
1087 suspendsched(); 1087 suspendsched();
1088 (void)spl0(); 1088 (void)spl0();
1089 1089
1090 /* avoid coming back this way again if we panic. */ 1090 /* avoid coming back this way again if we panic. */
1091 doing_shutdown = 1; 1091 doing_shutdown = 1;
1092 1092
1093 do_sys_sync(l); 1093 do_sys_sync(l);
1094 1094
1095 /* Wait for sync to finish. */ 1095 /* Wait for sync to finish. */
1096 if (buf_syncwait() != 0) { 1096 if (vfs_syncwait() != 0) {
1097#if defined(DDB) && defined(DEBUG_HALT_BUSY) 1097#if defined(DDB) && defined(DEBUG_HALT_BUSY)
1098 Debugger(); 1098 Debugger();
1099#endif 1099#endif
1100 printf("giving up\n"); 1100 printf("giving up\n");
1101 return; 1101 return;
1102 } else 1102 } else
1103 printf("done\n"); 1103 printf("done\n");
1104} 1104}
1105 1105
1106/* 1106/*
1107 * Sync and unmount file systems before shutting down. 1107 * Sync and unmount file systems before shutting down.
1108 */ 1108 */
1109void 1109void

cvs diff -r1.545 -r1.546 src/sys/kern/vfs_syscalls.c (expand / switch to unified diff)

--- src/sys/kern/vfs_syscalls.c 2020/04/04 20:49:30 1.545
+++ src/sys/kern/vfs_syscalls.c 2020/04/20 21:39:05 1.546
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_syscalls.c,v 1.545 2020/04/04 20:49:30 ad Exp $ */ 1/* $NetBSD: vfs_syscalls.c,v 1.546 2020/04/20 21:39:05 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -60,27 +60,27 @@ @@ -60,27 +60,27 @@
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE. 63 * SUCH DAMAGE.
64 * 64 *
65 * @(#)vfs_syscalls.c 8.42 (Berkeley) 7/31/95 65 * @(#)vfs_syscalls.c 8.42 (Berkeley) 7/31/95
66 */ 66 */
67 67
68/* 68/*
69 * Virtual File System System Calls 69 * Virtual File System System Calls
70 */ 70 */
71 71
72#include <sys/cdefs.h> 72#include <sys/cdefs.h>
73__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.545 2020/04/04 20:49:30 ad Exp $"); 73__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.546 2020/04/20 21:39:05 ad Exp $");
74 74
75#ifdef _KERNEL_OPT 75#ifdef _KERNEL_OPT
76#include "opt_fileassoc.h" 76#include "opt_fileassoc.h"
77#include "veriexec.h" 77#include "veriexec.h"
78#endif 78#endif
79 79
80#include <sys/param.h> 80#include <sys/param.h>
81#include <sys/systm.h> 81#include <sys/systm.h>
82#include <sys/namei.h> 82#include <sys/namei.h>
83#include <sys/filedesc.h> 83#include <sys/filedesc.h>
84#include <sys/kernel.h> 84#include <sys/kernel.h>
85#include <sys/file.h> 85#include <sys/file.h>
86#include <sys/fcntl.h> 86#include <sys/fcntl.h>
@@ -662,26 +662,92 @@ do_sys_sync(struct lwp *l) @@ -662,26 +662,92 @@ do_sys_sync(struct lwp *l)
662 VFS_SYNC(mp, MNT_NOWAIT, l->l_cred); 662 VFS_SYNC(mp, MNT_NOWAIT, l->l_cred);
663 if (asyncflag) 663 if (asyncflag)
664 mp->mnt_flag |= MNT_ASYNC; 664 mp->mnt_flag |= MNT_ASYNC;
665 } 665 }
666 mutex_exit(mp->mnt_updating); 666 mutex_exit(mp->mnt_updating);
667 } 667 }
668 mountlist_iterator_destroy(iter); 668 mountlist_iterator_destroy(iter);
669#ifdef DEBUG 669#ifdef DEBUG
670 if (syncprt) 670 if (syncprt)
671 vfs_bufstats(); 671 vfs_bufstats();
672#endif /* DEBUG */ 672#endif /* DEBUG */
673} 673}
674 674
 675static bool
 676sync_vnode_filter(void *cookie, vnode_t *vp)
 677{
 678
 679 if (vp->v_numoutput > 0) {
 680 ++*(int *)cookie;
 681 }
 682 return false;
 683}
 684
 685int
 686vfs_syncwait(void)
 687{
 688 int nbusy, nbusy_prev, iter;
 689 struct vnode_iterator *vniter;
 690 mount_iterator_t *mpiter;
 691 struct mount *mp;
 692
 693 for (nbusy_prev = 0, iter = 0; iter < 20;) {
 694 nbusy = 0;
 695 mountlist_iterator_init(&mpiter);
 696 while ((mp = mountlist_iterator_next(mpiter)) != NULL) {
 697 vnode_t *vp __diagused;
 698 vfs_vnode_iterator_init(mp, &vniter);
 699 vp = vfs_vnode_iterator_next(vniter,
 700 sync_vnode_filter, &nbusy);
 701 KASSERT(vp == NULL);
 702 vfs_vnode_iterator_destroy(vniter);
 703 }
 704 mountlist_iterator_destroy(mpiter);
 705
 706 if (nbusy == 0)
 707 break;
 708 if (nbusy_prev == 0)
 709 nbusy_prev = nbusy;
 710 printf("%d ", nbusy);
 711 kpause("syncwait", false, MAX(1, hz / 25 * iter), NULL);
 712 if (nbusy >= nbusy_prev) /* we didn't flush anything */
 713 iter++;
 714 else
 715 nbusy_prev = nbusy;
 716 }
 717
 718 if (nbusy) {
 719#if defined(DEBUG) || defined(DEBUG_HALT_BUSY)
 720 printf("giving up\nPrinting vnodes for busy buffers\n");
 721 mountlist_iterator_init(&mpiter);
 722 while ((mp = mountlist_iterator_next(mpiter)) != NULL) {
 723 vnode_t *vp;
 724 vfs_vnode_iterator_init(mp, &vniter);
 725 vp = vfs_vnode_iterator_next(vniter,
 726 NULL, NULL);
 727 mutex_enter(vp->v_interlock);
 728 if (vp->v_numoutput > 0)
 729 vprint(NULL, vp);
 730 mutex_exit(vp->v_interlock);
 731 vrele(vp);
 732 vfs_vnode_iterator_destroy(vniter);
 733 }
 734 mountlist_iterator_destroy(mpiter);
 735#endif
 736 }
 737
 738 return nbusy;
 739}
 740
675/* ARGSUSED */ 741/* ARGSUSED */
676int 742int
677sys_sync(struct lwp *l, const void *v, register_t *retval) 743sys_sync(struct lwp *l, const void *v, register_t *retval)
678{ 744{
679 do_sys_sync(l); 745 do_sys_sync(l);
680 return (0); 746 return (0);
681} 747}
682 748
683 749
684/* 750/*
685 * Access or change filesystem quotas. 751 * Access or change filesystem quotas.
686 * 752 *
687 * (this is really 14 different calls bundled into one) 753 * (this is really 14 different calls bundled into one)

cvs diff -r1.91 -r1.92 src/sys/rump/librump/rumpvfs/rump_vfs.c (expand / switch to unified diff)

--- src/sys/rump/librump/rumpvfs/rump_vfs.c 2020/04/13 19:23:20 1.91
+++ src/sys/rump/librump/rumpvfs/rump_vfs.c 2020/04/20 21:39:05 1.92
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rump_vfs.c,v 1.91 2020/04/13 19:23:20 ad Exp $ */ 1/* $NetBSD: rump_vfs.c,v 1.92 2020/04/20 21:39:05 ad Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2008 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by the 6 * Development of this software was supported by the
7 * Finnish Cultural Foundation. 7 * Finnish Cultural Foundation.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.91 2020/04/13 19:23:20 ad Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.92 2020/04/20 21:39:05 ad Exp $");
33 33
34#include <sys/param.h> 34#include <sys/param.h>
35#include <sys/buf.h> 35#include <sys/buf.h>
36#include <sys/conf.h> 36#include <sys/conf.h>
37#include <sys/evcnt.h> 37#include <sys/evcnt.h>
38#include <sys/fcntl.h> 38#include <sys/fcntl.h>
39#include <sys/filedesc.h> 39#include <sys/filedesc.h>
40#include <sys/fstrans.h> 40#include <sys/fstrans.h>
41#include <sys/lockf.h> 41#include <sys/lockf.h>
42#include <sys/kthread.h> 42#include <sys/kthread.h>
43#include <sys/module.h> 43#include <sys/module.h>
44#include <sys/namei.h> 44#include <sys/namei.h>
45#include <sys/queue.h> 45#include <sys/queue.h>
@@ -460,27 +460,27 @@ int @@ -460,27 +460,27 @@ int
460rump_vfs_extattrctl(struct mount *mp, int cmd, struct vnode *vp, 460rump_vfs_extattrctl(struct mount *mp, int cmd, struct vnode *vp,
461 int attrnamespace, const char *attrname) 461 int attrnamespace, const char *attrname)
462{ 462{
463 463
464 return VFS_EXTATTRCTL(mp, cmd, vp, attrnamespace, attrname); 464 return VFS_EXTATTRCTL(mp, cmd, vp, attrnamespace, attrname);
465} 465}
466 466
467/*ARGSUSED*/ 467/*ARGSUSED*/
468void 468void
469rump_vfs_syncwait(struct mount *mp) 469rump_vfs_syncwait(struct mount *mp)
470{ 470{
471 int n; 471 int n;
472 472
473 n = buf_syncwait(); 473 n = vfs_syncwait();
474 if (n) 474 if (n)
475 printf("syncwait: unsynced buffers: %d\n", n); 475 printf("syncwait: unsynced buffers: %d\n", n);
476} 476}
477 477
478/* 478/*
479 * Dump info about mount point. No locking. 479 * Dump info about mount point. No locking.
480 */ 480 */
481static bool 481static bool
482rump_print_selector(void *cl, struct vnode *vp) 482rump_print_selector(void *cl, struct vnode *vp)
483{ 483{
484 int *full = cl; 484 int *full = cl;
485 485
486 KASSERT(mutex_owned(vp->v_interlock)); 486 KASSERT(mutex_owned(vp->v_interlock));

cvs diff -r1.132 -r1.133 src/sys/sys/buf.h (expand / switch to unified diff)

--- src/sys/sys/buf.h 2020/04/10 17:18:04 1.132
+++ src/sys/sys/buf.h 2020/04/20 21:39:05 1.133
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: buf.h,v 1.132 2020/04/10 17:18:04 ad Exp $ */ 1/* $NetBSD: buf.h,v 1.133 2020/04/20 21:39:05 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Andrew Doran. 9 * NASA Ames Research Center, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -289,27 +289,26 @@ void brelsel(buf_t *, int); @@ -289,27 +289,26 @@ void brelsel(buf_t *, int);
289void brelse(buf_t *, int); 289void brelse(buf_t *, int);
290 290
291/* 291/*
292 * So-far indeterminate ops that might belong to either 292 * So-far indeterminate ops that might belong to either
293 * bufferio(9) or buffercache(9). 293 * bufferio(9) or buffercache(9).
294 */ 294 */
295void bremfree(buf_t *); 295void bremfree(buf_t *);
296void bufinit(void); 296void bufinit(void);
297void bufinit2(void); 297void bufinit2(void);
298void minphys(buf_t *); 298void minphys(buf_t *);
299void brelvp(buf_t *); 299void brelvp(buf_t *);
300void reassignbuf(buf_t *, struct vnode *); 300void reassignbuf(buf_t *, struct vnode *);
301void bgetvp(struct vnode *, buf_t *); 301void bgetvp(struct vnode *, buf_t *);
302int buf_syncwait(void); 
303u_long buf_memcalc(void); 302u_long buf_memcalc(void);
304int buf_drain(int); 303int buf_drain(int);
305int buf_setvalimit(vsize_t); 304int buf_setvalimit(vsize_t);
306#if defined(DDB) || defined(DEBUGPRINT) 305#if defined(DDB) || defined(DEBUGPRINT)
307void vfs_buf_print(buf_t *, int, void (*)(const char *, ...) 306void vfs_buf_print(buf_t *, int, void (*)(const char *, ...)
308 __printflike(1, 2)); 307 __printflike(1, 2));
309#endif 308#endif
310void buf_init(buf_t *); 309void buf_init(buf_t *);
311void buf_destroy(buf_t *); 310void buf_destroy(buf_t *);
312int bbusy(buf_t *, bool, int, kmutex_t *); 311int bbusy(buf_t *, bool, int, kmutex_t *);
313u_int buf_nbuf(void); 312u_int buf_nbuf(void);
314 313
315void biohist_init(void); 314void biohist_init(void);

cvs diff -r1.27 -r1.28 src/sys/sys/vfs_syscalls.h (expand / switch to unified diff)

--- src/sys/sys/vfs_syscalls.h 2020/02/23 22:14:04 1.27
+++ src/sys/sys/vfs_syscalls.h 2020/04/20 21:39:05 1.28
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_syscalls.h,v 1.27 2020/02/23 22:14:04 ad Exp $ */ 1/* $NetBSD: vfs_syscalls.h,v 1.28 2020/04/20 21:39:05 ad Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -70,21 +70,22 @@ int dofhopen(struct lwp *, const void *, @@ -70,21 +70,22 @@ int dofhopen(struct lwp *, const void *,
70int do_sys_linkat(struct lwp *, int, const char *, int, const char *, int, register_t *); 70int do_sys_linkat(struct lwp *, int, const char *, int, const char *, int, register_t *);
71int do_sys_unlink(const char *, enum uio_seg); 71int do_sys_unlink(const char *, enum uio_seg);
72int do_sys_rename(const char *, const char *, enum uio_seg, int); 72int do_sys_rename(const char *, const char *, enum uio_seg, int);
73int do_posix_mknodat(struct lwp *, int, const char *, mode_t, dev_t); 73int do_posix_mknodat(struct lwp *, int, const char *, mode_t, dev_t);
74int do_sys_mknod(struct lwp *, const char *, mode_t, dev_t, enum uio_seg); 74int do_sys_mknod(struct lwp *, const char *, mode_t, dev_t, enum uio_seg);
75int do_sys_mknodat(struct lwp *, int, const char *, mode_t, dev_t, enum uio_seg); 75int do_sys_mknodat(struct lwp *, int, const char *, mode_t, dev_t, enum uio_seg);
76int do_sys_chmodat(struct lwp *, int, const char *, int, int); 76int do_sys_chmodat(struct lwp *, int, const char *, int, int);
77int do_sys_chownat(struct lwp *, int, const char *, uid_t, gid_t, int); 77int do_sys_chownat(struct lwp *, int, const char *, uid_t, gid_t, int);
78int do_sys_accessat(struct lwp *, int, const char *, int ,int); 78int do_sys_accessat(struct lwp *, int, const char *, int ,int);
79int do_sys_mkdir(const char *, mode_t, enum uio_seg); 79int do_sys_mkdir(const char *, mode_t, enum uio_seg);
80int do_sys_symlink(const char *, const char *, enum uio_seg); 80int do_sys_symlink(const char *, const char *, enum uio_seg);
81int do_sys_quotactl(const char *, const struct quotactl_args *); 81int do_sys_quotactl(const char *, const struct quotactl_args *);
82void do_sys_sync(struct lwp *); 82void do_sys_sync(struct lwp *);
 83int vfs_syncwait(void);
83 84
84int chdir_lookup(const char *, int, struct vnode **, struct lwp *); 85int chdir_lookup(const char *, int, struct vnode **, struct lwp *);
85void change_root(struct vnode *); 86void change_root(struct vnode *);
86 87
87extern const char *const mountcompatnames[]; 88extern const char *const mountcompatnames[];
88extern const u_int nmountcompatnames; 89extern const u_int nmountcompatnames;
89 90
90#endif /* _SYS_VFS_SYSCALLS_H_ */ 91#endif /* _SYS_VFS_SYSCALLS_H_ */