Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in AbortIO #13205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions env/fs_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ class PosixFileSystem : public FileSystem {
return IOStatus::OK();
}

std::set<void*> be_canceled;
for (size_t i = 0; i < io_handles.size(); i++) {
Posix_IOHandle* posix_handle =
static_cast<Posix_IOHandle*>(io_handles[i]);
Expand Down Expand Up @@ -1173,6 +1174,7 @@ class PosixFileSystem : public FileSystem {
return IOStatus::IOError("io_uring_submit() requested but returned " +
std::to_string(ret));
}
be_canceled.insert(io_handles[i]);
}

// After submitting the requests, wait for the requests.
Expand All @@ -1198,12 +1200,34 @@ class PosixFileSystem : public FileSystem {
if (posix_handle->iu != iu) {
return IOStatus::IOError("");
}
posix_handle->req_count++;

// Reset cqe data to catch any stray reuse of it
static_cast<struct io_uring_cqe*>(cqe)->user_data = 0xd5d5d5d5d5d5d5d5;
io_uring_cqe_seen(iu, cqe);

// If the handle is not in the handles set that needs to be cancelled,
// update the result and execute the callback normally.
if (!be_canceled.count(static_cast<void*>(posix_handle))) {
FSReadRequest req;
req.scratch = posix_handle->scratch;
req.offset = posix_handle->offset;
req.len = posix_handle->len;

size_t finished_len = 0;
size_t bytes_read = 0;
bool read_again = false;
UpdateResult(cqe, "", req.len, posix_handle->iov.iov_len,
true /*async_read*/, posix_handle->use_direct_io,
posix_handle->alignment, finished_len, &req, bytes_read,
read_again);
posix_handle->is_finished = true;
posix_handle->cb(req, posix_handle->cb_arg);
(void)finished_len;
(void)bytes_read;
(void)read_again;
continue;
}

// - If the request is cancelled successfully, the original request is
// completed with -ECANCELED and the cancel request is completed with
// a result of 0.
Expand All @@ -1215,7 +1239,7 @@ class PosixFileSystem : public FileSystem {
//
// Every handle has to wait for 2 requests completion: original one and
// the cancel request which is tracked by PosixHandle::req_count.
if (posix_handle->req_count == 2 &&
if (++posix_handle->req_count == 2 &&
static_cast<Posix_IOHandle*>(io_handles[i]) == posix_handle) {
posix_handle->is_finished = true;
FSReadRequest req;
Expand Down