提交 2ac20613 编写于 作者: L Luiz Capitulino

qemu-config: find_list(): use error_set()

Note that qemu_find_opts() and qemu_config_parse() need to call
error_report() to maintain their semantics on error.
Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
Reviewed-By: NLaszlo Ersek <lersek@redhat.com>
上级 8ff15d4a
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "qemu-option.h" #include "qemu-option.h"
#include "qemu-config.h" #include "qemu-config.h"
#include "hw/qdev.h" #include "hw/qdev.h"
#include "error.h"
static QemuOptsList qemu_drive_opts = { static QemuOptsList qemu_drive_opts = {
.name = "drive", .name = "drive",
...@@ -631,7 +632,8 @@ static QemuOptsList *vm_config_groups[32] = { ...@@ -631,7 +632,8 @@ static QemuOptsList *vm_config_groups[32] = {
NULL, NULL,
}; };
static QemuOptsList *find_list(QemuOptsList **lists, const char *group) static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
Error **errp)
{ {
int i; int i;
...@@ -640,14 +642,23 @@ static QemuOptsList *find_list(QemuOptsList **lists, const char *group) ...@@ -640,14 +642,23 @@ static QemuOptsList *find_list(QemuOptsList **lists, const char *group)
break; break;
} }
if (lists[i] == NULL) { if (lists[i] == NULL) {
error_report("there is no option group \"%s\"", group); error_set(errp, QERR_INVALID_OPTION_GROUP, group);
} }
return lists[i]; return lists[i];
} }
QemuOptsList *qemu_find_opts(const char *group) QemuOptsList *qemu_find_opts(const char *group)
{ {
return find_list(vm_config_groups, group); QemuOptsList *ret;
Error *local_err = NULL;
ret = find_list(vm_config_groups, group, &local_err);
if (error_is_set(&local_err)) {
error_report("%s\n", error_get_pretty(local_err));
error_free(local_err);
}
return ret;
} }
void qemu_add_opts(QemuOptsList *list) void qemu_add_opts(QemuOptsList *list)
...@@ -762,6 +773,7 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) ...@@ -762,6 +773,7 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
char line[1024], group[64], id[64], arg[64], value[1024]; char line[1024], group[64], id[64], arg[64], value[1024];
Location loc; Location loc;
QemuOptsList *list = NULL; QemuOptsList *list = NULL;
Error *local_err = NULL;
QemuOpts *opts = NULL; QemuOpts *opts = NULL;
int res = -1, lno = 0; int res = -1, lno = 0;
...@@ -778,17 +790,23 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) ...@@ -778,17 +790,23 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
} }
if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) { if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) {
/* group with id */ /* group with id */
list = find_list(lists, group); list = find_list(lists, group, &local_err);
if (list == NULL) if (error_is_set(&local_err)) {
error_report("%s\n", error_get_pretty(local_err));
error_free(local_err);
goto out; goto out;
}
opts = qemu_opts_create(list, id, 1, NULL); opts = qemu_opts_create(list, id, 1, NULL);
continue; continue;
} }
if (sscanf(line, "[%63[^]]]", group) == 1) { if (sscanf(line, "[%63[^]]]", group) == 1) {
/* group without id */ /* group without id */
list = find_list(lists, group); list = find_list(lists, group, &local_err);
if (list == NULL) if (error_is_set(&local_err)) {
error_report("%s\n", error_get_pretty(local_err));
error_free(local_err);
goto out; goto out;
}
opts = qemu_opts_create(list, NULL, 0, NULL); opts = qemu_opts_create(list, NULL, 0, NULL);
continue; continue;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册