Pull request

-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmW5b1IACgkQnKSrs4Gr
 c8geoQf8DU8Z8jlvy1luuBZLq3R7hnC7c3Wzje0atLGP++pX6QUXfAgGDsTTIQeh
 XWmkFhbOBurhToH8YpgPyNG8ZWYd9+NIvLnIJiWDklNDZg2zC00aOi8yBEbsgyFb
 50HJA30AAHq8PuctCzhGhENLxvBvNDNME74SwYH7FSIK5x/nA1XBHDZsjst1/Hk2
 1loLbVWElbU28Xll7hI862SAb8RULC/sRQomkQAhpydxq4TApNuRwvpRfPNFwFJ0
 +dCquCJEfV6wfD62xg2CBGA5DrD9T7ADxmCYl4DQyp3HIRKXAptjgLsx3aZaIr1z
 KAnCRNUXRuLgRZf7b9I+HhxGISoNng==
 =/bBL
 -----END PGP SIGNATURE-----

Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging

Pull request

# -----BEGIN PGP SIGNATURE-----
#
# iQEzBAABCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmW5b1IACgkQnKSrs4Gr
# c8geoQf8DU8Z8jlvy1luuBZLq3R7hnC7c3Wzje0atLGP++pX6QUXfAgGDsTTIQeh
# XWmkFhbOBurhToH8YpgPyNG8ZWYd9+NIvLnIJiWDklNDZg2zC00aOi8yBEbsgyFb
# 50HJA30AAHq8PuctCzhGhENLxvBvNDNME74SwYH7FSIK5x/nA1XBHDZsjst1/Hk2
# 1loLbVWElbU28Xll7hI862SAb8RULC/sRQomkQAhpydxq4TApNuRwvpRfPNFwFJ0
# +dCquCJEfV6wfD62xg2CBGA5DrD9T7ADxmCYl4DQyp3HIRKXAptjgLsx3aZaIr1z
# KAnCRNUXRuLgRZf7b9I+HhxGISoNng==
# =/bBL
# -----END PGP SIGNATURE-----
# gpg: Signature made Tue 30 Jan 2024 21:51:14 GMT
# gpg:                using RSA key 8695A8BFD3F97CDAAC35775A9CA4ABB381AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" [full]
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>" [full]
# Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35  775A 9CA4 ABB3 81AB 73C8

* tag 'block-pull-request' of https://gitlab.com/stefanha/qemu:
  hw/block/block.c: improve confusing blk_check_size_and_read_all() error
  hw/core/qdev.c: add qdev_get_human_name()
  pflash: fix sectors vs bytes confusion in blk_pread_nonzeroes()
  block/blkio: Make s->mem_region_alignment be 64 bits
  block/io_uring: improve error message when init fails

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
master
Peter Maydell 2024-01-31 19:53:33 +00:00
commit 24f920ad5a
9 changed files with 47 additions and 19 deletions

View File

