1998-12-28 04:56:24 +00:00
|
|
|
/*-
|
1999-08-07 08:11:22 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999
|
1998-12-28 04:56:24 +00:00
|
|
|
* Nan Yang Computer Services Limited. All rights reserved.
|
|
|
|
*
|
1999-08-07 08:11:22 +00:00
|
|
|
* Parts copyright (c) 1997, 1998 Cybernet Corporation, NetMAX project.
|
|
|
|
*
|
|
|
|
* Written by Greg Lehey
|
|
|
|
*
|
1998-12-28 04:56:24 +00:00
|
|
|
* This software is distributed under the so-called ``Berkeley
|
|
|
|
* License'':
|
|
|
|
*
|
|
|
|
* 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 Nan Yang Computer
|
|
|
|
* Services Limited.
|
|
|
|
* 4. Neither the name of the Company 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 ``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 company 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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-12-28 04:56:24 +00:00
|
|
|
*/
|
|
|
|
|
1998-12-28 16:28:24 +00:00
|
|
|
#include <dev/vinum/vinumhdr.h>
|
|
|
|
#include <dev/vinum/request.h>
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
1999-08-24 02:28:37 +00:00
|
|
|
* Revive a block of a subdisk. Return an error
|
1998-12-28 04:56:24 +00:00
|
|
|
* indication. EAGAIN means successful copy, but
|
1999-08-24 02:28:37 +00:00
|
|
|
* that more blocks remain to be copied. EINVAL
|
|
|
|
* means that the subdisk isn't associated with a
|
|
|
|
* plex (which means a programming error if we get
|
|
|
|
* here at all; FIXME).
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-24 02:28:37 +00:00
|
|
|
int
|
1999-01-21 00:40:03 +00:00
|
|
|
revive_block(int sdno)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
1999-01-21 00:40:03 +00:00
|
|
|
struct sd *sd;
|
|
|
|
struct plex *plex;
|
|
|
|
struct volume *vol;
|
1998-12-28 04:56:24 +00:00
|
|
|
struct buf *bp;
|
|
|
|
int error = EAGAIN;
|
|
|
|
int size; /* size of revive block, bytes */
|
|
|
|
int s; /* priority level */
|
1999-01-21 00:40:03 +00:00
|
|
|
daddr_t plexblkno; /* lblkno in plex */
|
1999-08-07 08:11:22 +00:00
|
|
|
int psd; /* parity subdisk number */
|
|
|
|
int stripe; /* stripe number */
|
|
|
|
int isparity = 0; /* set if this is the parity stripe */
|
1999-08-24 02:28:37 +00:00
|
|
|
struct rangelock *lock; /* for locking */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-21 00:40:03 +00:00
|
|
|
plexblkno = 0; /* to keep the compiler happy */
|
|
|
|
sd = &SD[sdno];
|
1999-08-24 02:28:37 +00:00
|
|
|
lock = NULL;
|
1999-01-21 00:40:03 +00:00
|
|
|
if (sd->plexno < 0) /* no plex? */
|
|
|
|
return EINVAL;
|
|
|
|
plex = &PLEX[sd->plexno]; /* point to plex */
|
|
|
|
if (plex->volno >= 0)
|
|
|
|
vol = &VOL[plex->volno];
|
|
|
|
else
|
|
|
|
vol = NULL;
|
|
|
|
|
|
|
|
if (sd->revive_blocksize == 0) {
|
1998-12-28 04:56:24 +00:00
|
|
|
if (plex->stripesize != 0) /* we're striped, don't revive more than */
|
1999-01-21 00:40:03 +00:00
|
|
|
sd->revive_blocksize = min(DEFAULT_REVIVE_BLOCKSIZE, /* one block at a time */
|
1998-12-28 04:56:24 +00:00
|
|
|
plex->stripesize << DEV_BSHIFT);
|
|
|
|
else
|
1999-01-21 00:40:03 +00:00
|
|
|
sd->revive_blocksize = DEFAULT_REVIVE_BLOCKSIZE;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
1999-01-21 00:40:03 +00:00
|
|
|
size = min(sd->revive_blocksize >> DEV_BSHIFT, sd->sectors - sd->revived) << DEV_BSHIFT;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
s = splbio();
|
1999-01-21 00:40:03 +00:00
|
|
|
bp = geteblk(size); /* Get a buffer */
|
1998-12-28 04:56:24 +00:00
|
|
|
if (bp == NULL) {
|
|
|
|
splx(s);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
if (bp->b_qindex != 0) /* on a queue, */
|
1999-01-21 00:40:03 +00:00
|
|
|
bremfree(bp); /* remove it XXX how can this happen? */
|
1998-12-28 04:56:24 +00:00
|
|
|
splx(s);
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Amount to transfer: block size, unless it
|
1999-08-24 02:28:37 +00:00
|
|
|
* would overlap the end
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
bp->b_bufsize = size;
|
|
|
|
bp->b_bcount = bp->b_bufsize;
|
1999-09-28 22:57:29 +00:00
|
|
|
bp->b_resid = bp->b_bcount;
|
1999-01-21 00:40:03 +00:00
|
|
|
|
|
|
|
/* Now decide where to read from */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-21 00:40:03 +00:00
|
|
|
switch (plex->organization) {
|
|
|
|
daddr_t stripeoffset; /* offset in stripe */
|
|
|
|
|
|
|
|
case plex_concat:
|
|
|
|
plexblkno = sd->revived + sd->plexoffset; /* corresponding address in plex */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case plex_striped:
|
|
|
|
stripeoffset = sd->revived % plex->stripesize; /* offset from beginning of stripe */
|
|
|
|
plexblkno = sd->plexoffset /* base */
|
|
|
|
+ (sd->revived - stripeoffset) * plex->subdisks /* offset to beginning of stripe */
|
|
|
|
+ sd->revived % plex->stripesize; /* offset from beginning of stripe */
|
1999-08-24 02:28:37 +00:00
|
|
|
lock = lockrange(plexblkno << DEV_BSHIFT, bp, plex); /* lock it */
|
1999-01-21 00:40:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case plex_raid5:
|
1999-08-07 08:11:22 +00:00
|
|
|
stripeoffset = sd->revived % plex->stripesize; /* offset from beginning of stripe */
|
|
|
|
plexblkno = sd->plexoffset /* base */
|
|
|
|
+ (sd->revived - stripeoffset) * (plex->subdisks - 1) /* offset to beginning of stripe */
|
1999-09-28 22:57:29 +00:00
|
|
|
+stripeoffset; /* offset from beginning of stripe */
|
1999-08-07 08:11:22 +00:00
|
|
|
stripe = (sd->revived / plex->stripesize); /* stripe number */
|
|
|
|
psd = plex->subdisks - 1 - stripe % plex->subdisks; /* parity subdisk for this stripe */
|
|
|
|
isparity = plex->sdnos[psd] == sdno; /* note if it's the parity subdisk */
|
1999-08-24 02:28:37 +00:00
|
|
|
|
1999-08-07 08:11:22 +00:00
|
|
|
/*
|
1999-08-24 02:28:37 +00:00
|
|
|
* Now adjust for the strangenesses
|
|
|
|
* in RAID-5 striping.
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
if (sd->plexsdno > psd) /* beyond the parity stripe, */
|
|
|
|
plexblkno -= plex->stripesize; /* one stripe less */
|
1999-08-24 02:28:37 +00:00
|
|
|
lock = lockrange(plexblkno << DEV_BSHIFT, bp, plex); /* lock it */
|
1999-08-07 08:11:22 +00:00
|
|
|
break;
|
1999-08-24 02:28:37 +00:00
|
|
|
|
1999-01-21 00:40:03 +00:00
|
|
|
case plex_disorg: /* to keep the compiler happy */
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-08-07 08:11:22 +00:00
|
|
|
if (isparity) { /* we're reviving a parity block, */
|
|
|
|
int mysdno;
|
|
|
|
int *tbuf; /* temporary buffer to read the stuff in to */
|
|
|
|
caddr_t parity_buf; /* the address supplied by geteblk */
|
|
|
|
int isize;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
tbuf = (int *) Malloc(size);
|
|
|
|
isize = size / (sizeof(int)); /* number of ints in the buffer */
|
1999-08-24 02:28:37 +00:00
|
|
|
|
1999-08-07 08:11:22 +00:00
|
|
|
/*
|
|
|
|
* We have calculated plexblkno assuming it
|
|
|
|
* was a data block. Go back to the beginning
|
1999-08-24 02:28:37 +00:00
|
|
|
* of the band.
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
plexblkno -= plex->stripesize * sd->plexsdno;
|
|
|
|
|
|
|
|
/*
|
1999-08-24 02:28:37 +00:00
|
|
|
* Read each subdisk in turn, except for this
|
|
|
|
* one, and xor them together.
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
parity_buf = bp->b_data; /* save the buffer getblk gave us */
|
|
|
|
bzero(parity_buf, size); /* start with nothing */
|
|
|
|
bp->b_data = (caddr_t) tbuf; /* read into here */
|
|
|
|
for (mysdno = 0; mysdno < plex->subdisks; mysdno++) { /* for each subdisk */
|
|
|
|
if (mysdno != sdno) { /* not our subdisk */
|
|
|
|
if (vol != NULL) /* it's part of a volume, */
|
|
|
|
/*
|
1999-08-24 02:28:37 +00:00
|
|
|
* First, read the data from the volume.
|
|
|
|
* We don't care which plex, that's the
|
|
|
|
* driver's job.
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
bp->b_dev = VINUMBDEV(plex->volno, 0, 0, VINUM_VOLUME_TYPE); /* create the device number */
|
|
|
|
else /* it's an unattached plex */
|
|
|
|
bp->b_dev = VINUMRBDEV(sd->plexno, VINUM_RAWPLEX_TYPE); /* create the device number */
|
|
|
|
|
|
|
|
bp->b_blkno = plexblkno; /* read from here */
|
|
|
|
bp->b_flags = B_READ; /* either way, read it */
|
|
|
|
BUF_LOCKINIT(bp); /* get a lock for the buffer */
|
|
|
|
BUF_LOCK(bp, LK_EXCLUSIVE); /* and lock it */
|
|
|
|
vinumstart(bp, 1);
|
|
|
|
biowait(bp);
|
|
|
|
if (bp->b_flags & B_ERROR) /* can't read, */
|
|
|
|
/*
|
1999-08-24 02:28:37 +00:00
|
|
|
* If we have a read error, there's
|
|
|
|
* nothing we can do. By this time, the
|
|
|
|
* daemon has already run out of magic.
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
break;
|
|
|
|
/*
|
1999-08-24 02:28:37 +00:00
|
|
|
* To save time, we do the XOR wordwise.
|
|
|
|
* This requires sectors to be a multiple
|
|
|
|
* of the length of an int, which is
|
|
|
|
* currently always the case.
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
for (i = 0; i < isize; i++)
|
|
|
|
((int *) parity_buf)[i] ^= tbuf[i]; /* xor in the buffer */
|
|
|
|
plexblkno += plex->stripesize; /* move on to the next subdisk */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bp->b_data = parity_buf; /* put the buf header back the way it was */
|
|
|
|
Free(tbuf);
|
|
|
|
} else {
|
1999-01-21 00:40:03 +00:00
|
|
|
bp->b_blkno = plexblkno; /* start here */
|
|
|
|
if (vol != NULL) /* it's part of a volume, */
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
1999-08-24 02:28:37 +00:00
|
|
|
* First, read the data from the volume. We
|
|
|
|
* don't care which plex, that's bre's job.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-01-21 00:40:03 +00:00
|
|
|
bp->b_dev = VINUMBDEV(plex->volno, 0, 0, VINUM_VOLUME_TYPE); /* create the device number */
|
|
|
|
else /* it's an unattached plex */
|
|
|
|
bp->b_dev = VINUMRBDEV(sd->plexno, VINUM_RAWPLEX_TYPE); /* create the device number */
|
|
|
|
|
1999-06-26 02:47:16 +00:00
|
|
|
bp->b_flags = B_READ; /* either way, read it */
|
1999-01-21 00:40:03 +00:00
|
|
|
vinumstart(bp, 1);
|
|
|
|
biowait(bp);
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
if (bp->b_flags & B_ERROR)
|
|
|
|
error = bp->b_error;
|
|
|
|
else
|
1999-01-21 00:40:03 +00:00
|
|
|
/* Now write to the subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
|
|
|
s = splbio();
|
|
|
|
if (bp->b_qindex != 0) /* on a queue, */
|
|
|
|
bremfree(bp); /* remove it */
|
|
|
|
splx(s);
|
|
|
|
|
1999-01-21 00:40:03 +00:00
|
|
|
bp->b_dev = VINUMRBDEV(sdno, VINUM_RAWSD_TYPE); /* create the device number */
|
1999-06-26 02:47:16 +00:00
|
|
|
bp->b_flags = B_ORDERED; /* and make this an ordered write */
|
1999-06-29 04:10:05 +00:00
|
|
|
BUF_LOCKINIT(bp); /* get a lock for the buffer */
|
|
|
|
BUF_LOCK(bp, LK_EXCLUSIVE); /* and lock it */
|
1999-09-28 22:57:29 +00:00
|
|
|
bp->b_resid = bp->b_bcount;
|
1999-01-21 00:40:03 +00:00
|
|
|
bp->b_blkno = sd->revived; /* write it to here */
|
|
|
|
sdio(bp); /* perform the I/O */
|
1998-12-28 04:56:24 +00:00
|
|
|
biowait(bp);
|
|
|
|
if (bp->b_flags & B_ERROR)
|
|
|
|
error = bp->b_error;
|
|
|
|
else {
|
1999-01-21 00:40:03 +00:00
|
|
|
sd->revived += bp->b_bcount >> DEV_BSHIFT; /* moved this much further down */
|
|
|
|
if (sd->revived >= sd->sectors) { /* finished */
|
|
|
|
sd->revived = 0;
|
|
|
|
set_sd_state(sdno, sd_up, setstate_force); /* bring the sd up */
|
1999-03-02 06:56:39 +00:00
|
|
|
log(LOG_INFO, "vinum: %s is %s\n", sd->name, sd_state(sd->state));
|
1998-12-28 04:56:24 +00:00
|
|
|
save_config(); /* and save the updated configuration */
|
|
|
|
error = 0; /* we're done */
|
|
|
|
}
|
|
|
|
}
|
1999-08-24 02:28:37 +00:00
|
|
|
if (lock) /* we took a lock, */
|
|
|
|
unlockrange(sd->plexno, lock); /* give it back */
|
1999-01-21 00:40:03 +00:00
|
|
|
while (sd->waitlist) { /* we have waiting requests */
|
|
|
|
#if VINUMDEBUG
|
|
|
|
struct request *rq = sd->waitlist;
|
|
|
|
|
|
|
|
if (debug & DEBUG_REVIVECONFLICT)
|
1999-03-02 06:56:39 +00:00
|
|
|
log(LOG_DEBUG,
|
1999-05-15 05:49:21 +00:00
|
|
|
"Relaunch revive conflict sd %d: %x\n%s dev %d.%d, offset 0x%x, length %ld\n",
|
1999-01-21 00:40:03 +00:00
|
|
|
rq->sdno,
|
|
|
|
(u_int) rq,
|
|
|
|
rq->bp->b_flags & B_READ ? "Read" : "Write",
|
1999-05-15 05:49:21 +00:00
|
|
|
major(rq->bp->b_dev),
|
|
|
|
minor(rq->bp->b_dev),
|
1999-01-21 00:40:03 +00:00
|
|
|
rq->bp->b_blkno,
|
|
|
|
rq->bp->b_bcount);
|
|
|
|
#endif
|
|
|
|
launch_requests(sd->waitlist, 1); /* do them now */
|
|
|
|
sd->waitlist = sd->waitlist->next; /* and move on to the next */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bp->b_qindex == 0) /* not on a queue, */
|
|
|
|
brelse(bp); /* is this kosher? */
|
|
|
|
return error;
|
|
|
|
}
|
1999-09-28 22:57:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check or rebuild the parity blocks of a RAID-5
|
|
|
|
* plex.
|
|
|
|
*
|
|
|
|
* The variables plex->checkblock and
|
|
|
|
* plex->rebuildblock represent the
|
|
|
|
* subdisk-relative address of the stripe we're
|
|
|
|
* looking at, not the plex-relative address. We
|
|
|
|
* store it in the plex and not as a local
|
|
|
|
* variable because this function could be
|
|
|
|
* stopped, and we don't want to repeat the part
|
|
|
|
* we've already done. This is also the reason
|
|
|
|
* why we don't initialize it here except at the
|
|
|
|
* end. It gets initialized with the plex on
|
|
|
|
* creation.
|
|
|
|
*
|
|
|
|
* Each call to this function processes at most
|
|
|
|
* one stripe. We can't loop in this function,
|
|
|
|
* because we're unstoppable, so we have to be
|
|
|
|
* called repeatedly from userland.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
parityops(struct vinum_ioctl_msg *data, enum parityop op)
|
|
|
|
{
|
|
|
|
int plexno;
|
|
|
|
int s;
|
|
|
|
struct plex *plex;
|
|
|
|
int sdno;
|
|
|
|
int *tbuf; /* temporary buffer to read the stuff in to */
|
|
|
|
int *parity_buf; /* the address supplied by geteblk */
|
|
|
|
int size; /* I/O transfer size, bytes */
|
|
|
|
int mysize; /* I/O transfer size for this transfer */
|
|
|
|
int isize; /* mysize in ints */
|
|
|
|
int i;
|
|
|
|
int stripe; /* stripe number in plex */
|
|
|
|
int psd; /* parity subdisk number */
|
|
|
|
struct rangelock *lock; /* lock on stripe */
|
|
|
|
struct _ioctl_reply *reply;
|
|
|
|
u_int64_t *pstripe; /* pointer to our stripe counter */
|
|
|
|
struct buf **bpp; /* pointers to our bps */
|
|
|
|
|
|
|
|
plexno = data->index;
|
|
|
|
reply = (struct _ioctl_reply *) data;
|
|
|
|
reply->error = EAGAIN; /* expect to repeat this call */
|
|
|
|
reply->msg[0] = '\0';
|
|
|
|
plex = &PLEX[plexno];
|
|
|
|
if (plex->organization != plex_raid5) {
|
|
|
|
reply->error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (op == rebuildparity) /* point to our counter */
|
|
|
|
pstripe = &plex->rebuildblock;
|
|
|
|
else
|
|
|
|
pstripe = &plex->checkblock;
|
|
|
|
stripe = *pstripe / plex->stripesize; /* stripe number */
|
|
|
|
psd = plex->subdisks - 1 - stripe % plex->subdisks; /* parity subdisk for this stripe */
|
|
|
|
size = min(DEFAULT_REVIVE_BLOCKSIZE, /* one block at a time */
|
|
|
|
plex->stripesize << DEV_BSHIFT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It's possible that the default transfer
|
|
|
|
* size we chose is not a factor of the stripe
|
|
|
|
* size. We *must* limit this operation to a
|
|
|
|
* single stripe, at least for rebuild, since
|
|
|
|
* the parity subdisk changes between stripes,
|
|
|
|
* so in this case we need to perform a short
|
|
|
|
* transfer. Set variable mysize to reflect
|
|
|
|
* this.
|
|
|
|
*/
|
|
|
|
mysize = min(size, (plex->stripesize * (stripe + 1) - *pstripe) << DEV_BSHIFT);
|
|
|
|
isize = mysize / (sizeof(int)); /* number of ints in the buffer */
|
|
|
|
|
|
|
|
tbuf = (int *) Malloc(mysize * plex->subdisks); /* space for the whole stripe */
|
|
|
|
parity_buf = &tbuf[isize * psd]; /* this is the parity stripe */
|
|
|
|
if (op == rebuildparity)
|
|
|
|
bzero(parity_buf, mysize);
|
|
|
|
bpp = (struct buf **) Malloc(plex->subdisks * sizeof(struct buf *)); /* array of pointers to bps */
|
|
|
|
|
|
|
|
/* First, issue requests for all subdisks in parallel */
|
|
|
|
for (sdno = 0; sdno < plex->subdisks; sdno++) { /* for each subdisk */
|
|
|
|
/* Get a buffer header and initialize it. */
|
|
|
|
s = splbio();
|
|
|
|
bpp[sdno] = geteblk(mysize); /* Get a buffer */
|
|
|
|
if (bpp[sdno] == NULL) {
|
|
|
|
splx(s);
|
|
|
|
reply->error = ENOMEM;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (bpp[sdno]->b_qindex != 0) /* on a queue, */
|
|
|
|
bremfree(bpp[sdno]); /* remove it */
|
|
|
|
splx(s);
|
|
|
|
bpp[sdno]->b_data = (caddr_t) & tbuf[isize * sdno]; /* read into here */
|
|
|
|
bpp[sdno]->b_dev = VINUMRBDEV(plex->sdnos[sdno], /* device number */
|
|
|
|
VINUM_RAWSD_TYPE);
|
|
|
|
bpp[sdno]->b_flags = B_READ; /* either way, read it */
|
|
|
|
bpp[sdno]->b_bufsize = mysize;
|
|
|
|
bpp[sdno]->b_bcount = bpp[sdno]->b_bufsize;
|
|
|
|
bpp[sdno]->b_resid = bpp[sdno]->b_bcount;
|
|
|
|
bpp[sdno]->b_blkno = *pstripe; /* read from here */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now lock the stripe with the first non-parity
|
|
|
|
* bp as locking bp.
|
|
|
|
*/
|
|
|
|
lock = lockrange(stripe * plex->stripesize * (plex->subdisks - 1),
|
|
|
|
bpp[psd ? 0 : 1],
|
|
|
|
plex);
|
|
|
|
|
|
|
|
/* Then issue requests for all subdisks in parallel */
|
|
|
|
for (sdno = 0; sdno < plex->subdisks; sdno++) { /* for each subdisk */
|
|
|
|
if ((sdno != psd)
|
|
|
|
|| (op == checkparity)) {
|
|
|
|
BUF_LOCKINIT(bpp[sdno]); /* get a lock for the buffer */
|
|
|
|
BUF_LOCK(bpp[sdno], LK_EXCLUSIVE); /* and lock it */
|
|
|
|
sdio(bpp[sdno]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Next, wait for the requests to complete.
|
|
|
|
* We wait in the order in which they were
|
|
|
|
* issued, which isn't necessarily the order in
|
|
|
|
* which they complete, but we don't have a
|
|
|
|
* convenient way of doing the latter, and the
|
|
|
|
* delay is minimal.
|
|
|
|
*/
|
|
|
|
for (sdno = 0; sdno < plex->subdisks; sdno++) { /* for each subdisk */
|
|
|
|
if ((sdno != psd)
|
|
|
|
|| (op == checkparity)) {
|
|
|
|
biowait(bpp[sdno]);
|
|
|
|
if (bpp[sdno]->b_flags & B_ERROR) /* can't read, */
|
|
|
|
reply->error = bpp[sdno]->b_error;
|
|
|
|
brelse(bpp[sdno]); /* give back our resources */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, do the xors. We need to do this in
|
|
|
|
* a separate loop because we don't know when
|
|
|
|
* the parity stripe will be completed.
|
|
|
|
*/
|
|
|
|
for (sdno = 0; sdno < plex->subdisks; sdno++) { /* for each subdisk */
|
|
|
|
int *sbuf = &tbuf[isize * sdno];
|
|
|
|
|
|
|
|
if (sdno != psd) {
|
|
|
|
/*
|
|
|
|
* To save time, we do the XOR wordwise.
|
|
|
|
* This requires sectors to be a multiple
|
|
|
|
* of the length of an int, which is
|
|
|
|
* currently always the case.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < isize; i++)
|
|
|
|
((int *) parity_buf)[i] ^= sbuf[i]; /* xor in the buffer */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reply->error == EAGAIN) { /* no other error */
|
|
|
|
/*
|
|
|
|
* Finished building the parity block. Now
|
|
|
|
* decide what to do with it.
|
|
|
|
*/
|
|
|
|
if (op == checkparity) {
|
|
|
|
for (i = 0; i < isize; i++) {
|
|
|
|
if (((int *) parity_buf)[i] != 0) {
|
|
|
|
reply->error = EIO;
|
|
|
|
sprintf(reply->msg,
|
|
|
|
"Parity incorrect at offset 0x%lx\n",
|
|
|
|
(u_long) (*pstripe << DEV_BSHIFT) * (plex->subdisks - 1)
|
|
|
|
+ i * sizeof(int));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* rebuildparity */
|
|
|
|
s = splbio();
|
|
|
|
if (bpp[psd]->b_qindex != 0) /* on a queue, */
|
|
|
|
bremfree(bpp[psd]); /* remove it */
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
bpp[psd]->b_dev = VINUMRBDEV(psd, VINUM_RAWSD_TYPE); /* create the device number */
|
|
|
|
BUF_LOCKINIT(bpp[psd]); /* get a lock for the buffer */
|
|
|
|
BUF_LOCK(bpp[psd], LK_EXCLUSIVE); /* and lock it */
|
|
|
|
bpp[psd]->b_resid = bpp[psd]->b_bcount;
|
|
|
|
bpp[psd]->b_blkno = *pstripe; /* write it to here */
|
|
|
|
sdio(bpp[psd]); /* perform the I/O */
|
|
|
|
biowait(bpp[psd]);
|
|
|
|
brelse(bpp[psd]);
|
|
|
|
}
|
|
|
|
if (bpp[psd]->b_flags & B_ERROR)
|
|
|
|
reply->error = bpp[psd]->b_error;
|
|
|
|
if (reply->error == EAGAIN) { /* still OK, */
|
|
|
|
*pstripe += mysize >> DEV_BSHIFT; /* moved this much further down */
|
|
|
|
if (*pstripe >= SD[plex->sdnos[0]].sectors) { /* finished */
|
|
|
|
*pstripe = 0;
|
|
|
|
reply->error = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* release our resources */
|
|
|
|
unlockrange(plexno, lock);
|
|
|
|
Free(bpp);
|
|
|
|
Free(tbuf);
|
|
|
|
}
|
|
|
|
|
1999-08-24 02:28:37 +00:00
|
|
|
/* Local Variables: */
|
|
|
|
/* fill-column: 50 */
|
|
|
|
/* End: */
|