disksim_redun.c

来自「disksim是一个非常优秀的磁盘仿真工具」· C语言 代码 · 共 1,296 行 · 第 1/3 页

C
1,296
字号
	          tmpdep = tmpdep->cont;	       }            }            tmpdep->deps[(tmpdep->numdeps % 10)] = temp;	    tmpdep->numdeps++;            temp->opid++;	 }	 tmpread = tmpread->next;      }      temp = temp->next;   }   temp = readlist;   curr->prev = NULL;   while (temp) {      depend = (depends *) temp->prev;      temp->prev = NULL;      depend->next = (depends *) curr->prev;      curr->prev = (ioreq_event *) depend;      if (temp->next == NULL) {	 temp->next = curr->next;	 curr->next = readlist;	 break;      }      temp = temp->next;   }}int logorg_parity_table (logorg *currlogorg, ioreq_event *curr, int numreqs){   int i;   ioreq_event *reqs[MAXDEVICES];   ioreq_event *redunreqs[MAXDEVICES];   int reqcnt = 0;   ioreq_event *lastrow = NULL;   int stripeunit;   ioreq_event *temp;   ioreq_event *newreq;   int unitno;   int stripeno;   int entryno;   int blkno;   int blksinpart;   int reqsize;   int partsperstripe;   int rowcnt = 1;   int firstrow = 0;   int opid = 0x1;   int blkscovered;   tableentry *table;   int tablestart;   int preventryno;/*fprintf (outputfile, "Entered logorg_parity_table - devno %d, blkno %d, bcount %d, read %d\n", curr->devno, curr->blkno, curr->bcount, (curr->flags & READ));*/   if (numreqs != 1) {      fprintf(stderr, "Multiple numreqs at logorg_parity_table is not acceptable - %d\n", numreqs);      exit(1);   }   stripeunit = currlogorg->stripeunit;   partsperstripe = currlogorg->partsperstripe;   table = currlogorg->table;   if (currlogorg->addrbyparts) {      curr->blkno += curr->devno * currlogorg->blksperpart;   }   for (i=0; i<currlogorg->actualnumdisks; i++) {      reqs[i] = NULL;   }   unitno = curr->blkno / stripeunit;   stripeno = unitno / partsperstripe;   tablestart = (stripeno / currlogorg->tablestripes) * currlogorg->tablesize;   stripeno = stripeno % currlogorg->tablestripes;   blkno = tablestart + table[(stripeno*(partsperstripe+1))].blkno;   if (blkno == currlogorg->numfull) {      stripeunit = currlogorg->actualblksperpart - blkno;      curr->blkno -= blkno;      unitno = curr->blkno / stripeunit;   }   blksinpart = stripeunit;   unitno = unitno % partsperstripe;   curr->blkno = curr->blkno % stripeunit;   reqsize = curr->bcount;   entryno = stripeno * partsperstripe + stripeno + unitno;   blkno = tablestart + table[entryno].blkno;   blksinpart -= curr->blkno;   temp = ioreq_copy(curr);   curr->next = temp;   temp->blkno = blkno + curr->blkno;   temp->devno = table[entryno].devno;   temp->opid = 0;   blkscovered = curr->bcount;   curr->blkno = stripeno;   curr->devno = unitno;   curr->bcount = tablestart;   reqs[temp->devno] = curr->next;   temp->next = NULL;   temp->prev = NULL;   if (reqsize > blksinpart) {      temp->bcount = blksinpart;      blkscovered = blksinpart;      reqsize -= blksinpart;      unitno++;      if (unitno == partsperstripe) {	 if (!(curr->flags & READ)) {	    newreq = (ioreq_event *) getfromextraq();	    newreq->devno = table[(entryno+1)].devno;	    newreq->blkno = table[(entryno+1)].blkno;	    newreq->blkno += tablestart + temp->blkno - blkno;	    newreq->bcount = blkscovered;	    newreq->flags = curr->flags;            newreq->opid = 0;	    reqs[newreq->devno] = newreq;	    newreq->next = NULL;	    temp->prev = newreq;	    newreq->prev = NULL;	 }	 blkscovered = 0;	 unitno = 0;	 if (firstrow == 0) {	    firstrow = 1;	 }	 rowcnt = 0;	 stripeno++;	 temp = NULL;	 if (stripeno == currlogorg->tablestripes) {	    stripeno = 0;	    tablestart += currlogorg->tablesize;	 }      }      entryno = (stripeno * partsperstripe) + stripeno + unitno;      blkno = tablestart + table[entryno].blkno;      blksinpart = (blkno != currlogorg->numfull) ? stripeunit : currlogorg->actualblksperpart - blkno;      while (reqsize > blksinpart) {	 rowcnt++;	 newreq = (ioreq_event *) getfromextraq();         newreq->blkno = blkno;	 newreq->devno = table[entryno].devno;	 newreq->bcount = blksinpart;	 blkscovered = max(blkscovered, blksinpart);	 newreq->flags = curr->flags;         newreq->opid = 0;	 newreq->prev = NULL;	 if (temp) {	    temp->prev = newreq;	 } else {	    lastrow = newreq;	 }	 temp = newreq;	 logorg_parity_table_insert(&reqs[temp->devno], temp);         reqsize -= blksinpart;         unitno++;         if (unitno == partsperstripe) {	    if (!(curr->flags & READ)) {	       newreq = (ioreq_event *) getfromextraq();	       newreq->devno = table[(entryno+1)].devno;	       newreq->blkno = table[(entryno+1)].blkno + tablestart;	       newreq->bcount = blkscovered;	       newreq->flags = curr->flags;               newreq->opid = 0;               temp->prev = newreq;	       newreq->prev = NULL;	       logorg_parity_table_insert(&reqs[newreq->devno], newreq);	    }	    blkscovered = 0;	    unitno = 0;	    if (firstrow == 0) {	       firstrow = rowcnt;	    }	    rowcnt = 0;	    temp = NULL;	    stripeno++;	    if (stripeno == currlogorg->tablestripes) {	       stripeno = 0;	       tablestart += currlogorg->tablesize;	    }         }         entryno = (stripeno * partsperstripe) + stripeno + unitno;         blkno = tablestart + table[entryno].blkno;         blksinpart = (blkno != currlogorg->numfull) ? stripeunit : currlogorg->actualblksperpart - blkno;      }      newreq = (ioreq_event *) getfromextraq();      newreq->blkno = blkno;      newreq->devno = table[entryno].devno;      newreq->bcount = reqsize;      rowcnt++;      blkscovered = max(blkscovered, blksinpart);      newreq->flags = curr->flags;      newreq->opid = 0;      newreq->prev = NULL;      if (temp) {	 temp->prev = newreq;      } else {	 lastrow = newreq;      }      temp = newreq;      logorg_parity_table_insert(&reqs[newreq->devno], newreq);   }   if (curr->flags & READ) {      curr->next = curr;      for (i=0; i<currlogorg->actualnumdisks; i++) {	 reqcnt += logorg_join_seqreqs(reqs[i], curr, LOGORG_PARITY_SEQGIVE);      }   } else {      preventryno = entryno;      entryno = (stripeno * partsperstripe) + stripeno + partsperstripe;      newreq = (ioreq_event *) getfromextraq();      newreq->devno = table[entryno].devno;      newreq->blkno = table[entryno].blkno + temp->blkno - table[preventryno].blkno;      newreq->bcount = (rowcnt == 1) ? temp->bcount : blkscovered;      newreq->flags = curr->flags;      newreq->opid = 0;      temp->prev = newreq;      newreq->prev = NULL;      logorg_parity_table_insert(&reqs[newreq->devno], newreq);      if (firstrow == 0) {	 if ((rowcnt == 2) && ((curr->next->blkno - temp->blkno - temp->bcount) > 0)) {	    newreq->bcount = temp->bcount;	    newreq = (ioreq_event *) getfromextraq();	    newreq->devno = temp->prev->devno;	    lastrow = temp;	    temp = curr->next;	    newreq->blkno = table[entryno].blkno + temp->blkno - table[(preventryno-1)].blkno;	    newreq->bcount = temp->bcount;	    newreq->flags = curr->flags;	    newreq->opid = 0;	    temp->prev = newreq;	    newreq->prev = NULL;            logorg_parity_table_insert(&reqs[newreq->devno], newreq);	    firstrow = 1;	    rowcnt = 1;	 } else {	    firstrow = rowcnt;	    rowcnt = 0;	 }      }      for (i=0; i<currlogorg->actualnumdisks; i++) {	 redunreqs[i] = NULL;      }      if (firstrow < partsperstripe) {	 if (firstrow < currlogorg->rmwpoint) {	    logorg_parity_table_read_old(currlogorg, curr->next, redunreqs, opid);	 } else {	    logorg_parity_table_recon(currlogorg, curr->next, redunreqs, curr->blkno, curr->devno, curr->bcount, opid);	 }	 opid = opid << 1;      }      if ((rowcnt) && (rowcnt != partsperstripe)) {	 if (rowcnt < currlogorg->rmwpoint) {	    logorg_parity_table_read_old(currlogorg, lastrow, redunreqs, opid);	 } else {	    logorg_parity_table_recon(currlogorg, lastrow, redunreqs, stripeno, 0, tablestart, opid);	 }      }      for (i=0; i<currlogorg->actualnumdisks; i++) {	 curr->next = NULL;	 reqcnt += logorg_join_seqreqs(redunreqs[i], curr, LOGORG_PARITY_SEQGIVE);	 redunreqs[i] = curr->next;	 curr->next = NULL;	 reqcnt += logorg_join_seqreqs(reqs[i], curr, LOGORG_PARITY_SEQGIVE);	 reqs[i] = curr->next;      }      curr->next = curr;      if (currlogorg->writesync) {	 logorg_parity_table_dodeps_sync(currlogorg, curr, redunreqs, reqs);      } else {	 logorg_parity_table_dodeps_nosync(currlogorg, curr, redunreqs, reqs);      }   }   if (curr->next) {      temp = curr->next;      curr->blkno = temp->blkno;      curr->devno = temp->devno;      curr->bcount = temp->bcount;      curr->flags = temp->flags;      curr->next = temp->next;      addtoextraq((event *) temp);   } else {      fprintf(stderr, "Seem to have no requests when leaving logorg_parity_table\n");      exit(1);   }/*fprintf (outputfile, "Exiting logorg_parity_table - reqcnt %d\n", reqcnt);*/   return(reqcnt);}static void logorg_create_table_left_sym (logorg *currlogorg){   int i, j;   int numdisks;   int stripeno = 0;   int devno = 0;   int blkno = 0;   int parityno;   numdisks = currlogorg->numdisks;   parityno = numdisks - 1;   for (i=0; i<currlogorg->tablestripes; i++) {      for (j=1; j<numdisks; j++) {         currlogorg->table[stripeno].devno = devno;         currlogorg->table[stripeno].blkno = blkno;         stripeno++;	 devno = logorg_modulus_update(1, devno, numdisks);         if (devno == parityno) {	    devno = logorg_modulus_update(1, devno, numdisks);         }      }      currlogorg->table[stripeno].devno = parityno;      currlogorg->table[stripeno].blkno = blkno;      blkno += currlogorg->stripeunit;      stripeno++;      if ((blkno % currlogorg->parityunit) == 0) {         devno = parityno;         parityno = logorg_modulus_update(-1, parityno, numdisks);      }   }}void logorg_create_table (logorg *currlogorg){   int i;   int numdisks;   int parityunit;   int stripeunit;   numdisks = currlogorg->numdisks;   parityunit = currlogorg->parityunit;   stripeunit = currlogorg->stripeunit;   if (currlogorg->reduntype != PARITY_DISK) {      if ((parityunit < stripeunit) || ((parityunit % stripeunit) != 0)) {         fprintf(stderr, "Illegal parityunit - stripeunit combination at logorg_create_table\n");         exit(1);      }   }   if (currlogorg->reduntype == PARITY_DISK) {      currlogorg->tablestripes = 1;   } else {      currlogorg->tablestripes = numdisks * parityunit / stripeunit;   }   currlogorg->table = DISKSIM_malloc(currlogorg->tablestripes * numdisks * sizeof(tableentry));   currlogorg->tablesize = currlogorg->tablestripes * stripeunit;   currlogorg->partsperstripe = numdisks - 1;   if (currlogorg->reduntype == PARITY_DISK) {      for (i=0; i<numdisks; i++) {         currlogorg->table[i].devno = i;         currlogorg->table[i].blkno = 0;      }      return;   }   switch (currlogorg->rottype) {      case PARITY_LEFT_SYM:	      logorg_create_table_left_sym(currlogorg);	      break;      case PARITY_LEFT_ASYM:      case PARITY_RIGHT_SYM:      case PARITY_RIGHT_ASYM:      default:	      fprintf(stderr, "Unknown parity rotation type at logorg_create_table\n");	      exit(1);   }/*   for (i=0; i<(currlogorg->tablestripes * numdisks); i++) {      fprintf (outputfile, "tableentry #%d: devno %d, blkno %d\n", i, currlogorg->table[i].devno, currlogorg->table[i].blkno);   }*/}int logorg_check_dependencies (logorg *currlogorg, outstand *req, ioreq_event *curr){   int i;   depends *tmpdep;   depends *del = NULL;   int numreqs = 0;   int devno = 0;   int numdeps;   ioreq_event *temp;   tmpdep = req->depend;   if (tmpdep == NULL) {      return(0);   }   if ((tmpdep->devno == curr->devno) && (tmpdep->blkno == curr->blkno)) {      req->depend = tmpdep->next;   } else {      while (tmpdep->next) {         if ((tmpdep->next->devno == curr->devno) && (tmpdep->next->blkno == curr->blkno)) {            del = tmpdep->next;            tmpdep->next = del->next;            tmpdep = del;            break;         }         tmpdep = tmpdep->next;      }      if (del == NULL) {         return(0);      }   }   curr->next = curr;   numdeps = tmpdep->numdeps;   i = 0;   while (i < numdeps) {      temp = tmpdep->deps[devno];      temp->opid--;      if (temp->opid == 0) {         numreqs++;         temp->next = curr->next;         curr->next = temp;         temp->opid = req->opid;         temp->time = 0.0;         if (req->flags & TIME_CRITICAL) {            temp->flags |= TIME_CRITICAL;         }      }      if ((i++) >= numdeps) {	 break;      }      devno = logorg_modulus_update(1, devno, 10);      if (devno == 0) {         del = tmpdep;         tmpdep = tmpdep->cont;         addtoextraq((event *) del);      }   }   addtoextraq((event *) tmpdep);   return(numreqs);}

⌨️ 快捷键说明

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