raid6check: Check return value of lseek64()
If lseek64() failed it was still writing to the disks, which would introduce data corruption. Signed-off-by: Bernd Schubert <bernd.schubert@fastmail.fm> Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
parent
2c7b668df7
commit
2161adce8f
32
raid6check.c
32
raid6check.c
|
@ -185,11 +185,19 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets,
|
||||||
goto exitCheck;
|
goto exitCheck;
|
||||||
}
|
}
|
||||||
for (i = 0 ; i < raid_disks ; i++) {
|
for (i = 0 ; i < raid_disks ; i++) {
|
||||||
lseek64(source[i], offsets[i] + start * chunk_size, 0);
|
off64_t seek_res = lseek64(source[i], offsets[i] + start * chunk_size,
|
||||||
|
SEEK_SET);
|
||||||
|
if (seek_res < 0) {
|
||||||
|
fprintf(stderr, "lseek to source %d failed\n", i);
|
||||||
|
unlock_all_stripes(info, sig);
|
||||||
|
err = -1;
|
||||||
|
goto exitCheck;
|
||||||
|
}
|
||||||
int read_res = read(source[i], stripes[i], chunk_size);
|
int read_res = read(source[i], stripes[i], chunk_size);
|
||||||
if (read_res < chunk_size) {
|
if (read_res < chunk_size) {
|
||||||
fprintf(stderr, "Failed to read complete chunk disk %d, aborting\n", i);
|
fprintf(stderr, "Failed to read complete chunk disk %d, aborting\n", i);
|
||||||
unlock_all_stripes(info, sig);
|
unlock_all_stripes(info, sig);
|
||||||
|
err = -1;
|
||||||
goto exitCheck;
|
goto exitCheck;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,17 +296,33 @@ int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets,
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_res1, write_res2;
|
int write_res1, write_res2;
|
||||||
|
off64_t seek_res;
|
||||||
|
|
||||||
lseek64(source[failed_disk1], offsets[failed_disk1] + start * chunk_size, 0);
|
seek_res = lseek64(source[failed_disk1],
|
||||||
|
offsets[failed_disk1] + start * chunk_size, SEEK_SET);
|
||||||
|
if (seek_res < 0) {
|
||||||
|
fprintf(stderr, "lseek failed for failed_disk1\n");
|
||||||
|
unlock_all_stripes(info, sig);
|
||||||
|
err = -1;
|
||||||
|
goto exitCheck;
|
||||||
|
}
|
||||||
write_res1 = write(source[failed_disk1], stripes[failed_disk1], chunk_size);
|
write_res1 = write(source[failed_disk1], stripes[failed_disk1], chunk_size);
|
||||||
lseek64(source[failed_disk2], offsets[failed_disk2] + start * chunk_size, 0);
|
|
||||||
|
|
||||||
|
seek_res = lseek64(source[failed_disk2],
|
||||||
|
offsets[failed_disk2] + start * chunk_size, SEEK_SET);
|
||||||
|
if (seek_res < 0) {
|
||||||
|
fprintf(stderr, "lseek failed for failed_disk1\n");
|
||||||
|
unlock_all_stripes(info, sig);
|
||||||
|
err = -1;
|
||||||
|
goto exitCheck;
|
||||||
|
}
|
||||||
write_res2 = write(source[failed_disk2], stripes[failed_disk2], chunk_size);
|
write_res2 = write(source[failed_disk2], stripes[failed_disk2], chunk_size);
|
||||||
|
|
||||||
err = unlock_all_stripes(info, sig);
|
err = unlock_all_stripes(info, sig);
|
||||||
if(err != 0)
|
if(err != 0)
|
||||||
goto exitCheck;
|
goto exitCheck;
|
||||||
|
|
||||||
|
|
||||||
if (write_res1 != chunk_size || write_res2 != chunk_size) {
|
if (write_res1 != chunk_size || write_res2 != chunk_size) {
|
||||||
fprintf(stderr, "Failed to write a complete chunk.\n");
|
fprintf(stderr, "Failed to write a complete chunk.\n");
|
||||||
goto exitCheck;
|
goto exitCheck;
|
||||||
|
|
Loading…
Reference in New Issue