case 500 + ALGORITHM_PARITY_0:
return block + 1;
-
case 600 + ALGORITHM_PARITY_N_6:
if (block == -2)
return raid_disks - 1;
return raid_disks - 1;
return block + 1;
-
case 600 + ALGORITHM_PARITY_0:
if (block == -1)
return 0;
if (block == -2) return (pd+1) % raid_disks;
return (pd + 2 + block) % raid_disks;
-
case 600 + ALGORITHM_ROTATING_N_RESTART:
/* Same a left_asymmetric, by first stripe is
* D D D P Q rather than
}
}
-
-static void xor_blocks(char *target, char **sources, int disks, int size)
+void xor_blocks(char *target, char **sources, int disks, int size)
{
int i, j;
/* Amazingly inefficient... */
}
}
-
/*
* The following was taken from linux/drivers/md/mktables.c, and modified
* to create in-memory tables rather than C code
uint8_t *zero;
int zero_size;
+
+void ensure_zero_has_size(int chunk_size)
+{
+ if (zero == NULL || chunk_size > zero_size) {
+ if (zero)
+ free(zero);
+ zero = xcalloc(1, chunk_size);
+ zero_size = chunk_size;
+ }
+}
+
/* Following was taken from linux/drivers/md/raid6recov.c */
/* Recover two failed data blocks. */
if((Px != 0) && (Qx == 0))
curr_broken_disk = diskP;
-
if((Px == 0) && (Qx != 0))
curr_broken_disk = diskQ;
-
if((Px != 0) && (Qx != 0)) {
data_id = (raid6_gflog[Qx] - raid6_gflog[Px]);
if(data_id < 0) data_id += 255;
if (!tables_ready)
make_tables();
-
- if (zero == NULL || chunk_size > zero_size) {
- if (zero)
- free(zero);
- zero = malloc(chunk_size);
- if (zero)
- memset(zero, 0, chunk_size);
- zero_size = chunk_size;
- }
+ ensure_zero_has_size(chunk_size);
len = data_disks * chunk_size;
length_test = length / len;
fdisk[0], fdisk[1], bufs);
}
}
- if (dest)
+ if (dest) {
for (i = 0; i < nwrites; i++)
if (write(dest[i], buf, len) != len)
return -1;
+ } else {
+ /* build next stripe in buffer */
+ buf += len;
+ }
length -= len;
start += len;
}
char *src_buf)
{
char *stripe_buf;
- char **stripes = malloc(raid_disks * sizeof(char*));
- char **blocks = malloc(raid_disks * sizeof(char*));
+ char **stripes = xmalloc(raid_disks * sizeof(char*));
+ char **blocks = xmalloc(raid_disks * sizeof(char*));
int i;
+ int rv;
int data_disks = raid_disks - (level == 0 ? 0 : level <= 5 ? 1 : 2);
if (zero == NULL || chunk_size > zero_size) {
if (zero)
free(zero);
- zero = malloc(chunk_size);
- if (zero)
- memset(zero, 0, chunk_size);
+ zero = xcalloc(1, chunk_size);
zero_size = chunk_size;
}
if (stripe_buf == NULL || stripes == NULL || blocks == NULL
|| zero == NULL) {
- free(stripe_buf);
- free(stripes);
- free(blocks);
- free(zero);
- return -2;
+ rv = -2;
+ goto abort;
}
for (i = 0; i < raid_disks; i++)
stripes[i] = stripe_buf + i * chunk_size;
unsigned long long offset;
int disk, qdisk;
int syndrome_disks;
- if (length < len)
- return -3;
+ if (length < len) {
+ rv = -3;
+ goto abort;
+ }
for (i = 0; i < data_disks; i++) {
int disk = geo_map(i, start/chunk_size/data_disks,
raid_disks, level, layout);
if (src_buf == NULL) {
/* read from file */
- if (lseek64(source,
- read_offset, 0) != (off64_t)read_offset)
- return -1;
+ if (lseek64(source, read_offset, 0) !=
+ (off64_t)read_offset) {
+ rv = -1;
+ goto abort;
+ }
if (read(source,
stripes[disk],
- chunk_size) != chunk_size)
- return -1;
+ chunk_size) != chunk_size) {
+ rv = -1;
+ goto abort;
+ }
} else {
/* read from input buffer */
memcpy(stripes[disk],
syndrome_disks = data_disks;
}
qsyndrome((uint8_t*)stripes[disk],
- (uint8_t*)stripes[qdisk],
+ (uint8_t*)stripes[qdisk],
(uint8_t**)blocks,
syndrome_disks, chunk_size);
break;
}
for (i=0; i < raid_disks ; i++)
if (dest[i] >= 0) {
- if (lseek64(dest[i], offsets[i]+offset, 0) < 0)
- return -1;
- if (write(dest[i], stripes[i], chunk_size) != chunk_size)
- return -1;
+ if (lseek64(dest[i],
+ offsets[i]+offset, 0) < 0) {
+ rv = -1;
+ goto abort;
+ }
+ if (write(dest[i], stripes[i],
+ chunk_size) != chunk_size) {
+ rv = -1;
+ goto abort;
+ }
}
length -= len;
start += len;
}
- return 0;
+ rv = 0;
+
+abort:
+ free(stripe_buf);
+ free(stripes);
+ free(blocks);
+ return rv;
}
#ifdef MAIN
unsigned long long start, unsigned long long length)
{
/* ready the data and p (and q) blocks, and check we got them right */
- char *stripe_buf = malloc(raid_disks * chunk_size);
- char **stripes = malloc(raid_disks * sizeof(char*));
- char **blocks = malloc(raid_disks * sizeof(char*));
- char *p = malloc(chunk_size);
- char *q = malloc(chunk_size);
+ char *stripe_buf = xmalloc(raid_disks * chunk_size);
+ char **stripes = xmalloc(raid_disks * sizeof(char*));
+ char **blocks = xmalloc(raid_disks * sizeof(char*));
+ char *p = xmalloc(chunk_size);
+ char *q = xmalloc(chunk_size);
int i;
int diskP, diskQ;
raid_disks, argc-9);
exit(2);
}
- fds = malloc(raid_disks * sizeof(*fds));
- offsets = malloc(raid_disks * sizeof(*offsets));
- memset(offsets, 0, raid_disks * sizeof(*offsets));
+ fds = xmalloc(raid_disks * sizeof(*fds));
+ offsets = xcalloc(raid_disks, sizeof(*offsets));
storefd = open(file, O_RDWR);
if (storefd < 0) {
*p++ = '\0';
offsets[i] = atoll(p) * 512;
}
-
+
fds[i] = open(argv[9+i], O_RDWR);
if (fds[i] < 0) {
perror(argv[9+i]);
}
}
- buf = malloc(raid_disks * chunk_size);
+ buf = xmalloc(raid_disks * chunk_size);
if (save == 1) {
int rv = save_stripes(fds, offsets,
int rv = restore_stripes(fds, offsets,
raid_disks, chunk_size, level, layout,
storefd, 0ULL,
- start, length);
+ start, length, NULL);
if (rv != 0) {
fprintf(stderr,
"test_stripe: restore_stripes returned %d\n",