[libvirt] [PATCH 12/13] virsh: Introduce connection handler

Erik Skultety eskultet at redhat.com
Mon Jun 29 15:43:30 UTC 2015


Before any virsh command can be executed, client connection to daemon
needs to be checked, i.e. first we try to reconnect if needed and then
check the connection usability which is connection type specific. This
handler is registered as client hook.
---
 tools/virsh.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/virsh.c b/tools/virsh.c
index 017a669..fcbd553 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -915,9 +915,17 @@ virshConnectionUsability(vshControl *ctl, virConnectPtr conn)
     return true;
 }
 
+static void *
+virshConnectionHandler(vshControl *ctl)
 {
+    virshControlPtr priv = ctl->privData;
 
+    if (!priv->conn || disconnected)
+        virshReconnect(ctl);
 
+    if (virshConnectionUsability(ctl, priv->conn))
+        return priv->conn;
+    return NULL;
 }
 
 /* ---------------
-- 
1.9.3




More information about the libvir-list mailing list