Menu

[b65d6a]: / mio_r5.c  Maximize  Restore  History

Download this file

708 lines (651 with data), 22.3 kB

  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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
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
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/*
Copyright (c) 2015, Sung Hoon Baek (shun.baek@gmail.com)
http://core.jwu.ac.kr/me
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Sung Hoon Baek nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL SUNG HOON BAEK BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* RAID Level 5 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/bio.h>
#include <linux/slab.h>
#include "lore.h"
//#include "lore_alloc.h"
#include "sc.h"
#include "mio.h"
#include "mio_page.h"
#if 0
#define ENTERING printk("Entering %s\n", __FUNCTION__)
#define LEAVING printk("Leaving %s\n", __FUNCTION__)
#else
#define ENTERING
#define LEAVING
#endif
#define PARITY_PAGE(mio, miou, pbg) ((miou)->mio_pages + (mio)->m*(mio)->D + pbg)
struct mio_r5_priv {
int physical_failed_disk;
struct semaphore scrub_mutex;
uint8_t *p_scrub_page;
};
static void mio_r5_cleanup(struct mio *mio)
{
struct mio_r5_priv *priv;
priv = (struct mio_r5_priv *)mio->raid_priv;
if (priv) {
free_page((unsigned long)priv->p_scrub_page);
vfree(priv);
}
mio->raid_priv = NULL;
}
static int mio_r5_init(struct mio *mio)
{
struct mio_r5_priv *priv;
mio->D = mio->N - 1;
mio->num_pages = mio->m * mio->N; /* data pages + parity pages */
mio->num_data_pages = mio->m * mio->D;
mio->raid_priv = (void *)vmalloc(sizeof(struct mio_r5_priv));
if (mio->raid_priv == NULL)
return -ENOMEM;
priv = (struct mio_r5_priv *)mio->raid_priv;
priv->physical_failed_disk = lore_get_failed_disk(mio->lore);
sema_init(&priv->scrub_mutex, 1);
priv->p_scrub_page = (uint8_t *)__get_free_page(GFP_KERNEL);
BUG_ON(priv->p_scrub_page == NULL);
BUG_ON(PAGE_SIZE != mio->page_size);
return 0;
}
/*
logical data placement: before rotating parity strips
0 1 2 3
S1 S2 S3 P
S4 S5 S6 P
S7 S8 S9 P
S10 S11 S12 P
S13 S14 S15 P
S?: strip
P: parity strip
the strip comprises contiguous blocks.
S1 & S2 & S3 & P consists of a stripe.
the strip is not the stripe.
physical data placement of RAID5: after rotating parity strips
0 1 2 3
S1 S2 S3 P
S4 S5 P S6
S7 P S8 S9
P S10 S11 S12
S13 S14 S15 P
*/
// the physical parity disk for (sc_pos, *)
#define mio_r5_parity_disk(mio, sc_pos) ((mio)->D - ((sc_pos) % (mio)->N))
// logical disk for (*, b_pos)
#define mio_r5_logical_data_disk(mio, b_pos) ((b_pos) / (mio)->m)
/* the physical data disk for (sc_pos, b_pos) */
static int mio_r5_physical_data_disk(struct mio *mio, stripe_t sc_pos, unsigned b_pos)
{
int l_disk = mio_r5_logical_data_disk(mio, b_pos);
if (l_disk >= mio_r5_parity_disk(mio, sc_pos) ) return l_disk+1;
return l_disk;
}
static int mio_r5_logical_data_disk_func(struct mio *mio, unsigned b_pos)
{
return mio_r5_logical_data_disk(mio, b_pos);
}
/* input: logical disk number with the LB position
* output: physical disk number */
static int mio_r5_logi2phys_disk(struct mio *mio, stripe_t sc_pos, int l_disk)
{
int parity_disk;
if (l_disk<0) return -1;
parity_disk = mio_r5_parity_disk(mio, sc_pos);
if (l_disk == mio->D) return parity_disk;
if (l_disk >= parity_disk) return l_disk+1;
return l_disk;
}
/* input: physical disk number with the LB position
* output: logical disk number */
static int mio_r5_phys2logi_disk(struct mio *mio, stripe_t sc_pos, int p_disk)
{
int parity_disk;
if (p_disk<0) return -1;
parity_disk = mio_r5_parity_disk(mio, sc_pos);
if (p_disk == parity_disk) return mio->D;
if (p_disk > parity_disk) return p_disk-1;
return p_disk;
}
/* sector offset of the parity for (sc_pos, 0) */
static sector_t mio_r5_get_parity_sector(struct mio *mio, stripe_t sc_pos)
{
sector_t s = sc_pos;
return (s*mio->m)<<mio->page_to_sector_shift;
}
/* return offset from the logical position (sc_pos, b_pos) in the disk */
static sector_t mio_r5_get_data_sector(struct mio *mio, stripe_t sc_pos, unsigned b_pos)
{
sector_t s = sc_pos;
return (s*mio->m + (b_pos%mio->m))<<mio->page_to_sector_shift;
}
static sector_t mio_r5_sector_offset(struct mio *mio, stripe_t sc_pos, unsigned b_pos)
{
if (b_pos >= mio->num_data_pages)
return mio_r5_get_parity_sector(mio, sc_pos);
else
return mio_r5_get_data_sector(mio, sc_pos, b_pos);
}
/* logical fault disk */
/* return: # of faulty disks that include bad blocks
it assign the faulty disk to the argument fail.
*/
static int mio_r5_l_failed_disk(struct mio *mio, stripe_t sc_pos, int *fail)
{
int num_faults=0;
struct mio_r5_priv *priv = (struct mio_r5_priv *)mio->raid_priv;
int fd = mio_r5_phys2logi_disk(mio, sc_pos, priv->physical_failed_disk);
if (fd>=0) num_faults=1;
/*
if (mio->bad_block_count>0)
for (i=0; i<mio->N; i++) {
if (fd == i) continue;
if (mio_find_bad_block(mio, i, sc_pos)) {
num_faults++;
if (fd<0) fd = i;
}
}
*/
*fail = fd;
return num_faults;
}
static int mio_r5_full_stripe_read_condition(struct mio *mio, stripe_t sc_pos)
{
int fd;
return mio_r5_l_failed_disk(mio, sc_pos, &fd);
}
static int mio_r5_rxw_matrix_for_write(struct mio_unit *miou)
{
struct sc *sc = miou->sc;
struct mio *mio = miou->mio;
int pbg,disk,pos;
uint8_t st;
int n_d, n_e;
uint8_t *data_rxw_matrix = miou->rxw_matrix;
uint8_t *parity_rxw_matrix = miou->rxw_matrix + mio->num_data_pages;
int l_parity_disk = mio->D;
int l_failed_disk;
int failed_disk_st;
int failed_disk_writable;
int num_faults;
memset(miou->rxw_matrix, 0, mio->num_pages*sizeof(uint8_t));
memset(miou->rxw_column, 0, mio->N*sizeof(uint8_t));
memset(miou->recov_op, 0, mio->m*sizeof(uint8_t));
num_faults = mio_r5_l_failed_disk(mio, sc->sc_pos, &l_failed_disk);
if (unlikely(num_faults>1)) return -1;
if (unlikely(num_faults>0))
failed_disk_writable = mio_writable_ldisk(mio, sc, l_failed_disk);
else
failed_disk_writable = 0;
for (pbg=0; pbg<mio->m; pbg++) {
n_d = n_e = 0;
failed_disk_st = -1;
for (disk=0, pos=pbg; disk<mio->D; disk++, pos+=mio->m) {
st = __sc_get_block_status(sc, pos);
if (st==B_EMPTY) n_e++;
else if (st==B_DIRTY) n_d++;
}
if (n_d == 0) continue; /* there is no dirty pages */
if (l_failed_disk>=0 && l_failed_disk<mio->D)
failed_disk_st = __sc_get_block_status(sc, l_failed_disk*mio->m + pbg);
/* read-modify-write is more beneficial than reconstruct-write or the faulty disk is empty */
if ((failed_disk_st!=B_DIRTY && l_failed_disk!=l_parity_disk && n_d+1 < n_e) || failed_disk_st==B_EMPTY) { //read-modify-write: new parity = old data ^ old parity ^ new data
parity_rxw_matrix[pbg] = MIO_RXW | MIO_XOR_DEST;
miou->rxw_column[l_parity_disk] |= MIO_RXW | MIO_XOR_DEST;
miou->recov_op[pbg] = MIO_RECOV_XOR;
for (disk=0, pos=pbg; disk<mio->D; disk++, pos+=mio->m) {
if (__sc_get_block_status(sc, pos)==B_DIRTY) {
data_rxw_matrix[pos] = MIO_TXXW;
miou->rxw_column[disk] |= MIO_TXXW;
}
}
} else { /* read to empty pages */
// here: the fault disk is parity, clean, or dirty
if (l_failed_disk==l_parity_disk && !failed_disk_writable) { /* parity fault */
for (disk=0, pos=pbg; disk<mio->D; disk++, pos+=mio->m) {
if ( __sc_get_block_status(sc, pos) == B_DIRTY ) {
data_rxw_matrix[pos] = MIO_WRITE;
miou->rxw_column[disk] |= MIO_WRITE;
}
}
} else {
/* here: no fault, or the fault page is not empty*/
/* reconstruct-write: read the empties and xor all the pages and then write the parity and the dirties */
miou->recov_op[pbg] = MIO_RECOV_XOR;
parity_rxw_matrix[pbg] = MIO_WRITE | MIO_XOR_DEST; // if parity disk failed, it is writable here
miou->rxw_column[l_parity_disk] |= MIO_WRITE | MIO_XOR_DEST;
for (disk=0, pos=pbg; disk<mio->D; disk++, pos+=mio->m) {
st = __sc_get_block_status(sc, pos);
if (l_failed_disk==disk) {
/* CLEAN or DIRTY because the fault disk is not empty here */
if (st==B_DIRTY && failed_disk_writable) data_rxw_matrix[pos] = MIO_XOR | MIO_WRITE;
else data_rxw_matrix[pos] = MIO_XOR;
} else {
if (st==B_DIRTY) data_rxw_matrix[pos] = MIO_XOR | MIO_WRITE;
else if (st==B_EMPTY) data_rxw_matrix[pos] = MIO_READ | MIO_XOR;
else data_rxw_matrix[pos] = MIO_XOR; /* CLEAN */
}
miou->rxw_column[disk] |= data_rxw_matrix[pos];
}
}
}
}
return 0;
}
/* read all empty pages */
static int mio_r5_rxw_matrix_for_full_read(struct mio_unit *miou)
{
struct sc *sc = miou->sc;
struct mio *mio = miou->mio;
int pbg,disk,pos;
uint8_t *data_rxw_matrix = miou->rxw_matrix;
uint8_t *parity_rxw_matrix = miou->rxw_matrix + mio->num_data_pages;
int l_parity_disk = mio->D;
int st;
int num_faults;
int l_failed_disk;
num_faults = mio_r5_l_failed_disk(miou->mio, miou->sc->sc_pos, &l_failed_disk);
if (unlikely(num_faults) > 1) return -1;
memset(miou->rxw_column, 0, mio->N*sizeof(uint8_t));
memset(miou->rxw_matrix, 0, mio->num_pages*sizeof(uint8_t));
memset(miou->recov_op, 0, mio->m*sizeof(uint8_t));
for (pbg=0; pbg<mio->m; pbg++) {
if (l_failed_disk >= 0 && l_failed_disk < l_parity_disk)
st = __sc_get_block_status(sc, mio->m*l_failed_disk+pbg);
else
st = -1;
if (st != B_EMPTY) {
for (disk=0, pos=pbg; disk<mio->D; disk++, pos+=mio->m) {
if ( __sc_get_block_status(sc, pos) == B_EMPTY ) {
data_rxw_matrix[pos] = MIO_READ;
miou->rxw_column[disk] |= MIO_READ;
}
}
} else {
// here, the parity is not faulty and the fault page is empty
parity_rxw_matrix[pbg] = MIO_READ | MIO_XOR;
miou->rxw_column[l_parity_disk] |= MIO_READ | MIO_XOR;
miou->recov_op[pbg] = MIO_RECOV_XOR;
for (disk=0, pos=pbg; disk<mio->D; disk++, pos+=mio->m) {
if (l_failed_disk != disk) {
st = __sc_get_block_status(sc, pos);
if (st == B_EMPTY)
data_rxw_matrix[pos] = MIO_READ | MIO_XOR;
else if (st == B_DIRTY)
data_rxw_matrix[pos] = MIO_TREAD | MIO_XOR;
else
data_rxw_matrix[pos] = MIO_XOR;
} else
data_rxw_matrix[pos] = MIO_XOR_DEST;
miou->rxw_column[disk] |= data_rxw_matrix[pos];
}
}
}
return 0;
}
// NOTICE: offsets from start to start+len-1 must belong to a single strip.
static int mio_r5_rxw_matrix_for_read(struct mio_unit *miou, unsigned start, unsigned len)
{
int end = start+len;
int pbg; //parity block group
int b_pos, i;
struct sc *sc = miou->sc;
struct mio *mio = miou->mio;
uint8_t *parity_rxw_matrix = miou->rxw_matrix + mio->num_data_pages;
uint8_t *data_rxw_matrix = miou->rxw_matrix;
int l_parity_disk = mio->D;
int data_ldisk;
int l_failed_disk;
int num_faults;
num_faults = mio_r5_l_failed_disk(mio, sc->sc_pos, &l_failed_disk);
if (unlikely(num_faults>1)) return -1;
memset(miou->rxw_matrix, 0, mio->num_pages*sizeof(uint8_t));
memset(miou->rxw_column, 0, mio->N*sizeof(uint8_t));
memset(miou->recov_op, 0, mio->m*sizeof(uint8_t));
data_ldisk = mio_r5_logical_data_disk(mio, start);
for (b_pos=start; b_pos<end; b_pos++) {
if (__sc_get_block_status(sc, b_pos) == B_EMPTY) {
if ( l_failed_disk != data_ldisk ) {
data_rxw_matrix[b_pos] = MIO_READ;
miou->rxw_column[data_ldisk] |= MIO_READ;
} else {
// TODO : this code will not be executed becuase full_read is used at the degraded mode.
pbg = b_pos % mio->m;
parity_rxw_matrix[pbg] = MIO_READ | MIO_XOR;
miou->rxw_column[l_parity_disk] |= MIO_READ | MIO_XOR;
miou->recov_op[pbg] = MIO_RECOV_XOR;
for (i=0; i<mio->D; pbg += mio->m, i++) {
if (l_failed_disk != i) {
if (__sc_get_block_status(sc, pbg) == B_EMPTY) {
data_rxw_matrix[pbg] = MIO_READ | MIO_XOR;
miou->rxw_column[i] |= MIO_READ | MIO_XOR;
}
else {
data_rxw_matrix[pbg] = MIO_XOR;
miou->rxw_column[i] |= MIO_XOR;
}
}
else {
data_rxw_matrix[pbg] = MIO_XOR_DEST;
miou->rxw_column[i] |= MIO_XOR_DEST;
}
}
}
}
}
return 0;
}
static int mio_r5_rxw_matrix_for_rebuild(struct mio_unit *miou)
{
struct sc *sc = miou->sc;
struct mio *mio = miou->mio;
struct lore *lore = mio->lore;
uint8_t *rxw_matrix = miou->rxw_matrix;
uint8_t *parity_rxw_matrix = miou->rxw_matrix + mio->num_data_pages;
int pbg,j,pos, disk;
int l_parity_disk = mio->D;
int l_failed_disk;
int st;
int bD;
mio_r5_l_failed_disk(mio, sc->sc_pos, &l_failed_disk);
if (l_failed_disk<0) return 0;
if (!mio_writable_ldisk(mio, sc, l_failed_disk)) {
if (!lore_spare_exist(lore))
return -1;
}
memset(rxw_matrix, 0, mio->num_pages*sizeof(uint8_t));
memset(miou->rxw_column, 0, mio->N*sizeof(uint8_t));
memset(miou->recov_op, 0, mio->m*sizeof(uint8_t));
if (l_failed_disk < 0) return 0;
for (pbg=0; pbg<mio->m; pbg++) {
if (l_failed_disk == l_parity_disk) {
miou->recov_op[pbg] = MIO_RECOV_XOR;
for (j=0, pos=pbg; j<mio->D; j++, pos+=mio->m) {
st = __sc_get_block_status(sc, pos);
if (st==B_EMPTY)
rxw_matrix[pos] = MIO_READ | MIO_XOR;
else if (st==B_DIRTY)
rxw_matrix[pos] = MIO_XOR | MIO_WRITE;
else
rxw_matrix[pos] = MIO_XOR;
miou->rxw_column[j] |= rxw_matrix[pos];
}
parity_rxw_matrix[pbg] = MIO_XOR_DEST | MIO_WRITE;
miou->rxw_column[l_parity_disk] = parity_rxw_matrix[pbg];
}
else {
st = __sc_get_block_status(sc, mio->m*l_failed_disk+pbg);
if (st==B_EMPTY) {
// the failed_disk is B_EMPTY
bD=0;
for (j=0, pos=pbg; j<mio->D; j++, pos+=mio->m) {
st = __sc_get_block_status(sc, pos);
if (st==B_DIRTY) bD=1;
if ( l_failed_disk==j )
rxw_matrix[pos] = MIO_XOR_DEST | MIO_WRITE;
else if (st==B_EMPTY)
rxw_matrix[pos] = MIO_READ | MIO_XOR;
else if (st==B_DIRTY)
rxw_matrix[pos] = MIO_TREAD | MIO_XOR | MIO_WRITE;
else
rxw_matrix[pos] = MIO_XOR;
miou->rxw_column[j] |= rxw_matrix[pos];
}
if (bD) {
parity_rxw_matrix[pbg] = MIO_READ | MIO_XOR | MIO_WRITE;
miou->recov_op[pbg] = MIO_RECOV_XOR | MIO_GEN_P;
} else {
parity_rxw_matrix[pbg] = MIO_READ | MIO_XOR;
miou->recov_op[pbg] = MIO_RECOV_XOR;
}
miou->rxw_column[l_parity_disk] = parity_rxw_matrix[pbg];
}
else {
// the l_failed_disk is B_CLEAN or B_DIRTY
bD = 0;
for (disk=0, pos=pbg; disk<mio->D; disk++, pos+=mio->m)
if (__sc_get_block_status(sc, pos)==B_DIRTY) { bD=1; break;}
if (bD==0) { // the block status of the failed disk must be B_CLEAN
rxw_matrix[mio->m*l_failed_disk + pbg] = MIO_WRITE;
miou->rxw_column[l_failed_disk] |= MIO_WRITE;
} else {
miou->recov_op[pbg] = MIO_RECOV_XOR;
for (j=0, pos=pbg; j<mio->D; j++, pos+=mio->m) {
st = __sc_get_block_status(sc, pos);
if ( l_failed_disk==j )
rxw_matrix[pos] = MIO_XOR | MIO_WRITE;
else if (st==B_EMPTY)
rxw_matrix[pos] = MIO_READ | MIO_XOR;
else if (st==B_DIRTY)
rxw_matrix[pos] = MIO_XOR | MIO_WRITE;
else
rxw_matrix[pos] = MIO_XOR;
miou->rxw_column[j] |= rxw_matrix[pos];
}
parity_rxw_matrix[pbg] = MIO_XOR_DEST | MIO_WRITE;
miou->rxw_column[l_parity_disk] = parity_rxw_matrix[pbg];
}
}
} // a data disk failure
}
return 0;
}
static int mio_r5_rxw_matrix_for_initialization(struct mio_unit *miou)
{
struct sc *sc = miou->sc;
struct mio *mio = miou->mio;
uint8_t *rxw_matrix = miou->rxw_matrix;
uint8_t *parity_rxw_matrix = miou->rxw_matrix + mio->num_data_pages;
int pbg,j,pos;
int l_parity_disk = mio->D;
int l_failed_disk;
mio_r5_l_failed_disk(mio, sc->sc_pos, &l_failed_disk);
if (l_failed_disk>=0) return -1;
memset(rxw_matrix, 0, mio->num_pages*sizeof(uint8_t));
memset(miou->rxw_column, 0, mio->N*sizeof(uint8_t));
memset(miou->recov_op, 0, mio->m*sizeof(uint8_t));
for (pbg=0; pbg<mio->m; pbg++) {
miou->recov_op[pbg] = MIO_RECOV_INIT;
for (j=0, pos=pbg; j<mio->D; j++, pos+=mio->m) {
rxw_matrix[pos] = MIO_READ | MIO_XOR;
miou->rxw_column[j] |= rxw_matrix[pos];
}
parity_rxw_matrix[pbg] = MIO_READ | MIO_XOR_DEST | MIO_WRITE;
miou->rxw_column[l_parity_disk] = parity_rxw_matrix[pbg];
}
return 0;
}
static int mio_r5_rxw_matrix_for_scrub(struct mio_unit *miou)
{
struct sc *sc = miou->sc;
struct mio *mio = miou->mio;
int pbg,disk,pos;
uint8_t *data_rxw_matrix = miou->rxw_matrix;
uint8_t *parity_rxw_matrix = miou->rxw_matrix + mio->num_data_pages;
int l_parity_disk = mio->D;
int st;
int num_faults;
int l_failed_disk;
ENTERING;
num_faults = mio_r5_l_failed_disk(mio, sc->sc_pos, &l_failed_disk);
if (unlikely(num_faults>0))
return -1;
memset(miou->rxw_column, 0, mio->N*sizeof(uint8_t));
memset(miou->rxw_matrix, 0, mio->num_pages*sizeof(uint8_t));
memset(miou->recov_op, 0, mio->m*sizeof(uint8_t));
for (pbg=0; pbg<mio->m; pbg++) {
parity_rxw_matrix[pbg] = MIO_READ;
miou->rxw_column[l_parity_disk] = MIO_READ;
miou->recov_op[pbg] = MIO_RECOV_SCRUB;
for (disk=0, pos=pbg; disk<mio->D; disk++, pos+=mio->m) {
st = __sc_get_block_status(sc, pos);
if (st == B_EMPTY)
data_rxw_matrix[pos] = MIO_READ | MIO_XOR;
else if (st == B_DIRTY)
data_rxw_matrix[pos] = MIO_TREAD | MIO_XOR;
else //B_CLEAN
data_rxw_matrix[pos] = MIO_XOR;
miou->rxw_column[disk] |= data_rxw_matrix[pos] | MIO_TEMP_PAGE;
}
}
LEAVING;
return 0;
}
static void mio_r5_check_raid_status(struct mio *mio)
{
int num_fd;
struct lore *lore;
struct mio_r5_priv *priv;
if (mio==NULL||mio->lore==NULL) return;
lore = mio->lore;
priv = (struct mio_r5_priv *)mio->raid_priv;
num_fd = lore_num_failed_disks(lore);
if (num_fd >= 2) {
lore->raid_status = LORE_DOWN;
}
if (num_fd == 1) {
lore->raid_status = LORE_DEGRADED;
priv->physical_failed_disk = lore_get_failed_disk(mio->lore);
}
if (num_fd == 0) {
lore->raid_status = LORE_OK;
priv->physical_failed_disk = -1;
}
}
static void mio_gen_parity(struct mio_unit *miou, int pbg)
{
struct mio_page *miop;
struct mio *mio = miou->mio;
uint8_t *xor_src[LORE_MAX_DISKS*2], *xor_dest;
int disk;
for (disk=0, miop=miou->mio_pages+pbg; disk<mio->D;
disk++, miop+=mio->m)
xor_src[disk] = miop->addr;
xor_dest = PARITY_PAGE(mio,miou, pbg)->addr;
do_xor(xor_dest, xor_src, mio->D, mio->page_size);
}
static void mio_gen_parity_for_scrub(struct mio_unit *miou, int pbg)
{
int disk;
struct mio_page *miop;
struct mio *mio = miou->mio;
uint8_t *xor_src[LORE_MAX_DISKS*2], *xor_dest;
uint8_t *data_rxw_matrix = miou->rxw_matrix;
struct mio_r5_priv *priv;
priv = (struct mio_r5_priv *)mio->raid_priv;
ENTERING;
for (disk=0, miop=miou->mio_pages+pbg; disk<mio->D;
disk++, miop+=mio->m) {
if (data_rxw_matrix[disk*mio->m + pbg] & MIO_TREAD) {
BUG_ON(miop->temp_page == NULL);
xor_src[disk] = miop->temp_page;
}
else {
if (miop->addr == NULL) {
printk(KERN_DEBUG "rxw: %d at %d,%d\n", data_rxw_matrix[disk*mio->m + pbg], disk,pbg);
printk(KERN_DEBUG "%p\n", miou->sc->strips[disk].page_pnts[pbg]);
printk(KERN_DEBUG "%d\n", __sc_get_block_status(miou->sc, disk*mio->m+pbg));
}
BUG_ON(miop->addr == NULL);
xor_src[disk] = miop->addr;
}
}
xor_dest = priv->p_scrub_page;
do_xor(xor_dest, xor_src, mio->D, mio->page_size);
LEAVING;
}
static void mio_r5_scrub(struct mio_unit *miou)
{
int pbg;
struct mio *mio = miou->mio;
struct mio_r5_priv *priv;
uint8_t *parity_page;
priv = (struct mio_r5_priv *)mio->raid_priv;
down(&priv->scrub_mutex); //mutex for p_scrub_page
for (pbg=0; pbg<mio->m; pbg++) {
mio_gen_parity_for_scrub(miou, pbg);
parity_page = PARITY_PAGE(mio,miou,pbg)->addr;
if (memcmp(parity_page, priv->p_scrub_page, mio->page_size) != 0) {
uint8_t *parity_rxw_matrix = miou->rxw_matrix + mio->num_data_pages;
printk(KERN_INFO "lore: found a parity-inconsistent stripe %llu.%d\n",
miou->sc->sc_pos, pbg);
memcpy(parity_page, priv->p_scrub_page, mio->page_size);
miou->rxw_column[mio->D] |= MIO_WRITE; //parity column
parity_rxw_matrix[pbg] |= MIO_WRITE;
}
}
up(&priv->scrub_mutex);
}
// if it return 1, miou has been finished, so skip mio_write_disks() but mio_end()
static int mio_r5_syndrome(struct mio_unit *miou)
{
int pbg;
struct mio *mio = miou->mio;
uint8_t recov_op = miou->recov_op[0];
ENTERING;
if ( unlikely(recov_op == MIO_RECOV_INIT) ) {
if (mio_is_zeros(miou))
return 1;
else {
for (pbg=0; pbg<mio->m; pbg++)
mio_gen_parity(miou,pbg);
return 0;
}
} else if ( unlikely(recov_op == MIO_RECOV_SCRUB) ) {
mio_r5_scrub(miou);
LEAVING;
return 0;
} else {
for (pbg=0; pbg<mio->m; pbg++) {
if ((miou->recov_op[pbg]&MIO_RECOV_MASK) == MIO_RECOV_XOR)
mio_xor_pbg(miou, pbg);
if (unlikely(miou->recov_op[pbg]&MIO_GEN_P))
mio_gen_parity(miou, pbg);
}
LEAVING;
return 0;
}
}
struct mio_raid mio_raid5 = {
LORE_RAID5,
1,
mio_r5_init,
mio_r5_cleanup,
mio_r5_logi2phys_disk,
mio_r5_physical_data_disk,
mio_r5_logical_data_disk_func,
mio_r5_sector_offset,
mio_r5_rxw_matrix_for_write,
mio_r5_rxw_matrix_for_read,
mio_r5_rxw_matrix_for_full_read,
mio_r5_rxw_matrix_for_rebuild,
mio_r5_rxw_matrix_for_initialization,
mio_r5_rxw_matrix_for_scrub,
mio_r5_check_raid_status,
mio_r5_syndrome,
mio_r5_full_stripe_read_condition
};