driver(9): Make vdevgone call config_detach_commit if appropriate.
Make sure to do this before spec_node_lookup_by_dev -- that might wait for a concurrent revoke to complete, which in turn might wait for a concurrent open to complete, which in turn might be waiting for the device to commit to detaching.
This commit is contained in:
parent
4a4b9d79d4
commit
ce25ec449c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: subr_devsw.c,v 1.42 2022/03/28 12:34:08 riastradh Exp $ */
|
||||
/* $NetBSD: subr_devsw.c,v 1.43 2022/03/28 12:38:33 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -69,7 +69,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.42 2022/03/28 12:34:08 riastradh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.43 2022/03/28 12:38:33 riastradh Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_dtrace.h"
|
||||
|
@ -1068,6 +1068,24 @@ bdev_discard(dev_t dev, off_t pos, off_t len)
|
|||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
bdev_detached(dev_t dev)
|
||||
{
|
||||
const struct bdevsw *d;
|
||||
device_t dv;
|
||||
int unit;
|
||||
|
||||
if ((d = bdevsw_lookup(dev)) == NULL)
|
||||
return;
|
||||
if (d->d_devtounit == NULL)
|
||||
return;
|
||||
if ((unit = (*d->d_devtounit)(dev)) == -1)
|
||||
return;
|
||||
if ((dv = device_lookup(d->d_cfdriver, unit)) == NULL)
|
||||
return;
|
||||
config_detach_commit(dv);
|
||||
}
|
||||
|
||||
int
|
||||
cdev_open(dev_t dev, int flag, int devtype, lwp_t *l)
|
||||
{
|
||||
|
@ -1288,6 +1306,24 @@ cdev_type(dev_t dev)
|
|||
return d->d_flag & D_TYPEMASK;
|
||||
}
|
||||
|
||||
void
|
||||
cdev_detached(dev_t dev)
|
||||
{
|
||||
const struct cdevsw *d;
|
||||
device_t dv;
|
||||
int unit;
|
||||
|
||||
if ((d = cdevsw_lookup(dev)) == NULL)
|
||||
return;
|
||||
if (d->d_devtounit == NULL)
|
||||
return;
|
||||
if ((unit = (*d->d_devtounit)(dev)) == -1)
|
||||
return;
|
||||
if ((dv = device_lookup(d->d_cfdriver, unit)) == NULL)
|
||||
return;
|
||||
config_detach_commit(dv);
|
||||
}
|
||||
|
||||
/*
|
||||
* nommap(dev, off, prot)
|
||||
*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: vfs_subr.c,v 1.492 2022/03/28 12:37:46 riastradh Exp $ */
|
||||
/* $NetBSD: vfs_subr.c,v 1.493 2022/03/28 12:38:33 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008, 2019, 2020
|
||||
|
@ -69,7 +69,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.492 2022/03/28 12:37:46 riastradh Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.493 2022/03/28 12:38:33 riastradh Exp $");
|
||||
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_ddb.h"
|
||||
|
@ -511,6 +511,20 @@ vdevgone(int maj, int minl, int minh, enum vtype type)
|
|||
|
||||
for (mn = minl; mn <= minh; mn++) {
|
||||
dev = makedev(maj, mn);
|
||||
/*
|
||||
* Notify anyone trying to get at this device that it
|
||||
* has been detached, and then revoke it.
|
||||
*/
|
||||
switch (type) {
|
||||
case VBLK:
|
||||
bdev_detached(dev);
|
||||
break;
|
||||
case VCHR:
|
||||
cdev_detached(dev);
|
||||
break;
|
||||
default:
|
||||
panic("invalid specnode type: %d", type);
|
||||
}
|
||||
/*
|
||||
* Passing 0 as flags, instead of VDEAD_NOWAIT, means
|
||||
* spec_node_lookup_by_dev will wait for vnodes it
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: conf.h,v 1.158 2022/03/28 12:34:17 riastradh Exp $ */
|
||||
/* $NetBSD: conf.h,v 1.159 2022/03/28 12:38:33 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
|
@ -172,6 +172,8 @@ dev_type_dump(bdev_dump);
|
|||
dev_type_size(bdev_size);
|
||||
dev_type_discard(bdev_discard);
|
||||
|
||||
void bdev_detached(dev_t);
|
||||
|
||||
dev_type_open(cdev_open);
|
||||
dev_type_close(cdev_close);
|
||||
dev_type_read(cdev_read);
|
||||
|
@ -184,6 +186,8 @@ dev_type_mmap(cdev_mmap);
|
|||
dev_type_kqfilter(cdev_kqfilter);
|
||||
dev_type_discard(cdev_discard);
|
||||
|
||||
void cdev_detached(dev_t);
|
||||
|
||||
int cdev_type(dev_t);
|
||||
int cdev_flags(dev_t);
|
||||
int bdev_type(dev_t);
|
||||
|
|
Loading…
Reference in New Issue