aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hmp.c1
-rw-r--r--include/sysemu/char.h21
-rw-r--r--net/colo-compare.c30
-rw-r--r--net/vhost-user.c41
-rw-r--r--qemu-char.c22
5 files changed, 49 insertions, 66 deletions
diff --git a/hmp.c b/hmp.c
index 336e7bf076..3c421828ff 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1909,6 +1909,7 @@ void hmp_chardev_add(Monitor *mon, const QDict *qdict)
error_setg(&err, "Parsing chardev args failed");
} else {
qemu_chr_new_from_opts(opts, NULL, &err);
+ qemu_opts_del(opts);
}
hmp_handle_error(mon, &err);
}
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index 0d0465ae0e..19dad3fb9c 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -9,6 +9,7 @@
#include "qapi/qmp/qobject.h"
#include "qapi/qmp/qstring.h"
#include "qemu/main-loop.h"
+#include "qemu/bitmap.h"
/* character device */
@@ -58,6 +59,20 @@ struct ParallelIOArg {
typedef void IOEventHandler(void *opaque, int event);
+typedef enum {
+ /* Whether the chardev peer is able to close and
+ * reopen the data channel, thus requiring support
+ * for qemu_chr_wait_connected() to wait for a
+ * valid connection */
+ QEMU_CHAR_FEATURE_RECONNECTABLE,
+ /* Whether it is possible to send/recv file descriptors
+ * over the data channel */
+ QEMU_CHAR_FEATURE_FD_PASS,
+
+ QEMU_CHAR_FEATURE_LAST,
+} CharDriverFeature;
+
+
struct CharDriverState {
QemuMutex chr_write_lock;
void (*init)(struct CharDriverState *s);
@@ -93,8 +108,8 @@ struct CharDriverState {
int avail_connections;
int is_mux;
guint fd_in_tag;
- QemuOpts *opts;
bool replay;
+ DECLARE_BITMAP(features, QEMU_CHAR_FEATURE_LAST);
QTAILQ_ENTRY(CharDriverState) next;
};
@@ -437,6 +452,10 @@ int qemu_chr_add_client(CharDriverState *s, int fd);
CharDriverState *qemu_chr_find(const char *name);
bool chr_is_ringbuf(const CharDriverState *chr);
+bool qemu_chr_has_feature(CharDriverState *chr,
+ CharDriverFeature feature);
+void qemu_chr_set_feature(CharDriverState *chr,
+ CharDriverFeature feature);
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
void register_char_driver(const char *name, ChardevBackendKind kind,
diff --git a/net/colo-compare.c b/net/colo-compare.c
index 22b1da19f5..47703c59bc 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -564,29 +564,6 @@ static void compare_sec_rs_finalize(SocketReadState *sec_rs)
}
}
-static int compare_chardev_opts(void *opaque,
- const char *name, const char *value,
- Error **errp)
-{
- CompareChardevProps *props = opaque;
-
- if (strcmp(name, "backend") == 0 &&
- strcmp(value, "socket") == 0) {
- props->is_socket = true;
- return 0;
- } else if (strcmp(name, "host") == 0 ||
- (strcmp(name, "port") == 0) ||
- (strcmp(name, "server") == 0) ||
- (strcmp(name, "wait") == 0) ||
- (strcmp(name, "path") == 0)) {
- return 0;
- } else {
- error_setg(errp,
- "COLO-compare does not support a chardev with option %s=%s",
- name, value);
- return -1;
- }
-}
/*
* Return 0 is success.
@@ -606,12 +583,9 @@ static int find_and_check_chardev(CharDriverState **chr,
}
memset(&props, 0, sizeof(props));
- if (qemu_opt_foreach((*chr)->opts, compare_chardev_opts, &props, errp)) {
- return 1;
- }
- if (!props.is_socket) {
- error_setg(errp, "chardev \"%s\" is not a tcp socket",
+ if (!qemu_chr_has_feature(*chr, QEMU_CHAR_FEATURE_RECONNECTABLE)) {
+ error_setg(errp, "chardev \"%s\" is not reconnectable",
chr_name);
return 1;
}
diff --git a/net/vhost-user.c b/net/vhost-user.c
index b0595f8781..5b94c84541 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -27,11 +27,6 @@ typedef struct VhostUserState {
bool started;
} VhostUserState;
-typedef struct VhostUserChardevProps {
- bool is_socket;
- bool is_unix;
-} VhostUserChardevProps;
-
VHostNetState *vhost_user_get_vhost_net(NetClientState *nc)
{
VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
@@ -278,45 +273,23 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
return 0;
}
-static int net_vhost_chardev_opts(void *opaque,
- const char *name, const char *value,
- Error **errp)
-{
- VhostUserChardevProps *props = opaque;
-
- if (strcmp(name, "backend") == 0 && strcmp(value, "socket") == 0) {
- props->is_socket = true;
- } else if (strcmp(name, "path") == 0) {
- props->is_unix = true;
- } else if (strcmp(name, "server") == 0) {
- } else {
- error_setg(errp,
- "vhost-user does not support a chardev with option %s=%s",
- name, value);
- return -1;
- }
- return 0;
-}
-
-static CharDriverState *net_vhost_parse_chardev(
+static CharDriverState *net_vhost_claim_chardev(
const NetdevVhostUserOptions *opts, Error **errp)
{
CharDriverState *chr = qemu_chr_find(opts->chardev);
- VhostUserChardevProps props;
if (chr == NULL) {
error_setg(errp, "chardev \"%s\" not found", opts->chardev);
return NULL;
}
- /* inspect chardev opts */
- memset(&props, 0, sizeof(props));
- if (qemu_opt_foreach(chr->opts, net_vhost_chardev_opts, &props, errp)) {
+ if (!qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_RECONNECTABLE)) {
+ error_setg(errp, "chardev \"%s\" is not reconnectable",
+ opts->chardev);
return NULL;
}
-
- if (!props.is_socket || !props.is_unix) {
- error_setg(errp, "chardev \"%s\" is not a unix socket",
+ if (!qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_FD_PASS)) {
+ error_setg(errp, "chardev \"%s\" does not support FD passing",
opts->chardev);
return NULL;
}
@@ -357,7 +330,7 @@ int net_init_vhost_user(const Netdev *netdev, const char *name,
assert(netdev->type == NET_CLIENT_DRIVER_VHOST_USER);
vhost_user_opts = &netdev->u.vhost_user;
- chr = net_vhost_parse_chardev(vhost_user_opts, errp);
+ chr = net_vhost_claim_chardev(vhost_user_opts, errp);
if (!chr) {
return -1;
}
diff --git a/qemu-char.c b/qemu-char.c
index fb456cec34..768150d1f8 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3996,7 +3996,6 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
}
chr = qemu_chr_find(id);
- chr->opts = opts;
qapi_out:
qapi_free_ChardevBackend(backend);
@@ -4005,7 +4004,6 @@ qapi_out:
return chr;
err:
- qemu_opts_del(opts);
return NULL;
}
@@ -4033,6 +4031,7 @@ CharDriverState *qemu_chr_new_noreplay(const char *label, const char *filename,
qemu_chr_fe_claim_no_fail(chr);
monitor_init(chr, MONITOR_USE_READLINE);
}
+ qemu_opts_del(opts);
return chr;
}
@@ -4132,7 +4131,6 @@ static void qemu_chr_free_common(CharDriverState *chr)
{
g_free(chr->filename);
g_free(chr->label);
- qemu_opts_del(chr->opts);
if (chr->logfd != -1) {
close(chr->logfd);
}
@@ -4513,6 +4511,11 @@ static CharDriverState *qmp_chardev_open_socket(const char *id,
s->addr = QAPI_CLONE(SocketAddress, sock->addr);
+ qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_RECONNECTABLE);
+ if (s->is_unix) {
+ qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS);
+ }
+
chr->opaque = s;
chr->chr_wait_connected = tcp_chr_wait_connected;
chr->chr_write = tcp_chr_write;
@@ -4596,6 +4599,19 @@ static CharDriverState *qmp_chardev_open_udp(const char *id,
return qemu_chr_open_udp(sioc, common, errp);
}
+
+bool qemu_chr_has_feature(CharDriverState *chr,
+ CharDriverFeature feature)
+{
+ return test_bit(feature, chr->features);
+}
+
+void qemu_chr_set_feature(CharDriverState *chr,
+ CharDriverFeature feature)
+{
+ return set_bit(feature, chr->features);
+}
+
ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
Error **errp)
{