block: Factor out qobject_input_visitor_new_flat_confused()

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Markus Armbruster 2018-06-14 21:14:33 +02:00 committed by Kevin Wolf
parent 92adf9dbcd
commit af91062ee1
13 changed files with 53 additions and 62 deletions

View file

@ -263,7 +263,6 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
{
SocketAddress *saddr = NULL;
QDict *addr = NULL;
QObject *crumpled_addr = NULL;
Visitor *iv = NULL;
Error *local_err = NULL;
@ -273,12 +272,11 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
goto done;
}
crumpled_addr = qdict_crumple_for_keyval_qiv(addr, errp);
if (!crumpled_addr) {
iv = qobject_input_visitor_new_flat_confused(addr, errp);
if (!iv) {
goto done;
}
iv = qobject_input_visitor_new_keyval(crumpled_addr);
visit_type_SocketAddress(iv, NULL, &saddr, &local_err);
if (local_err) {
error_propagate(errp, local_err);
@ -287,7 +285,6 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options,
done:
qobject_unref(addr);
qobject_unref(crumpled_addr);
visit_free(iv);
return saddr;
}

View file

@ -556,20 +556,17 @@ static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options,
Error **errp)
{
BlockdevOptionsNfs *opts = NULL;
QObject *crumpled = NULL;
Visitor *v;
const QDictEntry *e;
Error *local_err = NULL;
crumpled = qdict_crumple_for_keyval_qiv(options, errp);
if (crumpled == NULL) {
v = qobject_input_visitor_new_flat_confused(options, errp);
if (!v) {
return NULL;
}
v = qobject_input_visitor_new_keyval(crumpled);
visit_type_BlockdevOptionsNfs(v, NULL, &opts, &local_err);
visit_free(v);
qobject_unref(crumpled);
if (local_err) {
error_propagate(errp, local_err);

View file

@ -617,7 +617,6 @@ static int coroutine_fn parallels_co_create_opts(const char *filename,
Error *local_err = NULL;
BlockDriverState *bs = NULL;
QDict *qdict;
QObject *qobj;
Visitor *v;
int ret;
@ -653,14 +652,12 @@ static int coroutine_fn parallels_co_create_opts(const char *filename,
qdict_put_str(qdict, "driver", "parallels");
qdict_put_str(qdict, "file", bs->node_name);
qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
if (!qobj) {
v = qobject_input_visitor_new_flat_confused(qdict, errp);
if (!v) {
ret = -EINVAL;
goto done;
}
v = qobject_input_visitor_new_keyval(qobj);
qobject_unref(qobj);
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
visit_free(v);

View file

@ -947,7 +947,6 @@ static int coroutine_fn qcow_co_create_opts(const char *filename,
BlockdevCreateOptions *create_options = NULL;
BlockDriverState *bs = NULL;
QDict *qdict;
QObject *qobj;
Visitor *v;
const char *val;
Error *local_err = NULL;
@ -997,14 +996,12 @@ static int coroutine_fn qcow_co_create_opts(const char *filename,
qdict_put_str(qdict, "driver", "qcow");
qdict_put_str(qdict, "file", bs->node_name);
qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
if (!qobj) {
v = qobject_input_visitor_new_flat_confused(qdict, errp);
if (!v) {
ret = -EINVAL;
goto fail;
}
v = qobject_input_visitor_new_keyval(qobj);
qobject_unref(qobj);
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
visit_free(v);

View file

@ -3081,7 +3081,6 @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt
{
BlockdevCreateOptions *create_options = NULL;
QDict *qdict;
QObject *qobj;
Visitor *v;
BlockDriverState *bs = NULL;
Error *local_err = NULL;
@ -3152,14 +3151,12 @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt
qdict_put_str(qdict, "file", bs->node_name);
/* Now get the QAPI type BlockdevCreateOptions */
qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
if (!qobj) {
v = qobject_input_visitor_new_flat_confused(qdict, errp);
if (!v) {
ret = -EINVAL;
goto finish;
}
v = qobject_input_visitor_new_keyval(qobj);
qobject_unref(qobj);
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
visit_free(v);

View file

@ -723,7 +723,6 @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename,
{
BlockdevCreateOptions *create_options = NULL;
QDict *qdict;
QObject *qobj;
Visitor *v;
BlockDriverState *bs = NULL;
Error *local_err = NULL;
@ -763,14 +762,12 @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename,
qdict_put_str(qdict, "driver", "qed");
qdict_put_str(qdict, "file", bs->node_name);
qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
if (!qobj) {
v = qobject_input_visitor_new_flat_confused(qdict, errp);
if (!v) {
ret = -EINVAL;
goto fail;
}
v = qobject_input_visitor_new_keyval(qobj);
qobject_unref(qobj);
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
visit_free(v);

View file

@ -630,7 +630,6 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
BDRVRBDState *s = bs->opaque;
BlockdevOptionsRbd *opts = NULL;
Visitor *v;
QObject *crumpled = NULL;
const QDictEntry *e;
Error *local_err = NULL;
char *keypairs, *secretid;
@ -647,16 +646,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
}
/* Convert the remaining options into a QAPI object */
crumpled = qdict_crumple_for_keyval_qiv(options, errp);
if (crumpled == NULL) {
v = qobject_input_visitor_new_flat_confused(options, errp);
if (!v) {
r = -EINVAL;
goto out;
}
v = qobject_input_visitor_new_keyval(crumpled);
visit_type_BlockdevOptionsRbd(v, NULL, &opts, &local_err);
visit_free(v);
qobject_unref(crumpled);
if (local_err) {
error_propagate(errp, local_err);

View file

@ -539,19 +539,17 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s,
static SocketAddress *sd_server_config(QDict *options, Error **errp)
{
QDict *server = NULL;
QObject *crumpled_server = NULL;
Visitor *iv = NULL;
SocketAddress *saddr = NULL;
Error *local_err = NULL;
qdict_extract_subqdict(options, &server, "server.");
crumpled_server = qdict_crumple_for_keyval_qiv(server, errp);
if (!crumpled_server) {
iv = qobject_input_visitor_new_flat_confused(server, errp);
if (!iv) {
goto done;
}
iv = qobject_input_visitor_new_keyval(crumpled_server);
visit_type_SocketAddress(iv, NULL, &saddr, &local_err);
if (local_err) {
error_propagate(errp, local_err);
@ -560,7 +558,6 @@ static SocketAddress *sd_server_config(QDict *options, Error **errp)
done:
visit_free(iv);
qobject_unref(crumpled_server);
qobject_unref(server);
return saddr;
}
@ -2173,7 +2170,6 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
{
BlockdevCreateOptions *create_options = NULL;
QDict *qdict, *location_qdict;
QObject *crumpled;
Visitor *v;
char *redundancy;
Error *local_err = NULL;
@ -2209,16 +2205,14 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
}
/* Get the QAPI object */
crumpled = qdict_crumple_for_keyval_qiv(qdict, errp);
if (crumpled == NULL) {
v = qobject_input_visitor_new_flat_confused(qdict, errp);
if (!v) {
ret = -EINVAL;
goto fail;
}
v = qobject_input_visitor_new_keyval(crumpled);
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
visit_free(v);
qobject_unref(crumpled);
if (local_err) {
error_propagate(errp, local_err);

View file

@ -606,7 +606,6 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp)
BlockdevOptionsSsh *result = NULL;
QemuOpts *opts = NULL;
Error *local_err = NULL;
QObject *crumpled;
const QDictEntry *e;
Visitor *v;
@ -623,15 +622,13 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp)
}
/* Create the QAPI object */
crumpled = qdict_crumple_for_keyval_qiv(options, errp);
if (crumpled == NULL) {
v = qobject_input_visitor_new_flat_confused(options, errp);
if (!v) {
goto fail;
}
v = qobject_input_visitor_new_keyval(crumpled);
visit_type_BlockdevOptionsSsh(v, NULL, &result, &local_err);
visit_free(v);
qobject_unref(crumpled);
if (local_err) {
error_propagate(errp, local_err);

View file

@ -1966,7 +1966,6 @@ static int coroutine_fn vhdx_co_create_opts(const char *filename,
{
BlockdevCreateOptions *create_options = NULL;
QDict *qdict;
QObject *qobj;
Visitor *v;
BlockDriverState *bs = NULL;
Error *local_err = NULL;
@ -2005,14 +2004,12 @@ static int coroutine_fn vhdx_co_create_opts(const char *filename,
qdict_put_str(qdict, "driver", "vhdx");
qdict_put_str(qdict, "file", bs->node_name);
qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
if (!qobj) {
v = qobject_input_visitor_new_flat_confused(qdict, errp);
if (!v) {
ret = -EINVAL;
goto fail;
}
v = qobject_input_visitor_new_keyval(qobj);
qobject_unref(qobj);
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
visit_free(v);

View file

@ -1082,7 +1082,6 @@ static int coroutine_fn vpc_co_create_opts(const char *filename,
{
BlockdevCreateOptions *create_options = NULL;
QDict *qdict;
QObject *qobj;
Visitor *v;
BlockDriverState *bs = NULL;
Error *local_err = NULL;
@ -1119,14 +1118,12 @@ static int coroutine_fn vpc_co_create_opts(const char *filename,
qdict_put_str(qdict, "driver", "vpc");
qdict_put_str(qdict, "file", bs->node_name);
qobj = qdict_crumple_for_keyval_qiv(qdict, errp);
if (!qobj) {
v = qobject_input_visitor_new_flat_confused(qdict, errp);
if (!v) {
ret = -EINVAL;
goto fail;
}
v = qobject_input_visitor_new_keyval(qobj);
qobject_unref(qobj);
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
visit_free(v);

View file

@ -21,7 +21,6 @@ void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start);
void qdict_array_split(QDict *src, QList **dst);
int qdict_array_entries(QDict *src, const char *subqdict);
QObject *qdict_crumple(const QDict *src, Error **errp);
QObject *qdict_crumple_for_keyval_qiv(QDict *qdict, Error **errp);
void qdict_flatten(QDict *qdict);
typedef struct QDictRenames {
@ -30,4 +29,6 @@ typedef struct QDictRenames {
} QDictRenames;
bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp);
Visitor *qobject_input_visitor_new_flat_confused(QDict *qdict,
Error **errp);
#endif

View file

@ -13,6 +13,7 @@
#include "qapi/qmp/qlist.h"
#include "qapi/qmp/qnum.h"
#include "qapi/qmp/qstring.h"
#include "qapi/qobject-input-visitor.h"
#include "qemu/cutils.h"
#include "qapi/error.h"
@ -529,7 +530,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
* used for anything else, and it should go away once the block
* subsystem has been cleaned up.
*/
QObject *qdict_crumple_for_keyval_qiv(QDict *src, Error **errp)
static QObject *qdict_crumple_for_keyval_qiv(QDict *src, Error **errp)
{
QDict *tmp = NULL;
char *buf;
@ -695,3 +696,28 @@ bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp)
}
return true;
}
/*
* Create a QObject input visitor for flat @qdict with possibly
* confused scalar types.
*
* The block subsystem uses this function to visit its flat QDict with
* possibly confused scalar types. It should not be used for anything
* else, and it should go away once the block subsystem has been
* cleaned up.
*/
Visitor *qobject_input_visitor_new_flat_confused(QDict *qdict,
Error **errp)
{
QObject *crumpled;
Visitor *v;
crumpled = qdict_crumple_for_keyval_qiv(qdict, errp);
if (!crumpled) {
return NULL;
}
v = qobject_input_visitor_new_keyval(crumpled);
qobject_unref(crumpled);
return v;
}