[libvirt] [PATCH v2 3/3] [DO_NOT_APPLY_UPSTREAM] virsh: add connection monitoring into vshWatchJob

Martin Kletzander mkletzan at redhat.com
Mon Mar 10 11:26:59 UTC 2014


Similarly to Guannan's patches in 2012, this one does add the
connection monitoring into vshWatchJob function.

*But Beware*, while testing this I discovered it adds no new
functionality.  Probably since we're catching disconnects by a
callback, there is no way to get to the code introduced.  Although it
might sound weird, this patch just demonstrates that there is no need
for it.  Just for the purpose of nobody asking for such addition.

On a side note: I'd love for this to be useful; changing the current
output from "error received on socket" to simple "Lost connection to
destination", but it would require much more wiring and overhead, I
guess.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 tools/virsh-domain.c | 19 ++++++++++++++-----
 tools/virsh.c        |  2 +-
 tools/virsh.h        |  2 ++
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 3e989ee..5933ce8 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -3569,7 +3569,7 @@ typedef void (*jobWatchTimeoutFunc)(vshControl *ctl, virDomainPtr dom,
                                     void *opaque);

 static bool
-vshWatchJob(vshControl *ctl,
+vshWatchJob(vshCtrlData *data,
             virDomainPtr dom,
             bool verbose,
             int pipe_fd,
@@ -3590,6 +3590,7 @@ vshWatchJob(vshControl *ctl,
     sigset_t sigmask, oldsigmask;
     bool jobStarted = false;
     nfds_t npollfd = 2;
+    vshControl *ctl = data->ctl;

     sigemptyset(&sigmask);
     sigaddset(&sigmask, SIGINT);
@@ -3642,6 +3643,14 @@ vshWatchJob(vshControl *ctl,
             goto cleanup;
         }

+        if (data->dconn &&
+            !vshConnectionUsability(ctl, data->dconn)) {
+            vshError(ctl, "%s", _("Lost connection to destrination server, "
+                                  "aborting job"));
+            virDomainAbortJob(dom);
+            goto cleanup;
+        }
+
         GETTIMEOFDAY(&curr);
         if (timeout_ms && (((int)(curr.tv_sec - start.tv_sec)  * 1000 +
                             (int)(curr.tv_usec - start.tv_usec) / 1000) >
@@ -3716,7 +3725,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
                         &data) < 0)
         goto cleanup;

-    ret = vshWatchJob(ctl, dom, verbose, p[0], 0, NULL, NULL, _("Save"));
+    ret = vshWatchJob(&data, dom, verbose, p[0], 0, NULL, NULL, _("Save"));

     virThreadJoin(&workerThread);

@@ -4037,7 +4046,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
                         &data) < 0)
         goto cleanup;

-    ret = vshWatchJob(ctl, dom, verbose, p[0], 0,
+    ret = vshWatchJob(&data, dom, verbose, p[0], 0,
                       NULL, NULL, _("Managedsave"));

     virThreadJoin(&workerThread);
@@ -4572,7 +4581,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
                         &data) < 0)
         goto cleanup;

-    ret = vshWatchJob(ctl, dom, verbose, p[0], 0, NULL, NULL, _("Dump"));
+    ret = vshWatchJob(&data, dom, verbose, p[0], 0, NULL, NULL, _("Dump"));

     virThreadJoin(&workerThread);

@@ -8856,7 +8865,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
                         doMigrate,
                         &data) < 0)
         goto cleanup;
-    functionReturn = vshWatchJob(ctl, dom, verbose, p[0], timeout,
+    functionReturn = vshWatchJob(&data, dom, verbose, p[0], timeout,
                                  vshMigrationTimeout, NULL, _("Migration"));

     virThreadJoin(&workerThread);
diff --git a/tools/virsh.c b/tools/virsh.c
index 02835d9..9288a49 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1789,7 +1789,7 @@ vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout)
 }


-static bool
+bool
 vshConnectionUsability(vshControl *ctl, virConnectPtr conn)
 {
     if (!conn ||
diff --git a/tools/virsh.h b/tools/virsh.h
index 3e0251b..efad272 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -273,6 +273,7 @@ void vshOutputLogFile(vshControl *ctl, int log_level, const char *format,
 void vshCloseLogFile(vshControl *ctl);

 virConnectPtr vshConnect(vshControl *ctl, const char *uri, bool readonly);
+bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn);

 const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info);
 const vshCmdDef *vshCmddefSearch(const char *cmdname);
@@ -362,6 +363,7 @@ struct _vshCtrlData {
     vshControl *ctl;
     const vshCmd *cmd;
     int writefd;
+    virConnectPtr dconn;
 };

 /* error handling */
-- 
1.9.0




More information about the libvir-list mailing list