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

📄 rf_paritylog.c

📁 RAIDFrame是个非常好的磁盘阵列RAID仿真工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 1995 Carnegie-Mellon University. * All rights reserved. * * Author: William V. Courtright II * * 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. *//* Code for manipulating in-core parity logs * * $Locker:  $ * $Log: rf_paritylog.c,v $ * Revision 1.27  1996/07/28  20:31:39  jimz * i386netbsd port * true/false fixup * * Revision 1.26  1996/07/27  23:36:08  jimz * Solaris port of simulator * * Revision 1.25  1996/07/17  21:00:58  jimz * clean up timer interface, tracing * * Revision 1.24  1996/06/11  10:18:59  jimz * AllocParityLogCommonData() was freeing the common pointer immediately * after allocating this. It appeared that this free really belonged * inside one of the failure cases (for backing out), so I moved it * in there. * * Revision 1.23  1996/06/05  18:06:02  jimz * Major code cleanup. The Great Renaming is now done. * Better modularity. Better typing. Fixed a bunch of * synchronization bugs. Made a lot of global stuff * per-desc or per-array. Removed dead code. * * Revision 1.22  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.21  1996/05/31  22:26:54  jimz * fix a lot of mapping problems, memory allocation problems * found some weird lock issues, fixed 'em * more code cleanup * * Revision 1.20  1996/05/30  23:22:16  jimz * bugfixes of serialization, timing problems * more cleanup * * Revision 1.19  1996/05/30  12:59:18  jimz * make etimer happier, more portable * * Revision 1.18  1996/05/27  18:56:37  jimz * more code cleanup * better typing * compiles in all 3 environments * * Revision 1.17  1996/05/24  04:28:55  jimz * release cleanup ckpt * * Revision 1.16  1996/05/23  21:46:35  jimz * checkpoint in code cleanup (release prep) * lots of types, function names have been fixed * * Revision 1.15  1996/05/23  00:33:23  jimz * code cleanup: move all debug decls to rf_options.c, all extern * debug decls to rf_options.h, all debug vars preceded by rf_ * * Revision 1.14  1996/05/20  16:16:59  jimz * switch to rf_{mutex,cond}_{init,destroy} * * Revision 1.13  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.12  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.11  1995/12/06  20:54:44  wvcii * added prototyping * * Revision 1.10  1995/11/30  16:05:37  wvcii * added copyright info * * Revision 1.9  1995/10/08  20:41:28  wvcii * fixed bug in allocation of CommonLogData (was allocating incorrect size) * * Revision 1.8  1995/09/07  15:52:12  jimz * noop compile when INCLUDE_PARITYLOGGING not defined * * Revision 1.7  1995/09/06  19:17:36  wvcii * moved code for reintegration to rf_paritylogDiskMgr.c * * Revision 1.6  95/07/07  00:16:06  wvcii * this version free from deadlock, fails parity verification *  * Revision 1.5  1995/06/09  13:14:24  wvcii * code is now nonblocking * * Revision 1.4  95/06/01  17:01:59  wvcii * code debug *  * Revision 1.3  95/05/31  13:08:23  wvcii * code debug *  * Revision 1.2  95/05/21  15:42:15  wvcii * code debug *  * Revision 1.1  95/05/18  10:43:54  wvcii * Initial revision *  */#include "rf_archs.h"#if RF_INCLUDE_PARITYLOGGING > 0/* * Append-only log for recording parity "update" and "overwrite" records */#include "rf_types.h"#include "rf_threadstuff.h"#include "rf_mcpair.h"#include "rf_raid.h"#include "rf_dag.h"#include "rf_dagfuncs.h"#include "rf_desc.h"#include "rf_layout.h"#include "rf_diskqueue.h"#include "rf_etimer.h"#include "rf_paritylog.h"#include "rf_general.h"#include "rf_threadid.h"#include "rf_map.h"#include "rf_paritylogging.h"#include "rf_paritylogDiskMgr.h"#include "rf_sys.h"static RF_CommonLogData_t *AllocParityLogCommonData(RF_Raid_t *raidPtr){  RF_CommonLogData_t *common = NULL;  int rc;  /* Return a struct for holding common parity log information from the free     list (rf_parityLogDiskQueue.freeCommonList).  If the free list is empty, call     RF_Malloc to create a new structure.     NON-BLOCKING */  RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);  if (raidPtr->parityLogDiskQueue.freeCommonList)    {      common = raidPtr->parityLogDiskQueue.freeCommonList;      raidPtr->parityLogDiskQueue.freeCommonList = raidPtr->parityLogDiskQueue.freeCommonList->next;      RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);    }  else    {      RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);      RF_Malloc(common, sizeof(RF_CommonLogData_t), (RF_CommonLogData_t *));      rc = rf_mutex_init(&common->mutex);      if (rc) {        RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,          __LINE__, rc);        RF_Free(common, sizeof(RF_CommonLogData_t));        common = NULL;      }    }  common->next = NULL;  return(common);}static void FreeParityLogCommonData(RF_CommonLogData_t *common){  RF_Raid_t *raidPtr;  /* Insert a single struct for holding parity log information     (data) into the free list (rf_parityLogDiskQueue.freeCommonList).     NON-BLOCKING */  raidPtr = common->raidPtr;  RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);  common->next = raidPtr->parityLogDiskQueue.freeCommonList;  raidPtr->parityLogDiskQueue.freeCommonList = common;  RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);}static RF_ParityLogData_t *AllocParityLogData(RF_Raid_t *raidPtr){  RF_ParityLogData_t *data = NULL;  /* Return a struct for holding parity log information from the free     list (rf_parityLogDiskQueue.freeList).  If the free list is empty, call     RF_Malloc to create a new structure.     NON-BLOCKING */    RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);  if (raidPtr->parityLogDiskQueue.freeDataList)    {      data = raidPtr->parityLogDiskQueue.freeDataList;      raidPtr->parityLogDiskQueue.freeDataList = raidPtr->parityLogDiskQueue.freeDataList->next;      RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);    }  else    {      RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);      RF_Malloc(data, sizeof(RF_ParityLogData_t), (RF_ParityLogData_t *));    }  data->next = NULL;  data->prev = NULL;  return(data);}static void FreeParityLogData(RF_ParityLogData_t *data){  RF_ParityLogData_t *nextItem;  RF_Raid_t *raidPtr;  /* Insert a linked list of structs for holding parity log     information (data) into the free list (parityLogDiskQueue.freeList).     NON-BLOCKING */  raidPtr = data->common->raidPtr;  RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);  while (data)    {      nextItem = data->next;      data->next = raidPtr->parityLogDiskQueue.freeDataList;      raidPtr->parityLogDiskQueue.freeDataList = data;      data = nextItem;    }  RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);}static void EnqueueParityLogData(  RF_ParityLogData_t   *data,  RF_ParityLogData_t  **head,  RF_ParityLogData_t  **tail){  RF_Raid_t *raidPtr;  /* Insert an in-core parity log (*data) into the head of     a disk queue (*head, *tail).     NON-BLOCKING */  raidPtr = data->common->raidPtr;  if (rf_parityLogDebug)    printf("[enqueueing parity log data, region %d, raidAddress %d, numSector %d]\n",data->regionID,data->diskAddress.raidAddress, data->diskAddress.numSector);  RF_ASSERT(data->prev == NULL);  RF_ASSERT(data->next == NULL);  RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);  if (*head)    {      /* insert into head of queue */      RF_ASSERT((*head)->prev == NULL);      RF_ASSERT((*tail)->next == NULL);      data->next = *head;      (*head)->prev = data;      *head = data;    }  else    {      /* insert into empty list */      RF_ASSERT(*head == NULL);      RF_ASSERT(*tail == NULL);      *head = data;      *tail = data;    }  RF_ASSERT((*head)->prev == NULL);  RF_ASSERT((*tail)->next == NULL);  RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);}static RF_ParityLogData_t *DequeueParityLogData(  RF_Raid_t            *raidPtr,  RF_ParityLogData_t  **head,  RF_ParityLogData_t  **tail,  int                   ignoreLocks){  RF_ParityLogData_t *data;  /* Remove and return an in-core parity log from the tail of     a disk queue (*head, *tail).     NON-BLOCKING */  /* remove from tail, preserving FIFO order */  if (!ignoreLocks)    RF_LOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);  data = *tail;  if (data)    {      if (*head == *tail)	{	  /* removing last item from queue */	  *head = NULL;	  *tail = NULL;	}      else	{	  *tail = (*tail)->prev;	  (*tail)->next = NULL;	  RF_ASSERT((*head)->prev == NULL);	  RF_ASSERT((*tail)->next == NULL);	}      data->next = NULL;      data->prev = NULL;      if (rf_parityLogDebug)	printf("[dequeueing parity log data, region %d, raidAddress %d, numSector %d]\n",data->regionID,data->diskAddress.raidAddress, data->diskAddress.numSector);    }  if (*head)    {      RF_ASSERT((*head)->prev == NULL);      RF_ASSERT((*tail)->next == NULL);    }  if (!ignoreLocks)    RF_UNLOCK_MUTEX(raidPtr->parityLogDiskQueue.mutex);  return(data);}

⌨️ 快捷键说明

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