Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/raidframe allocate devices dynamically.
details: https://anonhg.NetBSD.org/src/rev/860e9dbc0865
branches: trunk
changeset: 786387:860e9dbc0865
user: christos <christos%NetBSD.org@localhost>
date: Sat Apr 27 21:18:42 2013 +0000
description:
allocate devices dynamically.
diffstat:
sys/dev/raidframe/rf_engine.c | 6 +-
sys/dev/raidframe/rf_netbsd.h | 4 +-
sys/dev/raidframe/rf_netbsdkintf.c | 353 ++++++++++++++++--------------------
sys/dev/raidframe/rf_raid.h | 3 +-
4 files changed, 167 insertions(+), 199 deletions(-)
diffs (truncated from 764 to 300 lines):
diff -r 03f5e31e4475 -r 860e9dbc0865 sys/dev/raidframe/rf_engine.c
--- a/sys/dev/raidframe/rf_engine.c Sat Apr 27 20:36:47 2013 +0000
+++ b/sys/dev/raidframe/rf_engine.c Sat Apr 27 21:18:42 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_engine.c,v 1.47 2011/09/07 07:46:45 mbalmer Exp $ */
+/* $NetBSD: rf_engine.c,v 1.48 2013/04/27 21:18:42 christos 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.47 2011/09/07 07:46:45 mbalmer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_engine.c,v 1.48 2013/04/27 21:18:42 christos Exp $");
#include <sys/errno.h>
@@ -862,7 +862,7 @@
while (!raidPtr->shutdown_raidio) {
/* if there is nothing to do, then snooze. */
if (TAILQ_EMPTY(&(raidPtr->iodone)) &&
- rf_buf_queue_check(raidPtr->raidid)) {
+ rf_buf_queue_check(raidPtr)) {
rf_wait_cond2(raidPtr->iodone_cv, raidPtr->iodone_lock);
}
diff -r 03f5e31e4475 -r 860e9dbc0865 sys/dev/raidframe/rf_netbsd.h
--- a/sys/dev/raidframe/rf_netbsd.h Sat Apr 27 20:36:47 2013 +0000
+++ b/sys/dev/raidframe/rf_netbsd.h Sat Apr 27 21:18:42 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_netbsd.h,v 1.29 2008/04/28 20:23:56 martin Exp $ */
+/* $NetBSD: rf_netbsd.h,v 1.30 2013/04/27 21:18:42 christos Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -83,7 +83,7 @@
extern struct RF_Pools_s rf_pools;
void rf_pool_init(struct pool *, size_t, const char *, size_t, size_t);
-int rf_buf_queue_check(int);
+int rf_buf_queue_check(RF_Raid_t *);
/* XXX probably belongs in a different .h file. */
typedef struct RF_AutoConfig_s {
diff -r 03f5e31e4475 -r 860e9dbc0865 sys/dev/raidframe/rf_netbsdkintf.c
--- a/sys/dev/raidframe/rf_netbsdkintf.c Sat Apr 27 20:36:47 2013 +0000
+++ b/sys/dev/raidframe/rf_netbsdkintf.c Sat Apr 27 21:18:42 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_netbsdkintf.c,v 1.299 2013/02/18 19:42:54 oster Exp $ */
+/* $NetBSD: rf_netbsdkintf.c,v 1.300 2013/04/27 21:18:42 christos 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.299 2013/02/18 19:42:54 oster Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.300 2013/04/27 21:18:42 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -159,8 +159,6 @@
#define db1_printf(a) { }
#endif /* DEBUG */
-static RF_Raid_t **raidPtrs; /* global raid device descriptors */
-
#if (RF_INCLUDE_PARITY_DECLUSTERING_DS > 0)
static rf_declare_mutex2(rf_sparet_wait_mutex);
static rf_declare_cond2(rf_sparet_wait_cv);
@@ -179,7 +177,8 @@
static void InitBP(struct buf *, struct vnode *, unsigned,
dev_t, RF_SectorNum_t, RF_SectorCount_t, void *, void (*) (struct buf *),
void *, int, struct proc *);
-static void raidinit(RF_Raid_t *);
+struct raid_softc;
+static void raidinit(struct raid_softc *);
void raidattach(int);
static int raid_match(device_t, cfdata_t, void *);
@@ -218,18 +217,17 @@
static struct dkdriver rf_dkdriver = { raidstrategy, minphys };
-/* XXX Not sure if the following should be replacing the raidPtrs above,
- or if it should be used in conjunction with that...
-*/
-
struct raid_softc {
device_t sc_dev;
+ int sc_unit;
int sc_flags; /* flags */
int sc_cflags; /* configuration flags */
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;
};
/* sc_flags */
#define RAIDF_INITED 0x01 /* unit has been initialized */
@@ -240,7 +238,6 @@
#define RAIDF_LOCKED 0x80 /* unit is locked */
#define raidunit(x) DISKUNIT(x)
-int numraid = 0;
extern struct cfdriver raid_cd;
CFATTACH_DECL3_NEW(raid, sizeof(struct raid_softc),
@@ -272,7 +269,6 @@
(MAKEDISKDEV(major((dev)), raidunit((dev)), RAW_PART))
/* declared here, and made public, for the benefit of KVM stuff.. */
-struct raid_softc *raid_softc;
static void raidgetdefaultlabel(RF_Raid_t *, struct raid_softc *,
struct disklabel *);
@@ -304,7 +300,7 @@
void rf_release_all_vps(RF_ConfigSet_t *);
void rf_cleanup_config_set(RF_ConfigSet_t *);
int rf_have_enough_components(RF_ConfigSet_t *);
-int rf_auto_config_set(RF_ConfigSet_t *, int *);
+struct raid_softc *rf_auto_config_set(RF_ConfigSet_t *);
static void rf_fix_old_label_size(RF_ComponentLabel_t *, uint64_t);
/*
@@ -321,31 +317,69 @@
struct RF_Pools_s rf_pools;
+static LIST_HEAD(, raid_softc) raids = LIST_HEAD_INITIALIZER(raids);
+static kmutex_t raid_lock;
+
+static struct raid_softc *
+raidcreate(int unit) {
+ struct raid_softc *sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
+ if (sc == NULL) {
+#ifdef DIAGNOSTIC
+ printf("%s: out of memory\n", __func__);
+#endif
+ return NULL;
+ }
+ sc->sc_unit = unit;
+ sc->sc_r.softc = sc;
+ bufq_alloc(&sc->buf_queue, BUFQ_DISK_DEFAULT_STRAT, BUFQ_SORT_RAWBLOCK);
+ return sc;
+}
+
+static void
+raiddestroy(struct raid_softc *sc) {
+ bufq_free(sc->buf_queue);
+ kmem_free(sc, sizeof(*sc));
+}
+
+static struct raid_softc *
+raidget(int unit) {
+ struct raid_softc *sc;
+ if (unit < 0) {
+#ifdef DIAGNOSTIC
+ panic("%s: unit %d!", __func__, unit);
+#endif
+ return NULL;
+ }
+ mutex_enter(&raid_lock);
+ LIST_FOREACH(sc, &raids, sc_link) {
+ if (sc->sc_unit == unit) {
+ mutex_exit(&raid_lock);
+ return sc;
+ }
+ }
+ mutex_exit(&raid_lock);
+ if ((sc = raidcreate(unit)) == NULL)
+ return NULL;
+ mutex_enter(&raid_lock);
+ LIST_INSERT_HEAD(&raids, sc, sc_link);
+ mutex_exit(&raid_lock);
+ return sc;
+}
+
+static void
+raidput(struct raid_softc *sc) {
+ mutex_enter(&raid_lock);
+ LIST_REMOVE(sc, sc_link);
+ mutex_exit(&raid_lock);
+ raiddestroy(sc);
+}
+
void
raidattach(int num)
{
- int raidID;
- int i, rc;
-
- aprint_debug("raidattach: Asked for %d units\n", num);
-
- if (num <= 0) {
-#ifdef DIAGNOSTIC
- panic("raidattach: count <= 0");
-#endif
- return;
- }
+ mutex_init(&raid_lock, MUTEX_DEFAULT, IPL_NONE);
/* This is where all the initialization stuff gets done. */
- numraid = num;
-
- /* Make some space for requested number of units... */
-
- RF_Malloc(raidPtrs, num * sizeof(RF_Raid_t *), (RF_Raid_t **));
- if (raidPtrs == NULL) {
- panic("raidPtrs is NULL!!");
- }
-
#if (RF_INCLUDE_PARITY_DECLUSTERING_DS > 0)
rf_init_mutex2(rf_sparet_wait_mutex, IPL_VM);
rf_init_cond2(rf_sparet_wait_cv, "sparetw");
@@ -354,39 +388,11 @@
rf_sparet_wait_queue = rf_sparet_resp_queue = NULL;
#endif
- for (i = 0; i < num; i++)
- raidPtrs[i] = NULL;
- rc = rf_BootRaidframe();
- if (rc == 0)
+ if (rf_BootRaidframe() == 0)
aprint_verbose("Kernelized RAIDframe activated\n");
else
panic("Serious error booting RAID!!");
- /* put together some datastructures like the CCD device does.. This
- * lets us lock the device and what-not when it gets opened. */
-
- raid_softc = (struct raid_softc *)
- malloc(num * sizeof(struct raid_softc),
- M_RAIDFRAME, M_NOWAIT);
- if (raid_softc == NULL) {
- aprint_error("WARNING: no memory for RAIDframe driver\n");
- return;
- }
-
- memset(raid_softc, 0, num * sizeof(struct raid_softc));
-
- for (raidID = 0; raidID < num; raidID++) {
- bufq_alloc(&raid_softc[raidID].buf_queue, BUFQ_DISK_DEFAULT_STRAT, BUFQ_SORT_RAWBLOCK);
-
- RF_Malloc(raidPtrs[raidID], sizeof(RF_Raid_t),
- (RF_Raid_t *));
- if (raidPtrs[raidID] == NULL) {
- aprint_error("WARNING: raidPtrs[%d] is NULL\n", raidID);
- numraid = raidID;
- return;
- }
- }
-
if (config_cfattach_attach(raid_cd.cd_name, &raid_ca)) {
aprint_error("raidattach: config_cfattach_attach failed?\n");
}
@@ -434,30 +440,29 @@
{
RF_ConfigSet_t *cset;
RF_ConfigSet_t *next_cset;
- int retcode;
- int raidID;
- int rootID;
int col;
int num_root;
char *devname;
-
- rootID = 0;
+ struct raid_softc *sc, *rsc;
+
+ sc = rsc = NULL;
num_root = 0;
cset = config_sets;
while (cset != NULL) {
next_cset = cset->next;
if (rf_have_enough_components(cset) &&
- cset->ac->clabel->autoconfigure==1) {
- retcode = rf_auto_config_set(cset,&raidID);
- if (!retcode) {
- aprint_debug("raid%d: configured ok\n", raidID);
+ cset->ac->clabel->autoconfigure == 1) {
+ sc = rf_auto_config_set(cset);
+ if (sc != NULL) {
+ aprint_debug("raid%d: configured ok\n",
+ sc->sc_unit);
if (cset->rootable) {
- rootID = raidID;
+ rsc = sc;
num_root++;
}
} else {
/* The autoconfig didn't work :( */
- aprint_debug("Autoconfig failed with code %d for raid%d\n", retcode, raidID);
+ aprint_debug("Autoconfig failed\n");
rf_release_all_vps(cset);
}
Home |
Main Index |
Thread Index |
Old Index