2002-09-27 06:24:06 +04:00
|
|
|
/* $NetBSD: rf_netbsdkintf.c,v 1.140 2002/09/27 02:24:31 thorpej Exp $ */
|
1998-11-13 07:20:26 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Greg Oster; Jason R. Thorpe.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1988 University of Utah.
|
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Systems Programming Group of the University of Utah Computer
|
|
|
|
* Science Department.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from: Utah $Hdr: cd.c 1.6 90/11/28$
|
|
|
|
*
|
|
|
|
* @(#)cd.c 8.2 (Berkeley) 11/16/93
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Authors: Mark Holland, Jim Zelenka
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
*
|
|
|
|
* rf_kintf.c -- the kernel interface routines for RAIDframe
|
|
|
|
*
|
|
|
|
***********************************************************/
|
|
|
|
|
2001-11-13 10:11:12 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-09-27 06:24:06 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.140 2002/09/27 02:24:31 thorpej Exp $");
|
2001-11-13 10:11:12 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
#include <sys/param.h>
|
2001-11-15 12:47:59 +03:00
|
|
|
#include <sys/errno.h>
|
1998-11-13 07:20:26 +03:00
|
|
|
#include <sys/pool.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/user.h>
|
2000-03-03 04:46:36 +03:00
|
|
|
#include <sys/reboot.h>
|
1999-01-26 05:33:49 +03:00
|
|
|
|
2001-10-04 19:58:51 +04:00
|
|
|
#include <dev/raidframe/raidframevar.h>
|
|
|
|
#include <dev/raidframe/raidframeio.h>
|
1999-01-26 05:33:49 +03:00
|
|
|
#include "raid.h"
|
2000-02-26 20:35:33 +03:00
|
|
|
#include "opt_raid_autoconfig.h"
|
1998-11-13 07:20:26 +03:00
|
|
|
#include "rf_raid.h"
|
2000-01-09 04:29:27 +03:00
|
|
|
#include "rf_copyback.h"
|
1998-11-13 07:20:26 +03:00
|
|
|
#include "rf_dag.h"
|
|
|
|
#include "rf_dagflags.h"
|
2000-10-20 06:24:45 +04:00
|
|
|
#include "rf_desc.h"
|
1998-11-13 07:20:26 +03:00
|
|
|
#include "rf_diskqueue.h"
|
|
|
|
#include "rf_etimer.h"
|
|
|
|
#include "rf_general.h"
|
|
|
|
#include "rf_kintf.h"
|
|
|
|
#include "rf_options.h"
|
|
|
|
#include "rf_driver.h"
|
|
|
|
#include "rf_parityscan.h"
|
|
|
|
#include "rf_threadstuff.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-09-21 11:05:06 +04:00
|
|
|
int rf_kdebug_level = 0;
|
1998-11-13 07:20:26 +03:00
|
|
|
#define db1_printf(a) if (rf_kdebug_level > 0) printf a
|
1999-02-05 03:06:06 +03:00
|
|
|
#else /* DEBUG */
|
1998-11-13 07:20:26 +03:00
|
|
|
#define db1_printf(a) { }
|
1999-02-05 03:06:06 +03:00
|
|
|
#endif /* DEBUG */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
static RF_Raid_t **raidPtrs; /* global raid device descriptors */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
RF_DECLARE_STATIC_MUTEX(rf_sparet_wait_mutex)
|
1999-02-24 02:57:53 +03:00
|
|
|
|
1999-02-11 04:23:32 +03:00
|
|
|
static RF_SparetWait_t *rf_sparet_wait_queue; /* requests to install a
|
|
|
|
* spare table */
|
|
|
|
static RF_SparetWait_t *rf_sparet_resp_queue; /* responses from
|
|
|
|
* installation process */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/* prototypes */
|
1999-02-11 04:23:32 +03:00
|
|
|
static void KernelWakeupFunc(struct buf * bp);
|
|
|
|
static void InitBP(struct buf * bp, struct vnode *, unsigned rw_flag,
|
|
|
|
dev_t dev, RF_SectorNum_t startSect,
|
|
|
|
RF_SectorCount_t numSect, caddr_t buf,
|
|
|
|
void (*cbFunc) (struct buf *), void *cbArg,
|
|
|
|
int logBytesPerSector, struct proc * b_proc);
|
2001-01-27 23:42:20 +03:00
|
|
|
static void raidinit(RF_Raid_t *);
|
|
|
|
|
|
|
|
void raidattach(int);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
dev_type_open(raidopen);
|
|
|
|
dev_type_close(raidclose);
|
|
|
|
dev_type_read(raidread);
|
|
|
|
dev_type_write(raidwrite);
|
|
|
|
dev_type_ioctl(raidioctl);
|
|
|
|
dev_type_strategy(raidstrategy);
|
|
|
|
dev_type_dump(raiddump);
|
|
|
|
dev_type_size(raidsize);
|
|
|
|
|
|
|
|
const struct bdevsw raid_bdevsw = {
|
|
|
|
raidopen, raidclose, raidstrategy, raidioctl,
|
|
|
|
raiddump, raidsize, D_DISK
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw raid_cdevsw = {
|
|
|
|
raidopen, raidclose, raidread, raidwrite, raidioctl,
|
|
|
|
nostop, notty, nopoll, nommap, D_DISK
|
|
|
|
};
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pilfered from ccd.c
|
|
|
|
*/
|
|
|
|
|
1999-02-11 04:23:32 +03:00
|
|
|
struct raidbuf {
|
|
|
|
struct buf rf_buf; /* new I/O buf. MUST BE FIRST!!! */
|
|
|
|
struct buf *rf_obp; /* ptr. to original I/O buf */
|
1999-02-24 02:57:53 +03:00
|
|
|
RF_DiskQueueData_t *req;/* the request that this was part of.. */
|
1999-02-11 04:23:32 +03:00
|
|
|
};
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2002-01-09 07:21:43 +03:00
|
|
|
/* component buffer pool */
|
|
|
|
struct pool raidframe_cbufpool;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* XXX Not sure if the following should be replacing the raidPtrs above,
|
2000-02-23 02:13:15 +03:00
|
|
|
or if it should be used in conjunction with that...
|
2000-02-25 05:42:30 +03:00
|
|
|
*/
|
1999-02-11 04:23:32 +03:00
|
|
|
|
|
|
|
struct raid_softc {
|
|
|
|
int sc_flags; /* flags */
|
|
|
|
int sc_cflags; /* configuration flags */
|
1999-02-24 02:57:53 +03:00
|
|
|
size_t sc_size; /* size of the raid device */
|
1999-02-11 04:23:32 +03:00
|
|
|
char sc_xname[20]; /* XXX external name */
|
|
|
|
struct disk sc_dkdev; /* generic disk device info */
|
2002-07-20 20:30:18 +04:00
|
|
|
struct bufq_state buf_queue; /* used for the device queue */
|
1999-02-11 04:23:32 +03:00
|
|
|
};
|
1998-11-13 07:20:26 +03:00
|
|
|
/* sc_flags */
|
|
|
|
#define RAIDF_INITED 0x01 /* unit has been initialized */
|
|
|
|
#define RAIDF_WLABEL 0x02 /* label area is writable */
|
|
|
|
#define RAIDF_LABELLING 0x04 /* unit is currently being labelled */
|
|
|
|
#define RAIDF_WANTED 0x40 /* someone is waiting to obtain a lock */
|
|
|
|
#define RAIDF_LOCKED 0x80 /* unit is locked */
|
|
|
|
|
|
|
|
#define raidunit(x) DISKUNIT(x)
|
2000-02-13 07:53:57 +03:00
|
|
|
int numraid = 0;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-07-08 04:45:23 +04:00
|
|
|
/*
|
|
|
|
* Allow RAIDOUTSTANDING number of simultaneous IO's to this RAID device.
|
|
|
|
* Be aware that large numbers can allow the driver to consume a lot of
|
1999-08-14 07:47:07 +04:00
|
|
|
* kernel memory, especially on writes, and in degraded mode reads.
|
|
|
|
*
|
|
|
|
* For example: with a stripe width of 64 blocks (32k) and 5 disks,
|
|
|
|
* a single 64K write will typically require 64K for the old data,
|
|
|
|
* 64K for the old parity, and 64K for the new parity, for a total
|
|
|
|
* of 192K (if the parity buffer is not re-used immediately).
|
2001-10-04 19:58:51 +04:00
|
|
|
* Even it if is used immediately, that's still 128K, which when multiplied
|
1999-08-14 07:47:07 +04:00
|
|
|
* by say 10 requests, is 1280K, *on top* of the 640K of incoming data.
|
|
|
|
*
|
|
|
|
* Now in degraded mode, for example, a 64K read on the above setup may
|
|
|
|
* require data reconstruction, which will require *all* of the 4 remaining
|
|
|
|
* disks to participate -- 4 * 32K/disk == 128K again.
|
1999-07-08 04:45:23 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RAIDOUTSTANDING
|
1999-08-14 07:47:07 +04:00
|
|
|
#define RAIDOUTSTANDING 6
|
1999-07-08 04:45:23 +04:00
|
|
|
#endif
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
#define RAIDLABELDEV(dev) \
|
|
|
|
(MAKEDISKDEV(major((dev)), raidunit((dev)), RAW_PART))
|
|
|
|
|
|
|
|
/* declared here, and made public, for the benefit of KVM stuff.. */
|
1999-02-11 04:23:32 +03:00
|
|
|
struct raid_softc *raid_softc;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2001-01-27 23:42:20 +03:00
|
|
|
static void raidgetdefaultlabel(RF_Raid_t *, struct raid_softc *,
|
|
|
|
struct disklabel *);
|
|
|
|
static void raidgetdisklabel(dev_t);
|
|
|
|
static void raidmakedisklabel(struct raid_softc *);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2001-01-27 23:42:20 +03:00
|
|
|
static int raidlock(struct raid_softc *);
|
|
|
|
static void raidunlock(struct raid_softc *);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2001-01-27 23:42:20 +03:00
|
|
|
static void rf_markalldirty(RF_Raid_t *);
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
struct device *raidrootdev;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2001-01-27 23:42:20 +03:00
|
|
|
void rf_ReconThread(struct rf_recon_req *);
|
2000-01-05 05:57:28 +03:00
|
|
|
/* XXX what I want is: */
|
2001-01-27 23:42:20 +03:00
|
|
|
/*void rf_ReconThread(RF_Raid_t *raidPtr); */
|
|
|
|
void rf_RewriteParityThread(RF_Raid_t *raidPtr);
|
|
|
|
void rf_CopybackThread(RF_Raid_t *raidPtr);
|
|
|
|
void rf_ReconstructInPlaceThread(struct rf_recon_req *);
|
|
|
|
void rf_buildroothack(void *);
|
|
|
|
|
|
|
|
RF_AutoConfig_t *rf_find_raid_components(void);
|
|
|
|
RF_ConfigSet_t *rf_create_auto_sets(RF_AutoConfig_t *);
|
|
|
|
static int rf_does_it_fit(RF_ConfigSet_t *,RF_AutoConfig_t *);
|
|
|
|
static int rf_reasonable_label(RF_ComponentLabel_t *);
|
|
|
|
void rf_create_configuration(RF_AutoConfig_t *,RF_Config_t *, RF_Raid_t *);
|
|
|
|
int rf_set_autoconfig(RF_Raid_t *, int);
|
|
|
|
int rf_set_rootpartition(RF_Raid_t *, int);
|
|
|
|
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 *);
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
static int raidautoconfig = 0; /* Debugging, mostly. Set to 0 to not
|
2000-02-26 20:35:33 +03:00
|
|
|
allow autoconfig to take place.
|
|
|
|
Note that this is overridden by having
|
|
|
|
RAID_AUTOCONFIG as an option in the
|
|
|
|
kernel config file. */
|
2000-01-05 05:57:28 +03:00
|
|
|
|
1999-02-11 04:23:32 +03:00
|
|
|
void
|
|
|
|
raidattach(num)
|
1999-02-05 03:06:06 +03:00
|
|
|
int num;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-03-09 06:53:18 +03:00
|
|
|
int raidID;
|
|
|
|
int i, rc;
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_AutoConfig_t *ac_list; /* autoconfig list */
|
|
|
|
RF_ConfigSet_t *config_sets;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1999-02-05 03:06:06 +03:00
|
|
|
printf("raidattach: Asked for %d units\n", num);
|
1998-11-13 07:20:26 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (num <= 0) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("raidattach: count <= 0");
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
/* This is where all the initialization stuff gets done. */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2000-02-22 02:33:45 +03:00
|
|
|
numraid = num;
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
/* Make some space for requested number of units... */
|
|
|
|
|
|
|
|
RF_Calloc(raidPtrs, num, sizeof(RF_Raid_t *), (RF_Raid_t **));
|
|
|
|
if (raidPtrs == NULL) {
|
|
|
|
panic("raidPtrs is NULL!!\n");
|
|
|
|
}
|
2002-01-09 07:21:43 +03:00
|
|
|
|
|
|
|
/* Initialize the component buffer pool. */
|
|
|
|
pool_init(&raidframe_cbufpool, sizeof(struct raidbuf), 0,
|
2002-03-08 23:48:27 +03:00
|
|
|
0, 0, "raidpl", NULL);
|
2002-01-09 07:21:43 +03:00
|
|
|
|
1999-03-09 06:53:18 +03:00
|
|
|
rc = rf_mutex_init(&rf_sparet_wait_mutex);
|
|
|
|
if (rc) {
|
|
|
|
RF_PANIC();
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-03-09 06:53:18 +03:00
|
|
|
|
|
|
|
rf_sparet_wait_queue = rf_sparet_resp_queue = NULL;
|
|
|
|
|
2000-02-25 05:21:12 +03:00
|
|
|
for (i = 0; i < num; i++)
|
1999-03-09 06:53:18 +03:00
|
|
|
raidPtrs[i] = NULL;
|
|
|
|
rc = rf_BootRaidframe();
|
|
|
|
if (rc == 0)
|
|
|
|
printf("Kernelized RAIDframe activated\n");
|
|
|
|
else
|
|
|
|
panic("Serious error booting RAID!!\n");
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* put together some datastructures like the CCD device does.. This
|
|
|
|
* lets us lock the device and what-not when it gets opened. */
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
raid_softc = (struct raid_softc *)
|
2000-02-13 07:53:57 +03:00
|
|
|
malloc(num * sizeof(struct raid_softc),
|
|
|
|
M_RAIDFRAME, M_NOWAIT);
|
1998-11-13 07:20:26 +03:00
|
|
|
if (raid_softc == NULL) {
|
|
|
|
printf("WARNING: no memory for RAIDframe driver\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-02-22 02:33:45 +03:00
|
|
|
|
2001-07-18 10:45:33 +04:00
|
|
|
memset(raid_softc, 0, num * sizeof(struct raid_softc));
|
1999-12-12 23:51:41 +03:00
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
raidrootdev = (struct device *)malloc(num * sizeof(struct device),
|
|
|
|
M_RAIDFRAME, M_NOWAIT);
|
|
|
|
if (raidrootdev == NULL) {
|
|
|
|
panic("No memory for RAIDframe driver!!?!?!\n");
|
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
for (raidID = 0; raidID < num; raidID++) {
|
2002-07-21 19:32:17 +04:00
|
|
|
bufq_alloc(&raid_softc[raidID].buf_queue, BUFQ_FCFS);
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
raidrootdev[raidID].dv_class = DV_DISK;
|
|
|
|
raidrootdev[raidID].dv_cfdata = NULL;
|
|
|
|
raidrootdev[raidID].dv_unit = raidID;
|
|
|
|
raidrootdev[raidID].dv_parent = NULL;
|
|
|
|
raidrootdev[raidID].dv_flags = 0;
|
|
|
|
sprintf(raidrootdev[raidID].dv_xname,"raid%d",raidID);
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_Calloc(raidPtrs[raidID], 1, sizeof(RF_Raid_t),
|
1999-02-24 02:57:53 +03:00
|
|
|
(RF_Raid_t *));
|
1999-02-05 03:06:06 +03:00
|
|
|
if (raidPtrs[raidID] == NULL) {
|
2000-01-06 05:06:41 +03:00
|
|
|
printf("WARNING: raidPtrs[%d] is NULL\n", raidID);
|
|
|
|
numraid = raidID;
|
|
|
|
return;
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
}
|
2000-02-13 07:53:57 +03:00
|
|
|
|
2001-11-28 08:39:13 +03:00
|
|
|
#ifdef RAID_AUTOCONFIG
|
2000-02-26 20:35:33 +03:00
|
|
|
raidautoconfig = 1;
|
|
|
|
#endif
|
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
if (raidautoconfig) {
|
|
|
|
/* 1. locate all RAID components on the system */
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
printf("Searching for raid components...\n");
|
|
|
|
#endif
|
|
|
|
ac_list = rf_find_raid_components();
|
|
|
|
|
|
|
|
/* 2. sort them into their respective sets */
|
|
|
|
|
|
|
|
config_sets = rf_create_auto_sets(ac_list);
|
|
|
|
|
|
|
|
/* 3. evaluate each set and configure the valid ones
|
|
|
|
This gets done in rf_buildroothack() */
|
|
|
|
|
|
|
|
/* schedule the creation of the thread to do the
|
|
|
|
"/ on RAID" stuff */
|
|
|
|
|
|
|
|
kthread_create(rf_buildroothack,config_sets);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rf_buildroothack(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
RF_ConfigSet_t *config_sets = arg;
|
|
|
|
RF_ConfigSet_t *cset;
|
|
|
|
RF_ConfigSet_t *next_cset;
|
|
|
|
int retcode;
|
2000-02-22 06:38:42 +03:00
|
|
|
int raidID;
|
|
|
|
int rootID;
|
|
|
|
int num_root;
|
2000-02-13 07:53:57 +03:00
|
|
|
|
2000-12-05 04:35:56 +03:00
|
|
|
rootID = 0;
|
2000-02-22 06:38:42 +03:00
|
|
|
num_root = 0;
|
2000-02-13 07:53:57 +03:00
|
|
|
cset = config_sets;
|
|
|
|
while(cset != NULL ) {
|
|
|
|
next_cset = cset->next;
|
2000-02-22 06:38:42 +03:00
|
|
|
if (rf_have_enough_components(cset) &&
|
|
|
|
cset->ac->clabel->autoconfigure==1) {
|
|
|
|
retcode = rf_auto_config_set(cset,&raidID);
|
|
|
|
if (!retcode) {
|
|
|
|
if (cset->rootable) {
|
|
|
|
rootID = raidID;
|
|
|
|
num_root++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* The autoconfig didn't work :( */
|
2000-02-13 07:53:57 +03:00
|
|
|
#if DEBUG
|
2000-02-22 06:38:42 +03:00
|
|
|
printf("Autoconfig failed with code %d for raid%d\n", retcode, raidID);
|
|
|
|
#endif
|
|
|
|
rf_release_all_vps(cset);
|
2000-02-13 07:53:57 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* we're not autoconfiguring this set...
|
|
|
|
release the associated resources */
|
2000-02-16 04:10:44 +03:00
|
|
|
rf_release_all_vps(cset);
|
2000-02-13 07:53:57 +03:00
|
|
|
}
|
|
|
|
/* cleanup */
|
2000-02-16 04:10:44 +03:00
|
|
|
rf_cleanup_config_set(cset);
|
2000-02-13 07:53:57 +03:00
|
|
|
cset = next_cset;
|
|
|
|
}
|
2002-07-13 21:04:09 +04:00
|
|
|
|
|
|
|
/* we found something bootable... */
|
|
|
|
|
|
|
|
if (num_root == 1) {
|
|
|
|
booted_device = &raidrootdev[rootID];
|
|
|
|
} else if (num_root > 1) {
|
|
|
|
/* we can't guess.. require the user to answer... */
|
|
|
|
boothowto |= RB_ASKNAME;
|
2000-02-22 06:38:42 +03:00
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
raidsize(dev)
|
1999-02-05 03:06:06 +03:00
|
|
|
dev_t dev;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
|
|
|
struct raid_softc *rs;
|
|
|
|
struct disklabel *lp;
|
1999-02-05 03:06:06 +03:00
|
|
|
int part, unit, omask, size;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
unit = raidunit(dev);
|
|
|
|
if (unit >= numraid)
|
|
|
|
return (-1);
|
|
|
|
rs = &raid_softc[unit];
|
|
|
|
|
|
|
|
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, curproc))
|
|
|
|
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, curproc))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return (size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
raiddump(dev, blkno, va, size)
|
1999-02-05 03:06:06 +03:00
|
|
|
dev_t dev;
|
1998-11-13 07:20:26 +03:00
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
1999-02-05 03:06:06 +03:00
|
|
|
size_t size;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
|
|
|
/* Not implemented. */
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
raidopen(dev, flags, fmt, p)
|
1999-02-05 03:06:06 +03:00
|
|
|
dev_t dev;
|
|
|
|
int flags, fmt;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int unit = raidunit(dev);
|
1998-11-13 07:20:26 +03:00
|
|
|
struct raid_softc *rs;
|
|
|
|
struct disklabel *lp;
|
1999-02-05 03:06:06 +03:00
|
|
|
int part, pmask;
|
|
|
|
int error = 0;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
if (unit >= numraid)
|
|
|
|
return (ENXIO);
|
|
|
|
rs = &raid_softc[unit];
|
|
|
|
|
|
|
|
if ((error = raidlock(rs)) != 0)
|
1999-02-05 03:06:06 +03:00
|
|
|
return (error);
|
1998-11-13 07:20:26 +03:00
|
|
|
lp = rs->sc_dkdev.dk_label;
|
|
|
|
|
|
|
|
part = DISKPART(dev);
|
|
|
|
pmask = (1 << part);
|
|
|
|
|
|
|
|
db1_printf(("Opening raid device number: %d partition: %d\n",
|
1999-03-09 06:53:18 +03:00
|
|
|
unit, part));
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
if ((rs->sc_flags & RAIDF_INITED) &&
|
|
|
|
(rs->sc_dkdev.dk_openmask == 0))
|
1999-02-05 03:06:06 +03:00
|
|
|
raidgetdisklabel(dev);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/* make sure that this partition exists */
|
|
|
|
|
|
|
|
if (part != RAW_PART) {
|
|
|
|
db1_printf(("Not a raw partition..\n"));
|
|
|
|
if (((rs->sc_flags & RAIDF_INITED) == 0) ||
|
|
|
|
((part >= lp->d_npartitions) ||
|
1999-02-05 03:06:06 +03:00
|
|
|
(lp->d_partitions[part].p_fstype == FS_UNUSED))) {
|
1998-11-13 07:20:26 +03:00
|
|
|
error = ENXIO;
|
|
|
|
raidunlock(rs);
|
|
|
|
db1_printf(("Bailing out...\n"));
|
1999-02-05 03:06:06 +03:00
|
|
|
return (error);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Prevent this unit from being unconfigured while open. */
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
rs->sc_dkdev.dk_copenmask |= pmask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFBLK:
|
|
|
|
rs->sc_dkdev.dk_bopenmask |= pmask;
|
|
|
|
break;
|
|
|
|
}
|
1999-03-09 05:59:25 +03:00
|
|
|
|
|
|
|
if ((rs->sc_dkdev.dk_openmask == 0) &&
|
|
|
|
((rs->sc_flags & RAIDF_INITED) != 0)) {
|
|
|
|
/* First one... mark things as dirty... Note that we *MUST*
|
|
|
|
have done a configure before this. I DO NOT WANT TO BE
|
|
|
|
SCRIBBLING TO RANDOM COMPONENTS UNTIL IT'S BEEN DETERMINED
|
|
|
|
THAT THEY BELONG TOGETHER!!!!! */
|
|
|
|
/* XXX should check to see if we're only open for reading
|
|
|
|
here... If so, we needn't do this, but then need some
|
|
|
|
other way of keeping track of what's happened.. */
|
|
|
|
|
|
|
|
rf_markalldirty( raidPtrs[unit] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
rs->sc_dkdev.dk_openmask =
|
|
|
|
rs->sc_dkdev.dk_copenmask | rs->sc_dkdev.dk_bopenmask;
|
|
|
|
|
|
|
|
raidunlock(rs);
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
return (error);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
raidclose(dev, flags, fmt, p)
|
1999-02-05 03:06:06 +03:00
|
|
|
dev_t dev;
|
|
|
|
int flags, fmt;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int unit = raidunit(dev);
|
1998-11-13 07:20:26 +03:00
|
|
|
struct raid_softc *rs;
|
1999-02-05 03:06:06 +03:00
|
|
|
int error = 0;
|
|
|
|
int part;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
if (unit >= numraid)
|
|
|
|
return (ENXIO);
|
|
|
|
rs = &raid_softc[unit];
|
|
|
|
|
|
|
|
if ((error = raidlock(rs)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
part = DISKPART(dev);
|
|
|
|
|
|
|
|
/* ...that much closer to allowing unconfiguration... */
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
rs->sc_dkdev.dk_copenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFBLK:
|
|
|
|
rs->sc_dkdev.dk_bopenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rs->sc_dkdev.dk_openmask =
|
|
|
|
rs->sc_dkdev.dk_copenmask | rs->sc_dkdev.dk_bopenmask;
|
1999-03-09 05:59:25 +03:00
|
|
|
|
|
|
|
if ((rs->sc_dkdev.dk_openmask == 0) &&
|
|
|
|
((rs->sc_flags & RAIDF_INITED) != 0)) {
|
|
|
|
/* Last one... device is not unconfigured yet.
|
|
|
|
Device shutdown has taken care of setting the
|
|
|
|
clean bits if RAIDF_INITED is not set
|
|
|
|
mark things as clean... */
|
2000-02-27 05:35:33 +03:00
|
|
|
#if 0
|
2000-02-23 05:04:21 +03:00
|
|
|
printf("Last one on raid%d. Updating status.\n",unit);
|
|
|
|
#endif
|
2000-06-04 06:05:13 +04:00
|
|
|
rf_update_component_labels(raidPtrs[unit],
|
|
|
|
RF_FINAL_COMPONENT_UPDATE);
|
2001-07-16 19:50:27 +04:00
|
|
|
if (doing_shutdown) {
|
|
|
|
/* last one, and we're going down, so
|
|
|
|
lights out for this RAID set too. */
|
|
|
|
error = rf_Shutdown(raidPtrs[unit]);
|
|
|
|
|
|
|
|
/* It's no longer initialized... */
|
|
|
|
rs->sc_flags &= ~RAIDF_INITED;
|
|
|
|
|
|
|
|
/* Detach the disk. */
|
|
|
|
disk_detach(&rs->sc_dkdev);
|
|
|
|
}
|
1999-03-09 05:59:25 +03:00
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
raidunlock(rs);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
raidstrategy(bp)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct buf *bp;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
int s;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
unsigned int raidID = raidunit(bp->b_dev);
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
struct raid_softc *rs = &raid_softc[raidID];
|
|
|
|
struct disklabel *lp;
|
1999-02-05 03:06:06 +03:00
|
|
|
int wlabel;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-11-17 04:16:37 +03:00
|
|
|
if ((rs->sc_flags & RAIDF_INITED) ==0) {
|
|
|
|
bp->b_error = ENXIO;
|
2000-11-20 11:24:08 +03:00
|
|
|
bp->b_flags |= B_ERROR;
|
1999-11-17 04:16:37 +03:00
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
1998-11-13 07:20:26 +03:00
|
|
|
return;
|
1999-11-17 04:16:37 +03:00
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
if (raidID >= numraid || !raidPtrs[raidID]) {
|
|
|
|
bp->b_error = ENODEV;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
raidPtr = raidPtrs[raidID];
|
|
|
|
if (!raidPtr->valid) {
|
|
|
|
bp->b_error = ENODEV;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (bp->b_bcount == 0) {
|
|
|
|
db1_printf(("b_bcount is zero..\n"));
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lp = rs->sc_dkdev.dk_label;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do bounds checking and adjust transfer. If there's an
|
|
|
|
* error, the bounds check will flag that for us.
|
|
|
|
*/
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
wlabel = rs->sc_flags & (RAIDF_WLABEL | RAIDF_LABELLING);
|
1998-11-13 07:20:26 +03:00
|
|
|
if (DISKPART(bp->b_dev) != RAW_PART)
|
|
|
|
if (bounds_check_with_label(bp, lp, wlabel) <= 0) {
|
|
|
|
db1_printf(("Bounds check failed!!:%d %d\n",
|
1999-02-05 03:06:06 +03:00
|
|
|
(int) bp->b_blkno, (int) wlabel));
|
1998-11-13 07:20:26 +03:00
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
1999-12-12 23:51:41 +03:00
|
|
|
s = splbio();
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
bp->b_resid = 0;
|
1999-12-12 23:51:41 +03:00
|
|
|
|
|
|
|
/* stuff it onto our queue */
|
2002-07-20 20:30:18 +04:00
|
|
|
BUFQ_PUT(&rs->buf_queue, bp);
|
1999-12-12 23:51:41 +03:00
|
|
|
|
|
|
|
raidstart(raidPtrs[raidID]);
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
raidread(dev, uio, flags)
|
1999-02-05 03:06:06 +03:00
|
|
|
dev_t dev;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct uio *uio;
|
1999-02-05 03:06:06 +03:00
|
|
|
int flags;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int unit = raidunit(dev);
|
1998-11-13 07:20:26 +03:00
|
|
|
struct raid_softc *rs;
|
1999-02-05 03:06:06 +03:00
|
|
|
int part;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
if (unit >= numraid)
|
|
|
|
return (ENXIO);
|
|
|
|
rs = &raid_softc[unit];
|
|
|
|
|
|
|
|
if ((rs->sc_flags & RAIDF_INITED) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
part = DISKPART(dev);
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
db1_printf(("raidread: unit: %d partition: %d\n", unit, part));
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
return (physio(raidstrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
|
|
|
|
}
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
raidwrite(dev, uio, flags)
|
1999-02-05 03:06:06 +03:00
|
|
|
dev_t dev;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct uio *uio;
|
1999-02-05 03:06:06 +03:00
|
|
|
int flags;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int unit = raidunit(dev);
|
1998-11-13 07:20:26 +03:00
|
|
|
struct raid_softc *rs;
|
|
|
|
|
|
|
|
if (unit >= numraid)
|
|
|
|
return (ENXIO);
|
|
|
|
rs = &raid_softc[unit];
|
|
|
|
|
|
|
|
if ((rs->sc_flags & RAIDF_INITED) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
db1_printf(("raidwrite\n"));
|
|
|
|
return (physio(raidstrategy, NULL, dev, B_WRITE, minphys, uio));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
raidioctl(dev, cmd, data, flag, p)
|
1999-02-05 03:06:06 +03:00
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
1998-11-13 07:20:26 +03:00
|
|
|
caddr_t data;
|
1999-02-05 03:06:06 +03:00
|
|
|
int flag;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int unit = raidunit(dev);
|
|
|
|
int error = 0;
|
|
|
|
int part, pmask;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct raid_softc *rs;
|
|
|
|
RF_Config_t *k_cfg, *u_cfg;
|
2000-01-08 04:52:42 +03:00
|
|
|
RF_Raid_t *raidPtr;
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_RaidDisk_t *diskPtr;
|
2000-01-08 04:37:37 +03:00
|
|
|
RF_AccTotals_t *totals;
|
|
|
|
RF_DeviceConfig_t *d_cfg, **ucfgp;
|
1998-11-13 07:20:26 +03:00
|
|
|
u_char *specific_buf;
|
1999-02-24 02:57:53 +03:00
|
|
|
int retcode = 0;
|
|
|
|
int row;
|
|
|
|
int column;
|
2002-07-13 21:24:41 +04:00
|
|
|
int raidid;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct rf_recon_req *rrcopy, *rr;
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t *clabel;
|
1999-02-24 02:57:53 +03:00
|
|
|
RF_ComponentLabel_t ci_label;
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t **clabel_ptr;
|
1999-03-02 06:18:48 +03:00
|
|
|
RF_SingleComponent_t *sparePtr,*componentPtr;
|
|
|
|
RF_SingleComponent_t hot_spare;
|
|
|
|
RF_SingleComponent_t component;
|
2000-05-28 04:48:30 +04:00
|
|
|
RF_ProgressInfo_t progressInfo, **progressInfoPtr;
|
2000-01-08 04:37:37 +03:00
|
|
|
int i, j, d;
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
struct disklabel newlabel;
|
|
|
|
#endif
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
if (unit >= numraid)
|
|
|
|
return (ENXIO);
|
|
|
|
rs = &raid_softc[unit];
|
2000-01-08 04:52:42 +03:00
|
|
|
raidPtr = raidPtrs[unit];
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
db1_printf(("raidioctl: %d %d %d %d\n", (int) dev,
|
|
|
|
(int) DISKPART(dev), (int) unit, (int) cmd));
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/* Must be open for writes for these commands... */
|
|
|
|
switch (cmd) {
|
|
|
|
case DIOCSDINFO:
|
|
|
|
case DIOCWDINFO:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCWDINFO:
|
|
|
|
case ODIOCSDINFO:
|
|
|
|
#endif
|
1998-11-13 07:20:26 +03:00
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be initialized for these... */
|
|
|
|
switch (cmd) {
|
|
|
|
case DIOCGDINFO:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
case DIOCWDINFO:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDINFO:
|
|
|
|
case ODIOCWDINFO:
|
|
|
|
case ODIOCSDINFO:
|
|
|
|
case ODIOCGDEFLABEL:
|
|
|
|
#endif
|
1998-11-13 07:20:26 +03:00
|
|
|
case DIOCGPART:
|
|
|
|
case DIOCWLABEL:
|
|
|
|
case DIOCGDEFLABEL:
|
|
|
|
case RAIDFRAME_SHUTDOWN:
|
|
|
|
case RAIDFRAME_REWRITEPARITY:
|
|
|
|
case RAIDFRAME_GET_INFO:
|
|
|
|
case RAIDFRAME_RESET_ACCTOTALS:
|
|
|
|
case RAIDFRAME_GET_ACCTOTALS:
|
|
|
|
case RAIDFRAME_KEEP_ACCTOTALS:
|
|
|
|
case RAIDFRAME_GET_SIZE:
|
|
|
|
case RAIDFRAME_FAIL_DISK:
|
|
|
|
case RAIDFRAME_COPYBACK:
|
2000-01-05 05:57:28 +03:00
|
|
|
case RAIDFRAME_CHECK_RECON_STATUS:
|
2000-05-28 04:48:30 +04:00
|
|
|
case RAIDFRAME_CHECK_RECON_STATUS_EXT:
|
1999-02-24 02:57:53 +03:00
|
|
|
case RAIDFRAME_GET_COMPONENT_LABEL:
|
|
|
|
case RAIDFRAME_SET_COMPONENT_LABEL:
|
|
|
|
case RAIDFRAME_ADD_HOT_SPARE:
|
|
|
|
case RAIDFRAME_REMOVE_HOT_SPARE:
|
|
|
|
case RAIDFRAME_INIT_LABELS:
|
1999-03-02 06:18:48 +03:00
|
|
|
case RAIDFRAME_REBUILD_IN_PLACE:
|
1999-08-11 01:41:37 +04:00
|
|
|
case RAIDFRAME_CHECK_PARITY:
|
2000-01-05 05:57:28 +03:00
|
|
|
case RAIDFRAME_CHECK_PARITYREWRITE_STATUS:
|
2000-05-28 04:48:30 +04:00
|
|
|
case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT:
|
2000-01-05 05:57:28 +03:00
|
|
|
case RAIDFRAME_CHECK_COPYBACK_STATUS:
|
2000-05-28 04:48:30 +04:00
|
|
|
case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT:
|
2000-02-13 07:53:57 +03:00
|
|
|
case RAIDFRAME_SET_AUTOCONFIG:
|
|
|
|
case RAIDFRAME_SET_ROOT:
|
2000-03-27 02:38:28 +04:00
|
|
|
case RAIDFRAME_DELETE_COMPONENT:
|
|
|
|
case RAIDFRAME_INCORPORATE_HOT_SPARE:
|
1998-11-13 07:20:26 +03:00
|
|
|
if ((rs->sc_flags & RAIDF_INITED) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
/* configure the system */
|
|
|
|
case RAIDFRAME_CONFIGURE:
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
if (raidPtr->valid) {
|
|
|
|
/* There is a valid RAID set running on this unit! */
|
|
|
|
printf("raid%d: Device already configured!\n",unit);
|
2000-03-04 09:03:21 +03:00
|
|
|
return(EINVAL);
|
2000-02-13 07:53:57 +03:00
|
|
|
}
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
/* copy-in the configuration information */
|
|
|
|
/* data points to a pointer to the configuration structure */
|
2000-01-08 05:04:06 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
u_cfg = *((RF_Config_t **) data);
|
|
|
|
RF_Malloc(k_cfg, sizeof(RF_Config_t), (RF_Config_t *));
|
1998-11-13 07:20:26 +03:00
|
|
|
if (k_cfg == NULL) {
|
1999-02-05 03:06:06 +03:00
|
|
|
return (ENOMEM);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
retcode = copyin((caddr_t) u_cfg, (caddr_t) k_cfg,
|
|
|
|
sizeof(RF_Config_t));
|
1998-11-13 07:20:26 +03:00
|
|
|
if (retcode) {
|
1999-12-03 06:06:44 +03:00
|
|
|
RF_Free(k_cfg, sizeof(RF_Config_t));
|
2000-01-09 06:39:13 +03:00
|
|
|
db1_printf(("rf_ioctl: retcode=%d copyin.1\n",
|
1999-02-05 03:06:06 +03:00
|
|
|
retcode));
|
|
|
|
return (retcode);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
/* allocate a buffer for the layout-specific data, and copy it
|
|
|
|
* in */
|
1998-11-13 07:20:26 +03:00
|
|
|
if (k_cfg->layoutSpecificSize) {
|
1999-02-05 03:06:06 +03:00
|
|
|
if (k_cfg->layoutSpecificSize > 10000) {
|
1998-11-13 07:20:26 +03:00
|
|
|
/* sanity check */
|
1999-12-03 06:06:44 +03:00
|
|
|
RF_Free(k_cfg, sizeof(RF_Config_t));
|
1999-02-05 03:06:06 +03:00
|
|
|
return (EINVAL);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_Malloc(specific_buf, k_cfg->layoutSpecificSize,
|
|
|
|
(u_char *));
|
1998-11-13 07:20:26 +03:00
|
|
|
if (specific_buf == NULL) {
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_Free(k_cfg, sizeof(RF_Config_t));
|
|
|
|
return (ENOMEM);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
retcode = copyin(k_cfg->layoutSpecific,
|
|
|
|
(caddr_t) specific_buf,
|
|
|
|
k_cfg->layoutSpecificSize);
|
1998-11-13 07:20:26 +03:00
|
|
|
if (retcode) {
|
1999-12-03 06:06:44 +03:00
|
|
|
RF_Free(k_cfg, sizeof(RF_Config_t));
|
2000-01-08 04:52:42 +03:00
|
|
|
RF_Free(specific_buf,
|
|
|
|
k_cfg->layoutSpecificSize);
|
2000-01-09 06:39:13 +03:00
|
|
|
db1_printf(("rf_ioctl: retcode=%d copyin.2\n",
|
1999-02-05 03:06:06 +03:00
|
|
|
retcode));
|
|
|
|
return (retcode);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
} else
|
|
|
|
specific_buf = NULL;
|
1998-11-13 07:20:26 +03:00
|
|
|
k_cfg->layoutSpecific = specific_buf;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
/* should do some kind of sanity check on the configuration.
|
|
|
|
* Store the sum of all the bytes in the last byte? */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/* configure the system */
|
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
/*
|
|
|
|
* Clear the entire RAID descriptor, just to make sure
|
|
|
|
* there is no stale data left in the case of a
|
|
|
|
* reconfiguration
|
|
|
|
*/
|
2001-07-18 10:45:33 +04:00
|
|
|
memset((char *) raidPtr, 0, sizeof(RF_Raid_t));
|
2000-01-08 04:52:42 +03:00
|
|
|
raidPtr->raidid = unit;
|
1999-07-08 04:45:23 +04:00
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
retcode = rf_Configure(raidPtr, k_cfg, NULL);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2000-01-07 16:57:20 +03:00
|
|
|
if (retcode == 0) {
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2000-01-07 16:57:20 +03:00
|
|
|
/* allow this many simultaneous IO's to
|
|
|
|
this RAID device */
|
2000-01-08 04:52:42 +03:00
|
|
|
raidPtr->openings = RAIDOUTSTANDING;
|
2000-02-13 07:53:57 +03:00
|
|
|
|
2000-02-25 05:42:30 +03:00
|
|
|
raidinit(raidPtr);
|
|
|
|
rf_markalldirty(raidPtr);
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
/* free the buffers. No return code here. */
|
|
|
|
if (k_cfg->layoutSpecificSize) {
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_Free(specific_buf, k_cfg->layoutSpecificSize);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_Free(k_cfg, sizeof(RF_Config_t));
|
|
|
|
|
|
|
|
return (retcode);
|
|
|
|
|
|
|
|
/* shutdown the system */
|
1998-11-13 07:20:26 +03:00
|
|
|
case RAIDFRAME_SHUTDOWN:
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
if ((error = raidlock(rs)) != 0)
|
|
|
|
return (error);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If somebody has a partition mounted, we shouldn't
|
|
|
|
* shutdown.
|
|
|
|
*/
|
|
|
|
|
|
|
|
part = DISKPART(dev);
|
|
|
|
pmask = (1 << part);
|
1999-02-05 03:06:06 +03:00
|
|
|
if ((rs->sc_dkdev.dk_openmask & ~pmask) ||
|
|
|
|
((rs->sc_dkdev.dk_bopenmask & pmask) &&
|
|
|
|
(rs->sc_dkdev.dk_copenmask & pmask))) {
|
|
|
|
raidunlock(rs);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
1999-02-24 02:57:53 +03:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
retcode = rf_Shutdown(raidPtr);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/* It's no longer initialized... */
|
|
|
|
rs->sc_flags &= ~RAIDF_INITED;
|
1999-03-27 04:26:37 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* Detach the disk. */
|
|
|
|
disk_detach(&rs->sc_dkdev);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
raidunlock(rs);
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
return (retcode);
|
1999-02-24 02:57:53 +03:00
|
|
|
case RAIDFRAME_GET_COMPONENT_LABEL:
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel_ptr = (RF_ComponentLabel_t **) data;
|
1999-02-24 02:57:53 +03:00
|
|
|
/* need to read the component label for the disk indicated
|
2000-02-13 07:53:57 +03:00
|
|
|
by row,column in clabel */
|
1999-02-24 02:57:53 +03:00
|
|
|
|
|
|
|
/* For practice, let's get it directly fromdisk, rather
|
|
|
|
than from the in-core copy */
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_Malloc( clabel, sizeof( RF_ComponentLabel_t ),
|
1999-02-24 02:57:53 +03:00
|
|
|
(RF_ComponentLabel_t *));
|
2000-02-13 07:53:57 +03:00
|
|
|
if (clabel == NULL)
|
1999-02-24 02:57:53 +03:00
|
|
|
return (ENOMEM);
|
|
|
|
|
2001-07-18 10:45:33 +04:00
|
|
|
memset((char *) clabel, 0, sizeof(RF_ComponentLabel_t));
|
1999-02-24 02:57:53 +03:00
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
retcode = copyin( *clabel_ptr, clabel,
|
1999-02-24 02:57:53 +03:00
|
|
|
sizeof(RF_ComponentLabel_t));
|
|
|
|
|
|
|
|
if (retcode) {
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_Free( clabel, sizeof(RF_ComponentLabel_t));
|
1999-02-24 02:57:53 +03:00
|
|
|
return(retcode);
|
|
|
|
}
|
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
row = clabel->row;
|
|
|
|
column = clabel->column;
|
1999-08-14 06:41:36 +04:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if ((row < 0) || (row >= raidPtr->numRow) ||
|
2000-06-03 20:44:43 +04:00
|
|
|
(column < 0) || (column >= raidPtr->numCol +
|
|
|
|
raidPtr->numSpare)) {
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_Free( clabel, sizeof(RF_ComponentLabel_t));
|
1999-08-14 06:41:36 +04:00
|
|
|
return(EINVAL);
|
1999-02-24 02:57:53 +03:00
|
|
|
}
|
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
raidread_component_label(raidPtr->Disks[row][column].dev,
|
|
|
|
raidPtr->raid_cinfo[row][column].ci_vp,
|
|
|
|
clabel );
|
1999-02-24 02:57:53 +03:00
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
retcode = copyout((caddr_t) clabel,
|
|
|
|
(caddr_t) *clabel_ptr,
|
1999-02-24 02:57:53 +03:00
|
|
|
sizeof(RF_ComponentLabel_t));
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_Free( clabel, sizeof(RF_ComponentLabel_t));
|
1999-02-24 02:57:53 +03:00
|
|
|
return (retcode);
|
|
|
|
|
|
|
|
case RAIDFRAME_SET_COMPONENT_LABEL:
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel = (RF_ComponentLabel_t *) data;
|
1999-02-24 02:57:53 +03:00
|
|
|
|
|
|
|
/* XXX check the label for valid stuff... */
|
|
|
|
/* Note that some things *should not* get modified --
|
|
|
|
the user should be re-initing the labels instead of
|
|
|
|
trying to patch things.
|
|
|
|
*/
|
|
|
|
|
2002-07-13 21:24:41 +04:00
|
|
|
raidid = raidPtr->raidid;
|
|
|
|
printf("raid%d: Got component label:\n", raidid);
|
|
|
|
printf("raid%d: Version: %d\n", raidid, clabel->version);
|
|
|
|
printf("raid%d: Serial Number: %d\n", raidid, clabel->serial_number);
|
|
|
|
printf("raid%d: Mod counter: %d\n", raidid, clabel->mod_counter);
|
|
|
|
printf("raid%d: Row: %d\n", raidid, clabel->row);
|
|
|
|
printf("raid%d: Column: %d\n", raidid, clabel->column);
|
|
|
|
printf("raid%d: Num Rows: %d\n", raidid, clabel->num_rows);
|
|
|
|
printf("raid%d: Num Columns: %d\n", raidid, clabel->num_columns);
|
|
|
|
printf("raid%d: Clean: %d\n", raidid, clabel->clean);
|
|
|
|
printf("raid%d: Status: %d\n", raidid, clabel->status);
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
row = clabel->row;
|
|
|
|
column = clabel->column;
|
1999-03-02 06:18:48 +03:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if ((row < 0) || (row >= raidPtr->numRow) ||
|
|
|
|
(column < 0) || (column >= raidPtr->numCol)) {
|
1999-03-02 06:18:48 +03:00
|
|
|
return(EINVAL);
|
1999-02-24 02:57:53 +03:00
|
|
|
}
|
1999-03-02 06:18:48 +03:00
|
|
|
|
|
|
|
/* XXX this isn't allowed to do anything for now :-) */
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
/* XXX and before it is, we need to fill in the rest
|
|
|
|
of the fields!?!?!?! */
|
1999-03-02 06:18:48 +03:00
|
|
|
#if 0
|
1999-02-24 02:57:53 +03:00
|
|
|
raidwrite_component_label(
|
2000-01-08 04:52:42 +03:00
|
|
|
raidPtr->Disks[row][column].dev,
|
|
|
|
raidPtr->raid_cinfo[row][column].ci_vp,
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel );
|
1999-03-02 06:18:48 +03:00
|
|
|
#endif
|
|
|
|
return (0);
|
1999-02-24 02:57:53 +03:00
|
|
|
|
|
|
|
case RAIDFRAME_INIT_LABELS:
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel = (RF_ComponentLabel_t *) data;
|
1999-02-24 02:57:53 +03:00
|
|
|
/*
|
|
|
|
we only want the serial number from
|
|
|
|
the above. We get all the rest of the information
|
|
|
|
from the config that was used to create this RAID
|
|
|
|
set.
|
|
|
|
*/
|
1999-03-02 06:18:48 +03:00
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
raidPtr->serial_number = clabel->serial_number;
|
2000-02-22 06:38:42 +03:00
|
|
|
|
|
|
|
raid_init_component_label(raidPtr, &ci_label);
|
|
|
|
ci_label.serial_number = clabel->serial_number;
|
1999-02-24 02:57:53 +03:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
for(row=0;row<raidPtr->numRow;row++) {
|
1999-02-24 02:57:53 +03:00
|
|
|
ci_label.row = row;
|
2000-01-08 04:52:42 +03:00
|
|
|
for(column=0;column<raidPtr->numCol;column++) {
|
2000-02-13 07:53:57 +03:00
|
|
|
diskPtr = &raidPtr->Disks[row][column];
|
2000-10-17 07:39:41 +04:00
|
|
|
if (!RF_DEAD_DISK(diskPtr->status)) {
|
2000-08-19 22:07:36 +04:00
|
|
|
ci_label.partitionSize = diskPtr->partitionSize;
|
|
|
|
ci_label.column = column;
|
|
|
|
raidwrite_component_label(
|
|
|
|
raidPtr->Disks[row][column].dev,
|
|
|
|
raidPtr->raid_cinfo[row][column].ci_vp,
|
|
|
|
&ci_label );
|
|
|
|
}
|
1999-02-24 02:57:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (retcode);
|
2000-02-13 07:53:57 +03:00
|
|
|
case RAIDFRAME_SET_AUTOCONFIG:
|
2000-05-19 08:53:25 +04:00
|
|
|
d = rf_set_autoconfig(raidPtr, *(int *) data);
|
2002-07-13 21:24:41 +04:00
|
|
|
printf("raid%d: New autoconfig value is: %d\n",
|
|
|
|
raidPtr->raidid, d);
|
2000-05-19 08:53:25 +04:00
|
|
|
*(int *) data = d;
|
2000-02-13 07:53:57 +03:00
|
|
|
return (retcode);
|
|
|
|
|
|
|
|
case RAIDFRAME_SET_ROOT:
|
2000-05-19 08:53:25 +04:00
|
|
|
d = rf_set_rootpartition(raidPtr, *(int *) data);
|
2002-07-13 21:24:41 +04:00
|
|
|
printf("raid%d: New rootpartition value is: %d\n",
|
|
|
|
raidPtr->raidid, d);
|
2000-05-19 08:53:25 +04:00
|
|
|
*(int *) data = d;
|
2000-02-13 07:53:57 +03:00
|
|
|
return (retcode);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
/* initialize all parity */
|
|
|
|
case RAIDFRAME_REWRITEPARITY:
|
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->Layout.map->faultsTolerated == 0) {
|
1999-04-07 18:17:10 +04:00
|
|
|
/* Parity for RAID 0 is trivially correct */
|
2000-01-08 04:52:42 +03:00
|
|
|
raidPtr->parity_good = RF_RAID_CLEAN;
|
1999-04-07 18:17:10 +04:00
|
|
|
return(0);
|
|
|
|
}
|
2000-01-05 05:57:28 +03:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->parity_rewrite_in_progress == 1) {
|
2000-01-05 05:57:28 +03:00
|
|
|
/* Re-write is already in progress! */
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
1999-04-07 18:17:10 +04:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
retcode = RF_CREATE_THREAD(raidPtr->parity_rewrite_thread,
|
2000-01-05 05:57:28 +03:00
|
|
|
rf_RewriteParityThread,
|
2000-01-08 04:52:42 +03:00
|
|
|
raidPtr,"raid_parity");
|
1999-02-05 03:06:06 +03:00
|
|
|
return (retcode);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-24 02:57:53 +03:00
|
|
|
|
|
|
|
case RAIDFRAME_ADD_HOT_SPARE:
|
1999-03-02 06:18:48 +03:00
|
|
|
sparePtr = (RF_SingleComponent_t *) data;
|
|
|
|
memcpy( &hot_spare, sparePtr, sizeof(RF_SingleComponent_t));
|
2000-01-08 04:52:42 +03:00
|
|
|
retcode = rf_add_hot_spare(raidPtr, &hot_spare);
|
1999-02-24 02:57:53 +03:00
|
|
|
return(retcode);
|
|
|
|
|
|
|
|
case RAIDFRAME_REMOVE_HOT_SPARE:
|
|
|
|
return(retcode);
|
|
|
|
|
2000-03-27 02:38:28 +04:00
|
|
|
case RAIDFRAME_DELETE_COMPONENT:
|
|
|
|
componentPtr = (RF_SingleComponent_t *)data;
|
|
|
|
memcpy( &component, componentPtr,
|
|
|
|
sizeof(RF_SingleComponent_t));
|
|
|
|
retcode = rf_delete_component(raidPtr, &component);
|
|
|
|
return(retcode);
|
|
|
|
|
|
|
|
case RAIDFRAME_INCORPORATE_HOT_SPARE:
|
|
|
|
componentPtr = (RF_SingleComponent_t *)data;
|
|
|
|
memcpy( &component, componentPtr,
|
|
|
|
sizeof(RF_SingleComponent_t));
|
|
|
|
retcode = rf_incorporate_hot_spare(raidPtr, &component);
|
|
|
|
return(retcode);
|
|
|
|
|
1999-03-02 06:18:48 +03:00
|
|
|
case RAIDFRAME_REBUILD_IN_PLACE:
|
1999-08-11 02:46:59 +04:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->Layout.map->faultsTolerated == 0) {
|
1999-08-11 02:46:59 +04:00
|
|
|
/* Can't do this on a RAID 0!! */
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->recon_in_progress == 1) {
|
2000-01-05 05:57:28 +03:00
|
|
|
/* a reconstruct is already in progress! */
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
1999-03-02 06:18:48 +03:00
|
|
|
componentPtr = (RF_SingleComponent_t *) data;
|
|
|
|
memcpy( &component, componentPtr,
|
|
|
|
sizeof(RF_SingleComponent_t));
|
|
|
|
row = component.row;
|
|
|
|
column = component.column;
|
2002-07-13 21:24:41 +04:00
|
|
|
printf("raid%d: Rebuild: %d %d\n", raidPtr->raidid,
|
|
|
|
row, column);
|
2000-01-08 04:52:42 +03:00
|
|
|
if ((row < 0) || (row >= raidPtr->numRow) ||
|
|
|
|
(column < 0) || (column >= raidPtr->numCol)) {
|
1999-03-02 06:18:48 +03:00
|
|
|
return(EINVAL);
|
|
|
|
}
|
2000-01-05 05:57:28 +03:00
|
|
|
|
|
|
|
RF_Malloc(rrcopy, sizeof(*rrcopy), (struct rf_recon_req *));
|
2000-01-05 07:15:30 +03:00
|
|
|
if (rrcopy == NULL)
|
|
|
|
return(ENOMEM);
|
2000-01-05 05:57:28 +03:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
rrcopy->raidPtr = (void *) raidPtr;
|
2000-01-05 05:57:28 +03:00
|
|
|
rrcopy->row = row;
|
|
|
|
rrcopy->col = column;
|
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
retcode = RF_CREATE_THREAD(raidPtr->recon_thread,
|
2000-01-05 05:57:28 +03:00
|
|
|
rf_ReconstructInPlaceThread,
|
|
|
|
rrcopy,"raid_reconip");
|
1999-03-02 06:18:48 +03:00
|
|
|
return(retcode);
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
case RAIDFRAME_GET_INFO:
|
2000-01-08 04:52:42 +03:00
|
|
|
if (!raidPtr->valid)
|
2000-01-08 04:37:37 +03:00
|
|
|
return (ENODEV);
|
|
|
|
ucfgp = (RF_DeviceConfig_t **) data;
|
|
|
|
RF_Malloc(d_cfg, sizeof(RF_DeviceConfig_t),
|
|
|
|
(RF_DeviceConfig_t *));
|
|
|
|
if (d_cfg == NULL)
|
|
|
|
return (ENOMEM);
|
2001-07-18 10:45:33 +04:00
|
|
|
memset((char *) d_cfg, 0, sizeof(RF_DeviceConfig_t));
|
2000-01-08 04:52:42 +03:00
|
|
|
d_cfg->rows = raidPtr->numRow;
|
|
|
|
d_cfg->cols = raidPtr->numCol;
|
|
|
|
d_cfg->ndevs = raidPtr->numRow * raidPtr->numCol;
|
2000-01-08 04:37:37 +03:00
|
|
|
if (d_cfg->ndevs >= RF_MAX_DISKS) {
|
|
|
|
RF_Free(d_cfg, sizeof(RF_DeviceConfig_t));
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
2000-01-08 04:52:42 +03:00
|
|
|
d_cfg->nspares = raidPtr->numSpare;
|
2000-01-08 04:37:37 +03:00
|
|
|
if (d_cfg->nspares >= RF_MAX_DISKS) {
|
|
|
|
RF_Free(d_cfg, sizeof(RF_DeviceConfig_t));
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
2000-01-08 04:52:42 +03:00
|
|
|
d_cfg->maxqdepth = raidPtr->maxQueueDepth;
|
2000-01-08 04:37:37 +03:00
|
|
|
d = 0;
|
|
|
|
for (i = 0; i < d_cfg->rows; i++) {
|
|
|
|
for (j = 0; j < d_cfg->cols; j++) {
|
2000-01-08 04:52:42 +03:00
|
|
|
d_cfg->devs[d] = raidPtr->Disks[i][j];
|
2000-01-08 04:37:37 +03:00
|
|
|
d++;
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
}
|
2000-01-08 04:37:37 +03:00
|
|
|
for (j = d_cfg->cols, i = 0; i < d_cfg->nspares; i++, j++) {
|
2000-01-08 04:52:42 +03:00
|
|
|
d_cfg->spares[i] = raidPtr->Disks[0][j];
|
2000-01-08 04:37:37 +03:00
|
|
|
}
|
|
|
|
retcode = copyout((caddr_t) d_cfg, (caddr_t) * ucfgp,
|
|
|
|
sizeof(RF_DeviceConfig_t));
|
|
|
|
RF_Free(d_cfg, sizeof(RF_DeviceConfig_t));
|
|
|
|
|
|
|
|
return (retcode);
|
|
|
|
|
1999-08-10 22:18:30 +04:00
|
|
|
case RAIDFRAME_CHECK_PARITY:
|
2000-01-08 04:52:42 +03:00
|
|
|
*(int *) data = raidPtr->parity_good;
|
1999-08-10 22:18:30 +04:00
|
|
|
return (0);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2000-01-08 04:37:37 +03:00
|
|
|
case RAIDFRAME_RESET_ACCTOTALS:
|
2001-07-18 10:45:33 +04:00
|
|
|
memset(&raidPtr->acc_totals, 0, sizeof(raidPtr->acc_totals));
|
2000-01-08 04:37:37 +03:00
|
|
|
return (0);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
case RAIDFRAME_GET_ACCTOTALS:
|
2000-01-08 04:37:37 +03:00
|
|
|
totals = (RF_AccTotals_t *) data;
|
2000-01-08 04:52:42 +03:00
|
|
|
*totals = raidPtr->acc_totals;
|
2000-01-08 04:37:37 +03:00
|
|
|
return (0);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
case RAIDFRAME_KEEP_ACCTOTALS:
|
2000-01-08 04:52:42 +03:00
|
|
|
raidPtr->keep_acc_totals = *(int *)data;
|
2000-01-08 04:37:37 +03:00
|
|
|
return (0);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
case RAIDFRAME_GET_SIZE:
|
2000-01-08 04:52:42 +03:00
|
|
|
*(int *) data = raidPtr->totalSectors;
|
1999-02-05 03:06:06 +03:00
|
|
|
return (0);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/* fail a disk & optionally start reconstruction */
|
|
|
|
case RAIDFRAME_FAIL_DISK:
|
1999-08-11 02:46:59 +04:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->Layout.map->faultsTolerated == 0) {
|
1999-08-11 02:46:59 +04:00
|
|
|
/* Can't do this on a RAID 0!! */
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
rr = (struct rf_recon_req *) data;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if (rr->row < 0 || rr->row >= raidPtr->numRow
|
|
|
|
|| rr->col < 0 || rr->col >= raidPtr->numCol)
|
1999-02-05 03:06:06 +03:00
|
|
|
return (EINVAL);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-03-02 06:18:48 +03:00
|
|
|
printf("raid%d: Failing the disk: row: %d col: %d\n",
|
|
|
|
unit, rr->row, rr->col);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
/* make a copy of the recon request so that we don't rely on
|
|
|
|
* the user's buffer */
|
1998-11-13 07:20:26 +03:00
|
|
|
RF_Malloc(rrcopy, sizeof(*rrcopy), (struct rf_recon_req *));
|
2000-01-05 07:15:30 +03:00
|
|
|
if (rrcopy == NULL)
|
|
|
|
return(ENOMEM);
|
2002-05-22 19:40:47 +04:00
|
|
|
memcpy(rrcopy, rr, sizeof(*rr));
|
2000-01-08 04:52:42 +03:00
|
|
|
rrcopy->raidPtr = (void *) raidPtr;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
retcode = RF_CREATE_THREAD(raidPtr->recon_thread,
|
2000-01-05 05:57:28 +03:00
|
|
|
rf_ReconThread,
|
|
|
|
rrcopy,"raid_recon");
|
1999-02-05 03:06:06 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* invoke a copyback operation after recon on whatever disk
|
|
|
|
* needs it, if any */
|
|
|
|
case RAIDFRAME_COPYBACK:
|
1999-08-11 02:46:59 +04:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->Layout.map->faultsTolerated == 0) {
|
1999-08-11 02:46:59 +04:00
|
|
|
/* This makes no sense on a RAID 0!! */
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->copyback_in_progress == 1) {
|
2000-01-05 05:57:28 +03:00
|
|
|
/* Copyback is already in progress! */
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
1999-08-14 07:10:03 +04:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
retcode = RF_CREATE_THREAD(raidPtr->copyback_thread,
|
2000-01-05 05:57:28 +03:00
|
|
|
rf_CopybackThread,
|
2000-01-08 04:52:42 +03:00
|
|
|
raidPtr,"raid_copyback");
|
2000-01-05 05:57:28 +03:00
|
|
|
return (retcode);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
/* return the percentage completion of reconstruction */
|
2000-01-05 05:57:28 +03:00
|
|
|
case RAIDFRAME_CHECK_RECON_STATUS:
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->Layout.map->faultsTolerated == 0) {
|
2000-03-21 01:59:26 +03:00
|
|
|
/* This makes no sense on a RAID 0, so tell the
|
|
|
|
user it's done. */
|
|
|
|
*(int *) data = 100;
|
|
|
|
return(0);
|
1999-08-11 02:46:59 +04:00
|
|
|
}
|
2000-01-05 05:57:28 +03:00
|
|
|
row = 0; /* XXX we only consider a single row... */
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->status[row] != rf_rs_reconstructing)
|
1998-11-13 07:20:26 +03:00
|
|
|
*(int *) data = 100;
|
1999-02-05 03:06:06 +03:00
|
|
|
else
|
2000-01-08 04:52:42 +03:00
|
|
|
*(int *) data = raidPtr->reconControl[row]->percentComplete;
|
1999-02-05 03:06:06 +03:00
|
|
|
return (0);
|
2000-05-28 04:48:30 +04:00
|
|
|
case RAIDFRAME_CHECK_RECON_STATUS_EXT:
|
|
|
|
progressInfoPtr = (RF_ProgressInfo_t **) data;
|
|
|
|
row = 0; /* XXX we only consider a single row... */
|
|
|
|
if (raidPtr->status[row] != rf_rs_reconstructing) {
|
|
|
|
progressInfo.remaining = 0;
|
|
|
|
progressInfo.completed = 100;
|
|
|
|
progressInfo.total = 100;
|
|
|
|
} else {
|
|
|
|
progressInfo.total =
|
|
|
|
raidPtr->reconControl[row]->numRUsTotal;
|
|
|
|
progressInfo.completed =
|
|
|
|
raidPtr->reconControl[row]->numRUsComplete;
|
|
|
|
progressInfo.remaining = progressInfo.total -
|
|
|
|
progressInfo.completed;
|
|
|
|
}
|
|
|
|
retcode = copyout((caddr_t) &progressInfo,
|
|
|
|
(caddr_t) *progressInfoPtr,
|
|
|
|
sizeof(RF_ProgressInfo_t));
|
|
|
|
return (retcode);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2000-01-05 05:57:28 +03:00
|
|
|
case RAIDFRAME_CHECK_PARITYREWRITE_STATUS:
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->Layout.map->faultsTolerated == 0) {
|
2000-05-27 22:23:27 +04:00
|
|
|
/* This makes no sense on a RAID 0, so tell the
|
|
|
|
user it's done. */
|
|
|
|
*(int *) data = 100;
|
|
|
|
return(0);
|
2000-01-05 05:57:28 +03:00
|
|
|
}
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->parity_rewrite_in_progress == 1) {
|
2000-05-28 04:48:30 +04:00
|
|
|
*(int *) data = 100 *
|
|
|
|
raidPtr->parity_rewrite_stripes_done /
|
|
|
|
raidPtr->Layout.numStripe;
|
2000-01-05 05:57:28 +03:00
|
|
|
} else {
|
|
|
|
*(int *) data = 100;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
|
2000-05-28 04:48:30 +04:00
|
|
|
case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT:
|
|
|
|
progressInfoPtr = (RF_ProgressInfo_t **) data;
|
|
|
|
if (raidPtr->parity_rewrite_in_progress == 1) {
|
|
|
|
progressInfo.total = raidPtr->Layout.numStripe;
|
|
|
|
progressInfo.completed =
|
|
|
|
raidPtr->parity_rewrite_stripes_done;
|
|
|
|
progressInfo.remaining = progressInfo.total -
|
|
|
|
progressInfo.completed;
|
|
|
|
} else {
|
|
|
|
progressInfo.remaining = 0;
|
|
|
|
progressInfo.completed = 100;
|
|
|
|
progressInfo.total = 100;
|
|
|
|
}
|
|
|
|
retcode = copyout((caddr_t) &progressInfo,
|
|
|
|
(caddr_t) *progressInfoPtr,
|
|
|
|
sizeof(RF_ProgressInfo_t));
|
|
|
|
return (retcode);
|
|
|
|
|
2000-01-05 05:57:28 +03:00
|
|
|
case RAIDFRAME_CHECK_COPYBACK_STATUS:
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->Layout.map->faultsTolerated == 0) {
|
2000-01-05 05:57:28 +03:00
|
|
|
/* This makes no sense on a RAID 0 */
|
2000-05-28 04:48:30 +04:00
|
|
|
*(int *) data = 100;
|
|
|
|
return(0);
|
2000-01-05 05:57:28 +03:00
|
|
|
}
|
2000-01-08 04:52:42 +03:00
|
|
|
if (raidPtr->copyback_in_progress == 1) {
|
|
|
|
*(int *) data = 100 * raidPtr->copyback_stripes_done /
|
|
|
|
raidPtr->Layout.numStripe;
|
2000-01-05 05:57:28 +03:00
|
|
|
} else {
|
|
|
|
*(int *) data = 100;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
|
2000-05-28 04:48:30 +04:00
|
|
|
case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT:
|
2000-07-14 19:26:29 +04:00
|
|
|
progressInfoPtr = (RF_ProgressInfo_t **) data;
|
2000-05-28 04:48:30 +04:00
|
|
|
if (raidPtr->copyback_in_progress == 1) {
|
|
|
|
progressInfo.total = raidPtr->Layout.numStripe;
|
|
|
|
progressInfo.completed =
|
2000-07-14 19:26:29 +04:00
|
|
|
raidPtr->copyback_stripes_done;
|
2000-05-28 04:48:30 +04:00
|
|
|
progressInfo.remaining = progressInfo.total -
|
|
|
|
progressInfo.completed;
|
|
|
|
} else {
|
|
|
|
progressInfo.remaining = 0;
|
|
|
|
progressInfo.completed = 100;
|
|
|
|
progressInfo.total = 100;
|
|
|
|
}
|
|
|
|
retcode = copyout((caddr_t) &progressInfo,
|
|
|
|
(caddr_t) *progressInfoPtr,
|
|
|
|
sizeof(RF_ProgressInfo_t));
|
|
|
|
return (retcode);
|
2000-01-05 05:57:28 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* the sparetable daemon calls this to wait for the kernel to
|
|
|
|
* need a spare table. this ioctl does not return until a
|
|
|
|
* spare table is needed. XXX -- calling mpsleep here in the
|
|
|
|
* ioctl code is almost certainly wrong and evil. -- XXX XXX
|
|
|
|
* -- I should either compute the spare table in the kernel,
|
|
|
|
* or have a different -- XXX XXX -- interface (a different
|
2000-01-08 04:52:42 +03:00
|
|
|
* character device) for delivering the table -- XXX */
|
1998-11-13 07:20:26 +03:00
|
|
|
#if 0
|
|
|
|
case RAIDFRAME_SPARET_WAIT:
|
|
|
|
RF_LOCK_MUTEX(rf_sparet_wait_mutex);
|
1999-02-05 03:06:06 +03:00
|
|
|
while (!rf_sparet_wait_queue)
|
|
|
|
mpsleep(&rf_sparet_wait_queue, (PZERO + 1) | PCATCH, "sparet wait", 0, (void *) simple_lock_addr(rf_sparet_wait_mutex), MS_LOCK_SIMPLE);
|
1998-11-13 07:20:26 +03:00
|
|
|
waitreq = rf_sparet_wait_queue;
|
|
|
|
rf_sparet_wait_queue = rf_sparet_wait_queue->next;
|
|
|
|
RF_UNLOCK_MUTEX(rf_sparet_wait_mutex);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
/* structure assignment */
|
|
|
|
*((RF_SparetWait_t *) data) = *waitreq;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
RF_Free(waitreq, sizeof(*waitreq));
|
1999-02-05 03:06:06 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* wakes up a process waiting on SPARET_WAIT and puts an error
|
|
|
|
* code in it that will cause the dameon to exit */
|
1998-11-13 07:20:26 +03:00
|
|
|
case RAIDFRAME_ABORT_SPARET_WAIT:
|
|
|
|
RF_Malloc(waitreq, sizeof(*waitreq), (RF_SparetWait_t *));
|
|
|
|
waitreq->fcol = -1;
|
|
|
|
RF_LOCK_MUTEX(rf_sparet_wait_mutex);
|
|
|
|
waitreq->next = rf_sparet_wait_queue;
|
|
|
|
rf_sparet_wait_queue = waitreq;
|
|
|
|
RF_UNLOCK_MUTEX(rf_sparet_wait_mutex);
|
|
|
|
wakeup(&rf_sparet_wait_queue);
|
1999-02-05 03:06:06 +03:00
|
|
|
return (0);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* used by the spare table daemon to deliver a spare table
|
|
|
|
* into the kernel */
|
1998-11-13 07:20:26 +03:00
|
|
|
case RAIDFRAME_SEND_SPARET:
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
/* install the spare table */
|
2000-01-08 04:52:42 +03:00
|
|
|
retcode = rf_SetSpareTable(raidPtr, *(void **) data);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
/* respond to the requestor. the return status of the spare
|
|
|
|
* table installation is passed in the "fcol" field */
|
1998-11-13 07:20:26 +03:00
|
|
|
RF_Malloc(waitreq, sizeof(*waitreq), (RF_SparetWait_t *));
|
|
|
|
waitreq->fcol = retcode;
|
|
|
|
RF_LOCK_MUTEX(rf_sparet_wait_mutex);
|
|
|
|
waitreq->next = rf_sparet_resp_queue;
|
|
|
|
rf_sparet_resp_queue = waitreq;
|
|
|
|
wakeup(&rf_sparet_resp_queue);
|
|
|
|
RF_UNLOCK_MUTEX(rf_sparet_wait_mutex);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
|
|
|
return (retcode);
|
1998-11-13 07:20:26 +03:00
|
|
|
#endif
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
default:
|
1999-12-15 05:02:16 +03:00
|
|
|
break; /* fall through to the os-specific code below */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2000-01-08 04:52:42 +03:00
|
|
|
if (!raidPtr->valid)
|
1999-02-05 03:06:06 +03:00
|
|
|
return (EINVAL);
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
/*
|
|
|
|
* Add support for "regular" device ioctls here.
|
|
|
|
*/
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
switch (cmd) {
|
|
|
|
case DIOCGDINFO:
|
1999-02-05 03:06:06 +03:00
|
|
|
*(struct disklabel *) data = *(rs->sc_dkdev.dk_label);
|
1998-11-13 07:20:26 +03:00
|
|
|
break;
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDINFO:
|
|
|
|
newlabel = *(rs->sc_dkdev.dk_label);
|
|
|
|
if (newlabel.d_npartitions > OLDMAXPARTITIONS)
|
2001-01-08 05:03:45 +03:00
|
|
|
return ENOTTY;
|
2001-01-07 21:09:01 +03:00
|
|
|
memcpy(data, &newlabel, sizeof (struct olddisklabel));
|
|
|
|
break;
|
|
|
|
#endif
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
case DIOCGPART:
|
1999-02-05 03:06:06 +03:00
|
|
|
((struct partinfo *) data)->disklab = rs->sc_dkdev.dk_label;
|
|
|
|
((struct partinfo *) data)->part =
|
1998-11-13 07:20:26 +03:00
|
|
|
&rs->sc_dkdev.dk_label->d_partitions[DISKPART(dev)];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCWDINFO:
|
|
|
|
case ODIOCSDINFO:
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct disklabel *lp;
|
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) {
|
|
|
|
memset(&newlabel, 0, sizeof newlabel);
|
|
|
|
memcpy(&newlabel, data, sizeof (struct olddisklabel));
|
|
|
|
lp = &newlabel;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
lp = (struct disklabel *)data;
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
if ((error = raidlock(rs)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
rs->sc_flags |= RAIDF_LABELLING;
|
|
|
|
|
|
|
|
error = setdisklabel(rs->sc_dkdev.dk_label,
|
2001-01-07 21:09:01 +03:00
|
|
|
lp, 0, rs->sc_dkdev.dk_cpulabel);
|
1998-11-13 07:20:26 +03:00
|
|
|
if (error == 0) {
|
2001-01-07 21:09:01 +03:00
|
|
|
if (cmd == DIOCWDINFO
|
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
|| cmd == ODIOCWDINFO
|
|
|
|
#endif
|
|
|
|
)
|
1998-11-13 07:20:26 +03:00
|
|
|
error = writedisklabel(RAIDLABELDEV(dev),
|
|
|
|
raidstrategy, rs->sc_dkdev.dk_label,
|
|
|
|
rs->sc_dkdev.dk_cpulabel);
|
|
|
|
}
|
|
|
|
rs->sc_flags &= ~RAIDF_LABELLING;
|
|
|
|
|
|
|
|
raidunlock(rs);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
break;
|
2001-01-07 21:09:01 +03:00
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
case DIOCWLABEL:
|
1999-02-05 03:06:06 +03:00
|
|
|
if (*(int *) data != 0)
|
1998-11-13 07:20:26 +03:00
|
|
|
rs->sc_flags |= RAIDF_WLABEL;
|
|
|
|
else
|
|
|
|
rs->sc_flags &= ~RAIDF_WLABEL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCGDEFLABEL:
|
2001-01-07 21:09:01 +03:00
|
|
|
raidgetdefaultlabel(raidPtr, rs, (struct disklabel *) data);
|
1998-11-13 07:20:26 +03:00
|
|
|
break;
|
|
|
|
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDEFLABEL:
|
|
|
|
raidgetdefaultlabel(raidPtr, rs, &newlabel);
|
|
|
|
if (newlabel.d_npartitions > OLDMAXPARTITIONS)
|
2001-01-08 05:03:45 +03:00
|
|
|
return ENOTTY;
|
2001-01-07 21:09:01 +03:00
|
|
|
memcpy(data, &newlabel, sizeof (struct olddisklabel));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
default:
|
2000-01-06 05:06:41 +03:00
|
|
|
retcode = ENOTTY;
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
return (retcode);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* raidinit -- complete the rest of the initialization for the
|
1998-11-13 07:20:26 +03:00
|
|
|
RAIDframe device. */
|
|
|
|
|
|
|
|
|
2000-02-25 05:42:30 +03:00
|
|
|
static void
|
|
|
|
raidinit(raidPtr)
|
1998-11-13 07:20:26 +03:00
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
{
|
|
|
|
struct raid_softc *rs;
|
2000-02-25 05:42:30 +03:00
|
|
|
int unit;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
2000-02-25 05:42:30 +03:00
|
|
|
unit = raidPtr->raidid;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
rs = &raid_softc[unit];
|
|
|
|
|
|
|
|
/* XXX should check return code first... */
|
|
|
|
rs->sc_flags |= RAIDF_INITED;
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
sprintf(rs->sc_xname, "raid%d", unit); /* XXX doesn't check bounds. */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
rs->sc_dkdev.dk_name = rs->sc_xname;
|
1999-02-24 02:57:53 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
/* disk_attach actually creates space for the CPU disklabel, among
|
1999-02-05 03:06:06 +03:00
|
|
|
* other things, so it's critical to call this *BEFORE* we try putzing
|
|
|
|
* with disklabels. */
|
1999-02-24 02:57:53 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
disk_attach(&rs->sc_dkdev);
|
|
|
|
|
|
|
|
/* XXX There may be a weird interaction here between this, and
|
1999-02-05 03:06:06 +03:00
|
|
|
* protectedSectors, as used in RAIDframe. */
|
1999-02-24 02:57:53 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
rs->sc_size = raidPtr->totalSectors;
|
1999-02-24 02:57:53 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* wake up the daemon & tell it to get us a spare table
|
|
|
|
* XXX
|
1999-02-05 03:06:06 +03:00
|
|
|
* the entries in the queues should be tagged with the raidPtr
|
1999-02-24 02:57:53 +03:00
|
|
|
* so that in the extremely rare case that two recons happen at once,
|
|
|
|
* we know for which device were requesting a spare table
|
1998-11-13 07:20:26 +03:00
|
|
|
* XXX
|
2000-01-06 05:06:41 +03:00
|
|
|
*
|
|
|
|
* XXX This code is not currently used. GO
|
1998-11-13 07:20:26 +03:00
|
|
|
*/
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_GetSpareTableFromDaemon(req)
|
|
|
|
RF_SparetWait_t *req;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int retcode;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_LOCK_MUTEX(rf_sparet_wait_mutex);
|
|
|
|
req->next = rf_sparet_wait_queue;
|
|
|
|
rf_sparet_wait_queue = req;
|
|
|
|
wakeup(&rf_sparet_wait_queue);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* mpsleep unlocks the mutex */
|
|
|
|
while (!rf_sparet_resp_queue) {
|
1999-03-15 00:53:31 +03:00
|
|
|
tsleep(&rf_sparet_resp_queue, PRIBIO,
|
1999-02-05 03:06:06 +03:00
|
|
|
"raidframe getsparetable", 0);
|
|
|
|
}
|
|
|
|
req = rf_sparet_resp_queue;
|
|
|
|
rf_sparet_resp_queue = req->next;
|
|
|
|
RF_UNLOCK_MUTEX(rf_sparet_wait_mutex);
|
|
|
|
|
|
|
|
retcode = req->fcol;
|
|
|
|
RF_Free(req, sizeof(*req)); /* this is not the same req as we
|
|
|
|
* alloc'd */
|
|
|
|
return (retcode);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
2000-01-06 05:06:41 +03:00
|
|
|
|
1999-02-24 02:57:53 +03:00
|
|
|
/* a wrapper around rf_DoAccess that extracts appropriate info from the
|
|
|
|
* bp & passes it down.
|
1998-11-13 07:20:26 +03:00
|
|
|
* any calls originating in the kernel must use non-blocking I/O
|
|
|
|
* do some extra sanity checking to return "appropriate" error values for
|
|
|
|
* certain conditions (to make some standard utilities work)
|
1999-12-12 23:51:41 +03:00
|
|
|
*
|
|
|
|
* Formerly known as: rf_DoAccessKernel
|
1998-11-13 07:20:26 +03:00
|
|
|
*/
|
1999-12-12 23:51:41 +03:00
|
|
|
void
|
|
|
|
raidstart(raidPtr)
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_Raid_t *raidPtr;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
|
|
|
RF_SectorCount_t num_blocks, pb, sum;
|
|
|
|
RF_RaidAddr_t raid_addr;
|
1999-02-05 03:06:06 +03:00
|
|
|
int retcode;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct partition *pp;
|
1999-02-05 03:06:06 +03:00
|
|
|
daddr_t blocknum;
|
|
|
|
int unit;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct raid_softc *rs;
|
1999-02-05 03:06:06 +03:00
|
|
|
int do_async;
|
1999-12-12 23:51:41 +03:00
|
|
|
struct buf *bp;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
unit = raidPtr->raidid;
|
|
|
|
rs = &raid_softc[unit];
|
1999-12-12 23:51:41 +03:00
|
|
|
|
2000-02-23 06:44:02 +03:00
|
|
|
/* quick check to see if anything has died recently */
|
|
|
|
RF_LOCK_MUTEX(raidPtr->mutex);
|
|
|
|
if (raidPtr->numNewFailures > 0) {
|
2000-06-04 06:05:13 +04:00
|
|
|
rf_update_component_labels(raidPtr,
|
|
|
|
RF_NORMAL_COMPONENT_UPDATE);
|
2000-02-23 06:44:02 +03:00
|
|
|
raidPtr->numNewFailures--;
|
|
|
|
}
|
|
|
|
|
1999-12-12 23:51:41 +03:00
|
|
|
/* Check to see if we're at the limit... */
|
|
|
|
while (raidPtr->openings > 0) {
|
|
|
|
RF_UNLOCK_MUTEX(raidPtr->mutex);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-12-12 23:51:41 +03:00
|
|
|
/* get the next item, if any, from the queue */
|
2002-07-20 20:30:18 +04:00
|
|
|
if ((bp = BUFQ_GET(&rs->buf_queue)) == NULL) {
|
1999-12-12 23:51:41 +03:00
|
|
|
/* nothing more to do */
|
|
|
|
return;
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-12-12 23:51:41 +03:00
|
|
|
/* Ok, for the bp we have here, bp->b_blkno is relative to the
|
|
|
|
* partition.. Need to make it absolute to the underlying
|
|
|
|
* device.. */
|
1999-07-08 04:45:23 +04:00
|
|
|
|
1999-12-12 23:51:41 +03:00
|
|
|
blocknum = bp->b_blkno;
|
|
|
|
if (DISKPART(bp->b_dev) != RAW_PART) {
|
|
|
|
pp = &rs->sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)];
|
|
|
|
blocknum += pp->p_offset;
|
|
|
|
}
|
1999-07-08 04:45:23 +04:00
|
|
|
|
1999-12-12 23:51:41 +03:00
|
|
|
db1_printf(("Blocks: %d, %d\n", (int) bp->b_blkno,
|
|
|
|
(int) blocknum));
|
|
|
|
|
|
|
|
db1_printf(("bp->b_bcount = %d\n", (int) bp->b_bcount));
|
|
|
|
db1_printf(("bp->b_resid = %d\n", (int) bp->b_resid));
|
|
|
|
|
|
|
|
/* *THIS* is where we adjust what block we're going to...
|
|
|
|
* but DO NOT TOUCH bp->b_blkno!!! */
|
|
|
|
raid_addr = blocknum;
|
|
|
|
|
|
|
|
num_blocks = bp->b_bcount >> raidPtr->logBytesPerSector;
|
|
|
|
pb = (bp->b_bcount & raidPtr->sectorMask) ? 1 : 0;
|
|
|
|
sum = raid_addr + num_blocks + pb;
|
|
|
|
if (1 || rf_debugKernelAccess) {
|
|
|
|
db1_printf(("raid_addr=%d sum=%d num_blocks=%d(+%d) (%d)\n",
|
|
|
|
(int) raid_addr, (int) sum, (int) num_blocks,
|
|
|
|
(int) pb, (int) bp->b_resid));
|
|
|
|
}
|
|
|
|
if ((sum > raidPtr->totalSectors) || (sum < raid_addr)
|
|
|
|
|| (sum < num_blocks) || (sum < pb)) {
|
|
|
|
bp->b_error = ENOSPC;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
RF_LOCK_MUTEX(raidPtr->mutex);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX rf_DoAccess() should do this, not just DoAccessKernel()
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (bp->b_bcount & raidPtr->sectorMask) {
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
RF_LOCK_MUTEX(raidPtr->mutex);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
db1_printf(("Calling DoAccess..\n"));
|
|
|
|
|
1999-07-08 04:45:23 +04:00
|
|
|
|
1999-12-12 23:51:41 +03:00
|
|
|
RF_LOCK_MUTEX(raidPtr->mutex);
|
|
|
|
raidPtr->openings--;
|
1999-07-08 04:45:23 +04:00
|
|
|
RF_UNLOCK_MUTEX(raidPtr->mutex);
|
1999-12-12 23:51:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Everything is async.
|
|
|
|
*/
|
|
|
|
do_async = 1;
|
|
|
|
|
2000-10-20 06:24:45 +04:00
|
|
|
disk_busy(&rs->sc_dkdev);
|
|
|
|
|
1999-12-12 23:51:41 +03:00
|
|
|
/* XXX we're still at splbio() here... do we *really*
|
|
|
|
need to be? */
|
|
|
|
|
2000-10-20 06:24:45 +04:00
|
|
|
/* don't ever condition on bp->b_flags & B_WRITE.
|
|
|
|
* always condition on B_READ instead */
|
2000-01-05 05:57:28 +03:00
|
|
|
|
1999-12-12 23:51:41 +03:00
|
|
|
retcode = rf_DoAccess(raidPtr, (bp->b_flags & B_READ) ?
|
|
|
|
RF_IO_TYPE_READ : RF_IO_TYPE_WRITE,
|
|
|
|
do_async, raid_addr, num_blocks,
|
2001-07-27 07:30:07 +04:00
|
|
|
bp->b_data, bp, RF_DAG_NONBLOCKING_IO);
|
1999-12-12 23:51:41 +03:00
|
|
|
|
1999-07-08 04:45:23 +04:00
|
|
|
RF_LOCK_MUTEX(raidPtr->mutex);
|
|
|
|
}
|
|
|
|
RF_UNLOCK_MUTEX(raidPtr->mutex);
|
1999-12-12 23:51:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-08 04:45:23 +04:00
|
|
|
|
1999-01-15 20:55:52 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
/* invoke an I/O from kernel mode. Disk queue should be locked upon entry */
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_DispatchKernelIO(queue, req)
|
|
|
|
RF_DiskQueue_t *queue;
|
|
|
|
RF_DiskQueueData_t *req;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int op = (req->type == RF_IO_TYPE_READ) ? B_READ : B_WRITE;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct buf *bp;
|
1999-02-05 03:06:06 +03:00
|
|
|
struct raidbuf *raidbp = NULL;
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
req->queue = queue;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
2002-09-22 07:44:42 +04:00
|
|
|
#if DIAGNOSTIC
|
|
|
|
if (queue->raidPtr->raidid >= numraid) {
|
2002-09-23 07:17:36 +04:00
|
|
|
printf("Invalid unit number: %d %d\n", queue->raidPtr->raidid,
|
|
|
|
numraid);
|
1998-11-13 07:20:26 +03:00
|
|
|
panic("Invalid Unit number in rf_DispatchKernelIO\n");
|
|
|
|
}
|
2002-09-22 07:44:42 +04:00
|
|
|
#endif
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
bp = req->bp;
|
1999-03-27 04:26:37 +03:00
|
|
|
#if 1
|
1999-02-05 03:06:06 +03:00
|
|
|
/* XXX when there is a physical disk failure, someone is passing us a
|
|
|
|
* buffer that contains old stuff!! Attempt to deal with this problem
|
|
|
|
* without taking a performance hit... (not sure where the real bug
|
|
|
|
* is. It's buried in RAIDframe somewhere) :-( GO ) */
|
1998-12-03 18:14:40 +03:00
|
|
|
|
|
|
|
if (bp->b_flags & B_ERROR) {
|
|
|
|
bp->b_flags &= ~B_ERROR;
|
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
if (bp->b_error != 0) {
|
1998-12-03 18:14:40 +03:00
|
|
|
bp->b_error = 0;
|
|
|
|
}
|
1999-03-27 04:26:37 +03:00
|
|
|
#endif
|
2002-09-22 07:56:08 +04:00
|
|
|
raidbp = pool_get(&raidframe_cbufpool, PR_NOWAIT);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* context for raidiodone
|
|
|
|
*/
|
|
|
|
raidbp->rf_obp = bp;
|
|
|
|
raidbp->req = req;
|
|
|
|
|
1999-12-03 05:43:22 +03:00
|
|
|
LIST_INIT(&raidbp->rf_buf.b_dep);
|
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
switch (req->type) {
|
1999-02-05 03:06:06 +03:00
|
|
|
case RF_IO_TYPE_NOP: /* used primarily to unlock a locked queue */
|
1998-11-13 07:20:26 +03:00
|
|
|
/* XXX need to do something extra here.. */
|
1999-02-05 03:06:06 +03:00
|
|
|
/* I'm leaving this in, as I've never actually seen it used,
|
|
|
|
* and I'd like folks to report it... GO */
|
1998-11-13 07:20:26 +03:00
|
|
|
printf(("WAKEUP CALLED\n"));
|
|
|
|
queue->numOutstanding++;
|
|
|
|
|
|
|
|
/* XXX need to glue the original buffer into this?? */
|
|
|
|
|
|
|
|
KernelWakeupFunc(&raidbp->rf_buf);
|
|
|
|
break;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
case RF_IO_TYPE_READ:
|
|
|
|
case RF_IO_TYPE_WRITE:
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
if (req->tracerec) {
|
|
|
|
RF_ETIMER_START(req->tracerec->timer);
|
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
InitBP(&raidbp->rf_buf, queue->rf_cinfo->ci_vp,
|
|
|
|
op | bp->b_flags, queue->rf_cinfo->ci_dev,
|
|
|
|
req->sectorOffset, req->numSector,
|
|
|
|
req->buf, KernelWakeupFunc, (void *) req,
|
|
|
|
queue->raidPtr->logBytesPerSector, req->b_proc);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
if (rf_debugKernelAccess) {
|
1999-02-05 03:06:06 +03:00
|
|
|
db1_printf(("dispatch: bp->b_blkno = %ld\n",
|
|
|
|
(long) bp->b_blkno));
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
queue->numOutstanding++;
|
|
|
|
queue->last_deq_sector = req->sectorOffset;
|
1999-02-05 03:06:06 +03:00
|
|
|
/* acc wouldn't have been let in if there were any pending
|
|
|
|
* reqs at any other priority */
|
1998-11-13 07:20:26 +03:00
|
|
|
queue->curPriority = req->priority;
|
|
|
|
|
|
|
|
db1_printf(("Going for %c to unit %d row %d col %d\n",
|
2002-09-22 07:44:42 +04:00
|
|
|
req->type, queue->raidPtr->raidid,
|
|
|
|
queue->row, queue->col));
|
1998-11-13 07:20:26 +03:00
|
|
|
db1_printf(("sector %d count %d (%d bytes) %d\n",
|
1999-02-05 03:06:06 +03:00
|
|
|
(int) req->sectorOffset, (int) req->numSector,
|
|
|
|
(int) (req->numSector <<
|
|
|
|
queue->raidPtr->logBytesPerSector),
|
|
|
|
(int) queue->raidPtr->logBytesPerSector));
|
1998-11-13 07:20:26 +03:00
|
|
|
if ((raidbp->rf_buf.b_flags & B_READ) == 0) {
|
|
|
|
raidbp->rf_buf.b_vp->v_numoutput++;
|
|
|
|
}
|
|
|
|
VOP_STRATEGY(&raidbp->rf_buf);
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
break;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1998-11-13 07:20:26 +03:00
|
|
|
default:
|
|
|
|
panic("bad req->type in rf_DispatchKernelIO");
|
|
|
|
}
|
|
|
|
db1_printf(("Exiting from DispatchKernelIO\n"));
|
2002-09-22 07:44:42 +04:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
return (0);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
/* this is the callback function associated with a I/O invoked from
|
1998-11-13 07:20:26 +03:00
|
|
|
kernel code.
|
|
|
|
*/
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
|
|
|
KernelWakeupFunc(vbp)
|
|
|
|
struct buf *vbp;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_DiskQueueData_t *req = NULL;
|
|
|
|
RF_DiskQueue_t *queue;
|
|
|
|
struct raidbuf *raidbp = (struct raidbuf *) vbp;
|
|
|
|
struct buf *bp;
|
2000-03-30 16:41:09 +04:00
|
|
|
int s;
|
1999-02-05 03:06:06 +03:00
|
|
|
|
1999-12-15 05:02:16 +03:00
|
|
|
s = splbio();
|
1999-02-05 03:06:06 +03:00
|
|
|
db1_printf(("recovering the request queue:\n"));
|
|
|
|
req = raidbp->req;
|
|
|
|
|
|
|
|
bp = raidbp->rf_obp;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
queue = (RF_DiskQueue_t *) req->queue;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
if (raidbp->rf_buf.b_flags & B_ERROR) {
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = raidbp->rf_buf.b_error ?
|
|
|
|
raidbp->rf_buf.b_error : EIO;
|
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* XXX methinks this could be wrong... */
|
1998-11-13 07:20:26 +03:00
|
|
|
#if 1
|
1999-02-05 03:06:06 +03:00
|
|
|
bp->b_resid = raidbp->rf_buf.b_resid;
|
1998-11-13 07:20:26 +03:00
|
|
|
#endif
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
if (req->tracerec) {
|
|
|
|
RF_ETIMER_STOP(req->tracerec->timer);
|
|
|
|
RF_ETIMER_EVAL(req->tracerec->timer);
|
|
|
|
RF_LOCK_MUTEX(rf_tracing_mutex);
|
|
|
|
req->tracerec->diskwait_us += RF_ETIMER_VAL_US(req->tracerec->timer);
|
|
|
|
req->tracerec->phys_io_us += RF_ETIMER_VAL_US(req->tracerec->timer);
|
|
|
|
req->tracerec->num_phys_ios++;
|
|
|
|
RF_UNLOCK_MUTEX(rf_tracing_mutex);
|
|
|
|
}
|
|
|
|
bp->b_bcount = raidbp->rf_buf.b_bcount; /* XXXX ?? */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* XXX Ok, let's get aggressive... If B_ERROR is set, let's go
|
|
|
|
* ballistic, and mark the component as hosed... */
|
1999-12-15 05:02:16 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
if (bp->b_flags & B_ERROR) {
|
|
|
|
/* Mark the disk as dead */
|
|
|
|
/* but only mark it once... */
|
|
|
|
if (queue->raidPtr->Disks[queue->row][queue->col].status ==
|
|
|
|
rf_ds_optimal) {
|
|
|
|
printf("raid%d: IO Error. Marking %s as failed.\n",
|
2002-09-22 07:56:08 +04:00
|
|
|
queue->raidPtr->raidid,
|
|
|
|
queue->raidPtr->Disks[queue->row][queue->col].devname);
|
1999-02-05 03:06:06 +03:00
|
|
|
queue->raidPtr->Disks[queue->row][queue->col].status =
|
|
|
|
rf_ds_failed;
|
|
|
|
queue->raidPtr->status[queue->row] = rf_rs_degraded;
|
|
|
|
queue->raidPtr->numFailures++;
|
2000-02-23 06:44:02 +03:00
|
|
|
queue->raidPtr->numNewFailures++;
|
1999-02-05 03:06:06 +03:00
|
|
|
} else { /* Disk is already dead... */
|
|
|
|
/* printf("Disk already marked as dead!\n"); */
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
1998-12-03 18:14:40 +03:00
|
|
|
|
2002-09-22 07:56:08 +04:00
|
|
|
pool_put(&raidframe_cbufpool, raidbp);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
rf_DiskIOComplete(queue, req, (bp->b_flags & B_ERROR) ? 1 : 0);
|
|
|
|
(req->CompleteFunc) (req->argument, (bp->b_flags & B_ERROR) ? 1 : 0);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-12-15 05:02:16 +03:00
|
|
|
splx(s);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize a buf structure for doing an I/O in the kernel.
|
|
|
|
*/
|
1999-02-05 03:06:06 +03:00
|
|
|
static void
|
2000-03-07 06:09:47 +03:00
|
|
|
InitBP(bp, b_vp, rw_flag, dev, startSect, numSect, buf, cbFunc, cbArg,
|
|
|
|
logBytesPerSector, b_proc)
|
|
|
|
struct buf *bp;
|
|
|
|
struct vnode *b_vp;
|
|
|
|
unsigned rw_flag;
|
|
|
|
dev_t dev;
|
|
|
|
RF_SectorNum_t startSect;
|
|
|
|
RF_SectorCount_t numSect;
|
|
|
|
caddr_t buf;
|
|
|
|
void (*cbFunc) (struct buf *);
|
|
|
|
void *cbArg;
|
|
|
|
int logBytesPerSector;
|
|
|
|
struct proc *b_proc;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
/* bp->b_flags = B_PHYS | rw_flag; */
|
|
|
|
bp->b_flags = B_CALL | rw_flag; /* XXX need B_PHYS here too??? */
|
|
|
|
bp->b_bcount = numSect << logBytesPerSector;
|
|
|
|
bp->b_bufsize = bp->b_bcount;
|
|
|
|
bp->b_error = 0;
|
|
|
|
bp->b_dev = dev;
|
2000-05-19 22:54:22 +04:00
|
|
|
bp->b_data = buf;
|
1999-02-05 03:06:06 +03:00
|
|
|
bp->b_blkno = startSect;
|
|
|
|
bp->b_resid = bp->b_bcount; /* XXX is this right!??!?!! */
|
1998-11-13 07:20:26 +03:00
|
|
|
if (bp->b_bcount == 0) {
|
|
|
|
panic("bp->b_bcount is zero in InitBP!!\n");
|
|
|
|
}
|
1999-02-05 03:06:06 +03:00
|
|
|
bp->b_proc = b_proc;
|
|
|
|
bp->b_iodone = cbFunc;
|
|
|
|
bp->b_vp = b_vp;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
}
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
raidgetdefaultlabel(raidPtr, rs, lp)
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
struct raid_softc *rs;
|
|
|
|
struct disklabel *lp;
|
|
|
|
{
|
|
|
|
db1_printf(("Building a default label...\n"));
|
2001-07-18 10:45:33 +04:00
|
|
|
memset(lp, 0, sizeof(*lp));
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
/* fabricate a label... */
|
|
|
|
lp->d_secperunit = raidPtr->totalSectors;
|
|
|
|
lp->d_secsize = raidPtr->bytesPerSector;
|
2000-01-09 05:56:13 +03:00
|
|
|
lp->d_nsectors = raidPtr->Layout.dataSectorsPerStripe;
|
2001-04-05 06:48:51 +04:00
|
|
|
lp->d_ntracks = 4 * raidPtr->numCol;
|
2000-01-09 05:56:13 +03:00
|
|
|
lp->d_ncylinders = raidPtr->totalSectors /
|
|
|
|
(lp->d_nsectors * lp->d_ntracks);
|
1998-11-13 07:20:26 +03:00
|
|
|
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
|
|
|
|
|
|
|
strncpy(lp->d_typename, "raid", sizeof(lp->d_typename));
|
1999-02-05 03:06:06 +03:00
|
|
|
lp->d_type = DTYPE_RAID;
|
1998-11-13 07:20:26 +03:00
|
|
|
strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
|
|
|
|
lp->d_rpm = 3600;
|
|
|
|
lp->d_interleave = 1;
|
|
|
|
lp->d_flags = 0;
|
|
|
|
|
|
|
|
lp->d_partitions[RAW_PART].p_offset = 0;
|
|
|
|
lp->d_partitions[RAW_PART].p_size = raidPtr->totalSectors;
|
|
|
|
lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
|
|
|
|
lp->d_npartitions = RAW_PART + 1;
|
|
|
|
|
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
|
|
|
lp->d_checksum = dkcksum(rs->sc_dkdev.dk_label);
|
|
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Read the disklabel from the raid device. If one is not present, fake one
|
|
|
|
* up.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
raidgetdisklabel(dev)
|
1999-02-05 03:06:06 +03:00
|
|
|
dev_t dev;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int unit = raidunit(dev);
|
1998-11-13 07:20:26 +03:00
|
|
|
struct raid_softc *rs = &raid_softc[unit];
|
1999-02-05 03:06:06 +03:00
|
|
|
char *errstring;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct disklabel *lp = rs->sc_dkdev.dk_label;
|
|
|
|
struct cpu_disklabel *clp = rs->sc_dkdev.dk_cpulabel;
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
|
|
|
|
db1_printf(("Getting the disklabel...\n"));
|
|
|
|
|
2001-07-18 10:45:33 +04:00
|
|
|
memset(clp, 0, sizeof(*clp));
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
raidPtr = raidPtrs[unit];
|
|
|
|
|
|
|
|
raidgetdefaultlabel(raidPtr, rs, lp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the generic disklabel extraction routine.
|
|
|
|
*/
|
|
|
|
errstring = readdisklabel(RAIDLABELDEV(dev), raidstrategy,
|
|
|
|
rs->sc_dkdev.dk_label, rs->sc_dkdev.dk_cpulabel);
|
1999-02-05 03:06:06 +03:00
|
|
|
if (errstring)
|
1998-11-13 07:20:26 +03:00
|
|
|
raidmakedisklabel(rs);
|
|
|
|
else {
|
1999-02-05 03:06:06 +03:00
|
|
|
int i;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct partition *pp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity check whether the found disklabel is valid.
|
|
|
|
*
|
|
|
|
* This is necessary since total size of the raid device
|
|
|
|
* may vary when an interleave is changed even though exactly
|
|
|
|
* same componets are used, and old disklabel may used
|
|
|
|
* if that is found.
|
|
|
|
*/
|
|
|
|
if (lp->d_secperunit != rs->sc_size)
|
2002-07-13 21:24:41 +04:00
|
|
|
printf("raid%d: WARNING: %s: "
|
1998-11-13 07:20:26 +03:00
|
|
|
"total sector size in disklabel (%d) != "
|
2002-07-13 21:24:41 +04:00
|
|
|
"the size of raid (%ld)\n", unit, rs->sc_xname,
|
1999-04-12 23:39:59 +04:00
|
|
|
lp->d_secperunit, (long) rs->sc_size);
|
1998-11-13 07:20:26 +03:00
|
|
|
for (i = 0; i < lp->d_npartitions; i++) {
|
|
|
|
pp = &lp->d_partitions[i];
|
|
|
|
if (pp->p_offset + pp->p_size > rs->sc_size)
|
2002-07-13 21:24:41 +04:00
|
|
|
printf("raid%d: WARNING: %s: end of partition `%c' "
|
|
|
|
"exceeds the size of raid (%ld)\n",
|
|
|
|
unit, rs->sc_xname, 'a' + i, (long) rs->sc_size);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Take care of things one might want to take care of in the event
|
|
|
|
* that a disklabel isn't present.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
raidmakedisklabel(rs)
|
|
|
|
struct raid_softc *rs;
|
|
|
|
{
|
|
|
|
struct disklabel *lp = rs->sc_dkdev.dk_label;
|
|
|
|
db1_printf(("Making a label..\n"));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For historical reasons, if there's no disklabel present
|
|
|
|
* the raw partition must be marked FS_BSDFFS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
lp->d_partitions[RAW_PART].p_fstype = FS_BSDFFS;
|
|
|
|
|
|
|
|
strncpy(lp->d_packname, "default label", sizeof(lp->d_packname));
|
|
|
|
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Lookup the provided name in the filesystem. If the file exists,
|
|
|
|
* is a valid block device, and isn't being used by anyone else,
|
|
|
|
* set *vpp to the file's vnode.
|
1999-02-05 03:06:06 +03:00
|
|
|
* You'll find the original of this in ccd.c
|
1998-11-13 07:20:26 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
raidlookup(path, p, vpp)
|
1999-02-05 03:06:06 +03:00
|
|
|
char *path;
|
1998-11-13 07:20:26 +03:00
|
|
|
struct proc *p;
|
|
|
|
struct vnode **vpp; /* result */
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct vattr va;
|
1999-02-05 03:06:06 +03:00
|
|
|
int error;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path, p);
|
1999-02-05 03:06:06 +03:00
|
|
|
if ((error = vn_open(&nd, FREAD | FWRITE, 0)) != 0) {
|
2002-07-13 21:24:41 +04:00
|
|
|
#if 0
|
1999-02-05 03:06:06 +03:00
|
|
|
printf("RAIDframe: vn_open returned %d\n", error);
|
1998-11-13 07:20:26 +03:00
|
|
|
#endif
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
vp = nd.ni_vp;
|
|
|
|
if (vp->v_usecount > 1) {
|
|
|
|
VOP_UNLOCK(vp, 0);
|
1999-02-05 03:06:06 +03:00
|
|
|
(void) vn_close(vp, FREAD | FWRITE, p->p_ucred, p);
|
1998-11-13 07:20:26 +03:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)) != 0) {
|
|
|
|
VOP_UNLOCK(vp, 0);
|
1999-02-05 03:06:06 +03:00
|
|
|
(void) vn_close(vp, FREAD | FWRITE, p->p_ucred, p);
|
1998-11-13 07:20:26 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
/* XXX: eventually we should handle VREG, too. */
|
|
|
|
if (va.va_type != VBLK) {
|
|
|
|
VOP_UNLOCK(vp, 0);
|
1999-02-05 03:06:06 +03:00
|
|
|
(void) vn_close(vp, FREAD | FWRITE, p->p_ucred, p);
|
1998-11-13 07:20:26 +03:00
|
|
|
return (ENOTBLK);
|
|
|
|
}
|
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Wait interruptibly for an exclusive lock.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* Several drivers do this; it should be abstracted and made MP-safe.
|
|
|
|
* (Hmm... where have we seen this warning before :-> GO )
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
raidlock(rs)
|
|
|
|
struct raid_softc *rs;
|
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int error;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
while ((rs->sc_flags & RAIDF_LOCKED) != 0) {
|
|
|
|
rs->sc_flags |= RAIDF_WANTED;
|
1999-02-05 03:06:06 +03:00
|
|
|
if ((error =
|
|
|
|
tsleep(rs, PRIBIO | PCATCH, "raidlck", 0)) != 0)
|
1998-11-13 07:20:26 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
rs->sc_flags |= RAIDF_LOCKED;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Unlock and wake up any waiters.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
raidunlock(rs)
|
|
|
|
struct raid_softc *rs;
|
|
|
|
{
|
|
|
|
|
|
|
|
rs->sc_flags &= ~RAIDF_LOCKED;
|
|
|
|
if ((rs->sc_flags & RAIDF_WANTED) != 0) {
|
|
|
|
rs->sc_flags &= ~RAIDF_WANTED;
|
|
|
|
wakeup(rs);
|
|
|
|
}
|
|
|
|
}
|
1999-02-24 02:57:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
#define RF_COMPONENT_INFO_OFFSET 16384 /* bytes */
|
|
|
|
#define RF_COMPONENT_INFO_SIZE 1024 /* bytes */
|
|
|
|
|
|
|
|
int
|
1999-03-02 06:18:48 +03:00
|
|
|
raidmarkclean(dev_t dev, struct vnode *b_vp, int mod_counter)
|
|
|
|
{
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t clabel;
|
|
|
|
raidread_component_label(dev, b_vp, &clabel);
|
|
|
|
clabel.mod_counter = mod_counter;
|
|
|
|
clabel.clean = RF_RAID_CLEAN;
|
|
|
|
raidwrite_component_label(dev, b_vp, &clabel);
|
1999-03-02 06:18:48 +03:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
raidmarkdirty(dev_t dev, struct vnode *b_vp, int mod_counter)
|
1999-02-24 02:57:53 +03:00
|
|
|
{
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t clabel;
|
|
|
|
raidread_component_label(dev, b_vp, &clabel);
|
|
|
|
clabel.mod_counter = mod_counter;
|
|
|
|
clabel.clean = RF_RAID_DIRTY;
|
|
|
|
raidwrite_component_label(dev, b_vp, &clabel);
|
1999-02-24 02:57:53 +03:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2000-02-13 07:53:57 +03:00
|
|
|
raidread_component_label(dev, b_vp, clabel)
|
1999-02-24 02:57:53 +03:00
|
|
|
dev_t dev;
|
|
|
|
struct vnode *b_vp;
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t *clabel;
|
1999-02-24 02:57:53 +03:00
|
|
|
{
|
|
|
|
struct buf *bp;
|
2002-09-06 17:18:43 +04:00
|
|
|
const struct bdevsw *bdev;
|
1999-02-24 02:57:53 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/* XXX should probably ensure that we don't try to do this if
|
|
|
|
someone has changed rf_protected_sectors. */
|
|
|
|
|
2000-10-17 07:39:41 +04:00
|
|
|
if (b_vp == NULL) {
|
|
|
|
/* For whatever reason, this component is not valid.
|
|
|
|
Don't try to read a component label from it. */
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
|
1999-02-24 02:57:53 +03:00
|
|
|
/* get a block of the appropriate size... */
|
|
|
|
bp = geteblk((int)RF_COMPONENT_INFO_SIZE);
|
|
|
|
bp->b_dev = dev;
|
|
|
|
|
|
|
|
/* get our ducks in a row for the read */
|
|
|
|
bp->b_blkno = RF_COMPONENT_INFO_OFFSET / DEV_BSIZE;
|
|
|
|
bp->b_bcount = RF_COMPONENT_INFO_SIZE;
|
2000-11-20 11:24:08 +03:00
|
|
|
bp->b_flags |= B_READ;
|
1999-02-24 02:57:53 +03:00
|
|
|
bp->b_resid = RF_COMPONENT_INFO_SIZE / DEV_BSIZE;
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
bdev = bdevsw_lookup(bp->b_dev);
|
|
|
|
if (bdev == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
(*bdev->d_strategy)(bp);
|
1999-02-24 02:57:53 +03:00
|
|
|
|
|
|
|
error = biowait(bp);
|
|
|
|
|
|
|
|
if (!error) {
|
2000-05-19 22:54:22 +04:00
|
|
|
memcpy(clabel, bp->b_data,
|
1999-02-24 02:57:53 +03:00
|
|
|
sizeof(RF_ComponentLabel_t));
|
1999-03-02 06:18:48 +03:00
|
|
|
#if 0
|
2000-03-07 05:12:13 +03:00
|
|
|
rf_print_component_label( clabel );
|
1999-02-24 02:57:53 +03:00
|
|
|
#endif
|
|
|
|
} else {
|
2000-02-13 07:53:57 +03:00
|
|
|
#if 0
|
1999-02-24 02:57:53 +03:00
|
|
|
printf("Failed to read RAID component label!\n");
|
2000-02-13 07:53:57 +03:00
|
|
|
#endif
|
1999-02-24 02:57:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
brelse(bp);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2000-02-13 07:53:57 +03:00
|
|
|
raidwrite_component_label(dev, b_vp, clabel)
|
1999-02-24 02:57:53 +03:00
|
|
|
dev_t dev;
|
|
|
|
struct vnode *b_vp;
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t *clabel;
|
1999-02-24 02:57:53 +03:00
|
|
|
{
|
|
|
|
struct buf *bp;
|
2002-09-06 17:18:43 +04:00
|
|
|
const struct bdevsw *bdev;
|
1999-02-24 02:57:53 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/* get a block of the appropriate size... */
|
|
|
|
bp = geteblk((int)RF_COMPONENT_INFO_SIZE);
|
|
|
|
bp->b_dev = dev;
|
|
|
|
|
|
|
|
/* get our ducks in a row for the write */
|
|
|
|
bp->b_blkno = RF_COMPONENT_INFO_OFFSET / DEV_BSIZE;
|
|
|
|
bp->b_bcount = RF_COMPONENT_INFO_SIZE;
|
2000-11-20 11:24:08 +03:00
|
|
|
bp->b_flags |= B_WRITE;
|
1999-02-24 02:57:53 +03:00
|
|
|
bp->b_resid = RF_COMPONENT_INFO_SIZE / DEV_BSIZE;
|
|
|
|
|
2000-05-19 22:54:22 +04:00
|
|
|
memset(bp->b_data, 0, RF_COMPONENT_INFO_SIZE );
|
1999-02-24 02:57:53 +03:00
|
|
|
|
2000-05-19 22:54:22 +04:00
|
|
|
memcpy(bp->b_data, clabel, sizeof(RF_ComponentLabel_t));
|
1999-02-24 02:57:53 +03:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
bdev = bdevsw_lookup(bp->b_dev);
|
|
|
|
if (bdev == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
(*bdev->d_strategy)(bp);
|
1999-02-24 02:57:53 +03:00
|
|
|
error = biowait(bp);
|
|
|
|
brelse(bp);
|
|
|
|
if (error) {
|
2000-02-13 07:53:57 +03:00
|
|
|
#if 1
|
1999-02-24 02:57:53 +03:00
|
|
|
printf("Failed to write RAID component info!\n");
|
2000-02-13 07:53:57 +03:00
|
|
|
#endif
|
1999-02-24 02:57:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
1999-03-02 06:18:48 +03:00
|
|
|
|
|
|
|
void
|
2000-03-07 06:09:47 +03:00
|
|
|
rf_markalldirty(raidPtr)
|
1999-03-02 06:18:48 +03:00
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
{
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t clabel;
|
1999-03-02 06:18:48 +03:00
|
|
|
int r,c;
|
|
|
|
|
|
|
|
raidPtr->mod_counter++;
|
|
|
|
for (r = 0; r < raidPtr->numRow; r++) {
|
|
|
|
for (c = 0; c < raidPtr->numCol; c++) {
|
2000-10-17 07:39:41 +04:00
|
|
|
/* we don't want to touch (at all) a disk that has
|
|
|
|
failed */
|
|
|
|
if (!RF_DEAD_DISK(raidPtr->Disks[r][c].status)) {
|
1999-03-02 06:18:48 +03:00
|
|
|
raidread_component_label(
|
|
|
|
raidPtr->Disks[r][c].dev,
|
|
|
|
raidPtr->raid_cinfo[r][c].ci_vp,
|
2000-02-13 07:53:57 +03:00
|
|
|
&clabel);
|
|
|
|
if (clabel.status == rf_ds_spared) {
|
1999-03-02 06:18:48 +03:00
|
|
|
/* XXX do something special...
|
|
|
|
but whatever you do, don't
|
|
|
|
try to access it!! */
|
|
|
|
} else {
|
|
|
|
#if 0
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel.status =
|
1999-03-02 06:18:48 +03:00
|
|
|
raidPtr->Disks[r][c].status;
|
|
|
|
raidwrite_component_label(
|
|
|
|
raidPtr->Disks[r][c].dev,
|
|
|
|
raidPtr->raid_cinfo[r][c].ci_vp,
|
2000-02-13 07:53:57 +03:00
|
|
|
&clabel);
|
1999-03-02 06:18:48 +03:00
|
|
|
#endif
|
|
|
|
raidmarkdirty(
|
|
|
|
raidPtr->Disks[r][c].dev,
|
|
|
|
raidPtr->raid_cinfo[r][c].ci_vp,
|
|
|
|
raidPtr->mod_counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-03-09 05:59:25 +03:00
|
|
|
/* printf("Component labels marked dirty.\n"); */
|
1999-03-02 06:18:48 +03:00
|
|
|
#if 0
|
|
|
|
for( c = 0; c < raidPtr->numSpare ; c++) {
|
|
|
|
sparecol = raidPtr->numCol + c;
|
|
|
|
if (raidPtr->Disks[r][sparecol].status == rf_ds_used_spare) {
|
|
|
|
/*
|
|
|
|
|
|
|
|
XXX this is where we get fancy and map this spare
|
|
|
|
into it's correct spot in the array.
|
|
|
|
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
|
|
|
|
we claim this disk is "optimal" if it's
|
|
|
|
rf_ds_used_spare, as that means it should be
|
|
|
|
directly substitutable for the disk it replaced.
|
|
|
|
We note that too...
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
for(i=0;i<raidPtr->numRow;i++) {
|
|
|
|
for(j=0;j<raidPtr->numCol;j++) {
|
|
|
|
if ((raidPtr->Disks[i][j].spareRow ==
|
|
|
|
r) &&
|
|
|
|
(raidPtr->Disks[i][j].spareCol ==
|
|
|
|
sparecol)) {
|
|
|
|
srow = r;
|
|
|
|
scol = sparecol;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
raidread_component_label(
|
|
|
|
raidPtr->Disks[r][sparecol].dev,
|
|
|
|
raidPtr->raid_cinfo[r][sparecol].ci_vp,
|
2000-02-13 07:53:57 +03:00
|
|
|
&clabel);
|
1999-03-02 06:18:48 +03:00
|
|
|
/* make sure status is noted */
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel.version = RF_COMPONENT_LABEL_VERSION;
|
|
|
|
clabel.mod_counter = raidPtr->mod_counter;
|
|
|
|
clabel.serial_number = raidPtr->serial_number;
|
|
|
|
clabel.row = srow;
|
|
|
|
clabel.column = scol;
|
|
|
|
clabel.num_rows = raidPtr->numRow;
|
|
|
|
clabel.num_columns = raidPtr->numCol;
|
|
|
|
clabel.clean = RF_RAID_DIRTY; /* changed in a bit*/
|
|
|
|
clabel.status = rf_ds_optimal;
|
1999-03-02 06:18:48 +03:00
|
|
|
raidwrite_component_label(
|
|
|
|
raidPtr->Disks[r][sparecol].dev,
|
|
|
|
raidPtr->raid_cinfo[r][sparecol].ci_vp,
|
2000-02-13 07:53:57 +03:00
|
|
|
&clabel);
|
1999-03-02 06:18:48 +03:00
|
|
|
raidmarkclean( raidPtr->Disks[r][sparecol].dev,
|
|
|
|
raidPtr->raid_cinfo[r][sparecol].ci_vp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-03-09 05:59:25 +03:00
|
|
|
|
|
|
|
void
|
2000-06-04 06:05:13 +04:00
|
|
|
rf_update_component_labels(raidPtr, final)
|
1999-03-09 05:59:25 +03:00
|
|
|
RF_Raid_t *raidPtr;
|
2000-06-04 06:05:13 +04:00
|
|
|
int final;
|
1999-03-09 05:59:25 +03:00
|
|
|
{
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t clabel;
|
1999-03-09 05:59:25 +03:00
|
|
|
int sparecol;
|
|
|
|
int r,c;
|
|
|
|
int i,j;
|
|
|
|
int srow, scol;
|
|
|
|
|
|
|
|
srow = -1;
|
|
|
|
scol = -1;
|
|
|
|
|
|
|
|
/* XXX should do extra checks to make sure things really are clean,
|
|
|
|
rather than blindly setting the clean bit... */
|
|
|
|
|
|
|
|
raidPtr->mod_counter++;
|
|
|
|
|
|
|
|
for (r = 0; r < raidPtr->numRow; r++) {
|
|
|
|
for (c = 0; c < raidPtr->numCol; c++) {
|
|
|
|
if (raidPtr->Disks[r][c].status == rf_ds_optimal) {
|
|
|
|
raidread_component_label(
|
|
|
|
raidPtr->Disks[r][c].dev,
|
|
|
|
raidPtr->raid_cinfo[r][c].ci_vp,
|
2000-02-13 07:53:57 +03:00
|
|
|
&clabel);
|
1999-03-09 05:59:25 +03:00
|
|
|
/* make sure status is noted */
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel.status = rf_ds_optimal;
|
2000-02-24 04:23:05 +03:00
|
|
|
/* bump the counter */
|
2000-02-25 22:56:56 +03:00
|
|
|
clabel.mod_counter = raidPtr->mod_counter;
|
2000-02-24 04:23:05 +03:00
|
|
|
|
1999-03-09 05:59:25 +03:00
|
|
|
raidwrite_component_label(
|
|
|
|
raidPtr->Disks[r][c].dev,
|
|
|
|
raidPtr->raid_cinfo[r][c].ci_vp,
|
2000-02-13 07:53:57 +03:00
|
|
|
&clabel);
|
2000-06-04 06:05:13 +04:00
|
|
|
if (final == RF_FINAL_COMPONENT_UPDATE) {
|
|
|
|
if (raidPtr->parity_good == RF_RAID_CLEAN) {
|
|
|
|
raidmarkclean(
|
|
|
|
raidPtr->Disks[r][c].dev,
|
|
|
|
raidPtr->raid_cinfo[r][c].ci_vp,
|
|
|
|
raidPtr->mod_counter);
|
2000-02-27 04:50:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* else we don't touch it.. */
|
1999-03-09 05:59:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( c = 0; c < raidPtr->numSpare ; c++) {
|
|
|
|
sparecol = raidPtr->numCol + c;
|
2001-10-04 19:58:51 +04:00
|
|
|
/* Need to ensure that the reconstruct actually completed! */
|
2001-10-06 04:47:46 +04:00
|
|
|
if (raidPtr->Disks[0][sparecol].status == rf_ds_used_spare) {
|
1999-03-09 05:59:25 +03:00
|
|
|
/*
|
|
|
|
|
|
|
|
we claim this disk is "optimal" if it's
|
|
|
|
rf_ds_used_spare, as that means it should be
|
|
|
|
directly substitutable for the disk it replaced.
|
|
|
|
We note that too...
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
for(i=0;i<raidPtr->numRow;i++) {
|
|
|
|
for(j=0;j<raidPtr->numCol;j++) {
|
|
|
|
if ((raidPtr->Disks[i][j].spareRow ==
|
|
|
|
0) &&
|
|
|
|
(raidPtr->Disks[i][j].spareCol ==
|
|
|
|
sparecol)) {
|
|
|
|
srow = i;
|
|
|
|
scol = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-24 04:23:05 +03:00
|
|
|
/* XXX shouldn't *really* need this... */
|
1999-03-09 05:59:25 +03:00
|
|
|
raidread_component_label(
|
|
|
|
raidPtr->Disks[0][sparecol].dev,
|
|
|
|
raidPtr->raid_cinfo[0][sparecol].ci_vp,
|
2000-02-13 07:53:57 +03:00
|
|
|
&clabel);
|
1999-03-09 05:59:25 +03:00
|
|
|
/* make sure status is noted */
|
2000-02-24 04:23:05 +03:00
|
|
|
|
|
|
|
raid_init_component_label(raidPtr, &clabel);
|
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel.mod_counter = raidPtr->mod_counter;
|
|
|
|
clabel.row = srow;
|
|
|
|
clabel.column = scol;
|
|
|
|
clabel.status = rf_ds_optimal;
|
2000-02-24 04:23:05 +03:00
|
|
|
|
1999-03-09 05:59:25 +03:00
|
|
|
raidwrite_component_label(
|
|
|
|
raidPtr->Disks[0][sparecol].dev,
|
|
|
|
raidPtr->raid_cinfo[0][sparecol].ci_vp,
|
2000-02-13 07:53:57 +03:00
|
|
|
&clabel);
|
2000-06-04 06:05:13 +04:00
|
|
|
if (final == RF_FINAL_COMPONENT_UPDATE) {
|
|
|
|
if (raidPtr->parity_good == RF_RAID_CLEAN) {
|
|
|
|
raidmarkclean( raidPtr->Disks[0][sparecol].dev,
|
|
|
|
raidPtr->raid_cinfo[0][sparecol].ci_vp,
|
|
|
|
raidPtr->mod_counter);
|
|
|
|
}
|
1999-03-09 05:59:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* printf("Component labels updated\n"); */
|
|
|
|
}
|
2000-01-05 05:57:28 +03:00
|
|
|
|
2000-03-07 05:59:50 +03:00
|
|
|
void
|
2000-03-07 06:09:47 +03:00
|
|
|
rf_close_component(raidPtr, vp, auto_configured)
|
2000-03-07 05:59:50 +03:00
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
struct vnode *vp;
|
|
|
|
int auto_configured;
|
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
|
|
|
|
p = raidPtr->engine_thread;
|
|
|
|
|
|
|
|
if (vp != NULL) {
|
|
|
|
if (auto_configured == 1) {
|
2000-09-08 05:36:35 +04:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2000-09-21 05:37:35 +04:00
|
|
|
VOP_CLOSE(vp, FREAD | FWRITE, NOCRED, 0);
|
2000-03-07 05:59:50 +03:00
|
|
|
vput(vp);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
(void) vn_close(vp, FREAD | FWRITE, p->p_ucred, p);
|
|
|
|
}
|
|
|
|
} else {
|
2002-07-13 21:24:41 +04:00
|
|
|
#if 0
|
2000-03-07 05:59:50 +03:00
|
|
|
printf("vnode was NULL\n");
|
2002-07-13 21:24:41 +04:00
|
|
|
#endif
|
2000-03-07 05:59:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-07 05:28:05 +03:00
|
|
|
void
|
2000-03-07 06:09:47 +03:00
|
|
|
rf_UnconfigureVnodes(raidPtr)
|
2000-03-07 05:28:05 +03:00
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
{
|
|
|
|
int r,c;
|
2000-03-07 05:59:50 +03:00
|
|
|
struct vnode *vp;
|
|
|
|
int acd;
|
2000-03-07 05:28:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* We take this opportunity to close the vnodes like we should.. */
|
|
|
|
|
|
|
|
for (r = 0; r < raidPtr->numRow; r++) {
|
|
|
|
for (c = 0; c < raidPtr->numCol; c++) {
|
2002-07-13 21:24:41 +04:00
|
|
|
#if 0
|
|
|
|
printf("raid%d: Closing vnode for row: %d col: %d\n",
|
|
|
|
raidPtr->raidid, r, c);
|
|
|
|
#endif
|
2000-03-07 05:59:50 +03:00
|
|
|
vp = raidPtr->raid_cinfo[r][c].ci_vp;
|
|
|
|
acd = raidPtr->Disks[r][c].auto_configured;
|
|
|
|
rf_close_component(raidPtr, vp, acd);
|
|
|
|
raidPtr->raid_cinfo[r][c].ci_vp = NULL;
|
|
|
|
raidPtr->Disks[r][c].auto_configured = 0;
|
2000-03-07 05:28:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (r = 0; r < raidPtr->numSpare; r++) {
|
2002-07-13 21:24:41 +04:00
|
|
|
#if 0
|
|
|
|
printf("raid%d: Closing vnode for spare: %d\n",
|
|
|
|
raidPtr->raidid, r);
|
|
|
|
#endif
|
2000-03-07 05:59:50 +03:00
|
|
|
vp = raidPtr->raid_cinfo[0][raidPtr->numCol + r].ci_vp;
|
|
|
|
acd = raidPtr->Disks[0][raidPtr->numCol + r].auto_configured;
|
|
|
|
rf_close_component(raidPtr, vp, acd);
|
|
|
|
raidPtr->raid_cinfo[0][raidPtr->numCol + r].ci_vp = NULL;
|
|
|
|
raidPtr->Disks[0][raidPtr->numCol + r].auto_configured = 0;
|
2000-03-07 05:28:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-27 04:50:22 +03:00
|
|
|
|
2000-01-05 05:57:28 +03:00
|
|
|
void
|
|
|
|
rf_ReconThread(req)
|
|
|
|
struct rf_recon_req *req;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
raidPtr = (RF_Raid_t *) req->raidPtr;
|
|
|
|
raidPtr->recon_in_progress = 1;
|
|
|
|
|
|
|
|
rf_FailDisk((RF_Raid_t *) req->raidPtr, req->row, req->col,
|
|
|
|
((req->flags & RF_FDFLAGS_RECON) ? 1 : 0));
|
|
|
|
|
|
|
|
/* XXX get rid of this! we don't need it at all.. */
|
|
|
|
RF_Free(req, sizeof(*req));
|
|
|
|
|
|
|
|
raidPtr->recon_in_progress = 0;
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/* That's all... */
|
|
|
|
kthread_exit(0); /* does not return */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rf_RewriteParityThread(raidPtr)
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
{
|
|
|
|
int retcode;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
raidPtr->parity_rewrite_in_progress = 1;
|
|
|
|
s = splbio();
|
|
|
|
retcode = rf_RewriteParity(raidPtr);
|
|
|
|
splx(s);
|
|
|
|
if (retcode) {
|
|
|
|
printf("raid%d: Error re-writing parity!\n",raidPtr->raidid);
|
|
|
|
} else {
|
|
|
|
/* set the clean bit! If we shutdown correctly,
|
|
|
|
the clean bit on each component label will get
|
|
|
|
set */
|
|
|
|
raidPtr->parity_good = RF_RAID_CLEAN;
|
|
|
|
}
|
|
|
|
raidPtr->parity_rewrite_in_progress = 0;
|
|
|
|
|
2000-05-28 07:00:31 +04:00
|
|
|
/* Anyone waiting for us to stop? If so, inform them... */
|
|
|
|
if (raidPtr->waitShutdown) {
|
|
|
|
wakeup(&raidPtr->parity_rewrite_in_progress);
|
|
|
|
}
|
|
|
|
|
2000-01-05 05:57:28 +03:00
|
|
|
/* That's all... */
|
|
|
|
kthread_exit(0); /* does not return */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
rf_CopybackThread(raidPtr)
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
raidPtr->copyback_in_progress = 1;
|
|
|
|
s = splbio();
|
|
|
|
rf_CopybackReconstructedData(raidPtr);
|
|
|
|
splx(s);
|
|
|
|
raidPtr->copyback_in_progress = 0;
|
|
|
|
|
|
|
|
/* That's all... */
|
|
|
|
kthread_exit(0); /* does not return */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
rf_ReconstructInPlaceThread(req)
|
|
|
|
struct rf_recon_req *req;
|
|
|
|
{
|
|
|
|
int retcode;
|
|
|
|
int s;
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
raidPtr = req->raidPtr;
|
|
|
|
raidPtr->recon_in_progress = 1;
|
|
|
|
retcode = rf_ReconstructInPlace(raidPtr, req->row, req->col);
|
|
|
|
RF_Free(req, sizeof(*req));
|
|
|
|
raidPtr->recon_in_progress = 0;
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/* That's all... */
|
|
|
|
kthread_exit(0); /* does not return */
|
|
|
|
}
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
RF_AutoConfig_t *
|
|
|
|
rf_find_raid_components()
|
|
|
|
{
|
|
|
|
struct vnode *vp;
|
|
|
|
struct disklabel label;
|
|
|
|
struct device *dv;
|
|
|
|
dev_t dev;
|
2002-09-06 17:18:43 +04:00
|
|
|
int bmajor;
|
2000-02-13 07:53:57 +03:00
|
|
|
int error;
|
|
|
|
int i;
|
|
|
|
int good_one;
|
|
|
|
RF_ComponentLabel_t *clabel;
|
|
|
|
RF_AutoConfig_t *ac_list;
|
|
|
|
RF_AutoConfig_t *ac;
|
|
|
|
|
|
|
|
|
|
|
|
/* initialize the AutoConfig list */
|
|
|
|
ac_list = NULL;
|
|
|
|
|
|
|
|
/* we begin by trolling through *all* the devices on the system */
|
|
|
|
|
|
|
|
for (dv = alldevs.tqh_first; dv != NULL;
|
|
|
|
dv = dv->dv_list.tqe_next) {
|
|
|
|
|
|
|
|
/* we are only interested in disks... */
|
|
|
|
if (dv->dv_class != DV_DISK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* we don't care about floppies... */
|
2002-09-27 06:24:06 +04:00
|
|
|
if (!strcmp(dv->dv_cfdata->cf_name,"fd")) {
|
2000-02-13 07:53:57 +03:00
|
|
|
continue;
|
|
|
|
}
|
2002-08-08 00:45:39 +04:00
|
|
|
|
|
|
|
/* we don't care about CD's... */
|
2002-09-27 06:24:06 +04:00
|
|
|
if (!strcmp(dv->dv_cfdata->cf_name,"cd")) {
|
2002-08-08 00:45:39 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-05-23 19:12:59 +04:00
|
|
|
/* hdfd is the Atari/Hades floppy driver */
|
2002-09-27 06:24:06 +04:00
|
|
|
if (!strcmp(dv->dv_cfdata->cf_name,"hdfd")) {
|
2002-05-23 19:03:33 +04:00
|
|
|
continue;
|
|
|
|
}
|
2002-06-27 09:13:33 +04:00
|
|
|
/* fdisa is the Atari/Milan floppy driver */
|
2002-09-27 06:24:06 +04:00
|
|
|
if (!strcmp(dv->dv_cfdata->cf_name,"fdisa")) {
|
2002-06-27 09:13:33 +04:00
|
|
|
continue;
|
|
|
|
}
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
/* need to find the device_name_to_block_device_major stuff */
|
2002-09-06 17:18:43 +04:00
|
|
|
bmajor = devsw_name2blk(dv->dv_xname, NULL, 0);
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
/* get a vnode for the raw partition of this disk */
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev = MAKEDISKDEV(bmajor, dv->dv_unit, RAW_PART);
|
2000-02-13 07:53:57 +03:00
|
|
|
if (bdevvp(dev, &vp))
|
|
|
|
panic("RAID can't alloc vnode");
|
|
|
|
|
|
|
|
error = VOP_OPEN(vp, FREAD, NOCRED, 0);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
/* "Who cares." Continue looking
|
|
|
|
for something that exists*/
|
|
|
|
vput(vp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ok, the disk exists. Go get the disklabel. */
|
|
|
|
error = VOP_IOCTL(vp, DIOCGDINFO, (caddr_t)&label,
|
|
|
|
FREAD, NOCRED, 0);
|
|
|
|
if (error) {
|
|
|
|
/*
|
|
|
|
* XXX can't happen - open() would
|
|
|
|
* have errored out (or faked up one)
|
|
|
|
*/
|
|
|
|
printf("can't get label for dev %s%c (%d)!?!?\n",
|
|
|
|
dv->dv_xname, 'a' + RAW_PART, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't need this any more. We'll allocate it again
|
|
|
|
a little later if we really do... */
|
2000-09-08 05:36:35 +04:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2000-09-21 05:37:35 +04:00
|
|
|
VOP_CLOSE(vp, FREAD | FWRITE, NOCRED, 0);
|
2000-02-13 07:53:57 +03:00
|
|
|
vput(vp);
|
|
|
|
|
|
|
|
for (i=0; i < label.d_npartitions; i++) {
|
|
|
|
/* We only support partitions marked as RAID */
|
|
|
|
if (label.d_partitions[i].p_fstype != FS_RAID)
|
|
|
|
continue;
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev = MAKEDISKDEV(bmajor, dv->dv_unit, i);
|
2000-02-13 07:53:57 +03:00
|
|
|
if (bdevvp(dev, &vp))
|
|
|
|
panic("RAID can't alloc vnode");
|
|
|
|
|
|
|
|
error = VOP_OPEN(vp, FREAD, NOCRED, 0);
|
|
|
|
if (error) {
|
|
|
|
/* Whatever... */
|
|
|
|
vput(vp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
good_one = 0;
|
|
|
|
|
|
|
|
clabel = (RF_ComponentLabel_t *)
|
|
|
|
malloc(sizeof(RF_ComponentLabel_t),
|
|
|
|
M_RAIDFRAME, M_NOWAIT);
|
|
|
|
if (clabel == NULL) {
|
|
|
|
/* XXX CLEANUP HERE */
|
|
|
|
printf("RAID auto config: out of memory!\n");
|
|
|
|
return(NULL); /* XXX probably should panic? */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!raidread_component_label(dev, vp, clabel)) {
|
|
|
|
/* Got the label. Does it look reasonable? */
|
2000-02-16 04:10:44 +03:00
|
|
|
if (rf_reasonable_label(clabel) &&
|
2000-02-23 05:04:21 +03:00
|
|
|
(clabel->partitionSize <=
|
2000-02-13 07:53:57 +03:00
|
|
|
label.d_partitions[i].p_size)) {
|
|
|
|
#if DEBUG
|
|
|
|
printf("Component on: %s%c: %d\n",
|
|
|
|
dv->dv_xname, 'a'+i,
|
|
|
|
label.d_partitions[i].p_size);
|
2000-03-07 05:12:13 +03:00
|
|
|
rf_print_component_label(clabel);
|
2000-02-13 07:53:57 +03:00
|
|
|
#endif
|
|
|
|
/* if it's reasonable, add it,
|
|
|
|
else ignore it. */
|
|
|
|
ac = (RF_AutoConfig_t *)
|
|
|
|
malloc(sizeof(RF_AutoConfig_t),
|
|
|
|
M_RAIDFRAME,
|
|
|
|
M_NOWAIT);
|
|
|
|
if (ac == NULL) {
|
|
|
|
/* XXX should panic?? */
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(ac->devname, "%s%c",
|
|
|
|
dv->dv_xname, 'a'+i);
|
|
|
|
ac->dev = dev;
|
|
|
|
ac->vp = vp;
|
|
|
|
ac->clabel = clabel;
|
|
|
|
ac->next = ac_list;
|
|
|
|
ac_list = ac;
|
|
|
|
good_one = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!good_one) {
|
|
|
|
/* cleanup */
|
|
|
|
free(clabel, M_RAIDFRAME);
|
2000-09-08 05:36:35 +04:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
2000-09-21 05:37:35 +04:00
|
|
|
VOP_CLOSE(vp, FREAD | FWRITE, NOCRED, 0);
|
2000-02-13 07:53:57 +03:00
|
|
|
vput(vp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-06-21 07:07:04 +04:00
|
|
|
return(ac_list);
|
2000-02-13 07:53:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-02-16 04:10:44 +03:00
|
|
|
rf_reasonable_label(clabel)
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t *clabel;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (((clabel->version==RF_COMPONENT_LABEL_VERSION_1) ||
|
|
|
|
(clabel->version==RF_COMPONENT_LABEL_VERSION)) &&
|
|
|
|
((clabel->clean == RF_RAID_CLEAN) ||
|
|
|
|
(clabel->clean == RF_RAID_DIRTY)) &&
|
|
|
|
clabel->row >=0 &&
|
|
|
|
clabel->column >= 0 &&
|
|
|
|
clabel->num_rows > 0 &&
|
|
|
|
clabel->num_columns > 0 &&
|
|
|
|
clabel->row < clabel->num_rows &&
|
|
|
|
clabel->column < clabel->num_columns &&
|
|
|
|
clabel->blockSize > 0 &&
|
|
|
|
clabel->numBlocks > 0) {
|
|
|
|
/* label looks reasonable enough... */
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-23 07:28:41 +04:00
|
|
|
#if DEBUG
|
2000-02-13 07:53:57 +03:00
|
|
|
void
|
2000-03-07 05:12:13 +03:00
|
|
|
rf_print_component_label(clabel)
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ComponentLabel_t *clabel;
|
|
|
|
{
|
|
|
|
printf(" Row: %d Column: %d Num Rows: %d Num Columns: %d\n",
|
|
|
|
clabel->row, clabel->column,
|
|
|
|
clabel->num_rows, clabel->num_columns);
|
|
|
|
printf(" Version: %d Serial Number: %d Mod Counter: %d\n",
|
|
|
|
clabel->version, clabel->serial_number,
|
|
|
|
clabel->mod_counter);
|
|
|
|
printf(" Clean: %s Status: %d\n",
|
|
|
|
clabel->clean ? "Yes" : "No", clabel->status );
|
|
|
|
printf(" sectPerSU: %d SUsPerPU: %d SUsPerRU: %d\n",
|
|
|
|
clabel->sectPerSU, clabel->SUsPerPU, clabel->SUsPerRU);
|
|
|
|
printf(" RAID Level: %c blocksize: %d numBlocks: %d\n",
|
|
|
|
(char) clabel->parityConfig, clabel->blockSize,
|
|
|
|
clabel->numBlocks);
|
|
|
|
printf(" Autoconfig: %s\n", clabel->autoconfigure ? "Yes" : "No" );
|
2000-03-31 05:20:43 +04:00
|
|
|
printf(" Contains root partition: %s\n",
|
|
|
|
clabel->root_partition ? "Yes" : "No" );
|
2000-02-13 07:53:57 +03:00
|
|
|
printf(" Last configured as: raid%d\n", clabel->last_unit );
|
2000-02-22 06:38:42 +03:00
|
|
|
#if 0
|
|
|
|
printf(" Config order: %d\n", clabel->config_order);
|
|
|
|
#endif
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
}
|
2002-09-21 11:05:06 +04:00
|
|
|
#endif
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
RF_ConfigSet_t *
|
|
|
|
rf_create_auto_sets(ac_list)
|
|
|
|
RF_AutoConfig_t *ac_list;
|
|
|
|
{
|
|
|
|
RF_AutoConfig_t *ac;
|
|
|
|
RF_ConfigSet_t *config_sets;
|
|
|
|
RF_ConfigSet_t *cset;
|
|
|
|
RF_AutoConfig_t *ac_next;
|
|
|
|
|
|
|
|
|
|
|
|
config_sets = NULL;
|
|
|
|
|
|
|
|
/* Go through the AutoConfig list, and figure out which components
|
|
|
|
belong to what sets. */
|
|
|
|
ac = ac_list;
|
|
|
|
while(ac!=NULL) {
|
|
|
|
/* we're going to putz with ac->next, so save it here
|
|
|
|
for use at the end of the loop */
|
|
|
|
ac_next = ac->next;
|
|
|
|
|
|
|
|
if (config_sets == NULL) {
|
|
|
|
/* will need at least this one... */
|
|
|
|
config_sets = (RF_ConfigSet_t *)
|
|
|
|
malloc(sizeof(RF_ConfigSet_t),
|
|
|
|
M_RAIDFRAME, M_NOWAIT);
|
|
|
|
if (config_sets == NULL) {
|
|
|
|
panic("rf_create_auto_sets: No memory!\n");
|
|
|
|
}
|
|
|
|
/* this one is easy :) */
|
|
|
|
config_sets->ac = ac;
|
|
|
|
config_sets->next = NULL;
|
2000-02-22 06:38:42 +03:00
|
|
|
config_sets->rootable = 0;
|
2000-02-13 07:53:57 +03:00
|
|
|
ac->next = NULL;
|
|
|
|
} else {
|
|
|
|
/* which set does this component fit into? */
|
|
|
|
cset = config_sets;
|
|
|
|
while(cset!=NULL) {
|
2000-02-16 04:10:44 +03:00
|
|
|
if (rf_does_it_fit(cset, ac)) {
|
2000-05-28 09:23:41 +04:00
|
|
|
/* looks like it matches... */
|
|
|
|
ac->next = cset->ac;
|
|
|
|
cset->ac = ac;
|
2000-02-13 07:53:57 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
cset = cset->next;
|
|
|
|
}
|
|
|
|
if (cset==NULL) {
|
|
|
|
/* didn't find a match above... new set..*/
|
|
|
|
cset = (RF_ConfigSet_t *)
|
|
|
|
malloc(sizeof(RF_ConfigSet_t),
|
|
|
|
M_RAIDFRAME, M_NOWAIT);
|
|
|
|
if (cset == NULL) {
|
|
|
|
panic("rf_create_auto_sets: No memory!\n");
|
|
|
|
}
|
|
|
|
cset->ac = ac;
|
|
|
|
ac->next = NULL;
|
|
|
|
cset->next = config_sets;
|
2000-02-22 06:38:42 +03:00
|
|
|
cset->rootable = 0;
|
2000-02-13 07:53:57 +03:00
|
|
|
config_sets = cset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ac = ac_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return(config_sets);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-02-16 04:10:44 +03:00
|
|
|
rf_does_it_fit(cset, ac)
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ConfigSet_t *cset;
|
|
|
|
RF_AutoConfig_t *ac;
|
|
|
|
{
|
|
|
|
RF_ComponentLabel_t *clabel1, *clabel2;
|
|
|
|
|
|
|
|
/* If this one matches the *first* one in the set, that's good
|
|
|
|
enough, since the other members of the set would have been
|
|
|
|
through here too... */
|
2000-02-25 22:56:56 +03:00
|
|
|
/* note that we are not checking partitionSize here..
|
|
|
|
|
|
|
|
Note that we are also not checking the mod_counters here.
|
|
|
|
If everything else matches execpt the mod_counter, that's
|
|
|
|
good enough for this test. We will deal with the mod_counters
|
|
|
|
a little later in the autoconfiguration process.
|
|
|
|
|
|
|
|
(clabel1->mod_counter == clabel2->mod_counter) &&
|
|
|
|
|
2000-05-27 23:12:03 +04:00
|
|
|
The reason we don't check for this is that failed disks
|
|
|
|
will have lower modification counts. If those disks are
|
|
|
|
not added to the set they used to belong to, then they will
|
|
|
|
form their own set, which may result in 2 different sets,
|
|
|
|
for example, competing to be configured at raid0, and
|
|
|
|
perhaps competing to be the root filesystem set. If the
|
|
|
|
wrong ones get configured, or both attempt to become /,
|
|
|
|
weird behaviour and or serious lossage will occur. Thus we
|
|
|
|
need to bring them into the fold here, and kick them out at
|
|
|
|
a later point.
|
|
|
|
|
2000-02-25 22:56:56 +03:00
|
|
|
*/
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
clabel1 = cset->ac->clabel;
|
|
|
|
clabel2 = ac->clabel;
|
|
|
|
if ((clabel1->version == clabel2->version) &&
|
|
|
|
(clabel1->serial_number == clabel2->serial_number) &&
|
|
|
|
(clabel1->num_rows == clabel2->num_rows) &&
|
|
|
|
(clabel1->num_columns == clabel2->num_columns) &&
|
|
|
|
(clabel1->sectPerSU == clabel2->sectPerSU) &&
|
|
|
|
(clabel1->SUsPerPU == clabel2->SUsPerPU) &&
|
|
|
|
(clabel1->SUsPerRU == clabel2->SUsPerRU) &&
|
|
|
|
(clabel1->parityConfig == clabel2->parityConfig) &&
|
|
|
|
(clabel1->maxOutstanding == clabel2->maxOutstanding) &&
|
|
|
|
(clabel1->blockSize == clabel2->blockSize) &&
|
|
|
|
(clabel1->numBlocks == clabel2->numBlocks) &&
|
|
|
|
(clabel1->autoconfigure == clabel2->autoconfigure) &&
|
|
|
|
(clabel1->root_partition == clabel2->root_partition) &&
|
|
|
|
(clabel1->last_unit == clabel2->last_unit) &&
|
|
|
|
(clabel1->config_order == clabel2->config_order)) {
|
|
|
|
/* if it get's here, it almost *has* to be a match */
|
|
|
|
} else {
|
|
|
|
/* it's not consistent with somebody in the set..
|
|
|
|
punt */
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
/* all was fine.. it must fit... */
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-22 06:38:42 +03:00
|
|
|
rf_have_enough_components(cset)
|
|
|
|
RF_ConfigSet_t *cset;
|
2000-02-13 07:53:57 +03:00
|
|
|
{
|
2000-02-22 06:38:42 +03:00
|
|
|
RF_AutoConfig_t *ac;
|
|
|
|
RF_AutoConfig_t *auto_config;
|
|
|
|
RF_ComponentLabel_t *clabel;
|
|
|
|
int r,c;
|
|
|
|
int num_rows;
|
|
|
|
int num_cols;
|
|
|
|
int num_missing;
|
2000-05-28 09:23:41 +04:00
|
|
|
int mod_counter;
|
2000-05-29 06:57:34 +04:00
|
|
|
int mod_counter_found;
|
2000-05-30 07:29:49 +04:00
|
|
|
int even_pair_failed;
|
|
|
|
char parity_type;
|
|
|
|
|
2000-02-22 06:38:42 +03:00
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
/* check to see that we have enough 'live' components
|
|
|
|
of this set. If so, we can configure it if necessary */
|
|
|
|
|
2000-02-22 06:38:42 +03:00
|
|
|
num_rows = cset->ac->clabel->num_rows;
|
|
|
|
num_cols = cset->ac->clabel->num_columns;
|
2000-05-30 07:29:49 +04:00
|
|
|
parity_type = cset->ac->clabel->parityConfig;
|
2000-02-22 06:38:42 +03:00
|
|
|
|
|
|
|
/* XXX Check for duplicate components!?!?!? */
|
|
|
|
|
2000-05-28 09:23:41 +04:00
|
|
|
/* Determine what the mod_counter is supposed to be for this set. */
|
|
|
|
|
2000-05-29 06:57:34 +04:00
|
|
|
mod_counter_found = 0;
|
2000-12-05 04:35:56 +03:00
|
|
|
mod_counter = 0;
|
2000-05-28 09:23:41 +04:00
|
|
|
ac = cset->ac;
|
|
|
|
while(ac!=NULL) {
|
2000-05-29 06:57:34 +04:00
|
|
|
if (mod_counter_found==0) {
|
2000-05-28 09:23:41 +04:00
|
|
|
mod_counter = ac->clabel->mod_counter;
|
2000-05-29 06:57:34 +04:00
|
|
|
mod_counter_found = 1;
|
|
|
|
} else {
|
|
|
|
if (ac->clabel->mod_counter > mod_counter) {
|
|
|
|
mod_counter = ac->clabel->mod_counter;
|
|
|
|
}
|
2000-05-28 09:23:41 +04:00
|
|
|
}
|
|
|
|
ac = ac->next;
|
|
|
|
}
|
|
|
|
|
2000-02-22 06:38:42 +03:00
|
|
|
num_missing = 0;
|
|
|
|
auto_config = cset->ac;
|
|
|
|
|
|
|
|
for(r=0; r<num_rows; r++) {
|
2000-05-30 07:29:49 +04:00
|
|
|
even_pair_failed = 0;
|
2000-02-22 06:38:42 +03:00
|
|
|
for(c=0; c<num_cols; c++) {
|
|
|
|
ac = auto_config;
|
|
|
|
while(ac!=NULL) {
|
|
|
|
if ((ac->clabel->row == r) &&
|
2000-05-28 09:23:41 +04:00
|
|
|
(ac->clabel->column == c) &&
|
|
|
|
(ac->clabel->mod_counter == mod_counter)) {
|
2000-02-22 06:38:42 +03:00
|
|
|
/* it's this one... */
|
|
|
|
#if DEBUG
|
|
|
|
printf("Found: %s at %d,%d\n",
|
|
|
|
ac->devname,r,c);
|
2000-02-13 07:53:57 +03:00
|
|
|
#endif
|
2000-02-22 06:38:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ac=ac->next;
|
|
|
|
}
|
|
|
|
if (ac==NULL) {
|
|
|
|
/* Didn't find one here! */
|
2000-05-30 07:29:49 +04:00
|
|
|
/* special case for RAID 1, especially
|
|
|
|
where there are more than 2
|
|
|
|
components (where RAIDframe treats
|
|
|
|
things a little differently :( ) */
|
|
|
|
if (parity_type == '1') {
|
|
|
|
if (c%2 == 0) { /* even component */
|
|
|
|
even_pair_failed = 1;
|
|
|
|
} else { /* odd component. If
|
|
|
|
we're failed, and
|
|
|
|
so is the even
|
|
|
|
component, it's
|
|
|
|
"Good Night, Charlie" */
|
|
|
|
if (even_pair_failed == 1) {
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* normal accounting */
|
|
|
|
num_missing++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((parity_type == '1') && (c%2 == 1)) {
|
|
|
|
/* Just did an even component, and we didn't
|
|
|
|
bail.. reset the even_pair_failed flag,
|
|
|
|
and go on to the next component.... */
|
|
|
|
even_pair_failed = 0;
|
2000-02-22 06:38:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clabel = cset->ac->clabel;
|
|
|
|
|
|
|
|
if (((clabel->parityConfig == '0') && (num_missing > 0)) ||
|
|
|
|
((clabel->parityConfig == '4') && (num_missing > 1)) ||
|
|
|
|
((clabel->parityConfig == '5') && (num_missing > 1))) {
|
|
|
|
/* XXX this needs to be made *much* more general */
|
|
|
|
/* Too many failures */
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
/* otherwise, all is well, and we've got enough to take a kick
|
|
|
|
at autoconfiguring this set */
|
|
|
|
return(1);
|
|
|
|
}
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
void
|
2000-02-16 04:10:44 +03:00
|
|
|
rf_create_configuration(ac,config,raidPtr)
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_AutoConfig_t *ac;
|
|
|
|
RF_Config_t *config;
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
{
|
|
|
|
RF_ComponentLabel_t *clabel;
|
2000-04-27 04:57:48 +04:00
|
|
|
int i;
|
2000-02-13 07:53:57 +03:00
|
|
|
|
|
|
|
clabel = ac->clabel;
|
|
|
|
|
|
|
|
/* 1. Fill in the common stuff */
|
|
|
|
config->numRow = clabel->num_rows;
|
|
|
|
config->numCol = clabel->num_columns;
|
|
|
|
config->numSpare = 0; /* XXX should this be set here? */
|
|
|
|
config->sectPerSU = clabel->sectPerSU;
|
|
|
|
config->SUsPerPU = clabel->SUsPerPU;
|
|
|
|
config->SUsPerRU = clabel->SUsPerRU;
|
|
|
|
config->parityConfig = clabel->parityConfig;
|
|
|
|
/* XXX... */
|
|
|
|
strcpy(config->diskQueueType,"fifo");
|
|
|
|
config->maxOutstandingDiskReqs = clabel->maxOutstanding;
|
|
|
|
config->layoutSpecificSize = 0; /* XXX ?? */
|
|
|
|
|
|
|
|
while(ac!=NULL) {
|
|
|
|
/* row/col values will be in range due to the checks
|
|
|
|
in reasonable_label() */
|
|
|
|
strcpy(config->devnames[ac->clabel->row][ac->clabel->column],
|
|
|
|
ac->devname);
|
|
|
|
ac = ac->next;
|
|
|
|
}
|
|
|
|
|
2000-04-27 04:57:48 +04:00
|
|
|
for(i=0;i<RF_MAXDBGV;i++) {
|
|
|
|
config->debugVars[i][0] = NULL;
|
|
|
|
}
|
2000-02-13 07:53:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rf_set_autoconfig(raidPtr, new_value)
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
int new_value;
|
|
|
|
{
|
|
|
|
RF_ComponentLabel_t clabel;
|
|
|
|
struct vnode *vp;
|
|
|
|
dev_t dev;
|
|
|
|
int row, column;
|
|
|
|
|
2000-02-23 05:04:21 +03:00
|
|
|
raidPtr->autoconfigure = new_value;
|
2000-02-13 07:53:57 +03:00
|
|
|
for(row=0; row<raidPtr->numRow; row++) {
|
|
|
|
for(column=0; column<raidPtr->numCol; column++) {
|
2000-05-28 05:03:22 +04:00
|
|
|
if (raidPtr->Disks[row][column].status ==
|
|
|
|
rf_ds_optimal) {
|
|
|
|
dev = raidPtr->Disks[row][column].dev;
|
|
|
|
vp = raidPtr->raid_cinfo[row][column].ci_vp;
|
|
|
|
raidread_component_label(dev, vp, &clabel);
|
|
|
|
clabel.autoconfigure = new_value;
|
|
|
|
raidwrite_component_label(dev, vp, &clabel);
|
|
|
|
}
|
2000-02-13 07:53:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rf_set_rootpartition(raidPtr, new_value)
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
int new_value;
|
|
|
|
{
|
|
|
|
RF_ComponentLabel_t clabel;
|
|
|
|
struct vnode *vp;
|
|
|
|
dev_t dev;
|
|
|
|
int row, column;
|
|
|
|
|
2000-02-23 05:04:21 +03:00
|
|
|
raidPtr->root_partition = new_value;
|
2000-02-13 07:53:57 +03:00
|
|
|
for(row=0; row<raidPtr->numRow; row++) {
|
|
|
|
for(column=0; column<raidPtr->numCol; column++) {
|
2000-05-28 05:03:22 +04:00
|
|
|
if (raidPtr->Disks[row][column].status ==
|
|
|
|
rf_ds_optimal) {
|
|
|
|
dev = raidPtr->Disks[row][column].dev;
|
|
|
|
vp = raidPtr->raid_cinfo[row][column].ci_vp;
|
|
|
|
raidread_component_label(dev, vp, &clabel);
|
|
|
|
clabel.root_partition = new_value;
|
|
|
|
raidwrite_component_label(dev, vp, &clabel);
|
|
|
|
}
|
2000-02-13 07:53:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-02-16 04:10:44 +03:00
|
|
|
rf_release_all_vps(cset)
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ConfigSet_t *cset;
|
|
|
|
{
|
|
|
|
RF_AutoConfig_t *ac;
|
|
|
|
|
|
|
|
ac = cset->ac;
|
|
|
|
while(ac!=NULL) {
|
|
|
|
/* Close the vp, and give it back */
|
|
|
|
if (ac->vp) {
|
2000-09-08 05:36:35 +04:00
|
|
|
vn_lock(ac->vp, LK_EXCLUSIVE | LK_RETRY);
|
2000-02-13 07:53:57 +03:00
|
|
|
VOP_CLOSE(ac->vp, FREAD, NOCRED, 0);
|
|
|
|
vput(ac->vp);
|
2000-05-28 09:23:41 +04:00
|
|
|
ac->vp = NULL;
|
2000-02-13 07:53:57 +03:00
|
|
|
}
|
|
|
|
ac = ac->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-02-16 04:10:44 +03:00
|
|
|
rf_cleanup_config_set(cset)
|
2000-02-13 07:53:57 +03:00
|
|
|
RF_ConfigSet_t *cset;
|
|
|
|
{
|
|
|
|
RF_AutoConfig_t *ac;
|
|
|
|
RF_AutoConfig_t *next_ac;
|
|
|
|
|
|
|
|
ac = cset->ac;
|
|
|
|
while(ac!=NULL) {
|
|
|
|
next_ac = ac->next;
|
|
|
|
/* nuke the label */
|
|
|
|
free(ac->clabel, M_RAIDFRAME);
|
|
|
|
/* cleanup the config structure */
|
|
|
|
free(ac, M_RAIDFRAME);
|
|
|
|
/* "next.." */
|
|
|
|
ac = next_ac;
|
|
|
|
}
|
|
|
|
/* and, finally, nuke the config set */
|
|
|
|
free(cset, M_RAIDFRAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
raid_init_component_label(raidPtr, clabel)
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
RF_ComponentLabel_t *clabel;
|
|
|
|
{
|
|
|
|
/* current version number */
|
|
|
|
clabel->version = RF_COMPONENT_LABEL_VERSION;
|
2000-02-24 04:23:05 +03:00
|
|
|
clabel->serial_number = raidPtr->serial_number;
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel->mod_counter = raidPtr->mod_counter;
|
|
|
|
clabel->num_rows = raidPtr->numRow;
|
|
|
|
clabel->num_columns = raidPtr->numCol;
|
|
|
|
clabel->clean = RF_RAID_DIRTY; /* not clean */
|
|
|
|
clabel->status = rf_ds_optimal; /* "It's good!" */
|
|
|
|
|
|
|
|
clabel->sectPerSU = raidPtr->Layout.sectorsPerStripeUnit;
|
|
|
|
clabel->SUsPerPU = raidPtr->Layout.SUsPerPU;
|
|
|
|
clabel->SUsPerRU = raidPtr->Layout.SUsPerRU;
|
2000-02-23 05:04:21 +03:00
|
|
|
|
|
|
|
clabel->blockSize = raidPtr->bytesPerSector;
|
|
|
|
clabel->numBlocks = raidPtr->sectorsPerDisk;
|
|
|
|
|
2000-02-13 07:53:57 +03:00
|
|
|
/* XXX not portable */
|
|
|
|
clabel->parityConfig = raidPtr->Layout.map->parityConfig;
|
2000-02-23 05:04:21 +03:00
|
|
|
clabel->maxOutstanding = raidPtr->maxOutstanding;
|
|
|
|
clabel->autoconfigure = raidPtr->autoconfigure;
|
|
|
|
clabel->root_partition = raidPtr->root_partition;
|
2000-02-13 07:53:57 +03:00
|
|
|
clabel->last_unit = raidPtr->raidid;
|
2000-02-23 05:04:21 +03:00
|
|
|
clabel->config_order = raidPtr->config_order;
|
2000-02-22 06:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rf_auto_config_set(cset,unit)
|
|
|
|
RF_ConfigSet_t *cset;
|
|
|
|
int *unit;
|
|
|
|
{
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
RF_Config_t *config;
|
|
|
|
int raidID;
|
|
|
|
int retcode;
|
|
|
|
|
2002-07-24 06:55:22 +04:00
|
|
|
#if DEBUG
|
2000-03-22 04:41:41 +03:00
|
|
|
printf("RAID autoconfigure\n");
|
2002-07-24 06:55:22 +04:00
|
|
|
#endif
|
2000-02-22 06:38:42 +03:00
|
|
|
|
|
|
|
retcode = 0;
|
|
|
|
*unit = -1;
|
|
|
|
|
|
|
|
/* 1. Create a config structure */
|
|
|
|
|
|
|
|
config = (RF_Config_t *)malloc(sizeof(RF_Config_t),
|
|
|
|
M_RAIDFRAME,
|
|
|
|
M_NOWAIT);
|
|
|
|
if (config==NULL) {
|
|
|
|
printf("Out of mem!?!?\n");
|
|
|
|
/* XXX do something more intelligent here. */
|
|
|
|
return(1);
|
|
|
|
}
|
2000-04-27 04:57:48 +04:00
|
|
|
|
|
|
|
memset(config, 0, sizeof(RF_Config_t));
|
|
|
|
|
2000-02-22 06:38:42 +03:00
|
|
|
/*
|
|
|
|
2. Figure out what RAID ID this one is supposed to live at
|
|
|
|
See if we can get the same RAID dev that it was configured
|
|
|
|
on last time..
|
|
|
|
*/
|
|
|
|
|
|
|
|
raidID = cset->ac->clabel->last_unit;
|
2000-02-22 19:07:02 +03:00
|
|
|
if ((raidID < 0) || (raidID >= numraid)) {
|
2000-02-22 06:38:42 +03:00
|
|
|
/* let's not wander off into lala land. */
|
|
|
|
raidID = numraid - 1;
|
|
|
|
}
|
|
|
|
if (raidPtrs[raidID]->valid != 0) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
Nope... Go looking for an alternative...
|
|
|
|
Start high so we don't immediately use raid0 if that's
|
|
|
|
not taken.
|
|
|
|
*/
|
|
|
|
|
2001-12-17 01:57:32 +03:00
|
|
|
for(raidID = numraid - 1; raidID >= 0; raidID--) {
|
2000-02-22 06:38:42 +03:00
|
|
|
if (raidPtrs[raidID]->valid == 0) {
|
|
|
|
/* can use this one! */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (raidID < 0) {
|
|
|
|
/* punt... */
|
|
|
|
printf("Unable to auto configure this set!\n");
|
|
|
|
printf("(Out of RAID devs!)\n");
|
|
|
|
return(1);
|
|
|
|
}
|
2002-07-24 06:55:22 +04:00
|
|
|
|
|
|
|
#if DEBUG
|
2000-03-22 04:41:41 +03:00
|
|
|
printf("Configuring raid%d:\n",raidID);
|
2002-07-24 06:55:22 +04:00
|
|
|
#endif
|
|
|
|
|
2000-02-22 06:38:42 +03:00
|
|
|
raidPtr = raidPtrs[raidID];
|
|
|
|
|
|
|
|
/* XXX all this stuff should be done SOMEWHERE ELSE! */
|
|
|
|
raidPtr->raidid = raidID;
|
|
|
|
raidPtr->openings = RAIDOUTSTANDING;
|
|
|
|
|
|
|
|
/* 3. Build the configuration structure */
|
|
|
|
rf_create_configuration(cset->ac, config, raidPtr);
|
|
|
|
|
|
|
|
/* 4. Do the configuration */
|
|
|
|
retcode = rf_Configure(raidPtr, config, cset->ac);
|
|
|
|
|
|
|
|
if (retcode == 0) {
|
2000-02-25 23:11:00 +03:00
|
|
|
|
2000-02-25 05:42:30 +03:00
|
|
|
raidinit(raidPtrs[raidID]);
|
|
|
|
|
|
|
|
rf_markalldirty(raidPtrs[raidID]);
|
2000-02-23 05:04:21 +03:00
|
|
|
raidPtrs[raidID]->autoconfigure = 1; /* XXX do this here? */
|
2000-02-22 06:38:42 +03:00
|
|
|
if (cset->ac->clabel->root_partition==1) {
|
|
|
|
/* everything configured just fine. Make a note
|
|
|
|
that this set is eligible to be root. */
|
|
|
|
cset->rootable = 1;
|
2000-02-23 05:04:21 +03:00
|
|
|
/* XXX do this here? */
|
|
|
|
raidPtrs[raidID]->root_partition = 1;
|
2000-02-22 06:38:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 5. Cleanup */
|
|
|
|
free(config, M_RAIDFRAME);
|
|
|
|
|
|
|
|
*unit = raidID;
|
|
|
|
return(retcode);
|
2000-02-13 07:53:57 +03:00
|
|
|
}
|
2000-10-20 06:24:45 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
rf_disk_unbusy(desc)
|
|
|
|
RF_RaidAccessDesc_t *desc;
|
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
|
|
|
|
bp = (struct buf *)desc->bp;
|
|
|
|
disk_unbusy(&raid_softc[desc->raidPtr->raidid].sc_dkdev,
|
|
|
|
(bp->b_bcount - bp->b_resid));
|
|
|
|
}
|