1 /* $NetBSD: rf_raid0.c,v 1.16 2019/02/09 03:34:00 christos 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 * 31 * rf_raid0.c -- implements RAID Level 0 32 * 33 ***************************************/ 34 35 #include <sys/cdefs.h> 36 __KERNEL_RCSID(0, "$NetBSD: rf_raid0.c,v 1.16 2019/02/09 03:34:00 christos Exp $"); 37 38 #include <dev/raidframe/raidframevar.h> 39 40 #include "rf_raid.h" 41 #include "rf_raid0.h" 42 #include "rf_dag.h" 43 #include "rf_dagffrd.h" 44 #include "rf_dagffwr.h" 45 #include "rf_dagutils.h" 46 #include "rf_dagfuncs.h" 47 #include "rf_general.h" 48 #include "rf_parityscan.h" 49 50 typedef struct RF_Raid0ConfigInfo_s { 51 RF_RowCol_t *stripeIdentifier; 52 } RF_Raid0ConfigInfo_t; 53 54 int 55 rf_ConfigureRAID0(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr, 56 RF_Config_t *cfgPtr) 57 { 58 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout; 59 RF_Raid0ConfigInfo_t *info; 60 RF_RowCol_t i; 61 62 /* create a RAID level 0 configuration structure */ 63 info = RF_MallocAndAdd(sizeof(*info), raidPtr->cleanupList); 64 if (info == NULL) 65 return (ENOMEM); 66 layoutPtr->layoutSpecificInfo = (void *) info; 67 68 info->stripeIdentifier = RF_MallocAndAdd(raidPtr->numCol 69 * sizeof(*info->stripeIdentifier), raidPtr->cleanupList); 70 if (info->stripeIdentifier == NULL) 71 return (ENOMEM); 72 for (i = 0; i < raidPtr->numCol; i++) 73 info->stripeIdentifier[i] = i; 74 75 raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * raidPtr->numCol * layoutPtr->sectorsPerStripeUnit; 76 layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk; 77 layoutPtr->dataSectorsPerStripe = raidPtr->numCol * layoutPtr->sectorsPerStripeUnit; 78 layoutPtr->numDataCol = raidPtr->numCol; 79 layoutPtr->numParityCol = 0; 80 return (0); 81 } 82 83 void 84 rf_MapSectorRAID0(RF_Raid_t *raidPtr, RF_RaidAddr_t raidSector, 85 RF_RowCol_t *col, RF_SectorNum_t *diskSector, int remap) 86 { 87 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit; 88 *col = SUID % raidPtr->numCol; 89 *diskSector = (SUID / raidPtr->numCol) * raidPtr->Layout.sectorsPerStripeUnit + 90 (raidSector % raidPtr->Layout.sectorsPerStripeUnit); 91 } 92 93 void 94 rf_MapParityRAID0(RF_Raid_t *raidPtr, 95 RF_RaidAddr_t raidSector, RF_RowCol_t *col, 96 RF_SectorNum_t *diskSector, int remap) 97 { 98 *col = 0; 99 *diskSector = 0; 100 } 101 102 void 103 rf_IdentifyStripeRAID0(RF_Raid_t *raidPtr, RF_RaidAddr_t addr, 104 RF_RowCol_t **diskids) 105 { 106 RF_Raid0ConfigInfo_t *info; 107 108 info = raidPtr->Layout.layoutSpecificInfo; 109 *diskids = info->stripeIdentifier; 110 } 111 112 void 113 rf_MapSIDToPSIDRAID0(RF_RaidLayout_t *layoutPtr, 114 RF_StripeNum_t stripeID, RF_StripeNum_t *psID, RF_ReconUnitNum_t *which_ru) 115 { 116 *which_ru = 0; 117 *psID = stripeID; 118 } 119 120 void 121 rf_RAID0DagSelect( 122 RF_Raid_t * raidPtr, 123 RF_IoType_t type, 124 RF_AccessStripeMap_t * asmap, 125 RF_VoidFuncPtr * createFunc) 126 { 127 if (raidPtr->numFailures > 0) { 128 *createFunc = NULL; 129 return; 130 } 131 *createFunc = ((type == RF_IO_TYPE_READ) ? 132 (RF_VoidFuncPtr) rf_CreateFaultFreeReadDAG : (RF_VoidFuncPtr) rf_CreateRAID0WriteDAG); 133 } 134 135 int 136 rf_VerifyParityRAID0(RF_Raid_t *raidPtr, 137 RF_RaidAddr_t raidAddr, RF_PhysDiskAddr_t *parityPDA, 138 int correct_it, RF_RaidAccessFlags_t flags) 139 { 140 /* 141 * No parity is always okay. 142 */ 143 return (RF_PARITY_OKAY); 144 } 145