/*
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
};