• Pavel Begunkov's avatar
    block: implement async io_uring discard cmd · 50c52250
    Pavel Begunkov authored
    io_uring allows implementing custom file specific asynchronous
    operations via the fops->uring_cmd callback, a.k.a. IORING_OP_URING_CMD
    requests or just io_uring commands. Use it to add support for async
    discards.
    
    Normally, it first tries to queue up bios in a non-blocking context,
    and if that fails, we'd retry from a blocking context by returning
    -EAGAIN to the core io_uring. We always get the result from bios
    asynchronously by setting a custom bi_end_io callback, at which point
    we drag the request into the task context to either reissue or complete
    it and post a completion to the user.
    
    Unlike ioctl(BLKDISCARD) with stronger guarantees against races, we only
    do a best effort attempt to invalidate page cache, and it can race with
    any writes and reads and leave page cache stale. It's the same kind of
    races we allow to direct writes.
    
    Also, apart from cases where discarding is not allowed at all, e.g.
    discards are not supported or the file/device is read only, the user
    should assume that the sector range on disk is not valid anymore, even
    when an error was returned to the user.
    Suggested-by: default avatarConrad Meyer <conradmeyer@meta.com>
    Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/2b5210443e4fa0257934f73dfafcc18a77cd0e09.1726072086.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
    50c52250
ioctl.c 21 KB