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.
This commit is contained in:
parent
ce78318abc
commit
4241b4d4c6
|
@ -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.
|
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#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/param.h>
|
||||||
#include <sys/proc.h>
|
#include <sys/proc.h>
|
||||||
|
@ -402,6 +402,8 @@ spec_node_revoke(vnode_t *vp)
|
||||||
specnode_t *sn;
|
specnode_t *sn;
|
||||||
specdev_t *sd;
|
specdev_t *sd;
|
||||||
|
|
||||||
|
KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
|
||||||
|
|
||||||
sn = vp->v_specnode;
|
sn = vp->v_specnode;
|
||||||
sd = sn->sn_dev;
|
sd = sn->sn_dev;
|
||||||
|
|
||||||
|
@ -552,11 +554,8 @@ spec_open(void *v)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Acquire an open reference -- as long as we hold onto it, and
|
* Acquire an open reference -- as long as we hold onto it, and
|
||||||
* the vnode isn't revoked, it can't be closed.
|
* the vnode isn't revoked, it can't be closed, and the vnode
|
||||||
*
|
* can't be revoked until we release the vnode lock.
|
||||||
* But first check whether it has been revoked -- if so, we
|
|
||||||
* can't acquire more open references and we must fail
|
|
||||||
* immediately with EBADF.
|
|
||||||
*/
|
*/
|
||||||
mutex_enter(&device_lock);
|
mutex_enter(&device_lock);
|
||||||
switch (vp->v_type) {
|
switch (vp->v_type) {
|
||||||
|
@ -565,10 +564,7 @@ spec_open(void *v)
|
||||||
* Character devices can accept opens from multiple
|
* Character devices can accept opens from multiple
|
||||||
* vnodes.
|
* vnodes.
|
||||||
*/
|
*/
|
||||||
if (sn->sn_gone) {
|
KASSERT(!sn->sn_gone);
|
||||||
error = EBADF;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sd->sd_opencnt++;
|
sd->sd_opencnt++;
|
||||||
sn->sn_opencnt++;
|
sn->sn_opencnt++;
|
||||||
break;
|
break;
|
||||||
|
@ -581,10 +577,7 @@ spec_open(void *v)
|
||||||
* Treat zero opencnt with non-NULL mountpoint as open.
|
* Treat zero opencnt with non-NULL mountpoint as open.
|
||||||
* This may happen after forced detach of a mounted device.
|
* This may happen after forced detach of a mounted device.
|
||||||
*/
|
*/
|
||||||
if (sn->sn_gone) {
|
KASSERT(!sn->sn_gone);
|
||||||
error = EBADF;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (sd->sd_opencnt != 0 || sd->sd_mountpoint != NULL) {
|
if (sd->sd_opencnt != 0 || sd->sd_mountpoint != NULL) {
|
||||||
error = EBUSY;
|
error = EBUSY;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue