Block layer patches
- Image creation: Honour pwrite_zeroes_alignment for zeroing first sector - block-backend: Fix race (causing a crash) when resuming queued requests -----BEGIN PGP SIGNATURE----- iQJFBAABCgAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmklvQMRHGt3b2xmQHJl ZGhhdC5jb20ACgkQfwmycsiPL9byFA//d9VtU3wLZpJRL2mnYH2qJME3WeqJaSB+ FzkG32gkCb0JtH5yr427oJYKhZsKpNkz20E7z4+1ZT4ovcjo7mddJYW7DwaMjUmO G3UXWE33ayLNZFMDrsMRV5tfiQkSb7Y0ekYfwU7GjC3qhMhRIX9eCRBrCLD6jdUx mg2h0ML0smE9AV5AEuunwSoqp+rD+OpRQ6EBkkCVF5iMlIHeiewP/TQbJtKBtxdK AumiIcYgPbH7QFG8kDTmVCCGPDC0v2i1G6Owtptbt9RmWTEGp++Ngm8F+7u/kPMk weRhlVhnxwDxVxmHzvysh0m+n08oVJyA2vB4QJrti6ZmgDcJYulxFfQgPCKxjvGd 6va02q0DYrCbO3YiViaAtnudEuqqaB1to57jeQq6tP9KrpH8uzAddrFWeb3TY4gN CvWr+p4V7bYvteNASJt/+VC5T3haR+U5eCRD5nOKPyXqCbMT+z6zZRuYxP2q1W6i VwQLIjuWIx+bXVRUrHkf9VNy1clB4ga+ZDbTGFrl0NOLDcn6u3Vcr4GQ7VvQ31Pj ulGA9F+DXjPRQpZC+WnCZsBSLwVBrNeYPyxsCSk2ORH930djgb7e1lxX5OawT7MT lNzbQ+N7PXCd5Yt0UyJ3uCF6gqlpvmUV7IZMbyoYHceoCnz8+McqvGORYfzkLwk9 HUDS3UTI8Ks= =57x4 -----END PGP SIGNATURE----- Merge tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging Block layer patches - Image creation: Honour pwrite_zeroes_alignment for zeroing first sector - block-backend: Fix race (causing a crash) when resuming queued requests # -----BEGIN PGP SIGNATURE----- # # iQJFBAABCgAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmklvQMRHGt3b2xmQHJl # ZGhhdC5jb20ACgkQfwmycsiPL9byFA//d9VtU3wLZpJRL2mnYH2qJME3WeqJaSB+ # FzkG32gkCb0JtH5yr427oJYKhZsKpNkz20E7z4+1ZT4ovcjo7mddJYW7DwaMjUmO # G3UXWE33ayLNZFMDrsMRV5tfiQkSb7Y0ekYfwU7GjC3qhMhRIX9eCRBrCLD6jdUx # mg2h0ML0smE9AV5AEuunwSoqp+rD+OpRQ6EBkkCVF5iMlIHeiewP/TQbJtKBtxdK # AumiIcYgPbH7QFG8kDTmVCCGPDC0v2i1G6Owtptbt9RmWTEGp++Ngm8F+7u/kPMk # weRhlVhnxwDxVxmHzvysh0m+n08oVJyA2vB4QJrti6ZmgDcJYulxFfQgPCKxjvGd # 6va02q0DYrCbO3YiViaAtnudEuqqaB1to57jeQq6tP9KrpH8uzAddrFWeb3TY4gN # CvWr+p4V7bYvteNASJt/+VC5T3haR+U5eCRD5nOKPyXqCbMT+z6zZRuYxP2q1W6i # VwQLIjuWIx+bXVRUrHkf9VNy1clB4ga+ZDbTGFrl0NOLDcn6u3Vcr4GQ7VvQ31Pj # ulGA9F+DXjPRQpZC+WnCZsBSLwVBrNeYPyxsCSk2ORH930djgb7e1lxX5OawT7MT # lNzbQ+N7PXCd5Yt0UyJ3uCF6gqlpvmUV7IZMbyoYHceoCnz8+McqvGORYfzkLwk9 # HUDS3UTI8Ks= # =57x4 # -----END PGP SIGNATURE----- # gpg: Signature made Tue 25 Nov 2025 06:28:19 AM PST # gpg: using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6 # gpg: issuer "kwolf@redhat.com" # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [unknown] # gpg: WARNING: The key's User ID is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * tag 'for-upstream' of https://repo.or.cz/qemu/kevin: iotests: add Linux loop device image creation test block: use pwrite_zeroes_alignment when writing first sector file-posix: populate pwrite_zeroes_alignment block-backend: Fix race when resuming queued requests Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
a8d023be62
6 changed files with 102 additions and 4 deletions
3
block.c
3
block.c
|
|
@ -606,12 +606,13 @@ create_file_fallback_zero_first_sector(BlockBackend *blk,
|
|||
int64_t current_size,
|
||||
Error **errp)
|
||||
{
|
||||
uint32_t alignment = blk_get_pwrite_zeroes_alignment(blk);
|
||||
int64_t bytes_to_clear;
|
||||
int ret;
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
|
||||
bytes_to_clear = MIN(current_size, BDRV_SECTOR_SIZE);
|
||||
bytes_to_clear = MIN(current_size, MAX(BDRV_SECTOR_SIZE, alignment));
|
||||
if (bytes_to_clear) {
|
||||
ret = blk_co_pwrite_zeroes(blk, 0, bytes_to_clear, BDRV_REQ_MAY_UNMAP);
|
||||
if (ret < 0) {
|
||||
|
|
|
|||
|
|
@ -1318,9 +1318,9 @@ static void coroutine_fn blk_wait_while_drained(BlockBackend *blk)
|
|||
* section.
|
||||
*/
|
||||
qemu_mutex_lock(&blk->queued_requests_lock);
|
||||
/* blk_root_drained_end() has the corresponding blk_inc_in_flight() */
|
||||
blk_dec_in_flight(blk);
|
||||
qemu_co_queue_wait(&blk->queued_requests, &blk->queued_requests_lock);
|
||||
blk_inc_in_flight(blk);
|
||||
qemu_mutex_unlock(&blk->queued_requests_lock);
|
||||
}
|
||||
}
|
||||
|
|
@ -2305,6 +2305,17 @@ uint32_t blk_get_request_alignment(BlockBackend *blk)
|
|||
return bs ? bs->bl.request_alignment : BDRV_SECTOR_SIZE;
|
||||
}
|
||||
|
||||
/* Returns the optimal write zeroes alignment, in bytes; guaranteed nonzero */
|
||||
uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk)
|
||||
{
|
||||
BlockDriverState *bs = blk_bs(blk);
|
||||
IO_CODE();
|
||||
if (!bs) {
|
||||
return BDRV_SECTOR_SIZE;
|
||||
}
|
||||
return bs->bl.pwrite_zeroes_alignment ?: bs->bl.request_alignment;
|
||||
}
|
||||
|
||||
/* Returns the maximum hardware transfer length, in bytes; guaranteed nonzero */
|
||||
uint64_t blk_get_max_hw_transfer(BlockBackend *blk)
|
||||
{
|
||||
|
|
@ -2767,9 +2778,11 @@ static void blk_root_drained_end(BdrvChild *child)
|
|||
blk->dev_ops->drained_end(blk->dev_opaque);
|
||||
}
|
||||
qemu_mutex_lock(&blk->queued_requests_lock);
|
||||
while (qemu_co_enter_next(&blk->queued_requests,
|
||||
&blk->queued_requests_lock)) {
|
||||
while (!qemu_co_queue_empty(&blk->queued_requests)) {
|
||||
/* Resume all queued requests */
|
||||
blk_inc_in_flight(blk);
|
||||
qemu_co_enter_next(&blk->queued_requests,
|
||||
&blk->queued_requests_lock);
|
||||
}
|
||||
qemu_mutex_unlock(&blk->queued_requests_lock);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1611,6 +1611,22 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
|
|||
|
||||
bs->bl.pdiscard_alignment = dalign;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
/*
|
||||
* Linux requires logical block size alignment for write zeroes even
|
||||
* when normal reads/writes do not require alignment.
|
||||
*/
|
||||
if (!s->needs_alignment) {
|
||||
ret = probe_logical_blocksize(s->fd,
|
||||
&bs->bl.pwrite_zeroes_alignment);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret,
|
||||
"Failed to probe logical block size");
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
}
|
||||
|
||||
raw_refresh_zoned_limits(bs, &st, errp);
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
|
|||
void *opaque, int ret);
|
||||
|
||||
uint32_t blk_get_request_alignment(BlockBackend *blk);
|
||||
uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk);
|
||||
uint32_t blk_get_max_transfer(BlockBackend *blk);
|
||||
uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
|
||||
|
||||
|
|
|
|||
59
tests/qemu-iotests/tests/loop-create-file
Executable file
59
tests/qemu-iotests/tests/loop-create-file
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env bash
|
||||
# group: quick
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#
|
||||
# Copyright Red Hat, Inc.
|
||||
#
|
||||
# Test Linux loop device image creation
|
||||
#
|
||||
# This test verifies #3127 "qemu-img create fails on loop device with sector size 4096"
|
||||
# https://gitlab.com/qemu-project/qemu/-/issues/3127
|
||||
|
||||
seq="$(basename $0)"
|
||||
echo "QA output created by $seq"
|
||||
|
||||
status=1 # failure is the default!
|
||||
|
||||
_cleanup() {
|
||||
if [ -n "$loopdev" ]; then
|
||||
sudo losetup --detach "$loopdev"
|
||||
fi
|
||||
|
||||
_cleanup_test_img
|
||||
}
|
||||
|
||||
trap "_cleanup; exit \$status" 0 1 2 3 15
|
||||
|
||||
# get standard environment, filters and checks
|
||||
cd ..
|
||||
. ./common.rc
|
||||
. ./common.filter
|
||||
|
||||
_supported_fmt raw
|
||||
_supported_proto file
|
||||
_supported_os Linux
|
||||
|
||||
if ! sudo -n losetup &>/dev/null; then
|
||||
_notrun "sudo losetup not available"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "=== Create image on a 4 KB sector size loop device ==="
|
||||
echo
|
||||
|
||||
_make_test_img -f $IMGFMT 1M
|
||||
|
||||
loopdev=$(sudo losetup --sector-size 4096 --find --show "$TEST_IMG")
|
||||
if [ -z "$loopdev" ]; then
|
||||
_fail
|
||||
fi
|
||||
|
||||
sudo $QEMU_IMG_PROG create -f raw "$loopdev" 1M | \
|
||||
sed -e "s#/dev/loop[0-9]\\+#LOOPDEV#g"
|
||||
|
||||
# success, all done
|
||||
echo
|
||||
echo '*** done'
|
||||
rm -f $seq.full
|
||||
status=0
|
||||
8
tests/qemu-iotests/tests/loop-create-file.out
Normal file
8
tests/qemu-iotests/tests/loop-create-file.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
QA output created by loop-create-file
|
||||
|
||||
=== Create image on a 4 KB sector size loop device ===
|
||||
|
||||
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
|
||||
Formatting 'LOOPDEV', fmt=raw size=1048576
|
||||
|
||||
*** done
|
||||
Loading…
Add table
Add a link
Reference in a new issue