From e40a71b2cee2362a9e4a109cacbab4417ecba662 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 17 Nov 2019 22:27:29 +0300 Subject: [PATCH] Check result to be equal to iov_len --- blockstore_flush.cpp | 14 ++++++++++---- blockstore_init.cpp | 4 +++- blockstore_read.cpp | 2 +- blockstore_stable.cpp | 7 +++++-- blockstore_sync.cpp | 7 +++++-- blockstore_write.cpp | 8 ++++++-- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/blockstore_flush.cpp b/blockstore_flush.cpp index 11968cbe..80dc5096 100644 --- a/blockstore_flush.cpp +++ b/blockstore_flush.cpp @@ -24,9 +24,12 @@ journal_flusher_co::journal_flusher_co() wait_state = 0; simple_callback = [this](ring_data_t* data) { - if (data->res < 0) + if (data->res != data->iov.iov_len) { - throw std::runtime_error("write operation failed. in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111"); + throw std::runtime_error( + "write operation failed ("+std::to_string(data->res)+" != "+std::to_string(data->iov.iov_len)+ + "). in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111" + ); } wait_count--; }; @@ -243,9 +246,12 @@ resume_0: data->iov = (struct iovec){ meta_it->second.buf, 512 }; data->callback = [this](ring_data_t* data) { - if (data->res < 0) + if (data->res != data->iov.iov_len) { - throw std::runtime_error("write operation failed. in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111"); + throw std::runtime_error( + "write operation failed ("+std::to_string(data->res)+" != "+std::to_string(data->iov.iov_len)+ + "). in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111" + ); } meta_it->second.state = 1; wait_count--; diff --git a/blockstore_init.cpp b/blockstore_init.cpp index 5c40ff0a..c82d7c31 100644 --- a/blockstore_init.cpp +++ b/blockstore_init.cpp @@ -7,7 +7,7 @@ blockstore_init_meta::blockstore_init_meta(blockstore *bs) void blockstore_init_meta::handle_event(ring_data_t *data) { - if (data->res < 0) + if (data->res <= 0) { throw std::runtime_error( std::string("read metadata failed at offset ") + std::to_string(metadata_read) + @@ -29,6 +29,8 @@ int blockstore_init_meta::loop() if (!metadata_buffer) { metadata_buffer = (uint8_t*)memalign(512, 2*bs->metadata_buf_size); + if (!metadata_buffer) + throw std::bad_alloc(); } if (!submitted) { diff --git a/blockstore_read.cpp b/blockstore_read.cpp index 65cf82af..ee0316d9 100644 --- a/blockstore_read.cpp +++ b/blockstore_read.cpp @@ -144,7 +144,7 @@ int blockstore::dequeue_read(blockstore_operation *read_op) void blockstore::handle_read_event(ring_data_t *data, blockstore_operation *op) { op->pending_ops--; - if (data->res < 0) + if (data->res != data->iov.iov_len) { // read error op->retval = data->res; diff --git a/blockstore_stable.cpp b/blockstore_stable.cpp index 5dfb9253..e6eed976 100644 --- a/blockstore_stable.cpp +++ b/blockstore_stable.cpp @@ -107,9 +107,12 @@ int blockstore::dequeue_stable(blockstore_operation *op) void blockstore::handle_stable_event(ring_data_t *data, blockstore_operation *op) { - if (data->res < 0) + if (data->res != data->iov.iov_len) { - throw std::runtime_error("write operation failed. in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111"); + throw std::runtime_error( + "write operation failed ("+std::to_string(data->res)+" != "+std::to_string(data->iov.iov_len)+ + "). in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111" + ); } op->pending_ops--; if (op->pending_ops == 0) diff --git a/blockstore_sync.cpp b/blockstore_sync.cpp index 1edd49e6..1ea6d009 100644 --- a/blockstore_sync.cpp +++ b/blockstore_sync.cpp @@ -111,9 +111,12 @@ int blockstore::continue_sync(blockstore_operation *op) void blockstore::handle_sync_event(ring_data_t *data, blockstore_operation *op) { - if (data->res < 0) + if (data->res < data->iov.iov_len) { - throw std::runtime_error("write operation failed. in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111"); + throw std::runtime_error( + "write operation failed ("+std::to_string(data->res)+" != "+std::to_string(data->iov.iov_len)+ + "). in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111" + ); } op->pending_ops--; if (op->pending_ops == 0) diff --git a/blockstore_write.cpp b/blockstore_write.cpp index a455e4f1..c1a57891 100644 --- a/blockstore_write.cpp +++ b/blockstore_write.cpp @@ -96,6 +96,7 @@ int blockstore::dequeue_write(blockstore_operation *op) vcnt = 1; op->iov_zerofill[0] = (struct iovec){ op->buf, op->len }; } + data->iov.iov_len = op->len; // to check it in the callback data->callback = cb; my_uring_prep_writev( sqe, data_fd, op->iov_zerofill, vcnt, data_offset + (loc << block_order) @@ -150,10 +151,13 @@ int blockstore::dequeue_write(blockstore_operation *op) void blockstore::handle_write_event(ring_data_t *data, blockstore_operation *op) { - if (data->res < 0) + if (data->res != data->iov.iov_len) { // FIXME: our state becomes corrupted after a write error. maybe do something better than just die - throw std::runtime_error("write operation failed. in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111"); + throw std::runtime_error( + "write operation failed ("+std::to_string(data->res)+" != "+std::to_string(data->iov.iov_len)+ + "). in-memory state is corrupted. AAAAAAAaaaaaaaaa!!!111" + ); } op->pending_ops--; if (op->pending_ops == 0)