rf_configure.c revision 1.7 1 1.7 oster /* $NetBSD: rf_configure.c,v 1.7 1999/08/07 23:48:11 oster Exp $ */
2 1.1 oster /*
3 1.1 oster * Copyright (c) 1995 Carnegie-Mellon University.
4 1.1 oster * All rights reserved.
5 1.1 oster *
6 1.1 oster * Author: Mark Holland
7 1.1 oster *
8 1.1 oster * Permission to use, copy, modify and distribute this software and
9 1.1 oster * its documentation is hereby granted, provided that both the copyright
10 1.1 oster * notice and this permission notice appear in all copies of the
11 1.1 oster * software, derivative works or modified versions, and any portions
12 1.1 oster * thereof, and that both notices appear in supporting documentation.
13 1.1 oster *
14 1.1 oster * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 1.1 oster * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 1.1 oster * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 1.1 oster *
18 1.1 oster * Carnegie Mellon requests users of this software to return to
19 1.1 oster *
20 1.1 oster * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 1.1 oster * School of Computer Science
22 1.1 oster * Carnegie Mellon University
23 1.1 oster * Pittsburgh PA 15213-3890
24 1.1 oster *
25 1.1 oster * any improvements or extensions that they make and grant Carnegie the
26 1.1 oster * rights to redistribute these changes.
27 1.1 oster */
28 1.1 oster
29 1.1 oster /***************************************************************
30 1.1 oster *
31 1.1 oster * rf_configure.c -- code related to configuring the raidframe system
32 1.1 oster *
33 1.1 oster * configuration is complicated by the fact that we want the same
34 1.1 oster * driver to work both in the kernel and at user level. In the
35 1.1 oster * kernel, we can't read the configuration file, so we configure
36 1.1 oster * by running a user-level program that reads the config file,
37 1.1 oster * creates a data structure describing the configuration and
38 1.1 oster * passes it into the kernel via an ioctl. Since we want the config
39 1.1 oster * code to be common between the two versions of the driver, we
40 1.1 oster * configure using the same two-step process when running at
41 1.1 oster * user level. Of course, at user level, the config structure is
42 1.1 oster * passed directly to the config routine, rather than via ioctl.
43 1.1 oster *
44 1.1 oster * This file is not compiled into the kernel, so we have no
45 1.1 oster * need for KERNEL ifdefs.
46 1.1 oster *
47 1.1 oster **************************************************************/
48 1.1 oster
49 1.1 oster #include <stdio.h>
50 1.4 oster #include <stdlib.h>
51 1.3 mjacob #include <errno.h>
52 1.4 oster #include <strings.h>
53 1.1 oster #include <sys/types.h>
54 1.1 oster #include <sys/stat.h>
55 1.1 oster #include "rf_raid.h"
56 1.1 oster #include "rf_raidframe.h"
57 1.1 oster #include "rf_general.h"
58 1.1 oster #include "rf_decluster.h"
59 1.1 oster #include "rf_configure.h"
60 1.1 oster #include "rf_sys.h"
61 1.1 oster
62 1.1 oster /*
63 1.1 oster
64 1.1 oster XXX we include this here so we don't need to drag rf_debugMem.c into
65 1.1 oster the picture... This is userland, afterall...
66 1.1 oster
67 1.1 oster */
68 1.1 oster
69 1.1 oster /* XXX sucky hack to override the defn. of RF_Malloc as given in
70 1.1 oster rf_debugMem.c... but I *really* don't want (nor need) to link with
71 1.1 oster that file here in userland.. GO
72 1.1 oster */
73 1.1 oster
74 1.1 oster #undef RF_Malloc
75 1.1 oster #define RF_Malloc(_p_, _size_, _cast_) \
76 1.1 oster { \
77 1.1 oster _p_ = _cast_ malloc((u_long)_size_); \
78 1.1 oster bzero((char *)_p_, _size_); \
79 1.1 oster }
80 1.1 oster
81 1.7 oster char *rf_find_non_white(char *p);
82 1.7 oster char *rf_find_white(char *p);
83 1.7 oster
84 1.1 oster
85 1.1 oster
86 1.1 oster static int rf_search_file_for_start_of(char *string, char *buf, int len,
87 1.1 oster FILE *fp);
88 1.1 oster static int rf_get_next_nonblank_line(char *buf, int len, FILE *fp,
89 1.1 oster char *errmsg);
90 1.1 oster
91 1.1 oster /* called from user level to read the configuration file and create
92 1.1 oster * a configuration control structure. This is used in the user-level
93 1.1 oster * version of the driver, and in the user-level program that configures
94 1.1 oster * the system via ioctl.
95 1.1 oster */
96 1.1 oster int rf_MakeConfig(configname, cfgPtr)
97 1.1 oster char *configname;
98 1.1 oster RF_Config_t *cfgPtr;
99 1.1 oster {
100 1.1 oster int numscanned, val, r, c, retcode, aa, bb, cc;
101 1.1 oster char buf[256], buf1[256], *cp;
102 1.1 oster RF_LayoutSW_t *lp;
103 1.1 oster FILE *fp;
104 1.1 oster
105 1.1 oster bzero((char *)cfgPtr, sizeof(RF_Config_t));
106 1.1 oster
107 1.1 oster fp = fopen(configname, "r");
108 1.1 oster if (!fp) {
109 1.1 oster RF_ERRORMSG1("Can't open config file %s\n",configname);
110 1.1 oster return(-1);
111 1.1 oster }
112 1.1 oster
113 1.1 oster rewind(fp);
114 1.1 oster if (rf_search_file_for_start_of("array", buf, 256, fp)) {
115 1.1 oster RF_ERRORMSG1("Unable to find start of \"array\" params in config file %s\n",configname);
116 1.1 oster retcode = -1; goto out;
117 1.1 oster }
118 1.1 oster rf_get_next_nonblank_line(buf, 256, fp, "Config file error (\"array\" section): unable to get numRow and numCol\n");
119 1.1 oster /*
120 1.1 oster * wackiness with aa, bb, cc to get around size problems on different platforms
121 1.1 oster */
122 1.1 oster numscanned = sscanf(buf,"%d %d %d", &aa, &bb, &cc);
123 1.1 oster if (numscanned != 3) {
124 1.1 oster RF_ERRORMSG("Config file error (\"array\" section): unable to get numRow, numCol, numSpare\n");
125 1.1 oster retcode = -1; goto out;
126 1.1 oster }
127 1.1 oster cfgPtr->numRow = (RF_RowCol_t)aa;
128 1.1 oster cfgPtr->numCol = (RF_RowCol_t)bb;
129 1.1 oster cfgPtr->numSpare = (RF_RowCol_t)cc;
130 1.1 oster
131 1.1 oster /* debug section is optional */
132 1.1 oster for (c=0; c<RF_MAXDBGV; c++)
133 1.1 oster cfgPtr->debugVars[c][0] = '\0';
134 1.1 oster rewind(fp);
135 1.1 oster if (!rf_search_file_for_start_of("debug", buf, 256, fp)) {
136 1.1 oster for (c=0; c < RF_MAXDBGV; c++) {
137 1.1 oster if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) break;
138 1.1 oster cp = rf_find_non_white(buf);
139 1.1 oster if (!strncmp(cp, "START", strlen("START"))) break;
140 1.1 oster (void) strcpy(&cfgPtr->debugVars[c][0], cp);
141 1.1 oster }
142 1.1 oster }
143 1.1 oster
144 1.1 oster rewind(fp);
145 1.1 oster strcpy(cfgPtr->diskQueueType,"fifo");
146 1.1 oster cfgPtr->maxOutstandingDiskReqs = 1;
147 1.1 oster /* scan the file for the block related to disk queues */
148 1.1 oster if (rf_search_file_for_start_of("queue",buf,256,fp)) {
149 1.1 oster RF_ERRORMSG2("[No disk queue discipline specified in config file %s. Using %s.]\n",configname, cfgPtr->diskQueueType);
150 1.1 oster } else {
151 1.1 oster if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) {
152 1.1 oster RF_ERRORMSG2("[No disk queue discipline specified in config file %s. Using %s.]\n",configname, cfgPtr->diskQueueType);
153 1.1 oster }
154 1.1 oster }
155 1.1 oster
156 1.1 oster /* the queue specifier line contains two entries:
157 1.1 oster * 1st char of first word specifies queue to be used
158 1.1 oster * 2nd word specifies max num reqs that can be outstanding on the disk itself (typically 1)
159 1.1 oster */
160 1.1 oster if (sscanf(buf,"%s %d",buf1,&val)!=2) {
161 1.1 oster RF_ERRORMSG1("Can't determine queue type and/or max outstanding reqs from line: %s",buf);
162 1.1 oster RF_ERRORMSG2("Using %s-%d\n", cfgPtr->diskQueueType, cfgPtr->maxOutstandingDiskReqs);
163 1.1 oster } else {
164 1.1 oster char *c;
165 1.1 oster bcopy(buf1, cfgPtr->diskQueueType, RF_MIN(sizeof(cfgPtr->diskQueueType), strlen(buf1)+1));
166 1.1 oster for(c=buf1;*c;c++) {
167 1.1 oster if (*c == ' ') {
168 1.1 oster *c = '\0';
169 1.1 oster break;
170 1.1 oster }
171 1.1 oster }
172 1.1 oster cfgPtr->maxOutstandingDiskReqs = val;
173 1.1 oster }
174 1.1 oster
175 1.1 oster rewind(fp);
176 1.1 oster
177 1.1 oster
178 1.1 oster if (rf_search_file_for_start_of("disks",buf,256,fp)) {
179 1.1 oster RF_ERRORMSG1("Can't find \"disks\" section in config file %s\n",configname);
180 1.1 oster retcode = -1; goto out;
181 1.1 oster }
182 1.1 oster
183 1.1 oster for (r=0; r<cfgPtr->numRow; r++) {
184 1.1 oster for (c=0; c<cfgPtr->numCol; c++) {
185 1.1 oster if (rf_get_next_nonblank_line(&cfgPtr->devnames[r][c][0], 50, fp, NULL)) {
186 1.1 oster RF_ERRORMSG2("Config file error: unable to get device file for disk at row %d col %d\n",r,c);
187 1.1 oster retcode = -1; goto out;
188 1.1 oster }
189 1.1 oster }
190 1.1 oster }
191 1.1 oster
192 1.1 oster /* "spare" section is optional */
193 1.1 oster rewind(fp);
194 1.1 oster if (rf_search_file_for_start_of("spare",buf,256,fp)) cfgPtr->numSpare =0;
195 1.1 oster for (c = 0; c < cfgPtr->numSpare; c++) {
196 1.1 oster if (rf_get_next_nonblank_line(&cfgPtr->spare_names[c][0], 256, fp, NULL)) {
197 1.1 oster RF_ERRORMSG1("Config file error: unable to get device file for spare disk %d\n",c);
198 1.1 oster retcode = -1; goto out;
199 1.1 oster }
200 1.1 oster }
201 1.1 oster
202 1.1 oster /* scan the file for the block related to layout */
203 1.1 oster rewind(fp);
204 1.1 oster if (rf_search_file_for_start_of("layout",buf,256,fp)) {
205 1.1 oster RF_ERRORMSG1("Can't find \"layout\" section in configuration file %s\n",configname);
206 1.1 oster retcode = -1; goto out;
207 1.1 oster }
208 1.1 oster if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) {
209 1.1 oster RF_ERRORMSG("Config file error (\"layout\" section): unable to find common layout param line\n");
210 1.1 oster retcode = -1; goto out;
211 1.1 oster }
212 1.1 oster c = sscanf(buf,"%d %d %d %c", &aa, &bb, &cc, &cfgPtr->parityConfig);
213 1.1 oster cfgPtr->sectPerSU = (RF_SectorNum_t)aa;
214 1.1 oster cfgPtr->SUsPerPU = (RF_StripeNum_t)bb;
215 1.1 oster cfgPtr->SUsPerRU = (RF_StripeNum_t)cc;
216 1.1 oster if (c != 4) {
217 1.1 oster RF_ERRORMSG("Unable to scan common layout line\n");
218 1.1 oster retcode = -1; goto out;
219 1.1 oster }
220 1.1 oster lp = rf_GetLayout(cfgPtr->parityConfig);
221 1.1 oster if (lp == NULL) {
222 1.1 oster RF_ERRORMSG1("Unknown parity config '%c'\n", cfgPtr->parityConfig);
223 1.1 oster retcode = -1;
224 1.1 oster goto out;
225 1.1 oster }
226 1.1 oster
227 1.1 oster /* XXX who cares.. it's not going into the kernel, so we should ignore this... */
228 1.1 oster #ifndef KERNEL
229 1.1 oster retcode = lp->MakeLayoutSpecific(fp, cfgPtr, lp->makeLayoutSpecificArg);
230 1.1 oster #endif
231 1.1 oster out:
232 1.1 oster fclose(fp);
233 1.1 oster if (retcode < 0)
234 1.1 oster retcode = errno = EINVAL;
235 1.1 oster else
236 1.1 oster errno = retcode;
237 1.1 oster return(retcode);
238 1.1 oster }
239 1.1 oster
240 1.1 oster
241 1.1 oster /* used in architectures such as RAID0 where there is no layout-specific
242 1.1 oster * information to be passed into the configuration code.
243 1.1 oster */
244 1.1 oster int rf_MakeLayoutSpecificNULL(fp, cfgPtr, ignored)
245 1.1 oster FILE *fp;
246 1.1 oster RF_Config_t *cfgPtr;
247 1.1 oster void *ignored;
248 1.1 oster {
249 1.1 oster cfgPtr->layoutSpecificSize = 0;
250 1.1 oster cfgPtr->layoutSpecific = NULL;
251 1.1 oster return(0);
252 1.1 oster }
253 1.1 oster
254 1.1 oster int rf_MakeLayoutSpecificDeclustered(configfp, cfgPtr, arg)
255 1.1 oster FILE *configfp;
256 1.1 oster RF_Config_t *cfgPtr;
257 1.1 oster void *arg;
258 1.1 oster {
259 1.1 oster int b, v, k, r, lambda, norotate, i, val, distSpare;
260 1.1 oster char *cfgBuf, *bdfile, *p, *smname;
261 1.1 oster char buf[256], smbuf[256];
262 1.1 oster FILE *fp;
263 1.1 oster
264 1.1 oster distSpare = *((int *)arg);
265 1.1 oster
266 1.1 oster /* get the block design file name */
267 1.1 oster if (rf_get_next_nonblank_line(buf,256,configfp,"Can't find block design file name in config file\n"))
268 1.1 oster return(EINVAL);
269 1.1 oster bdfile = rf_find_non_white(buf);
270 1.1 oster if (bdfile[strlen(bdfile)-1] == '\n') {
271 1.1 oster /* strip newline char */
272 1.1 oster bdfile[strlen(bdfile)-1] = '\0';
273 1.1 oster }
274 1.1 oster
275 1.1 oster /* open bd file, check validity of configuration */
276 1.1 oster if ((fp = fopen(bdfile,"r"))==NULL) {
277 1.1 oster RF_ERRORMSG1("RAID: config error: Can't open layout table file %s\n",bdfile);
278 1.1 oster return(EINVAL);
279 1.1 oster }
280 1.1 oster
281 1.1 oster fgets(buf,256,fp);
282 1.1 oster i = sscanf(buf,"%u %u %u %u %u %u",&b,&v,&k,&r,&lambda,&norotate);
283 1.1 oster if (i == 5)
284 1.1 oster norotate = 0; /* no-rotate flag is optional */
285 1.1 oster else if (i != 6) {
286 1.1 oster RF_ERRORMSG("Unable to parse header line in block design file\n");
287 1.1 oster return(EINVAL);
288 1.1 oster }
289 1.1 oster
290 1.1 oster /* set the sparemap directory. In the in-kernel version, there's a daemon
291 1.1 oster * that's responsible for finding the sparemaps
292 1.1 oster */
293 1.1 oster if (distSpare) {
294 1.1 oster if (rf_get_next_nonblank_line(smbuf,256,configfp,"Can't find sparemap file name in config file\n"))
295 1.1 oster return(EINVAL);
296 1.1 oster smname = rf_find_non_white(smbuf);
297 1.1 oster if (smname[strlen(smname)-1] == '\n') {
298 1.1 oster /* strip newline char */
299 1.1 oster smname[strlen(smname)-1] = '\0';
300 1.1 oster }
301 1.1 oster }
302 1.1 oster else {
303 1.1 oster smbuf[0] = '\0';
304 1.1 oster smname = smbuf;
305 1.1 oster }
306 1.1 oster
307 1.1 oster /* allocate a buffer to hold the configuration info */
308 1.1 oster cfgPtr->layoutSpecificSize = RF_SPAREMAP_NAME_LEN + 6 * sizeof(int) + b * k;
309 1.1 oster /* can't use RF_Malloc here b/c debugMem module not yet init'd */
310 1.1 oster cfgBuf = (char *) malloc(cfgPtr->layoutSpecificSize);
311 1.1 oster cfgPtr->layoutSpecific = (void *) cfgBuf;
312 1.1 oster p = cfgBuf;
313 1.1 oster
314 1.1 oster /* install name of sparemap file */
315 1.1 oster for (i=0; smname[i]; i++)
316 1.1 oster *p++ = smname[i];
317 1.1 oster /* pad with zeros */
318 1.1 oster while (i<RF_SPAREMAP_NAME_LEN) {
319 1.1 oster *p++ = '\0';
320 1.1 oster i++;
321 1.1 oster }
322 1.1 oster
323 1.1 oster /*
324 1.1 oster * fill in the buffer with the block design parameters
325 1.1 oster * and then the block design itself
326 1.1 oster */
327 1.1 oster *( (int *) p) = b; p += sizeof(int);
328 1.1 oster *( (int *) p) = v; p += sizeof(int);
329 1.1 oster *( (int *) p) = k; p += sizeof(int);
330 1.1 oster *( (int *) p) = r; p += sizeof(int);
331 1.1 oster *( (int *) p) = lambda; p += sizeof(int);
332 1.1 oster *( (int *) p) = norotate; p += sizeof(int);
333 1.1 oster
334 1.1 oster while (fscanf(fp,"%d",&val) == 1)
335 1.1 oster *p++ = (char) val;
336 1.1 oster fclose(fp);
337 1.1 oster if (p - cfgBuf != cfgPtr->layoutSpecificSize) {
338 1.2 mrg RF_ERRORMSG2("Size mismatch creating layout specific data: is %d sb %d bytes\n",(int)(p-cfgBuf),(int)(6*sizeof(int)+b*k));
339 1.1 oster return(EINVAL);
340 1.1 oster }
341 1.1 oster return(0);
342 1.1 oster }
343 1.1 oster
344 1.1 oster
345 1.1 oster /****************************************************************************
346 1.1 oster *
347 1.1 oster * utilities
348 1.1 oster *
349 1.1 oster ***************************************************************************/
350 1.7 oster
351 1.7 oster /* finds a non-white character in the line */
352 1.7 oster char *
353 1.7 oster rf_find_non_white(char *p)
354 1.7 oster {
355 1.7 oster for (; *p != '\0' && (*p == ' ' || *p == '\t'); p++);
356 1.7 oster return (p);
357 1.7 oster }
358 1.7 oster
359 1.7 oster /* finds a white character in the line */
360 1.7 oster char *
361 1.7 oster rf_find_white(char *p)
362 1.7 oster {
363 1.7 oster for (; *p != '\0' && (*p != ' ' && *p != '\t'); p++);
364 1.7 oster return (p);
365 1.7 oster }
366 1.1 oster
367 1.1 oster /* searches a file for a line that says "START string", where string is
368 1.1 oster * specified as a parameter
369 1.1 oster */
370 1.1 oster static int rf_search_file_for_start_of(string, buf, len, fp)
371 1.1 oster char *string;
372 1.1 oster char *buf;
373 1.1 oster int len;
374 1.1 oster FILE *fp;
375 1.1 oster {
376 1.1 oster char *p;
377 1.1 oster
378 1.1 oster while (1) {
379 1.1 oster if (fgets(buf, len, fp) == NULL) return(-1);
380 1.1 oster p = rf_find_non_white(buf);
381 1.1 oster if (!strncmp(p, "START", strlen("START"))) {
382 1.1 oster p = rf_find_white(p);
383 1.1 oster p = rf_find_non_white(p);
384 1.1 oster if (!strncmp(p, string, strlen(string))) return(0);
385 1.1 oster }
386 1.1 oster }
387 1.1 oster }
388 1.1 oster
389 1.1 oster /* reads from file fp into buf until it finds an interesting line */
390 1.1 oster int rf_get_next_nonblank_line(buf, len, fp, errmsg)
391 1.1 oster char *buf;
392 1.1 oster int len;
393 1.1 oster FILE *fp;
394 1.1 oster char *errmsg;
395 1.1 oster {
396 1.1 oster char *p;
397 1.1 oster
398 1.1 oster while (fgets(buf,256,fp) != NULL) {
399 1.1 oster p = rf_find_non_white(buf);
400 1.1 oster if (*p == '\n' || *p == '\0' || *p == '#') continue;
401 1.1 oster return(0);
402 1.1 oster }
403 1.1 oster if (errmsg) RF_ERRORMSG(errmsg);
404 1.1 oster return(1);
405 1.1 oster }
406 1.1 oster
407 1.1 oster /* Allocates an array for the spare table, and initializes it from a file.
408 1.1 oster * In the user-level version, this is called when recon is initiated.
409 1.1 oster * When/if I move recon into the kernel, there'll be a daemon that does
410 1.1 oster * an ioctl into raidframe which will block until a spare table is needed.
411 1.1 oster * When it returns, it will read a spare table from the file system,
412 1.1 oster * pass it into the kernel via a different ioctl, and then block again
413 1.1 oster * on the original ioctl.
414 1.1 oster *
415 1.1 oster * This is specific to the declustered layout, but doesn't belong in
416 1.1 oster * rf_decluster.c because it uses stuff that can't be compiled into
417 1.1 oster * the kernel, and it needs to be compiled into the user-level sparemap daemon.
418 1.1 oster *
419 1.1 oster */
420 1.1 oster void *rf_ReadSpareTable(req, fname)
421 1.1 oster RF_SparetWait_t *req;
422 1.1 oster char *fname;
423 1.1 oster {
424 1.1 oster int i, j, numFound, linecount, tableNum, tupleNum, spareDisk, spareBlkOffset;
425 1.1 oster char buf[1024], targString[100], errString[100];
426 1.1 oster RF_SpareTableEntry_t **table;
427 1.1 oster FILE *fp;
428 1.1 oster
429 1.1 oster /* allocate and initialize the table */
430 1.1 oster RF_Malloc(table, req->TablesPerSpareRegion * sizeof(RF_SpareTableEntry_t *), (RF_SpareTableEntry_t **));
431 1.1 oster for (i=0; i<req->TablesPerSpareRegion; i++) {
432 1.1 oster RF_Malloc(table[i], req->BlocksPerTable * sizeof(RF_SpareTableEntry_t), (RF_SpareTableEntry_t *));
433 1.1 oster for (j=0; j<req->BlocksPerTable; j++) table[i][j].spareDisk = table[i][j].spareBlockOffsetInSUs = -1;
434 1.1 oster }
435 1.1 oster
436 1.1 oster /* 2. open sparemap file, sanity check */
437 1.1 oster if ((fp = fopen(fname,"r"))==NULL) {
438 1.1 oster fprintf(stderr,"rf_ReadSpareTable: Can't open sparemap file %s\n",fname); return(NULL);
439 1.1 oster }
440 1.1 oster if (rf_get_next_nonblank_line(buf,1024,fp,"Invalid sparemap file: can't find header line\n"))
441 1.1 oster return(NULL);
442 1.1 oster if (buf[strlen(buf)-1] == '\n')
443 1.1 oster buf[strlen(buf)-1] = '\0';
444 1.1 oster
445 1.1 oster sprintf(targString, "fdisk %d\n", req->fcol);
446 1.1 oster sprintf(errString, "Invalid sparemap file: can't find \"fdisk %d\" line\n",req->fcol);
447 1.1 oster while (1) {
448 1.1 oster rf_get_next_nonblank_line(buf,1024,fp,errString);
449 1.1 oster if (!strncmp(buf,targString,strlen(targString))) break;
450 1.1 oster }
451 1.1 oster
452 1.1 oster /* no more blank lines or comments allowed now */
453 1.1 oster linecount = req->TablesPerSpareRegion * req->TableDepthInPUs;
454 1.1 oster for (i=0; i<linecount; i++) {
455 1.1 oster numFound = fscanf(fp," %d %d %d %d",&tableNum, &tupleNum, &spareDisk, &spareBlkOffset);
456 1.1 oster if (numFound != 4) {
457 1.1 oster fprintf(stderr,"Sparemap file prematurely exhausted after %d of %d lines\n",i,linecount); return(NULL);
458 1.1 oster }
459 1.4 oster
460 1.1 oster RF_ASSERT(tableNum >= 0 && tableNum < req->TablesPerSpareRegion);
461 1.1 oster RF_ASSERT(tupleNum >= 0 && tupleNum < req->BlocksPerTable);
462 1.1 oster RF_ASSERT(spareDisk >= 0 && spareDisk < req->C);
463 1.1 oster RF_ASSERT(spareBlkOffset >= 0 && spareBlkOffset < req->SpareSpaceDepthPerRegionInSUs / req->SUsPerPU);
464 1.4 oster
465 1.1 oster table[tableNum][tupleNum].spareDisk = spareDisk;
466 1.1 oster table[tableNum][tupleNum].spareBlockOffsetInSUs = spareBlkOffset * req->SUsPerPU;
467 1.1 oster }
468 1.1 oster
469 1.1 oster fclose(fp);
470 1.1 oster return((void *) table);
471 1.1 oster }
472