📄 rf_configure.c
字号:
/* * Copyright (c) 1995 Carnegie-Mellon University. * All rights reserved. * * Author: Mark Holland * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. *//*************************************************************** * * rf_configure.c -- code related to configuring the raidframe system * * configuration is complicated by the fact that we want the same * driver to work both in the kernel and at user level. In the * kernel, we can't read the configuration file, so we configure * by running a user-level program that reads the config file, * creates a data structure describing the configuration and * passes it into the kernel via an ioctl. Since we want the config * code to be common between the two versions of the driver, we * configure using the same two-step process when running at * user level. Of course, at user level, the config structure is * passed directly to the config routine, rather than via ioctl. * * This file is not compiled into the kernel, so we have no * need for KERNEL ifdefs. * **************************************************************//* $Locker: $ * $Log: rf_configure.c,v $ * Revision 1.42 1996/08/09 18:47:47 jimz * major -> dev_major * * Revision 1.41 1996/07/29 14:05:12 jimz * fix numPUs/numRUs confusion (everything is now numRUs) * clean up some commenting, return values * * Revision 1.40 1996/07/27 23:36:08 jimz * Solaris port of simulator * * Revision 1.39 1996/07/27 18:39:45 jimz * cleanup sweep * * Revision 1.38 1996/07/18 22:57:14 jimz * port simulator to AIX * * Revision 1.37 1996/06/19 14:58:02 jimz * move layout-specific config parsing hooks into RF_LayoutSW_t * table in rf_layout.c * * Revision 1.36 1996/06/17 14:38:33 jimz * properly #if out RF_DEMO code * fix bug in MakeConfig that was causing weird behavior * in configuration routines (config was not zeroed at start) * clean up genplot handling of stacks * * Revision 1.35 1996/06/05 19:38:32 jimz * fixed up disk queueing types config * added sstf disk queueing * fixed exit bug on diskthreads (ref-ing bad mem) * * Revision 1.34 1996/06/03 23:28:26 jimz * more bugfixes * check in tree to sync for IPDS runs with current bugfixes * there still may be a problem with threads in the script test * getting I/Os stuck- not trivially reproducible (runs ~50 times * in a row without getting stuck) * * Revision 1.33 1996/06/02 17:31:48 jimz * Moved a lot of global stuff into array structure, where it belongs. * Fixed up paritylogging, pss modules in this manner. Some general * code cleanup. Removed lots of dead code, some dead files. * * Revision 1.32 1996/05/30 23:22:16 jimz * bugfixes of serialization, timing problems * more cleanup * * Revision 1.31 1996/05/30 11:29:41 jimz * Numerous bug fixes. Stripe lock release code disagreed with the taking code * about when stripes should be locked (I made it consistent: no parity, no lock) * There was a lot of extra serialization of I/Os which I've removed- a lot of * it was to calculate values for the cache code, which is no longer with us. * More types, function, macro cleanup. Added code to properly quiesce the array * on shutdown. Made a lot of stuff array-specific which was (bogusly) general * before. Fixed memory allocation, freeing bugs. * * Revision 1.30 1996/05/27 18:56:37 jimz * more code cleanup * better typing * compiles in all 3 environments * * Revision 1.29 1996/05/24 01:59:45 jimz * another checkpoint in code cleanup for release * time to sync kernel tree * * Revision 1.28 1996/05/18 19:51:34 jimz * major code cleanup- fix syntax, make some types consistent, * add prototypes, clean out dead code, et cetera * * Revision 1.27 1995/12/12 18:10:06 jimz * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT * fix 80-column brain damage in comments * * Revision 1.26 1995/12/01 15:16:36 root * added copyright info * */#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include "rf_raid.h"#include "rf_raidframe.h"#include "rf_debugMem.h"#include "rf_utils.h"#include "rf_general.h"#include "rf_decluster.h"#include "rf_configure.h"#include "rf_sys.h"static unsigned int dev_name2num(char *s);static unsigned int osf_dev_name2num(char *s);static int rf_search_file_for_start_of(char *string, char *buf, int len, FILE *fp);static int rf_get_next_nonblank_line(char *buf, int len, FILE *fp, char *errmsg);/* called from user level to read the configuration file and create * a configuration control structure. This is used in the user-level * version of the driver, and in the user-level program that configures * the system via ioctl. */int rf_MakeConfig(configname, cfgPtr) char *configname; RF_Config_t *cfgPtr;{ int numscanned, val, r, c, retcode, aa, bb, cc; char buf[256], buf1[256], *cp; RF_LayoutSW_t *lp; FILE *fp; bzero((char *)cfgPtr, sizeof(RF_Config_t)); fp = fopen(configname, "r"); if (!fp) { RF_ERRORMSG1("Can't open config file %s\n",configname); return(-1); } rewind(fp); if (rf_search_file_for_start_of("array", buf, 256, fp)) { RF_ERRORMSG1("Unable to find start of \"array\" params in config file %s\n",configname); retcode = -1; goto out; } rf_get_next_nonblank_line(buf, 256, fp, "Config file error (\"array\" section): unable to get numRow and numCol\n"); /* * wackiness with aa, bb, cc to get around size problems on different platforms */ numscanned = sscanf(buf,"%d %d %d", &aa, &bb, &cc); if (numscanned != 3) { RF_ERRORMSG("Config file error (\"array\" section): unable to get numRow, numCol, numSpare\n"); retcode = -1; goto out; } cfgPtr->numRow = (RF_RowCol_t)aa; cfgPtr->numCol = (RF_RowCol_t)bb; cfgPtr->numSpare = (RF_RowCol_t)cc; /* debug section is optional */ for (c=0; c<RF_MAXDBGV; c++) cfgPtr->debugVars[c][0] = '\0'; rewind(fp); if (!rf_search_file_for_start_of("debug", buf, 256, fp)) { for (c=0; c < RF_MAXDBGV; c++) { if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) break; cp = rf_find_non_white(buf); if (!strncmp(cp, "START", strlen("START"))) break; (void) strcpy(&cfgPtr->debugVars[c][0], cp); } } rewind(fp); strcpy(cfgPtr->diskQueueType,"fifo"); cfgPtr->maxOutstandingDiskReqs = 1; /* scan the file for the block related to disk queues */ if (rf_search_file_for_start_of("queue",buf,256,fp)) { RF_ERRORMSG2("[No disk queue discipline specified in config file %s. Using %s.]\n",configname, cfgPtr->diskQueueType); } else { if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) { RF_ERRORMSG2("[No disk queue discipline specified in config file %s. Using %s.]\n",configname, cfgPtr->diskQueueType); } } /* the queue specifier line contains two entries: * 1st char of first word specifies queue to be used * 2nd word specifies max num reqs that can be outstanding on the disk itself (typically 1) */ if (sscanf(buf,"%s %d",buf1,&val)!=2) { RF_ERRORMSG1("Can't determine queue type and/or max outstanding reqs from line: ",buf); RF_ERRORMSG2("Using %s-%d\n", cfgPtr->diskQueueType, cfgPtr->maxOutstandingDiskReqs); } else { char *c; bcopy(buf1, cfgPtr->diskQueueType, RF_MIN(sizeof(cfgPtr->diskQueueType), strlen(buf1)+1)); for(c=buf1;*c;c++) { if (*c == ' ') { *c = '\0'; break; } } cfgPtr->maxOutstandingDiskReqs = val; } rewind(fp); if (rf_search_file_for_start_of("disks",buf,256,fp)) { RF_ERRORMSG1("Can't find \"disks\" section in config file %s\n",configname); retcode = -1; goto out; } for (r=0; r<cfgPtr->numRow; r++) { for (c=0; c<cfgPtr->numCol; c++) { if (rf_get_next_nonblank_line(&cfgPtr->devnames[r][c][0], 50, fp, NULL)) { RF_ERRORMSG2("Config file error: unable to get device file for disk at row %d col %d\n",r,c); retcode = -1; goto out; }#ifndef SIMULATE val = dev_name2num(&cfgPtr->devnames[r][c][0]); if (val < 0) { RF_ERRORMSG3("Config file error: can't get dev num (dev file '%s') for disk at row %d c %d\n", &cfgPtr->devnames[r][c][0],r,c); retcode = -1; goto out; } else cfgPtr->devs[r][c] = val;#endif /* !SIMULATE */ } } /* "spare" section is optional */ rewind(fp); if (rf_search_file_for_start_of("spare",buf,256,fp)) cfgPtr->numSpare =0; for (c = 0; c < cfgPtr->numSpare; c++) { if (rf_get_next_nonblank_line(&cfgPtr->spare_names[c][0], 256, fp, NULL)) { RF_ERRORMSG1("Config file error: unable to get device file for spare disk %d\n",c); retcode = -1; goto out; }#ifndef SIMULATE val = dev_name2num(&cfgPtr->spare_names[c][0]); if (val < 0) { RF_ERRORMSG2("Config file error: can't get dev num (dev file '%s') for spare disk %d\n", &cfgPtr->spare_names[c][0],c); retcode = -1; goto out; } else cfgPtr->spare_devs[c] = val;#endif /* !SIMULATE */ } /* scan the file for the block related to layout */ rewind(fp); if (rf_search_file_for_start_of("layout",buf,256,fp)) { RF_ERRORMSG1("Can't find \"layout\" section in configuration file %s\n",configname); retcode = -1; goto out; } if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) { RF_ERRORMSG("Config file error (\"layout\" section): unable to find common layout param line\n"); retcode = -1; goto out;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -