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