Home | History | Annotate | Line # | Download | only in raidframe
      1 /*	$NetBSD: rf_raid4.c,v 1.13 2019/02/09 03:34:00 christos Exp $	*/
      2 /*
      3  * Copyright (c) 1995 Carnegie-Mellon University.
      4  * All rights reserved.
      5  *
      6  * Author: Rachad Youssef
      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  *
     31  * rf_raid4.c -- implements RAID Level 4
     32  *
     33  ***************************************/
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: rf_raid4.c,v 1.13 2019/02/09 03:34:00 christos Exp $");
     37 
     38 #include "rf_raid.h"
     39 #include "rf_dag.h"
     40 #include "rf_dagutils.h"
     41 #include "rf_dagfuncs.h"
     42 #include "rf_dagffrd.h"
     43 #include "rf_dagffwr.h"
     44 #include "rf_dagdegrd.h"
     45 #include "rf_dagdegwr.h"
     46 #include "rf_raid4.h"
     47 #include "rf_general.h"
     48 
     49 typedef struct RF_Raid4ConfigInfo_s {
     50 	RF_RowCol_t *stripeIdentifier;	/* filled in at config time & used by
     51 					 * IdentifyStripe */
     52 }       RF_Raid4ConfigInfo_t;
     53 
     54 
     55 
     56 int
     57 rf_ConfigureRAID4(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
     58 		  RF_Config_t *cfgPtr)
     59 {
     60 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
     61 	RF_Raid4ConfigInfo_t *info;
     62 	int     i;
     63 
     64 	/* create a RAID level 4 configuration structure ... */
     65 	info = RF_MallocAndAdd(sizeof(*info), raidPtr->cleanupList);
     66 	if (info == NULL)
     67 		return (ENOMEM);
     68 	layoutPtr->layoutSpecificInfo = (void *) info;
     69 
     70 	/* ... and fill it in. */
     71 	info->stripeIdentifier = RF_MallocAndAdd(raidPtr->numCol *
     72 	    sizeof(*info->stripeIdentifier), raidPtr->cleanupList);
     73 	if (info->stripeIdentifier == NULL)
     74 		return (ENOMEM);
     75 	for (i = 0; i < raidPtr->numCol; i++)
     76 		info->stripeIdentifier[i] = i;
     77 
     78 	/* fill in the remaining layout parameters */
     79 	layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
     80 	layoutPtr->numDataCol = raidPtr->numCol - 1;
     81 	layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
     82 	layoutPtr->numParityCol = 1;
     83 	raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
     84 
     85 	return (0);
     86 }
     87 
     88 int
     89 rf_GetDefaultNumFloatingReconBuffersRAID4(RF_Raid_t *raidPtr)
     90 {
     91 	return (20);
     92 }
     93 
     94 RF_HeadSepLimit_t
     95 rf_GetDefaultHeadSepLimitRAID4(RF_Raid_t *raidPtr)
     96 {
     97 	return (20);
     98 }
     99 
    100 void
    101 rf_MapSectorRAID4(RF_Raid_t *raidPtr, RF_RaidAddr_t raidSector,
    102 		  RF_RowCol_t *col, RF_SectorNum_t *diskSector,
    103 		  int remap)
    104 {
    105 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    106 	*col = SUID % raidPtr->Layout.numDataCol;
    107 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    108 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    109 }
    110 
    111 void
    112 rf_MapParityRAID4(RF_Raid_t *raidPtr, RF_RaidAddr_t raidSector,
    113 		  RF_RowCol_t *col, RF_SectorNum_t *diskSector,
    114 		  int remap)
    115 {
    116 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
    117 
    118 	*col = raidPtr->Layout.numDataCol;
    119 	*diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
    120 	    (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
    121 }
    122 
    123 void
    124 rf_IdentifyStripeRAID4(RF_Raid_t *raidPtr, RF_RaidAddr_t addr,
    125 		       RF_RowCol_t **diskids)
    126 {
    127 	RF_Raid4ConfigInfo_t *info = raidPtr->Layout.layoutSpecificInfo;
    128 
    129 	*diskids = info->stripeIdentifier;
    130 }
    131 
    132 void
    133 rf_MapSIDToPSIDRAID4(RF_RaidLayout_t *layoutPtr,
    134 		     RF_StripeNum_t stripeID,
    135 		     RF_StripeNum_t *psID, RF_ReconUnitNum_t *which_ru)
    136 {
    137 	*which_ru = 0;
    138 	*psID = stripeID;
    139 }
    140