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:
parent
0f799b83bd
commit
5551449bb8
@ -273,7 +273,6 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
|
|||||||
uint64_t logical_block_size = VIRTIO_BLK_SECTOR_SIZE;
|
uint64_t logical_block_size = VIRTIO_BLK_SECTOR_SIZE;
|
||||||
uint16_t num_queues = VDUSE_DEFAULT_NUM_QUEUE;
|
uint16_t num_queues = VDUSE_DEFAULT_NUM_QUEUE;
|
||||||
uint16_t queue_size = VDUSE_DEFAULT_QUEUE_SIZE;
|
uint16_t queue_size = VDUSE_DEFAULT_QUEUE_SIZE;
|
||||||
Error *local_err = NULL;
|
|
||||||
struct virtio_blk_config config = { 0 };
|
struct virtio_blk_config config = { 0 };
|
||||||
uint64_t features;
|
uint64_t features;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
@ -297,10 +296,8 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
|
|||||||
|
|
||||||
if (vblk_opts->has_logical_block_size) {
|
if (vblk_opts->has_logical_block_size) {
|
||||||
logical_block_size = vblk_opts->logical_block_size;
|
logical_block_size = vblk_opts->logical_block_size;
|
||||||
check_block_size(exp->id, "logical-block-size", logical_block_size,
|
if (!check_block_size("logical-block-size", logical_block_size,
|
||||||
&local_err);
|
errp)) {
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,7 +319,6 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
|
|||||||
{
|
{
|
||||||
VuBlkExport *vexp = container_of(exp, VuBlkExport, export);
|
VuBlkExport *vexp = container_of(exp, VuBlkExport, export);
|
||||||
BlockExportOptionsVhostUserBlk *vu_opts = &opts->u.vhost_user_blk;
|
BlockExportOptionsVhostUserBlk *vu_opts = &opts->u.vhost_user_blk;
|
||||||
Error *local_err = NULL;
|
|
||||||
uint64_t logical_block_size;
|
uint64_t logical_block_size;
|
||||||
uint16_t num_queues = VHOST_USER_BLK_NUM_QUEUES_DEFAULT;
|
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 {
|
} else {
|
||||||
logical_block_size = VIRTIO_BLK_SECTOR_SIZE;
|
logical_block_size = VIRTIO_BLK_SECTOR_SIZE;
|
||||||
}
|
}
|
||||||
check_block_size(exp->id, "logical-block-size", logical_block_size,
|
if (!check_block_size("logical-block-size", logical_block_size, errp)) {
|
||||||
&local_err);
|
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,18 +588,14 @@ const PropertyInfo qdev_prop_losttickpolicy = {
|
|||||||
static void set_blocksize(Object *obj, Visitor *v, const char *name,
|
static void set_blocksize(Object *obj, Visitor *v, const char *name,
|
||||||
void *opaque, Error **errp)
|
void *opaque, Error **errp)
|
||||||
{
|
{
|
||||||
DeviceState *dev = DEVICE(obj);
|
|
||||||
Property *prop = opaque;
|
Property *prop = opaque;
|
||||||
uint32_t *ptr = object_field_prop_ptr(obj, prop);
|
uint32_t *ptr = object_field_prop_ptr(obj, prop);
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
Error *local_err = NULL;
|
|
||||||
|
|
||||||
if (!visit_type_size(v, name, &value, errp)) {
|
if (!visit_type_size(v, name, &value, errp)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
check_block_size(dev->id ? : "", name, value, &local_err);
|
if (!check_block_size(name, value, errp)) {
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*ptr = value;
|
*ptr = value;
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* check_block_size:
|
* check_block_size:
|
||||||
* @id: The unique ID of the object
|
|
||||||
* @name: The name of the property being validated
|
* @name: The name of the property being validated
|
||||||
* @value: The block size in bytes
|
* @value: The block size in bytes
|
||||||
* @errp: A pointer to an area to store an error
|
* @errp: A pointer to an area to store an error
|
||||||
@ -23,13 +22,14 @@
|
|||||||
* 1. At least MIN_BLOCK_SIZE
|
* 1. At least MIN_BLOCK_SIZE
|
||||||
* 2. No larger than MAX_BLOCK_SIZE
|
* 2. No larger than MAX_BLOCK_SIZE
|
||||||
* 3. A power of 2
|
* 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,
|
bool check_block_size(const char *name, int64_t value, Error **errp)
|
||||||
Error **errp)
|
|
||||||
{
|
{
|
||||||
if (!value) {
|
if (!value) {
|
||||||
/* unset */
|
/* unset */
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE
|
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
|
"parameter %s must be a power of 2 between %" PRId64
|
||||||
" and %" PRId64,
|
" and %" PRId64,
|
||||||
name, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE);
|
name, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#define MAX_BLOCK_SIZE (2 * MiB)
|
#define MAX_BLOCK_SIZE (2 * MiB)
|
||||||
#define MAX_BLOCK_SIZE_STR "2 MiB"
|
#define MAX_BLOCK_SIZE_STR "2 MiB"
|
||||||
|
|
||||||
void check_block_size(const char *id, const char *name, int64_t value,
|
bool check_block_size(const char *name, int64_t value, Error **errp);
|
||||||
Error **errp);
|
|
||||||
|
|
||||||
#endif /* BLOCK_HELPERS_H */
|
#endif /* BLOCK_HELPERS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user