chardev: generate an internal id when none given
Internally, qemu may create chardev without ID. Those will not be looked up with qemu_chr_find(), which prevents using qdev_prop_set_chr(). Use id_generate(), to generate an internal name (prefixed with #), so no conflict exist with user-named chardev. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: xiaoqiang zhao <zxq_yx_007@163.com>
This commit is contained in:
parent
a35c6ccc06
commit
1e419ee68f
|
@ -37,6 +37,7 @@
|
||||||
#include "qemu/help_option.h"
|
#include "qemu/help_option.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
#include "qemu/option.h"
|
#include "qemu/option.h"
|
||||||
|
#include "qemu/id.h"
|
||||||
|
|
||||||
#include "chardev/char-mux.h"
|
#include "chardev/char-mux.h"
|
||||||
|
|
||||||
|
@ -944,10 +945,10 @@ void qemu_chr_set_feature(Chardev *chr,
|
||||||
return set_bit(feature, chr->features);
|
return set_bit(feature, chr->features);
|
||||||
}
|
}
|
||||||
|
|
||||||
Chardev *qemu_chardev_new(const char *id, const char *typename,
|
static Chardev *chardev_new(const char *id, const char *typename,
|
||||||
ChardevBackend *backend,
|
ChardevBackend *backend,
|
||||||
GMainContext *gcontext,
|
GMainContext *gcontext,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
Object *obj;
|
Object *obj;
|
||||||
Chardev *chr = NULL;
|
Chardev *chr = NULL;
|
||||||
|
@ -991,6 +992,21 @@ end:
|
||||||
return chr;
|
return chr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Chardev *qemu_chardev_new(const char *id, const char *typename,
|
||||||
|
ChardevBackend *backend,
|
||||||
|
GMainContext *gcontext,
|
||||||
|
Error **errp)
|
||||||
|
{
|
||||||
|
g_autofree char *genid = NULL;
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
genid = id_generate(ID_CHR);
|
||||||
|
id = genid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return chardev_new(id, typename, backend, gcontext, errp);
|
||||||
|
}
|
||||||
|
|
||||||
ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
|
ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
|
@ -1003,8 +1019,8 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
chr = qemu_chardev_new(id, object_class_get_name(OBJECT_CLASS(cc)),
|
chr = chardev_new(id, object_class_get_name(OBJECT_CLASS(cc)),
|
||||||
backend, NULL, errp);
|
backend, NULL, errp);
|
||||||
if (!chr) {
|
if (!chr) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1061,8 +1077,8 @@ ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
chr_new = qemu_chardev_new(NULL, object_class_get_name(OBJECT_CLASS(cc)),
|
chr_new = chardev_new(NULL, object_class_get_name(OBJECT_CLASS(cc)),
|
||||||
backend, chr->gcontext, errp);
|
backend, chr->gcontext, errp);
|
||||||
if (!chr_new) {
|
if (!chr_new) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
typedef enum IdSubSystems {
|
typedef enum IdSubSystems {
|
||||||
ID_QDEV,
|
ID_QDEV,
|
||||||
ID_BLOCK,
|
ID_BLOCK,
|
||||||
|
ID_CHR,
|
||||||
ID_MAX /* last element, used as array size */
|
ID_MAX /* last element, used as array size */
|
||||||
} IdSubSystems;
|
} IdSubSystems;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue