mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-11 03:24:58 -06:00
quorum: Use bdrv_open_image()
Besides standardising on a single interface for opening child nodes, this simplifies the .bdrv_open() implementation of the quorum block driver by using block layer functionality for handling BlockdevRefs. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Jeff Cody <jcody@redhat.com> Reviewed-by: Alberto Garcia <berto@igalia.com>
This commit is contained in:
parent
ef1919df26
commit
ea6828d81b
1 changed files with 11 additions and 40 deletions
|
@ -866,25 +866,18 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
QemuOpts *opts = NULL;
|
QemuOpts *opts = NULL;
|
||||||
bool *opened;
|
bool *opened;
|
||||||
QDict *sub = NULL;
|
|
||||||
QList *list = NULL;
|
|
||||||
const QListEntry *lentry;
|
|
||||||
int i;
|
int i;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
qdict_flatten(options);
|
qdict_flatten(options);
|
||||||
qdict_extract_subqdict(options, &sub, "children.");
|
|
||||||
qdict_array_split(sub, &list);
|
|
||||||
|
|
||||||
if (qdict_size(sub)) {
|
/* count how many different children are present */
|
||||||
error_setg(&local_err, "Invalid option children.%s",
|
s->num_children = qdict_array_entries(options, "children.");
|
||||||
qdict_first(sub)->key);
|
if (s->num_children < 0) {
|
||||||
|
error_setg(&local_err, "Option children is not a valid array");
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count how many different children are present */
|
|
||||||
s->num_children = qlist_size(list);
|
|
||||||
if (s->num_children < 2) {
|
if (s->num_children < 2) {
|
||||||
error_setg(&local_err,
|
error_setg(&local_err,
|
||||||
"Number of provided children must be greater than 1");
|
"Number of provided children must be greater than 1");
|
||||||
|
@ -937,37 +930,17 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
s->bs = g_new0(BlockDriverState *, s->num_children);
|
s->bs = g_new0(BlockDriverState *, s->num_children);
|
||||||
opened = g_new0(bool, s->num_children);
|
opened = g_new0(bool, s->num_children);
|
||||||
|
|
||||||
for (i = 0, lentry = qlist_first(list); lentry;
|
for (i = 0; i < s->num_children; i++) {
|
||||||
lentry = qlist_next(lentry), i++) {
|
char indexstr[32];
|
||||||
QDict *d;
|
ret = snprintf(indexstr, 32, "children.%d", i);
|
||||||
QString *string;
|
assert(ret < 32);
|
||||||
|
|
||||||
switch (qobject_type(lentry->value))
|
|
||||||
{
|
|
||||||
/* List of options */
|
|
||||||
case QTYPE_QDICT:
|
|
||||||
d = qobject_to_qdict(lentry->value);
|
|
||||||
QINCREF(d);
|
|
||||||
ret = bdrv_open(&s->bs[i], NULL, NULL, d, flags, NULL,
|
|
||||||
&local_err);
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* QMP reference */
|
|
||||||
case QTYPE_QSTRING:
|
|
||||||
string = qobject_to_qstring(lentry->value);
|
|
||||||
ret = bdrv_open(&s->bs[i], NULL, qstring_get_str(string), NULL,
|
|
||||||
flags, NULL, &local_err);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
error_setg(&local_err, "Specification of child block device %i "
|
|
||||||
"is invalid", i);
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ret = bdrv_open_image(&s->bs[i], NULL, options, indexstr, flags,
|
||||||
|
false, &local_err);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto close_exit;
|
goto close_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
opened[i] = true;
|
opened[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -990,8 +963,6 @@ exit:
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
}
|
}
|
||||||
QDECREF(list);
|
|
||||||
QDECREF(sub);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue