Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys driver(9): Make vdevgone call config_detach_commit if ap...
details: https://anonhg.NetBSD.org/src/rev/9df7a090e68a
branches: trunk
changeset: 364524:9df7a090e68a
user: riastradh <riastradh%NetBSD.org@localhost>
date: Mon Mar 28 12:38:33 2022 +0000
description:
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.
diffstat:
sys/kern/subr_devsw.c | 40 ++++++++++++++++++++++++++++++++++++++--
sys/kern/vfs_subr.c | 18 ++++++++++++++++--
sys/sys/conf.h | 6 +++++-
3 files changed, 59 insertions(+), 5 deletions(-)
diffs (134 lines):
diff -r 6bf79b298bcc -r 9df7a090e68a sys/kern/subr_devsw.c
--- a/sys/kern/subr_devsw.c Mon Mar 28 12:38:24 2022 +0000
+++ b/sys/kern/subr_devsw.c Mon Mar 28 12:38:33 2022 +0000
@@ -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 @@
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 @@
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)
*
diff -r 6bf79b298bcc -r 9df7a090e68a sys/kern/vfs_subr.c
--- a/sys/kern/vfs_subr.c Mon Mar 28 12:38:24 2022 +0000
+++ b/sys/kern/vfs_subr.c Mon Mar 28 12:38:33 2022 +0000
@@ -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"
@@ -512,6 +512,20 @@
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
* finds concurrently being revoked before returning.
diff -r 6bf79b298bcc -r 9df7a090e68a sys/sys/conf.h
--- a/sys/sys/conf.h Mon Mar 28 12:38:24 2022 +0000
+++ b/sys/sys/conf.h Mon Mar 28 12:38:33 2022 +0000
@@ -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_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_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);
Home |
Main Index |
Thread Index |
Old Index