From fae85b1e6961525c0b9017bb021d98e19c2e4451 Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 21 Oct 2021 09:59:13 +0000 Subject: [PATCH] Move vfs_stall_barrier() from the fd layer into vn_lock() and the vfs layer. vfs stalling is used by suspend/resume and by vmt(4) to stall any filesystem operation from altering the state on disk. All these operations will call vn_lock and be stalled. Adjust vfs_stall_barrier() to allow the lock owner to still progress so that suspend can sync the filesystems after stalling vfs operation. OK mpi@ --- sys/kern/kern_descrip.c | 4 +--- sys/kern/vfs_subr.c | 8 +++++--- sys/kern/vfs_vnops.c | 4 +++- sys/sys/file.h | 8 ++------ 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 744b2247801..ea3e3399ce0 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.202 2020/06/11 13:23:18 visa Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.203 2021/10/21 09:59:13 claudio Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -232,8 +232,6 @@ fd_getfile(struct filedesc *fdp, int fd) { struct file *fp; - vfs_stall_barrier(); - if ((u_int)fd >= fdp->fd_nfiles) return (NULL); diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 794a4f2cf03..011e7597269 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_subr.c,v 1.308 2021/10/20 06:35:39 semarie Exp $ */ +/* $OpenBSD: vfs_subr.c,v 1.309 2021/10/21 09:59:14 claudio Exp $ */ /* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */ /* @@ -1701,8 +1701,10 @@ void vfs_stall_barrier(void) { if (__predict_false(vfs_stalling)) { - rw_enter_read(&vfs_stall_lock); - rw_exit_read(&vfs_stall_lock); + if (curproc != RWLOCK_OWNER(&vfs_stall_lock)) { + rw_enter_read(&vfs_stall_lock); + rw_exit_read(&vfs_stall_lock); + } } } diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index f726d72f8cb..de6d7593b14 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_vnops.c,v 1.116 2021/05/06 12:55:20 anton Exp $ */ +/* $OpenBSD: vfs_vnops.c,v 1.117 2021/10/21 09:59:14 claudio Exp $ */ /* $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $ */ /* @@ -565,6 +565,8 @@ vn_lock(struct vnode *vp, int flags) { int error, xlocked, do_wakeup; + vfs_stall_barrier(); + do { mtx_enter(&vnode_mtx); if (vp->v_lflag & VXLOCK) { diff --git a/sys/sys/file.h b/sys/sys/file.h index ff07a1d41b1..b440e1275c5 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file.h,v 1.62 2020/12/02 15:50:01 martijn Exp $ */ +/* $OpenBSD: file.h,v 1.63 2021/10/21 09:59:14 claudio Exp $ */ /* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */ /* @@ -106,11 +106,7 @@ struct file { #define FIF_INSERTED 0x80 /* present in `filehead' */ #define FREF(fp) \ - do { \ - extern void vfs_stall_barrier(void); \ - vfs_stall_barrier(); \ - atomic_inc_int(&(fp)->f_count); \ - } while (0) + atomic_inc_int(&(fp)->f_count) #define FRELE(fp,p) \ (atomic_dec_int_nv(&fp->f_count) == 0 ? fdrop(fp, p) : 0) -- 2.20.1