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