Home | History | Annotate | Line # | Download | only in raidframe
rf_decluster.c revision 1.8.8.1
      1  1.8.8.1  gehenna /*	$NetBSD: rf_decluster.c,v 1.8.8.1 2002/05/30 14:47:01 gehenna 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  *
     31      1.1    oster  * rf_decluster.c -- code related to the declustered layout
     32      1.1    oster  *
     33      1.1    oster  * Created 10-21-92 (MCH)
     34      1.1    oster  *
     35      1.1    oster  * Nov 93:  adding support for distributed sparing.  This code is a little
     36      1.1    oster  *          complex:  the basic layout used is as follows:
     37      1.1    oster  *          let F = (v-1)/GCD(r,v-1).  The spare space for each set of
     38      1.1    oster  *          F consecutive fulltables is grouped together and placed after
     39      1.1    oster  *          that set of tables.
     40      1.1    oster  *                   +------------------------------+
     41      1.1    oster  *                   |        F fulltables          |
     42      1.1    oster  *                   |        Spare Space           |
     43      1.1    oster  *                   |        F fulltables          |
     44      1.1    oster  *                   |        Spare Space           |
     45      1.1    oster  *                   |            ...               |
     46      1.1    oster  *                   +------------------------------+
     47      1.1    oster  *
     48      1.1    oster  *--------------------------------------------------------------------*/
     49      1.8    lukem 
     50      1.8    lukem #include <sys/cdefs.h>
     51  1.8.8.1  gehenna __KERNEL_RCSID(0, "$NetBSD: rf_decluster.c,v 1.8.8.1 2002/05/30 14:47:01 gehenna Exp $");
     52      1.1    oster 
     53      1.7    oster #include <dev/raidframe/raidframevar.h>
     54      1.7    oster 
     55      1.6    oster #include "rf_archs.h"
     56      1.1    oster #include "rf_raid.h"
     57      1.1    oster #include "rf_decluster.h"
     58      1.1    oster #include "rf_debugMem.h"
     59      1.1    oster #include "rf_utils.h"
     60      1.1    oster #include "rf_alloclist.h"
     61      1.1    oster #include "rf_general.h"
     62      1.1    oster #include "rf_shutdown.h"
     63      1.1    oster 
     64      1.6    oster 
     65      1.3    oster extern int rf_copyback_in_progress;	/* debug only */
     66      1.1    oster 
     67      1.1    oster /* found in rf_kintf.c */
     68      1.3    oster int     rf_GetSpareTableFromDaemon(RF_SparetWait_t * req);
     69      1.1    oster 
     70      1.6    oster #if (RF_INCLUDE_PARITY_DECLUSTERING > 0) || (RF_INCLUDE_PARITY_DECLUSTERING_PQ > 0)
     71      1.6    oster 
     72      1.1    oster /* configuration code */
     73      1.1    oster 
     74      1.3    oster int
     75      1.3    oster rf_ConfigureDeclustered(
     76      1.3    oster     RF_ShutdownList_t ** listp,
     77      1.3    oster     RF_Raid_t * raidPtr,
     78      1.3    oster     RF_Config_t * cfgPtr)
     79      1.3    oster {
     80      1.3    oster 	RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
     81      1.3    oster 	int     b, v, k, r, lambda;	/* block design params */
     82      1.3    oster 	int     i, j;
     83      1.3    oster 	RF_RowCol_t *first_avail_slot;
     84      1.3    oster 	RF_StripeCount_t complete_FT_count, numCompleteFullTablesPerDisk;
     85      1.3    oster 	RF_DeclusteredConfigInfo_t *info;
     86      1.3    oster 	RF_StripeCount_t PUsPerDisk, spareRegionDepthInPUs, numCompleteSpareRegionsPerDisk,
     87      1.3    oster 	        extraPUsPerDisk;
     88      1.3    oster 	RF_StripeCount_t totSparePUsPerDisk;
     89      1.3    oster 	RF_SectorNum_t diskOffsetOfLastFullTableInSUs;
     90      1.3    oster 	RF_SectorCount_t SpareSpaceInSUs;
     91      1.3    oster 	char   *cfgBuf = (char *) (cfgPtr->layoutSpecific);
     92      1.3    oster 	RF_StripeNum_t l, SUID;
     93      1.3    oster 
     94      1.3    oster 	SUID = l = 0;
     95      1.3    oster 	numCompleteSpareRegionsPerDisk = 0;
     96      1.3    oster 
     97      1.3    oster 	/* 1. create layout specific structure */
     98      1.3    oster 	RF_MallocAndAdd(info, sizeof(RF_DeclusteredConfigInfo_t), (RF_DeclusteredConfigInfo_t *), raidPtr->cleanupList);
     99      1.3    oster 	if (info == NULL)
    100      1.3    oster 		return (ENOMEM);
    101      1.3    oster 	layoutPtr->layoutSpecificInfo = (void *) info;
    102      1.3    oster 	info->SpareTable = NULL;
    103      1.3    oster 
    104      1.3    oster 	/* 2. extract parameters from the config structure */
    105      1.3    oster 	if (layoutPtr->map->flags & RF_DISTRIBUTE_SPARE) {
    106  1.8.8.1  gehenna 		(void)memcpy(info->sparemap_fname, cfgBuf, RF_SPAREMAP_NAME_LEN);
    107      1.3    oster 	}
    108      1.3    oster 	cfgBuf += RF_SPAREMAP_NAME_LEN;
    109      1.3    oster 
    110      1.3    oster 	b = *((int *) cfgBuf);
    111      1.3    oster 	cfgBuf += sizeof(int);
    112      1.3    oster 	v = *((int *) cfgBuf);
    113      1.3    oster 	cfgBuf += sizeof(int);
    114      1.3    oster 	k = *((int *) cfgBuf);
    115      1.3    oster 	cfgBuf += sizeof(int);
    116      1.3    oster 	r = *((int *) cfgBuf);
    117      1.3    oster 	cfgBuf += sizeof(int);
    118      1.3    oster 	lambda = *((int *) cfgBuf);
    119      1.3    oster 	cfgBuf += sizeof(int);
    120      1.3    oster 	raidPtr->noRotate = *((int *) cfgBuf);
    121      1.3    oster 	cfgBuf += sizeof(int);
    122      1.3    oster 
    123      1.3    oster 	/* the sparemaps are generated assuming that parity is rotated, so we
    124      1.3    oster 	 * issue a warning if both distributed sparing and no-rotate are on at
    125      1.3    oster 	 * the same time */
    126      1.3    oster 	if ((layoutPtr->map->flags & RF_DISTRIBUTE_SPARE) && raidPtr->noRotate) {
    127      1.3    oster 		RF_ERRORMSG("Warning:  distributed sparing specified without parity rotation.\n");
    128      1.3    oster 	}
    129      1.3    oster 	if (raidPtr->numCol != v) {
    130      1.3    oster 		RF_ERRORMSG2("RAID: config error: table element count (%d) not equal to no. of cols (%d)\n", v, raidPtr->numCol);
    131      1.3    oster 		return (EINVAL);
    132      1.3    oster 	}
    133      1.3    oster 	/* 3.  set up the values used in the mapping code */
    134      1.3    oster 	info->BlocksPerTable = b;
    135      1.3    oster 	info->Lambda = lambda;
    136      1.3    oster 	info->NumParityReps = info->groupSize = k;
    137      1.3    oster 	info->SUsPerTable = b * (k - 1) * layoutPtr->SUsPerPU;	/* b blks, k-1 SUs each */
    138      1.3    oster 	info->SUsPerFullTable = k * info->SUsPerTable;	/* rot k times */
    139      1.3    oster 	info->PUsPerBlock = k - 1;
    140      1.3    oster 	info->SUsPerBlock = info->PUsPerBlock * layoutPtr->SUsPerPU;
    141      1.3    oster 	info->TableDepthInPUs = (b * k) / v;
    142      1.3    oster 	info->FullTableDepthInPUs = info->TableDepthInPUs * k;	/* k repetitions */
    143      1.3    oster 
    144      1.3    oster 	/* used only in distributed sparing case */
    145      1.3    oster 	info->FullTablesPerSpareRegion = (v - 1) / rf_gcd(r, v - 1);	/* (v-1)/gcd fulltables */
    146      1.3    oster 	info->TablesPerSpareRegion = k * info->FullTablesPerSpareRegion;
    147      1.3    oster 	info->SpareSpaceDepthPerRegionInSUs = (r * info->TablesPerSpareRegion / (v - 1)) * layoutPtr->SUsPerPU;
    148      1.3    oster 
    149      1.3    oster 	/* check to make sure the block design is sufficiently small */
    150      1.3    oster 	if ((raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE)) {
    151      1.3    oster 		if (info->FullTableDepthInPUs * layoutPtr->SUsPerPU + info->SpareSpaceDepthPerRegionInSUs > layoutPtr->stripeUnitsPerDisk) {
    152      1.3    oster 			RF_ERRORMSG3("RAID: config error: Full Table depth (%d) + Spare Space (%d) larger than disk size (%d) (BD too big)\n",
    153      1.3    oster 			    (int) info->FullTableDepthInPUs,
    154      1.3    oster 			    (int) info->SpareSpaceDepthPerRegionInSUs,
    155      1.3    oster 			    (int) layoutPtr->stripeUnitsPerDisk);
    156      1.3    oster 			return (EINVAL);
    157      1.3    oster 		}
    158      1.3    oster 	} else {
    159      1.3    oster 		if (info->TableDepthInPUs * layoutPtr->SUsPerPU > layoutPtr->stripeUnitsPerDisk) {
    160      1.3    oster 			RF_ERRORMSG2("RAID: config error: Table depth (%d) larger than disk size (%d) (BD too big)\n",
    161      1.3    oster 			    (int) (info->TableDepthInPUs * layoutPtr->SUsPerPU), \
    162      1.3    oster 			    (int) layoutPtr->stripeUnitsPerDisk);
    163      1.3    oster 			return (EINVAL);
    164      1.3    oster 		}
    165      1.3    oster 	}
    166      1.3    oster 
    167      1.3    oster 
    168      1.3    oster 	/* compute the size of each disk, and the number of tables in the last
    169      1.3    oster 	 * fulltable (which need not be complete) */
    170      1.3    oster 	if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
    171      1.3    oster 
    172      1.3    oster 		PUsPerDisk = layoutPtr->stripeUnitsPerDisk / layoutPtr->SUsPerPU;
    173      1.3    oster 		spareRegionDepthInPUs = (info->TablesPerSpareRegion * info->TableDepthInPUs +
    174      1.3    oster 		    (info->TablesPerSpareRegion * info->TableDepthInPUs) / (v - 1));
    175      1.3    oster 		info->SpareRegionDepthInSUs = spareRegionDepthInPUs * layoutPtr->SUsPerPU;
    176      1.3    oster 
    177      1.3    oster 		numCompleteSpareRegionsPerDisk = PUsPerDisk / spareRegionDepthInPUs;
    178      1.3    oster 		info->NumCompleteSRs = numCompleteSpareRegionsPerDisk;
    179      1.3    oster 		extraPUsPerDisk = PUsPerDisk % spareRegionDepthInPUs;
    180      1.3    oster 
    181      1.3    oster 		/* assume conservatively that we need the full amount of spare
    182      1.3    oster 		 * space in one region in order to provide spares for the
    183      1.3    oster 		 * partial spare region at the end of the array.  We set "i"
    184      1.3    oster 		 * to the number of tables in the partial spare region.  This
    185      1.3    oster 		 * may actually include some fulltables. */
    186      1.3    oster 		extraPUsPerDisk -= (info->SpareSpaceDepthPerRegionInSUs / layoutPtr->SUsPerPU);
    187      1.3    oster 		if (extraPUsPerDisk <= 0)
    188      1.3    oster 			i = 0;
    189      1.3    oster 		else
    190      1.3    oster 			i = extraPUsPerDisk / info->TableDepthInPUs;
    191      1.3    oster 
    192      1.3    oster 		complete_FT_count = raidPtr->numRow * (numCompleteSpareRegionsPerDisk * (info->TablesPerSpareRegion / k) + i / k);
    193      1.3    oster 		info->FullTableLimitSUID = complete_FT_count * info->SUsPerFullTable;
    194      1.3    oster 		info->ExtraTablesPerDisk = i % k;
    195      1.3    oster 
    196      1.3    oster 		/* note that in the last spare region, the spare space is
    197      1.3    oster 		 * complete even though data/parity space is not */
    198      1.3    oster 		totSparePUsPerDisk = (numCompleteSpareRegionsPerDisk + 1) * (info->SpareSpaceDepthPerRegionInSUs / layoutPtr->SUsPerPU);
    199      1.3    oster 		info->TotSparePUsPerDisk = totSparePUsPerDisk;
    200      1.3    oster 
    201      1.3    oster 		layoutPtr->stripeUnitsPerDisk =
    202      1.3    oster 		    ((complete_FT_count / raidPtr->numRow) * info->FullTableDepthInPUs +	/* data & parity space */
    203      1.3    oster 		    info->ExtraTablesPerDisk * info->TableDepthInPUs +
    204      1.3    oster 		    totSparePUsPerDisk	/* spare space */
    205      1.3    oster 		    ) * layoutPtr->SUsPerPU;
    206      1.3    oster 		layoutPtr->dataStripeUnitsPerDisk =
    207      1.3    oster 		    (complete_FT_count * info->FullTableDepthInPUs + info->ExtraTablesPerDisk * info->TableDepthInPUs)
    208      1.3    oster 		    * layoutPtr->SUsPerPU * (k - 1) / k;
    209      1.3    oster 
    210      1.3    oster 	} else {
    211      1.3    oster 		/* non-dist spare case:  force each disk to contain an
    212      1.3    oster 		 * integral number of tables */
    213      1.3    oster 		layoutPtr->stripeUnitsPerDisk /= (info->TableDepthInPUs * layoutPtr->SUsPerPU);
    214      1.3    oster 		layoutPtr->stripeUnitsPerDisk *= (info->TableDepthInPUs * layoutPtr->SUsPerPU);
    215      1.3    oster 
    216      1.3    oster 		/* compute the number of tables in the last fulltable, which
    217      1.3    oster 		 * need not be complete */
    218      1.3    oster 		complete_FT_count =
    219      1.3    oster 		    ((layoutPtr->stripeUnitsPerDisk / layoutPtr->SUsPerPU) / info->FullTableDepthInPUs) * raidPtr->numRow;
    220      1.3    oster 
    221      1.3    oster 		info->FullTableLimitSUID = complete_FT_count * info->SUsPerFullTable;
    222      1.3    oster 		info->ExtraTablesPerDisk =
    223      1.3    oster 		    ((layoutPtr->stripeUnitsPerDisk / layoutPtr->SUsPerPU) / info->TableDepthInPUs) % k;
    224      1.3    oster 	}
    225      1.3    oster 
    226      1.3    oster 	raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit;
    227      1.3    oster 
    228      1.3    oster 	/* find the disk offset of the stripe unit where the last fulltable
    229      1.3    oster 	 * starts */
    230      1.3    oster 	numCompleteFullTablesPerDisk = complete_FT_count / raidPtr->numRow;
    231      1.3    oster 	diskOffsetOfLastFullTableInSUs = numCompleteFullTablesPerDisk * info->FullTableDepthInPUs * layoutPtr->SUsPerPU;
    232      1.3    oster 	if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
    233      1.3    oster 		SpareSpaceInSUs = numCompleteSpareRegionsPerDisk * info->SpareSpaceDepthPerRegionInSUs;
    234      1.3    oster 		diskOffsetOfLastFullTableInSUs += SpareSpaceInSUs;
    235      1.3    oster 		info->DiskOffsetOfLastSpareSpaceChunkInSUs =
    236      1.3    oster 		    diskOffsetOfLastFullTableInSUs + info->ExtraTablesPerDisk * info->TableDepthInPUs * layoutPtr->SUsPerPU;
    237      1.3    oster 	}
    238      1.3    oster 	info->DiskOffsetOfLastFullTableInSUs = diskOffsetOfLastFullTableInSUs;
    239      1.3    oster 	info->numCompleteFullTablesPerDisk = numCompleteFullTablesPerDisk;
    240      1.3    oster 
    241      1.3    oster 	/* 4.  create and initialize the lookup tables */
    242      1.3    oster 	info->LayoutTable = rf_make_2d_array(b, k, raidPtr->cleanupList);
    243      1.3    oster 	if (info->LayoutTable == NULL)
    244      1.3    oster 		return (ENOMEM);
    245      1.3    oster 	info->OffsetTable = rf_make_2d_array(b, k, raidPtr->cleanupList);
    246      1.3    oster 	if (info->OffsetTable == NULL)
    247      1.3    oster 		return (ENOMEM);
    248      1.3    oster 	info->BlockTable = rf_make_2d_array(info->TableDepthInPUs * layoutPtr->SUsPerPU, raidPtr->numCol, raidPtr->cleanupList);
    249      1.3    oster 	if (info->BlockTable == NULL)
    250      1.3    oster 		return (ENOMEM);
    251      1.3    oster 
    252      1.3    oster 	first_avail_slot = rf_make_1d_array(v, NULL);
    253      1.3    oster 	if (first_avail_slot == NULL)
    254      1.3    oster 		return (ENOMEM);
    255      1.3    oster 
    256      1.3    oster 	for (i = 0; i < b; i++)
    257      1.3    oster 		for (j = 0; j < k; j++)
    258      1.3    oster 			info->LayoutTable[i][j] = *cfgBuf++;
    259      1.3    oster 
    260      1.3    oster 	/* initialize offset table */
    261      1.3    oster 	for (i = 0; i < b; i++)
    262      1.3    oster 		for (j = 0; j < k; j++) {
    263      1.3    oster 			info->OffsetTable[i][j] = first_avail_slot[info->LayoutTable[i][j]];
    264      1.3    oster 			first_avail_slot[info->LayoutTable[i][j]]++;
    265      1.3    oster 		}
    266      1.3    oster 
    267      1.3    oster 	/* initialize block table */
    268      1.3    oster 	for (SUID = l = 0; l < layoutPtr->SUsPerPU; l++) {
    269      1.3    oster 		for (i = 0; i < b; i++) {
    270      1.3    oster 			for (j = 0; j < k; j++) {
    271      1.3    oster 				info->BlockTable[(info->OffsetTable[i][j] * layoutPtr->SUsPerPU) + l]
    272      1.3    oster 				    [info->LayoutTable[i][j]] = SUID;
    273      1.3    oster 			}
    274      1.3    oster 			SUID++;
    275      1.3    oster 		}
    276      1.3    oster 	}
    277      1.1    oster 
    278      1.3    oster 	rf_free_1d_array(first_avail_slot, v);
    279      1.3    oster 
    280      1.3    oster 	/* 5.  set up the remaining redundant-but-useful parameters */
    281      1.3    oster 
    282      1.3    oster 	raidPtr->totalSectors = (k * complete_FT_count + raidPtr->numRow * info->ExtraTablesPerDisk) *
    283      1.3    oster 	    info->SUsPerTable * layoutPtr->sectorsPerStripeUnit;
    284      1.3    oster 	layoutPtr->numStripe = (raidPtr->totalSectors / layoutPtr->sectorsPerStripeUnit) / (k - 1);
    285      1.3    oster 
    286      1.3    oster 	/* strange evaluation order below to try and minimize overflow
    287      1.3    oster 	 * problems */
    288      1.3    oster 
    289      1.3    oster 	layoutPtr->dataSectorsPerStripe = (k - 1) * layoutPtr->sectorsPerStripeUnit;
    290      1.3    oster 	layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
    291      1.3    oster 	layoutPtr->numDataCol = k - 1;
    292      1.3    oster 	layoutPtr->numParityCol = 1;
    293      1.3    oster 
    294      1.3    oster 	return (0);
    295      1.1    oster }
    296      1.1    oster /* declustering with distributed sparing */
    297      1.1    oster static void rf_ShutdownDeclusteredDS(RF_ThreadArg_t);
    298      1.3    oster static void
    299      1.3    oster rf_ShutdownDeclusteredDS(arg)
    300      1.3    oster 	RF_ThreadArg_t arg;
    301      1.3    oster {
    302      1.3    oster 	RF_DeclusteredConfigInfo_t *info;
    303      1.3    oster 	RF_Raid_t *raidPtr;
    304      1.3    oster 
    305      1.3    oster 	raidPtr = (RF_Raid_t *) arg;
    306      1.3    oster 	info = (RF_DeclusteredConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    307      1.3    oster 	if (info->SpareTable)
    308      1.3    oster 		rf_FreeSpareTable(raidPtr);
    309      1.3    oster }
    310      1.3    oster 
    311      1.3    oster int
    312      1.3    oster rf_ConfigureDeclusteredDS(
    313      1.3    oster     RF_ShutdownList_t ** listp,
    314      1.3    oster     RF_Raid_t * raidPtr,
    315      1.3    oster     RF_Config_t * cfgPtr)
    316      1.3    oster {
    317      1.3    oster 	int     rc;
    318      1.3    oster 
    319      1.3    oster 	rc = rf_ConfigureDeclustered(listp, raidPtr, cfgPtr);
    320      1.3    oster 	if (rc)
    321      1.3    oster 		return (rc);
    322      1.3    oster 	rc = rf_ShutdownCreate(listp, rf_ShutdownDeclusteredDS, raidPtr);
    323      1.3    oster 	if (rc) {
    324      1.3    oster 		RF_ERRORMSG1("Got %d adding shutdown event for DeclusteredDS\n", rc);
    325      1.3    oster 		rf_ShutdownDeclusteredDS(raidPtr);
    326      1.3    oster 		return (rc);
    327      1.3    oster 	}
    328      1.3    oster 	return (0);
    329      1.3    oster }
    330      1.3    oster 
    331      1.3    oster void
    332      1.3    oster rf_MapSectorDeclustered(raidPtr, raidSector, row, col, diskSector, remap)
    333      1.3    oster 	RF_Raid_t *raidPtr;
    334      1.3    oster 	RF_RaidAddr_t raidSector;
    335      1.3    oster 	RF_RowCol_t *row;
    336      1.3    oster 	RF_RowCol_t *col;
    337      1.3    oster 	RF_SectorNum_t *diskSector;
    338      1.3    oster 	int     remap;
    339      1.3    oster {
    340      1.3    oster 	RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
    341      1.3    oster 	RF_DeclusteredConfigInfo_t *info = (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
    342      1.3    oster 	RF_StripeNum_t SUID = raidSector / layoutPtr->sectorsPerStripeUnit;
    343      1.3    oster 	RF_StripeNum_t FullTableID, FullTableOffset, TableID, TableOffset;
    344      1.3    oster 	RF_StripeNum_t BlockID, BlockOffset, RepIndex;
    345      1.3    oster 	RF_StripeCount_t sus_per_fulltable = info->SUsPerFullTable;
    346      1.3    oster 	RF_StripeCount_t fulltable_depth = info->FullTableDepthInPUs * layoutPtr->SUsPerPU;
    347      1.3    oster 	RF_StripeNum_t base_suid = 0, outSU, SpareRegion = 0, SpareSpace = 0;
    348      1.3    oster 
    349      1.3    oster 	rf_decluster_adjust_params(layoutPtr, &SUID, &sus_per_fulltable, &fulltable_depth, &base_suid);
    350      1.3    oster 
    351      1.3    oster 	FullTableID = SUID / sus_per_fulltable;	/* fulltable ID within array
    352      1.3    oster 						 * (across rows) */
    353      1.3    oster 	if (raidPtr->numRow == 1)
    354      1.3    oster 		*row = 0;	/* avoid a mod and a div in the common case */
    355      1.3    oster 	else {
    356      1.3    oster 		*row = FullTableID % raidPtr->numRow;
    357      1.3    oster 		FullTableID /= raidPtr->numRow;	/* convert to fulltable ID on
    358      1.3    oster 						 * this disk */
    359      1.3    oster 	}
    360      1.3    oster 	if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
    361      1.3    oster 		SpareRegion = FullTableID / info->FullTablesPerSpareRegion;
    362      1.3    oster 		SpareSpace = SpareRegion * info->SpareSpaceDepthPerRegionInSUs;
    363      1.3    oster 	}
    364      1.3    oster 	FullTableOffset = SUID % sus_per_fulltable;
    365      1.3    oster 	TableID = FullTableOffset / info->SUsPerTable;
    366      1.3    oster 	TableOffset = FullTableOffset - TableID * info->SUsPerTable;
    367      1.3    oster 	BlockID = TableOffset / info->PUsPerBlock;
    368      1.3    oster 	BlockOffset = TableOffset - BlockID * info->PUsPerBlock;
    369      1.3    oster 	BlockID %= info->BlocksPerTable;
    370      1.3    oster 	RepIndex = info->PUsPerBlock - TableID;
    371      1.3    oster 	if (!raidPtr->noRotate)
    372      1.3    oster 		BlockOffset += ((BlockOffset >= RepIndex) ? 1 : 0);
    373      1.3    oster 	*col = info->LayoutTable[BlockID][BlockOffset];
    374      1.3    oster 
    375      1.3    oster 	/* remap to distributed spare space if indicated */
    376      1.3    oster 	if (remap) {
    377      1.3    oster 		RF_ASSERT(raidPtr->Disks[*row][*col].status == rf_ds_reconstructing || raidPtr->Disks[*row][*col].status == rf_ds_dist_spared ||
    378      1.3    oster 		    (rf_copyback_in_progress && raidPtr->Disks[*row][*col].status == rf_ds_optimal));
    379      1.3    oster 		rf_remap_to_spare_space(layoutPtr, info, *row, FullTableID, TableID, BlockID, (base_suid) ? 1 : 0, SpareRegion, col, &outSU);
    380      1.3    oster 	} else {
    381      1.3    oster 
    382      1.3    oster 		outSU = base_suid;
    383      1.3    oster 		outSU += FullTableID * fulltable_depth;	/* offs to strt of FT */
    384      1.3    oster 		outSU += SpareSpace;	/* skip rsvd spare space */
    385      1.3    oster 		outSU += TableID * info->TableDepthInPUs * layoutPtr->SUsPerPU;	/* offs to strt of tble */
    386      1.3    oster 		outSU += info->OffsetTable[BlockID][BlockOffset] * layoutPtr->SUsPerPU;	/* offs to the PU */
    387      1.3    oster 	}
    388      1.3    oster 	outSU += TableOffset / (info->BlocksPerTable * info->PUsPerBlock);	/* offs to the SU within
    389      1.3    oster 										 * a PU */
    390      1.1    oster 
    391      1.3    oster 	/* convert SUs to sectors, and, if not aligned to SU boundary, add in
    392      1.3    oster 	 * offset to sector.  */
    393      1.3    oster 	*diskSector = outSU * layoutPtr->sectorsPerStripeUnit + (raidSector % layoutPtr->sectorsPerStripeUnit);
    394      1.1    oster 
    395      1.3    oster 	RF_ASSERT(*col != -1);
    396      1.1    oster }
    397      1.1    oster 
    398      1.1    oster 
    399      1.1    oster /* prototyping this inexplicably causes the compile of the layout table (rf_layout.c) to fail */
    400      1.3    oster void
    401      1.3    oster rf_MapParityDeclustered(
    402      1.3    oster     RF_Raid_t * raidPtr,
    403      1.3    oster     RF_RaidAddr_t raidSector,
    404      1.3    oster     RF_RowCol_t * row,
    405      1.3    oster     RF_RowCol_t * col,
    406      1.3    oster     RF_SectorNum_t * diskSector,
    407      1.3    oster     int remap)
    408      1.3    oster {
    409      1.3    oster 	RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
    410      1.3    oster 	RF_DeclusteredConfigInfo_t *info = (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
    411      1.3    oster 	RF_StripeNum_t SUID = raidSector / layoutPtr->sectorsPerStripeUnit;
    412      1.3    oster 	RF_StripeNum_t FullTableID, FullTableOffset, TableID, TableOffset;
    413      1.3    oster 	RF_StripeNum_t BlockID, BlockOffset, RepIndex;
    414      1.3    oster 	RF_StripeCount_t sus_per_fulltable = info->SUsPerFullTable;
    415      1.3    oster 	RF_StripeCount_t fulltable_depth = info->FullTableDepthInPUs * layoutPtr->SUsPerPU;
    416      1.3    oster 	RF_StripeNum_t base_suid = 0, outSU, SpareRegion = 0, SpareSpace = 0;
    417      1.3    oster 
    418      1.3    oster 	rf_decluster_adjust_params(layoutPtr, &SUID, &sus_per_fulltable, &fulltable_depth, &base_suid);
    419      1.3    oster 
    420      1.3    oster 	/* compute row & (possibly) spare space exactly as before */
    421      1.3    oster 	FullTableID = SUID / sus_per_fulltable;
    422      1.3    oster 	if (raidPtr->numRow == 1)
    423      1.3    oster 		*row = 0;	/* avoid a mod and a div in the common case */
    424      1.3    oster 	else {
    425      1.3    oster 		*row = FullTableID % raidPtr->numRow;
    426      1.3    oster 		FullTableID /= raidPtr->numRow;	/* convert to fulltable ID on
    427      1.3    oster 						 * this disk */
    428      1.3    oster 	}
    429      1.3    oster 	if ((raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE)) {
    430      1.3    oster 		SpareRegion = FullTableID / info->FullTablesPerSpareRegion;
    431      1.3    oster 		SpareSpace = SpareRegion * info->SpareSpaceDepthPerRegionInSUs;
    432      1.3    oster 	}
    433      1.3    oster 	/* compute BlockID and RepIndex exactly as before */
    434      1.3    oster 	FullTableOffset = SUID % sus_per_fulltable;
    435      1.3    oster 	TableID = FullTableOffset / info->SUsPerTable;
    436      1.3    oster 	TableOffset = FullTableOffset - TableID * info->SUsPerTable;
    437      1.3    oster 	/* TableOffset     = FullTableOffset % info->SUsPerTable; */
    438      1.3    oster 	/* BlockID         = (TableOffset / info->PUsPerBlock) %
    439      1.3    oster 	 * info->BlocksPerTable; */
    440      1.3    oster 	BlockID = TableOffset / info->PUsPerBlock;
    441      1.3    oster 	/* BlockOffset     = TableOffset % info->PUsPerBlock; */
    442      1.3    oster 	BlockOffset = TableOffset - BlockID * info->PUsPerBlock;
    443      1.3    oster 	BlockID %= info->BlocksPerTable;
    444      1.3    oster 
    445      1.3    oster 	/* the parity block is in the position indicated by RepIndex */
    446      1.3    oster 	RepIndex = (raidPtr->noRotate) ? info->PUsPerBlock : info->PUsPerBlock - TableID;
    447      1.3    oster 	*col = info->LayoutTable[BlockID][RepIndex];
    448      1.3    oster 
    449      1.3    oster 	if (remap) {
    450      1.3    oster 		RF_ASSERT(raidPtr->Disks[*row][*col].status == rf_ds_reconstructing || raidPtr->Disks[*row][*col].status == rf_ds_dist_spared ||
    451      1.3    oster 		    (rf_copyback_in_progress && raidPtr->Disks[*row][*col].status == rf_ds_optimal));
    452      1.3    oster 		rf_remap_to_spare_space(layoutPtr, info, *row, FullTableID, TableID, BlockID, (base_suid) ? 1 : 0, SpareRegion, col, &outSU);
    453      1.3    oster 	} else {
    454      1.3    oster 
    455      1.3    oster 		/* compute sector as before, except use RepIndex instead of
    456      1.3    oster 		 * BlockOffset */
    457      1.3    oster 		outSU = base_suid;
    458      1.3    oster 		outSU += FullTableID * fulltable_depth;
    459      1.3    oster 		outSU += SpareSpace;	/* skip rsvd spare space */
    460      1.3    oster 		outSU += TableID * info->TableDepthInPUs * layoutPtr->SUsPerPU;
    461      1.3    oster 		outSU += info->OffsetTable[BlockID][RepIndex] * layoutPtr->SUsPerPU;
    462      1.3    oster 	}
    463      1.3    oster 
    464      1.3    oster 	outSU += TableOffset / (info->BlocksPerTable * info->PUsPerBlock);
    465      1.3    oster 	*diskSector = outSU * layoutPtr->sectorsPerStripeUnit + (raidSector % layoutPtr->sectorsPerStripeUnit);
    466      1.3    oster 
    467      1.3    oster 	RF_ASSERT(*col != -1);
    468      1.1    oster }
    469      1.1    oster /* returns an array of ints identifying the disks that comprise the stripe containing the indicated address.
    470      1.1    oster  * the caller must _never_ attempt to modify this array.
    471      1.1    oster  */
    472      1.3    oster void
    473      1.3    oster rf_IdentifyStripeDeclustered(
    474      1.3    oster     RF_Raid_t * raidPtr,
    475      1.3    oster     RF_RaidAddr_t addr,
    476      1.3    oster     RF_RowCol_t ** diskids,
    477      1.3    oster     RF_RowCol_t * outRow)
    478      1.3    oster {
    479      1.3    oster 	RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
    480      1.3    oster 	RF_DeclusteredConfigInfo_t *info = (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
    481      1.3    oster 	RF_StripeCount_t sus_per_fulltable = info->SUsPerFullTable;
    482      1.3    oster 	RF_StripeCount_t fulltable_depth = info->FullTableDepthInPUs * layoutPtr->SUsPerPU;
    483      1.3    oster 	RF_StripeNum_t base_suid = 0;
    484      1.3    oster 	RF_StripeNum_t SUID = rf_RaidAddressToStripeUnitID(layoutPtr, addr);
    485      1.3    oster 	RF_StripeNum_t stripeID, FullTableID;
    486      1.3    oster 	int     tableOffset;
    487      1.3    oster 
    488      1.3    oster 	rf_decluster_adjust_params(layoutPtr, &SUID, &sus_per_fulltable, &fulltable_depth, &base_suid);
    489      1.3    oster 	FullTableID = SUID / sus_per_fulltable;	/* fulltable ID within array
    490      1.3    oster 						 * (across rows) */
    491      1.3    oster 	*outRow = FullTableID % raidPtr->numRow;
    492      1.3    oster 	stripeID = rf_StripeUnitIDToStripeID(layoutPtr, SUID);	/* find stripe offset
    493      1.3    oster 								 * into array */
    494      1.3    oster 	tableOffset = (stripeID % info->BlocksPerTable);	/* find offset into
    495      1.3    oster 								 * block design table */
    496      1.3    oster 	*diskids = info->LayoutTable[tableOffset];
    497      1.1    oster }
    498      1.1    oster /* This returns the default head-separation limit, which is measured
    499      1.1    oster  * in "required units for reconstruction".  Each time a disk fetches
    500      1.1    oster  * a unit, it bumps a counter.  The head-sep code prohibits any disk
    501      1.3    oster  * from getting more than headSepLimit counter values ahead of any
    502      1.1    oster  * other.
    503      1.1    oster  *
    504      1.1    oster  * We assume here that the number of floating recon buffers is already
    505      1.1    oster  * set.  There are r stripes to be reconstructed in each table, and so
    506      1.1    oster  * if we have a total of B buffers, we can have at most B/r tables
    507      1.1    oster  * under recon at any one time.  In each table, lambda units are required
    508      1.1    oster  * from each disk, so given B buffers, the head sep limit has to be
    509      1.1    oster  * (lambda*B)/r units.  We subtract one to avoid weird boundary cases.
    510      1.3    oster  *
    511      1.1    oster  * for example, suppose were given 50 buffers, r=19, and lambda=4 as in
    512      1.1    oster  * the 20.5 design.  There are 19 stripes/table to be reconstructed, so
    513      1.1    oster  * we can have 50/19 tables concurrently under reconstruction, which means
    514      1.1    oster  * we can allow the fastest disk to get 50/19 tables ahead of the slower
    515      1.1    oster  * disk.  There are lambda "required units" for each disk, so the fastest
    516      1.1    oster  * disk can get 4*50/19 = 10 counter values ahead of the slowest.
    517      1.1    oster  *
    518      1.1    oster  * If numBufsToAccumulate is not 1, we need to limit the head sep further
    519      1.1    oster  * because multiple bufs will be required for each stripe under recon.
    520      1.1    oster  */
    521      1.3    oster RF_HeadSepLimit_t
    522      1.3    oster rf_GetDefaultHeadSepLimitDeclustered(
    523      1.3    oster     RF_Raid_t * raidPtr)
    524      1.1    oster {
    525      1.3    oster 	RF_DeclusteredConfigInfo_t *info = (RF_DeclusteredConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    526      1.1    oster 
    527      1.3    oster 	return (info->Lambda * raidPtr->numFloatingReconBufs / info->TableDepthInPUs / rf_numBufsToAccumulate);
    528      1.1    oster }
    529      1.1    oster /* returns the default number of recon buffers to use.  The value
    530      1.1    oster  * is somewhat arbitrary...it's intended to be large enough to allow
    531      1.1    oster  * for a reasonably large head-sep limit, but small enough that you
    532      1.1    oster  * don't use up all your system memory with buffers.
    533      1.1    oster  */
    534      1.3    oster int
    535      1.3    oster rf_GetDefaultNumFloatingReconBuffersDeclustered(RF_Raid_t * raidPtr)
    536      1.1    oster {
    537      1.3    oster 	return (100 * rf_numBufsToAccumulate);
    538      1.1    oster }
    539      1.1    oster /* sectors in the last fulltable of the array need to be handled
    540      1.1    oster  * specially since this fulltable can be incomplete.  this function
    541      1.1    oster  * changes the values of certain params to handle this.
    542      1.1    oster  *
    543      1.1    oster  * the idea here is that MapSector et. al. figure out which disk the
    544      1.1    oster  * addressed unit lives on by computing the modulos of the unit number
    545      1.1    oster  * with the number of units per fulltable, table, etc.  In the last
    546      1.1    oster  * fulltable, there are fewer units per fulltable, so we need to adjust
    547      1.1    oster  * the number of user data units per fulltable to reflect this.
    548      1.1    oster  *
    549      1.1    oster  * so, we (1) convert the fulltable size and depth parameters to
    550      1.1    oster  * the size of the partial fulltable at the end, (2) compute the
    551      1.1    oster  * disk sector offset where this fulltable starts, and (3) convert
    552      1.1    oster  * the users stripe unit number from an offset into the array to
    553      1.1    oster  * an offset into the last fulltable.
    554      1.1    oster  */
    555      1.3    oster void
    556      1.3    oster rf_decluster_adjust_params(
    557      1.3    oster     RF_RaidLayout_t * layoutPtr,
    558      1.3    oster     RF_StripeNum_t * SUID,
    559      1.3    oster     RF_StripeCount_t * sus_per_fulltable,
    560      1.3    oster     RF_StripeCount_t * fulltable_depth,
    561      1.3    oster     RF_StripeNum_t * base_suid)
    562      1.1    oster {
    563      1.3    oster 	RF_DeclusteredConfigInfo_t *info = (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
    564      1.1    oster 
    565      1.3    oster 	if (*SUID >= info->FullTableLimitSUID) {
    566      1.3    oster 		/* new full table size is size of last full table on disk */
    567      1.3    oster 		*sus_per_fulltable = info->ExtraTablesPerDisk * info->SUsPerTable;
    568      1.3    oster 
    569      1.3    oster 		/* new full table depth is corresponding depth */
    570      1.3    oster 		*fulltable_depth = info->ExtraTablesPerDisk * info->TableDepthInPUs * layoutPtr->SUsPerPU;
    571      1.3    oster 
    572      1.3    oster 		/* set up the new base offset */
    573      1.3    oster 		*base_suid = info->DiskOffsetOfLastFullTableInSUs;
    574      1.3    oster 
    575      1.3    oster 		/* convert users array address to an offset into the last
    576      1.3    oster 		 * fulltable */
    577      1.3    oster 		*SUID -= info->FullTableLimitSUID;
    578      1.3    oster 	}
    579      1.1    oster }
    580      1.1    oster /*
    581      1.1    oster  * map a stripe ID to a parity stripe ID.
    582      1.1    oster  * See comment above RaidAddressToParityStripeID in layout.c.
    583      1.1    oster  */
    584      1.3    oster void
    585      1.3    oster rf_MapSIDToPSIDDeclustered(
    586      1.3    oster     RF_RaidLayout_t * layoutPtr,
    587      1.3    oster     RF_StripeNum_t stripeID,
    588      1.3    oster     RF_StripeNum_t * psID,
    589      1.3    oster     RF_ReconUnitNum_t * which_ru)
    590      1.3    oster {
    591      1.3    oster 	RF_DeclusteredConfigInfo_t *info;
    592      1.3    oster 
    593      1.3    oster 	info = (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
    594      1.3    oster 
    595      1.3    oster 	*psID = (stripeID / (layoutPtr->SUsPerPU * info->BlocksPerTable))
    596      1.3    oster 	    * info->BlocksPerTable + (stripeID % info->BlocksPerTable);
    597      1.3    oster 	*which_ru = (stripeID % (info->BlocksPerTable * layoutPtr->SUsPerPU))
    598      1.3    oster 	    / info->BlocksPerTable;
    599      1.3    oster 	RF_ASSERT((*which_ru) < layoutPtr->SUsPerPU / layoutPtr->SUsPerRU);
    600      1.1    oster }
    601      1.1    oster /*
    602      1.1    oster  * Called from MapSector and MapParity to retarget an access at the spare unit.
    603      1.1    oster  * Modifies the "col" and "outSU" parameters only.
    604      1.1    oster  */
    605      1.3    oster void
    606      1.3    oster rf_remap_to_spare_space(
    607      1.3    oster     RF_RaidLayout_t * layoutPtr,
    608      1.3    oster     RF_DeclusteredConfigInfo_t * info,
    609      1.3    oster     RF_RowCol_t row,
    610      1.3    oster     RF_StripeNum_t FullTableID,
    611      1.3    oster     RF_StripeNum_t TableID,
    612      1.3    oster     RF_SectorNum_t BlockID,
    613      1.3    oster     RF_StripeNum_t base_suid,
    614      1.3    oster     RF_StripeNum_t SpareRegion,
    615      1.3    oster     RF_RowCol_t * outCol,
    616      1.3    oster     RF_StripeNum_t * outSU)
    617      1.3    oster {
    618      1.3    oster 	RF_StripeNum_t ftID, spareTableStartSU, TableInSpareRegion, lastSROffset,
    619      1.3    oster 	        which_ft;
    620      1.3    oster 
    621      1.3    oster 	/*
    622      1.3    oster          * note that FullTableID and hence SpareRegion may have gotten
    623      1.3    oster          * tweaked by rf_decluster_adjust_params. We detect this by
    624      1.3    oster          * noticing that base_suid is not 0.
    625      1.3    oster          */
    626      1.3    oster 	if (base_suid == 0) {
    627      1.3    oster 		ftID = FullTableID;
    628      1.3    oster 	} else {
    629      1.3    oster 		/*
    630      1.3    oster 	         * There may be > 1.0 full tables in the last (i.e. partial)
    631      1.3    oster 	         * spare region.  find out which of these we're in.
    632      1.3    oster 	         */
    633      1.3    oster 		lastSROffset = info->NumCompleteSRs * info->SpareRegionDepthInSUs;
    634      1.3    oster 		which_ft = (info->DiskOffsetOfLastFullTableInSUs - lastSROffset) / (info->FullTableDepthInPUs * layoutPtr->SUsPerPU);
    635      1.3    oster 
    636      1.3    oster 		/* compute the actual full table ID */
    637      1.3    oster 		ftID = info->DiskOffsetOfLastFullTableInSUs / (info->FullTableDepthInPUs * layoutPtr->SUsPerPU) + which_ft;
    638      1.3    oster 		SpareRegion = info->NumCompleteSRs;
    639      1.3    oster 	}
    640      1.3    oster 	TableInSpareRegion = (ftID * info->NumParityReps + TableID) % info->TablesPerSpareRegion;
    641      1.3    oster 
    642      1.3    oster 	*outCol = info->SpareTable[TableInSpareRegion][BlockID].spareDisk;
    643      1.3    oster 	RF_ASSERT(*outCol != -1);
    644      1.3    oster 
    645      1.3    oster 	spareTableStartSU = (SpareRegion == info->NumCompleteSRs) ?
    646      1.1    oster 	    info->DiskOffsetOfLastFullTableInSUs + info->ExtraTablesPerDisk * info->TableDepthInPUs * layoutPtr->SUsPerPU :
    647      1.3    oster 	    (SpareRegion + 1) * info->SpareRegionDepthInSUs - info->SpareSpaceDepthPerRegionInSUs;
    648      1.3    oster 	*outSU = spareTableStartSU + info->SpareTable[TableInSpareRegion][BlockID].spareBlockOffsetInSUs;
    649      1.3    oster 	if (*outSU >= layoutPtr->stripeUnitsPerDisk) {
    650      1.3    oster 		printf("rf_remap_to_spare_space: invalid remapped disk SU offset %ld\n", (long) *outSU);
    651      1.3    oster 	}
    652      1.1    oster }
    653      1.1    oster 
    654      1.6    oster #endif /* (RF_INCLUDE_PARITY_DECLUSTERING > 0)  || (RF_INCLUDE_PARITY_DECLUSTERING_PQ > 0) */
    655      1.6    oster 
    656      1.6    oster 
    657      1.3    oster int
    658      1.3    oster rf_InstallSpareTable(
    659      1.3    oster     RF_Raid_t * raidPtr,
    660      1.3    oster     RF_RowCol_t frow,
    661      1.3    oster     RF_RowCol_t fcol)
    662      1.3    oster {
    663      1.3    oster 	RF_DeclusteredConfigInfo_t *info = (RF_DeclusteredConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    664      1.3    oster 	RF_SparetWait_t *req;
    665      1.3    oster 	int     retcode;
    666      1.3    oster 
    667      1.3    oster 	RF_Malloc(req, sizeof(*req), (RF_SparetWait_t *));
    668      1.3    oster 	req->C = raidPtr->numCol;
    669      1.3    oster 	req->G = raidPtr->Layout.numDataCol + raidPtr->Layout.numParityCol;
    670      1.3    oster 	req->fcol = fcol;
    671      1.3    oster 	req->SUsPerPU = raidPtr->Layout.SUsPerPU;
    672      1.3    oster 	req->TablesPerSpareRegion = info->TablesPerSpareRegion;
    673      1.3    oster 	req->BlocksPerTable = info->BlocksPerTable;
    674      1.3    oster 	req->TableDepthInPUs = info->TableDepthInPUs;
    675      1.3    oster 	req->SpareSpaceDepthPerRegionInSUs = info->SpareSpaceDepthPerRegionInSUs;
    676      1.3    oster 
    677      1.3    oster 	retcode = rf_GetSpareTableFromDaemon(req);
    678      1.3    oster 	RF_ASSERT(!retcode);	/* XXX -- fix this to recover gracefully --
    679      1.3    oster 				 * XXX */
    680      1.3    oster 	return (retcode);
    681      1.3    oster }
    682      1.1    oster /*
    683      1.1    oster  * Invoked via ioctl to install a spare table in the kernel.
    684      1.1    oster  */
    685      1.3    oster int
    686      1.3    oster rf_SetSpareTable(raidPtr, data)
    687      1.3    oster 	RF_Raid_t *raidPtr;
    688      1.3    oster 	void   *data;
    689      1.3    oster {
    690      1.3    oster 	RF_DeclusteredConfigInfo_t *info = (RF_DeclusteredConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
    691      1.3    oster 	RF_SpareTableEntry_t **ptrs;
    692      1.3    oster 	int     i, retcode;
    693      1.3    oster 
    694      1.3    oster 	/* what we need to copyin is a 2-d array, so first copyin the user
    695      1.3    oster 	 * pointers to the rows in the table */
    696      1.3    oster 	RF_Malloc(ptrs, info->TablesPerSpareRegion * sizeof(RF_SpareTableEntry_t *), (RF_SpareTableEntry_t **));
    697      1.3    oster 	retcode = copyin((caddr_t) data, (caddr_t) ptrs, info->TablesPerSpareRegion * sizeof(RF_SpareTableEntry_t *));
    698      1.3    oster 
    699      1.3    oster 	if (retcode)
    700      1.3    oster 		return (retcode);
    701      1.3    oster 
    702      1.3    oster 	/* now allocate kernel space for the row pointers */
    703      1.3    oster 	RF_Malloc(info->SpareTable, info->TablesPerSpareRegion * sizeof(RF_SpareTableEntry_t *), (RF_SpareTableEntry_t **));
    704      1.3    oster 
    705      1.3    oster 	/* now allocate kernel space for each row in the table, and copy it in
    706      1.3    oster 	 * from user space */
    707      1.3    oster 	for (i = 0; i < info->TablesPerSpareRegion; i++) {
    708      1.3    oster 		RF_Malloc(info->SpareTable[i], info->BlocksPerTable * sizeof(RF_SpareTableEntry_t), (RF_SpareTableEntry_t *));
    709      1.3    oster 		retcode = copyin(ptrs[i], info->SpareTable[i], info->BlocksPerTable * sizeof(RF_SpareTableEntry_t));
    710      1.3    oster 		if (retcode) {
    711      1.3    oster 			info->SpareTable = NULL;	/* blow off the memory
    712      1.3    oster 							 * we've allocated */
    713      1.3    oster 			return (retcode);
    714      1.3    oster 		}
    715      1.3    oster 	}
    716      1.1    oster 
    717      1.3    oster 	/* free up the temporary array we used */
    718      1.3    oster 	RF_Free(ptrs, info->TablesPerSpareRegion * sizeof(RF_SpareTableEntry_t *));
    719      1.1    oster 
    720      1.3    oster 	return (0);
    721      1.1    oster }
    722      1.1    oster 
    723      1.3    oster RF_ReconUnitCount_t
    724      1.3    oster rf_GetNumSpareRUsDeclustered(raidPtr)
    725      1.3    oster 	RF_Raid_t *raidPtr;
    726      1.1    oster {
    727      1.3    oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
    728      1.1    oster 
    729      1.3    oster 	return (((RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo)->TotSparePUsPerDisk);
    730      1.1    oster }
    731      1.1    oster 
    732      1.3    oster void
    733      1.3    oster rf_FreeSpareTable(raidPtr)
    734      1.3    oster 	RF_Raid_t *raidPtr;
    735      1.1    oster {
    736      1.3    oster 	long    i;
    737      1.3    oster 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
    738      1.3    oster 	RF_DeclusteredConfigInfo_t *info = (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
    739      1.3    oster 	RF_SpareTableEntry_t **table = info->SpareTable;
    740      1.1    oster 
    741      1.3    oster 	for (i = 0; i < info->TablesPerSpareRegion; i++) {
    742      1.3    oster 		RF_Free(table[i], info->BlocksPerTable * sizeof(RF_SpareTableEntry_t));
    743      1.3    oster 	}
    744      1.3    oster 	RF_Free(table, info->TablesPerSpareRegion * sizeof(RF_SpareTableEntry_t *));
    745      1.3    oster 	info->SpareTable = (RF_SpareTableEntry_t **) NULL;
    746      1.1    oster }
    747