xref: /netbsd/sys/dev/raidframe/rf_raid.h (revision bf9ec67e)
1 /*	$NetBSD: rf_raid.h,v 1.14 2001/10/04 15:58:55 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 <dev/raidframe/raidframevar.h>
38 #include "rf_archs.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_COMPONENT_LABEL_VERSION_1 1
60 #define RF_COMPONENT_LABEL_VERSION 2
61 #define RF_RAID_DIRTY 0
62 #define RF_RAID_CLEAN 1
63 
64 
65 /*
66  * Each row in the array is a distinct parity group, so
67  * each has it's own status, which is one of the following.
68  */
69 typedef enum RF_RowStatus_e {
70 	rf_rs_optimal,
71 	rf_rs_degraded,
72 	rf_rs_reconstructing,
73 	rf_rs_reconfigured
74 }       RF_RowStatus_t;
75 
76 struct RF_CumulativeStats_s {
77 	struct timeval start;	/* the time when the stats were last started */
78 	struct timeval stop;	/* the time when the stats were last stopped */
79 	long    sum_io_us;	/* sum of all user response times (us) */
80 	long    num_ios;	/* total number of I/Os serviced */
81 	long    num_sect_moved;	/* total number of sectors read or written */
82 };
83 
84 struct RF_ThroughputStats_s {
85 	RF_DECLARE_MUTEX(mutex)	/* a mutex used to lock the configuration
86 				 * stuff */
87 	struct timeval start;	/* timer started when numOutstandingRequests
88 				 * moves from 0 to 1 */
89 	struct timeval stop;	/* timer stopped when numOutstandingRequests
90 				 * moves from 1 to 0 */
91 	RF_uint64 sum_io_us;	/* total time timer is enabled */
92 	RF_uint64 num_ios;	/* total number of ios processed by RAIDframe */
93 	long    num_out_ios;	/* number of outstanding ios */
94 };
95 
96 struct RF_Raid_s {
97 	/* This portion never changes, and can be accessed without locking */
98 	/* an exception is Disks[][].status, which requires locking when it is
99 	 * changed.  XXX this is no longer true.  numSpare and friends can
100 	 * change now.
101          */
102 	u_int   numRow;		/* number of rows of disks, typically == # of
103 				 * ranks */
104 	u_int   numCol;		/* number of columns of disks, typically == #
105 				 * of disks/rank */
106 	u_int   numSpare;	/* number of spare disks */
107 	int     maxQueueDepth;	/* max disk queue depth */
108 	RF_SectorCount_t totalSectors;	/* total number of sectors in the
109 					 * array */
110 	RF_SectorCount_t sectorsPerDisk;	/* number of sectors on each
111 						 * disk */
112 	u_int   logBytesPerSector;	/* base-2 log of the number of bytes
113 					 * in a sector */
114 	u_int   bytesPerSector;	/* bytes in a sector */
115 	RF_int32 sectorMask;	/* mask of bytes-per-sector */
116 
117 	RF_RaidLayout_t Layout;	/* all information related to layout */
118 	RF_RaidDisk_t **Disks;	/* all information related to physical disks */
119 	RF_DiskQueue_t **Queues;/* all information related to disk queues */
120 	RF_DiskQueueSW_t *qType;/* pointer to the DiskQueueSW used for the
121 				   component 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 	int     numNewFailures; /* number of *new* failures (that havn't
135 				   caused a mod_counter update */
136 
137 	int     parity_good;    /* !0 if parity is known to be correct */
138 	int     serial_number;  /* a "serial number" for this set */
139 	int     mod_counter;    /* modification counter for component labels */
140 	int     clean;          /* the clean bit for this array. */
141 
142 	int     openings;       /* Number of IO's which can be scheduled
143 				   simultaneously (high-level - not a
144 				   per-component limit)*/
145 
146 	int maxOutstanding;   /* maxOutstanding requests (per-component) */
147 	int autoconfigure;    /* automatically configure this RAID set.
148 				 0 == no, 1 == yes */
149 	int root_partition;   /* Use this set as /
150 				 0 == no, 1 == yes*/
151 	int last_unit;        /* last unit number (e.g. 0 for /dev/raid0)
152 				 of this component.  Used for autoconfigure
153 				 only. */
154 	int config_order;     /* 0 .. n.  The order in which the component
155 				 should be auto-configured.  E.g. 0 is will
156 				 done first, (and would become raid0).
157 				 This may be in conflict with last_unit!!?! */
158 	                      /* Not currently used. */
159 
160 	/*
161          * Cleanup stuff
162          */
163 	RF_ShutdownList_t *shutdownList;	/* shutdown activities */
164 	RF_AllocListElem_t *cleanupList;	/* memory to be freed at
165 						 * shutdown time */
166 
167 	/*
168          * Recon stuff
169          */
170 	RF_HeadSepLimit_t headSepLimit;
171 	int     numFloatingReconBufs;
172 	int     reconInProgress;
173 	        RF_DECLARE_COND(waitForReconCond)
174 	RF_RaidReconDesc_t *reconDesc;	/* reconstruction descriptor */
175 	RF_ReconCtrl_t **reconControl;	/* reconstruction control structure
176 					 * pointers for each row in the array */
177 
178 	/*
179          * Array-quiescence stuff
180          */
181 	        RF_DECLARE_MUTEX(access_suspend_mutex)
182 	        RF_DECLARE_COND(quiescent_cond)
183 	RF_IoCount_t accesses_suspended;
184 	RF_IoCount_t accs_in_flight;
185 	int     access_suspend_release;
186 	int     waiting_for_quiescence;
187 	RF_CallbackDesc_t *quiesce_wait_list;
188 
189 	/*
190          * Statistics
191          */
192 #if !defined(_KERNEL) && !defined(SIMULATE)
193 	RF_ThroughputStats_t throughputstats;
194 #endif				/* !KERNEL && !SIMULATE */
195 	RF_CumulativeStats_t userstats;
196 	int     parity_rewrite_stripes_done;
197 	int     recon_stripes_done;
198 	int     copyback_stripes_done;
199 
200 	int     recon_in_progress;
201 	int     parity_rewrite_in_progress;
202 	int     copyback_in_progress;
203 
204 	/*
205          * Engine thread control
206          */
207 	        RF_DECLARE_MUTEX(node_queue_mutex)
208 	        RF_DECLARE_COND(node_queue_cond)
209 	RF_DagNode_t *node_queue;
210 	RF_Thread_t parity_rewrite_thread;
211 	RF_Thread_t copyback_thread;
212 	RF_Thread_t engine_thread;
213 	RF_Thread_t recon_thread;
214 	RF_ThreadGroup_t engine_tg;
215 	int     shutdown_engine;
216 	int     dags_in_flight;	/* debug */
217 
218 	/*
219          * PSS (Parity Stripe Status) stuff
220          */
221 	RF_FreeList_t *pss_freelist;
222 	long    pssTableSize;
223 
224 	/*
225          * Reconstruction stuff
226          */
227 	int     procsInBufWait;
228 	int     numFullReconBuffers;
229 	RF_AccTraceEntry_t *recon_tracerecs;
230 	unsigned long accumXorTimeUs;
231 	RF_ReconDoneProc_t *recon_done_procs;
232 	        RF_DECLARE_MUTEX(recon_done_proc_mutex)
233 	/*
234          * nAccOutstanding, waitShutdown protected by desc freelist lock
235          * (This may seem strange, since that's a central serialization point
236          * for a per-array piece of data, but otherwise, it'd be an extra
237          * per-array lock, and that'd only be less efficient...)
238          */
239 	        RF_DECLARE_COND(outstandingCond)
240 	int     waitShutdown;
241 	int     nAccOutstanding;
242 
243 	RF_DiskId_t **diskids;
244 	RF_DiskId_t *sparediskids;
245 
246 	int     raidid;
247 	RF_AccTotals_t acc_totals;
248 	int     keep_acc_totals;
249 
250 	struct raidcinfo **raid_cinfo;	/* array of component info */
251 
252 	int     terminate_disk_queues;
253 
254 	/*
255          * XXX
256          *
257          * config-specific information should be moved
258          * somewhere else, or at least hung off this
259          * in some generic way
260          */
261 
262 	/* used by rf_compute_workload_shift */
263 	RF_RowCol_t hist_diskreq[RF_MAXROW][RF_MAXCOL];
264 
265 	/* used by declustering */
266 	int     noRotate;
267 
268 #if RF_INCLUDE_PARITYLOGGING > 0
269 	/* used by parity logging */
270 	RF_SectorCount_t regionLogCapacity;
271 	RF_ParityLogQueue_t parityLogPool;	/* pool of unused parity logs */
272 	RF_RegionInfo_t *regionInfo;	/* array of region state */
273 	int     numParityLogs;
274 	int     numSectorsPerLog;
275 	int     regionParityRange;
276 	int     logsInUse;	/* debugging */
277 	RF_ParityLogDiskQueue_t parityLogDiskQueue;	/* state of parity
278 							 * logging disk work */
279 	RF_RegionBufferQueue_t regionBufferPool;	/* buffers for holding
280 							 * region log */
281 	RF_RegionBufferQueue_t parityBufferPool;	/* buffers for holding
282 							 * parity */
283 	caddr_t parityLogBufferHeap;	/* pool of unused parity logs */
284 	RF_Thread_t pLogDiskThreadHandle;
285 
286 #endif				/* RF_INCLUDE_PARITYLOGGING > 0 */
287 };
288 #endif				/* !_RF__RF_RAID_H_ */
289