Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev refactor the ld(4) DIOCCACHESYNC hook into general i...
details: https://anonhg.NetBSD.org/src/rev/5c15f2edae29
branches: trunk
changeset: 351813:5c15f2edae29
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Mon Feb 27 21:32:33 2017 +0000
description:
refactor the ld(4) DIOCCACHESYNC hook into general ioctl hook, so that attachments
would be able to implement arbitrary other ioctls
diffstat:
sys/dev/i2o/ld_iop.c | 31 ++++++++++++++++++----
sys/dev/ic/ld_icp.c | 30 ++++++++++++++++++---
sys/dev/ic/ld_nvme.c | 33 +++++++++++++++++++-----
sys/dev/ld.c | 67 +++++++++++++++++++++++++++++-------------------
sys/dev/ldvar.h | 7 +---
sys/dev/pci/ld_twa.c | 29 +++++++++++++++++---
sys/dev/pci/ld_twe.c | 31 ++++++++++++++++++----
sys/dev/pci/ld_virtio.c | 5 +--
8 files changed, 170 insertions(+), 63 deletions(-)
diffs (truncated from 559 to 300 lines):
diff -r 2565b119c3bf -r 5c15f2edae29 sys/dev/i2o/ld_iop.c
--- a/sys/dev/i2o/ld_iop.c Mon Feb 27 21:27:07 2017 +0000
+++ b/sys/dev/i2o/ld_iop.c Mon Feb 27 21:32:33 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_iop.c,v 1.36 2016/09/16 15:20:50 jdolecek Exp $ */
+/* $NetBSD: ld_iop.c,v 1.37 2017/02/27 21:32:33 jdolecek Exp $ */
/*-
* Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_iop.c,v 1.36 2016/09/16 15:20:50 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_iop.c,v 1.37 2017/02/27 21:32:33 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -73,7 +73,8 @@
static void ld_iop_attach(device_t, device_t, void *);
static int ld_iop_detach(device_t, int);
static int ld_iop_dump(struct ld_softc *, void *, int, int);
-static int ld_iop_flush(struct ld_softc *, int);
+static int ld_iop_flush(struct ld_softc *, bool);
+static int ld_iop_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
static void ld_iop_intr(device_t, struct iop_msg *, void *);
static void ld_iop_intr_event(device_t, struct iop_msg *, void *);
static int ld_iop_match(device_t, cfdata_t, void *);
@@ -168,7 +169,7 @@
ld->sc_maxxfer = IOP_MAX_XFER;
ld->sc_dump = ld_iop_dump;
- ld->sc_flush = ld_iop_flush;
+ ld->sc_ioctl = ld_iop_ioctl;
ld->sc_start = ld_iop_start;
/* Say what the device is. */
@@ -437,7 +438,7 @@
}
static int
-ld_iop_flush(struct ld_softc *ld, int flags)
+ld_iop_flush(struct ld_softc *ld, bool poll)
{
struct iop_msg *im;
struct iop_softc *iop;
@@ -461,7 +462,25 @@
return (rv);
}
-void
+static int
+ld_iop_ioctl(struct ld_softc *ld, u_long cmd, void *addr, int32_t flag, bool poll)
+{
+ int error;
+
+ switch (cmd) {
+ case DIOCCACHESYNC:
+ error = ld_iop_flush(ld, poll);
+ break;
+
+ default:
+ error = EPASSTHROUGH;
+ break;
+ }
+
+ return error;
+}
+
+static void
ld_iop_intr(device_t dv, struct iop_msg *im, void *reply)
{
struct i2o_rbs_reply *rb;
diff -r 2565b119c3bf -r 5c15f2edae29 sys/dev/ic/ld_icp.c
--- a/sys/dev/ic/ld_icp.c Mon Feb 27 21:27:07 2017 +0000
+++ b/sys/dev/ic/ld_icp.c Mon Feb 27 21:32:33 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_icp.c,v 1.30 2017/02/26 23:06:36 jdolecek Exp $ */
+/* $NetBSD: ld_icp.c,v 1.31 2017/02/27 21:32:33 jdolecek Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_icp.c,v 1.30 2017/02/26 23:06:36 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_icp.c,v 1.31 2017/02/27 21:32:33 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -65,7 +65,8 @@
static int ld_icp_dobio(struct ld_icp_softc *, void *, int, int, int,
struct buf *);
static int ld_icp_dump(struct ld_softc *, void *, int, int);
-static int ld_icp_flush(struct ld_softc *, int);
+static int ld_icp_flush(struct ld_softc *, bool);
+static int ld_icp_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
static void ld_icp_intr(struct icp_ccb *);
static int ld_icp_match(device_t, cfdata_t, void *);
static int ld_icp_start(struct ld_softc *, struct buf *);
@@ -110,7 +111,7 @@
ld->sc_secsize = ICP_SECTOR_SIZE;
ld->sc_start = ld_icp_start;
ld->sc_dump = ld_icp_dump;
- ld->sc_flush = ld_icp_flush;
+ ld->sc_ioctl = ld_icp_ioctl;
ld->sc_secperunit = cd->cd_size;
ld->sc_flags = LDF_ENABLED;
ld->sc_maxqueuecnt = icp->icp_openings;
@@ -254,8 +255,9 @@
blkcnt * ld->sc_secsize, blkno, 1, NULL));
}
+/* ARGSUSED */
static int
-ld_icp_flush(struct ld_softc *ld, int flags)
+ld_icp_flush(struct ld_softc *ld, bool poll)
{
struct ld_icp_softc *sc;
struct icp_softc *icp;
@@ -285,6 +287,24 @@
return (rv);
}
+static int
+ld_icp_ioctl(struct ld_softc *ld, u_long cmd, void *addr, int32_t flag, bool poll)
+{
+ int error;
+
+ switch (cmd) {
+ case DIOCCACHESYNC:
+ error = ld_icp_flush(ld, poll);
+ break;
+
+ default:
+ error = EPASSTHROUGH;
+ break;
+ }
+
+ return error;
+}
+
static void
ld_icp_intr(struct icp_ccb *ic)
{
diff -r 2565b119c3bf -r 5c15f2edae29 sys/dev/ic/ld_nvme.c
--- a/sys/dev/ic/ld_nvme.c Mon Feb 27 21:27:07 2017 +0000
+++ b/sys/dev/ic/ld_nvme.c Mon Feb 27 21:32:33 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_nvme.c,v 1.10 2016/11/01 14:39:38 jdolecek Exp $ */
+/* $NetBSD: ld_nvme.c,v 1.11 2017/02/27 21:32:33 jdolecek Exp $ */
/*-
* Copyright (C) 2016 NONAKA Kimihiro <nonaka%netbsd.org@localhost>
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.10 2016/11/01 14:39:38 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.11 2017/02/27 21:32:33 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -60,7 +60,8 @@
static int ld_nvme_start(struct ld_softc *, struct buf *);
static int ld_nvme_dump(struct ld_softc *, void *, int, int);
-static int ld_nvme_flush(struct ld_softc *, int);
+static int ld_nvme_flush(struct ld_softc *, bool);
+static int ld_nvme_ioctl(struct ld_softc *, u_long, void *, int32_t, bool);
static void ld_nvme_biodone(void *, struct buf *, uint16_t);
static void ld_nvme_syncdone(void *, struct buf *, uint16_t);
@@ -112,7 +113,7 @@
ld->sc_maxqueuecnt = naa->naa_qentries;
ld->sc_start = ld_nvme_start;
ld->sc_dump = ld_nvme_dump;
- ld->sc_flush = ld_nvme_flush;
+ ld->sc_ioctl = ld_nvme_ioctl;
ld->sc_flags = LDF_ENABLED;
ldattach(ld, "fcfs");
}
@@ -180,16 +181,34 @@
}
static int
-ld_nvme_flush(struct ld_softc *ld, int flags)
+ld_nvme_flush(struct ld_softc *ld, bool poll)
{
struct ld_nvme_softc *sc = device_private(ld->sc_dv);
- /* wait for the sync to finish */
return nvme_ns_sync(sc->sc_nvme, sc->sc_nsid, sc,
- (flags & LDFL_POLL) ? NVME_NS_CTX_F_POLL : 0,
+ poll ? NVME_NS_CTX_F_POLL : 0,
ld_nvme_syncdone);
}
+static int
+ld_nvme_ioctl(struct ld_softc *ld, u_long cmd, void *addr, int32_t flag, bool poll)
+{
+ int error;
+ struct ld_nvme_softc *sc = device_private(ld->sc_dv);
+
+ switch (cmd) {
+ case DIOCCACHESYNC:
+ error = ld_nvme_flush(ld, poll);
+ break;
+
+ default:
+ error = EPASSTHROUGH;
+ break;
+ }
+
+ return error;
+}
+
static void
ld_nvme_syncdone(void *xc, struct buf *bp, uint16_t cmd_status)
{
diff -r 2565b119c3bf -r 5c15f2edae29 sys/dev/ld.c
--- a/sys/dev/ld.c Mon Feb 27 21:27:07 2017 +0000
+++ b/sys/dev/ld.c Mon Feb 27 21:32:33 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ld.c,v 1.99 2016/11/26 12:32:03 mlelstv Exp $ */
+/* $NetBSD: ld.c,v 1.100 2017/02/27 21:32:33 jdolecek Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.99 2016/11/26 12:32:03 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.100 2017/02/27 21:32:33 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -70,6 +70,7 @@
static void ld_config_interrupts (device_t);
static int ld_lastclose(device_t);
static int ld_discard(device_t, off_t, off_t);
+static int ld_flush(device_t, bool);
extern struct cfdriver ld_cd;
@@ -247,15 +248,12 @@
pmf_device_deregister(dksc->sc_dev);
/*
- * XXX We can't really flush the cache here, beceause the
+ * XXX We can't really flush the cache here, because the
* XXX device may already be non-existent from the controller's
* XXX perspective.
*/
#if 0
- /* Flush the device's cache. */
- if (sc->sc_flush != NULL)
- if ((*sc->sc_flush)(sc, 0) != 0)
- device_printf(dksc->sc_dev, "unable to flush cache\n");
+ ld_flush(dksc->sc_dev, false);
#endif
cv_destroy(&sc->sc_drain);
mutex_destroy(&sc->sc_mutex);
@@ -272,14 +270,8 @@
static bool
ld_shutdown(device_t dev, int flags)
{
- struct ld_softc *sc = device_private(dev);
- struct dk_softc *dksc = &sc->sc_dksc;
-
- if ((flags & RB_NOSYNC) == 0 && sc->sc_flush != NULL
- && (*sc->sc_flush)(sc, LDFL_POLL) != 0) {
- device_printf(dksc->sc_dev, "unable to flush cache\n");
+ if ((flags & RB_NOSYNC) == 0 && ld_flush(dev, true) != 0)
return false;
- }
return true;
}
@@ -303,10 +295,7 @@
static int
ld_lastclose(device_t self)
{
- struct ld_softc *sc = device_private(self);
-
- if (sc->sc_flush != NULL && (*sc->sc_flush)(sc, 0) != 0)
- device_printf(self, "unable to flush cache\n");
+ ld_flush(self, false);
return 0;
}
@@ -356,6 +345,10 @@
error = 0;
+ /*
+ * Some common checks so that individual attachments wouldn't need
+ * to duplicate them.
Home |
Main Index |
Thread Index |
Old Index