1998-12-28 04:56:24 +00:00
|
|
|
/*-
|
2000-05-11 07:25:36 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999
|
1999-08-07 08:13:23 +00:00
|
|
|
* Nan Yang Computer Services Limited. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2000-01-05 06:10:52 +00:00
|
|
|
* $Id: vinumrequest.c,v 1.26 1999/12/30 07:38:33 grog Exp grog $
|
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
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
|
|
|
|
enum requeststatus bre(struct request *rq,
|
|
|
|
int plexno,
|
|
|
|
daddr_t * diskstart,
|
|
|
|
daddr_t diskend);
|
|
|
|
enum requeststatus bre5(struct request *rq,
|
|
|
|
int plexno,
|
|
|
|
daddr_t * diskstart,
|
|
|
|
daddr_t diskend);
|
|
|
|
enum requeststatus build_read_request(struct request *rq, int volplexno);
|
|
|
|
enum requeststatus build_write_request(struct request *rq);
|
|
|
|
enum requeststatus build_rq_buffer(struct rqelement *rqe, struct plex *plex);
|
|
|
|
int find_alternate_sd(struct request *rq);
|
|
|
|
int check_range_covered(struct request *);
|
|
|
|
void complete_rqe(struct buf *bp);
|
|
|
|
void complete_raid5_write(struct rqelement *);
|
|
|
|
int abortrequest(struct request *rq, int error);
|
|
|
|
void sdio_done(struct buf *bp);
|
|
|
|
int vinum_bounds_check(struct buf *bp, struct volume *vol);
|
|
|
|
caddr_t allocdatabuf(struct rqelement *rqe);
|
|
|
|
void freedatabuf(struct rqelement *rqe);
|
|
|
|
|
1998-12-28 16:28:24 +00:00
|
|
|
#ifdef VINUMDEBUG
|
1998-12-28 04:56:24 +00:00
|
|
|
struct rqinfo rqinfo[RQINFO_SIZE];
|
|
|
|
struct rqinfo *rqip = rqinfo;
|
|
|
|
|
1999-08-24 02:17:42 +00:00
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
logrq(enum rqinfo_type type, union rqinfou info, struct buf *ubp)
|
|
|
|
{
|
|
|
|
int s = splhigh();
|
|
|
|
|
|
|
|
microtime(&rqip->timestamp); /* when did this happen? */
|
|
|
|
rqip->type = type;
|
|
|
|
rqip->bp = ubp; /* user buffer */
|
|
|
|
switch (type) {
|
|
|
|
case loginfo_user_bp:
|
|
|
|
case loginfo_user_bpl:
|
1999-08-24 02:17:42 +00:00
|
|
|
case loginfo_sdio: /* subdisk I/O */
|
|
|
|
case loginfo_sdiol: /* subdisk I/O launch */
|
1999-09-28 22:56:54 +00:00
|
|
|
case loginfo_sdiodone: /* subdisk I/O complete */
|
1998-12-28 04:56:24 +00:00
|
|
|
bcopy(info.bp, &rqip->info.b, sizeof(struct buf));
|
1999-08-07 08:13:23 +00:00
|
|
|
rqip->devmajor = major(info.bp->b_dev);
|
|
|
|
rqip->devminor = minor(info.bp->b_dev);
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case loginfo_iodone:
|
|
|
|
case loginfo_rqe:
|
|
|
|
case loginfo_raid5_data:
|
|
|
|
case loginfo_raid5_parity:
|
|
|
|
bcopy(info.rqe, &rqip->info.rqe, sizeof(struct rqelement));
|
1999-08-07 08:13:23 +00:00
|
|
|
rqip->devmajor = major(info.rqe->b.b_dev);
|
|
|
|
rqip->devminor = minor(info.rqe->b.b_dev);
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
1999-08-14 06:30:15 +00:00
|
|
|
case loginfo_lockwait:
|
|
|
|
case loginfo_lock:
|
|
|
|
case loginfo_unlock:
|
|
|
|
bcopy(info.lockinfo, &rqip->info.lockinfo, sizeof(struct rangelock));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
1998-12-28 04:56:24 +00:00
|
|
|
case loginfo_unused:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rqip++;
|
|
|
|
if (rqip >= &rqinfo[RQINFO_SIZE]) /* wrap around */
|
|
|
|
rqip = rqinfo;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1999-08-24 02:17:42 +00:00
|
|
|
void
|
2000-05-04 07:44:23 +00:00
|
|
|
vinumstrategy(struct bio *biop)
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
2000-05-04 07:44:23 +00:00
|
|
|
struct buf *bp = (struct buf *) biop;
|
1998-12-28 04:56:24 +00:00
|
|
|
int volno;
|
|
|
|
struct volume *vol = NULL;
|
|
|
|
|
1999-05-15 05:49:21 +00:00
|
|
|
switch (DEVTYPE(bp->b_dev)) {
|
1998-12-28 04:56:24 +00:00
|
|
|
case VINUM_SD_TYPE:
|
1999-01-21 00:39:36 +00:00
|
|
|
case VINUM_RAWSD_TYPE:
|
1998-12-28 04:56:24 +00:00
|
|
|
sdio(bp);
|
|
|
|
return;
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* In fact, vinum doesn't handle drives: they're
|
1999-02-05 05:09:22 +00:00
|
|
|
* handled directly by the disk drivers
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
case VINUM_DRIVE_TYPE:
|
|
|
|
default:
|
|
|
|
bp->b_error = EIO; /* I/O error */
|
2000-05-04 07:44:23 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case VINUM_VOLUME_TYPE: /* volume I/O */
|
1999-01-21 00:39:36 +00:00
|
|
|
volno = Volno(bp->b_dev);
|
1998-12-28 04:56:24 +00:00
|
|
|
vol = &VOL[volno];
|
|
|
|
if (vol->state != volume_up) { /* can't access this volume */
|
|
|
|
bp->b_error = EIO; /* I/O error */
|
2000-05-04 07:44:23 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (vinum_bounds_check(bp, vol) <= 0) { /* don't like them bounds */
|
2000-05-04 07:44:23 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Plex I/O is pretty much the same as volume I/O
|
1998-12-28 04:56:24 +00:00
|
|
|
* for a single plex. Indicate this by passing a NULL
|
1999-02-05 05:09:22 +00:00
|
|
|
* pointer (set above) for the volume
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
case VINUM_PLEX_TYPE:
|
1999-01-21 00:39:36 +00:00
|
|
|
case VINUM_RAWPLEX_TYPE:
|
1998-12-28 04:56:24 +00:00
|
|
|
bp->b_resid = bp->b_bcount; /* transfer everything */
|
|
|
|
vinumstart(bp, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Start a transfer. Return -1 on error,
|
1998-12-28 04:56:24 +00:00
|
|
|
* 0 if OK, 1 if we need to retry.
|
|
|
|
* Parameter reviveok is set when doing
|
|
|
|
* transfers for revives: it allows transfers to
|
|
|
|
* be started immediately when a revive is in
|
|
|
|
* progress. During revive, normal transfers
|
|
|
|
* are queued if they share address space with
|
1999-02-05 05:09:22 +00:00
|
|
|
* a currently active revive operation.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-24 02:17:42 +00:00
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
vinumstart(struct buf *bp, int reviveok)
|
|
|
|
{
|
|
|
|
int plexno;
|
|
|
|
int maxplex; /* maximum number of plexes to handle */
|
|
|
|
struct volume *vol;
|
|
|
|
struct request *rq; /* build up our request here */
|
|
|
|
enum requeststatus status;
|
|
|
|
|
1998-12-28 16:28:24 +00:00
|
|
|
#if VINUMDEBUG
|
1998-12-28 04:56:24 +00:00
|
|
|
if (debug & DEBUG_LASTREQS)
|
1999-03-18 23:26:22 +00:00
|
|
|
logrq(loginfo_user_bp, (union rqinfou) bp, bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((bp->b_bcount % DEV_BSIZE) != 0) { /* bad length */
|
|
|
|
bp->b_error = EINVAL; /* invalid size */
|
2000-05-04 07:44:23 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
rq = (struct request *) Malloc(sizeof(struct request)); /* allocate a request struct */
|
|
|
|
if (rq == NULL) { /* can't do it */
|
|
|
|
bp->b_error = ENOMEM; /* can't get memory */
|
2000-05-04 07:44:23 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
bzero(rq, sizeof(struct request));
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Note the volume ID. This can be NULL, which
|
1998-12-28 04:56:24 +00:00
|
|
|
* the request building functions use as an
|
1999-02-05 05:09:22 +00:00
|
|
|
* indication for single plex I/O
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
rq->bp = bp; /* and the user buffer struct */
|
|
|
|
|
|
|
|
if (DEVTYPE(bp->b_dev) == VINUM_VOLUME_TYPE) { /* it's a volume, */
|
1999-01-21 00:39:36 +00:00
|
|
|
rq->volplex.volno = Volno(bp->b_dev); /* get the volume number */
|
1998-12-28 04:56:24 +00:00
|
|
|
vol = &VOL[rq->volplex.volno]; /* and point to it */
|
|
|
|
vol->active++; /* one more active request */
|
|
|
|
maxplex = vol->plexes; /* consider all its plexes */
|
|
|
|
} else {
|
|
|
|
vol = NULL; /* no volume */
|
1999-01-21 00:39:36 +00:00
|
|
|
rq->volplex.plexno = Plexno(bp->b_dev); /* point to the plex */
|
1998-12-28 04:56:24 +00:00
|
|
|
rq->isplex = 1; /* note that it's a plex */
|
|
|
|
maxplex = 1; /* just the one plex */
|
|
|
|
}
|
|
|
|
|
2000-03-20 10:44:49 +00:00
|
|
|
if (bp->b_iocmd == BIO_READ) {
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* This is a read request. Decide
|
1998-12-28 04:56:24 +00:00
|
|
|
* which plex to read from.
|
|
|
|
*
|
|
|
|
* There's a potential race condition here,
|
|
|
|
* since we're not locked, and we could end
|
|
|
|
* up multiply incrementing the round-robin
|
|
|
|
* counter. This doesn't have any serious
|
1999-02-05 05:09:22 +00:00
|
|
|
* effects, however.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
if (vol != NULL) {
|
|
|
|
plexno = vol->preferred_plex; /* get the plex to use */
|
|
|
|
if (plexno < 0) { /* round robin */
|
|
|
|
plexno = vol->last_plex_read;
|
|
|
|
vol->last_plex_read++;
|
1999-08-14 06:30:15 +00:00
|
|
|
if (vol->last_plex_read >= vol->plexes) /* got the the end? */
|
1998-12-28 04:56:24 +00:00
|
|
|
vol->last_plex_read = 0; /* wrap around */
|
|
|
|
}
|
|
|
|
status = build_read_request(rq, plexno); /* build a request */
|
|
|
|
} else {
|
|
|
|
daddr_t diskaddr = bp->b_blkno; /* start offset of transfer */
|
|
|
|
status = bre(rq, /* build a request list */
|
|
|
|
rq->volplex.plexno,
|
|
|
|
&diskaddr,
|
|
|
|
diskaddr + (bp->b_bcount / DEV_BSIZE));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((status > REQUEST_RECOVERED) /* can't satisfy it */
|
|
|
|
||(bp->b_flags & B_DONE)) { /* XXX shouldn't get this without bad status */
|
|
|
|
if (status == REQUEST_DOWN) { /* not enough subdisks */
|
|
|
|
bp->b_error = EIO; /* I/O error */
|
2000-05-04 07:44:23 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
freerq(rq);
|
|
|
|
return -1;
|
|
|
|
}
|
1999-03-19 07:15:24 +00:00
|
|
|
return launch_requests(rq, reviveok); /* now start the requests if we can */
|
1998-12-28 04:56:24 +00:00
|
|
|
} else
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
2000-02-29 06:14:44 +00:00
|
|
|
* This is a write operation. We write to all plexes. If this is
|
|
|
|
* a RAID-4 or RAID-5 plex, we must also update the parity stripe.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
{
|
2000-05-04 07:44:23 +00:00
|
|
|
if (vol != NULL)
|
1998-12-28 04:56:24 +00:00
|
|
|
status = build_write_request(rq); /* Not all the subdisks are up */
|
2000-05-04 07:44:23 +00:00
|
|
|
else { /* plex I/O */
|
1998-12-28 04:56:24 +00:00
|
|
|
daddr_t diskstart;
|
|
|
|
|
|
|
|
diskstart = bp->b_blkno; /* start offset of transfer */
|
|
|
|
status = bre(rq,
|
1999-01-21 00:39:36 +00:00
|
|
|
Plexno(bp->b_dev),
|
1998-12-28 04:56:24 +00:00
|
|
|
&diskstart,
|
|
|
|
bp->b_blkno + (bp->b_bcount / DEV_BSIZE)); /* build requests for the plex */
|
|
|
|
}
|
|
|
|
if ((status > REQUEST_RECOVERED) /* can't satisfy it */
|
|
|
|
||(bp->b_flags & B_DONE)) { /* XXX shouldn't get this without bad status */
|
|
|
|
if (status == REQUEST_DOWN) { /* not enough subdisks */
|
|
|
|
bp->b_error = EIO; /* I/O error */
|
2000-05-04 07:44:23 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
if ((bp->b_flags & B_DONE) == 0)
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
freerq(rq);
|
|
|
|
return -1;
|
|
|
|
}
|
1999-01-21 00:39:36 +00:00
|
|
|
return launch_requests(rq, reviveok); /* now start the requests if we can */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Call the low-level strategy routines to
|
1999-02-05 05:09:22 +00:00
|
|
|
* perform the requests in a struct request
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-24 02:17:42 +00:00
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
launch_requests(struct request *rq, int reviveok)
|
|
|
|
{
|
|
|
|
struct rqgroup *rqg;
|
|
|
|
int rqno; /* loop index */
|
|
|
|
struct rqelement *rqe; /* current element */
|
1999-10-13 03:19:31 +00:00
|
|
|
struct drive *drive;
|
2000-01-05 06:10:52 +00:00
|
|
|
int rcount; /* request count */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* First find out whether we're reviving, and the
|
1998-12-28 04:56:24 +00:00
|
|
|
* request contains a conflict. If so, we hang
|
|
|
|
* the request off plex->waitlist of the first
|
1999-02-05 05:09:22 +00:00
|
|
|
* plex we find which is reviving
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
2000-05-04 07:44:23 +00:00
|
|
|
|
1998-12-28 04:56:24 +00:00
|
|
|
if ((rq->flags & XFR_REVIVECONFLICT) /* possible revive conflict */
|
|
|
|
&&(!reviveok)) { /* and we don't want to do it now, */
|
1999-01-21 00:39:36 +00:00
|
|
|
struct sd *sd;
|
|
|
|
struct request *waitlist; /* point to the waitlist */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
1999-01-21 00:39:36 +00:00
|
|
|
sd = &SD[rq->sdno];
|
|
|
|
if (sd->waitlist != NULL) { /* something there already, */
|
|
|
|
waitlist = sd->waitlist;
|
1998-12-28 04:56:24 +00:00
|
|
|
while (waitlist->next != NULL) /* find the end */
|
|
|
|
waitlist = waitlist->next;
|
|
|
|
waitlist->next = rq; /* hook our request there */
|
1999-01-21 00:39:36 +00:00
|
|
|
} else
|
|
|
|
sd->waitlist = rq; /* hook our request at the front */
|
|
|
|
|
|
|
|
#if VINUMDEBUG
|
|
|
|
if (debug & DEBUG_REVIVECONFLICT)
|
1999-03-02 06:56:39 +00:00
|
|
|
log(LOG_DEBUG,
|
2000-01-05 06:10:52 +00:00
|
|
|
"Revive conflict sd %d: %p\n%s dev %d.%d, offset 0x%x, length %ld\n",
|
1999-01-21 00:39:36 +00:00
|
|
|
rq->sdno,
|
2000-01-05 06:10:52 +00:00
|
|
|
rq,
|
2000-03-20 10:44:49 +00:00
|
|
|
rq->bp->b_iocmd == BIO_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:39:36 +00:00
|
|
|
rq->bp->b_blkno,
|
1999-08-14 06:30:15 +00:00
|
|
|
rq->bp->b_bcount);
|
1999-01-21 00:39:36 +00:00
|
|
|
#endif
|
|
|
|
return 0; /* and get out of here */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
rq->active = 0; /* nothing yet */
|
1998-12-28 16:28:24 +00:00
|
|
|
#if VINUMDEBUG
|
1998-12-28 04:56:24 +00:00
|
|
|
if (debug & DEBUG_ADDRESSES)
|
1999-03-02 06:56:39 +00:00
|
|
|
log(LOG_DEBUG,
|
2000-01-05 06:10:52 +00:00
|
|
|
"Request: %p\n%s dev %d.%d, offset 0x%x, length %ld\n",
|
|
|
|
rq,
|
2000-03-20 10:44:49 +00:00
|
|
|
rq->bp->b_iocmd == BIO_READ ? "Read" : "Write",
|
1999-05-15 05:49:21 +00:00
|
|
|
major(rq->bp->b_dev),
|
|
|
|
minor(rq->bp->b_dev),
|
1998-12-28 04:56:24 +00:00
|
|
|
rq->bp->b_blkno,
|
1999-08-14 06:30:15 +00:00
|
|
|
rq->bp->b_bcount);
|
2000-01-05 06:10:52 +00:00
|
|
|
vinum_conf.lastrq = rq;
|
1998-12-28 04:56:24 +00:00
|
|
|
vinum_conf.lastbuf = rq->bp;
|
|
|
|
if (debug & DEBUG_LASTREQS)
|
1999-03-18 23:26:22 +00:00
|
|
|
logrq(loginfo_user_bpl, (union rqinfou) rq->bp, rq->bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
#endif
|
1999-10-13 03:19:31 +00:00
|
|
|
|
|
|
|
/*
|
2000-05-04 07:44:23 +00:00
|
|
|
* We used to have an splbio() here anyway, out
|
|
|
|
* of superstition. With the division of labour
|
|
|
|
* below (first count the requests, then issue
|
|
|
|
* them), it looks as if we don't need this
|
|
|
|
* splbio() protection. In fact, as dillon
|
|
|
|
* points out, there's a race condition
|
|
|
|
* incrementing and decrementing rq->active and
|
|
|
|
* rqg->active. This splbio() didn't help
|
|
|
|
* there, because the device strategy routine
|
|
|
|
* can sleep. Solve this by putting shorter
|
|
|
|
* duration locks on the code.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This loop happens without any participation
|
|
|
|
* of the bottom half, so it requires no
|
|
|
|
* protection.
|
1999-10-13 03:19:31 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
for (rqg = rq->rqg; rqg != NULL; rqg = rqg->next) { /* through the whole request chain */
|
|
|
|
rqg->active = rqg->count; /* they're all active */
|
|
|
|
for (rqno = 0; rqno < rqg->count; rqno++) {
|
|
|
|
rqe = &rqg->rqe[rqno];
|
|
|
|
if (rqe->flags & XFR_BAD_SUBDISK) /* this subdisk is bad, */
|
|
|
|
rqg->active--; /* one less active request */
|
1999-10-13 03:19:31 +00:00
|
|
|
}
|
|
|
|
if (rqg->active) /* we have at least one active request, */
|
|
|
|
rq->active++; /* one more active request group */
|
|
|
|
}
|
|
|
|
|
2000-05-04 07:44:23 +00:00
|
|
|
/*
|
|
|
|
* Now fire off the requests. In this loop the
|
|
|
|
* bottom half could be completing requests
|
|
|
|
* before we finish, so we need splbio() protection.
|
|
|
|
*/
|
2000-01-05 06:10:52 +00:00
|
|
|
for (rqg = rq->rqg; rqg != NULL;) { /* through the whole request chain */
|
|
|
|
if (rqg->lockbase >= 0) /* this rqg needs a lock first */
|
|
|
|
rqg->lock = lockrange(rqg->lockbase, rqg->rq->bp, &PLEX[rqg->plexno]);
|
|
|
|
rcount = rqg->count;
|
|
|
|
for (rqno = 0; rqno < rcount;) {
|
1999-10-13 03:19:31 +00:00
|
|
|
rqe = &rqg->rqe[rqno];
|
2000-01-05 06:10:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Point to next rqg before the bottom end
|
|
|
|
* changes the structures.
|
|
|
|
*/
|
|
|
|
if (++rqno >= rcount)
|
|
|
|
rqg = rqg->next;
|
1999-10-13 03:19:31 +00:00
|
|
|
if ((rqe->flags & XFR_BAD_SUBDISK) == 0) { /* this subdisk is good, */
|
|
|
|
drive = &DRIVE[rqe->driveno]; /* look at drive */
|
|
|
|
drive->active++;
|
|
|
|
if (drive->active >= drive->maxactive)
|
|
|
|
drive->maxactive = drive->active;
|
|
|
|
vinum_conf.active++;
|
|
|
|
if (vinum_conf.active >= vinum_conf.maxactive)
|
|
|
|
vinum_conf.maxactive = vinum_conf.active;
|
|
|
|
|
2000-05-04 07:44:23 +00:00
|
|
|
#ifdef VINUMDEBUG
|
1998-12-28 04:56:24 +00:00
|
|
|
if (debug & DEBUG_ADDRESSES)
|
1999-03-02 06:56:39 +00:00
|
|
|
log(LOG_DEBUG,
|
1999-05-15 05:49:21 +00:00
|
|
|
" %s dev %d.%d, sd %d, offset 0x%x, devoffset 0x%x, length %ld\n",
|
2000-03-20 10:44:49 +00:00
|
|
|
rqe->b.b_iocmd == BIO_READ ? "Read" : "Write",
|
1999-05-15 05:49:21 +00:00
|
|
|
major(rqe->b.b_dev),
|
|
|
|
minor(rqe->b.b_dev),
|
1998-12-28 04:56:24 +00:00
|
|
|
rqe->sdno,
|
|
|
|
(u_int) (rqe->b.b_blkno - SD[rqe->sdno].driveoffset),
|
|
|
|
rqe->b.b_blkno,
|
1999-08-14 06:30:15 +00:00
|
|
|
rqe->b.b_bcount);
|
1998-12-28 04:56:24 +00:00
|
|
|
if (debug & DEBUG_LASTREQS)
|
1999-03-18 23:26:22 +00:00
|
|
|
logrq(loginfo_rqe, (union rqinfou) rqe, rq->bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
#endif
|
|
|
|
/* fire off the request */
|
2000-03-20 11:29:10 +00:00
|
|
|
DEV_STRATEGY(&rqe->b, 0);
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* define the low-level requests needed to perform a
|
1998-12-28 04:56:24 +00:00
|
|
|
* high-level I/O operation for a specific plex 'plexno'.
|
|
|
|
*
|
1999-08-07 08:13:23 +00:00
|
|
|
* Return REQUEST_OK if all subdisks involved in the request are up,
|
|
|
|
* REQUEST_DOWN if some subdisks are not up, and REQUEST_EOF if the
|
|
|
|
* request is at least partially outside the bounds of the subdisks.
|
1998-12-28 04:56:24 +00:00
|
|
|
*
|
|
|
|
* Modify the pointer *diskstart to point to the end address. On
|
|
|
|
* read, return on the first bad subdisk, so that the caller
|
|
|
|
* (build_read_request) can try alternatives.
|
|
|
|
*
|
|
|
|
* On entry to this routine, the rqg structures are not assigned. The
|
|
|
|
* assignment is performed by expandrq(). Strictly speaking, the
|
|
|
|
* elements rqe->sdno of all entries should be set to -1, since 0
|
|
|
|
* (from bzero) is a valid subdisk number. We avoid this problem by
|
|
|
|
* initializing the ones we use, and not looking at the others (index
|
|
|
|
* >= rqg->requests).
|
|
|
|
*/
|
1999-08-24 02:17:42 +00:00
|
|
|
enum requeststatus
|
1998-12-28 04:56:24 +00:00
|
|
|
bre(struct request *rq,
|
|
|
|
int plexno,
|
|
|
|
daddr_t * diskaddr,
|
|
|
|
daddr_t diskend)
|
|
|
|
{
|
|
|
|
int sdno;
|
|
|
|
struct sd *sd;
|
|
|
|
struct rqgroup *rqg;
|
|
|
|
struct buf *bp; /* user's bp */
|
|
|
|
struct plex *plex;
|
|
|
|
enum requeststatus status; /* return value */
|
|
|
|
daddr_t plexoffset; /* offset of transfer in plex */
|
|
|
|
daddr_t stripebase; /* base address of stripe (1st subdisk) */
|
|
|
|
daddr_t stripeoffset; /* offset in stripe */
|
|
|
|
daddr_t blockoffset; /* offset in stripe on subdisk */
|
|
|
|
struct rqelement *rqe; /* point to this request information */
|
|
|
|
daddr_t diskstart = *diskaddr; /* remember where this transfer starts */
|
1999-08-07 08:13:23 +00:00
|
|
|
enum requeststatus s; /* temp return value */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
bp = rq->bp; /* buffer pointer */
|
|
|
|
status = REQUEST_OK; /* return value: OK until proven otherwise */
|
|
|
|
plex = &PLEX[plexno]; /* point to the plex */
|
|
|
|
|
|
|
|
switch (plex->organization) {
|
|
|
|
case plex_concat:
|
1999-08-07 08:13:23 +00:00
|
|
|
sd = NULL; /* (keep compiler quiet) */
|
1998-12-28 04:56:24 +00:00
|
|
|
for (sdno = 0; sdno < plex->subdisks; sdno++) {
|
|
|
|
sd = &SD[plex->sdnos[sdno]];
|
1999-08-07 08:13:23 +00:00
|
|
|
if (*diskaddr < sd->plexoffset) /* we must have a hole, */
|
|
|
|
status = REQUEST_DEGRADED; /* note the fact */
|
|
|
|
if (*diskaddr < (sd->plexoffset + sd->sectors)) { /* the request starts in this subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
rqg = allocrqg(rq, 1); /* space for the request */
|
|
|
|
if (rqg == NULL) { /* malloc failed */
|
|
|
|
bp->b_error = ENOMEM;
|
2000-05-11 07:25:36 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return REQUEST_ENOMEM;
|
|
|
|
}
|
|
|
|
rqg->plexno = plexno;
|
|
|
|
|
|
|
|
rqe = &rqg->rqe[0]; /* point to the element */
|
|
|
|
rqe->rqg = rqg; /* group */
|
|
|
|
rqe->sdno = sd->sdno; /* put in the subdisk number */
|
1999-08-07 08:13:23 +00:00
|
|
|
plexoffset = *diskaddr; /* start offset in plex */
|
1998-12-28 04:56:24 +00:00
|
|
|
rqe->sdoffset = plexoffset - sd->plexoffset; /* start offset in subdisk */
|
|
|
|
rqe->useroffset = plexoffset - diskstart; /* start offset in user buffer */
|
|
|
|
rqe->dataoffset = 0;
|
|
|
|
rqe->datalen = min(diskend - *diskaddr, /* number of sectors to transfer in this sd */
|
|
|
|
sd->sectors - rqe->sdoffset);
|
|
|
|
rqe->groupoffset = 0; /* no groups for concatenated plexes */
|
|
|
|
rqe->grouplen = 0;
|
|
|
|
rqe->buflen = rqe->datalen; /* buffer length is data buffer length */
|
|
|
|
rqe->flags = 0;
|
|
|
|
rqe->driveno = sd->driveno;
|
1999-08-07 08:13:23 +00:00
|
|
|
if (sd->state != sd_up) { /* *now* we find the sd is down */
|
|
|
|
s = checksdstate(sd, rq, *diskaddr, diskend); /* do we need to change state? */
|
|
|
|
if (s == REQUEST_DOWN) { /* down? */
|
1999-08-14 06:30:15 +00:00
|
|
|
rqe->flags = XFR_BAD_SUBDISK; /* yup */
|
2000-05-11 07:25:36 +00:00
|
|
|
if (rq->bp->b_iocmd == BIO_READ) /* read request, */
|
1999-08-07 08:13:23 +00:00
|
|
|
return REQUEST_DEGRADED; /* give up here */
|
|
|
|
/*
|
|
|
|
* If we're writing, don't give up
|
|
|
|
* because of a bad subdisk. Go
|
|
|
|
* through to the bitter end, but note
|
|
|
|
* which ones we can't access.
|
|
|
|
*/
|
|
|
|
status = REQUEST_DEGRADED; /* can't do it all */
|
|
|
|
}
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
*diskaddr += rqe->datalen; /* bump the address */
|
1999-08-14 06:30:15 +00:00
|
|
|
if (build_rq_buffer(rqe, plex)) { /* build the buffer */
|
|
|
|
deallocrqg(rqg);
|
|
|
|
bp->b_error = ENOMEM;
|
2000-05-11 07:25:36 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1999-08-14 06:30:15 +00:00
|
|
|
return REQUEST_ENOMEM; /* can't do it */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
1999-08-07 08:13:23 +00:00
|
|
|
if (*diskaddr == diskend) /* we're finished, */
|
1998-12-28 04:56:24 +00:00
|
|
|
break; /* get out of here */
|
|
|
|
}
|
1999-08-07 08:13:23 +00:00
|
|
|
/*
|
|
|
|
* We've got to the end of the plex. Have we got to the end of
|
|
|
|
* the transfer? It would seem that having an offset beyond the
|
|
|
|
* end of the subdisk is an error, but in fact it can happen if
|
|
|
|
* the volume has another plex of different size. There's a valid
|
|
|
|
* question as to why you would want to do this, but currently
|
|
|
|
* it's allowed.
|
|
|
|
*
|
|
|
|
* In a previous version, I returned REQUEST_DOWN here. I think
|
|
|
|
* REQUEST_EOF is more appropriate now.
|
|
|
|
*/
|
|
|
|
if (diskend > sd->sectors + sd->plexoffset) /* pointing beyond EOF? */
|
|
|
|
status = REQUEST_EOF;
|
1998-12-28 04:56:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case plex_striped:
|
|
|
|
{
|
|
|
|
while (*diskaddr < diskend) { /* until we get it all sorted out */
|
1999-08-07 08:13:23 +00:00
|
|
|
if (*diskaddr >= plex->length) /* beyond the end of the plex */
|
|
|
|
return REQUEST_EOF; /* can't continue */
|
|
|
|
|
|
|
|
/* The offset of the start address from the start of the stripe. */
|
1998-12-28 04:56:24 +00:00
|
|
|
stripeoffset = *diskaddr % (plex->stripesize * plex->subdisks);
|
|
|
|
|
1999-08-07 08:13:23 +00:00
|
|
|
/* The plex-relative address of the start of the stripe. */
|
1998-12-28 04:56:24 +00:00
|
|
|
stripebase = *diskaddr - stripeoffset;
|
|
|
|
|
1999-08-07 08:13:23 +00:00
|
|
|
/* The number of the subdisk in which the start is located. */
|
1998-12-28 04:56:24 +00:00
|
|
|
sdno = stripeoffset / plex->stripesize;
|
|
|
|
|
1999-08-07 08:13:23 +00:00
|
|
|
/* The offset from the beginning of the stripe on this subdisk. */
|
1998-12-28 04:56:24 +00:00
|
|
|
blockoffset = stripeoffset % plex->stripesize;
|
|
|
|
|
|
|
|
sd = &SD[plex->sdnos[sdno]]; /* the subdisk in question */
|
|
|
|
rqg = allocrqg(rq, 1); /* space for the request */
|
|
|
|
if (rqg == NULL) { /* malloc failed */
|
|
|
|
bp->b_error = ENOMEM;
|
2000-05-11 07:25:36 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return REQUEST_ENOMEM;
|
|
|
|
}
|
|
|
|
rqg->plexno = plexno;
|
|
|
|
|
|
|
|
rqe = &rqg->rqe[0]; /* point to the element */
|
|
|
|
rqe->rqg = rqg;
|
|
|
|
rqe->sdoffset = stripebase / plex->subdisks + blockoffset; /* start offset in this subdisk */
|
|
|
|
rqe->useroffset = *diskaddr - diskstart; /* The offset of the start in the user buffer */
|
|
|
|
rqe->dataoffset = 0;
|
|
|
|
rqe->datalen = min(diskend - *diskaddr, /* the amount remaining to transfer */
|
|
|
|
plex->stripesize - blockoffset); /* and the amount left in this stripe */
|
|
|
|
rqe->groupoffset = 0; /* no groups for striped plexes */
|
|
|
|
rqe->grouplen = 0;
|
|
|
|
rqe->buflen = rqe->datalen; /* buffer length is data buffer length */
|
|
|
|
rqe->flags = 0;
|
|
|
|
rqe->sdno = sd->sdno; /* put in the subdisk number */
|
|
|
|
rqe->driveno = sd->driveno;
|
|
|
|
|
1999-08-07 08:13:23 +00:00
|
|
|
if (sd->state != sd_up) { /* *now* we find the sd is down */
|
|
|
|
s = checksdstate(sd, rq, *diskaddr, diskend); /* do we need to change state? */
|
|
|
|
if (s == REQUEST_DOWN) { /* down? */
|
1999-08-14 06:30:15 +00:00
|
|
|
rqe->flags = XFR_BAD_SUBDISK; /* yup */
|
2000-05-11 07:25:36 +00:00
|
|
|
if (rq->bp->b_iocmd == BIO_READ) /* read request, */
|
1999-08-07 08:13:23 +00:00
|
|
|
return REQUEST_DEGRADED; /* give up here */
|
|
|
|
/*
|
|
|
|
* If we're writing, don't give up
|
|
|
|
* because of a bad subdisk. Go through
|
|
|
|
* to the bitter end, but note which
|
|
|
|
* ones we can't access.
|
|
|
|
*/
|
|
|
|
status = REQUEST_DEGRADED; /* can't do it all */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* It would seem that having an offset
|
|
|
|
* beyond the end of the subdisk is an
|
|
|
|
* error, but in fact it can happen if the
|
|
|
|
* volume has another plex of different
|
|
|
|
* size. There's a valid question as to why
|
|
|
|
* you would want to do this, but currently
|
|
|
|
* it's allowed.
|
|
|
|
*/
|
|
|
|
if (rqe->sdoffset + rqe->datalen > sd->sectors) { /* ends beyond the end of the subdisk? */
|
|
|
|
rqe->datalen = sd->sectors - rqe->sdoffset; /* truncate */
|
1999-03-13 07:38:27 +00:00
|
|
|
#if VINUMDEBUG
|
|
|
|
if (debug & DEBUG_EOFINFO) { /* tell on the request */
|
|
|
|
log(LOG_DEBUG,
|
|
|
|
"vinum: EOF on plex %s, sd %s offset %x (user offset %x)\n",
|
|
|
|
plex->name,
|
|
|
|
sd->name,
|
|
|
|
(u_int) sd->sectors,
|
|
|
|
bp->b_blkno);
|
|
|
|
log(LOG_DEBUG,
|
|
|
|
"vinum: stripebase %x, stripeoffset %x, blockoffset %x\n",
|
|
|
|
stripebase,
|
|
|
|
stripeoffset,
|
|
|
|
blockoffset);
|
|
|
|
}
|
|
|
|
#endif
|
1999-08-07 08:13:23 +00:00
|
|
|
}
|
1999-08-14 06:30:15 +00:00
|
|
|
if (build_rq_buffer(rqe, plex)) { /* build the buffer */
|
|
|
|
deallocrqg(rqg);
|
|
|
|
bp->b_error = ENOMEM;
|
2000-05-11 07:25:36 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1999-08-14 06:30:15 +00:00
|
|
|
return REQUEST_ENOMEM; /* can't do it */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
*diskaddr += rqe->datalen; /* look at the remainder */
|
1999-08-07 08:13:23 +00:00
|
|
|
if ((*diskaddr < diskend) /* didn't finish the request on this stripe */
|
|
|
|
&&(*diskaddr < plex->length)) { /* and there's more to come */
|
1998-12-28 04:56:24 +00:00
|
|
|
plex->multiblock++; /* count another one */
|
|
|
|
if (sdno == plex->subdisks - 1) /* last subdisk, */
|
|
|
|
plex->multistripe++; /* another stripe as well */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-08-07 08:13:23 +00:00
|
|
|
/*
|
2000-02-29 06:14:44 +00:00
|
|
|
* RAID-4 and RAID-5 are complicated enough to have their own
|
|
|
|
* function.
|
1999-08-07 08:13:23 +00:00
|
|
|
*/
|
2000-02-29 06:14:44 +00:00
|
|
|
case plex_raid4:
|
1999-08-07 08:13:23 +00:00
|
|
|
case plex_raid5:
|
|
|
|
status = bre5(rq, plexno, diskaddr, diskend);
|
|
|
|
break;
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
default:
|
1999-03-28 08:54:25 +00:00
|
|
|
log(LOG_ERR, "vinum: invalid plex type %d in bre\n", plex->organization);
|
1999-06-22 05:40:51 +00:00
|
|
|
status = REQUEST_DOWN; /* can't access it */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Build up a request structure for reading volumes.
|
1998-12-28 04:56:24 +00:00
|
|
|
* This function is not needed for plex reads, since there's
|
1999-02-05 05:09:22 +00:00
|
|
|
* no recovery if a plex read can't be satisified.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-24 02:17:42 +00:00
|
|
|
enum requeststatus
|
1998-12-28 04:56:24 +00:00
|
|
|
build_read_request(struct request *rq, /* request */
|
|
|
|
int plexindex)
|
|
|
|
{ /* index in the volume's plex table */
|
|
|
|
struct buf *bp;
|
|
|
|
daddr_t startaddr; /* offset of previous part of transfer */
|
|
|
|
daddr_t diskaddr; /* offset of current part of transfer */
|
|
|
|
daddr_t diskend; /* and end offset of transfer */
|
|
|
|
int plexno; /* plex index in vinum_conf */
|
|
|
|
struct rqgroup *rqg; /* point to the request we're working on */
|
|
|
|
struct volume *vol; /* volume in question */
|
|
|
|
int recovered = 0; /* set if we recover a read */
|
|
|
|
enum requeststatus status = REQUEST_OK;
|
1999-08-07 08:13:23 +00:00
|
|
|
int plexmask; /* bit mask of plexes, for recovery */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
bp = rq->bp; /* buffer pointer */
|
|
|
|
diskaddr = bp->b_blkno; /* start offset of transfer */
|
|
|
|
diskend = diskaddr + (bp->b_bcount / DEV_BSIZE); /* and end offset of transfer */
|
|
|
|
rqg = &rq->rqg[plexindex]; /* plex request */
|
|
|
|
vol = &VOL[rq->volplex.volno]; /* point to volume */
|
|
|
|
|
|
|
|
while (diskaddr < diskend) { /* build up request components */
|
|
|
|
startaddr = diskaddr;
|
|
|
|
status = bre(rq, vol->plex[plexindex], &diskaddr, diskend); /* build up a request */
|
|
|
|
switch (status) {
|
|
|
|
case REQUEST_OK:
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case REQUEST_RECOVERED:
|
1999-08-07 08:13:23 +00:00
|
|
|
/*
|
|
|
|
* XXX FIXME if we have more than one plex, and we can
|
|
|
|
* satisfy the request from another, don't use the
|
|
|
|
* recovered request, since it's more expensive.
|
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
recovered = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REQUEST_ENOMEM:
|
|
|
|
return status;
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
1999-08-07 08:13:23 +00:00
|
|
|
* If we get here, our request is not complete. Try
|
|
|
|
* to fill in the missing parts from another plex.
|
|
|
|
* This can happen multiple times in this function,
|
|
|
|
* and we reinitialize the plex mask each time, since
|
|
|
|
* we could have a hole in our plexes.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-07 08:13:23 +00:00
|
|
|
case REQUEST_EOF:
|
1998-12-28 04:56:24 +00:00
|
|
|
case REQUEST_DOWN: /* can't access the plex */
|
1999-08-07 08:13:23 +00:00
|
|
|
case REQUEST_DEGRADED: /* can't access the plex */
|
|
|
|
plexmask = ((1 << vol->plexes) - 1) /* all plexes in the volume */
|
|
|
|
&~(1 << plexindex); /* except for the one we were looking at */
|
|
|
|
for (plexno = 0; plexno < vol->plexes; plexno++) {
|
|
|
|
if (plexmask == 0) /* no plexes left to try */
|
|
|
|
return REQUEST_DOWN; /* failed */
|
|
|
|
diskaddr = startaddr; /* start at the beginning again */
|
|
|
|
if (plexmask & (1 << plexno)) { /* we haven't tried this plex yet */
|
|
|
|
bre(rq, vol->plex[plexno], &diskaddr, diskend); /* try a request */
|
1999-08-14 06:30:15 +00:00
|
|
|
if (diskaddr > startaddr) { /* we satisfied another part */
|
1999-08-07 08:13:23 +00:00
|
|
|
recovered = 1; /* we recovered from the problem */
|
|
|
|
status = REQUEST_OK; /* don't complain about it */
|
|
|
|
break;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
1999-08-07 08:13:23 +00:00
|
|
|
}
|
1999-08-14 06:30:15 +00:00
|
|
|
if (diskaddr == startaddr) /* didn't get any further, */
|
|
|
|
return status;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
if (recovered)
|
|
|
|
vol->recovered_reads += recovered; /* adjust our recovery count */
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Build up a request structure for writes.
|
1998-12-28 04:56:24 +00:00
|
|
|
* Return 0 if all subdisks involved in the request are up, 1 if some
|
|
|
|
* subdisks are not up, and -1 if the request is at least partially
|
1999-02-05 05:09:22 +00:00
|
|
|
* outside the bounds of the subdisks.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-24 02:17:42 +00:00
|
|
|
enum requeststatus
|
1998-12-28 04:56:24 +00:00
|
|
|
build_write_request(struct request *rq)
|
|
|
|
{ /* request */
|
|
|
|
struct buf *bp;
|
|
|
|
daddr_t diskstart; /* offset of current part of transfer */
|
|
|
|
daddr_t diskend; /* and end offset of transfer */
|
|
|
|
int plexno; /* plex index in vinum_conf */
|
|
|
|
struct volume *vol; /* volume in question */
|
|
|
|
enum requeststatus status;
|
|
|
|
|
|
|
|
bp = rq->bp; /* buffer pointer */
|
|
|
|
vol = &VOL[rq->volplex.volno]; /* point to volume */
|
|
|
|
diskend = bp->b_blkno + (bp->b_bcount / DEV_BSIZE); /* end offset of transfer */
|
1999-02-05 05:09:22 +00:00
|
|
|
status = REQUEST_DOWN; /* assume the worst */
|
1998-12-28 04:56:24 +00:00
|
|
|
for (plexno = 0; plexno < vol->plexes; plexno++) {
|
|
|
|
diskstart = bp->b_blkno; /* start offset of transfer */
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Build requests for the plex.
|
1999-01-28 07:00:55 +00:00
|
|
|
* We take the best possible result here (min,
|
1999-02-05 05:09:22 +00:00
|
|
|
* not max): we're happy if we can write at all
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-01-28 07:00:55 +00:00
|
|
|
status = min(status, bre(rq,
|
1998-12-28 04:56:24 +00:00
|
|
|
vol->plex[plexno],
|
|
|
|
&diskstart,
|
|
|
|
diskend));
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the struct buf part of a request element. */
|
1999-08-24 02:17:42 +00:00
|
|
|
enum requeststatus
|
1998-12-28 04:56:24 +00:00
|
|
|
build_rq_buffer(struct rqelement *rqe, struct plex *plex)
|
|
|
|
{
|
|
|
|
struct sd *sd; /* point to subdisk */
|
|
|
|
struct volume *vol;
|
|
|
|
struct buf *bp;
|
|
|
|
struct buf *ubp; /* user (high level) buffer header */
|
|
|
|
|
|
|
|
vol = &VOL[rqe->rqg->rq->volplex.volno];
|
|
|
|
sd = &SD[rqe->sdno]; /* point to subdisk */
|
|
|
|
bp = &rqe->b;
|
|
|
|
ubp = rqe->rqg->rq->bp; /* pointer to user buffer header */
|
|
|
|
|
|
|
|
/* Initialize the buf struct */
|
2000-03-01 07:24:26 +00:00
|
|
|
/* copy these flags from user bp */
|
2000-04-02 15:24:56 +00:00
|
|
|
bp->b_flags = ubp->b_flags & (B_NOCACHE | B_ASYNC);
|
2000-05-04 07:44:23 +00:00
|
|
|
bp->b_io.bio_flags = ubp->b_io.bio_flags & BIO_ORDERED;
|
2000-03-26 23:06:12 +00:00
|
|
|
bp->b_iocmd = ubp->b_iocmd;
|
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 */
|
2000-06-02 04:05:05 +00:00
|
|
|
bp->b_iodone = complete_rqe;
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
1999-08-14 06:30:15 +00:00
|
|
|
* You'd think that we wouldn't need to even
|
|
|
|
* build the request buffer for a dead subdisk,
|
|
|
|
* but in some cases we need information like
|
|
|
|
* the user buffer address. Err on the side of
|
|
|
|
* generosity and supply what we can. That
|
|
|
|
* obviously doesn't include drive information
|
|
|
|
* when the drive is dead.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
2000-05-04 07:44:23 +00:00
|
|
|
if ((rqe->flags & XFR_BAD_SUBDISK) == 0) /* subdisk is accessible, */
|
2000-02-29 06:14:44 +00:00
|
|
|
bp->b_dev = DRIVE[rqe->driveno].dev; /* drive device */
|
1998-12-28 04:56:24 +00:00
|
|
|
bp->b_blkno = rqe->sdoffset + sd->driveoffset; /* start address */
|
|
|
|
bp->b_bcount = rqe->buflen << DEV_BSHIFT; /* number of bytes to transfer */
|
|
|
|
bp->b_resid = bp->b_bcount; /* and it's still all waiting */
|
|
|
|
bp->b_bufsize = bp->b_bcount; /* and buffer size */
|
|
|
|
bp->b_rcred = FSCRED; /* we have the file system credentials */
|
|
|
|
bp->b_wcred = FSCRED; /* we have the file system credentials */
|
|
|
|
|
|
|
|
if (rqe->flags & XFR_MALLOCED) { /* this operation requires a malloced buffer */
|
|
|
|
bp->b_data = Malloc(bp->b_bcount); /* get a buffer to put it in */
|
|
|
|
if (bp->b_data == NULL) { /* failed */
|
|
|
|
abortrequest(rqe->rqg->rq, ENOMEM);
|
|
|
|
return REQUEST_ENOMEM; /* no memory */
|
|
|
|
}
|
|
|
|
} else
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Point directly to user buffer data. This means
|
1998-12-28 04:56:24 +00:00
|
|
|
* that we don't need to do anything when we have
|
1999-02-05 05:09:22 +00:00
|
|
|
* finished the transfer
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
bp->b_data = ubp->b_data + rqe->useroffset * DEV_BSIZE;
|
1999-08-07 08:13:23 +00:00
|
|
|
/*
|
|
|
|
* On a recovery read, we perform an XOR of
|
|
|
|
* all blocks to the user buffer. To make
|
|
|
|
* this work, we first clean out the buffer
|
|
|
|
*/
|
|
|
|
if ((rqe->flags & (XFR_RECOVERY_READ | XFR_BAD_SUBDISK))
|
|
|
|
== (XFR_RECOVERY_READ | XFR_BAD_SUBDISK)) { /* bad subdisk of a recovery read */
|
|
|
|
int length = rqe->grouplen << DEV_BSHIFT; /* and count involved */
|
|
|
|
char *data = (char *) &rqe->b.b_data[rqe->groupoffset << DEV_BSHIFT]; /* destination */
|
|
|
|
|
|
|
|
bzero(data, length); /* clean it out */
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-08-14 06:30:15 +00:00
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Abort a request: free resources and complete the
|
1999-02-05 05:09:22 +00:00
|
|
|
* user request with the specified error
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-24 02:17:42 +00:00
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
abortrequest(struct request *rq, int error)
|
|
|
|
{
|
|
|
|
struct buf *bp = rq->bp; /* user buffer */
|
|
|
|
|
|
|
|
bp->b_error = error;
|
|
|
|
freerq(rq); /* free everything we're doing */
|
2000-05-11 07:25:36 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return error; /* and give up */
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Check that our transfer will cover the
|
1998-12-28 04:56:24 +00:00
|
|
|
* complete address space of the user request.
|
|
|
|
*
|
1999-02-05 05:09:22 +00:00
|
|
|
* Return 1 if it can, otherwise 0
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-24 02:17:42 +00:00
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
check_range_covered(struct request *rq)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform I/O on a subdisk */
|
1999-08-24 02:17:42 +00:00
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
sdio(struct buf *bp)
|
|
|
|
{
|
|
|
|
int s; /* spl */
|
|
|
|
struct sd *sd;
|
|
|
|
struct sdbuf *sbp;
|
|
|
|
daddr_t endoffset;
|
|
|
|
struct drive *drive;
|
|
|
|
|
1999-08-24 02:17:42 +00:00
|
|
|
#if VINUMDEBUG
|
|
|
|
if (debug & DEBUG_LASTREQS)
|
|
|
|
logrq(loginfo_sdio, (union rqinfou) bp, bp);
|
|
|
|
#endif
|
1999-01-21 00:39:36 +00:00
|
|
|
sd = &SD[Sdno(bp->b_dev)]; /* point to the subdisk */
|
1998-12-28 04:56:24 +00:00
|
|
|
drive = &DRIVE[sd->driveno];
|
|
|
|
|
2000-02-29 06:14:44 +00:00
|
|
|
if (drive->state != drive_up) {
|
|
|
|
if (sd->state >= sd_crashed) {
|
2000-05-04 07:44:23 +00:00
|
|
|
if (bp->b_iocmd == BIO_WRITE) /* writing, */
|
2000-03-12 05:05:41 +00:00
|
|
|
set_sd_state(sd->sdno, sd_stale, setstate_force);
|
2000-05-04 07:44:23 +00:00
|
|
|
else
|
|
|
|
set_sd_state(sd->sdno, sd_crashed, setstate_force);
|
2000-02-29 06:14:44 +00:00
|
|
|
}
|
|
|
|
bp->b_error = EIO;
|
2000-05-11 07:25:36 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
2000-02-29 06:14:44 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-09-28 22:56:54 +00:00
|
|
|
/*
|
|
|
|
* We allow access to any kind of subdisk as long as we can expect
|
|
|
|
* to get the I/O performed.
|
|
|
|
*/
|
1999-01-21 00:39:36 +00:00
|
|
|
if (sd->state < sd_empty) { /* nothing to talk to, */
|
1999-08-24 02:17:42 +00:00
|
|
|
bp->b_error = EIO;
|
2000-05-11 07:25:36 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Get a buffer */
|
|
|
|
sbp = (struct sdbuf *) Malloc(sizeof(struct sdbuf));
|
|
|
|
if (sbp == NULL) {
|
|
|
|
bp->b_error = ENOMEM;
|
2000-05-11 07:25:36 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-06-24 08:56:03 +00:00
|
|
|
bzero(sbp, sizeof(struct sdbuf)); /* start with nothing */
|
2000-03-20 10:44:49 +00:00
|
|
|
sbp->b.b_flags = bp->b_flags;
|
2000-03-26 23:06:12 +00:00
|
|
|
sbp->b.b_iocmd = bp->b_iocmd;
|
1999-06-24 08:56:03 +00:00
|
|
|
sbp->b.b_bufsize = bp->b_bufsize; /* buffer size */
|
|
|
|
sbp->b.b_bcount = bp->b_bcount; /* number of bytes to transfer */
|
|
|
|
sbp->b.b_resid = bp->b_resid; /* and amount waiting */
|
2000-02-29 06:14:44 +00:00
|
|
|
sbp->b.b_dev = DRIVE[sd->driveno].dev; /* device */
|
1999-06-24 08:56:03 +00:00
|
|
|
sbp->b.b_data = bp->b_data; /* data buffer */
|
|
|
|
sbp->b.b_blkno = bp->b_blkno + sd->driveoffset;
|
|
|
|
sbp->b.b_iodone = sdio_done; /* come here on completion */
|
1999-08-07 08:13:23 +00:00
|
|
|
BUF_LOCKINIT(&sbp->b); /* get a lock for the buffer */
|
|
|
|
BUF_LOCK(&sbp->b, LK_EXCLUSIVE); /* and lock it */
|
1998-12-28 04:56:24 +00:00
|
|
|
sbp->bp = bp; /* note the address of the original header */
|
|
|
|
sbp->sdno = sd->sdno; /* note for statistics */
|
|
|
|
sbp->driveno = sd->driveno;
|
|
|
|
endoffset = bp->b_blkno + sbp->b.b_bcount / DEV_BSIZE; /* final sector offset */
|
|
|
|
if (endoffset > sd->sectors) { /* beyond the end */
|
|
|
|
sbp->b.b_bcount -= (endoffset - sd->sectors) * DEV_BSIZE; /* trim */
|
|
|
|
if (sbp->b.b_bcount <= 0) { /* nothing to transfer */
|
|
|
|
bp->b_resid = bp->b_bcount; /* nothing transferred */
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(bp);
|
1998-12-28 04:56:24 +00:00
|
|
|
Free(sbp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1998-12-28 16:28:24 +00:00
|
|
|
#if VINUMDEBUG
|
1998-12-28 04:56:24 +00:00
|
|
|
if (debug & DEBUG_ADDRESSES)
|
1999-03-02 06:56:39 +00:00
|
|
|
log(LOG_DEBUG,
|
1999-05-15 05:49:21 +00:00
|
|
|
" %s dev %d.%d, sd %d, offset 0x%x, devoffset 0x%x, length %ld\n",
|
2000-03-20 10:44:49 +00:00
|
|
|
sbp->b.b_iocmd == BIO_READ ? "Read" : "Write",
|
1999-05-15 05:49:21 +00:00
|
|
|
major(sbp->b.b_dev),
|
|
|
|
minor(sbp->b.b_dev),
|
1998-12-28 04:56:24 +00:00
|
|
|
sbp->sdno,
|
|
|
|
(u_int) (sbp->b.b_blkno - SD[sbp->sdno].driveoffset),
|
|
|
|
(int) sbp->b.b_blkno,
|
1999-08-14 06:30:15 +00:00
|
|
|
sbp->b.b_bcount);
|
1998-12-28 04:56:24 +00:00
|
|
|
#endif
|
|
|
|
s = splbio();
|
1999-08-24 02:17:42 +00:00
|
|
|
#if VINUMDEBUG
|
|
|
|
if (debug & DEBUG_LASTREQS)
|
1999-09-28 22:56:54 +00:00
|
|
|
logrq(loginfo_sdiol, (union rqinfou) &sbp->b, &sbp->b);
|
1999-08-24 02:17:42 +00:00
|
|
|
#endif
|
2000-03-20 11:29:10 +00:00
|
|
|
DEV_STRATEGY(&sbp->b, 0);
|
1998-12-28 04:56:24 +00:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Simplified version of bounds_check_with_label
|
1998-12-28 04:56:24 +00:00
|
|
|
* Determine the size of the transfer, and make sure it is
|
|
|
|
* within the boundaries of the partition. Adjust transfer
|
|
|
|
* if needed, and signal errors or early completion.
|
|
|
|
*
|
|
|
|
* Volumes are simpler than disk slices: they only contain
|
|
|
|
* one component (though we call them a, b and c to make
|
|
|
|
* system utilities happy), and they always take up the
|
|
|
|
* complete space of the "partition".
|
|
|
|
*
|
|
|
|
* I'm still not happy with this: why should the label be
|
|
|
|
* protected? If it weren't so damned difficult to write
|
|
|
|
* one in the first pleace (because it's protected), it wouldn't
|
|
|
|
* be a problem.
|
|
|
|
*/
|
1999-08-24 02:17:42 +00:00
|
|
|
int
|
1998-12-28 04:56:24 +00:00
|
|
|
vinum_bounds_check(struct buf *bp, struct volume *vol)
|
|
|
|
{
|
|
|
|
int maxsize = vol->size; /* size of the partition (sectors) */
|
|
|
|
int size = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; /* size of this request (sectors) */
|
|
|
|
|
|
|
|
/* Would this transfer overwrite the disk label? */
|
|
|
|
if (bp->b_blkno <= LABELSECTOR /* starts before or at the label */
|
|
|
|
#if LABELSECTOR != 0
|
|
|
|
&& bp->b_blkno + size > LABELSECTOR /* and finishes after */
|
|
|
|
#endif
|
|
|
|
&& (!(vol->flags & VF_RAW)) /* and it's not raw */
|
2000-05-11 07:25:36 +00:00
|
|
|
&&(bp->b_iocmd == BIO_WRITE) /* and it's a write */
|
|
|
|
&&(!vol->flags & (VF_WLABEL | VF_LABELLING))) { /* and we're not allowed to write the label */
|
1998-12-28 04:56:24 +00:00
|
|
|
bp->b_error = EROFS; /* read-only */
|
2000-05-04 07:44:23 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
1998-12-28 04:56:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (size == 0) /* no transfer specified, */
|
|
|
|
return 0; /* treat as EOF */
|
|
|
|
/* beyond partition? */
|
|
|
|
if (bp->b_blkno < 0 /* negative start */
|
|
|
|
|| bp->b_blkno + size > maxsize) { /* or goes beyond the end of the partition */
|
|
|
|
/* if exactly at end of disk, return an EOF */
|
|
|
|
if (bp->b_blkno == maxsize) {
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* or truncate if part of it fits */
|
|
|
|
size = maxsize - bp->b_blkno;
|
|
|
|
if (size <= 0) { /* nothing to transfer */
|
|
|
|
bp->b_error = EINVAL;
|
2000-05-04 07:44:23 +00:00
|
|
|
bp->b_io.bio_flags |= BIO_ERROR;
|
1998-12-28 04:56:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
bp->b_bcount = size << DEV_BSHIFT;
|
|
|
|
}
|
|
|
|
bp->b_pblkno = bp->b_blkno;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Allocate a request group and hook
|
1999-02-05 05:09:22 +00:00
|
|
|
* it in in the list for rq
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1998-12-28 04:56:24 +00:00
|
|
|
struct rqgroup *
|
|
|
|
allocrqg(struct request *rq, int elements)
|
|
|
|
{
|
|
|
|
struct rqgroup *rqg; /* the one we're going to allocate */
|
|
|
|
int size = sizeof(struct rqgroup) + elements * sizeof(struct rqelement);
|
|
|
|
|
|
|
|
rqg = (struct rqgroup *) Malloc(size);
|
|
|
|
if (rqg != NULL) { /* malloc OK, */
|
|
|
|
if (rq->rqg) /* we already have requests */
|
|
|
|
rq->lrqg->next = rqg; /* hang it off the end */
|
|
|
|
else /* first request */
|
|
|
|
rq->rqg = rqg; /* at the start */
|
|
|
|
rq->lrqg = rqg; /* this one is the last in the list */
|
|
|
|
|
|
|
|
bzero(rqg, size); /* no old junk */
|
|
|
|
rqg->rq = rq; /* point back to the parent request */
|
|
|
|
rqg->count = elements; /* number of requests in the group */
|
1999-02-05 05:09:22 +00:00
|
|
|
}
|
2000-01-05 06:10:52 +00:00
|
|
|
rqg->lockbase = -1; /* no lock required yet */
|
1998-12-28 04:56:24 +00:00
|
|
|
return rqg;
|
|
|
|
}
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Deallocate a request group out of a chain. We do
|
1998-12-28 04:56:24 +00:00
|
|
|
* this by linear search: the chain is short, this
|
|
|
|
* almost never happens, and currently it can only
|
1999-02-05 05:09:22 +00:00
|
|
|
* happen to the first member of the chain.
|
1999-01-29 01:17:54 +00:00
|
|
|
*/
|
1999-08-24 02:17:42 +00:00
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
deallocrqg(struct rqgroup *rqg)
|
|
|
|
{
|
|
|
|
struct rqgroup *rqgc = rqg->rq->rqg; /* point to the request chain */
|
|
|
|
|
1999-08-14 06:30:15 +00:00
|
|
|
if (rqg->lock) /* got a lock? */
|
1999-08-24 02:17:42 +00:00
|
|
|
unlockrange(rqg->plexno, rqg->lock); /* yes, free it */
|
1999-03-14 04:04:23 +00:00
|
|
|
if (rqgc == rqg) /* we're first in line */
|
1998-12-28 04:56:24 +00:00
|
|
|
rqg->rq->rqg = rqg->next; /* unhook ourselves */
|
|
|
|
else {
|
1999-03-14 04:04:23 +00:00
|
|
|
while ((rqgc->next != NULL) /* find the group */
|
|
|
|
&&(rqgc->next != rqg))
|
1998-12-28 04:56:24 +00:00
|
|
|
rqgc = rqgc->next;
|
1999-03-14 04:04:23 +00:00
|
|
|
if (rqgc->next == NULL)
|
|
|
|
log(LOG_ERR,
|
|
|
|
"vinum deallocrqg: rqg %p not found in request %p\n",
|
|
|
|
rqg->rq,
|
|
|
|
rqg);
|
|
|
|
else
|
|
|
|
rqgc->next = rqg->next; /* make the chain jump over us */
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
1999-03-14 04:04:23 +00:00
|
|
|
Free(rqg);
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
2000-05-04 07:44:23 +00:00
|
|
|
|
|
|
|
/* Local Variables: */
|
|
|
|
/* fill-column: 50 */
|
|
|
|
/* End: */
|