#include "qemu_alias.h"
#include "qemu_security.h"
#include "qemu_process.h"
+#include "qemu_chardev.h"
#include "storage_source.h"
#include "viralloc.h"
return -1;
if (data->chardevDef) {
- if (qemuMonitorAttachCharDev(mon, data->chardevAlias, data->chardevDef) < 0)
+ g_autoptr(virJSONValue) props = NULL;
+
+ if (qemuChardevGetBackendProps(data->chardevDef, false,
+ data->chardevAlias, NULL, &props) < 0)
+ return -1;
+
+ if (qemuMonitorAttachCharDev(mon, &props, NULL) < 0)
return -1;
data->chardevAdded = true;
#include "qemu_block.h"
#include "qemu_snapshot.h"
#include "qemu_virtiofs.h"
+#include "qemu_chardev.h"
#include "domain_audit.h"
#include "domain_cgroup.h"
#include "domain_interface.h"
const char *alias,
virDomainChrSourceDef *def)
{
+ g_autoptr(virJSONValue) props = NULL;
+ g_autofree char *ptypath = NULL;
+
switch ((virDomainChrType) def->type) {
case VIR_DOMAIN_CHR_TYPE_NULL:
case VIR_DOMAIN_CHR_TYPE_VC:
return -1;
}
- return qemuMonitorAttachCharDev(mon, alias, def);
+ if (qemuChardevGetBackendProps(def, false, alias, NULL, &props) < 0)
+ return -1;
+
+ if (qemuMonitorAttachCharDev(mon, &props, &ptypath) < 0)
+ return -1;
+
+ if (def->type == VIR_DOMAIN_CHR_TYPE_PTY) {
+ if (!ptypath) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("chardev-add reply was missing pty path"));
+ return -1;
+ }
+
+ def->data.file.path = g_steal_pointer(&ptypath);
+ }
+
+ return 0;
}
int
qemuMonitorAttachCharDev(qemuMonitor *mon,
- const char *chrID,
- virDomainChrSourceDef *chr)
+ virJSONValue **props,
+ char **ptypath)
{
- VIR_DEBUG("chrID=%s chr=%p", chrID, chr);
-
QEMU_CHECK_MONITOR(mon);
- return qemuMonitorJSONAttachCharDev(mon, chrID, chr);
+ return qemuMonitorJSONAttachCharDev(mon, props, ptypath);
}
char ***tpmtypes);
int qemuMonitorAttachCharDev(qemuMonitor *mon,
- const char *chrID,
- virDomainChrSourceDef *chr);
+ virJSONValue **props,
+ char **ptypath);
int qemuMonitorDetachCharDev(qemuMonitor *mon,
const char *chrID);
}
-static virJSONValue *
+static G_GNUC_UNUSED virJSONValue *
qemuMonitorJSONAttachCharDevGetProps(const char *chrID,
const virDomainChrSourceDef *chr)
{
int
qemuMonitorJSONAttachCharDev(qemuMonitor *mon,
- const char *chrID,
- virDomainChrSourceDef *chr)
+ virJSONValue **props,
+ char **ptypath)
{
g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL;
- g_autoptr(virJSONValue) props = NULL;
-
- if (!(props = qemuMonitorJSONAttachCharDevGetProps(chrID, chr)))
- return -1;
+ virJSONValue *data;
- if (!(cmd = qemuMonitorJSONMakeCommandInternal("chardev-add", &props)))
+ if (!(cmd = qemuMonitorJSONMakeCommandInternal("chardev-add", props)))
return -1;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
- if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) {
- virJSONValue *data;
-
- if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
- return -1;
+ if (!(data = qemuMonitorJSONGetReply(cmd, reply, VIR_JSON_TYPE_OBJECT)))
+ return -1;
- if (!(chr->data.file.path = g_strdup(virJSONValueObjectGetString(data, "pty")))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("chardev-add reply was missing pty path"));
- return -1;
- }
- } else {
- if (qemuMonitorJSONCheckError(cmd, reply) < 0)
- return -1;
- }
+ if (ptypath)
+ *ptypath = g_strdup(virJSONValueObjectGetString(data, "pty"));
return 0;
}
+
int
qemuMonitorJSONDetachCharDev(qemuMonitor *mon,
const char *chrID)
int
qemuMonitorJSONAttachCharDev(qemuMonitor *mon,
- const char *chrID,
- virDomainChrSourceDef *chr);
+ virJSONValue **props,
+ char **ptypath);
int
qemuMonitorJSONDetachCharDev(qemuMonitor *mon,
const char *chrID);
#include "qemu/qemu_monitor_json.h"
#include "qemu/qemu_qapi.h"
#include "qemu/qemu_alias.h"
+#include "qemu/qemu_chardev.h"
#include "virerror.h"
#include "cpu/cpu.h"
#include "qemu/qemu_monitor.h"
{
const struct qemuMonitorJSONTestAttachChardevData *data = opaque;
g_autoptr(qemuMonitorTest) test = qemuMonitorTestNewSchema(data->xmlopt, data->schema);
+ g_autoptr(virJSONValue) props = NULL;
+ g_autofree char *ptypath = NULL;
int rc;
if (!test)
return -1;
}
- if ((rc = qemuMonitorAttachCharDev(qemuMonitorTestGetMonitor(test),
- "alias", data->chr)) < 0)
+ if (qemuChardevGetBackendProps(data->chr, false, "alias", NULL, &props) < 0)
+ return -1;
+
+ if ((rc = qemuMonitorAttachCharDev(qemuMonitorTestGetMonitor(test), &props, &ptypath)) < 0)
goto cleanup;
if (data->chr->type == VIR_DOMAIN_CHR_TYPE_PTY) {
- if (STRNEQ_NULLABLE(data->expectPty, data->chr->data.file.path)) {
+ if (STRNEQ_NULLABLE(data->expectPty, ptypath)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"expected PTY path: %s got: %s",
NULLSTR(data->expectPty),
NULLSTR(data->chr->data.file.path));
rc = -1;
}
-
- VIR_FREE(data->chr->data.file.path);
}
cleanup:
"'data':{'type':'vdagent'}}}");
chr->type = VIR_DOMAIN_CHR_TYPE_PTY;
- CHECK("pty missing path", true,
+ /* Higher level code regards the missing path as error, but we simply
+ * check here what we've parsed */
+ CHECK("pty missing path", false,
"{'id':'alias','backend':{'type':'pty','data':{}}}");
if (qemuMonitorJSONTestAttachOneChardev(xmlopt, schema, "pty", chr,
"{'id':'alias',"