⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rf_testcode.c

📁 RAIDFrame是个非常好的磁盘阵列RAID仿真工具
💻 C
📖 第 1 页 / 共 5 页
字号:
 * rewrite to move disk queues, recon, & atomic RMW to kernel * * Revision 1.25  1995/04/06  14:47:56  rachad * merge completed *<<<<<<< 1.24 * Revision 1.24  1995/04/03  20:33:20  rachad *  added reconstruction to simulato * * Revision 1.23  1995/03/17  22:51:52  rachad * Fixed Script test to use all the array * * Revision 1.22.10.3  1995/04/03  20:45:31  holland * misc changes related to distributed sparing * * Revision 1.22.10.2  1995/03/18  02:50:56  holland * fixed remap flags on calls to MapAccess * * Revision 1.22  1995/03/15  20:06:23  holland * enabled remapping for distributed sparing in calls to MapAccess * * Revision 1.21  1995/03/15  17:05:15  holland * ifdef'd out call to signal().  More trouble than it's worth. * * Revision 1.20  1995/03/09  19:56:08  rachad * Added suport for threadless simulator * * Revision 1.19  1995/03/03  18:36:16  rachad *  Simulator mechanism added * * Revision 1.18  1995/03/01  20:25:48  holland * kernelization changes * * Revision 1.17  1995/02/17  19:39:56  holland * added size param to all calls to Free(). * this is ignored at user level, but necessary in the kernel. * * Revision 1.16  1995/02/17  13:36:48  holland * added bp to call to rf_DoAccess * * Revision 1.15  1995/02/10  18:08:07  holland * fixed a few things I broke during kernelization * * Revision 1.14  1995/02/03  22:31:36  holland * many changes related to kernelization * * Revision 1.13  1995/02/01  15:13:05  holland * moved #include of general.h out of raid.h and into each file * * Revision 1.12  1995/02/01  14:27:31  holland * began changes for kernelization: *     changed all instances of mutex_t and cond_t to DECLARE macros *     converted configuration code to use config structure * * Revision 1.11  1995/01/30  14:53:46  holland * extensive changes related to making DoIO non-blocking * * Revision 1.10  1995/01/24  23:58:46  holland * multi-way recon XOR, + various small changes * * Revision 1.9  1995/01/11  19:27:02  holland * various changes related to performance tuning * * Revision 1.8  1994/12/05  22:21:06  holland * disabled trace run time limitation when doing reconstruction * * Revision 1.7  1994/12/05  20:12:35  danner * support for double degraded mode. * * Revision 1.6  1994/12/05  15:29:33  holland * added trace run time limitation (maxTraceRunTimeSec) * * Revision 1.5  1994/12/05  04:44:20  holland * in tracing code, wrap around to start of array if an address * is outside the bounds of the array * * Revision 1.4  1994/11/29  21:24:36  danner * support for script generate workloads from holland. * */#include "rf_threadstuff.h"#include "rf_types.h"#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <unistd.h>#include <sys/file.h>#include "rf_raid.h"#include "rf_dag.h"#include "rf_threadid.h"#include "rf_randmacros.h"#include "rf_parityscan.h"#include "rf_etimer.h"#include "rf_script.h"#include "rf_mcpair.h"#include "rf_configure.h"#include "rf_stripelocks.h"#include "rf_general.h"#include "rf_utils.h"#include "rf_testcode.h"#include "rf_driver.h"#include "rf_cpuutil.h"#include "rf_map.h"#include "rf_dagutils.h"#include "rf_copyback.h"#include "rf_shutdown.h"#include "rf_sys.h"#if RF_DEMO > 0#include "rf_demo.h"#endif /* RF_DEMO > 0 */#ifdef SIMULATE#include "rf_desc.h"#include "rf_owner.h"#include "rf_diskevent.h"#include "rf_diskthreads.h"#endif /* SIMULATE */RF_Raid_t *globalRaidPtr;               /* debug only -- allows cleanup after ^C */static int disk_has_failed = 0;/* signal handler for interrupt.  clean up and exit */char rf_testcode_degr_mode_type = 'n';     /* n = none, c = constant, i = intermittent */int rf_test_running = 0;static void PrintAccessInfo(RF_Raid_t *raidPtr, RF_RaidAddr_t offset,	RF_SectorCount_t numsect, RF_AccessStripeMapHeader_t *wasm,	RF_DagHeader_t *wdag, RF_AccessStripeMapHeader_t *rasm,	RF_DagHeader_t *rdag);#ifndef SIMULATEstatic void RRTest(RF_ThreadArg_t arg);static void RealLoopTest(RF_ThreadArg_t arg);static void VerifyAllParity(RF_Raid_t *raidPtr);static int VerifyAllData(RF_Raid_t *raidPtr, long *buf);#else /* !SIMULATE */static void UpdateUserStats(int resptime);static int CreateDagEvent(RF_EventCreate_t *createParam);static int CreateEvent(RF_EventCreate_t *createParam);static int CreateDagEventFunc(RF_EventCreate_t *createParam);static void CreateReconEvent(RF_Raid_t *raidPtr, RF_Owner_t owner);static void CreateSyncEvent(RF_Raid_t *raidPtr, RF_Owner_t owner);#endif /* !SIMULATE */static RF_SectorNum_t ***MakeOrInitLTT(RF_Raid_t *raidPtr,	RF_SectorNum_t ***table_in, RF_AllocListElem_t *alist);static void DoLayoutTest(RF_Raid_t *raidPtr, RF_SectorNum_t ***addrTable,	int remap);static void CheckAddress(RF_Raid_t *raidPtr, RF_RaidAddr_t i,	RF_SectorNum_t ***addrTable, void (*mapFunc)(), int parity_unit,	int remap);static void CheckValidMapping(RF_Raid_t *raidPtr, RF_RaidAddr_t i,	RF_RowCol_t row, RF_RowCol_t col, RF_SectorNum_t offset);static void CheckUniqueMapping(RF_Raid_t *raidPtr, RF_RaidAddr_t i, RF_SectorNum_t ***addrTable,	RF_RowCol_t row, RF_RowCol_t col, RF_SectorNum_t offset, int parity_unit);static void PrintParityVerifyString(status)  int  status;{  switch(status) {    case RF_PARITY_OKAY:      printf("Parity okay\n");      break;    case RF_PARITY_CORRECTED:      printf("[Parity was bad prior to an access. Corrected it.]\n");      break;    case RF_PARITY_BAD:      printf("[Bad parity.]\n");      break;    case RF_PARITY_COULD_NOT_CORRECT:      printf("Warning: bad parity, could not be corrected.\n");      break;    case RF_PARITY_COULD_NOT_VERIFY:      printf("Warning: could not verify parity\n");      break;    default:      printf("Bad parity verification status %d\n", status);  }}static int punt(status)  int  status;{  printf("Received interrupt signal.  Cleaning up...\n");  rf_PrintPSStatusTable(globalRaidPtr, 0);  fflush(stdout);  fflush(stderr);  rf_Shutdown(globalRaidPtr);  printf("\nExiting...\n");  fflush(stdout);  fflush(stderr);  exit(1);}static void do_free_grpair(arg)  void  *arg;{  RF_GRpair_t *p = (RF_GRpair_t *)arg;  RF_Free(p, sizeof(RF_GRpair_t));}RF_GRpair_t *rf_GetGrpair(listp)  RF_ShutdownList_t  **listp;{  RF_GRpair_t *p;  int rc;  RF_Calloc(p, 1, sizeof(RF_GRpair_t), (RF_GRpair_t *));  rc = rf_ShutdownCreate(listp, do_free_grpair, p);  if (rc) {    RF_Free(p, sizeof(RF_GRpair_t));    return(NULL);  }  rc = rf_init_managed_threadgroup(listp, &p->group);  if (rc) {    /* shutdown list will free above for us */    return(NULL);  }  return(p);}#ifndef SIMULATEvoid DegradedModeReadTest(raidPtr)  RF_Raid_t  *raidPtr;{  RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);  char buf[50];  unsigned long rv;  RF_RaidAddr_t raidAddr;  int numBlocks;  char *buffer, *ff_buffer;  int bufSize, i, badsu, miscomparecount, do_loop = 0, frow, fcol, status;  RF_AccessStripeMapHeader_t *asm_h, *ff_asm_h;  RF_PhysDiskAddr_t *pda;  RF_DagHeader_t *dag_h, *ff_dag_h;  RF_DECLARE_RANDOM;  RF_INIT_RANDOM(1);  fprintf(stderr,"Loop forever or single-access test? [l/s] ");  gets(buf);  if (*buf == 'l') do_loop=1;  while (1) {    if (do_loop) {      rv = RF_RANDOM();      numBlocks = (rv % 255) + 1;      rv = RF_RANDOM();      raidAddr = rv % (raidPtr->totalSectors - numBlocks);    } else {      fprintf(stderr,"Starting RAID address [0-%ld]? ",raidPtr->totalSectors);      gets(buf);      raidAddr = atol(buf);      fprintf(stderr,"number of blocks? ");      gets(buf);      numBlocks = atoi(buf);    }    bufSize = rf_RaidAddressToByte(raidPtr, numBlocks);    RF_Malloc(buffer, bufSize, (char *));    asm_h = rf_MapAccess(raidPtr, raidAddr, numBlocks, buffer, RF_DONT_REMAP);    if (do_loop) {      rv = RF_RANDOM();      badsu = rv % asm_h->stripeMap->numStripeUnitsAccessed;    } else {      printf("Access stripe map is:\n");      rf_PrintFullAccessStripeMap(asm_h, 1);      printf("The access uses %d SUs in the first stripe.  Which one do you want to mark as bad? [0-%d] ",	     asm_h->stripeMap->numStripeUnitsAccessed, asm_h->stripeMap->numStripeUnitsAccessed-1);      gets(buf);      badsu = atoi(buf);      if (badsu >= asm_h->stripeMap->numStripeUnitsAccessed) {printf("huh?\n"); goto eol;}    }    for (pda = asm_h->stripeMap->physInfo; i<badsu; pda=pda->next);    frow = pda->row; fcol = pda->col;     /* find out which disk we want to fail */    /* verify that the parity is correct in the indicated stripe */    if (layoutPtr->map->faultsTolerated) {      status = rf_VerifyParity(raidPtr, asm_h->stripeMap, RF_DO_CORRECT_PARITY, RF_DAG_FLAGS_NONE);      if (status)        PrintParityVerifyString(status);    }    rf_FreeAccessStripeMap(asm_h);    /* do the access in degraded mode */    rf_FailDisk(raidPtr, frow, fcol, 0);    rf_DoAccess(raidPtr, RF_IO_TYPE_READ, NULL, raidAddr, numBlocks, buffer, NULL, &dag_h, &asm_h, RF_DAG_RETURN_ASM|RF_DAG_RETURN_DAG, NULL,NULL,NULL);        /* cfb -- added because cache is unable to return ASM or DAG */    if (asm_h == NULL)      {	asm_h = rf_MapAccess(raidPtr, raidAddr, numBlocks, buffer, RF_DONT_REMAP);      }          /* make a new buffer and do a fault-free read on the same address */    RF_Malloc(ff_buffer, bufSize, (char *));    raidPtr->Disks[frow][fcol].status = rf_ds_optimal;    rf_DoAccess(raidPtr, RF_IO_TYPE_READ,NULL,  raidAddr, numBlocks, ff_buffer, NULL, &ff_dag_h, &ff_asm_h, RF_DAG_RETURN_ASM|RF_DAG_RETURN_DAG, NULL, NULL, NULL);    if (ff_asm_h == NULL)      {	ff_asm_h = rf_MapAccess(raidPtr, raidAddr, numBlocks, ff_buffer, 			     RF_DONT_REMAP);      }    for (miscomparecount=i=0; i<bufSize; i++) {      if (ff_buffer[i] != buffer[i]) {	miscomparecount=1;	printf("MISCOMPARE!  Index %d, ff is 0x%x, deg is 0x%x\n",(u_char) ff_buffer[i], (u_char) buffer[i]);	printf("Deg Access stripe map is:\n");	rf_PrintFullAccessStripeMap(asm_h, 1);	printf("FF Access stripe map is:\n");	rf_PrintFullAccessStripeMap(ff_asm_h, 1);	printf("Degraded-read dag:\n");	rf_PrintDAGList(dag_h);	printf("Fault-free-read dag:\n");	rf_PrintDAGList(ff_dag_h);	break;      }    }    printf("RAIDADDR 0x%lx numblocks %d, bad su %d:  ",raidAddr,numBlocks, badsu);    if (!miscomparecount) printf("SUCCESSFUL.\n"); else {printf("MISCOMPARED\n"); exit(1);}    if (dag_h != NULL)      rf_FreeDAG(dag_h);    if (ff_dag_h != NULL)      rf_FreeDAG(ff_dag_h);    rf_FreeAccessStripeMap(ff_asm_h);    rf_FreeAccessStripeMap(asm_h);    RF_Free(ff_buffer, bufSize);eol:    RF_Free(buffer, bufSize);  }}void SingleAccessTest(raidPtr)  RF_Raid_t  *raidPtr;{  char buf[50];  RF_RaidAddr_t raidAddr;  int numBlocks, retcode;  char type;  char *buffer, *rdbuf, *tbuf;  int bufSize, i, miscomparecount, status;  int badrow, badcol, markbad;  int badrow2, badcol2, markbad2;  RF_DagHeader_t *wdag, *rdag;  RF_AccessStripeMapHeader_t *wasm, *rasm;  unsigned long rv;  RF_DECLARE_RANDOM;  printf ("enter -1 for the RAID address to quit\n");  RF_INIT_RANDOM(1);  if (raidPtr->Layout.map->faultsTolerated && rf_rewriteParityStripes) rf_RewriteParity(raidPtr);  while (1) {    fflush(stderr);    fflush(stdout);    fprintf(stderr,"Starting RAID address [0-%ld]? ",raidPtr->totalSectors);    gets(buf);    raidAddr = atol(buf);    if (raidAddr == -1) return;    fprintf(stderr,"number of blocks? ");    gets(buf);    numBlocks = atoi(buf);        markbad=0;    fprintf(stderr,"Input row id of disk to mark failed (-1 for none): ");    gets(buf);    badrow = atoi(buf);    if (badrow >= 0 && badrow < raidPtr->numRow) {      fprintf(stderr,"Input column id of disk to mark failed (-1 for none): ");      gets(buf);      badcol = atoi(buf);      if (badcol >= 0 && badcol < raidPtr->numCol) markbad=1;    }    markbad2=0;    fprintf(stderr,"Input row id of second disk to mark failed (-1 for none): ");    gets(buf);    badrow2 = atoi(buf);    if (badrow2 >= 0 && badrow2 < raidPtr->numRow) {      fprintf(stderr,"Input column id of second disk to mark failed (-1 for none): ");      gets(buf);      badcol2 = atoi(buf);      if (badcol2 >= 0 && badcol2 < raidPtr->numCol) markbad2=1;    }    bufSize = rf_RaidAddressToByte(raidPtr, numBlocks);    RF_Malloc(buffer, bufSize, (char *));    RF_Malloc(rdbuf, bufSize, (char *));    RF_Malloc(tbuf, bufSize, (char *));    for (i=0; i<bufSize; i++) {      rv = RF_RANDOM();      rv &= 0xff;      tbuf[i] = buffer[i] = (char)rv;    }    rasm = rf_MapAccess(raidPtr, raidAddr, numBlocks, buf, RF_DONT_REMAP);    /* if we've marked a disk bad, parity will typically be bad here => supress warning message */    if (raidPtr->Layout.map->faultsTolerated) {      status = rf_VerifyParity(raidPtr, rasm->stripeMap, RF_DO_CORRECT_PARITY, RF_DAG_FLAGS_NONE);      if ((status && !markbad && !markbad2) || (status == RF_PARITY_COULD_NOT_VERIFY)          || (status == RF_PARITY_COULD_NOT_CORRECT)) {        PrintParityVerifyString(status);      }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -