Home | History | Annotate | Line # | Download | only in raidctl
rf_configure.c revision 1.3
      1 /*
      2  * Copyright (c) 1995 Carnegie-Mellon University.
      3  * All rights reserved.
      4  *
      5  * Author: Mark Holland
      6  *
      7  * Permission to use, copy, modify and distribute this software and
      8  * its documentation is hereby granted, provided that both the copyright
      9  * notice and this permission notice appear in all copies of the
     10  * software, derivative works or modified versions, and any portions
     11  * thereof, and that both notices appear in supporting documentation.
     12  *
     13  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     14  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     15  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     16  *
     17  * Carnegie Mellon requests users of this software to return to
     18  *
     19  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     20  *  School of Computer Science
     21  *  Carnegie Mellon University
     22  *  Pittsburgh PA 15213-3890
     23  *
     24  * any improvements or extensions that they make and grant Carnegie the
     25  * rights to redistribute these changes.
     26  */
     27 
     28 /***************************************************************
     29  *
     30  * rf_configure.c -- code related to configuring the raidframe system
     31  *
     32  * configuration is complicated by the fact that we want the same
     33  * driver to work both in the kernel and at user level.  In the
     34  * kernel, we can't read the configuration file, so we configure
     35  * by running a user-level program that reads the config file,
     36  * creates a data structure describing the configuration and
     37  * passes it into the kernel via an ioctl.  Since we want the config
     38  * code to be common between the two versions of the driver, we
     39  * configure using the same two-step process when running at
     40  * user level.  Of course, at user level, the config structure is
     41  * passed directly to the config routine, rather than via ioctl.
     42  *
     43  * This file is not compiled into the kernel, so we have no
     44  * need for KERNEL ifdefs.
     45  *
     46  **************************************************************/
     47 
     48 /* $Locker:  $
     49  * $Log: rf_configure.c,v $
     50  * Revision 1.3  1999/01/12 22:58:10  mjacob
     51  * recover from errno.h changes
     52  *
     53  * Revision 1.2  1998/11/23 00:18:40  mrg
     54  * fix compile errors on the alpha.
     55  *
     56  * Revision 1.1  1998/11/13 04:34:02  oster
     57  *
     58  * RAIDframe, version 1.1, from the Parallel Data Laboratory at
     59  * Carnegie Mellon University.  Full RAID implementation, including
     60  * levels 0, 1, 4, 5, 6, parity logging, and a few other goodies.
     61  * Ported to NetBSD by Greg Oster.
     62  *
     63  * raidctl is our userland configuration tool for RAIDframe.
     64  *
     65  * Revision 1.42  1996/08/09 18:47:47  jimz
     66  * major -> dev_major
     67  *
     68  * Revision 1.41  1996/07/29  14:05:12  jimz
     69  * fix numPUs/numRUs confusion (everything is now numRUs)
     70  * clean up some commenting, return values
     71  *
     72  * Revision 1.40  1996/07/27  23:36:08  jimz
     73  * Solaris port of simulator
     74  *
     75  * Revision 1.39  1996/07/27  18:39:45  jimz
     76  * cleanup sweep
     77  *
     78  * Revision 1.38  1996/07/18  22:57:14  jimz
     79  * port simulator to AIX
     80  *
     81  * Revision 1.37  1996/06/19  14:58:02  jimz
     82  * move layout-specific config parsing hooks into RF_LayoutSW_t
     83  * table in rf_layout.c
     84  *
     85  * Revision 1.36  1996/06/17  14:38:33  jimz
     86  * properly #if out RF_DEMO code
     87  * fix bug in MakeConfig that was causing weird behavior
     88  * in configuration routines (config was not zeroed at start)
     89  * clean up genplot handling of stacks
     90  *
     91  * Revision 1.35  1996/06/05  19:38:32  jimz
     92  * fixed up disk queueing types config
     93  * added sstf disk queueing
     94  * fixed exit bug on diskthreads (ref-ing bad mem)
     95  *
     96  * Revision 1.34  1996/06/03  23:28:26  jimz
     97  * more bugfixes
     98  * check in tree to sync for IPDS runs with current bugfixes
     99  * there still may be a problem with threads in the script test
    100  * getting I/Os stuck- not trivially reproducible (runs ~50 times
    101  * in a row without getting stuck)
    102  *
    103  * Revision 1.33  1996/06/02  17:31:48  jimz
    104  * Moved a lot of global stuff into array structure, where it belongs.
    105  * Fixed up paritylogging, pss modules in this manner. Some general
    106  * code cleanup. Removed lots of dead code, some dead files.
    107  *
    108  * Revision 1.32  1996/05/30  23:22:16  jimz
    109  * bugfixes of serialization, timing problems
    110  * more cleanup
    111  *
    112  * Revision 1.31  1996/05/30  11:29:41  jimz
    113  * Numerous bug fixes. Stripe lock release code disagreed with the taking code
    114  * about when stripes should be locked (I made it consistent: no parity, no lock)
    115  * There was a lot of extra serialization of I/Os which I've removed- a lot of
    116  * it was to calculate values for the cache code, which is no longer with us.
    117  * More types, function, macro cleanup. Added code to properly quiesce the array
    118  * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
    119  * before. Fixed memory allocation, freeing bugs.
    120  *
    121  * Revision 1.30  1996/05/27  18:56:37  jimz
    122  * more code cleanup
    123  * better typing
    124  * compiles in all 3 environments
    125  *
    126  * Revision 1.29  1996/05/24  01:59:45  jimz
    127  * another checkpoint in code cleanup for release
    128  * time to sync kernel tree
    129  *
    130  * Revision 1.28  1996/05/18  19:51:34  jimz
    131  * major code cleanup- fix syntax, make some types consistent,
    132  * add prototypes, clean out dead code, et cetera
    133  *
    134  * Revision 1.27  1995/12/12  18:10:06  jimz
    135  * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
    136  * fix 80-column brain damage in comments
    137  *
    138  * Revision 1.26  1995/12/01  15:16:36  root
    139  * added copyright info
    140  *
    141  */
    142 
    143 
    144 #include <stdio.h>
    145 #include <errno.h>
    146 #include <sys/types.h>
    147 #include <sys/stat.h>
    148 #include "rf_raid.h"
    149 #include "rf_raidframe.h"
    150 #include "rf_utils.h"
    151 #include "rf_general.h"
    152 #include "rf_decluster.h"
    153 #include "rf_configure.h"
    154 #include "rf_sys.h"
    155 
    156 /*
    157 
    158    XXX we include this here so we don't need to drag rf_debugMem.c into
    159    the picture...  This is userland, afterall...
    160 
    161  */
    162 
    163 /* XXX sucky hack to override the defn. of RF_Malloc as given in
    164 rf_debugMem.c...  but I *really* don't want (nor need) to link with
    165 that file here in userland..  GO
    166 */
    167 
    168 #undef RF_Malloc
    169 #define RF_Malloc(_p_, _size_, _cast_) \
    170   { \
    171      _p_ = _cast_ malloc((u_long)_size_); \
    172      bzero((char *)_p_, _size_); \
    173   }
    174 
    175 
    176 
    177 #ifndef SIMULATE
    178 static unsigned int dev_name2num(char *s);
    179 static unsigned int osf_dev_name2num(char *s);
    180 #endif
    181 static int rf_search_file_for_start_of(char *string, char *buf, int len,
    182 	FILE *fp);
    183 static int rf_get_next_nonblank_line(char *buf, int len, FILE *fp,
    184 	char *errmsg);
    185 
    186 /* called from user level to read the configuration file and create
    187  * a configuration control structure.  This is used in the user-level
    188  * version of the driver, and in the user-level program that configures
    189  * the system via ioctl.
    190  */
    191 int rf_MakeConfig(configname, cfgPtr)
    192   char         *configname;
    193   RF_Config_t  *cfgPtr;
    194 {
    195   int numscanned, val, r, c, retcode, aa, bb, cc;
    196   char buf[256], buf1[256], *cp;
    197   RF_LayoutSW_t *lp;
    198   FILE *fp;
    199 
    200   bzero((char *)cfgPtr, sizeof(RF_Config_t));
    201 
    202   fp = fopen(configname, "r");
    203   if (!fp) {
    204     RF_ERRORMSG1("Can't open config file %s\n",configname);
    205     return(-1);
    206   }
    207 
    208   rewind(fp);
    209   if (rf_search_file_for_start_of("array", buf, 256, fp)) {
    210     RF_ERRORMSG1("Unable to find start of \"array\" params in config file %s\n",configname);
    211     retcode = -1; goto out;
    212   }
    213   rf_get_next_nonblank_line(buf, 256, fp, "Config file error (\"array\" section):  unable to get numRow and numCol\n");
    214   /*
    215    * wackiness with aa, bb, cc to get around size problems on different platforms
    216    */
    217   numscanned = sscanf(buf,"%d %d %d", &aa, &bb, &cc);
    218   if (numscanned != 3) {
    219     RF_ERRORMSG("Config file error (\"array\" section):  unable to get numRow, numCol, numSpare\n");
    220     retcode = -1; goto out;
    221   }
    222   cfgPtr->numRow = (RF_RowCol_t)aa;
    223   cfgPtr->numCol = (RF_RowCol_t)bb;
    224   cfgPtr->numSpare = (RF_RowCol_t)cc;
    225 
    226   /* debug section is optional */
    227   for (c=0; c<RF_MAXDBGV; c++)
    228     cfgPtr->debugVars[c][0] = '\0';
    229   rewind(fp);
    230   if (!rf_search_file_for_start_of("debug", buf, 256, fp)) {
    231     for (c=0; c < RF_MAXDBGV; c++) {
    232       if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) break;
    233       cp = rf_find_non_white(buf);
    234       if (!strncmp(cp, "START", strlen("START"))) break;
    235       (void) strcpy(&cfgPtr->debugVars[c][0], cp);
    236     }
    237   }
    238 
    239   rewind(fp);
    240   strcpy(cfgPtr->diskQueueType,"fifo");
    241   cfgPtr->maxOutstandingDiskReqs = 1;
    242   /* scan the file for the block related to disk queues */
    243   if (rf_search_file_for_start_of("queue",buf,256,fp)) {
    244     RF_ERRORMSG2("[No disk queue discipline specified in config file %s.  Using %s.]\n",configname, cfgPtr->diskQueueType);
    245   } else {
    246     if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) {
    247       RF_ERRORMSG2("[No disk queue discipline specified in config file %s.  Using %s.]\n",configname, cfgPtr->diskQueueType);
    248     }
    249   }
    250 
    251   /* the queue specifier line contains two entries:
    252    * 1st char of first word specifies queue to be used
    253    * 2nd word specifies max num reqs that can be outstanding on the disk itself (typically 1)
    254    */
    255   if (sscanf(buf,"%s %d",buf1,&val)!=2) {
    256     RF_ERRORMSG1("Can't determine queue type and/or max outstanding reqs from line: %s",buf);
    257     RF_ERRORMSG2("Using %s-%d\n", cfgPtr->diskQueueType, cfgPtr->maxOutstandingDiskReqs);
    258   } else {
    259     char *c;
    260     bcopy(buf1, cfgPtr->diskQueueType, RF_MIN(sizeof(cfgPtr->diskQueueType), strlen(buf1)+1));
    261     for(c=buf1;*c;c++) {
    262       if (*c == ' ') {
    263         *c = '\0';
    264         break;
    265       }
    266     }
    267     cfgPtr->maxOutstandingDiskReqs = val;
    268   }
    269 
    270   rewind(fp);
    271 
    272 
    273   if (rf_search_file_for_start_of("disks",buf,256,fp)) {
    274     RF_ERRORMSG1("Can't find \"disks\" section in config file %s\n",configname);
    275     retcode = -1; goto out;
    276   }
    277 
    278   for (r=0; r<cfgPtr->numRow; r++) {
    279     for (c=0; c<cfgPtr->numCol; c++) {
    280       if (rf_get_next_nonblank_line(&cfgPtr->devnames[r][c][0], 50, fp, NULL)) {
    281 	RF_ERRORMSG2("Config file error: unable to get device file for disk at row %d col %d\n",r,c);
    282 	retcode = -1; goto out;
    283       }
    284 #ifndef SIMULATE
    285       val = dev_name2num(&cfgPtr->devnames[r][c][0]);
    286 
    287       if (val < 0) {
    288 	RF_ERRORMSG3("Config file error: can't get dev num (dev file '%s') for disk at row %d c %d\n",
    289 		  &cfgPtr->devnames[r][c][0],r,c);
    290 	retcode = -1; goto out;
    291       } else cfgPtr->devs[r][c] = val;
    292 #endif /* !SIMULATE */
    293     }
    294   }
    295 
    296   /* "spare" section is optional */
    297   rewind(fp);
    298   if (rf_search_file_for_start_of("spare",buf,256,fp)) cfgPtr->numSpare =0;
    299   for (c = 0; c < cfgPtr->numSpare; c++) {
    300     if (rf_get_next_nonblank_line(&cfgPtr->spare_names[c][0], 256, fp, NULL)) {
    301       RF_ERRORMSG1("Config file error: unable to get device file for spare disk %d\n",c);
    302       retcode = -1; goto out;
    303     }
    304 #ifndef SIMULATE
    305     val = dev_name2num(&cfgPtr->spare_names[c][0]);
    306     if (val < 0) {
    307       RF_ERRORMSG2("Config file error: can't get dev num (dev file '%s') for spare disk %d\n",
    308 		&cfgPtr->spare_names[c][0],c);
    309       retcode = -1; goto out;
    310     } else cfgPtr->spare_devs[c] = val;
    311 #endif /* !SIMULATE */
    312   }
    313 
    314   /* scan the file for the block related to layout */
    315   rewind(fp);
    316   if (rf_search_file_for_start_of("layout",buf,256,fp)) {
    317     RF_ERRORMSG1("Can't find \"layout\" section in configuration file %s\n",configname);
    318     retcode = -1; goto out;
    319   }
    320   if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) {
    321     RF_ERRORMSG("Config file error (\"layout\" section): unable to find common layout param line\n");
    322     retcode = -1; goto out;
    323   }
    324   c = sscanf(buf,"%d %d %d %c", &aa, &bb, &cc, &cfgPtr->parityConfig);
    325   cfgPtr->sectPerSU = (RF_SectorNum_t)aa;
    326   cfgPtr->SUsPerPU = (RF_StripeNum_t)bb;
    327   cfgPtr->SUsPerRU = (RF_StripeNum_t)cc;
    328   if (c != 4) {
    329     RF_ERRORMSG("Unable to scan common layout line\n");
    330     retcode = -1; goto out;
    331   }
    332   lp = rf_GetLayout(cfgPtr->parityConfig);
    333   if (lp == NULL) {
    334     RF_ERRORMSG1("Unknown parity config '%c'\n", cfgPtr->parityConfig);
    335     retcode = -1;
    336     goto out;
    337   }
    338 
    339   /* XXX who cares.. it's not going into the kernel, so we should ignore this... */
    340 #ifndef KERNEL
    341   retcode = lp->MakeLayoutSpecific(fp, cfgPtr, lp->makeLayoutSpecificArg);
    342 #endif
    343 out:
    344   fclose(fp);
    345   if (retcode < 0)
    346     retcode = errno = EINVAL;
    347   else
    348     errno = retcode;
    349   return(retcode);
    350 }
    351 
    352 
    353 /* used in architectures such as RAID0 where there is no layout-specific
    354  * information to be passed into the configuration code.
    355  */
    356 int rf_MakeLayoutSpecificNULL(fp, cfgPtr, ignored)
    357   FILE         *fp;
    358   RF_Config_t  *cfgPtr;
    359   void         *ignored;
    360 {
    361   cfgPtr->layoutSpecificSize = 0;
    362   cfgPtr->layoutSpecific     = NULL;
    363   return(0);
    364 }
    365 
    366 int rf_MakeLayoutSpecificDeclustered(configfp, cfgPtr, arg)
    367   FILE         *configfp;
    368   RF_Config_t  *cfgPtr;
    369   void         *arg;
    370 {
    371   int b, v, k, r, lambda, norotate, i, val, distSpare;
    372   char *cfgBuf, *bdfile, *p, *smname;
    373   char buf[256], smbuf[256];
    374   FILE *fp;
    375 
    376   distSpare = *((int *)arg);
    377 
    378   /* get the block design file name */
    379   if (rf_get_next_nonblank_line(buf,256,configfp,"Can't find block design file name in config file\n"))
    380     return(EINVAL);
    381   bdfile = rf_find_non_white(buf);
    382   if (bdfile[strlen(bdfile)-1] == '\n') {
    383     /* strip newline char */
    384     bdfile[strlen(bdfile)-1] = '\0';
    385   }
    386 
    387   /* open bd file, check validity of configuration */
    388   if ((fp = fopen(bdfile,"r"))==NULL) {
    389     RF_ERRORMSG1("RAID: config error: Can't open layout table file %s\n",bdfile);
    390     return(EINVAL);
    391   }
    392 
    393   fgets(buf,256,fp);
    394   i = sscanf(buf,"%u %u %u %u %u %u",&b,&v,&k,&r,&lambda,&norotate);
    395   if (i == 5)
    396     norotate = 0; /* no-rotate flag is optional */
    397   else if (i != 6) {
    398     RF_ERRORMSG("Unable to parse header line in block design file\n");
    399     return(EINVAL);
    400   }
    401 
    402   /* set the sparemap directory.  In the in-kernel version, there's a daemon
    403    * that's responsible for finding the sparemaps
    404    */
    405   if (distSpare) {
    406     if (rf_get_next_nonblank_line(smbuf,256,configfp,"Can't find sparemap file name in config file\n"))
    407       return(EINVAL);
    408     smname = rf_find_non_white(smbuf);
    409     if (smname[strlen(smname)-1] == '\n') {
    410       /* strip newline char */
    411       smname[strlen(smname)-1] = '\0';
    412     }
    413   }
    414   else {
    415     smbuf[0] = '\0';
    416     smname = smbuf;
    417   }
    418 
    419   /* allocate a buffer to hold the configuration info */
    420   cfgPtr->layoutSpecificSize = RF_SPAREMAP_NAME_LEN + 6 * sizeof(int) + b * k;
    421   /* can't use RF_Malloc here b/c debugMem module not yet init'd */
    422   cfgBuf = (char *) malloc(cfgPtr->layoutSpecificSize);
    423   cfgPtr->layoutSpecific = (void *) cfgBuf;
    424   p = cfgBuf;
    425 
    426   /* install name of sparemap file */
    427   for (i=0; smname[i]; i++)
    428     *p++ = smname[i];
    429   /* pad with zeros */
    430   while (i<RF_SPAREMAP_NAME_LEN) {
    431     *p++ = '\0';
    432     i++;
    433   }
    434 
    435   /*
    436    * fill in the buffer with the block design parameters
    437    * and then the block design itself
    438    */
    439   *( (int *) p) = b;        p += sizeof(int);
    440   *( (int *) p) = v;        p += sizeof(int);
    441   *( (int *) p) = k;        p += sizeof(int);
    442   *( (int *) p) = r;        p += sizeof(int);
    443   *( (int *) p) = lambda;   p += sizeof(int);
    444   *( (int *) p) = norotate; p += sizeof(int);
    445 
    446   while (fscanf(fp,"%d",&val) == 1)
    447     *p++ = (char) val;
    448   fclose(fp);
    449   if (p - cfgBuf != cfgPtr->layoutSpecificSize) {
    450       RF_ERRORMSG2("Size mismatch creating layout specific data: is %d sb %d bytes\n",(int)(p-cfgBuf),(int)(6*sizeof(int)+b*k));
    451       return(EINVAL);
    452   }
    453   return(0);
    454 }
    455 
    456 
    457 /****************************************************************************
    458  *
    459  * utilities
    460  *
    461  ***************************************************************************/
    462 #ifndef SIMULATE
    463 /* convert a device file name to a device number */
    464 static unsigned int dev_name2num(s)
    465   char  *s;
    466 {
    467   struct stat buf;
    468 
    469   if (stat(s, &buf) < 0) return(osf_dev_name2num(s));
    470   else return(buf.st_rdev);
    471 }
    472 
    473 /* converts an osf/1 style device name to a device number.  We use this
    474  * only if the stat of the device file fails.
    475  */
    476 static unsigned int osf_dev_name2num(s)
    477   char  *s;
    478 {
    479   int num;
    480   char part_ch, lun_ch;
    481   unsigned int bus, target, lun, part, dev_major;
    482 
    483   dev_major = RF_SCSI_DISK_MAJOR;
    484   if (sscanf(s,"/dev/rrz%d%c", &num, &part_ch) == 2) {
    485     bus = num>>3;
    486     target = num & 0x7;
    487     part = part_ch - 'a';
    488     lun = 0;
    489   } else if (sscanf(s,"/dev/rrz%c%d%c", &lun_ch, &num, &part_ch) == 3) {
    490     bus = num>>3;
    491     target = num & 0x7;
    492     part = part_ch - 'a';
    493     lun = lun_ch - 'a' + 1;
    494   } else {
    495     RF_ERRORMSG1("Unable to parse disk dev file name %s\n",s);
    496     return(-1);
    497   }
    498 
    499   return( (dev_major<<20) | (bus<<14) | (target<<10) | (lun<<6) | part );
    500 }
    501 #endif
    502 
    503 /* searches a file for a line that says "START string", where string is
    504  * specified as a parameter
    505  */
    506 static int rf_search_file_for_start_of(string, buf, len, fp)
    507   char  *string;
    508   char  *buf;
    509   int    len;
    510   FILE  *fp;
    511 {
    512   char *p;
    513 
    514   while (1) {
    515     if (fgets(buf, len, fp) == NULL) return(-1);
    516     p = rf_find_non_white(buf);
    517     if (!strncmp(p, "START", strlen("START"))) {
    518       p = rf_find_white(p);
    519       p = rf_find_non_white(p);
    520       if (!strncmp(p, string, strlen(string))) return(0);
    521     }
    522   }
    523 }
    524 
    525 /* reads from file fp into buf until it finds an interesting line */
    526 int rf_get_next_nonblank_line(buf, len, fp, errmsg)
    527   char  *buf;
    528   int    len;
    529   FILE  *fp;
    530   char  *errmsg;
    531 {
    532   char *p;
    533 
    534   while (fgets(buf,256,fp) != NULL) {
    535     p = rf_find_non_white(buf);
    536     if (*p == '\n' || *p == '\0' || *p == '#') continue;
    537     return(0);
    538   }
    539   if (errmsg) RF_ERRORMSG(errmsg);
    540   return(1);
    541 }
    542 
    543 /* Allocates an array for the spare table, and initializes it from a file.
    544  * In the user-level version, this is called when recon is initiated.
    545  * When/if I move recon into the kernel, there'll be a daemon that does
    546  * an ioctl into raidframe which will block until a spare table is needed.
    547  * When it returns, it will read a spare table from the file system,
    548  * pass it into the kernel via a different ioctl, and then block again
    549  * on the original ioctl.
    550  *
    551  * This is specific to the declustered layout, but doesn't belong in
    552  * rf_decluster.c because it uses stuff that can't be compiled into
    553  * the kernel, and it needs to be compiled into the user-level sparemap daemon.
    554  *
    555  */
    556 void *rf_ReadSpareTable(req, fname)
    557   RF_SparetWait_t  *req;
    558   char             *fname;
    559 {
    560   int i, j, numFound, linecount, tableNum, tupleNum, spareDisk, spareBlkOffset;
    561   char buf[1024], targString[100], errString[100];
    562   RF_SpareTableEntry_t **table;
    563   FILE *fp;
    564 
    565   /* allocate and initialize the table */
    566   RF_Malloc(table, req->TablesPerSpareRegion * sizeof(RF_SpareTableEntry_t *), (RF_SpareTableEntry_t **));
    567   for (i=0; i<req->TablesPerSpareRegion; i++) {
    568     RF_Malloc(table[i], req->BlocksPerTable * sizeof(RF_SpareTableEntry_t), (RF_SpareTableEntry_t *));
    569     for (j=0; j<req->BlocksPerTable; j++) table[i][j].spareDisk = table[i][j].spareBlockOffsetInSUs = -1;
    570   }
    571 
    572   /* 2.  open sparemap file, sanity check */
    573   if ((fp = fopen(fname,"r"))==NULL) {
    574     fprintf(stderr,"rf_ReadSpareTable:  Can't open sparemap file %s\n",fname);  return(NULL);
    575   }
    576   if (rf_get_next_nonblank_line(buf,1024,fp,"Invalid sparemap file:  can't find header line\n"))
    577     return(NULL);
    578   if (buf[strlen(buf)-1] == '\n')
    579     buf[strlen(buf)-1] = '\0';
    580 
    581   sprintf(targString, "fdisk %d\n", req->fcol);
    582   sprintf(errString, "Invalid sparemap file:  can't find \"fdisk %d\" line\n",req->fcol);
    583   while (1) {
    584     rf_get_next_nonblank_line(buf,1024,fp,errString);
    585     if (!strncmp(buf,targString,strlen(targString))) break;
    586   }
    587 
    588   /* no more blank lines or comments allowed now */
    589   linecount = req->TablesPerSpareRegion * req->TableDepthInPUs;
    590   for (i=0; i<linecount; i++) {
    591     numFound = fscanf(fp," %d %d %d %d",&tableNum, &tupleNum, &spareDisk, &spareBlkOffset);
    592     if (numFound != 4) {
    593       fprintf(stderr,"Sparemap file prematurely exhausted after %d of %d lines\n",i,linecount); return(NULL);
    594     }
    595     RF_ASSERT(tableNum >= 0 && tableNum < req->TablesPerSpareRegion);
    596     RF_ASSERT(tupleNum >= 0 && tupleNum < req->BlocksPerTable);
    597     RF_ASSERT(spareDisk >= 0 && spareDisk < req->C);
    598     RF_ASSERT(spareBlkOffset >= 0 && spareBlkOffset < req->SpareSpaceDepthPerRegionInSUs / req->SUsPerPU);
    599 
    600     table[tableNum][tupleNum].spareDisk = spareDisk;
    601     table[tableNum][tupleNum].spareBlockOffsetInSUs = spareBlkOffset * req->SUsPerPU;
    602   }
    603 
    604   fclose(fp);
    605   return((void *) table);
    606 }
    607