mirror of
https://github.com/Motorhead1991/qemu.git
synced 2026-02-11 19:39:26 -07:00
block/io: skip head/tail requests on EINVAL
When guests send misaligned discard requests, the block layer breaks them up into a misaligned head, an aligned main body, and a misaligned tail. The file-posix block driver on Linux returns -EINVAL on misaligned discard requests. This causes bdrv_co_pdiscard() to fail and guests configured with werror=stop will pause. Add a special case for misaligned head/tail requests. Simply continue when EINVAL is encountered so that the aligned main body of the request can be completed and the guest is not paused. This is the best we can do when guest discard limits do not match the host discard limits. Fixes: https://issues.redhat.com/browse/RHEL-86032 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Hanna Czenczek <hreitz@redhat.com> Message-ID: <20250417150528.76470-3-stefanha@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
f605796aae
commit
4733cb0833
1 changed files with 10 additions and 5 deletions
15
block/io.c
15
block/io.c
|
|
@ -3109,11 +3109,12 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset,
|
|||
/* Invalidate the cached block-status data range if this discard overlaps */
|
||||
bdrv_bsc_invalidate_range(bs, offset, bytes);
|
||||
|
||||
/* Discard is advisory, but some devices track and coalesce
|
||||
/*
|
||||
* Discard is advisory, but some devices track and coalesce
|
||||
* unaligned requests, so we must pass everything down rather than
|
||||
* round here. Still, most devices will just silently ignore
|
||||
* unaligned requests (by returning -ENOTSUP), so we must fragment
|
||||
* the request accordingly. */
|
||||
* round here. Still, most devices reject unaligned requests with
|
||||
* -EINVAL or -ENOTSUP, so we must fragment the request accordingly.
|
||||
*/
|
||||
align = MAX(bs->bl.pdiscard_alignment, bs->bl.request_alignment);
|
||||
assert(align % bs->bl.request_alignment == 0);
|
||||
head = offset % align;
|
||||
|
|
@ -3180,7 +3181,11 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset,
|
|||
}
|
||||
}
|
||||
if (ret && ret != -ENOTSUP) {
|
||||
goto out;
|
||||
if (ret == -EINVAL && (offset % align != 0 || num % align != 0)) {
|
||||
/* Silently skip rejected unaligned head/tail requests */
|
||||
} else {
|
||||
goto out; /* bail out */
|
||||
}
|
||||
}
|
||||
|
||||
offset += num;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue