block: move discard checks into the ioctl handler
authorChristoph Hellwig <hch@lst.de>
Mon, 6 May 2024 04:20:23 +0000 (06:20 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 7 May 2024 13:29:42 +0000 (07:29 -0600)
commit30f1e724142242a453f92d90b33e030014900bf0
treebe11fbd287ea98d07697887c0ad5c484ab4e075b
parent0942592045782e76a9d52c409955c2dc313cbd30
block: move discard checks into the ioctl handler

Most bio operations get basic sanity checking in submit_bio and anything
more complicated than that is done in the callers.  Discards are a bit
different from that in that a lot of checking is done in
__blkdev_issue_discard, and the specific errnos for that are returned
to userspace.  Move the checks that require specific errnos to the ioctl
handler instead, and just leave the basic sanity checking in submit_bio
for the other handlers.  This introduces two changes in behavior:

 1) the logical block size alignment check of the start and len is lost
    for non-ioctl callers.
    This matches what is done for other operations including reads and
    writes.  We should probably verify this for all bios, but for now
    make discards match the normal flow.
 2) for non-ioctl callers all errors are reported on I/O completion now
    instead of synchronously.  Callers in general mostly ignore or log
    errors so this will actually simplify the code once cleaned up

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20240506042027.2289826-3-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-lib.c
block/ioctl.c