@ -68,7 +68,7 @@ typedef struct {
CoQueue bounce_available;
/* The value of the "mem-region-alignment" property */
size_t mem_region_alignment;
uint64_t mem_region_alignment;
/* Can we skip adding/deleting blkio_mem_regions? */
bool needs_mem_regions;

View File

@ -432,7 +432,7 @@ LuringState *luring_init(Error **errp)
rc = io_uring_queue_init(MAX_ENTRIES, ring, 0);
if (rc < 0) {
error_setg_errno(errp, errno, "failed to init linux io_uring ring");
error_setg_errno(errp, -rc, "failed to init linux io_uring ring");
g_free(s);
return NULL;
}

View File

@ -30,7 +30,7 @@ static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf)
BlockDriverState *bs = blk_bs(blk);
for (;;) {
bytes = MIN(size - offset, BDRV_REQUEST_MAX_SECTORS);
bytes = MIN(size - offset, BDRV_REQUEST_MAX_BYTES);
if (bytes <= 0) {
return 0;
}
@ -54,29 +54,30 @@ static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf)
* BDRV_REQUEST_MAX_BYTES.
* On success, return true.
* On failure, store an error through @errp and return false.
* Note that the error messages do not identify the block backend.
* TODO Since callers don't either, this can result in confusing
* errors.
*
* This function not intended for actual block devices, which read on
* demand. It's for things like memory devices that (ab)use a block
* backend to provide persistence.
*/
bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size,
Error **errp)
bool blk_check_size_and_read_all(BlockBackend *blk, DeviceState *dev,
void *buf, hwaddr size, Error **errp)
{
int64_t blk_len;
int ret;
g_autofree char *dev_id = NULL;
blk_len = blk_getlength(blk);
if (blk_len < 0) {
error_setg_errno(errp, -blk_len,
"can't get size of block backend");
"can't get size of %s block backend", blk_name(blk));
return false;
}
if (blk_len != size) {
error_setg(errp, "device requires %" HWADDR_PRIu " bytes, "
"block backend provides %" PRIu64 " bytes",
size, blk_len);
dev_id = qdev_get_human_name(dev);
error_setg(errp, "%s device '%s' requires %" HWADDR_PRIu
" bytes, %s block backend provides %" PRIu64 " bytes",
object_get_typename(OBJECT(dev)), dev_id, size,
blk_name(blk), blk_len);
return false;
}
@ -89,7 +90,11 @@ bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size,
assert(size <= BDRV_REQUEST_MAX_BYTES);
ret = blk_pread_nonzeroes(blk, size, buf);
if (ret < 0) {
error_setg_errno(errp, -ret, "can't read block backend");
dev_id = qdev_get_human_name(dev);
error_setg_errno(errp, -ret, "can't read %s block backend"
" for %s device '%s'",
blk_name(blk), object_get_typename(OBJECT(dev)),
dev_id);
return false;
}
return true;

View File

@ -1617,7 +1617,8 @@ static void m25p80_realize(SSIPeripheral *ss, Error **errp)
trace_m25p80_binding(s);
s->storage = blk_blockalign(s->blk, s->size);
if (!blk_check_size_and_read_all(s->blk, s->storage, s->size, errp)) {
if (!blk_check_size_and_read_all(s->blk, DEVICE(s),
s->storage, s->size, errp)) {
return;
}
} else {

View File

@ -848,8 +848,8 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
}
if (pfl->blk) {
if (!blk_check_size_and_read_all(pfl->blk, pfl->storage, total_len,
errp)) {
if (!blk_check_size_and_read_all(pfl->blk, dev, pfl->storage,
total_len, errp)) {
vmstate_unregister_ram(&pfl->mem, DEVICE(pfl));
return;
}

View File

@ -902,7 +902,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
}
if (pfl->blk) {
if (!blk_check_size_and_read_all(pfl->blk, pfl->storage,
if (!blk_check_size_and_read_all(pfl->blk, dev, pfl->storage,
pfl->chip_len, errp)) {
vmstate_unregister_ram(&pfl->orig_mem, DEVICE(pfl));
return;

View File

@ -879,6 +879,14 @@ Object *qdev_get_machine(void)
return dev;
}
char *qdev_get_human_name(DeviceState *dev)
{
g_assert(dev != NULL);
return dev->id ?
g_strdup(dev->id) : object_get_canonical_path(OBJECT(dev));
}
static MachineInitPhase machine_phase;
bool phase_check(MachineInitPhase phase)

View File

@ -88,8 +88,8 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
/* Backend access helpers */
bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size,
Error **errp);
bool blk_check_size_and_read_all(BlockBackend *blk, DeviceState *dev,
void *buf, hwaddr size, Error **errp);
/* Configuration helpers */

View File

@ -993,6 +993,20 @@ const char *qdev_fw_name(DeviceState *dev);
void qdev_assert_realized_properly(void);
Object *qdev_get_machine(void);
/**
* qdev_get_human_name() - Return a human-readable name for a device
* @dev: The device. Must be a valid and non-NULL pointer.
*
* .. note::
* This function is intended for user friendly error messages.
*
* Returns: A newly allocated string containing the device id if not null,
* else the object canonical path.
*
* Use g_free() to free it.
*/
char *qdev_get_human_name(DeviceState *dev);
/* FIXME: make this a link<> */
bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp);