Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/raidframe refactor driver to use common code in dksubr.
details: https://anonhg.NetBSD.org/src/rev/2e3bfe43de31
branches: trunk
changeset: 342645:2e3bfe43de31
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Sun Jan 03 08:17:24 2016 +0000
description:
refactor driver to use common code in dksubr.
diffstat:
sys/dev/raidframe/rf_engine.c | 6 +-
sys/dev/raidframe/rf_kintf.h | 4 +-
sys/dev/raidframe/rf_netbsdkintf.c | 1266 +++++++++++++----------------------
sys/dev/raidframe/rf_states.c | 26 +-
4 files changed, 479 insertions(+), 823 deletions(-)
diffs (truncated from 1856 to 300 lines):
diff -r 349ca77a735d -r 2e3bfe43de31 sys/dev/raidframe/rf_engine.c
--- a/sys/dev/raidframe/rf_engine.c Sun Jan 03 06:23:25 2016 +0000
+++ b/sys/dev/raidframe/rf_engine.c Sun Jan 03 08:17:24 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_engine.c,v 1.50 2014/10/18 08:33:28 snj Exp $ */
+/* $NetBSD: rf_engine.c,v 1.51 2016/01/03 08:17:24 mlelstv Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
* All rights reserved.
@@ -55,7 +55,7 @@
****************************************************************************/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_engine.c,v 1.50 2014/10/18 08:33:28 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_engine.c,v 1.51 2016/01/03 08:17:24 mlelstv Exp $");
#include <sys/errno.h>
@@ -843,7 +843,7 @@
/*
* rf_RaidIOThread() -- When I/O to a component begins, raidstrategy()
- * puts the I/O on a buf_queue, and then signals raidPtr->iodone. If
+ * puts the I/O on a buffer queue, and then signals raidPtr->iodone. If
* necessary, this function calls raidstart() to initiate the I/O.
* When I/O to a component completes, KernelWakeupFunc() puts the
* completed request onto raidPtr->iodone TAILQ. This function looks
diff -r 349ca77a735d -r 2e3bfe43de31 sys/dev/raidframe/rf_kintf.h
--- a/sys/dev/raidframe/rf_kintf.h Sun Jan 03 06:23:25 2016 +0000
+++ b/sys/dev/raidframe/rf_kintf.h Sun Jan 03 08:17:24 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_kintf.h,v 1.23 2011/08/03 14:44:38 oster Exp $ */
+/* $NetBSD: rf_kintf.h,v 1.24 2016/01/03 08:17:24 mlelstv Exp $ */
/*
* rf_kintf.h
*
@@ -42,6 +42,7 @@
void raidstart(RF_Raid_t * raidPtr);
int rf_DispatchKernelIO(RF_DiskQueue_t * queue, RF_DiskQueueData_t * req);
+void raiddone(RF_Raid_t * raidPtr, struct buf * bp);
int raidfetch_component_label(RF_Raid_t *, RF_RowCol_t);
RF_ComponentLabel_t *raidget_component_label(RF_Raid_t *, RF_RowCol_t);
@@ -59,7 +60,6 @@
void rf_print_component_label(RF_ComponentLabel_t *);
void rf_UnconfigureVnodes( RF_Raid_t * );
void rf_close_component( RF_Raid_t *, struct vnode *, int);
-void rf_disk_unbusy(RF_RaidAccessDesc_t *);
int rf_getdisksize(struct vnode *, RF_RaidDisk_t *);
int rf_sync_component_caches(RF_Raid_t *raidPtr);
#endif /* _RF__RF_KINTF_H_ */
diff -r 349ca77a735d -r 2e3bfe43de31 sys/dev/raidframe/rf_netbsdkintf.c
--- a/sys/dev/raidframe/rf_netbsdkintf.c Sun Jan 03 06:23:25 2016 +0000
+++ b/sys/dev/raidframe/rf_netbsdkintf.c Sun Jan 03 08:17:24 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_netbsdkintf.c,v 1.334 2016/01/02 16:20:50 mlelstv Exp $ */
+/* $NetBSD: rf_netbsdkintf.c,v 1.335 2016/01/03 08:17:24 mlelstv Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2008-2011 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
***********************************************************/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.334 2016/01/02 16:20:50 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.335 2016/01/03 08:17:24 mlelstv Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -181,6 +181,7 @@
void *, int, struct proc *);
struct raid_softc;
static void raidinit(struct raid_softc *);
+static int raiddoaccess(RF_Raid_t *raidPtr, struct buf *bp);
static int raid_match(device_t, cfdata_t, void *);
static void raid_attach(device_t, device_t, void *);
@@ -196,6 +197,9 @@
static int raidread_component_label(unsigned,
dev_t, struct vnode *, RF_ComponentLabel_t *);
+static int raid_diskstart(device_t, struct buf *bp);
+static int raid_dumpblocks(device_t, void *, daddr_t, int);
+static int raid_lastclose(device_t);
static dev_type_open(raidopen);
static dev_type_close(raidclose);
@@ -233,12 +237,17 @@
};
static struct dkdriver rf_dkdriver = {
+ .d_open = raidopen,
+ .d_close = raidclose,
.d_strategy = raidstrategy,
+ .d_diskstart = raid_diskstart,
+ .d_dumpblocks = raid_dumpblocks,
+ .d_lastclose = raid_lastclose,
.d_minphys = minphys
};
struct raid_softc {
- device_t sc_dev;
+ struct dk_softc sc_dksc;
int sc_unit;
int sc_flags; /* flags */
int sc_cflags; /* configuration flags */
@@ -246,8 +255,6 @@
kcondvar_t sc_cv; /* and the condvar */
uint64_t sc_size; /* size of the raid device */
char sc_xname[20]; /* XXX external name */
- struct disk sc_dkdev; /* generic disk device info */
- struct bufq_state *buf_queue; /* used for the device queue */
RF_Raid_t sc_r;
LIST_ENTRY(raid_softc) sc_link;
};
@@ -256,10 +263,12 @@
#define RAIDF_WLABEL 0x02 /* label area is writable */
#define RAIDF_LABELLING 0x04 /* unit is currently being labelled */
#define RAIDF_SHUTDOWN 0x08 /* unit is being shutdown */
+#define RAIDF_DETACH 0x10 /* detach after final close */
#define RAIDF_WANTED 0x40 /* someone is waiting to obtain a lock */
#define RAIDF_LOCKED 0x80 /* unit is locked */
#define raidunit(x) DISKUNIT(x)
+#define raidsoftc(dev) (((struct raid_softc *)device_private(dev))->sc_r.softc)
extern struct cfdriver raid_cd;
CFATTACH_DECL3_NEW(raid, sizeof(struct raid_softc),
@@ -292,11 +301,6 @@
/* declared here, and made public, for the benefit of KVM stuff.. */
-static void raidgetdefaultlabel(RF_Raid_t *, struct raid_softc *,
- struct disklabel *);
-static void raidgetdisklabel(dev_t);
-static void raidmakedisklabel(struct raid_softc *);
-
static int raidlock(struct raid_softc *);
static void raidunlock(struct raid_softc *);
@@ -352,7 +356,6 @@
return NULL;
}
sc->sc_unit = unit;
- bufq_alloc(&sc->buf_queue, "fcfs", BUFQ_SORT_RAWBLOCK);
cv_init(&sc->sc_cv, "raidunit");
mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
return sc;
@@ -362,7 +365,6 @@
raiddestroy(struct raid_softc *sc) {
cv_destroy(&sc->sc_cv);
mutex_destroy(&sc->sc_mutex);
- bufq_free(sc->buf_queue);
kmem_free(sc, sizeof(*sc));
}
@@ -480,6 +482,7 @@
RF_ConfigSet_t *next_cset;
int num_root;
struct raid_softc *sc, *rsc;
+ struct dk_softc *dksc;
sc = rsc = NULL;
num_root = 0;
@@ -510,6 +513,7 @@
rf_cleanup_config_set(cset);
cset = next_cset;
}
+ dksc = &rsc->sc_dksc;
/* if the user has specified what the root device should be
then we don't touch booted_device or boothowto... */
@@ -532,14 +536,14 @@
*/
if (num_root == 1) {
device_t candidate_root;
- if (rsc->sc_dkdev.dk_nwedges != 0) {
+ if (dksc->sc_dkdev.dk_nwedges != 0) {
char cname[sizeof(cset->ac->devname)];
/* XXX: assume 'a' */
snprintf(cname, sizeof(cname), "%s%c",
- device_xname(rsc->sc_dev), 'a');
+ device_xname(dksc->sc_dev), 'a');
candidate_root = dkwedge_find_by_wname(cname);
} else
- candidate_root = rsc->sc_dev;
+ candidate_root = dksc->sc_dev;
if (booted_device == NULL ||
rsc->sc_r.root_partition == 1 ||
rf_containsboot(&rsc->sc_r, booted_device)) {
@@ -570,12 +574,13 @@
if (rf_containsboot(r, booted_device)) {
num_root++;
rsc = sc;
+ dksc = &rsc->sc_dksc;
}
}
mutex_exit(&raid_lock);
if (num_root == 1) {
- booted_device = rsc->sc_dev;
+ booted_device = dksc->sc_dev;
booted_partition = 0; /* XXX assume 'a' */
} else {
/* we can't guess.. require the user to answer... */
@@ -588,55 +593,49 @@
raidsize(dev_t dev)
{
struct raid_softc *rs;
- struct disklabel *lp;
- int part, unit, omask, size;
+ struct dk_softc *dksc;
+ unsigned int unit;
unit = raidunit(dev);
if ((rs = raidget(unit, false)) == NULL)
- return -1;
+ return ENXIO;
+ dksc = &rs->sc_dksc;
+
if ((rs->sc_flags & RAIDF_INITED) == 0)
- return (-1);
-
- part = DISKPART(dev);
- omask = rs->sc_dkdev.dk_openmask & (1 << part);
- lp = rs->sc_dkdev.dk_label;
-
- if (omask == 0 && raidopen(dev, 0, S_IFBLK, curlwp))
- return (-1);
-
- if (lp->d_partitions[part].p_fstype != FS_SWAP)
- size = -1;
- else
- size = lp->d_partitions[part].p_size *
- (lp->d_secsize / DEV_BSIZE);
-
- if (omask == 0 && raidclose(dev, 0, S_IFBLK, curlwp))
- return (-1);
-
- return (size);
-
+ return (ENODEV);
+
+ return dk_size(dksc, dev);
}
static int
raiddump(dev_t dev, daddr_t blkno, void *va, size_t size)
{
- int unit = raidunit(dev);
+ unsigned int unit;
struct raid_softc *rs;
- const struct bdevsw *bdev;
- struct disklabel *lp;
- RF_Raid_t *raidPtr;
- daddr_t offset;
- int part, c, sparecol, j, scol, dumpto;
- int error = 0;
-
+ struct dk_softc *dksc;
+
+ unit = raidunit(dev);
if ((rs = raidget(unit, false)) == NULL)
return ENXIO;
+ dksc = &rs->sc_dksc;
+
+ if ((rs->sc_flags & RAIDF_INITED) == 0)
+ return ENODEV;
+
+ return dk_dump(dksc, dev, blkno, va, size);
+}
+
+static int
+raid_dumpblocks(device_t dev, void *va, daddr_t blkno, int nblk)
+{
+ struct raid_softc *rs = raidsoftc(dev);
+ const struct bdevsw *bdev;
+ RF_Raid_t *raidPtr;
+ int c, sparecol, j, scol, dumpto;
+ int error = 0;
raidPtr = &rs->sc_r;
- if ((rs->sc_flags & RAIDF_INITED) == 0)
- return ENXIO;
-
/* we only support dumping to RAID 1 sets */
if (raidPtr->Layout.numDataCol != 1 ||
raidPtr->Layout.numParityCol != 1)
@@ -645,23 +644,6 @@
if ((error = raidlock(rs)) != 0)
return error;
- if (size % DEV_BSIZE != 0) {
- error = EINVAL;
- goto out;
- }
-
- if (blkno + size / DEV_BSIZE > rs->sc_size) {
Home |
Main Index |
Thread Index |
Old Index