The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/vinum/vinumrevive.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 458d4d92c01c74c8d978dd6ba8625ae6


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.