Skip to content

Add write_stream support to Write opcode#381

Open
rektide wants to merge 5 commits intotokio-rs:masterfrom
rektide:fdp-write-stream
Open

Add write_stream support to Write opcode#381
rektide wants to merge 5 commits intotokio-rs:masterfrom
rektide:fdp-write-stream

Conversation

@rektide
Copy link

@rektide rektide commented Jan 29, 2026

Resolves #380.

Expose the write_stream field from io_uring_sqe for IORING_OP_WRITE. Uses Option<u8> to only set the field when explicitly configured.

caveats

This PR has big caveats, on an otherwise very simple change:

  1. A new write_stream feature is used to enable this capability. This allows kernels <6.16 to still compile, while newer kernel users can enable write_stream to get the feature.
  2. When write_stream feature isn't on we got a dead_code warning, for code inside the opcode! macro. Added an allow(dead_code) there.

Expose the write_stream field from io_uring_sqe for IORING_OP_WRITE.
Uses Option<u8> to only set the field when explicitly configured,
avoiding potential issues on older kernels that don't support this feature.
Make write_stream support optional via cargo feature.
Only compiles write_stream field and setter when feature is enabled,
ensuring compatibility with older kernel versions.
Use cfg_attr to apply allow(dead_code) annotation only when write_stream
feature is disabled. This is more targeted than module-level suppression.
ioprio: u16 = 0,
rw_flags: i32 = 0
rw_flags: i32 = 0,
#[cfg_attr(not(feature = "write_stream"), allow(dead_code))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this need a feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more than happy to remove the feature!!

I want to call this out again; I personally think not supporting old kernels is fine, but I expect some people will be kind of unhappy:

A new write_stream feature is used to enable this capability. This allows kernels <6.16 to still compile, while newer kernel users can enable write_stream to get the feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work correctly on older kernels as long as the user doesn't set the flag.

We don't use a feature for every opcode flag.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this line here that had driven me to put in the feature flag. This won't be in the bindings unless the kernel is new enough: https://github.com/tokio-rs/io-uring/pull/381/changes#diff-a91a9fa57b926d127e913cad0a3ede5577f5aca0623066c07c2d2322221a6627R985

Rust won't compile that unless the bindings have it, right? I could definitely be missing something about how macros or how this works! But that seems like the root of the tension to me, that makes me think the feature flag is needed.

Simplify the write_stream API by changing from Option<u8> to a plain
u8 with default value 0. When write_stream is 0, it is not set on the
SQE. This removes the need for conditional compilation in the struct
destructuring and simplifies the code.
Add a test for the write_stream feature to io-uring-test. The test verifies
that write_stream=1 works correctly by performing a write and read operation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: write_stream support for Write

2 participants