Skip to content

Commit

Permalink
Fix sqe->addr passed in cancel request in io_uring (#10644)
Browse files Browse the repository at this point in the history
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: #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
  • Loading branch information
akankshamahajan15 authored and riversand963 committed Sep 22, 2022
1 parent 9b1817d commit d034981
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Rocksdb Change Log

## 7.7.0 (09/18/2022)
### Bug Fixes
* Fixed a hang when an operation such as `GetLiveFiles` or `CreateNewBackup` is asked to trigger and wait for memtable flush on a read-only DB. Such indirect requests for memtable flush are now ignored on a read-only DB.
Expand All @@ -10,6 +11,7 @@
* Fix a bug in key range overlap checking with concurrent compactions when user-defined timestamp is enabled. User-defined timestamps should be EXCLUDED when checking if two ranges overlap.
* Fixed a bug where the blob cache prepopulating logic did not consider the secondary cache (see #10603).
* Fixed the rocksdb.num.sst.read.per.level, rocksdb.num.index.and.filter.blocks.read.per.level and rocksdb.num.level.read.per.multiget stats in the MultiGet coroutines
* 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.

### Public API changes
* Add `rocksdb_column_family_handle_get_id`, `rocksdb_column_family_handle_get_name` to get name, id of column family in C API
Expand Down
10 changes: 6 additions & 4 deletions env/fs_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,11 @@ class PosixFileSystem : public FileSystem {
// Prepare the cancel request.
struct io_uring_sqe* sqe;
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
io_uring_prep_cancel(sqe, 0, 0);
sqe->addr = reinterpret_cast<uint64_t>(posix_handle);

// In order to cancel the request, sqe->addr of cancel request should
// match with the read request submitted which is posix_handle->iov.
io_uring_prep_cancel(sqe, &posix_handle->iov, 0);
// Sets sqe->user_data to posix_handle.
io_uring_sqe_set_data(sqe, posix_handle);

// submit the request.
Expand Down Expand Up @@ -1146,6 +1147,7 @@ class PosixFileSystem : public FileSystem {
}
assert(cqe != nullptr);

// Returns cqe->user_data.
Posix_IOHandle* posix_handle =
static_cast<Posix_IOHandle*>(io_uring_cqe_get_data(cqe));
assert(posix_handle->iu == iu);
Expand Down
4 changes: 3 additions & 1 deletion env/io_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,10 @@ IOStatus PosixRandomAccessFile::ReadAsync(
struct io_uring_sqe* sqe;
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);

// Step 4: io_uring_submit
Expand Down

0 comments on commit d034981

Please sign in to comment.