Module Name: src Committed By: riastradh Date: Mon Mar 28 12:35:44 UTC 2022
Modified Files: src/sys/miscfs/specfs: spec_vnops.c Log Message: specfs: sn_gone cannot be set while we hold the vnode lock. Revoke runs with the vnode lock too, which is exclusive. Add an assertion to this effect in spec_node_revoke to make it clear. To generate a diff of this commit: cvs rdiff -u -r1.194 -r1.195 src/sys/miscfs/specfs/spec_vnops.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/miscfs/specfs/spec_vnops.c diff -u src/sys/miscfs/specfs/spec_vnops.c:1.194 src/sys/miscfs/specfs/spec_vnops.c:1.195 --- src/sys/miscfs/specfs/spec_vnops.c:1.194 Mon Mar 28 12:35:35 2022 +++ src/sys/miscfs/specfs/spec_vnops.c Mon Mar 28 12:35:44 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: spec_vnops.c,v 1.194 2022/03/28 12:35:35 riastradh Exp $ */ +/* $NetBSD: spec_vnops.c,v 1.195 2022/03/28 12:35:44 riastradh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.194 2022/03/28 12:35:35 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.195 2022/03/28 12:35:44 riastradh Exp $"); #include <sys/param.h> #include <sys/proc.h> @@ -402,6 +402,8 @@ spec_node_revoke(vnode_t *vp) specnode_t *sn; specdev_t *sd; + KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE); + sn = vp->v_specnode; sd = sn->sn_dev; @@ -552,11 +554,8 @@ spec_open(void *v) /* * Acquire an open reference -- as long as we hold onto it, and - * the vnode isn't revoked, it can't be closed. - * - * But first check whether it has been revoked -- if so, we - * can't acquire more open references and we must fail - * immediately with EBADF. + * the vnode isn't revoked, it can't be closed, and the vnode + * can't be revoked until we release the vnode lock. */ mutex_enter(&device_lock); switch (vp->v_type) { @@ -565,10 +564,7 @@ spec_open(void *v) * Character devices can accept opens from multiple * vnodes. */ - if (sn->sn_gone) { - error = EBADF; - break; - } + KASSERT(!sn->sn_gone); sd->sd_opencnt++; sn->sn_opencnt++; break; @@ -581,10 +577,7 @@ spec_open(void *v) * Treat zero opencnt with non-NULL mountpoint as open. * This may happen after forced detach of a mounted device. */ - if (sn->sn_gone) { - error = EBADF; - break; - } + KASSERT(!sn->sn_gone); if (sd->sd_opencnt != 0 || sd->sd_mountpoint != NULL) { error = EBUSY; break;