Module Name: src
Committed By: riastradh
Date: Fri Apr 21 18:30:21 UTC 2023
Modified Files:
src/sys/dev/dkwedge: dk.c
Log Message:
dk(4): Add null d_cancel routine to devsw.
This way, dkclose is guaranteed that dkopen, dkread, dkwrite,
dkioctl, &c., have all returned before it runs. For block opens,
setting d_cancel also guarantees that any buffered writes are flushed
with vinvalbuf before dkclose is called.
To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/dev/dkwedge/dk.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/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.140 src/sys/dev/dkwedge/dk.c:1.141
--- src/sys/dev/dkwedge/dk.c:1.140 Fri Apr 21 18:29:43 2023
+++ src/sys/dev/dkwedge/dk.c Fri Apr 21 18:30:21 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: dk.c,v 1.140 2023/04/21 18:29:43 riastradh Exp $ */
+/* $NetBSD: dk.c,v 1.141 2023/04/21 18:30:21 riastradh Exp $ */
/*-
* Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.140 2023/04/21 18:29:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.141 2023/04/21 18:30:21 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_dkwedge.h"
@@ -116,6 +116,7 @@ static int dk_close_parent(struct vnode
static dev_type_open(dkopen);
static dev_type_close(dkclose);
+static dev_type_cancel(dkcancel);
static dev_type_read(dkread);
static dev_type_write(dkwrite);
static dev_type_ioctl(dkioctl);
@@ -132,6 +133,7 @@ CFATTACH_DECL3_NEW(dk, 0,
const struct bdevsw dk_bdevsw = {
.d_open = dkopen,
.d_close = dkclose,
+ .d_cancel = dkcancel,
.d_strategy = dkstrategy,
.d_ioctl = dkioctl,
.d_dump = dkdump,
@@ -143,6 +145,7 @@ const struct bdevsw dk_bdevsw = {
const struct cdevsw dk_cdevsw = {
.d_open = dkopen,
.d_close = dkclose,
+ .d_cancel = dkcancel,
.d_read = dkread,
.d_write = dkwrite,
.d_ioctl = dkioctl,
@@ -1379,6 +1382,32 @@ dkclose(dev_t dev, int flags, int fmt, s
}
/*
+ * dkcancel: [devsw entry point]
+ *
+ * Cancel any pending I/O operations waiting on a wedge.
+ */
+static int
+dkcancel(dev_t dev, int flags, int fmt, struct lwp *l)
+{
+ struct dkwedge_softc *sc = dkwedge_lookup(dev);
+
+ KASSERT(sc != NULL);
+ KASSERT(sc->sc_dev != NULL);
+
+ /*
+ * Disk I/O is expected to complete or fail within a reasonable
+ * timeframe -- it's storage, not communication. Further, the
+ * character and block device interface guarantees that prior
+ * reads and writes have completed or failed by the time close
+ * returns -- we are not to cancel them here. If the parent
+ * device's hardware is gone, the parent driver can make them
+ * fail. Nothing for dk(4) itself to do.
+ */
+
+ return 0;
+}
+
+/*
* dkstrategy: [devsw entry point]
*
* Perform I/O based on the wedge I/O strategy.