xref: /dragonfly/sys/dev/raid/vinum/vinumrevive.c (revision 1de703da)
1 /*-
2  * Copyright (c) 1997, 1998, 1999
3  *	Nan Yang Computer Services Limited.  All rights reserved.
4  *
5  *  Parts copyright (c) 1997, 1998 Cybernet Corporation, NetMAX project.
6  *
7  *  Written by Greg Lehey
8  *
9  *  This software is distributed under the so-called ``Berkeley
10  *  License'':
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *	This product includes software developed by Nan Yang Computer
23  *      Services Limited.
24  * 4. Neither the name of the Company nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * This software is provided ``as is'', and any express or implied
29  * warranties, including, but not limited to, the implied warranties of
30  * merchantability and fitness for a particular purpose are disclaimed.
31  * In no event shall the company or contributors be liable for any
32  * direct, indirect, incidental, special, exemplary, or consequential
33  * damages (including, but not limited to, procurement of substitute
34  * goods or services; loss of use, data, or profits; or business
35  * interruption) however caused and on any theory of liability, whether
36  * in contract, strict liability, or tort (including negligence or
37  * otherwise) arising in any way out of the use of this software, even if
38  * advised of the possibility of such damage.
39  *
40  * $Id: vinumrevive.c,v 1.14 2000/12/21 01:55:11 grog Exp grog $
41  * $FreeBSD: src/sys/dev/vinum/vinumrevive.c,v 1.22.2.5 2001/03/13 02:59:43 grog Exp $
42  * $DragonFly: src/sys/dev/raid/vinum/vinumrevive.c,v 1.2 2003/06/17 04:28:33 dillon Exp $
43  */
44 
45 #include <dev/vinum/vinumhdr.h>
46 #include <dev/vinum/request.h>
47 
48 /*
49  * Revive a block of a subdisk.  Return an error
50  * indication.  EAGAIN means successful copy, but
51  * that more blocks remain to be copied.  EINVAL
52  * means that the subdisk isn't associated with a
53  * plex (which means a programming error if we get
54  * here at all; FIXME).
55  */
56 
57 int
58 revive_block(int sdno)
59 {
60     int s;						    /* priority level */
61     struct sd *sd;
62     struct plex *plex;
63     struct volume *vol;
64     struct buf *bp;
65     int error = EAGAIN;
66     int size;						    /* size of revive block, bytes */
67     daddr_t plexblkno;					    /* lblkno in plex */
68     int psd;						    /* parity subdisk number */
69     u_int64_t stripe;					    /* stripe number */
70     int paritysd = 0;					    /* set if this is the parity stripe */
71     struct rangelock *lock;				    /* for locking */
72     daddr_t stripeoffset;				    /* offset in stripe */
73 
74     plexblkno = 0;					    /* to keep the compiler happy */
75     sd = &SD[sdno];
76     lock = NULL;
77     if (sd->plexno < 0)					    /* no plex? */
78 	return EINVAL;
79     plex = &PLEX[sd->plexno];				    /* point to plex */
80     if (plex->volno >= 0)
81 	vol = &VOL[plex->volno];
82     else
83 	vol = NULL;
84 
85     if ((sd->revive_blocksize == 0)			    /* no block size */
86     ||(sd->revive_blocksize & ((1 << DEV_BSHIFT) - 1)))	    /* or invalid block size */
87 	sd->revive_blocksize = DEFAULT_REVIVE_BLOCKSIZE;
88     else if (sd->revive_blocksize > MAX_REVIVE_BLOCKSIZE)
89 	sd->revive_blocksize = MAX_REVIVE_BLOCKSIZE;
90     size = min(sd->revive_blocksize >> DEV_BSHIFT, sd->sectors - sd->revived) << DEV_BSHIFT;
91     sd->reviver = curproc->p_pid;			    /* note who last had a bash at it */
92 
93     /* Now decide where to read from */
94     switch (plex->organization) {
95     case plex_concat:
96 	plexblkno = sd->revived + sd->plexoffset;	    /* corresponding address in plex */
97 	break;
98 
99     case plex_striped:
100 	stripeoffset = sd->revived % plex->stripesize;	    /* offset from beginning of stripe */
101 	if (stripeoffset + (size >> DEV_BSHIFT) > plex->stripesize)
102 	    size = (plex->stripesize - stripeoffset) << DEV_BSHIFT;
103 	plexblkno = sd->plexoffset			    /* base */
104 	    + (sd->revived - stripeoffset) * plex->subdisks /* offset to beginning of stripe */
105 	    + stripeoffset;				    /* offset from beginning of stripe */
106 	break;
107 
108     case plex_raid4:
109     case plex_raid5:
110 	stripeoffset = sd->revived % plex->stripesize;	    /* offset from beginning of stripe */
111 	plexblkno = sd->plexoffset			    /* base */
112 	    + (sd->revived - stripeoffset) * (plex->subdisks - 1) /* offset to beginning of stripe */
113 	    +stripeoffset;				    /* offset from beginning of stripe */
114 	stripe = (sd->revived / plex->stripesize);	    /* stripe number */
115 
116 	/* Make sure we don't go beyond the end of the band. */
117 	size = min(size, (plex->stripesize - stripeoffset) << DEV_BSHIFT);
118 	if (plex->organization == plex_raid4)
119 	    psd = plex->subdisks - 1;			    /* parity subdisk for this stripe */
120 	else
121 	    psd = plex->subdisks - 1 - stripe % plex->subdisks;	/* parity subdisk for this stripe */
122 	paritysd = plex->sdnos[psd] == sdno;		    /* note if it's the parity subdisk */
123 
124 	/*
125 	 * Now adjust for the strangenesses
126 	 * in RAID-4 and RAID-5 striping.
127 	 */
128 	if (sd->plexsdno > psd)				    /* beyond the parity stripe, */
129 	    plexblkno -= plex->stripesize;		    /* one stripe less */
130 	else if (paritysd)
131 	    plexblkno -= plex->stripesize * sd->plexsdno;   /* go back to the beginning of the band */
132 	break;
133 
134     case plex_disorg:					    /* to keep the compiler happy */
135     }
136 
137     if (paritysd) {					    /* we're reviving a parity block, */
138 	bp = parityrebuild(plex, sd->revived, size, rebuildparity, &lock, NULL); /* do the grunt work */
139 	if (bp == NULL)					    /* no buffer space */
140 	    return ENOMEM;				    /* chicken out */
141     } else {						    /* data block */
142 	s = splbio();
143 	bp = geteblk(size);				    /* Get a buffer */
144 	splx(s);
145 	if (bp == NULL)
146 	    return ENOMEM;
147 
148 	/*
149 	 * Amount to transfer: block size, unless it
150 	 * would overlap the end.
151 	 */
152 	bp->b_bcount = size;
153 	bp->b_resid = bp->b_bcount;
154 	bp->b_blkno = plexblkno;			    /* start here */
155 	if (isstriped(plex))				    /* we need to lock striped plexes */
156 	    lock = lockrange(plexblkno << DEV_BSHIFT, bp, plex); /* lock it */
157 	if (vol != NULL)				    /* it's part of a volume, */
158 	    /*
159 	       * First, read the data from the volume.  We
160 	       * don't care which plex, that's bre's job.
161 	     */
162 	    bp->b_dev = VINUMDEV(plex->volno, 0, 0, VINUM_VOLUME_TYPE);	/* create the device number */
163 	else						    /* it's an unattached plex */
164 	    bp->b_dev = VINUM_PLEX(sd->plexno);		    /* create the device number */
165 
166 	bp->b_flags = B_READ;				    /* either way, read it */
167 	vinumstart(bp, 1);
168 	biowait(bp);
169     }
170 
171     if (bp->b_flags & B_ERROR)
172 	error = bp->b_error;
173     else
174 	/* Now write to the subdisk */
175     {
176 	bp->b_dev = VINUM_SD(sdno);			    /* create the device number */
177 	bp->b_flags = B_ORDERED | B_WRITE;		    /* and make this an ordered write */
178 	bp->b_resid = bp->b_bcount;
179 	bp->b_blkno = sd->revived;			    /* write it to here */
180 	sdio(bp);					    /* perform the I/O */
181 	biowait(bp);
182 	if (bp->b_flags & B_ERROR)
183 	    error = bp->b_error;
184 	else {
185 	    sd->revived += bp->b_bcount >> DEV_BSHIFT;	    /* moved this much further down */
186 	    if (sd->revived >= sd->sectors) {		    /* finished */
187 		sd->revived = 0;
188 		set_sd_state(sdno, sd_up, setstate_force);  /* bring the sd up */
189 		log(LOG_INFO, "vinum: %s is %s\n", sd->name, sd_state(sd->state));
190 		save_config();				    /* and save the updated configuration */
191 		error = 0;				    /* we're done */
192 	    }
193 	}
194 	if (lock)					    /* we took a lock, */
195 	    unlockrange(sd->plexno, lock);		    /* give it back */
196 	while (sd->waitlist) {				    /* we have waiting requests */
197 #if VINUMDEBUG
198 	    struct request *rq = sd->waitlist;
199 
200 	    if (debug & DEBUG_REVIVECONFLICT)
201 		log(LOG_DEBUG,
202 		    "Relaunch revive conflict sd %d: %p\n%s dev %d.%d, offset 0x%x, length %ld\n",
203 		    rq->sdno,
204 		    rq,
205 		    rq->bp->b_flags & B_READ ? "Read" : "Write",
206 		    major(rq->bp->b_dev),
207 		    minor(rq->bp->b_dev),
208 		    rq->bp->b_blkno,
209 		    rq->bp->b_bcount);
210 #endif
211 	    launch_requests(sd->waitlist, 1);		    /* do them now */
212 	    sd->waitlist = sd->waitlist->next;		    /* and move on to the next */
213 	}
214     }
215     if (bp->b_qindex == 0) {				    /* not on a queue, */
216 	bp->b_flags |= B_INVAL;
217 	bp->b_flags &= ~B_ERROR;
218 	brelse(bp);					    /* is this kosher? */
219     }
220     return error;
221 }
222 
223 /*
224  * Check or rebuild the parity blocks of a RAID-4
225  * or RAID-5 plex.
226  *
227  * The variables plex->checkblock and
228  * plex->rebuildblock represent the
229  * subdisk-relative address of the stripe we're
230  * looking at, not the plex-relative address.  We
231  * store it in the plex and not as a local
232  * variable because this function could be
233  * stopped, and we don't want to repeat the part
234  * we've already done.  This is also the reason
235  * why we don't initialize it here except at the
236  * end.  It gets initialized with the plex on
237  * creation.
238  *
239  * Each call to this function processes at most
240  * one stripe.  We can't loop in this function,
241  * because we're unstoppable, so we have to be
242  * called repeatedly from userland.
243  */
244 void
245 parityops(struct vinum_ioctl_msg *data)
246 {
247     int plexno;
248     struct plex *plex;
249     int size;						    /* I/O transfer size, bytes */
250     int stripe;						    /* stripe number in plex */
251     int psd;						    /* parity subdisk number */
252     struct rangelock *lock;				    /* lock on stripe */
253     struct _ioctl_reply *reply;
254     off_t pstripe;					    /* pointer to our stripe counter */
255     struct buf *pbp;
256     off_t errorloc;					    /* offset of parity error */
257     enum parityop op;					    /* operation to perform */
258 
259     plexno = data->index;
260     op = data->op;
261     pbp = NULL;
262     reply = (struct _ioctl_reply *) data;
263     reply->error = EAGAIN;				    /* expect to repeat this call */
264     plex = &PLEX[plexno];
265     if (!isparity(plex)) {				    /* not RAID-4 or RAID-5 */
266 	reply->error = EINVAL;
267 	return;
268     } else if (plex->state < plex_flaky) {
269 	reply->error = EIO;
270 	strcpy(reply->msg, "Plex is not completely accessible\n");
271 	return;
272     }
273     pstripe = data->offset;
274     stripe = pstripe / plex->stripesize;		    /* stripe number */
275     psd = plex->subdisks - 1 - stripe % plex->subdisks;	    /* parity subdisk for this stripe */
276     size = min(DEFAULT_REVIVE_BLOCKSIZE,		    /* one block at a time */
277 	plex->stripesize << DEV_BSHIFT);
278 
279     pbp = parityrebuild(plex, pstripe, size, op, &lock, &errorloc); /* do the grunt work */
280     if (pbp == NULL) {					    /* no buffer space */
281 	reply->error = ENOMEM;
282 	return;						    /* chicken out */
283     }
284     /*
285      * Now we have a result in the data buffer of
286      * the parity buffer header, which we have kept.
287      * Decide what to do with it.
288      */
289     reply->msg[0] = '\0';				    /* until shown otherwise */
290     if ((pbp->b_flags & B_ERROR) == 0) {		    /* no error */
291 	if ((op == rebuildparity)
292 	    || (op == rebuildandcheckparity)) {
293 	    pbp->b_flags &= ~B_READ;
294 	    pbp->b_resid = pbp->b_bcount;
295 	    sdio(pbp);					    /* write the parity block */
296 	    biowait(pbp);
297 	}
298 	if (((op == checkparity)
299 		|| (op == rebuildandcheckparity))
300 	    && (errorloc != -1)) {
301 	    if (op == checkparity)
302 		reply->error = EIO;
303 	    sprintf(reply->msg,
304 		"Parity incorrect at offset 0x%llx\n",
305 		errorloc);
306 	}
307 	if (reply->error == EAGAIN) {			    /* still OK, */
308 	    plex->checkblock = pstripe + (pbp->b_bcount >> DEV_BSHIFT);	/* moved this much further down */
309 	    if (plex->checkblock >= SD[plex->sdnos[0]].sectors) { /* finished */
310 		plex->checkblock = 0;
311 		reply->error = 0;
312 	    }
313 	}
314     }
315     if (pbp->b_flags & B_ERROR)
316 	reply->error = pbp->b_error;
317     pbp->b_flags |= B_INVAL;
318     pbp->b_flags &= ~B_ERROR;
319     brelse(pbp);
320     unlockrange(plexno, lock);
321 }
322 
323 /*
324  * Rebuild a parity stripe.  Return pointer to
325  * parity bp.  On return,
326  *
327  * 1.  The band is locked.  The caller must unlock
328  *     the band and release the buffer header.
329  *
330  * 2.  All buffer headers except php have been
331  *     released.  The caller must release pbp.
332  *
333  * 3.  For checkparity and rebuildandcheckparity,
334  *     the parity is compared with the current
335  *     parity block.  If it's different, the
336  *     offset of the error is returned to
337  *     errorloc.  The caller can set the value of
338  *     the pointer to NULL if this is called for
339  *     rebuilding parity.
340  *
341  * pstripe is the subdisk-relative base address of
342  * the data to be reconstructed, size is the size
343  * of the transfer in bytes.
344  */
345 struct buf *
346 parityrebuild(struct plex *plex,
347     u_int64_t pstripe,
348     int size,
349     enum parityop op,
350     struct rangelock **lockp,
351     off_t * errorloc)
352 {
353     int error;
354     int s;
355     int sdno;
356     u_int64_t stripe;					    /* stripe number */
357     int *parity_buf;					    /* buffer address for current parity block */
358     int *newparity_buf;					    /* and for new parity block */
359     int mysize;						    /* I/O transfer size for this transfer */
360     int isize;						    /* mysize in ints */
361     int i;
362     int psd;						    /* parity subdisk number */
363     int newpsd;						    /* and "subdisk number" of new parity */
364     struct buf **bpp;					    /* pointers to our bps */
365     struct buf *pbp;					    /* buffer header for parity stripe */
366     int *sbuf;
367     int bufcount;					    /* number of buffers we need */
368 
369     stripe = pstripe / plex->stripesize;		    /* stripe number */
370     psd = plex->subdisks - 1 - stripe % plex->subdisks;	    /* parity subdisk for this stripe */
371     parity_buf = NULL;					    /* to keep the compiler happy */
372     error = 0;
373 
374     /*
375      * It's possible that the default transfer size
376      * we chose is not a factor of the stripe size.
377      * We *must* limit this operation to a single
378      * stripe, at least for RAID-5 rebuild, since
379      * the parity subdisk changes between stripes,
380      * so in this case we need to perform a short
381      * transfer.  Set variable mysize to reflect
382      * this.
383      */
384     mysize = min(size, (plex->stripesize * (stripe + 1) - pstripe) << DEV_BSHIFT);
385     isize = mysize / (sizeof(int));			    /* number of ints in the buffer */
386     bufcount = plex->subdisks + 1;			    /* sd buffers plus result buffer */
387     newpsd = plex->subdisks;
388     bpp = (struct buf **) Malloc(bufcount * sizeof(struct buf *)); /* array of pointers to bps */
389 
390     /* First, build requests for all subdisks */
391     for (sdno = 0; sdno < bufcount; sdno++) {		    /* for each subdisk */
392 	if ((sdno != psd) || (op != rebuildparity)) {
393 	    /* Get a buffer header and initialize it. */
394 	    s = splbio();
395 	    bpp[sdno] = geteblk(mysize);		    /* Get a buffer */
396 	    if (bpp[sdno] == NULL) {
397 		while (sdno-- > 0) {			    /* release the ones we got */
398 		    bpp[sdno]->b_flags |= B_INVAL;
399 		    brelse(bpp[sdno]);			    /* give back our resources */
400 		}
401 		splx(s);
402 		printf("vinum: can't allocate buffer space for parity op.\n");
403 		return NULL;				    /* no bpps */
404 	    }
405 	    splx(s);
406 	    if (sdno == psd)
407 		parity_buf = (int *) bpp[sdno]->b_data;
408 	    if (sdno == newpsd)				    /* the new one? */
409 		bpp[sdno]->b_dev = VINUM_SD(plex->sdnos[psd]); /* write back to the parity SD */
410 	    else
411 		bpp[sdno]->b_dev = VINUM_SD(plex->sdnos[sdno]);	/* device number */
412 	    bpp[sdno]->b_flags = B_READ;		    /* either way, read it */
413 	    bpp[sdno]->b_bcount = mysize;
414 	    bpp[sdno]->b_resid = bpp[sdno]->b_bcount;
415 	    bpp[sdno]->b_blkno = pstripe;		    /* transfer from here */
416 	}
417     }
418 
419     /* Initialize result buffer */
420     pbp = bpp[newpsd];
421     newparity_buf = (int *) bpp[newpsd]->b_data;
422     bzero(newparity_buf, mysize);
423 
424     /*
425      * Now lock the stripe with the first non-parity
426      * bp as locking bp.
427      */
428     *lockp = lockrange(pstripe * plex->stripesize * (plex->subdisks - 1),
429 	bpp[psd ? 0 : 1],
430 	plex);
431 
432     /*
433      * Then issue requests for all subdisks in
434      * parallel.  Don't transfer the parity stripe
435      * if we're rebuilding parity, unless we also
436      * want to check it.
437      */
438     for (sdno = 0; sdno < plex->subdisks; sdno++) {	    /* for each real subdisk */
439 	if ((sdno != psd) || (op != rebuildparity)) {
440 	    sdio(bpp[sdno]);
441 	}
442     }
443 
444     /*
445      * Next, wait for the requests to complete.
446      * We wait in the order in which they were
447      * issued, which isn't necessarily the order in
448      * which they complete, but we don't have a
449      * convenient way of doing the latter, and the
450      * delay is minimal.
451      */
452     for (sdno = 0; sdno < plex->subdisks; sdno++) {	    /* for each subdisk */
453 	if ((sdno != psd) || (op != rebuildparity)) {
454 	    biowait(bpp[sdno]);
455 	    if (bpp[sdno]->b_flags & B_ERROR)		    /* can't read, */
456 		error = bpp[sdno]->b_error;
457 	    else if (sdno != psd) {			    /* update parity */
458 		sbuf = (int *) bpp[sdno]->b_data;
459 		for (i = 0; i < isize; i++)
460 		    ((int *) newparity_buf)[i] ^= sbuf[i];  /* xor in the buffer */
461 	    }
462 	}
463 	if (sdno != psd) {				    /* release all bps except parity */
464 	    bpp[sdno]->b_flags |= B_INVAL;
465 	    brelse(bpp[sdno]);				    /* give back our resources */
466 	}
467     }
468 
469     /*
470      * If we're checking, compare the calculated
471      * and the read parity block.  If they're
472      * different, return the plex-relative offset;
473      * otherwise return -1.
474      */
475     if ((op == checkparity)
476 	|| (op == rebuildandcheckparity)) {
477 	*errorloc = -1;					    /* no error yet */
478 	for (i = 0; i < isize; i++) {
479 	    if (parity_buf[i] != newparity_buf[i]) {
480 		*errorloc = (off_t) (pstripe << DEV_BSHIFT) * (plex->subdisks - 1)
481 		    + i * sizeof(int);
482 		break;
483 	    }
484 	}
485 	bpp[psd]->b_flags |= B_INVAL;
486 	brelse(bpp[psd]);				    /* give back our resources */
487     }
488     /* release our resources */
489     Free(bpp);
490     if (error) {
491 	pbp->b_flags |= B_ERROR;
492 	pbp->b_error = error;
493     }
494     return pbp;
495 }
496 
497 /*
498  * Initialize a subdisk by writing zeroes to the
499  * complete address space.  If verify is set,
500  * check each transfer for correctness.
501  *
502  * Each call to this function writes (and maybe
503  * checks) a single block.
504  */
505 int
506 initsd(int sdno, int verify)
507 {
508     int s;						    /* priority level */
509     struct sd *sd;
510     struct plex *plex;
511     struct volume *vol;
512     struct buf *bp;
513     int error;
514     int size;						    /* size of init block, bytes */
515     daddr_t plexblkno;					    /* lblkno in plex */
516     int verified;					    /* set when we're happy with what we wrote */
517 
518     error = 0;
519     plexblkno = 0;					    /* to keep the compiler happy */
520     sd = &SD[sdno];
521     if (sd->plexno < 0)					    /* no plex? */
522 	return EINVAL;
523     plex = &PLEX[sd->plexno];				    /* point to plex */
524     if (plex->volno >= 0)
525 	vol = &VOL[plex->volno];
526     else
527 	vol = NULL;
528 
529     if (sd->init_blocksize == 0) {
530 	if (plex->stripesize != 0)			    /* we're striped, don't init more than */
531 	    sd->init_blocksize = min(DEFAULT_REVIVE_BLOCKSIZE, /* one block at a time */
532 		plex->stripesize << DEV_BSHIFT);
533 	else
534 	    sd->init_blocksize = DEFAULT_REVIVE_BLOCKSIZE;
535     } else if (sd->init_blocksize > MAX_REVIVE_BLOCKSIZE)
536 	sd->init_blocksize = MAX_REVIVE_BLOCKSIZE;
537 
538     size = min(sd->init_blocksize >> DEV_BSHIFT, sd->sectors - sd->initialized) << DEV_BSHIFT;
539 
540     verified = 0;
541     while (!verified) {					    /* until we're happy with it, */
542 	s = splbio();
543 	bp = geteblk(size);				    /* Get a buffer */
544 	splx(s);
545 	if (bp == NULL)
546 	    return ENOMEM;
547 
548 	bp->b_bcount = size;
549 	bp->b_resid = bp->b_bcount;
550 	bp->b_blkno = sd->initialized;			    /* write it to here */
551 	bzero(bp->b_data, bp->b_bcount);
552 	bp->b_dev = VINUM_SD(sdno);			    /* create the device number */
553 	bp->b_flags &= ~B_READ;
554 	sdio(bp);					    /* perform the I/O */
555 	biowait(bp);
556 	if (bp->b_flags & B_ERROR)
557 	    error = bp->b_error;
558 	if (bp->b_qindex == 0) {			    /* not on a queue, */
559 	    bp->b_flags |= B_INVAL;
560 	    bp->b_flags &= ~B_ERROR;
561 	    brelse(bp);					    /* is this kosher? */
562 	}
563 	if ((error == 0) && verify) {			    /* check that it got there */
564 	    s = splbio();
565 	    bp = geteblk(size);				    /* get a buffer */
566 	    if (bp == NULL) {
567 		splx(s);
568 		error = ENOMEM;
569 	    } else {
570 		bp->b_bcount = size;
571 		bp->b_resid = bp->b_bcount;
572 		bp->b_blkno = sd->initialized;		    /* read from here */
573 		bp->b_dev = VINUM_SD(sdno);		    /* create the device number */
574 		bp->b_flags |= B_READ;			    /* read it back */
575 		splx(s);
576 		sdio(bp);
577 		biowait(bp);
578 		/*
579 		 * XXX Bug fix code.  This is hopefully no
580 		 * longer needed (21 February 2000).
581 		 */
582 		if (bp->b_flags & B_ERROR)
583 		    error = bp->b_error;
584 		else if ((*bp->b_data != 0)		    /* first word spammed */
585 		||(bcmp(bp->b_data, &bp->b_data[1], bp->b_bcount - 1))) { /* or one of the others */
586 		    printf("vinum: init error on %s, offset 0x%llx sectors\n",
587 			sd->name,
588 			(long long) sd->initialized);
589 		    verified = 0;
590 		} else
591 		    verified = 1;
592 		if (bp->b_qindex == 0) {		    /* not on a queue, */
593 		    bp->b_flags |= B_INVAL;
594 		    bp->b_flags &= ~B_ERROR;
595 		    brelse(bp);				    /* is this kosher? */
596 		}
597 	    }
598 	} else
599 	    verified = 1;
600     }
601     if (error == 0) {					    /* did it, */
602 	sd->initialized += size >> DEV_BSHIFT;		    /* moved this much further down */
603 	if (sd->initialized >= sd->sectors) {		    /* finished */
604 	    sd->initialized = 0;
605 	    set_sd_state(sdno, sd_initialized, setstate_force);	/* bring the sd up */
606 	    log(LOG_INFO, "vinum: %s is %s\n", sd->name, sd_state(sd->state));
607 	    save_config();				    /* and save the updated configuration */
608 	} else						    /* more to go, */
609 	    error = EAGAIN;				    /* ya'll come back, see? */
610     }
611     return error;
612 }
613 
614 /* Local Variables: */
615 /* fill-column: 50 */
616 /* End: */
617