1 1.53 oster /* $NetBSD: rf_raid.h,v 1.53 2023/09/25 21:59:38 oster Exp $ */ 2 1.1 oster /* 3 1.1 oster * Copyright (c) 1995 Carnegie-Mellon University. 4 1.1 oster * All rights reserved. 5 1.1 oster * 6 1.1 oster * Author: Mark Holland 7 1.1 oster * 8 1.1 oster * Permission to use, copy, modify and distribute this software and 9 1.1 oster * its documentation is hereby granted, provided that both the copyright 10 1.1 oster * notice and this permission notice appear in all copies of the 11 1.1 oster * software, derivative works or modified versions, and any portions 12 1.1 oster * thereof, and that both notices appear in supporting documentation. 13 1.1 oster * 14 1.1 oster * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 15 1.1 oster * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 16 1.1 oster * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 17 1.1 oster * 18 1.1 oster * Carnegie Mellon requests users of this software to return to 19 1.1 oster * 20 1.1 oster * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU 21 1.1 oster * School of Computer Science 22 1.1 oster * Carnegie Mellon University 23 1.1 oster * Pittsburgh PA 15213-3890 24 1.1 oster * 25 1.1 oster * any improvements or extensions that they make and grant Carnegie the 26 1.1 oster * rights to redistribute these changes. 27 1.1 oster */ 28 1.1 oster 29 1.1 oster /********************************************** 30 1.1 oster * rf_raid.h -- main header file for RAID driver 31 1.1 oster **********************************************/ 32 1.1 oster 33 1.1 oster 34 1.1 oster #ifndef _RF__RF_RAID_H_ 35 1.1 oster #define _RF__RF_RAID_H_ 36 1.1 oster 37 1.14 oster #include <dev/raidframe/raidframevar.h> 38 1.1 oster #include "rf_archs.h" 39 1.1 oster #include "rf_threadstuff.h" 40 1.1 oster 41 1.1 oster #include "rf_netbsd.h" 42 1.1 oster 43 1.1 oster #include <sys/disklabel.h> 44 1.1 oster #include <sys/types.h> 45 1.15 oster #include <sys/queue.h> 46 1.1 oster 47 1.1 oster #include "rf_alloclist.h" 48 1.1 oster #include "rf_stripelocks.h" 49 1.1 oster #include "rf_layout.h" 50 1.1 oster #include "rf_disks.h" 51 1.1 oster #include "rf_debugMem.h" 52 1.1 oster #include "rf_diskqueue.h" 53 1.1 oster #include "rf_reconstruct.h" 54 1.1 oster #include "rf_acctrace.h" 55 1.15 oster #include "rf_fifo.h" 56 1.1 oster 57 1.1 oster #if RF_INCLUDE_PARITYLOGGING > 0 58 1.1 oster #include "rf_paritylog.h" 59 1.3 oster #endif /* RF_INCLUDE_PARITYLOGGING > 0 */ 60 1.1 oster 61 1.9 oster #define RF_COMPONENT_LABEL_VERSION_1 1 62 1.9 oster #define RF_COMPONENT_LABEL_VERSION 2 63 1.4 oster #define RF_RAID_DIRTY 0 64 1.4 oster #define RF_RAID_CLEAN 1 65 1.4 oster 66 1.4 oster 67 1.1 oster /* 68 1.1 oster * Each row in the array is a distinct parity group, so 69 1.45 snj * each has its own status, which is one of the following. 70 1.1 oster */ 71 1.1 oster typedef enum RF_RowStatus_e { 72 1.3 oster rf_rs_optimal, 73 1.3 oster rf_rs_degraded, 74 1.3 oster rf_rs_reconstructing, 75 1.3 oster rf_rs_reconfigured 76 1.3 oster } RF_RowStatus_t; 77 1.1 oster 78 1.1 oster struct RF_CumulativeStats_s { 79 1.3 oster struct timeval start; /* the time when the stats were last started */ 80 1.3 oster struct timeval stop; /* the time when the stats were last stopped */ 81 1.3 oster long sum_io_us; /* sum of all user response times (us) */ 82 1.3 oster long num_ios; /* total number of I/Os serviced */ 83 1.3 oster long num_sect_moved; /* total number of sectors read or written */ 84 1.1 oster }; 85 1.1 oster 86 1.1 oster struct RF_ThroughputStats_s { 87 1.43 mrg rf_declare_mutex2(mutex);/* a mutex used to lock the configuration 88 1.3 oster * stuff */ 89 1.3 oster struct timeval start; /* timer started when numOutstandingRequests 90 1.3 oster * moves from 0 to 1 */ 91 1.3 oster struct timeval stop; /* timer stopped when numOutstandingRequests 92 1.3 oster * moves from 1 to 0 */ 93 1.3 oster RF_uint64 sum_io_us; /* total time timer is enabled */ 94 1.3 oster RF_uint64 num_ios; /* total number of ios processed by RAIDframe */ 95 1.3 oster long num_out_ios; /* number of outstanding ios */ 96 1.1 oster }; 97 1.1 oster 98 1.1 oster struct RF_Raid_s { 99 1.3 oster /* This portion never changes, and can be accessed without locking */ 100 1.3 oster /* an exception is Disks[][].status, which requires locking when it is 101 1.34 perry * changed. XXX this is no longer true. numSpare and friends can 102 1.34 perry * change now. 103 1.4 oster */ 104 1.3 oster u_int numCol; /* number of columns of disks, typically == # 105 1.3 oster * of disks/rank */ 106 1.3 oster u_int numSpare; /* number of spare disks */ 107 1.3 oster int maxQueueDepth; /* max disk queue depth */ 108 1.3 oster RF_SectorCount_t totalSectors; /* total number of sectors in the 109 1.3 oster * array */ 110 1.3 oster RF_SectorCount_t sectorsPerDisk; /* number of sectors on each 111 1.3 oster * disk */ 112 1.3 oster u_int logBytesPerSector; /* base-2 log of the number of bytes 113 1.3 oster * in a sector */ 114 1.3 oster u_int bytesPerSector; /* bytes in a sector */ 115 1.3 oster RF_int32 sectorMask; /* mask of bytes-per-sector */ 116 1.3 oster 117 1.3 oster RF_RaidLayout_t Layout; /* all information related to layout */ 118 1.19 oster RF_RaidDisk_t *Disks; /* all information related to physical disks */ 119 1.52 oster RF_DiskQueue_t *Queues; /* all information related to disk queues */ 120 1.52 oster u_int maxQueue; /* initialized queues in Queues array */ 121 1.18 jdolecek const RF_DiskQueueSW_t *qType;/* pointer to the DiskQueueSW used for the 122 1.28 oster component queues. */ 123 1.3 oster /* NOTE: This is an anchor point via which the queues can be 124 1.3 oster * accessed, but the enqueue/dequeue routines in diskqueue.c use a 125 1.3 oster * local copy of this pointer for the actual accesses. */ 126 1.3 oster /* The remainder of the structure can change, and therefore requires 127 1.3 oster * locking on reads and updates */ 128 1.43 mrg rf_declare_mutex2(mutex);/* mutex used to serialize access to 129 1.28 oster * the fields below */ 130 1.19 oster RF_RowStatus_t status; /* the status of each row in the array */ 131 1.3 oster int valid; /* indicates successful configuration */ 132 1.3 oster RF_LockTableEntry_t *lockTable; /* stripe-lock table */ 133 1.3 oster RF_LockTableEntry_t *quiesceLock; /* quiesnce table */ 134 1.3 oster int numFailures; /* total number of failures in the array */ 135 1.34 perry int numNewFailures; /* number of *new* failures (that havn't 136 1.11 oster caused a mod_counter update */ 137 1.5 oster 138 1.5 oster int parity_good; /* !0 if parity is known to be correct */ 139 1.5 oster int serial_number; /* a "serial number" for this set */ 140 1.5 oster int mod_counter; /* modification counter for component labels */ 141 1.38 jld int clean; /* completely unused and should be removed */ 142 1.6 oster 143 1.6 oster int openings; /* Number of IO's which can be scheduled 144 1.34 perry simultaneously (high-level - not a 145 1.6 oster per-component limit)*/ 146 1.10 oster 147 1.10 oster int maxOutstanding; /* maxOutstanding requests (per-component) */ 148 1.34 perry int autoconfigure; /* automatically configure this RAID set. 149 1.10 oster 0 == no, 1 == yes */ 150 1.10 oster int root_partition; /* Use this set as / 151 1.10 oster 0 == no, 1 == yes*/ 152 1.34 perry int last_unit; /* last unit number (e.g. 0 for /dev/raid0) 153 1.10 oster of this component. Used for autoconfigure 154 1.10 oster only. */ 155 1.10 oster int config_order; /* 0 .. n. The order in which the component 156 1.34 perry should be auto-configured. E.g. 0 is will 157 1.10 oster done first, (and would become raid0). 158 1.10 oster This may be in conflict with last_unit!!?! */ 159 1.10 oster /* Not currently used. */ 160 1.6 oster 161 1.15 oster /* queue to gather up requests from KernelWakeupFunc() and let 162 1.15 oster a kernel thread deal with calling rf_DiskIOComplete and any 163 1.15 oster callback functions. */ 164 1.34 perry TAILQ_HEAD(iodone_q,RF_DiskQueueData_s) iodone; 165 1.39 mrg /* and a lock/cv to protect it */ 166 1.40 mrg rf_declare_mutex2(iodone_lock); 167 1.40 mrg rf_declare_cond2(iodone_cv); 168 1.15 oster 169 1.32 oster 170 1.33 oster RF_VoidPointerListElem_t *iobuf; /* I/O buffer free list */ 171 1.32 oster int iobuf_count; /* count of I/O buffers on the freelist */ 172 1.32 oster int numEmergencyBuffers; /* number of these buffers to pre-allocate */ 173 1.33 oster 174 1.33 oster RF_VoidPointerListElem_t *stripebuf; /* Full-stripe buffer free list */ 175 1.33 oster int stripebuf_count; /* count of full-stripe buffers on the freelist */ 176 1.33 oster int numEmergencyStripeBuffers; /* number of these buffers to pre-allocate */ 177 1.33 oster 178 1.3 oster /* 179 1.3 oster * Cleanup stuff 180 1.3 oster */ 181 1.3 oster RF_ShutdownList_t *shutdownList; /* shutdown activities */ 182 1.3 oster RF_AllocListElem_t *cleanupList; /* memory to be freed at 183 1.3 oster * shutdown time */ 184 1.3 oster 185 1.3 oster /* 186 1.3 oster * Recon stuff 187 1.3 oster */ 188 1.3 oster RF_HeadSepLimit_t headSepLimit; 189 1.3 oster int numFloatingReconBufs; 190 1.3 oster int reconInProgress; 191 1.50 oster int forceRecon; 192 1.43 mrg rf_declare_cond2(waitForReconCond); /* goes with raidPtr->mutex */ 193 1.3 oster RF_RaidReconDesc_t *reconDesc; /* reconstruction descriptor */ 194 1.19 oster RF_ReconCtrl_t *reconControl; /* reconstruction control structure 195 1.3 oster * pointers for each row in the array */ 196 1.3 oster 197 1.3 oster /* 198 1.3 oster * Array-quiescence stuff 199 1.3 oster */ 200 1.42 mrg rf_declare_mutex2(access_suspend_mutex); 201 1.42 mrg rf_declare_cond2(access_suspend_cv); 202 1.3 oster RF_IoCount_t accesses_suspended; 203 1.3 oster RF_IoCount_t accs_in_flight; 204 1.3 oster int access_suspend_release; 205 1.3 oster int waiting_for_quiescence; 206 1.48 christos RF_CallbackFuncDesc_t *quiesce_wait_list; 207 1.3 oster 208 1.3 oster /* 209 1.3 oster * Statistics 210 1.3 oster */ 211 1.37 oster RF_StripeCount_t parity_rewrite_stripes_done; 212 1.8 oster 213 1.8 oster int recon_in_progress; 214 1.8 oster int parity_rewrite_in_progress; 215 1.52 oster int changing_components; 216 1.3 oster 217 1.46 mrg rf_declare_cond2(parity_rewrite_cv); 218 1.52 oster rf_declare_cond2(changing_components_cv); 219 1.43 mrg 220 1.3 oster /* 221 1.3 oster * Engine thread control 222 1.3 oster */ 223 1.40 mrg rf_declare_mutex2(node_queue_mutex); 224 1.40 mrg rf_declare_cond2(node_queue_cv); 225 1.3 oster RF_DagNode_t *node_queue; 226 1.8 oster RF_Thread_t parity_rewrite_thread; 227 1.3 oster RF_Thread_t engine_thread; 228 1.15 oster RF_Thread_t engine_helper_thread; 229 1.8 oster RF_Thread_t recon_thread; 230 1.3 oster int shutdown_engine; 231 1.15 oster int shutdown_raidio; 232 1.3 oster int dags_in_flight; /* debug */ 233 1.3 oster 234 1.3 oster /* 235 1.3 oster * PSS (Parity Stripe Status) stuff 236 1.3 oster */ 237 1.3 oster long pssTableSize; 238 1.3 oster 239 1.3 oster /* 240 1.3 oster * Reconstruction stuff 241 1.3 oster */ 242 1.3 oster int procsInBufWait; 243 1.3 oster int numFullReconBuffers; 244 1.26 oster #if RF_ACC_TRACE > 0 245 1.3 oster RF_AccTraceEntry_t *recon_tracerecs; 246 1.26 oster #endif 247 1.3 oster unsigned long accumXorTimeUs; 248 1.20 oster 249 1.3 oster /* 250 1.3 oster * nAccOutstanding, waitShutdown protected by desc freelist lock 251 1.3 oster * (This may seem strange, since that's a central serialization point 252 1.3 oster * for a per-array piece of data, but otherwise, it'd be an extra 253 1.3 oster * per-array lock, and that'd only be less efficient...) 254 1.3 oster */ 255 1.41 mrg rf_declare_mutex2(rad_lock); 256 1.41 mrg rf_declare_cond2(outstandingCond); 257 1.3 oster int waitShutdown; 258 1.3 oster int nAccOutstanding; 259 1.3 oster 260 1.52 oster int *abortRecon; /* Abort background operations requested */ 261 1.52 oster 262 1.3 oster RF_DiskId_t **diskids; 263 1.3 oster 264 1.3 oster int raidid; 265 1.44 christos void *softc; 266 1.3 oster RF_AccTotals_t acc_totals; 267 1.3 oster int keep_acc_totals; 268 1.3 oster 269 1.19 oster struct raidcinfo *raid_cinfo; /* array of component info */ 270 1.3 oster 271 1.3 oster int terminate_disk_queues; 272 1.3 oster 273 1.3 oster /* 274 1.3 oster * XXX 275 1.3 oster * 276 1.3 oster * config-specific information should be moved 277 1.3 oster * somewhere else, or at least hung off this 278 1.3 oster * in some generic way 279 1.3 oster */ 280 1.24 oster #if RF_INCLUDE_CHAINDECLUSTER > 0 281 1.1 oster 282 1.3 oster /* used by rf_compute_workload_shift */ 283 1.19 oster RF_RowCol_t hist_diskreq[RF_MAXCOL]; 284 1.24 oster #endif 285 1.3 oster /* used by declustering */ 286 1.3 oster int noRotate; 287 1.1 oster 288 1.1 oster #if RF_INCLUDE_PARITYLOGGING > 0 289 1.3 oster /* used by parity logging */ 290 1.3 oster RF_SectorCount_t regionLogCapacity; 291 1.3 oster RF_ParityLogQueue_t parityLogPool; /* pool of unused parity logs */ 292 1.3 oster RF_RegionInfo_t *regionInfo; /* array of region state */ 293 1.3 oster int numParityLogs; 294 1.3 oster int numSectorsPerLog; 295 1.3 oster int regionParityRange; 296 1.3 oster int logsInUse; /* debugging */ 297 1.3 oster RF_ParityLogDiskQueue_t parityLogDiskQueue; /* state of parity 298 1.3 oster * logging disk work */ 299 1.3 oster RF_RegionBufferQueue_t regionBufferPool; /* buffers for holding 300 1.3 oster * region log */ 301 1.3 oster RF_RegionBufferQueue_t parityBufferPool; /* buffers for holding 302 1.3 oster * parity */ 303 1.36 christos void *parityLogBufferHeap; /* pool of unused parity logs */ 304 1.3 oster RF_Thread_t pLogDiskThreadHandle; 305 1.1 oster 306 1.3 oster #endif /* RF_INCLUDE_PARITYLOGGING > 0 */ 307 1.38 jld struct rf_paritymap *parity_map; 308 1.49 oster struct RF_Pools_s pools; 309 1.49 oster struct RF_PoolNames_s poolNames; 310 1.1 oster }; 311 1.47 oster 312 1.47 oster struct raid_softc { 313 1.47 oster struct dk_softc sc_dksc; 314 1.47 oster int sc_unit; 315 1.47 oster int sc_flags; /* flags */ 316 1.47 oster int sc_cflags; /* configuration flags */ 317 1.47 oster kmutex_t sc_mutex; /* interlock mutex */ 318 1.47 oster kcondvar_t sc_cv; /* and the condvar */ 319 1.47 oster uint64_t sc_size; /* size of the raid device */ 320 1.47 oster char sc_xname[20]; /* XXX external name */ 321 1.47 oster RF_Raid_t sc_r; 322 1.47 oster LIST_ENTRY(raid_softc) sc_link; 323 1.47 oster }; 324 1.47 oster /* sc_flags */ 325 1.47 oster #define RAIDF_INITED 0x01 /* unit has been initialized */ 326 1.47 oster #define RAIDF_SHUTDOWN 0x02 /* unit is being shutdown */ 327 1.47 oster #define RAIDF_DETACH 0x04 /* detach after final close */ 328 1.47 oster #define RAIDF_WANTED 0x08 /* someone waiting to obtain a lock */ 329 1.47 oster #define RAIDF_LOCKED 0x10 /* unit is locked */ 330 1.47 oster #define RAIDF_UNIT_CHANGED 0x20 /* unit is being changed */ 331 1.47 oster 332 1.47 oster 333 1.47 oster int rf_fail_disk(RF_Raid_t *, struct rf_recon_req *); 334 1.47 oster 335 1.47 oster int rf_inited(const struct raid_softc *); 336 1.47 oster int rf_get_unit(const struct raid_softc *); 337 1.47 oster RF_Raid_t *rf_get_raid(struct raid_softc *); 338 1.47 oster int rf_construct(struct raid_softc *, RF_Config_t *); 339 1.47 oster 340 1.3 oster #endif /* !_RF__RF_RAID_H_ */ 341