xref: /netbsd-src/sys/dev/raidframe/rf_reconstruct.h (revision dc306354b0b29af51801a7632f1e95265a68cd81)
1 /*	$NetBSD: rf_reconstruct.h,v 1.1 1998/11/13 04:20:34 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_reconstruct.h -- header file for reconstruction code
31  *********************************************************/
32 
33 /* :
34  * Log: rf_reconstruct.h,v
35  * Revision 1.25  1996/08/01 15:57:24  jimz
36  * minor cleanup
37  *
38  * Revision 1.24  1996/07/22  19:52:16  jimz
39  * switched node params to RF_DagParam_t, a union of
40  * a 64-bit int and a void *, for better portability
41  * attempted hpux port, but failed partway through for
42  * lack of a single C compiler capable of compiling all
43  * source files
44  *
45  * Revision 1.23  1996/07/15  05:40:41  jimz
46  * some recon datastructure cleanup
47  * better handling of multiple failures
48  * added undocumented double-recon test
49  *
50  * Revision 1.22  1996/07/13  00:00:59  jimz
51  * sanitized generalized reconstruction architecture
52  * cleaned up head sep, rbuf problems
53  *
54  * Revision 1.21  1996/07/11  19:08:00  jimz
55  * generalize reconstruction mechanism
56  * allow raid1 reconstructs via copyback (done with array
57  * quiesced, not online, therefore not disk-directed)
58  *
59  * Revision 1.20  1996/06/11  10:57:30  jimz
60  * add rf_RegisterReconDoneProc
61  *
62  * Revision 1.19  1996/06/10  11:55:47  jimz
63  * Straightened out some per-array/not-per-array distinctions, fixed
64  * a couple bugs related to confusion. Added shutdown lists. Removed
65  * layout shutdown function (now subsumed by shutdown lists).
66  *
67  * Revision 1.18  1996/06/07  21:33:04  jimz
68  * begin using consistent types for sector numbers,
69  * stripe numbers, row+col numbers, recon unit numbers
70  *
71  * Revision 1.17  1996/06/05  18:06:02  jimz
72  * Major code cleanup. The Great Renaming is now done.
73  * Better modularity. Better typing. Fixed a bunch of
74  * synchronization bugs. Made a lot of global stuff
75  * per-desc or per-array. Removed dead code.
76  *
77  * Revision 1.16  1996/06/03  23:28:26  jimz
78  * more bugfixes
79  * check in tree to sync for IPDS runs with current bugfixes
80  * there still may be a problem with threads in the script test
81  * getting I/Os stuck- not trivially reproducible (runs ~50 times
82  * in a row without getting stuck)
83  *
84  * Revision 1.15  1996/06/02  17:31:48  jimz
85  * Moved a lot of global stuff into array structure, where it belongs.
86  * Fixed up paritylogging, pss modules in this manner. Some general
87  * code cleanup. Removed lots of dead code, some dead files.
88  *
89  * Revision 1.14  1996/05/31  22:26:54  jimz
90  * fix a lot of mapping problems, memory allocation problems
91  * found some weird lock issues, fixed 'em
92  * more code cleanup
93  *
94  * Revision 1.13  1996/05/30  11:29:41  jimz
95  * Numerous bug fixes. Stripe lock release code disagreed with the taking code
96  * about when stripes should be locked (I made it consistent: no parity, no lock)
97  * There was a lot of extra serialization of I/Os which I've removed- a lot of
98  * it was to calculate values for the cache code, which is no longer with us.
99  * More types, function, macro cleanup. Added code to properly quiesce the array
100  * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
101  * before. Fixed memory allocation, freeing bugs.
102  *
103  * Revision 1.12  1996/05/27  18:56:37  jimz
104  * more code cleanup
105  * better typing
106  * compiles in all 3 environments
107  *
108  * Revision 1.11  1996/05/23  21:46:35  jimz
109  * checkpoint in code cleanup (release prep)
110  * lots of types, function names have been fixed
111  *
112  * Revision 1.10  1996/05/18  19:51:34  jimz
113  * major code cleanup- fix syntax, make some types consistent,
114  * add prototypes, clean out dead code, et cetera
115  *
116  * Revision 1.9  1995/12/06  15:04:55  root
117  * added copyright info
118  *
119  */
120 
121 #ifndef _RF__RF_RECONSTRUCT_H_
122 #define _RF__RF_RECONSTRUCT_H_
123 
124 #include "rf_types.h"
125 #include <sys/time.h>
126 #include "rf_reconmap.h"
127 #include "rf_psstatus.h"
128 
129 /* reconstruction configuration information */
130 struct RF_ReconConfig_s {
131   unsigned           numFloatingReconBufs; /* number of floating recon bufs to use */
132   RF_HeadSepLimit_t  headSepLimit;         /* how far apart the heads are allow to become, in parity stripes */
133 };
134 
135 /* a reconstruction buffer */
136 struct RF_ReconBuffer_s {
137   RF_Raid_t        *raidPtr;          /* void * to avoid recursive includes */
138   caddr_t           buffer;           /* points to the data */
139   RF_StripeNum_t    parityStripeID;   /* the parity stripe that this data relates to */
140   int               which_ru;         /* which reconstruction unit within the PSS */
141   RF_SectorNum_t failedDiskSectorOffset;/* the offset into the failed disk */
142   RF_RowCol_t       row, col;         /* which disk this buffer belongs to or is targeted at */
143   RF_StripeCount_t  count;            /* counts the # of SUs installed so far */
144   int               priority;         /* used to force hi priority recon */
145   RF_RbufType_t     type;             /* FORCED or FLOATING */
146   char             *arrived;          /* [x] = 1/0 if SU from disk x has/hasn't arrived */
147   RF_ReconBuffer_t *next;             /* used for buffer management */
148   void             *arg;              /* generic field for general use */
149   RF_RowCol_t       spRow, spCol;     /* spare disk to which this buf should be written */
150                                       /* if dist sparing off, always identifies the replacement disk */
151   RF_SectorNum_t    spOffset;         /* offset into the spare disk */
152                                       /* if dist sparing off, identical to failedDiskSectorOffset */
153   RF_ReconParityStripeStatus_t *pssPtr; /* debug- pss associated with issue-pending write */
154 };
155 
156 /* a reconstruction event descriptor.  The event types currently are:
157  *    RF_REVENT_READDONE    -- a read operation has completed
158  *    RF_REVENT_WRITEDONE   -- a write operation has completed
159  *    RF_REVENT_BUFREADY    -- the buffer manager has produced a full buffer
160  *    RF_REVENT_BLOCKCLEAR  -- a reconstruction blockage has been cleared
161  *    RF_REVENT_BUFCLEAR    -- the buffer manager has released a process blocked on submission
162  *    RF_REVENT_SKIP        -- we need to skip the current RU and go on to the next one, typ. b/c we found recon forced
163  *    RF_REVENT_FORCEDREADONE- a forced-reconstructoin read operation has completed
164  */
165 typedef enum RF_Revent_e {
166 	RF_REVENT_READDONE,
167 	RF_REVENT_WRITEDONE,
168 	RF_REVENT_BUFREADY,
169 	RF_REVENT_BLOCKCLEAR,
170 	RF_REVENT_BUFCLEAR,
171 	RF_REVENT_HEADSEPCLEAR,
172 	RF_REVENT_SKIP,
173 	RF_REVENT_FORCEDREADDONE
174 } RF_Revent_t;
175 
176 struct RF_ReconEvent_s {
177   RF_Revent_t       type;  /* what kind of event has occurred */
178   RF_RowCol_t       col;   /* row ID is implicit in the queue in which the event is placed */
179   void             *arg;   /* a generic argument */
180   RF_ReconEvent_t  *next;
181 };
182 
183 /*
184  * Reconstruction control information maintained per-disk
185  * (for surviving disks)
186  */
187 struct RF_PerDiskReconCtrl_s {
188   RF_ReconCtrl_t     *reconCtrl;
189   RF_RowCol_t         row, col;              /* to make this structure self-identifying */
190   RF_StripeNum_t      curPSID;               /* the next parity stripe ID to check on this disk */
191   RF_HeadSepLimit_t   headSepCounter;        /* counter used to control maximum head separation */
192   RF_SectorNum_t      diskOffset;            /* the offset into the indicated disk of the current PU */
193   RF_ReconUnitNum_t   ru_count;              /* this counts off the recon units within each parity unit */
194   RF_ReconBuffer_t   *rbuf;                  /* the recon buffer assigned to this disk */
195 };
196 
197 /* main reconstruction control structure */
198 struct RF_ReconCtrl_s {
199   RF_RaidReconDesc_t    *reconDesc;
200   RF_RowCol_t            fcol;          /* which column has failed */
201   RF_PerDiskReconCtrl_t *perDiskInfo;   /* information maintained per-disk */
202   RF_ReconMap_t         *reconMap;      /* map of what has/has not been reconstructed */
203   RF_RowCol_t            spareRow;      /* which of the spare disks we're using */
204   RF_RowCol_t            spareCol;
205   RF_StripeNum_t         lastPSID;      /* the ID of the last parity stripe we want reconstructed */
206   int                    percentComplete; /* percentage completion of reconstruction */
207 
208   /* reconstruction event queue */
209   RF_ReconEvent_t  *eventQueue;    /* queue of pending reconstruction events */
210   RF_DECLARE_MUTEX(eq_mutex)       /* mutex for locking event queue */
211   RF_DECLARE_COND(eq_cond)         /* condition variable for signalling recon events */
212   int               eq_count;      /* debug only */
213 
214   /* reconstruction buffer management */
215   RF_DECLARE_MUTEX(rb_mutex)             /* mutex for messing around with recon buffers */
216   RF_ReconBuffer_t      *floatingRbufs;  /* available floating reconstruction buffers */
217   RF_ReconBuffer_t      *committedRbufs; /* recon buffers that have been committed to some waiting disk */
218   RF_ReconBuffer_t      *fullBufferList; /* full buffers waiting to be written out */
219   RF_ReconBuffer_t      *priorityList;   /* full buffers that have been elevated to higher priority */
220   RF_CallbackDesc_t     *bufferWaitList; /* disks that are currently blocked waiting for buffers */
221 
222   /* parity stripe status table */
223   RF_PSStatusHeader_t  *pssTable;  /* stores the reconstruction status of active parity stripes */
224 
225   /* maximum-head separation control */
226   RF_HeadSepLimit_t  minHeadSepCounter;  /* the minimum hs counter over all disks */
227   RF_CallbackDesc_t *headSepCBList;  /* list of callbacks to be done as minPSID advances */
228 
229   /* performance monitoring */
230   struct timeval    starttime;      /* recon start time */
231 
232   void (*continueFunc)(void *);     /* function to call when io returns*/
233   void *continueArg;                     /* argument for Func */
234 };
235 
236 /* the default priority for reconstruction accesses */
237 #define RF_IO_RECON_PRIORITY RF_IO_LOW_PRIORITY
238 
239 int rf_ConfigureReconstruction(RF_ShutdownList_t **listp);
240 
241 int rf_ReconstructFailedDisk(RF_Raid_t *raidPtr, RF_RowCol_t row,
242 	RF_RowCol_t col);
243 
244 int rf_ReconstructFailedDiskBasic(RF_Raid_t *raidPtr, RF_RowCol_t row,
245 	RF_RowCol_t col);
246 
247 int rf_ContinueReconstructFailedDisk(RF_RaidReconDesc_t *reconDesc);
248 
249 int rf_ForceOrBlockRecon(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
250 	void (*cbFunc)(RF_Raid_t *,void *), void *cbArg);
251 
252 int rf_UnblockRecon(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap);
253 
254 int rf_RegisterReconDoneProc(RF_Raid_t *raidPtr, void (*proc)(RF_Raid_t *, void *), void *arg,
255 	RF_ReconDoneProc_t **handlep);
256 
257 #endif /* !_RF__RF_RECONSTRUCT_H_ */
258