Fix sqe->addr passed in cancel request in io_uring (#10644)

Summary:
Update io_uring_prep_cancel as it is now backward compatible.
Also, io_uring_prep_cancel expects sqe->addr to match with read
request submitted. It's being set wrong which is now fixed in this PR.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10644

Test Plan:
- Ran internally with lastest liburing package and on RocksDB
github repo with older version.
- Ran seekrandom regression to confirm there is no regression.

Reviewed By: anand1976

Differential Revision: D39284229

Pulled By: akankshamahajan15

fbshipit-source-id: fd52cdf23d676da114896163626b75c8ae09c980
main
Akanksha Mahajan 2 years ago committed by Facebook GitHub Bot
parent 013305af13
commit 0f4978d34f
  1. 2
      HISTORY.md
  2. 10
      env/fs_posix.cc
  3. 4
      env/io_posix.cc

@ -1,5 +1,7 @@
# Rocksdb Change Log # Rocksdb Change Log
## Unreleased ## Unreleased
### Bug Fixes
* Fix a bug in io_uring_prep_cancel in AbortIO API for posix which expects sqe->addr to match with read request submitted and wrong paramter was being passed.
## 7.7.0 (09/18/2022) ## 7.7.0 (09/18/2022)
### Bug Fixes ### Bug Fixes

10
env/fs_posix.cc vendored

@ -1115,10 +1115,11 @@ class PosixFileSystem : public FileSystem {
// Prepare the cancel request. // Prepare the cancel request.
struct io_uring_sqe* sqe; struct io_uring_sqe* sqe;
sqe = io_uring_get_sqe(iu); sqe = io_uring_get_sqe(iu);
// prep_cancel changed API in liburing, but we need to support both old
// and new versions so do it by hand // In order to cancel the request, sqe->addr of cancel request should
io_uring_prep_cancel(sqe, 0, 0); // match with the read request submitted which is posix_handle->iov.
sqe->addr = reinterpret_cast<uint64_t>(posix_handle); io_uring_prep_cancel(sqe, &posix_handle->iov, 0);
// Sets sqe->user_data to posix_handle.
io_uring_sqe_set_data(sqe, posix_handle); io_uring_sqe_set_data(sqe, posix_handle);
// submit the request. // submit the request.
@ -1146,6 +1147,7 @@ class PosixFileSystem : public FileSystem {
} }
assert(cqe != nullptr); assert(cqe != nullptr);
// Returns cqe->user_data.
Posix_IOHandle* posix_handle = Posix_IOHandle* posix_handle =
static_cast<Posix_IOHandle*>(io_uring_cqe_get_data(cqe)); static_cast<Posix_IOHandle*>(io_uring_cqe_get_data(cqe));
assert(posix_handle->iu == iu); assert(posix_handle->iu == iu);

4
env/io_posix.cc vendored

@ -899,8 +899,10 @@ IOStatus PosixRandomAccessFile::ReadAsync(
struct io_uring_sqe* sqe; struct io_uring_sqe* sqe;
sqe = io_uring_get_sqe(iu); sqe = io_uring_get_sqe(iu);
io_uring_prep_readv(sqe, fd_, &posix_handle->iov, 1, posix_handle->offset); io_uring_prep_readv(sqe, fd_, /*sqe->addr=*/&posix_handle->iov,
/*sqe->len=*/1, /*sqe->offset=*/posix_handle->offset);
// Sets sqe->user_data to posix_handle.
io_uring_sqe_set_data(sqe, posix_handle); io_uring_sqe_set_data(sqe, posix_handle);
// Step 4: io_uring_submit // Step 4: io_uring_submit

Loading…
Cancel
Save