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

Cache object: 08dbddecc3ab55648ed32f4e3b1e6086


[ 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.