MPSAFE - tsleep_interlock, BUF/BIO, cluster, swap_pager.
[dragonfly.git] / sys / dev / raid / vinum / vinumrevive.c
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.15 2006/12/22 23:26:24 swildner Exp $
43  */
44
45 #include "vinumhdr.h"
46 #include "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     struct sd *sd;
61     struct plex *plex;
62     struct volume *vol;
63     struct buf *bp;
64     cdev_t dev;
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         break;
136     }
137
138     if (paritysd) {                                         /* we're reviving a parity block, */
139         bp = parityrebuild(plex, sd->revived, size, rebuildparity, &lock, NULL); /* do the grunt work */
140         if (bp == NULL)                                     /* no buffer space */
141             return ENOMEM;                                  /* chicken out */
142     } else {                                                /* data block */
143         bp = getpbuf(&vinum_conf.physbufs);                 /* Get a buffer */
144         bp->b_data = Malloc(size);
145
146         /*
147          * Amount to transfer: block size, unless it
148          * would overlap the end.
149          */
150         bp->b_bcount = size;
151         bp->b_resid = bp->b_bcount;
152         bp->b_bio1.bio_offset = (off_t)plexblkno << DEV_BSHIFT;             /* start here */
153         bp->b_bio1.bio_done = biodone_sync;
154         bp->b_bio1.bio_flags |= BIO_SYNC;
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             dev = VINUMDEV(plex->volno, 0, 0, VINUM_VOLUME_TYPE);       /* create the device number */
163         else                                                /* it's an unattached plex */
164             dev = VINUM_PLEX(sd->plexno);                   /* create the device number */
165
166         bp->b_cmd = BUF_CMD_READ;
167         vinumstart(dev, &bp->b_bio1, 1);
168         biowait(&bp->b_bio1, "drvrd");
169     }
170
171     if (bp->b_flags & B_ERROR)
172         error = bp->b_error;
173     else
174         /* Now write to the subdisk */
175     {
176         dev = VINUM_SD(sdno);                       /* create the device number */
177         bp->b_flags |= B_ORDERED;                   /* and make this an ordered write */
178         bp->b_cmd = BUF_CMD_WRITE;
179         bp->b_resid = bp->b_bcount;
180         bp->b_bio1.bio_offset = (off_t)sd->revived << DEV_BSHIFT;                   /* write it to here */
181         bp->b_bio1.bio_driver_info = dev;
182         sdio(&bp->b_bio1);                                  /* perform the I/O */
183         biowait(&bp->b_bio1, "drvwr");
184         if (bp->b_flags & B_ERROR)
185             error = bp->b_error;
186         else {
187             sd->revived += bp->b_bcount >> DEV_BSHIFT;      /* moved this much further down */
188             if (sd->revived >= sd->sectors) {               /* finished */
189                 sd->revived = 0;
190                 set_sd_state(sdno, sd_up, setstate_force);  /* bring the sd up */
191                 log(LOG_INFO, "vinum: %s is %s\n", sd->name, sd_state(sd->state));
192                 save_config();                              /* and save the updated configuration */
193                 error = 0;                                  /* we're done */
194             }
195         }
196         if (lock)                                           /* we took a lock, */
197             unlockrange(sd->plexno, lock);                  /* give it back */
198         while (sd->waitlist) {                              /* we have waiting requests */
199 #if VINUMDEBUG
200             struct request *rq = sd->waitlist;
201             cdev_t dev;
202
203             if (debug & DEBUG_REVIVECONFLICT) {
204                 dev = rq->bio->bio_driver_info;
205                 log(LOG_DEBUG,
206                     "Relaunch revive conflict sd %d: %p\n%s dev %d.%d, offset 0x%llx, length %d\n",
207                     rq->sdno,
208                     rq,
209                     (rq->bio->bio_buf->b_cmd == BUF_CMD_READ) ? "Read" : "Write",
210                     major(dev),
211                     minor(dev),
212                     rq->bio->bio_offset,
213                     rq->bio->bio_buf->b_bcount);
214             }
215 #endif
216             launch_requests(sd->waitlist, 1);               /* do them now */
217             sd->waitlist = sd->waitlist->next;              /* and move on to the next */
218         }
219     }
220     Free(bp->b_data);
221     relpbuf(bp, &vinum_conf.physbufs);
222     return error;
223 }
224
225 /*
226  * Check or rebuild the parity blocks of a RAID-4
227  * or RAID-5 plex.
228  *
229  * The variables plex->checkblock and
230  * plex->rebuildblock represent the
231  * subdisk-relative address of the stripe we're
232  * looking at, not the plex-relative address.  We
233  * store it in the plex and not as a local
234  * variable because this function could be
235  * stopped, and we don't want to repeat the part
236  * we've already done.  This is also the reason
237  * why we don't initialize it here except at the
238  * end.  It gets initialized with the plex on
239  * creation.
240  *
241  * Each call to this function processes at most
242  * one stripe.  We can't loop in this function,
243  * because we're unstoppable, so we have to be
244  * called repeatedly from userland.
245  */
246 void
247 parityops(struct vinum_ioctl_msg *data)
248 {
249     int plexno;
250     struct plex *plex;
251     int size;                                               /* I/O transfer size, bytes */
252     int stripe;                                             /* stripe number in plex */
253     int psd;                                                /* parity subdisk number */
254     struct rangelock *lock;                                 /* lock on stripe */
255     struct _ioctl_reply *reply;
256     off_t pstripe;                                          /* pointer to our stripe counter */
257     struct buf *pbp;
258     off_t errorloc;                                         /* offset of parity error */
259     enum parityop op;                                       /* operation to perform */
260
261     plexno = data->index;
262     op = data->op;
263     pbp = NULL;
264     reply = (struct _ioctl_reply *) data;
265     reply->error = EAGAIN;                                  /* expect to repeat this call */
266     plex = &PLEX[plexno];
267     if (!isparity(plex)) {                                  /* not RAID-4 or RAID-5 */
268         reply->error = EINVAL;
269         return;
270     } else if (plex->state < plex_flaky) {
271         reply->error = EIO;
272         strcpy(reply->msg, "Plex is not completely accessible\n");
273         return;
274     }
275     pstripe = data->offset;
276     stripe = pstripe / plex->stripesize;                    /* stripe number */
277     psd = plex->subdisks - 1 - stripe % plex->subdisks;     /* parity subdisk for this stripe */
278     size = min(DEFAULT_REVIVE_BLOCKSIZE,                    /* one block at a time */
279         plex->stripesize << DEV_BSHIFT);
280
281     pbp = parityrebuild(plex, pstripe, size, op, &lock, &errorloc); /* do the grunt work */
282     if (pbp == NULL) {                                      /* no buffer space */
283         reply->error = ENOMEM;
284         return;                                             /* chicken out */
285     }
286     /*
287      * Now we have a result in the data buffer of
288      * the parity buffer header, which we have kept.
289      * Decide what to do with it.
290      */
291     reply->msg[0] = '\0';                                   /* until shown otherwise */
292     if ((pbp->b_flags & B_ERROR) == 0) {                    /* no error */
293         if ((op == rebuildparity)
294             || (op == rebuildandcheckparity)) {
295             pbp->b_cmd = BUF_CMD_WRITE;
296             pbp->b_resid = pbp->b_bcount;
297             sdio(&pbp->b_bio1);                             /* write the parity block */
298             biowait(&pbp->b_bio1, "drvwr");
299         }
300         if (((op == checkparity)
301                 || (op == rebuildandcheckparity))
302             && (errorloc != -1)) {
303             if (op == checkparity)
304                 reply->error = EIO;
305             ksprintf(reply->msg,
306                 "Parity incorrect at offset 0x%llx\n",
307                 errorloc);
308         }
309         if (reply->error == EAGAIN) {                       /* still OK, */
310             plex->checkblock = pstripe + (pbp->b_bcount >> DEV_BSHIFT); /* moved this much further down */
311             if (plex->checkblock >= SD[plex->sdnos[0]].sectors) { /* finished */
312                 plex->checkblock = 0;
313                 reply->error = 0;
314             }
315         }
316     }
317     if (pbp->b_flags & B_ERROR)
318         reply->error = pbp->b_error;
319     Free(pbp->b_data);
320     relpbuf(pbp, &vinum_conf.physbufs);
321     unlockrange(plexno, lock);
322 }
323
324 /*
325  * Rebuild a parity stripe.  Return pointer to
326  * parity bp.  On return,
327  *
328  * 1.  The band is locked.  The caller must unlock
329  *     the band and release the buffer header.
330  *
331  * 2.  All buffer headers except php have been
332  *     released.  The caller must release pbp.
333  *
334  * 3.  For checkparity and rebuildandcheckparity,
335  *     the parity is compared with the current
336  *     parity block.  If it's different, the
337  *     offset of the error is returned to
338  *     errorloc.  The caller can set the value of
339  *     the pointer to NULL if this is called for
340  *     rebuilding parity.
341  *
342  * pstripe is the subdisk-relative base address of
343  * the data to be reconstructed, size is the size
344  * of the transfer in bytes.
345  */
346 struct buf *
347 parityrebuild(struct plex *plex,
348     u_int64_t pstripe,
349     int size,
350     enum parityop op,
351     struct rangelock **lockp,
352     off_t * errorloc)
353 {
354     int error;
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             bpp[sdno] = getpbuf(&vinum_conf.physbufs);      /* Get a buffer */
395             bpp[sdno]->b_data = Malloc(mysize);
396             if (sdno == psd)
397                 parity_buf = (int *) bpp[sdno]->b_data;
398             if (sdno == newpsd)                             /* the new one? */
399                 bpp[sdno]->b_bio1.bio_driver_info = VINUM_SD(plex->sdnos[psd]); /* write back to the parity SD */
400             else
401                 bpp[sdno]->b_bio1.bio_driver_info = VINUM_SD(plex->sdnos[sdno]);        /* device number */
402             bpp[sdno]->b_cmd = BUF_CMD_READ;        /* either way, read it */
403             bpp[sdno]->b_bcount = mysize;
404             bpp[sdno]->b_resid = bpp[sdno]->b_bcount;
405             bpp[sdno]->b_bio1.bio_offset = (off_t)pstripe << DEV_BSHIFT;            /* transfer from here */
406         }
407     }
408
409     /* Initialize result buffer */
410     pbp = bpp[newpsd];
411     newparity_buf = (int *) bpp[newpsd]->b_data;
412     bzero(newparity_buf, mysize);
413
414     /*
415      * Now lock the stripe with the first non-parity
416      * bp as locking bp.
417      */
418     *lockp = lockrange(pstripe * plex->stripesize * (plex->subdisks - 1),
419         bpp[psd ? 0 : 1],
420         plex);
421
422     /*
423      * Then issue requests for all subdisks in
424      * parallel.  Don't transfer the parity stripe
425      * if we're rebuilding parity, unless we also
426      * want to check it.
427      */
428     for (sdno = 0; sdno < plex->subdisks; sdno++) {         /* for each real subdisk */
429         if ((sdno != psd) || (op != rebuildparity)) {
430             sdio(&bpp[sdno]->b_bio1);
431         }
432     }
433
434     /*
435      * Next, wait for the requests to complete.
436      * We wait in the order in which they were
437      * issued, which isn't necessarily the order in
438      * which they complete, but we don't have a
439      * convenient way of doing the latter, and the
440      * delay is minimal.
441      */
442     for (sdno = 0; sdno < plex->subdisks; sdno++) {         /* for each subdisk */
443         if ((sdno != psd) || (op != rebuildparity)) {
444             biowait(&bpp[sdno]->b_bio1, "drvio");
445             if (bpp[sdno]->b_flags & B_ERROR)               /* can't read, */
446                 error = bpp[sdno]->b_error;
447             else if (sdno != psd) {                         /* update parity */
448                 sbuf = (int *) bpp[sdno]->b_data;
449                 for (i = 0; i < isize; i++)
450                     ((int *) newparity_buf)[i] ^= sbuf[i];  /* xor in the buffer */
451             }
452         }
453         if (sdno != psd) {                                  /* release all bps except parity */
454             Free(bpp[sdno]->b_data);
455             relpbuf(bpp[sdno], &vinum_conf.physbufs);       /* give back our resources */
456         }
457     }
458
459     /*
460      * If we're checking, compare the calculated
461      * and the read parity block.  If they're
462      * different, return the plex-relative offset;
463      * otherwise return -1.
464      */
465     if ((op == checkparity)
466         || (op == rebuildandcheckparity)) {
467         *errorloc = -1;                                     /* no error yet */
468         for (i = 0; i < isize; i++) {
469             if (parity_buf[i] != newparity_buf[i]) {
470                 *errorloc = (off_t) (pstripe << DEV_BSHIFT) * (plex->subdisks - 1)
471                     + i * sizeof(int);
472                 break;
473             }
474         }
475         Free(bpp[psd]->b_data);
476         relpbuf(bpp[psd], &vinum_conf.physbufs);            /* give back our resources */
477     }
478     /* release our resources */
479     Free(bpp);
480     if (error) {
481         pbp->b_flags |= B_ERROR;
482         pbp->b_error = error;
483     }
484     return pbp;
485 }
486
487 /*
488  * Initialize a subdisk by writing zeroes to the
489  * complete address space.  If verify is set,
490  * check each transfer for correctness.
491  *
492  * Each call to this function writes (and maybe
493  * checks) a single block.
494  */
495 int
496 initsd(int sdno, int verify)
497 {
498     struct sd *sd;
499     struct plex *plex;
500     struct volume *vol;
501     struct buf *bp;
502     int error;
503     int size;                                               /* size of init block, bytes */
504     daddr_t plexblkno;                                      /* lblkno in plex */
505     int verified;                                           /* set when we're happy with what we wrote */
506
507     error = 0;
508     plexblkno = 0;                                          /* to keep the compiler happy */
509     sd = &SD[sdno];
510     if (sd->plexno < 0)                                     /* no plex? */
511         return EINVAL;
512     plex = &PLEX[sd->plexno];                               /* point to plex */
513     if (plex->volno >= 0)
514         vol = &VOL[plex->volno];
515     else
516         vol = NULL;
517
518     if (sd->init_blocksize == 0) {
519         if (plex->stripesize != 0)                          /* we're striped, don't init more than */
520             sd->init_blocksize = min(DEFAULT_REVIVE_BLOCKSIZE, /* one block at a time */
521                 plex->stripesize << DEV_BSHIFT);
522         else
523             sd->init_blocksize = DEFAULT_REVIVE_BLOCKSIZE;
524     } else if (sd->init_blocksize > MAX_REVIVE_BLOCKSIZE)
525         sd->init_blocksize = MAX_REVIVE_BLOCKSIZE;
526
527     size = min(sd->init_blocksize >> DEV_BSHIFT, sd->sectors - sd->initialized) << DEV_BSHIFT;
528
529     bp = getpbuf(&vinum_conf.physbufs);             /* Get a buffer */
530     bp->b_data = Malloc(size);
531
532     verified = 0;
533     while (!verified) {                                     /* until we're happy with it, */
534         bp->b_bcount = size;
535         bp->b_resid = bp->b_bcount;
536         bp->b_bio1.bio_offset = (off_t)sd->initialized << DEV_BSHIFT;               /* write it to here */
537         bp->b_bio1.bio_driver_info = VINUM_SD(sdno);
538         bzero(bp->b_data, bp->b_bcount);
539         bp->b_cmd = BUF_CMD_WRITE;
540         sdio(&bp->b_bio1);                  /* perform the I/O */
541         biowait(&bp->b_bio1, "drvwr");
542         if (bp->b_flags & B_ERROR)
543             error = bp->b_error;
544         if ((error == 0) && verify) {                       /* check that it got there */
545             bp->b_bcount = size;
546             bp->b_resid = bp->b_bcount;
547             bp->b_bio1.bio_offset = (off_t)sd->initialized << DEV_BSHIFT;           /* read from here */
548             bp->b_bio1.bio_driver_info = VINUM_SD(sdno);
549             bp->b_cmd = BUF_CMD_READ;               /* read it back */
550             sdio(&bp->b_bio1);
551             biowait(&bp->b_bio1, "drvrd");
552             /*
553              * XXX Bug fix code.  This is hopefully no
554              * longer needed (21 February 2000).
555              */
556             if (bp->b_flags & B_ERROR)
557                 error = bp->b_error;
558             else if ((*bp->b_data != 0)             /* first word spammed */
559             ||(bcmp(bp->b_data, &bp->b_data[1], bp->b_bcount - 1))) { /* or one of the others */
560                 kprintf("vinum: init error on %s, offset 0x%llx sectors\n",
561                     sd->name,
562                     (long long) sd->initialized);
563                 verified = 0;
564             } else
565                 verified = 1;
566         } else
567             verified = 1;
568     }
569     Free(bp->b_data);
570     relpbuf(bp, &vinum_conf.physbufs);
571     if (error == 0) {                                       /* did it, */
572         sd->initialized += size >> DEV_BSHIFT;              /* moved this much further down */
573         if (sd->initialized >= sd->sectors) {               /* finished */
574             sd->initialized = 0;
575             set_sd_state(sdno, sd_initialized, setstate_force); /* bring the sd up */
576             log(LOG_INFO, "vinum: %s is %s\n", sd->name, sd_state(sd->state));
577             save_config();                                  /* and save the updated configuration */
578         } else                                              /* more to go, */
579             error = EAGAIN;                                 /* ya'll come back, see? */
580     }
581     return error;
582 }
583
584 /* Local Variables: */
585 /* fill-column: 50 */
586 /* End: */