2 * Block utility functions
4 * Copyright IBM, Corp. 2011
5 * Copyright (c) 2020 Coiby Xu <coiby.xu@gmail.com>
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
12 #include "qapi/error.h"
13 #include "qapi/qmp/qerror.h"
14 #include "block-helpers.h"
18 * @id: The unique ID of the object
19 * @name: The name of the property being validated
20 * @value: The block size in bytes
21 * @errp: A pointer to an area to store an error
23 * This function checks that the block size meets the following conditions:
24 * 1. At least MIN_BLOCK_SIZE
25 * 2. No larger than MAX_BLOCK_SIZE
28 void check_block_size(const char *id
, const char *name
, int64_t value
,
31 /* value of 0 means "unset" */
32 if (value
&& (value
< MIN_BLOCK_SIZE
|| value
> MAX_BLOCK_SIZE
)) {
33 error_setg(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
,
34 id
, name
, value
, MIN_BLOCK_SIZE
, MAX_BLOCK_SIZE
);
38 /* We rely on power-of-2 blocksizes for bitmasks */
39 if ((value
& (value
- 1)) != 0) {
41 "Property %s.%s doesn't take value '%" PRId64
42 "', it's not a power of 2",