xref: /netbsd-src/sys/dev/raidframe/rf_raid.h (revision 95d875fb90b1458e4f1de6950286ddcd6644bc61)
1 /*	$NetBSD: rf_raid.h,v 1.8 2000/01/05 02:57:29 oster Exp $	*/
2 /*
3  * Copyright (c) 1995 Carnegie-Mellon University.
4  * All rights reserved.
5  *
6  * Author: Mark Holland
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 /**********************************************
30  * rf_raid.h -- main header file for RAID driver
31  **********************************************/
32 
33 
34 #ifndef _RF__RF_RAID_H_
35 #define _RF__RF_RAID_H_
36 
37 #include "rf_archs.h"
38 #include "rf_types.h"
39 #include "rf_threadstuff.h"
40 
41 #include "rf_netbsd.h"
42 
43 #include <sys/disklabel.h>
44 #include <sys/types.h>
45 
46 #include "rf_alloclist.h"
47 #include "rf_stripelocks.h"
48 #include "rf_layout.h"
49 #include "rf_disks.h"
50 #include "rf_debugMem.h"
51 #include "rf_diskqueue.h"
52 #include "rf_reconstruct.h"
53 #include "rf_acctrace.h"
54 
55 #if RF_INCLUDE_PARITYLOGGING > 0
56 #include "rf_paritylog.h"
57 #endif				/* RF_INCLUDE_PARITYLOGGING > 0 */
58 
59 #define RF_MAX_DISKS 128	/* max disks per array */
60 #define RF_DEV2RAIDID(_dev)  (DISKUNIT(_dev))
61 
62 #define RF_COMPONENT_LABEL_VERSION 1
63 #define RF_RAID_DIRTY 0
64 #define RF_RAID_CLEAN 1
65 
66 
67 /*
68  * Each row in the array is a distinct parity group, so
69  * each has it's own status, which is one of the following.
70  */
71 typedef enum RF_RowStatus_e {
72 	rf_rs_optimal,
73 	rf_rs_degraded,
74 	rf_rs_reconstructing,
75 	rf_rs_reconfigured
76 }       RF_RowStatus_t;
77 
78 struct RF_CumulativeStats_s {
79 	struct timeval start;	/* the time when the stats were last started */
80 	struct timeval stop;	/* the time when the stats were last stopped */
81 	long    sum_io_us;	/* sum of all user response times (us) */
82 	long    num_ios;	/* total number of I/Os serviced */
83 	long    num_sect_moved;	/* total number of sectors read or written */
84 };
85 
86 struct RF_ThroughputStats_s {
87 	RF_DECLARE_MUTEX(mutex)	/* a mutex used to lock the configuration
88 				 * stuff */
89 	struct timeval start;	/* timer started when numOutstandingRequests
90 				 * moves from 0 to 1 */
91 	struct timeval stop;	/* timer stopped when numOutstandingRequests
92 				 * moves from 1 to 0 */
93 	RF_uint64 sum_io_us;	/* total time timer is enabled */
94 	RF_uint64 num_ios;	/* total number of ios processed by RAIDframe */
95 	long    num_out_ios;	/* number of outstanding ios */
96 };
97 
98 struct RF_Raid_s {
99 	/* This portion never changes, and can be accessed without locking */
100 	/* an exception is Disks[][].status, which requires locking when it is
101 	 * changed.  XXX this is no longer true.  numSpare and friends can
102 	 * change now.
103          */
104 	u_int   numRow;		/* number of rows of disks, typically == # of
105 				 * ranks */
106 	u_int   numCol;		/* number of columns of disks, typically == #
107 				 * of disks/rank */
108 	u_int   numSpare;	/* number of spare disks */
109 	int     maxQueueDepth;	/* max disk queue depth */
110 	RF_SectorCount_t totalSectors;	/* total number of sectors in the
111 					 * array */
112 	RF_SectorCount_t sectorsPerDisk;	/* number of sectors on each
113 						 * disk */
114 	u_int   logBytesPerSector;	/* base-2 log of the number of bytes
115 					 * in a sector */
116 	u_int   bytesPerSector;	/* bytes in a sector */
117 	RF_int32 sectorMask;	/* mask of bytes-per-sector */
118 
119 	RF_RaidLayout_t Layout;	/* all information related to layout */
120 	RF_RaidDisk_t **Disks;	/* all information related to physical disks */
121 	RF_DiskQueue_t **Queues;/* all information related to disk queues */
122 	/* NOTE:  This is an anchor point via which the queues can be
123 	 * accessed, but the enqueue/dequeue routines in diskqueue.c use a
124 	 * local copy of this pointer for the actual accesses. */
125 	/* The remainder of the structure can change, and therefore requires
126 	 * locking on reads and updates */
127 	        RF_DECLARE_MUTEX(mutex)	/* mutex used to serialize access to
128 					 * the fields below */
129 	RF_RowStatus_t *status;	/* the status of each row in the array */
130 	int     valid;		/* indicates successful configuration */
131 	RF_LockTableEntry_t *lockTable;	/* stripe-lock table */
132 	RF_LockTableEntry_t *quiesceLock;	/* quiesnce table */
133 	int     numFailures;	/* total number of failures in the array */
134 
135 	int     parity_good;    /* !0 if parity is known to be correct */
136 	int     serial_number;  /* a "serial number" for this set */
137 	int     mod_counter;    /* modification counter for component labels */
138 	int     clean;          /* the clean bit for this array. */
139 
140 	int     openings;       /* Number of IO's which can be scheduled
141 				   simultaneously (high-level - not a
142 				   per-component limit)*/
143 
144 	/*
145          * Cleanup stuff
146          */
147 	RF_ShutdownList_t *shutdownList;	/* shutdown activities */
148 	RF_AllocListElem_t *cleanupList;	/* memory to be freed at
149 						 * shutdown time */
150 
151 	/*
152          * Recon stuff
153          */
154 	RF_HeadSepLimit_t headSepLimit;
155 	int     numFloatingReconBufs;
156 	int     reconInProgress;
157 	        RF_DECLARE_COND(waitForReconCond)
158 	RF_RaidReconDesc_t *reconDesc;	/* reconstruction descriptor */
159 	RF_ReconCtrl_t **reconControl;	/* reconstruction control structure
160 					 * pointers for each row in the array */
161 
162 	/*
163          * Array-quiescence stuff
164          */
165 	        RF_DECLARE_MUTEX(access_suspend_mutex)
166 	        RF_DECLARE_COND(quiescent_cond)
167 	RF_IoCount_t accesses_suspended;
168 	RF_IoCount_t accs_in_flight;
169 	int     access_suspend_release;
170 	int     waiting_for_quiescence;
171 	RF_CallbackDesc_t *quiesce_wait_list;
172 
173 	/*
174          * Statistics
175          */
176 #if !defined(_KERNEL) && !defined(SIMULATE)
177 	RF_ThroughputStats_t throughputstats;
178 #endif				/* !KERNEL && !SIMULATE */
179 	RF_CumulativeStats_t userstats;
180 	int     parity_rewrite_stripes_done;
181 	int     recon_stripes_done;
182 	int     copyback_stripes_done;
183 
184 	int     recon_in_progress;
185 	int     parity_rewrite_in_progress;
186 	int     copyback_in_progress;
187 
188 	/*
189          * Engine thread control
190          */
191 	        RF_DECLARE_MUTEX(node_queue_mutex)
192 	        RF_DECLARE_COND(node_queue_cond)
193 	RF_DagNode_t *node_queue;
194 	RF_Thread_t parity_rewrite_thread;
195 	RF_Thread_t copyback_thread;
196 	RF_Thread_t engine_thread;
197 	RF_Thread_t recon_thread;
198 	RF_ThreadGroup_t engine_tg;
199 	int     shutdown_engine;
200 	int     dags_in_flight;	/* debug */
201 
202 	/*
203          * PSS (Parity Stripe Status) stuff
204          */
205 	RF_FreeList_t *pss_freelist;
206 	long    pssTableSize;
207 
208 	/*
209          * Reconstruction stuff
210          */
211 	int     procsInBufWait;
212 	int     numFullReconBuffers;
213 	RF_AccTraceEntry_t *recon_tracerecs;
214 	unsigned long accumXorTimeUs;
215 	RF_ReconDoneProc_t *recon_done_procs;
216 	        RF_DECLARE_MUTEX(recon_done_proc_mutex)
217 	/*
218          * nAccOutstanding, waitShutdown protected by desc freelist lock
219          * (This may seem strange, since that's a central serialization point
220          * for a per-array piece of data, but otherwise, it'd be an extra
221          * per-array lock, and that'd only be less efficient...)
222          */
223 	        RF_DECLARE_COND(outstandingCond)
224 	int     waitShutdown;
225 	int     nAccOutstanding;
226 
227 	RF_DiskId_t **diskids;
228 	RF_DiskId_t *sparediskids;
229 
230 	int     raidid;
231 	RF_AccTotals_t acc_totals;
232 	int     keep_acc_totals;
233 
234 	struct raidcinfo **raid_cinfo;	/* array of component info */
235 
236 	int     terminate_disk_queues;
237 
238 	/*
239          * XXX
240          *
241          * config-specific information should be moved
242          * somewhere else, or at least hung off this
243          * in some generic way
244          */
245 
246 	/* used by rf_compute_workload_shift */
247 	RF_RowCol_t hist_diskreq[RF_MAXROW][RF_MAXCOL];
248 
249 	/* used by declustering */
250 	int     noRotate;
251 
252 #if RF_INCLUDE_PARITYLOGGING > 0
253 	/* used by parity logging */
254 	RF_SectorCount_t regionLogCapacity;
255 	RF_ParityLogQueue_t parityLogPool;	/* pool of unused parity logs */
256 	RF_RegionInfo_t *regionInfo;	/* array of region state */
257 	int     numParityLogs;
258 	int     numSectorsPerLog;
259 	int     regionParityRange;
260 	int     logsInUse;	/* debugging */
261 	RF_ParityLogDiskQueue_t parityLogDiskQueue;	/* state of parity
262 							 * logging disk work */
263 	RF_RegionBufferQueue_t regionBufferPool;	/* buffers for holding
264 							 * region log */
265 	RF_RegionBufferQueue_t parityBufferPool;	/* buffers for holding
266 							 * parity */
267 	caddr_t parityLogBufferHeap;	/* pool of unused parity logs */
268 	RF_Thread_t pLogDiskThreadHandle;
269 
270 #endif				/* RF_INCLUDE_PARITYLOGGING > 0 */
271 };
272 #endif				/* !_RF__RF_RAID_H_ */
273