Add support for sending one FD from the client along with a monitor command so that it's possible to use 'getfd' and 'add-fd' to use FDs passed from the client with other QMP commands. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_driver.c | 42 ++++++++++++++++++++++++++++++++---- src/qemu/qemu_monitor.c | 7 +++--- src/qemu/qemu_monitor.h | 1 + src/qemu/qemu_monitor_json.c | 6 ++++-- src/qemu/qemu_monitor_json.h | 2 ++ src/qemu/qemu_monitor_text.c | 8 +++---- 6 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f1f708e511..706c47792c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13921,21 +13921,44 @@ qemuDomainBackupGetXMLDesc(virDomainPtr domain, } -static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, - char **result, unsigned int flags) +static int +qemuDomainQemuMonitorCommandWithFiles(virDomainPtr domain, + const char *cmd, + unsigned int ninfds, + int *infds, + unsigned int *noutfds, + int **outfds, + char **result, + unsigned int flags) { virQEMUDriver *driver = domain->conn->privateData; virDomainObj *vm = NULL; int ret = -1; qemuDomainObjPrivate *priv; bool hmp; + int fd = -1; virCheckFlags(VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP, -1); + /* currently we don't pass back any fds */ + if (outfds) + *outfds = NULL; + if (noutfds) + *noutfds = 0; + + if (ninfds > 1) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("at most 1 fd can be passed to qemu along with a command")); + return -1; + } + + if (ninfds == 1) + fd = infds[0]; + if (!(vm = qemuDomainObjFromDomain(domain))) goto cleanup; - if (virDomainQemuMonitorCommandEnsureACL(domain->conn, vm->def) < 0) + if (virDomainQemuMonitorCommandWithFilesEnsureACL(domain->conn, vm->def) < 0) goto cleanup; if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0) @@ -13951,7 +13974,7 @@ static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, hmp = !!(flags & VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP); qemuDomainObjEnterMonitor(driver, vm); - ret = qemuMonitorArbitraryCommand(priv->mon, cmd, result, hmp); + ret = qemuMonitorArbitraryCommand(priv->mon, cmd, fd, result, hmp); qemuDomainObjExitMonitor(driver, vm); endjob: @@ -13963,6 +13986,16 @@ static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, } +static int +qemuDomainQemuMonitorCommand(virDomainPtr domain, + const char *cmd, + char **result, + unsigned int flags) +{ + return qemuDomainQemuMonitorCommandWithFiles(domain, cmd, 0, NULL, NULL, NULL, result, flags); +} + + static int qemuDomainOpenConsole(virDomainPtr dom, const char *dev_name, @@ -20873,6 +20906,7 @@ static virHypervisorDriver qemuHypervisorDriver = { .domainRevertToSnapshot = qemuDomainRevertToSnapshot, /* 0.8.0 */ .domainSnapshotDelete = qemuDomainSnapshotDelete, /* 0.8.0 */ .domainQemuMonitorCommand = qemuDomainQemuMonitorCommand, /* 0.8.3 */ + .domainQemuMonitorCommandWithFiles = qemuDomainQemuMonitorCommandWithFiles, /* 8.1.0 */ .domainQemuAttach = NULL, /* 0.9.4 - 5.5.0 */ .domainQemuAgentCommand = qemuDomainQemuAgentCommand, /* 0.10.0 */ .connectDomainQemuMonitorEventRegister = qemuConnectDomainQemuMonitorEventRegister, /* 1.2.3 */ diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index dc81e41783..4fcba588c7 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3042,17 +3042,18 @@ qemuMonitorDrivePivot(qemuMonitor *mon, int qemuMonitorArbitraryCommand(qemuMonitor *mon, const char *cmd, + int fd, char **reply, bool hmp) { - VIR_DEBUG("cmd=%s, reply=%p, hmp=%d", cmd, reply, hmp); + VIR_DEBUG("cmd=%s, fd=%d, reply=%p, hmp=%d", cmd, fd, reply, hmp); QEMU_CHECK_MONITOR(mon); if (hmp) - return qemuMonitorJSONHumanCommand(mon, cmd, reply); + return qemuMonitorJSONHumanCommand(mon, cmd, fd, reply); else - return qemuMonitorJSONArbitraryCommand(mon, cmd, reply); + return qemuMonitorJSONArbitraryCommand(mon, cmd, fd, reply); } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 1d21183d82..c8e8036f26 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1088,6 +1088,7 @@ char *qemuMonitorDiskNameLookup(qemuMonitor *mon, int qemuMonitorArbitraryCommand(qemuMonitor *mon, const char *cmd, + int fd, char **reply, bool hmp); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 1de932f638..ad040e22c1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1462,6 +1462,7 @@ qemuMonitorJSONHandleGuestCrashloaded(qemuMonitor *mon, int qemuMonitorJSONHumanCommand(qemuMonitor *mon, const char *cmd_str, + int fd, char **reply_str) { g_autoptr(virJSONValue) cmd = NULL; @@ -1473,7 +1474,7 @@ qemuMonitorJSONHumanCommand(qemuMonitor *mon, "s:command-line", cmd_str, NULL); - if (!cmd || qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + if (!cmd || qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply) < 0) return -1; if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { @@ -4495,6 +4496,7 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon, int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, const char *cmd_str, + int fd, char **reply_str) { g_autoptr(virJSONValue) cmd = NULL; @@ -4503,7 +4505,7 @@ int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, if (!(cmd = virJSONValueFromString(cmd_str))) return -1; - if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + if (qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply) < 0) return -1; if (!(*reply_str = virJSONValueToString(reply, false))) diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index eea3478af0..e34a30c889 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -43,6 +43,7 @@ qemuMonitorJSONIOProcess(qemuMonitor *mon, int qemuMonitorJSONHumanCommand(qemuMonitor *mon, const char *cmd, + int fd, char **reply); int @@ -369,6 +370,7 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon, int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon, const char *cmd_str, + int fd, char **reply_str); int diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 0ca7f5a470..86af1e4975 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -43,7 +43,7 @@ int qemuMonitorTextAddDrive(qemuMonitor *mon, * address required when attaching drives to a controller */ cmd = g_strdup_printf("drive_add dummy %s", drivestr); - if (qemuMonitorJSONHumanCommand(mon, cmd, &reply) < 0) + if (qemuMonitorJSONHumanCommand(mon, cmd, -1, &reply) < 0) return -1; if (strstr(reply, "unknown command:")) { @@ -93,7 +93,7 @@ int qemuMonitorTextDriveDel(qemuMonitor *mon, cmd = g_strdup_printf("drive_del %s", drivestr); - if (qemuMonitorJSONHumanCommand(mon, cmd, &reply) < 0) + if (qemuMonitorJSONHumanCommand(mon, cmd, -1, &reply) < 0) return -1; if (strstr(reply, "unknown command:")) { @@ -124,7 +124,7 @@ qemuMonitorTextCreateSnapshot(qemuMonitor *mon, cmd = g_strdup_printf("savevm \"%s\"", name); - if (qemuMonitorJSONHumanCommand(mon, cmd, &reply)) + if (qemuMonitorJSONHumanCommand(mon, cmd, -1, &reply)) return -1; if (strstr(reply, "Error while creating snapshot") || @@ -150,7 +150,7 @@ int qemuMonitorTextDeleteSnapshot(qemuMonitor *mon, const char *name) g_autofree char *reply = NULL; cmd = g_strdup_printf("delvm \"%s\"", name); - if (qemuMonitorJSONHumanCommand(mon, cmd, &reply)) + if (qemuMonitorJSONHumanCommand(mon, cmd, -1, &reply)) return -1; if (strstr(reply, "No block device supports snapshots")) { -- 2.35.1