mirror of
https://github.com/qemu/qemu.git
synced 2024-11-28 06:13:46 +08:00
QemuOpts: Convert qemu_opt_foreach() to Error
Retain the function value for now, to permit selective conversion of its callers. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
1640b200d5
commit
71df1d8337
@ -100,8 +100,11 @@ void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
|
|||||||
Error **errp);
|
Error **errp);
|
||||||
void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
|
void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque);
|
typedef int (*qemu_opt_loopfunc)(void *opaque,
|
||||||
int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque);
|
const char *name, const char *value,
|
||||||
|
Error **errp);
|
||||||
|
int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
|
||||||
|
Error **errp);
|
||||||
|
|
||||||
QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
|
QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
|
||||||
QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
|
QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
|
||||||
|
@ -157,8 +157,9 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int net_vhost_chardev_opts(const char *name, const char *value,
|
static int net_vhost_chardev_opts(void *opaque,
|
||||||
void *opaque)
|
const char *name, const char *value,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
VhostUserChardevProps *props = opaque;
|
VhostUserChardevProps *props = opaque;
|
||||||
|
|
||||||
@ -189,7 +190,7 @@ static CharDriverState *net_vhost_parse_chardev(const NetdevVhostUserOptions *op
|
|||||||
|
|
||||||
/* inspect chardev opts */
|
/* inspect chardev opts */
|
||||||
memset(&props, 0, sizeof(props));
|
memset(&props, 0, sizeof(props));
|
||||||
if (qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props)) {
|
if (qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props, NULL)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,8 @@ static void qdev_print_devinfos(bool show_no_user)
|
|||||||
g_slist_free(list);
|
g_slist_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_property(const char *name, const char *value, void *opaque)
|
static int set_property(void *opaque, const char *name, const char *value,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
Object *obj = opaque;
|
Object *obj = opaque;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
@ -564,7 +565,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set properties */
|
/* set properties */
|
||||||
if (qemu_opt_foreach(opts, set_property, dev)) {
|
if (qemu_opt_foreach(opts, set_property, dev, NULL)) {
|
||||||
object_unparent(OBJECT(dev));
|
object_unparent(OBJECT(dev));
|
||||||
object_unref(OBJECT(dev));
|
object_unref(OBJECT(dev));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -583,7 +583,8 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_channel(const char *name, const char *value, void *opaque)
|
static int add_channel(void *opaque, const char *name, const char *value,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
int security = 0;
|
int security = 0;
|
||||||
int rc;
|
int rc;
|
||||||
@ -782,7 +783,7 @@ void qemu_spice_init(void)
|
|||||||
spice_server_set_playback_compression
|
spice_server_set_playback_compression
|
||||||
(spice_server, qemu_opt_get_bool(opts, "playback-compression", 1));
|
(spice_server, qemu_opt_get_bool(opts, "playback-compression", 1));
|
||||||
|
|
||||||
qemu_opt_foreach(opts, add_channel, &tls_port);
|
qemu_opt_foreach(opts, add_channel, &tls_port, NULL);
|
||||||
|
|
||||||
spice_server_set_name(spice_server, qemu_name);
|
spice_server_set_name(spice_server, qemu_name);
|
||||||
spice_server_set_uuid(spice_server, qemu_uuid);
|
spice_server_set_uuid(spice_server, qemu_uuid);
|
||||||
|
@ -335,7 +335,8 @@ struct ConfigWriteData {
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int config_write_opt(const char *name, const char *value, void *opaque)
|
static int config_write_opt(void *opaque, const char *name, const char *value,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
struct ConfigWriteData *data = opaque;
|
struct ConfigWriteData *data = opaque;
|
||||||
|
|
||||||
@ -353,7 +354,7 @@ static int config_write_opts(void *opaque, QemuOpts *opts, Error **errp)
|
|||||||
} else {
|
} else {
|
||||||
fprintf(data->fp, "[%s]\n", data->list->name);
|
fprintf(data->fp, "[%s]\n", data->list->name);
|
||||||
}
|
}
|
||||||
qemu_opt_foreach(opts, config_write_opt, data);
|
qemu_opt_foreach(opts, config_write_opt, data, NULL);
|
||||||
fprintf(data->fp, "\n");
|
fprintf(data->fp, "\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -597,20 +597,23 @@ void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For each member of @opts, call @func(name, value, @opaque).
|
* For each member of @opts, call @func(@opaque, name, value, @errp).
|
||||||
|
* @func() may store an Error through @errp, but must return non-zero then.
|
||||||
* When @func() returns non-zero, break the loop and return that value.
|
* When @func() returns non-zero, break the loop and return that value.
|
||||||
* Return zero when the loop completes.
|
* Return zero when the loop completes.
|
||||||
*/
|
*/
|
||||||
int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque)
|
int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
QemuOpt *opt;
|
QemuOpt *opt;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
QTAILQ_FOREACH(opt, &opts->head, next) {
|
QTAILQ_FOREACH(opt, &opts->head, next) {
|
||||||
rc = func(opt->name, opt->str, opaque);
|
rc = func(opaque, opt->name, opt->str, errp);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
assert(!errp || !*errp);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
9
vl.c
9
vl.c
@ -2576,8 +2576,9 @@ static void free_and_trace(gpointer mem)
|
|||||||
free(mem);
|
free(mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int machine_set_property(const char *name, const char *value,
|
static int machine_set_property(void *opaque,
|
||||||
void *opaque)
|
const char *name, const char *value,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
Object *obj = OBJECT(opaque);
|
Object *obj = OBJECT(opaque);
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
@ -4070,8 +4071,8 @@ int main(int argc, char **argv, char **envp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
machine_opts = qemu_get_machine_opts();
|
machine_opts = qemu_get_machine_opts();
|
||||||
if (qemu_opt_foreach(machine_opts, machine_set_property,
|
if (qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
|
||||||
current_machine)) {
|
NULL)) {
|
||||||
object_unref(OBJECT(current_machine));
|
object_unref(OBJECT(current_machine));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user