[PATCHv2 1/3] qemu: simplify monitor fd error handling

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

 



qemu_monitor was already returning -1 and setting errno to EINVAL
on any attempt to send an fd without a unix socket, but this was
a silent failure in the case of qemuDomainAttachHostPciDevice.
Meanwhile, qemuDomainAttachNetDevice was doing some sanity checking
for a better error message; it's better to consolidate that to a
central point in the API.

* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Move sanity
checking...
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle): ...into
central location.
Suggested by Chris Wright.
---

v2: new patch

Note that this changes the behavior of qemuDomainAttachHostPciDevice
even though that function is not directly patched, but hopefully for
the better.

 src/qemu/qemu_hotplug.c |   16 ----------------
 src/qemu/qemu_monitor.c |   13 +++++++++++++
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e4ba526..20d94e4 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -568,28 +568,12 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,

     if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
         net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
-        if (priv->monConfig->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
-            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                            _("network device type '%s' cannot be attached: "
-                              "qemu is not using a unix socket monitor"),
-                            virDomainNetTypeToString(net->type));
-            return -1;
-        }
-
         if ((tapfd = qemuNetworkIfaceConnect(vm->def, conn, driver, net,
                                              qemuCaps)) < 0)
             return -1;
         if (qemuOpenVhostNet(vm->def, net, qemuCaps, &vhostfd) < 0)
             goto cleanup;
     } else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
-        if (priv->monConfig->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
-            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                            _("network device type '%s' cannot be attached: "
-                            "qemu is not using a unix socket monitor"),
-                            virDomainNetTypeToString(net->type));
-            return -1;
-        }
-
         if ((tapfd = qemuPhysIfaceConnect(vm->def, conn, driver, net,
                                           qemuCaps,
                                           VIR_VM_OP_CREATE)) < 0)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index da38096..fb875fc 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1776,6 +1776,19 @@ int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
         return -1;
     }

+    if (fd < 0) {
+        qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                        _("fd must be valid"));
+        return -1;
+    }
+
+    if (!mon->hasSendFD) {
+        qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                        _("qemu is not using a unix socket monitor, "
+                          "cannot send fd %s"), fdname);
+        return -1;
+    }
+
     if (mon->json)
         ret = qemuMonitorJSONSendFileHandle(mon, fdname, fd);
     else
-- 
1.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]