block: Adjust check_block_size() signature

Parameter @id is no longer used, drop.  Return a bool to indicate
success / failure, as recommended by qapi/error.h.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20241010150144.986655-4-armbru@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
Markus Armbruster 2024-10-10 17:01:40 +02:00
parent 0f799b83bd
commit 5551449bb8
5 changed files with 11 additions and 21 deletions

View File

@ -273,7 +273,6 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
uint64_t logical_block_size = VIRTIO_BLK_SECTOR_SIZE;
uint16_t num_queues = VDUSE_DEFAULT_NUM_QUEUE;
uint16_t queue_size = VDUSE_DEFAULT_QUEUE_SIZE;
Error *local_err = NULL;
struct virtio_blk_config config = { 0 };
uint64_t features;
int i, ret;
@ -297,10 +296,8 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
if (vblk_opts->has_logical_block_size) {
logical_block_size = vblk_opts->logical_block_size;
check_block_size(exp->id, "logical-block-size", logical_block_size,
&local_err);
if (local_err) {
error_propagate(errp, local_err);
if (!check_block_size("logical-block-size", logical_block_size,
errp)) {
return -EINVAL;
}
}

View File

@ -319,7 +319,6 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
{
VuBlkExport *vexp = container_of(exp, VuBlkExport, export);
BlockExportOptionsVhostUserBlk *vu_opts = &opts->u.vhost_user_blk;
Error *local_err = NULL;
uint64_t logical_block_size;
uint16_t num_queues = VHOST_USER_BLK_NUM_QUEUES_DEFAULT;
@ -330,10 +329,7 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
} else {
logical_block_size = VIRTIO_BLK_SECTOR_SIZE;
}
check_block_size(exp->id, "logical-block-size", logical_block_size,
&local_err);
if (local_err) {
error_propagate(errp, local_err);
if (!check_block_size("logical-block-size", logical_block_size, errp)) {
return -EINVAL;
}

View File

@ -588,18 +588,14 @@ const PropertyInfo qdev_prop_losttickpolicy = {
static void set_blocksize(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
uint32_t *ptr = object_field_prop_ptr(obj, prop);
uint64_t value;
Error *local_err = NULL;
if (!visit_type_size(v, name, &value, errp)) {
return;
}
check_block_size(dev->id ? : "", name, value, &local_err);
if (local_err) {
error_propagate(errp, local_err);
if (!check_block_size(name, value, errp)) {
return;
}
*ptr = value;

View File

@ -14,7 +14,6 @@
/**
* check_block_size:
* @id: The unique ID of the object
* @name: The name of the property being validated
* @value: The block size in bytes
* @errp: A pointer to an area to store an error
@ -23,13 +22,14 @@
* 1. At least MIN_BLOCK_SIZE
* 2. No larger than MAX_BLOCK_SIZE
* 3. A power of 2
*
* Returns: true on success, false on failure
*/
void check_block_size(const char *id, const char *name, int64_t value,
Error **errp)
bool check_block_size(const char *name, int64_t value, Error **errp)
{
if (!value) {
/* unset */
return;
return true;
}
if (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE
@ -38,5 +38,7 @@ void check_block_size(const char *id, const char *name, int64_t value,
"parameter %s must be a power of 2 between %" PRId64
" and %" PRId64,
name, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE);
return false;
}
return true;
}

View File

@ -13,7 +13,6 @@
#define MAX_BLOCK_SIZE (2 * MiB)
#define MAX_BLOCK_SIZE_STR "2 MiB"
void check_block_size(const char *id, const char *name, int64_t value,
Error **errp);
bool check_block_size(const char *name, int64_t value, Error **errp);
#endif /* BLOCK_HELPERS_H */