]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virsh: Notify users about disconnects
authorJiri Denemark <jdenemar@redhat.com>
Tue, 15 Sep 2015 14:46:07 +0000 (16:46 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 23 Sep 2015 11:09:50 +0000 (13:09 +0200)
After my "client rpc: Report proper error for keepalive disconnections"
patch, virsh would no long print a warning when it closes a connection
to a daemon after a keepalive timeout. Although the warning

    virsh # 2015-09-15 10:59:26.729+0000: 642080: info :
    libvirt version: 1.2.19
    2015-09-15 10:59:26.729+0000: 642080: warning :
    virKeepAliveTimerInternal:143 : No response from client
    0x7efdc0a46730 after 1 keepalive messages in 2 seconds

was pretty ugly, it was still useful. This patch brings the useful part
back while making it much nicer:

virsh # error: Disconnected from qemu:///system due to keepalive timeout

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
tools/virsh.c

index bb12dec93d292641857e3c5602f3bc131dc373ab..76b5e9f9c7533d50944d8c993a66c2ddfa3732c3 100644 (file)
@@ -95,12 +95,42 @@ static int disconnected; /* we may have been disconnected */
  * handler, just save the fact it was raised.
  */
 static void
-virshCatchDisconnect(virConnectPtr conn ATTRIBUTE_UNUSED,
+virshCatchDisconnect(virConnectPtr conn,
                      int reason,
-                     void *opaque ATTRIBUTE_UNUSED)
+                     void *opaque)
 {
-    if (reason != VIR_CONNECT_CLOSE_REASON_CLIENT)
+    if (reason != VIR_CONNECT_CLOSE_REASON_CLIENT) {
+        vshControl *ctl = opaque;
+        const char *str = "unknown reason";
+        virErrorPtr error;
+        char *uri;
+
+        error = virSaveLastError();
+        uri = virConnectGetURI(conn);
+
+        switch ((virConnectCloseReason) reason) {
+        case VIR_CONNECT_CLOSE_REASON_ERROR:
+            str = N_("Disconnected from %s due to I/O error");
+            break;
+        case VIR_CONNECT_CLOSE_REASON_EOF:
+            str = N_("Disconnected from %s due to end of file");
+            break;
+        case VIR_CONNECT_CLOSE_REASON_KEEPALIVE:
+            str = N_("Disconnected from %s due to keepalive timeout");
+            break;
+        /* coverity[dead_error_begin] */
+        case VIR_CONNECT_CLOSE_REASON_CLIENT:
+        case VIR_CONNECT_CLOSE_REASON_LAST:
+            break;
+        }
+        vshError(ctl, _(str), NULLSTR(uri));
+
+        if (error) {
+            virSetError(error);
+            virFreeError(error);
+        }
         disconnected++;
+    }
 }
 
 /* Main Function which should be used for connecting.