提交 a61ae7f8 编写于 作者: P Peter Maydell

qemu-char: Remove register_char_driver() machinery

Now that all the char backends have been converted to the QAPI
framework we can remove the machinery for handling old style
backends.
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
Message-id: 1409653457-27863-5-git-send-email-peter.maydell@linaro.org
上级 90a14bfe
...@@ -344,7 +344,6 @@ bool chr_is_ringbuf(const CharDriverState *chr); ...@@ -344,7 +344,6 @@ bool chr_is_ringbuf(const CharDriverState *chr);
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename); QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts *));
void register_char_driver_qapi(const char *name, ChardevBackendKind kind, void register_char_driver_qapi(const char *name, ChardevBackendKind kind,
void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp)); void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp));
......
...@@ -3489,26 +3489,12 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, ...@@ -3489,26 +3489,12 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
typedef struct CharDriver { typedef struct CharDriver {
const char *name; const char *name;
/* old, pre qapi */
CharDriverState *(*open)(QemuOpts *opts);
/* new, qapi-based */
ChardevBackendKind kind; ChardevBackendKind kind;
void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp); void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp);
} CharDriver; } CharDriver;
static GSList *backends; static GSList *backends;
void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts *))
{
CharDriver *s;
s = g_malloc0(sizeof(*s));
s->name = g_strdup(name);
s->open = open;
backends = g_slist_append(backends, s);
}
void register_char_driver_qapi(const char *name, ChardevBackendKind kind, void register_char_driver_qapi(const char *name, ChardevBackendKind kind,
void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp)) void (*parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp))
{ {
...@@ -3530,8 +3516,12 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, ...@@ -3530,8 +3516,12 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
CharDriver *cd; CharDriver *cd;
CharDriverState *chr; CharDriverState *chr;
GSList *i; GSList *i;
ChardevReturn *ret = NULL;
ChardevBackend *backend;
const char *id = qemu_opts_id(opts);
char *bid = NULL;
if (qemu_opts_id(opts) == NULL) { if (id == NULL) {
error_setg(errp, "chardev: no id specified"); error_setg(errp, "chardev: no id specified");
goto err; goto err;
} }
...@@ -3554,89 +3544,49 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, ...@@ -3554,89 +3544,49 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
goto err; goto err;
} }
if (!cd->open) { backend = g_new0(ChardevBackend, 1);
/* using new, qapi init */
ChardevBackend *backend = g_new0(ChardevBackend, 1);
ChardevReturn *ret = NULL;
const char *id = qemu_opts_id(opts);
char *bid = NULL;
if (qemu_opt_get_bool(opts, "mux", 0)) { if (qemu_opt_get_bool(opts, "mux", 0)) {
bid = g_strdup_printf("%s-base", id); bid = g_strdup_printf("%s-base", id);
} }
chr = NULL; chr = NULL;
backend->kind = cd->kind; backend->kind = cd->kind;
if (cd->parse) { if (cd->parse) {
cd->parse(opts, backend, &local_err); cd->parse(opts, backend, &local_err);
if (local_err) { if (local_err) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
goto qapi_out;
}
}
ret = qmp_chardev_add(bid ? bid : id, backend, errp);
if (!ret) {
goto qapi_out; goto qapi_out;
} }
if (bid) {
qapi_free_ChardevBackend(backend);
qapi_free_ChardevReturn(ret);
backend = g_new0(ChardevBackend, 1);
backend->mux = g_new0(ChardevMux, 1);
backend->kind = CHARDEV_BACKEND_KIND_MUX;
backend->mux->chardev = g_strdup(bid);
ret = qmp_chardev_add(id, backend, errp);
if (!ret) {
chr = qemu_chr_find(bid);
qemu_chr_delete(chr);
chr = NULL;
goto qapi_out;
}
}
chr = qemu_chr_find(id);
chr->opts = opts;
qapi_out:
qapi_free_ChardevBackend(backend);
qapi_free_ChardevReturn(ret);
g_free(bid);
return chr;
} }
ret = qmp_chardev_add(bid ? bid : id, backend, errp);
chr = cd->open(opts); if (!ret) {
if (!chr) { goto qapi_out;
error_setg(errp, "chardev: opening backend \"%s\" failed",
qemu_opt_get(opts, "backend"));
goto err;
} }
if (!chr->filename) if (bid) {
chr->filename = g_strdup(qemu_opt_get(opts, "backend")); qapi_free_ChardevBackend(backend);
chr->init = init; qapi_free_ChardevReturn(ret);
/* if we didn't create the chardev via qmp_chardev_add, we backend = g_new0(ChardevBackend, 1);
* need to send the OPENED event here backend->mux = g_new0(ChardevMux, 1);
*/ backend->kind = CHARDEV_BACKEND_KIND_MUX;
if (!chr->explicit_be_open) { backend->mux->chardev = g_strdup(bid);
qemu_chr_be_event(chr, CHR_EVENT_OPENED); ret = qmp_chardev_add(id, backend, errp);
if (!ret) {
chr = qemu_chr_find(bid);
qemu_chr_delete(chr);
chr = NULL;
goto qapi_out;
}
} }
QTAILQ_INSERT_TAIL(&chardevs, chr, next);
if (qemu_opt_get_bool(opts, "mux", 0)) { chr = qemu_chr_find(id);
CharDriverState *base = chr;
int len = strlen(qemu_opts_id(opts)) + 6;
base->label = g_malloc(len);
snprintf(base->label, len, "%s-base", qemu_opts_id(opts));
chr = qemu_chr_open_mux(base);
chr->filename = base->filename;
chr->avail_connections = MAX_MUX;
QTAILQ_INSERT_TAIL(&chardevs, chr, next);
} else {
chr->avail_connections = 1;
}
chr->label = g_strdup(qemu_opts_id(opts));
chr->opts = opts; chr->opts = opts;
qapi_out:
qapi_free_ChardevBackend(backend);
qapi_free_ChardevReturn(ret);
g_free(bid);
return chr; return chr;
err: err:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册