axboe / liburing

Library providing helpers for the Linux kernel io_uring support
MIT License
2.85k stars 402 forks source link

[GIT PULL] Add ftruncate #1004

Closed tontinton closed 8 months ago

tontinton commented 10 months ago

To accompany the patches I sent for adding ftruncate, here are the changes for usermode.


git request-pull output:

The following changes since commit 63342497bec87b72d4b415c8bed930c15ff83b0d:

  test/read-mshot: check that IORING_CQE_F_MORE isn't set on error (2024-01-22 14:56:08 -0700)

are available in the Git repository at:

  git@github.com:tontinton/liburing.git truncate

for you to fetch changes up to c023393f3a3b960e3df77e5bcfd1b2e93e3b5e0f:

  man/io_uring_prep_ftruncate: Add the new ftruncate command (2024-01-31 17:52:13 +0200)

----------------------------------------------------------------
Tony Solomonik (4):
      Add ftruncate helpers
      test/truncate: Add test for ftruncate
      test/truncate: Add test for failure on truncate path
      man/io_uring_prep_ftruncate: Add the new ftruncate command

 man/io_uring_prep_ftruncate.3   |  48 ++++++++++++++++++++++++++++++++
 src/include/liburing.h          |   6 ++++
 src/include/liburing/io_uring.h |   1 +
 src/liburing-ffi.map            |   1 +
 test/Makefile                   |   1 +
 test/truncate.c                 | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 236 insertions(+)
 create mode 100644 man/io_uring_prep_ftruncate.3
 create mode 100644 test/truncate.c

Click to show/hide pull request guidelines ## Pull Request Guidelines 1. To make everyone easily filter pull request from the email notification, use `[GIT PULL]` as a prefix in your PR title. ``` [GIT PULL] Your Pull Request Title ``` 2. Follow the commit message format rules below. 3. Follow the Linux kernel coding style (see: https://github.com/torvalds/linux/blob/master/Documentation/process/coding-style.rst). ### Commit message format rules: 1. The first line is title (don't be more than 72 chars if possible). 2. Then an empty line. 3. Then a description (may be omitted for truly trivial changes). 4. Then an empty line again (if it has a description). 5. Then a `Signed-off-by` tag with your real name and email. For example: ``` Signed-off-by: Foo Bar ``` The description should be word-wrapped at 72 chars. Some things should not be word-wrapped. They may be some kind of quoted text - long compiler error messages, oops reports, Link, etc. (things that have a certain specific format). Note that all of this goes in the commit message, not in the pull request text. The pull request text should introduce what this pull request does, and each commit message should explain the rationale for why that particular change was made. The git tree is canonical source of truth, not github. Each patch should do one thing, and one thing only. If you find yourself writing an explanation for why a patch is fixing multiple issues, that's a good indication that the change should be split into separate patches. If the commit is a fix for an issue, add a `Fixes` tag with the issue URL. Don't use GitHub anonymous email like this as the commit author: ``` 123456789+username@users.noreply.github.com ``` Use a real email address! ### Commit message example: ``` src/queue: don't flush SQ ring for new wait interface If we have IORING_FEAT_EXT_ARG, then timeouts are done through the syscall instead of by posting an internal timeout. This was done to be both more efficient, but also to enable multi-threaded use the wait side. If we touch the SQ state by flushing it, that isn't safe without synchronization. Fixes: https://github.com/axboe/liburing/issues/402 Signed-off-by: Jens Axboe ```

By submitting this pull request, I acknowledge that:

  1. I have followed the above pull request guidelines.
  2. I have the rights to submit this work under the same license.
  3. I agree to a Developer Certificate of Origin (see https://developercertificate.org for more information).
axboe commented 8 months ago

Two minor things:

1) The prep helper should go into the ffi as well, and the ffi map (in the 2.6 section). See src/liburing-ffi.map. 2) The test case tests functionality, which is great, but it should also the failure case. Since we're potentially adding truncate support later where we'll put the path in sqe->addr, add a test case that issues an sqe where addr is set to a filename and verify that it fails with EINVAL.

axboe commented 8 months ago

I think this looks fine, but one problem is that if you run this test case on an older kernel, then the test will fail. If you get -EINVAL for the first ftruncate you try, just assume the kernel doesn't support it and return T_EXIT_SKIP for that and skip the other tests. That way it'll just skip the test case on older kernels, but test it on newer kernels.

See other test cases that do this very thing, usually with a static int no_ftruncate global that can be set by the first test invocation, and then checked again for non-zero when that first test case returns. If true, then it should return T_EXIT_SKIP.

tontinton commented 8 months ago

It already runs goto out which returns 0, when ftruncate is not supported.

axboe commented 8 months ago

It already runs goto out which returns 0, when ftruncate is not supported.

It does, but it doesn't return T_EXIT_SKIPPED. I think you should also distinguish between "we got EBADF/EINVAL on the first test, it's probably not supported, T_EXIT_SKIPPED" rather than just have any of the test cases returning EINVAL leading to a skipped test where it probably should've been a failure.