rf_paritylog.h revision 1.2
1139749Simp/*	$NetBSD: rf_paritylog.h,v 1.2 1999/01/26 02:33:59 oster Exp $	*/
255992Swpaul/*
355992Swpaul * Copyright (c) 1995 Carnegie-Mellon University.
455992Swpaul * All rights reserved.
555992Swpaul *
655992Swpaul * Author: William V. Courtright II
755992Swpaul *
855992Swpaul * Permission to use, copy, modify and distribute this software and
955992Swpaul * its documentation is hereby granted, provided that both the copyright
1055992Swpaul * notice and this permission notice appear in all copies of the
1155992Swpaul * software, derivative works or modified versions, and any portions
1255992Swpaul * thereof, and that both notices appear in supporting documentation.
1355992Swpaul *
1455992Swpaul * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
1555992Swpaul * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
1655992Swpaul * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1755992Swpaul *
1855992Swpaul * Carnegie Mellon requests users of this software to return to
1955992Swpaul *
2055992Swpaul *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
2155992Swpaul *  School of Computer Science
2255992Swpaul *  Carnegie Mellon University
2355992Swpaul *  Pittsburgh PA 15213-3890
2455992Swpaul *
2555992Swpaul * any improvements or extensions that they make and grant Carnegie the
2655992Swpaul * rights to redistribute these changes.
2755992Swpaul */
2855992Swpaul
2955992Swpaul/* header file for parity log
3055992Swpaul *
3155992Swpaul */
3255992Swpaul
3355992Swpaul#ifndef _RF__RF_PARITYLOG_H_
3455992Swpaul#define _RF__RF_PARITYLOG_H_
3555992Swpaul
3655992Swpaul#include "rf_types.h"
3755992Swpaul
3855992Swpaul#define RF_DEFAULT_NUM_SECTORS_PER_LOG 64
3955992Swpaul
40119418Sobrientypedef int RF_RegionId_t;
41119418Sobrien
42119418Sobrientypedef enum RF_ParityRecordType_e {
4355992Swpaul  RF_STOP,
4486259Sphk  RF_UPDATE,
4555992Swpaul  RF_OVERWRITE
46100770Sfenner} RF_ParityRecordType_t;
4755992Swpaul
4855992Swpaulstruct RF_CommonLogData_s {
4955992Swpaul  RF_DECLARE_MUTEX(mutex)               /* protects cnt */
5055992Swpaul  int                      cnt;         /* when 0, time to call wakeFunc */
5155992Swpaul  RF_Raid_t               *raidPtr;
5255992Swpaul/*   int                    (*wakeFunc)(struct buf *); */
5355992Swpaul  int                    (*wakeFunc)(RF_DagNode_t *node, int status);
5455992Swpaul  void                    *wakeArg;
5555992Swpaul  RF_AccTraceEntry_t      *tracerec;
5655992Swpaul  RF_Etimer_t              startTime;
5755992Swpaul  caddr_t                  bufPtr;
5855992Swpaul  RF_ParityRecordType_t    operation;
5955992Swpaul  RF_CommonLogData_t      *next;
6055992Swpaul};
6155992Swpaul
6255992Swpaulstruct RF_ParityLogData_s {
6355992Swpaul  RF_RegionId_t        regionID;    /* this struct guaranteed to span a single region */
6455992Swpaul  int                  bufOffset;   /* offset from common->bufPtr */
6555992Swpaul  RF_PhysDiskAddr_t    diskAddress;
6655992Swpaul  RF_CommonLogData_t  *common;      /* info shared by one or more parityLogData structs */
6755992Swpaul  RF_ParityLogData_t  *next;
6855992Swpaul  RF_ParityLogData_t  *prev;
6955992Swpaul};
7055992Swpaul
7186381Simpstruct RF_ParityLogAppendQueue_s {
7255992Swpaul  RF_DECLARE_MUTEX(mutex)
7355992Swpaul};
7455992Swpaul
7583270Sbrooksstruct RF_ParityLogRecord_s {
7655992Swpaul  RF_PhysDiskAddr_t      parityAddr;
7755992Swpaul  RF_ParityRecordType_t  operation;
7855992Swpaul};
7955992Swpaul
8055992Swpaulstruct RF_ParityLog_s {
8155992Swpaul  RF_RegionId_t          regionID;
8255992Swpaul  int                    numRecords;
8355992Swpaul  int                    diskOffset;
8455992Swpaul  RF_ParityLogRecord_t  *records;
8555992Swpaul  caddr_t                bufPtr;
8655992Swpaul  RF_ParityLog_t        *next;
8755992Swpaul};
8855992Swpaul
8955992Swpaulstruct RF_ParityLogQueue_s {
9055992Swpaul  RF_DECLARE_MUTEX(mutex)
91154866Snjl  RF_ParityLog_t  *parityLogs;
9255992Swpaul};
9355992Swpaul
9455992Swpaulstruct RF_RegionBufferQueue_s {
95164033Srwatson  RF_DECLARE_MUTEX(mutex)
9683366Sjulian  RF_DECLARE_COND(cond)
9755992Swpaul  int       bufferSize;
9855992Swpaul  int       totalBuffers;      /* size of array 'buffers' */
9955992Swpaul  int       availableBuffers;  /* num available 'buffers' */
10055992Swpaul  int       emptyBuffersIndex; /* stick next freed buffer here */
101108401Sambrisko  int       availBuffersIndex; /* grab next buffer from here */
10255992Swpaul  caddr_t  *buffers;           /* array buffers used to hold parity */
10355992Swpaul};
10455992Swpaul
10555992Swpaul#define RF_PLOG_CREATED   (1<<0) /* thread is created */
10655992Swpaul#define RF_PLOG_RUNNING   (1<<1) /* thread is running */
10755992Swpaul#define RF_PLOG_TERMINATE (1<<2) /* thread is terminated (should exit) */
10884811Sjhb#define RF_PLOG_SHUTDOWN  (1<<3) /* thread is aware and exiting/exited */
10967365Sjhb
11055992Swpaulstruct RF_ParityLogDiskQueue_s {
111108401Sambrisko  RF_DECLARE_MUTEX(mutex)          /* protects all vars in this struct */
11255992Swpaul  RF_DECLARE_COND(cond)
11355992Swpaul  int                  threadState;    /* is thread running, should it shutdown  (see above) */
114257176Sglebius  RF_ParityLog_t      *flushQueue;     /* list of parity logs to be flushed to log disk */
11555992Swpaul  RF_ParityLog_t      *reintQueue;     /* list of parity logs waiting to be reintegrated */
116152315Sru  RF_ParityLogData_t  *bufHead;        /* head of FIFO list of log data, waiting on a buffer */
11755992Swpaul  RF_ParityLogData_t  *bufTail;        /* tail of FIFO list of log data, waiting on a buffer */
11855992Swpaul  RF_ParityLogData_t  *reintHead;      /* head of FIFO list of log data, waiting on reintegration */
11977217Sphk  RF_ParityLogData_t  *reintTail;      /* tail of FIFO list of log data, waiting on reintegration */
12055992Swpaul  RF_ParityLogData_t  *logBlockHead;   /* queue of work, blocked until a log is available */
121116951Ssam  RF_ParityLogData_t  *logBlockTail;
122116951Ssam  RF_ParityLogData_t  *reintBlockHead; /* queue of work, blocked until reintegration is complete */
123116951Ssam  RF_ParityLogData_t  *reintBlockTail;
12455992Swpaul  RF_CommonLogData_t  *freeCommonList; /* list of unused common data structs */
12555992Swpaul  RF_ParityLogData_t  *freeDataList;   /* list of unused log data structs */
12655992Swpaul};
12755992Swpaul
12855992Swpaulstruct RF_DiskMap_s {
12955992Swpaul  RF_PhysDiskAddr_t      parityAddr;
13055992Swpaul  RF_ParityRecordType_t  operation;
13155992Swpaul};
13255992Swpaul
13355992Swpaulstruct RF_RegionInfo_s {
13455992Swpaul  RF_DECLARE_MUTEX(mutex)            /* protects: diskCount, diskMap, loggingEnabled, coreLog */
13555992Swpaul  RF_DECLARE_MUTEX(reintMutex)       /* protects: reintInProgress */
13655992Swpaul  int              reintInProgress;  /* flag used to suspend flushing operations */
13755992Swpaul  RF_SectorCount_t capacity;         /* capacity of this region in sectors */
13855992Swpaul  RF_SectorNum_t   regionStartAddr;  /* starting disk address for this region */
139150446Simp  RF_SectorNum_t   parityStartAddr;  /* starting disk address for this region */
140150446Simp  RF_SectorCount_t numSectorsParity; /* number of parity sectors protected by this region */
141150446Simp  RF_SectorCount_t diskCount;        /* num of sectors written to this region's disk log */
142150446Simp  RF_DiskMap_t    *diskMap;          /* in-core map of what's in this region's disk log */
143199154Sjhb  int              loggingEnabled;   /* logging enable for this region */
144150446Simp  RF_ParityLog_t  *coreLog;          /* in-core log for this region */
145150446Simp};
146199154Sjhb
147199154SjhbRF_ParityLogData_t *rf_CreateParityLogData(RF_ParityRecordType_t operation,
148150446Simp	RF_PhysDiskAddr_t *pda, caddr_t bufPtr, RF_Raid_t *raidPtr,
149150446Simp	int (*wakeFunc)(RF_DagNode_t *node, int status),
15055992Swpaul	void *wakeArg, RF_AccTraceEntry_t *tracerec,
151150446Simp	RF_Etimer_t startTime);
152150446SimpRF_ParityLogData_t *rf_SearchAndDequeueParityLogData(RF_Raid_t *raidPtr,
153150446Simp	RF_RegionId_t regionID, RF_ParityLogData_t **head,
154150446Simp	RF_ParityLogData_t **tail, int ignoreLocks);
155150446Simpvoid rf_ReleaseParityLogs(RF_Raid_t *raidPtr, RF_ParityLog_t *firstLog);
156150446Simpint rf_ParityLogAppend(RF_ParityLogData_t *logData, int finish,
157150446Simp	RF_ParityLog_t **incomingLog, int clearReintFlag);
158150446Simpvoid rf_EnableParityLogging(RF_Raid_t *raidPtr);
159150446Simp
160150446Simp#endif /* !_RF__RF_PARITYLOG_H_ */
161150446Simp