Return the read error instead of EDOM when a disk read fails #166
@@ -405,8 +405,8 @@ void blockstore_impl_t::handle_read_event(ring_data_t *data, blockstore_op_t *op
|
||||
}
|
||||
if (PRIV(op)->pending_ops == 0)
|
||||
{
|
||||
// verify checksums if required
|
||||
if (dsk.csum_block_size && !verify_read_checksums(op))
|
||||
// verify checksums if required, but not of a buffer that a failed read didn't fill
|
||||
if (op->retval >= 0 && dsk.csum_block_size && !verify_read_checksums(op))
|
||||
op->retval = -EDOM;
|
||||
else if (op->retval == 0)
|
||||
op->retval = op->len;
|
||||
|
||||
@@ -941,6 +941,7 @@ void blockstore_impl_t::handle_read_event(ring_data_t *data, blockstore_op_t *op
|
||||
if (dsk.csum_block_size)
|
||||
{
|
||||
// verify checksums if required
|
||||
bool read_failed = op->retval < 0;
|
||||
auto & rv = PRIV(op)->read_vec;
|
||||
void *meta_block = NULL;
|
||||
if (dsk.csum_block_size > dsk.bitmap_granularity)
|
||||
@@ -999,7 +1000,11 @@ void blockstore_impl_t::handle_read_event(ring_data_t *data, blockstore_op_t *op
|
||||
single_iov = { .iov_base = op->buf + rv[i].offset - op->offset, .iov_len = rv[i].len };
|
||||
}
|
||||
bool ok = true;
|
||||
if (rv[i].copy_flags & COPY_BUF_JOURNAL)
|
||||
if (read_failed)
|
||||
{
|
||||
// Nothing to verify, the failed read didn't fill the buffer
|
||||
}
|
||||
else if (rv[i].copy_flags & COPY_BUF_JOURNAL)
|
||||
{
|
||||
// SMALL_WRITE from journal
|
||||
verify_journal_checksums(
|
||||
@@ -1062,7 +1067,7 @@ void blockstore_impl_t::handle_read_event(ring_data_t *data, blockstore_op_t *op
|
||||
free_dirty_dyn_data(vec);
|
||||
continue;
|
||||
}
|
||||
if (vec.csum_buf && ((vec.copy_flags & COPY_BUF_JOURNAL) || !clean_changed))
|
||||
if (!read_failed && vec.csum_buf && ((vec.copy_flags & COPY_BUF_JOURNAL) || !clean_changed))
|
||||
{
|
||||
uint32_t *csum = (uint32_t*)vec.csum_buf;
|
||||
for (size_t p = 0; p < vec.len; p += dsk.csum_block_size, csum++)
|
||||
|
||||
@@ -2523,6 +2523,55 @@ static void test_tombstone()
|
||||
}
|
||||
}
|
||||
|
||||
// A read that fails with an I/O error has to return that error. Checksums of the buffer
|
||||
// that the failed read didn't fill must not be verified and turn it into -EDOM
|
||||
static void test_read_error_is_not_edom()
|
||||
{
|
||||
printf("\n-- test_read_error_is_not_edom\n");
|
||||
|
||||
bs_test_t test;
|
||||
test.default_cfg();
|
||||
test.init();
|
||||
|
||||
blockstore_op_t op;
|
||||
op.opcode = BS_OP_WRITE_STABLE;
|
||||
op.oid = { .inode = 1, .stripe = 0 };
|
||||
op.version = 1;
|
||||
op.offset = 0;
|
||||
op.len = 16*1024;
|
||||
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, op.len);
|
||||
memset(op.buf, 0xAA, op.len);
|
||||
test.exec_op(&op);
|
||||
assert(op.retval == op.len);
|
||||
|
||||
// Fail every read from the data area
|
||||
int failed_reads = 0;
|
||||
test.sqe_handler = [&](io_uring_sqe *sqe)
|
||||
{
|
||||
if (sqe->fd != MOCK_DATA_FD || sqe->opcode != IORING_OP_READV || sqe->off < test.bs->dsk.data_offset)
|
||||
return false;
|
||||
((ring_data_t*)sqe->user_data)->res = -EIO;
|
||||
test.ringloop->mark_completed((ring_data_t*)sqe->user_data);
|
||||
failed_reads++;
|
||||
return true;
|
||||
};
|
||||
blockstore_op_t read_op;
|
||||
read_op.opcode = BS_OP_READ;
|
||||
read_op.oid = { .inode = 1, .stripe = 0 };
|
||||
read_op.version = UINT64_MAX;
|
||||
read_op.offset = 0;
|
||||
read_op.len = 16*1024;
|
||||
read_op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, read_op.len);
|
||||
memset(read_op.buf, 0xCC, read_op.len);
|
||||
test.exec_op(&read_op);
|
||||
test.sqe_handler = NULL;
|
||||
assert(failed_reads > 0);
|
||||
assert(read_op.retval == -EIO);
|
||||
|
||||
free(op.buf);
|
||||
free(read_op.buf);
|
||||
}
|
||||
|
||||
int main(int narg, char *args[])
|
||||
{
|
||||
test_simple();
|
||||
@@ -2556,5 +2605,6 @@ int main(int narg, char *args[])
|
||||
test_no_intent_over_unwritten_compaction();
|
||||
test_big_write_after_redirect_intent();
|
||||
test_tombstone();
|
||||
test_read_error_is_not_edom();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3222,6 +3222,57 @@ static void test_tombstone_unsupported()
|
||||
assert(op.retval == -EOPNOTSUPP);
|
||||
}
|
||||
|
||||
// A read that fails with an I/O error has to return that error. Checksums of the buffer
|
||||
// that the failed read didn't fill must not be verified and turn it into -EDOM
|
||||
static void test_read_error_is_not_edom(const char *csum_block_size)
|
||||
{
|
||||
printf("\n-- test_read_error_is_not_edom csum_block_size=%s\n", csum_block_size);
|
||||
|
||||
bs_test_t test;
|
||||
test.default_cfg();
|
||||
test.config["data_csum_type"] = "crc32c";
|
||||
test.config["csum_block_size"] = csum_block_size;
|
||||
test.init();
|
||||
|
||||
blockstore_op_t op;
|
||||
op.opcode = BS_OP_WRITE_STABLE;
|
||||
op.oid = { .inode = 1, .stripe = 0 };
|
||||
op.version = 1;
|
||||
op.offset = 0;
|
||||
op.len = 16*1024;
|
||||
op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, op.len);
|
||||
memset(op.buf, 0xAA, op.len);
|
||||
test.exec_op(&op);
|
||||
assert(op.retval == op.len);
|
||||
|
||||
// Fail every read from the data area
|
||||
int failed_reads = 0;
|
||||
test.sqe_handler = [&](io_uring_sqe *sqe)
|
||||
{
|
||||
if (sqe->fd != MOCK_DATA_FD || sqe->opcode != IORING_OP_READV || sqe->off < test.dsk().data_offset)
|
||||
return false;
|
||||
((ring_data_t*)sqe->user_data)->res = -EIO;
|
||||
test.ringloop->mark_completed((ring_data_t*)sqe->user_data);
|
||||
failed_reads++;
|
||||
return true;
|
||||
};
|
||||
blockstore_op_t read_op;
|
||||
read_op.opcode = BS_OP_READ;
|
||||
read_op.oid = { .inode = 1, .stripe = 0 };
|
||||
read_op.version = UINT64_MAX;
|
||||
read_op.offset = 0;
|
||||
read_op.len = 16*1024;
|
||||
read_op.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, read_op.len);
|
||||
memset(read_op.buf, 0xCC, read_op.len);
|
||||
test.exec_op(&read_op);
|
||||
test.sqe_handler = NULL;
|
||||
assert(failed_reads > 0);
|
||||
assert(read_op.retval == -EIO);
|
||||
|
||||
free(op.buf);
|
||||
free(read_op.buf);
|
||||
}
|
||||
|
||||
int main(int narg, char *args[])
|
||||
{
|
||||
test_preserve_corruption();
|
||||
@@ -3236,6 +3287,8 @@ int main(int narg, char *args[])
|
||||
test_read_after_flush_verifies_csum("16384", true);
|
||||
test_read_after_flush_verifies_csum("4096", false);
|
||||
test_read_after_flush_verifies_csum("4096", true);
|
||||
test_read_error_is_not_edom("16384");
|
||||
test_read_error_is_not_edom("4096");
|
||||
test_meta_tail_reload();
|
||||
test_write_no_space_eagain();
|
||||
test_read_bitmap_of_deleted_object();
|
||||
|
||||
Reference in New Issue
Block a user