This source file includes following definitions.
- rf_ConfigureDeclustered
- rf_ShutdownDeclusteredDS
- rf_ConfigureDeclusteredDS
- rf_MapSectorDeclustered
- rf_MapParityDeclustered
- rf_IdentifyStripeDeclustered
- rf_GetDefaultHeadSepLimitDeclustered
- rf_GetDefaultNumFloatingReconBuffersDeclustered
- rf_decluster_adjust_params
- rf_MapSIDToPSIDDeclustered
- rf_remap_to_spare_space
- rf_InstallSpareTable
- rf_SetSpareTable
- rf_GetNumSpareRUsDeclustered
- rf_FreeSpareTable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 #include "rf_types.h"
53 #include "rf_raid.h"
54 #include "rf_raidframe.h"
55 #include "rf_configure.h"
56 #include "rf_decluster.h"
57 #include "rf_debugMem.h"
58 #include "rf_utils.h"
59 #include "rf_alloclist.h"
60 #include "rf_general.h"
61 #include "rf_shutdown.h"
62
63 extern int rf_copyback_in_progress;
64
65
66 int rf_GetSpareTableFromDaemon(RF_SparetWait_t *);
67
68
69
70 int
71 rf_ConfigureDeclustered(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
72 RF_Config_t *cfgPtr)
73 {
74 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
75 int b, v, k, r, lambda;
76 int i, j;
77 RF_RowCol_t *first_avail_slot;
78 RF_StripeCount_t complete_FT_count, numCompleteFullTablesPerDisk;
79 RF_DeclusteredConfigInfo_t *info;
80 RF_StripeCount_t PUsPerDisk, spareRegionDepthInPUs,
81 numCompleteSpareRegionsPerDisk, extraPUsPerDisk;
82 RF_StripeCount_t totSparePUsPerDisk;
83 RF_SectorNum_t diskOffsetOfLastFullTableInSUs;
84 RF_SectorCount_t SpareSpaceInSUs;
85 char *cfgBuf = (char *) (cfgPtr->layoutSpecific);
86 RF_StripeNum_t l, SUID;
87
88 SUID = l = 0;
89 numCompleteSpareRegionsPerDisk = 0;
90
91
92 RF_MallocAndAdd(info, sizeof(RF_DeclusteredConfigInfo_t),
93 (RF_DeclusteredConfigInfo_t *), raidPtr->cleanupList);
94 if (info == NULL)
95 return (ENOMEM);
96 layoutPtr->layoutSpecificInfo = (void *) info;
97 info->SpareTable = NULL;
98
99
100 if (layoutPtr->map->flags & RF_DISTRIBUTE_SPARE) {
101 bcopy(cfgBuf, info->sparemap_fname, RF_SPAREMAP_NAME_LEN);
102 }
103 cfgBuf += RF_SPAREMAP_NAME_LEN;
104
105 b = *((int *) cfgBuf);
106 cfgBuf += sizeof(int);
107 v = *((int *) cfgBuf);
108 cfgBuf += sizeof(int);
109 k = *((int *) cfgBuf);
110 cfgBuf += sizeof(int);
111 r = *((int *) cfgBuf);
112 cfgBuf += sizeof(int);
113 lambda = *((int *) cfgBuf);
114 cfgBuf += sizeof(int);
115 raidPtr->noRotate = *((int *) cfgBuf);
116 cfgBuf += sizeof(int);
117
118
119
120
121
122
123 if ((layoutPtr->map->flags & RF_DISTRIBUTE_SPARE) &&
124 raidPtr->noRotate) {
125 RF_ERRORMSG("Warning: distributed sparing specified without"
126 " parity rotation.\n");
127 }
128 if (raidPtr->numCol != v) {
129 RF_ERRORMSG2("RAID: config error: table element count (%d)"
130 " not equal to no. of cols (%d).\n", v, raidPtr->numCol);
131 return (EINVAL);
132 }
133
134 info->BlocksPerTable = b;
135 info->Lambda = lambda;
136 info->NumParityReps = info->groupSize = k;
137
138 info->SUsPerTable = b * (k - 1) * layoutPtr->SUsPerPU;
139 info->SUsPerFullTable = k * info->SUsPerTable;
140 info->PUsPerBlock = k - 1;
141 info->SUsPerBlock = info->PUsPerBlock * layoutPtr->SUsPerPU;
142 info->TableDepthInPUs = (b * k) / v;
143
144 info->FullTableDepthInPUs = info->TableDepthInPUs * k;
145
146
147
148 info->FullTablesPerSpareRegion = (v - 1) / rf_gcd(r, v - 1);
149 info->TablesPerSpareRegion = k * info->FullTablesPerSpareRegion;
150 info->SpareSpaceDepthPerRegionInSUs = (r * info->TablesPerSpareRegion /
151 (v - 1)) * layoutPtr->SUsPerPU;
152
153
154 if ((raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE)) {
155 if (info->FullTableDepthInPUs * layoutPtr->SUsPerPU +
156 info->SpareSpaceDepthPerRegionInSUs >
157 layoutPtr->stripeUnitsPerDisk) {
158 RF_ERRORMSG3("RAID: config error: Full Table depth"
159 " (%d) + Spare Space (%d) larger than disk size"
160 " (%d) (BD too big).\n",
161 (int) info->FullTableDepthInPUs,
162 (int) info->SpareSpaceDepthPerRegionInSUs,
163 (int) layoutPtr->stripeUnitsPerDisk);
164 return (EINVAL);
165 }
166 } else {
167 if (info->TableDepthInPUs * layoutPtr->SUsPerPU >
168 layoutPtr->stripeUnitsPerDisk) {
169 RF_ERRORMSG2("RAID: config error: Table depth (%d)"
170 " larger than disk size (%d) (BD too big).\n",
171 (int) (info->TableDepthInPUs * layoutPtr->SUsPerPU),
172 (int) layoutPtr->stripeUnitsPerDisk);
173 return (EINVAL);
174 }
175 }
176
177
178
179
180
181
182 if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
183
184 PUsPerDisk = layoutPtr->stripeUnitsPerDisk /
185 layoutPtr->SUsPerPU;
186 spareRegionDepthInPUs =
187 (info->TablesPerSpareRegion * info->TableDepthInPUs +
188 (info->TablesPerSpareRegion * info->TableDepthInPUs) /
189 (v - 1));
190 info->SpareRegionDepthInSUs =
191 spareRegionDepthInPUs * layoutPtr->SUsPerPU;
192
193 numCompleteSpareRegionsPerDisk =
194 PUsPerDisk / spareRegionDepthInPUs;
195 info->NumCompleteSRs = numCompleteSpareRegionsPerDisk;
196 extraPUsPerDisk = PUsPerDisk % spareRegionDepthInPUs;
197
198
199
200
201
202
203
204
205 extraPUsPerDisk -= (info->SpareSpaceDepthPerRegionInSUs /
206 layoutPtr->SUsPerPU);
207 if (extraPUsPerDisk <= 0)
208 i = 0;
209 else
210 i = extraPUsPerDisk / info->TableDepthInPUs;
211
212 complete_FT_count = raidPtr->numRow *
213 (numCompleteSpareRegionsPerDisk *
214 (info->TablesPerSpareRegion / k) + i / k);
215 info->FullTableLimitSUID =
216 complete_FT_count * info->SUsPerFullTable;
217 info->ExtraTablesPerDisk = i % k;
218
219
220
221
222
223 totSparePUsPerDisk = (numCompleteSpareRegionsPerDisk + 1) *
224 (info->SpareSpaceDepthPerRegionInSUs / layoutPtr->SUsPerPU);
225 info->TotSparePUsPerDisk = totSparePUsPerDisk;
226
227 layoutPtr->stripeUnitsPerDisk =
228 ((complete_FT_count / raidPtr->numRow) *
229 info->FullTableDepthInPUs +
230 info->ExtraTablesPerDisk * info->TableDepthInPUs +
231 totSparePUsPerDisk
232 ) * layoutPtr->SUsPerPU;
233 layoutPtr->dataStripeUnitsPerDisk =
234 (complete_FT_count * info->FullTableDepthInPUs +
235 info->ExtraTablesPerDisk * info->TableDepthInPUs) *
236 layoutPtr->SUsPerPU * (k - 1) / k;
237
238 } else {
239
240
241
242
243 layoutPtr->stripeUnitsPerDisk /=
244 (info->TableDepthInPUs * layoutPtr->SUsPerPU);
245 layoutPtr->stripeUnitsPerDisk *=
246 (info->TableDepthInPUs * layoutPtr->SUsPerPU);
247
248
249
250
251
252 complete_FT_count =
253 ((layoutPtr->stripeUnitsPerDisk / layoutPtr->SUsPerPU) /
254 info->FullTableDepthInPUs) * raidPtr->numRow;
255
256 info->FullTableLimitSUID =
257 complete_FT_count * info->SUsPerFullTable;
258 info->ExtraTablesPerDisk =
259 ((layoutPtr->stripeUnitsPerDisk / layoutPtr->SUsPerPU) /
260 info->TableDepthInPUs) % k;
261 }
262
263 raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk *
264 layoutPtr->sectorsPerStripeUnit;
265
266
267
268
269
270 numCompleteFullTablesPerDisk = complete_FT_count / raidPtr->numRow;
271 diskOffsetOfLastFullTableInSUs = numCompleteFullTablesPerDisk *
272 info->FullTableDepthInPUs * layoutPtr->SUsPerPU;
273 if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
274 SpareSpaceInSUs = numCompleteSpareRegionsPerDisk *
275 info->SpareSpaceDepthPerRegionInSUs;
276 diskOffsetOfLastFullTableInSUs += SpareSpaceInSUs;
277 info->DiskOffsetOfLastSpareSpaceChunkInSUs =
278 diskOffsetOfLastFullTableInSUs + info->ExtraTablesPerDisk *
279 info->TableDepthInPUs * layoutPtr->SUsPerPU;
280 }
281 info->DiskOffsetOfLastFullTableInSUs = diskOffsetOfLastFullTableInSUs;
282 info->numCompleteFullTablesPerDisk = numCompleteFullTablesPerDisk;
283
284
285 info->LayoutTable = rf_make_2d_array(b, k, raidPtr->cleanupList);
286 if (info->LayoutTable == NULL)
287 return (ENOMEM);
288 info->OffsetTable = rf_make_2d_array(b, k, raidPtr->cleanupList);
289 if (info->OffsetTable == NULL)
290 return (ENOMEM);
291 info->BlockTable = rf_make_2d_array(info->TableDepthInPUs *
292 layoutPtr->SUsPerPU, raidPtr->numCol, raidPtr->cleanupList);
293 if (info->BlockTable == NULL)
294 return (ENOMEM);
295
296 first_avail_slot = rf_make_1d_array(v, NULL);
297 if (first_avail_slot == NULL)
298 return (ENOMEM);
299
300 for (i = 0; i < b; i++)
301 for (j = 0; j < k; j++)
302 info->LayoutTable[i][j] = *cfgBuf++;
303
304
305 for (i = 0; i < b; i++)
306 for (j = 0; j < k; j++) {
307 info->OffsetTable[i][j] =
308 first_avail_slot[info->LayoutTable[i][j]];
309 first_avail_slot[info->LayoutTable[i][j]]++;
310 }
311
312
313 for (SUID = l = 0; l < layoutPtr->SUsPerPU; l++) {
314 for (i = 0; i < b; i++) {
315 for (j = 0; j < k; j++) {
316 info->BlockTable[(info->OffsetTable[i][j] *
317 layoutPtr->SUsPerPU) + l]
318 [info->LayoutTable[i][j]] = SUID;
319 }
320 SUID++;
321 }
322 }
323
324 rf_free_1d_array(first_avail_slot, v);
325
326
327
328 raidPtr->totalSectors = (k * complete_FT_count + raidPtr->numRow *
329 info->ExtraTablesPerDisk) * info->SUsPerTable *
330 layoutPtr->sectorsPerStripeUnit;
331 layoutPtr->numStripe = (raidPtr->totalSectors /
332 layoutPtr->sectorsPerStripeUnit) / (k - 1);
333
334
335
336
337
338
339 layoutPtr->dataSectorsPerStripe =
340 (k - 1) * layoutPtr->sectorsPerStripeUnit;
341 layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit <<
342 raidPtr->logBytesPerSector;
343 layoutPtr->numDataCol = k - 1;
344 layoutPtr->numParityCol = 1;
345
346 return (0);
347 }
348
349
350 void rf_ShutdownDeclusteredDS(RF_ThreadArg_t);
351 void
352 rf_ShutdownDeclusteredDS(RF_ThreadArg_t arg)
353 {
354 RF_DeclusteredConfigInfo_t *info;
355 RF_Raid_t *raidPtr;
356
357 raidPtr = (RF_Raid_t *) arg;
358 info =
359 (RF_DeclusteredConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
360 if (info->SpareTable)
361 rf_FreeSpareTable(raidPtr);
362 }
363
364 int
365 rf_ConfigureDeclusteredDS(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
366 RF_Config_t *cfgPtr)
367 {
368 int rc;
369
370 rc = rf_ConfigureDeclustered(listp, raidPtr, cfgPtr);
371 if (rc)
372 return (rc);
373
374 rc = rf_ShutdownCreate(listp, rf_ShutdownDeclusteredDS, raidPtr);
375 if (rc) {
376 RF_ERRORMSG1("Got %d adding shutdown event for"
377 " DeclusteredDS.\n", rc);
378 rf_ShutdownDeclusteredDS(raidPtr);
379 return (rc);
380 }
381
382 return (0);
383 }
384
385 void
386 rf_MapSectorDeclustered(RF_Raid_t *raidPtr, RF_RaidAddr_t raidSector,
387 RF_RowCol_t *row, RF_RowCol_t *col, RF_SectorNum_t *diskSector, int remap)
388 {
389 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
390 RF_DeclusteredConfigInfo_t *info =
391 (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
392 RF_StripeNum_t SUID = raidSector / layoutPtr->sectorsPerStripeUnit;
393 RF_StripeNum_t FullTableID, FullTableOffset, TableID, TableOffset;
394 RF_StripeNum_t BlockID, BlockOffset, RepIndex;
395 RF_StripeCount_t sus_per_fulltable = info->SUsPerFullTable;
396 RF_StripeCount_t fulltable_depth =
397 info->FullTableDepthInPUs * layoutPtr->SUsPerPU;
398 RF_StripeNum_t base_suid = 0, outSU, SpareRegion = 0, SpareSpace = 0;
399
400 rf_decluster_adjust_params(layoutPtr, &SUID, &sus_per_fulltable,
401 &fulltable_depth, &base_suid);
402
403
404 FullTableID = SUID / sus_per_fulltable;
405 if (raidPtr->numRow == 1)
406 *row = 0;
407 else {
408 *row = FullTableID % raidPtr->numRow;
409
410 FullTableID /= raidPtr->numRow;
411 }
412 if (raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE) {
413 SpareRegion = FullTableID / info->FullTablesPerSpareRegion;
414 SpareSpace = SpareRegion * info->SpareSpaceDepthPerRegionInSUs;
415 }
416 FullTableOffset = SUID % sus_per_fulltable;
417 TableID = FullTableOffset / info->SUsPerTable;
418 TableOffset = FullTableOffset - TableID * info->SUsPerTable;
419 BlockID = TableOffset / info->PUsPerBlock;
420 BlockOffset = TableOffset - BlockID * info->PUsPerBlock;
421 BlockID %= info->BlocksPerTable;
422 RepIndex = info->PUsPerBlock - TableID;
423 if (!raidPtr->noRotate)
424 BlockOffset += ((BlockOffset >= RepIndex) ? 1 : 0);
425 *col = info->LayoutTable[BlockID][BlockOffset];
426
427
428 if (remap) {
429 RF_ASSERT(raidPtr->Disks[*row][*col].status ==
430 rf_ds_reconstructing ||
431 raidPtr->Disks[*row][*col].status == rf_ds_dist_spared ||
432 (rf_copyback_in_progress &&
433 raidPtr->Disks[*row][*col].status == rf_ds_optimal));
434 rf_remap_to_spare_space(layoutPtr, info, *row, FullTableID,
435 TableID, BlockID, (base_suid) ? 1 : 0, SpareRegion, col,
436 &outSU);
437 } else {
438
439 outSU = base_suid;
440 outSU += FullTableID * fulltable_depth;
441
442 outSU += SpareSpace;
443
444 outSU += TableID * info->TableDepthInPUs * layoutPtr->SUsPerPU;
445
446 outSU += info->OffsetTable[BlockID][BlockOffset] *
447 layoutPtr->SUsPerPU;
448
449 }
450 outSU += TableOffset / (info->BlocksPerTable * info->PUsPerBlock);
451
452
453
454
455
456
457 *diskSector = outSU * layoutPtr->sectorsPerStripeUnit +
458 (raidSector % layoutPtr->sectorsPerStripeUnit);
459
460 RF_ASSERT(*col != -1);
461 }
462
463
464
465
466
467 void
468 rf_MapParityDeclustered(RF_Raid_t *raidPtr, RF_RaidAddr_t raidSector,
469 RF_RowCol_t *row, RF_RowCol_t *col, RF_SectorNum_t *diskSector, int remap)
470 {
471 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
472 RF_DeclusteredConfigInfo_t *info =
473 (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
474 RF_StripeNum_t SUID = raidSector / layoutPtr->sectorsPerStripeUnit;
475 RF_StripeNum_t FullTableID, FullTableOffset, TableID, TableOffset;
476 RF_StripeNum_t BlockID, BlockOffset, RepIndex;
477 RF_StripeCount_t sus_per_fulltable = info->SUsPerFullTable;
478 RF_StripeCount_t fulltable_depth =
479 info->FullTableDepthInPUs * layoutPtr->SUsPerPU;
480 RF_StripeNum_t base_suid = 0, outSU, SpareRegion = 0, SpareSpace = 0;
481
482 rf_decluster_adjust_params(layoutPtr, &SUID, &sus_per_fulltable,
483 &fulltable_depth, &base_suid);
484
485
486 FullTableID = SUID / sus_per_fulltable;
487 if (raidPtr->numRow == 1)
488 *row = 0;
489 else {
490 *row = FullTableID % raidPtr->numRow;
491
492 FullTableID /= raidPtr->numRow;
493 }
494 if ((raidPtr->Layout.map->flags & RF_DISTRIBUTE_SPARE)) {
495 SpareRegion = FullTableID / info->FullTablesPerSpareRegion;
496 SpareSpace = SpareRegion * info->SpareSpaceDepthPerRegionInSUs;
497 }
498
499 FullTableOffset = SUID % sus_per_fulltable;
500 TableID = FullTableOffset / info->SUsPerTable;
501 TableOffset = FullTableOffset - TableID * info->SUsPerTable;
502
503
504
505 BlockID = TableOffset / info->PUsPerBlock;
506
507 BlockOffset = TableOffset - BlockID * info->PUsPerBlock;
508 BlockID %= info->BlocksPerTable;
509
510
511 RepIndex = (raidPtr->noRotate) ?
512 info->PUsPerBlock : info->PUsPerBlock - TableID;
513 *col = info->LayoutTable[BlockID][RepIndex];
514
515 if (remap) {
516 RF_ASSERT(raidPtr->Disks[*row][*col].status ==
517 rf_ds_reconstructing ||
518 raidPtr->Disks[*row][*col].status == rf_ds_dist_spared ||
519 (rf_copyback_in_progress &&
520 raidPtr->Disks[*row][*col].status == rf_ds_optimal));
521 rf_remap_to_spare_space(layoutPtr, info, *row, FullTableID,
522 TableID, BlockID, (base_suid) ? 1 : 0, SpareRegion, col,
523 &outSU);
524 } else {
525
526
527
528
529
530 outSU = base_suid;
531 outSU += FullTableID * fulltable_depth;
532 outSU += SpareSpace;
533 outSU += TableID * info->TableDepthInPUs * layoutPtr->SUsPerPU;
534 outSU += info->OffsetTable[BlockID][RepIndex] *
535 layoutPtr->SUsPerPU;
536 }
537
538 outSU += TableOffset / (info->BlocksPerTable * info->PUsPerBlock);
539 *diskSector = outSU * layoutPtr->sectorsPerStripeUnit +
540 (raidSector % layoutPtr->sectorsPerStripeUnit);
541
542 RF_ASSERT(*col != -1);
543 }
544
545
546
547
548
549
550 void
551 rf_IdentifyStripeDeclustered(RF_Raid_t *raidPtr, RF_RaidAddr_t addr,
552 RF_RowCol_t **diskids, RF_RowCol_t *outRow)
553 {
554 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
555 RF_DeclusteredConfigInfo_t *info =
556 (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
557 RF_StripeCount_t sus_per_fulltable = info->SUsPerFullTable;
558 RF_StripeCount_t fulltable_depth =
559 info->FullTableDepthInPUs * layoutPtr->SUsPerPU;
560 RF_StripeNum_t base_suid = 0;
561 RF_StripeNum_t SUID = rf_RaidAddressToStripeUnitID(layoutPtr, addr);
562 RF_StripeNum_t stripeID, FullTableID;
563 int tableOffset;
564
565 rf_decluster_adjust_params(layoutPtr, &SUID, &sus_per_fulltable,
566 &fulltable_depth, &base_suid);
567
568 FullTableID = SUID / sus_per_fulltable;
569 *outRow = FullTableID % raidPtr->numRow;
570
571 stripeID = rf_StripeUnitIDToStripeID(layoutPtr, SUID);
572
573 tableOffset = (stripeID % info->BlocksPerTable);
574 *diskids = info->LayoutTable[tableOffset];
575 }
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601 RF_HeadSepLimit_t
602 rf_GetDefaultHeadSepLimitDeclustered(RF_Raid_t *raidPtr)
603 {
604 RF_DeclusteredConfigInfo_t *info =
605 (RF_DeclusteredConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
606
607 return (info->Lambda * raidPtr->numFloatingReconBufs /
608 info->TableDepthInPUs / rf_numBufsToAccumulate);
609 }
610
611
612
613
614
615
616
617 int
618 rf_GetDefaultNumFloatingReconBuffersDeclustered(RF_Raid_t *raidPtr)
619 {
620 return (100 * rf_numBufsToAccumulate);
621 }
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640 void
641 rf_decluster_adjust_params(RF_RaidLayout_t *layoutPtr, RF_StripeNum_t *SUID,
642 RF_StripeCount_t *sus_per_fulltable, RF_StripeCount_t *fulltable_depth,
643 RF_StripeNum_t *base_suid)
644 {
645 RF_DeclusteredConfigInfo_t *info =
646 (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
647
648 if (*SUID >= info->FullTableLimitSUID) {
649
650 *sus_per_fulltable =
651 info->ExtraTablesPerDisk * info->SUsPerTable;
652
653
654 *fulltable_depth =
655 info->ExtraTablesPerDisk * info->TableDepthInPUs *
656 layoutPtr->SUsPerPU;
657
658
659 *base_suid = info->DiskOffsetOfLastFullTableInSUs;
660
661
662
663
664
665 *SUID -= info->FullTableLimitSUID;
666 }
667 }
668
669
670
671
672
673 void
674 rf_MapSIDToPSIDDeclustered(RF_RaidLayout_t *layoutPtr, RF_StripeNum_t stripeID,
675 RF_StripeNum_t *psID, RF_ReconUnitNum_t *which_ru)
676 {
677 RF_DeclusteredConfigInfo_t *info;
678
679 info = (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
680
681 *psID = (stripeID / (layoutPtr->SUsPerPU * info->BlocksPerTable)) *
682 info->BlocksPerTable + (stripeID % info->BlocksPerTable);
683 *which_ru = (stripeID % (info->BlocksPerTable * layoutPtr->SUsPerPU)) /
684 info->BlocksPerTable;
685 RF_ASSERT((*which_ru) < layoutPtr->SUsPerPU / layoutPtr->SUsPerRU);
686 }
687
688
689
690
691
692 void
693 rf_remap_to_spare_space(RF_RaidLayout_t *layoutPtr,
694 RF_DeclusteredConfigInfo_t *info, RF_RowCol_t row,
695 RF_StripeNum_t FullTableID, RF_StripeNum_t TableID, RF_SectorNum_t BlockID,
696 RF_StripeNum_t base_suid, RF_StripeNum_t SpareRegion, RF_RowCol_t *outCol,
697 RF_StripeNum_t *outSU)
698 {
699 RF_StripeNum_t ftID, spareTableStartSU, TableInSpareRegion,
700 lastSROffset, which_ft;
701
702
703
704
705
706
707 if (base_suid == 0) {
708 ftID = FullTableID;
709 } else {
710
711
712
713
714 lastSROffset = info->NumCompleteSRs *
715 info->SpareRegionDepthInSUs;
716 which_ft =
717 (info->DiskOffsetOfLastFullTableInSUs - lastSROffset) /
718 (info->FullTableDepthInPUs * layoutPtr->SUsPerPU);
719
720
721 ftID = info->DiskOffsetOfLastFullTableInSUs /
722 (info->FullTableDepthInPUs * layoutPtr->SUsPerPU) +
723 which_ft;
724 SpareRegion = info->NumCompleteSRs;
725 }
726 TableInSpareRegion = (ftID * info->NumParityReps + TableID) %
727 info->TablesPerSpareRegion;
728
729 *outCol = info->SpareTable[TableInSpareRegion][BlockID].spareDisk;
730 RF_ASSERT(*outCol != -1);
731
732 spareTableStartSU = (SpareRegion == info->NumCompleteSRs) ?
733 info->DiskOffsetOfLastFullTableInSUs + info->ExtraTablesPerDisk *
734 info->TableDepthInPUs * layoutPtr->SUsPerPU :
735 (SpareRegion + 1) * info->SpareRegionDepthInSUs -
736 info->SpareSpaceDepthPerRegionInSUs;
737 *outSU = spareTableStartSU +
738 info->SpareTable[TableInSpareRegion][BlockID].spareBlockOffsetInSUs;
739 if (*outSU >= layoutPtr->stripeUnitsPerDisk) {
740 printf("rf_remap_to_spare_space: invalid remapped disk SU"
741 " offset %ld.\n", (long) *outSU);
742 }
743 }
744
745 int
746 rf_InstallSpareTable(RF_Raid_t *raidPtr, RF_RowCol_t frow, RF_RowCol_t fcol)
747 {
748 RF_DeclusteredConfigInfo_t *info =
749 (RF_DeclusteredConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
750 RF_SparetWait_t *req;
751 int retcode;
752
753 RF_Malloc(req, sizeof(*req), (RF_SparetWait_t *));
754 req->C = raidPtr->numCol;
755 req->G = raidPtr->Layout.numDataCol + raidPtr->Layout.numParityCol;
756 req->fcol = fcol;
757 req->SUsPerPU = raidPtr->Layout.SUsPerPU;
758 req->TablesPerSpareRegion = info->TablesPerSpareRegion;
759 req->BlocksPerTable = info->BlocksPerTable;
760 req->TableDepthInPUs = info->TableDepthInPUs;
761 req->SpareSpaceDepthPerRegionInSUs =
762 info->SpareSpaceDepthPerRegionInSUs;
763
764 retcode = rf_GetSpareTableFromDaemon(req);
765 RF_ASSERT(!retcode);
766
767
768 return (retcode);
769 }
770
771
772
773
774 int
775 rf_SetSpareTable(RF_Raid_t *raidPtr, void *data)
776 {
777 RF_DeclusteredConfigInfo_t *info =
778 (RF_DeclusteredConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
779 RF_SpareTableEntry_t **ptrs;
780 int i, retcode;
781
782
783
784
785
786 RF_Malloc(ptrs, info->TablesPerSpareRegion *
787 sizeof(RF_SpareTableEntry_t *), (RF_SpareTableEntry_t **));
788 retcode = copyin((caddr_t) data, (caddr_t) ptrs,
789 info->TablesPerSpareRegion * sizeof(RF_SpareTableEntry_t *));
790
791 if (retcode)
792 return (retcode);
793
794
795 RF_Malloc(info->SpareTable, info->TablesPerSpareRegion *
796 sizeof(RF_SpareTableEntry_t *), (RF_SpareTableEntry_t **));
797
798
799
800
801 for (i = 0; i < info->TablesPerSpareRegion; i++) {
802 RF_Malloc(info->SpareTable[i], info->BlocksPerTable *
803 sizeof(RF_SpareTableEntry_t), (RF_SpareTableEntry_t *));
804 retcode = copyin(ptrs[i], info->SpareTable[i],
805 info->BlocksPerTable * sizeof(RF_SpareTableEntry_t));
806 if (retcode) {
807
808 info->SpareTable = NULL;
809 return (retcode);
810 }
811 }
812
813
814 RF_Free(ptrs, info->TablesPerSpareRegion *
815 sizeof(RF_SpareTableEntry_t *));
816
817 return (0);
818 }
819
820 RF_ReconUnitCount_t
821 rf_GetNumSpareRUsDeclustered(RF_Raid_t *raidPtr)
822 {
823 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
824
825 return (((RF_DeclusteredConfigInfo_t *)
826 layoutPtr->layoutSpecificInfo)->TotSparePUsPerDisk);
827 }
828
829
830 void
831 rf_FreeSpareTable(RF_Raid_t *raidPtr)
832 {
833 long i;
834 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
835 RF_DeclusteredConfigInfo_t *info =
836 (RF_DeclusteredConfigInfo_t *) layoutPtr->layoutSpecificInfo;
837 RF_SpareTableEntry_t **table = info->SpareTable;
838
839 for (i = 0; i < info->TablesPerSpareRegion; i++) {
840 RF_Free(table[i], info->BlocksPerTable *
841 sizeof(RF_SpareTableEntry_t));
842 }
843 RF_Free(table, info->TablesPerSpareRegion *
844 sizeof(RF_SpareTableEntry_t *));
845 info->SpareTable = (RF_SpareTableEntry_t **) NULL;
846 }