1/* $NetBSD: rf_paritylog.h,v 1.11 2011/05/11 06:20:33 mrg Exp $ */ 2/* 3 * Copyright (c) 1995 Carnegie-Mellon University. 4 * All rights reserved. 5 * 6 * Author: William V. Courtright II 7 * 8 * Permission to use, copy, modify and distribute this software and 9 * its documentation is hereby granted, provided that both the copyright 10 * notice and this permission notice appear in all copies of the 11 * software, derivative works or modified versions, and any portions 12 * thereof, and that both notices appear in supporting documentation. 13 * 14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 17 * 18 * Carnegie Mellon requests users of this software to return to 19 * 20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 21 * School of Computer Science 22 * Carnegie Mellon University 23 * Pittsburgh PA 15213-3890 24 * 25 * any improvements or extensions that they make and grant Carnegie the 26 * rights to redistribute these changes. 27 */ 28 29/* header file for parity log 30 * 31 */ 32 33#ifndef _RF__RF_PARITYLOG_H_ 34#define _RF__RF_PARITYLOG_H_ 35 36#include <dev/raidframe/raidframevar.h> 37 38#define RF_DEFAULT_NUM_SECTORS_PER_LOG 64 39 40typedef int RF_RegionId_t; 41 42typedef enum RF_ParityRecordType_e { 43 RF_STOP, 44 RF_UPDATE, 45 RF_OVERWRITE 46} RF_ParityRecordType_t; 47 48struct RF_CommonLogData_s { 49 rf_declare_mutex2(mutex); /* protects cnt */ 50 int cnt; /* when 0, time to call wakeFunc */ 51 RF_Raid_t *raidPtr; 52/* int (*wakeFunc)(struct buf *); */ 53 int (*wakeFunc) (RF_DagNode_t * node, int status); 54 void *wakeArg; 55 RF_AccTraceEntry_t *tracerec; 56 RF_Etimer_t startTime; 57 void *bufPtr; 58 RF_ParityRecordType_t operation; 59 RF_CommonLogData_t *next; 60}; 61 62struct RF_ParityLogData_s { 63 RF_RegionId_t regionID; /* this struct guaranteed to span a single 64 * region */ 65 int bufOffset; /* offset from common->bufPtr */ 66 RF_PhysDiskAddr_t diskAddress; 67 RF_CommonLogData_t *common; /* info shared by one or more 68 * parityLogData structs */ 69 RF_ParityLogData_t *next; 70 RF_ParityLogData_t *prev; 71}; 72 73struct RF_ParityLogAppendQueue_s { 74 rf_declare_mutex2(mutex); 75}; 76 77struct RF_ParityLogRecord_s { 78 RF_PhysDiskAddr_t parityAddr; 79 RF_ParityRecordType_t operation; 80}; 81 82struct RF_ParityLog_s { 83 RF_RegionId_t regionID; 84 int numRecords; 85 int diskOffset; 86 RF_ParityLogRecord_t *records; 87 void *bufPtr; 88 RF_ParityLog_t *next; 89}; 90 91struct RF_ParityLogQueue_s { 92 rf_declare_mutex2(mutex); 93 RF_ParityLog_t *parityLogs; 94}; 95 96struct RF_RegionBufferQueue_s { 97 rf_declare_mutex2(mutex); 98 rf_declare_cond2(cond); 99 int bufferSize; 100 int totalBuffers; /* size of array 'buffers' */ 101 int availableBuffers; /* num available 'buffers' */ 102 int emptyBuffersIndex; /* stick next freed buffer here */ 103 int availBuffersIndex; /* grab next buffer from here */ 104 void **buffers; /* array buffers used to hold parity */ 105}; 106#define RF_PLOG_CREATED (1<<0)/* thread is created */ 107#define RF_PLOG_RUNNING (1<<1)/* thread is running */ 108#define RF_PLOG_TERMINATE (1<<2)/* thread is terminated (should exit) */ 109#define RF_PLOG_SHUTDOWN (1<<3)/* thread is aware and exiting/exited */ 110 111struct RF_ParityLogDiskQueue_s { 112 rf_declare_mutex2(mutex);/* protects all vars in this struct */ 113 rf_declare_cond2(cond); 114 int threadState; /* is thread running, should it shutdown (see 115 * above) */ 116 RF_ParityLog_t *flushQueue; /* list of parity logs to be flushed 117 * to log disk */ 118 RF_ParityLog_t *reintQueue; /* list of parity logs waiting to be 119 * reintegrated */ 120 RF_ParityLogData_t *bufHead; /* head of FIFO list of log data, 121 * waiting on a buffer */ 122 RF_ParityLogData_t *bufTail; /* tail of FIFO list of log data, 123 * waiting on a buffer */ 124 RF_ParityLogData_t *reintHead; /* head of FIFO list of log data, 125 * waiting on reintegration */ 126 RF_ParityLogData_t *reintTail; /* tail of FIFO list of log data, 127 * waiting on reintegration */ 128 RF_ParityLogData_t *logBlockHead; /* queue of work, blocked 129 * until a log is available */ 130 RF_ParityLogData_t *logBlockTail; 131 RF_ParityLogData_t *reintBlockHead; /* queue of work, blocked 132 * until reintegration is 133 * complete */ 134 RF_ParityLogData_t *reintBlockTail; 135 RF_CommonLogData_t *freeCommonList; /* list of unused common data 136 * structs */ 137 RF_ParityLogData_t *freeDataList; /* list of unused log data 138 * structs */ 139}; 140 141struct RF_DiskMap_s { 142 RF_PhysDiskAddr_t parityAddr; 143 RF_ParityRecordType_t operation; 144}; 145 146struct RF_RegionInfo_s { 147 rf_declare_mutex2(mutex); /* protects: diskCount, diskMap, 148 * loggingEnabled, coreLog */ 149 rf_declare_mutex2(reintMutex); /* protects: reintInProgress */ 150 int reintInProgress;/* flag used to suspend flushing operations */ 151 RF_SectorCount_t capacity; /* capacity of this region in sectors */ 152 RF_SectorNum_t regionStartAddr; /* starting disk address for this 153 * region */ 154 RF_SectorNum_t parityStartAddr; /* starting disk address for this 155 * region */ 156 RF_SectorCount_t numSectorsParity; /* number of parity sectors 157 * protected by this region */ 158 RF_SectorCount_t diskCount; /* num of sectors written to this 159 * region's disk log */ 160 RF_DiskMap_t *diskMap; /* in-core map of what's in this region's disk 161 * log */ 162 int loggingEnabled; /* logging enable for this region */ 163 RF_ParityLog_t *coreLog;/* in-core log for this region */ 164}; 165 166RF_ParityLogData_t * 167rf_CreateParityLogData(RF_ParityRecordType_t operation, 168 RF_PhysDiskAddr_t * pda, void *bufPtr, RF_Raid_t * raidPtr, 169 int (*wakeFunc) (RF_DagNode_t * node, int status), 170 void *wakeArg, RF_AccTraceEntry_t * tracerec, 171 RF_Etimer_t startTime); 172 RF_ParityLogData_t *rf_SearchAndDequeueParityLogData(RF_Raid_t * raidPtr, 173 RF_RegionId_t regionID, RF_ParityLogData_t ** head, 174 RF_ParityLogData_t ** tail, int ignoreLocks); 175 void rf_ReleaseParityLogs(RF_Raid_t * raidPtr, RF_ParityLog_t * firstLog); 176 int rf_ParityLogAppend(RF_ParityLogData_t * logData, int finish, 177 RF_ParityLog_t ** incomingLog, int clearReintFlag); 178 void rf_EnableParityLogging(RF_Raid_t * raidPtr); 179 180#endif /* !_RF__RF_PARITYLOG_H_ */ 181