[PATCH 5/5] qemu: Implement qemuDomainQemuMonitorCommandWithFiles

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c       | 34 ++++++++++++++++++++++++++++++----
 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, 45 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 698f57f00e..d10d1556a7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13897,21 +13897,36 @@ 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 nfds,
+                                      int *fds,
+                                      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);

+    if (nfds > 1) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("at most 1 fd can be passed to qemu along with a command"));
+        return -1;
+    }
+
+    if (nfds == 1)
+        fd = fds[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)
@@ -13927,7 +13942,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:
@@ -13939,6 +13954,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, result, flags);
+}
+
+
 static int
 qemuDomainOpenConsole(virDomainPtr dom,
                       const char *dev_name,
@@ -20849,6 +20874,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 babf9e62fb..6359a05155 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3104,17 +3104,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 9b2e4e1421..b7ed8d9bae 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1108,6 +1108,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 b0b513683b..9ab07bb29a 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1461,6 +1461,7 @@ qemuMonitorJSONHandleGuestCrashloaded(qemuMonitor *mon,
 int
 qemuMonitorJSONHumanCommand(qemuMonitor *mon,
                             const char *cmd_str,
+                            int fd,
                             char **reply_str)
 {
     g_autoptr(virJSONValue) cmd = NULL;
@@ -1472,7 +1473,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")) {
@@ -4497,6 +4498,7 @@ qemuMonitorJSONDiskNameLookup(qemuMonitor *mon,

 int qemuMonitorJSONArbitraryCommand(qemuMonitor *mon,
                                     const char *cmd_str,
+                                    int fd,
                                     char **reply_str)
 {
     g_autoptr(virJSONValue) cmd = NULL;
@@ -4505,7 +4507,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 64d9ebdaa3..c57f54e040 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.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux