block/qcow2: read_cache_sizes: return status value
It's better to return status together with setting errp. It allows to reduce error propagation. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Greg Kurz <groug@kaod.org> Reviewed-by: Alberto Garcia <berto@igalia.com> Message-Id: <20210202124956.63146-12-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
526e31de99
commit
772c4cad13
@ -868,7 +868,7 @@ static void qcow2_attach_aio_context(BlockDriverState *bs,
|
|||||||
cache_clean_timer_init(bs, new_context);
|
cache_clean_timer_init(bs, new_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
|
static bool read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
|
||||||
uint64_t *l2_cache_size,
|
uint64_t *l2_cache_size,
|
||||||
uint64_t *l2_cache_entry_size,
|
uint64_t *l2_cache_entry_size,
|
||||||
uint64_t *refcount_cache_size, Error **errp)
|
uint64_t *refcount_cache_size, Error **errp)
|
||||||
@ -906,16 +906,16 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
|
|||||||
error_setg(errp, QCOW2_OPT_CACHE_SIZE ", " QCOW2_OPT_L2_CACHE_SIZE
|
error_setg(errp, QCOW2_OPT_CACHE_SIZE ", " QCOW2_OPT_L2_CACHE_SIZE
|
||||||
" and " QCOW2_OPT_REFCOUNT_CACHE_SIZE " may not be set "
|
" and " QCOW2_OPT_REFCOUNT_CACHE_SIZE " may not be set "
|
||||||
"at the same time");
|
"at the same time");
|
||||||
return;
|
return false;
|
||||||
} else if (l2_cache_size_set &&
|
} else if (l2_cache_size_set &&
|
||||||
(l2_cache_max_setting > combined_cache_size)) {
|
(l2_cache_max_setting > combined_cache_size)) {
|
||||||
error_setg(errp, QCOW2_OPT_L2_CACHE_SIZE " may not exceed "
|
error_setg(errp, QCOW2_OPT_L2_CACHE_SIZE " may not exceed "
|
||||||
QCOW2_OPT_CACHE_SIZE);
|
QCOW2_OPT_CACHE_SIZE);
|
||||||
return;
|
return false;
|
||||||
} else if (*refcount_cache_size > combined_cache_size) {
|
} else if (*refcount_cache_size > combined_cache_size) {
|
||||||
error_setg(errp, QCOW2_OPT_REFCOUNT_CACHE_SIZE " may not exceed "
|
error_setg(errp, QCOW2_OPT_REFCOUNT_CACHE_SIZE " may not exceed "
|
||||||
QCOW2_OPT_CACHE_SIZE);
|
QCOW2_OPT_CACHE_SIZE);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l2_cache_size_set) {
|
if (l2_cache_size_set) {
|
||||||
@ -954,8 +954,10 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
|
|||||||
error_setg(errp, "L2 cache entry size must be a power of two "
|
error_setg(errp, "L2 cache entry size must be a power of two "
|
||||||
"between %d and the cluster size (%d)",
|
"between %d and the cluster size (%d)",
|
||||||
1 << MIN_CLUSTER_BITS, s->cluster_size);
|
1 << MIN_CLUSTER_BITS, s->cluster_size);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct Qcow2ReopenState {
|
typedef struct Qcow2ReopenState {
|
||||||
@ -982,7 +984,6 @@ static int qcow2_update_options_prepare(BlockDriverState *bs,
|
|||||||
int i;
|
int i;
|
||||||
const char *encryptfmt;
|
const char *encryptfmt;
|
||||||
QDict *encryptopts = NULL;
|
QDict *encryptopts = NULL;
|
||||||
Error *local_err = NULL;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
qdict_extract_subqdict(options, &encryptopts, "encrypt.");
|
qdict_extract_subqdict(options, &encryptopts, "encrypt.");
|
||||||
@ -995,10 +996,8 @@ static int qcow2_update_options_prepare(BlockDriverState *bs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* get L2 table/refcount block cache size from command line options */
|
/* get L2 table/refcount block cache size from command line options */
|
||||||
read_cache_sizes(bs, opts, &l2_cache_size, &l2_cache_entry_size,
|
if (!read_cache_sizes(bs, opts, &l2_cache_size, &l2_cache_entry_size,
|
||||||
&refcount_cache_size, &local_err);
|
&refcount_cache_size, errp)) {
|
||||||
if (local_err) {
|
|
||||||
error_propagate(errp, local_err);
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user