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

[libvirt] [PATCH 1/4] virsh: make conn global



Since virsh is not multi-threaded, it is safe to have it as global
variable. This is going to be needed in some special cases where we
can't change function prototype but want to have connection object
accessible.
---
 tools/virsh.c |  555 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 278 insertions(+), 277 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 9a189fd..eeacec3 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -218,7 +218,6 @@ typedef struct __vshCmd {
  */
 typedef struct __vshControl {
     char *name;                 /* connection name */
-    virConnectPtr conn;         /* connection to hypervisor (MAY BE NULL) */
     vshCmd *cmd;                /* the current command */
     char *cmdstr;               /* string with command */
     bool imode;                 /* interactive mode? */
@@ -242,6 +241,8 @@ typedef struct vshCmdGrp {
     const vshCmdDef *commands;
 } vshCmdGrp;
 
+virConnectPtr conn;             /* connection to hypervisor (MAY BE NULL) */
+
 static const vshCmdGrp cmdGroups[];
 
 static void vshError(vshControl *ctl, const char *format, ...)
@@ -354,7 +355,7 @@ static const char *vshDomainStateToString(int state);
 static const char *vshDomainStateReasonToString(int state, int reason);
 static const char *vshDomainControlStateToString(int state);
 static const char *vshDomainVcpuStateToString(int state);
-static bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn);
+static bool vshConnectionUsability(vshControl *ctl);
 
 static char *editWriteToTempFile (vshControl *ctl, const char *doc);
 static int   editFile (vshControl *ctl, const char *filename);
@@ -581,15 +582,15 @@ vshReconnect(vshControl *ctl)
 {
     bool connected = false;
 
-    if (ctl->conn != NULL) {
+    if (conn != NULL) {
         connected = true;
-        virConnectClose(ctl->conn);
+        virConnectClose(conn);
     }
 
-    ctl->conn = virConnectOpenAuth(ctl->name,
-                                   virConnectAuthPtrDefault,
-                                   ctl->readonly ? VIR_CONNECT_RO : 0);
-    if (!ctl->conn)
+    conn = virConnectOpenAuth(ctl->name,
+                              virConnectAuthPtrDefault,
+                              ctl->readonly ? VIR_CONNECT_RO : 0);
+    if (!conn)
         vshError(ctl, "%s", _("Failed to reconnect to the hypervisor"));
     else if (connected)
         vshError(ctl, "%s", _("Reconnected to the hypervisor"));
@@ -676,7 +677,7 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd)
     const char *name;
     int autostart;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
@@ -725,13 +726,13 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
     bool ro = vshCommandOptBool(cmd, "readonly");
     const char *name = NULL;
 
-    if (ctl->conn) {
+    if (conn) {
         int ret;
-        if ((ret = virConnectClose(ctl->conn)) != 0) {
+        if ((ret = virConnectClose(conn)) != 0) {
             vshError(ctl, _("Failed to disconnect from the hypervisor, %d leaked reference(s)"), ret);
             return false;
         }
-        ctl->conn = NULL;
+        conn = NULL;
     }
 
     VIR_FREE(ctl->name);
@@ -744,13 +745,13 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
     ctl->useGetInfo = false;
     ctl->readonly = ro;
 
-    ctl->conn = virConnectOpenAuth(ctl->name, virConnectAuthPtrDefault,
-                                   ctl->readonly ? VIR_CONNECT_RO : 0);
+    conn = virConnectOpenAuth(ctl->name, virConnectAuthPtrDefault,
+                              ctl->readonly ? VIR_CONNECT_RO : 0);
 
-    if (!ctl->conn)
+    if (!conn)
         vshError(ctl, "%s", _("Failed to connect to the hypervisor"));
 
-    return !!ctl->conn;
+    return !!conn;
 }
 
 #ifndef WIN32
@@ -804,7 +805,7 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     const char *name = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -852,11 +853,11 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     int maxname = 0;
     inactive |= all;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (active) {
-        maxid = virConnectNumOfDomains(ctl->conn);
+        maxid = virConnectNumOfDomains(conn);
         if (maxid < 0) {
             vshError(ctl, "%s", _("Failed to list active domains"));
             return false;
@@ -864,7 +865,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         if (maxid) {
             ids = vshMalloc(ctl, sizeof(int) * maxid);
 
-            if ((maxid = virConnectListDomains(ctl->conn, &ids[0], maxid)) < 0) {
+            if ((maxid = virConnectListDomains(conn, &ids[0], maxid)) < 0) {
                 vshError(ctl, "%s", _("Failed to list active domains"));
                 VIR_FREE(ids);
                 return false;
@@ -874,7 +875,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         }
     }
     if (inactive) {
-        maxname = virConnectNumOfDefinedDomains(ctl->conn);
+        maxname = virConnectNumOfDefinedDomains(conn);
         if (maxname < 0) {
             vshError(ctl, "%s", _("Failed to list inactive domains"));
             VIR_FREE(ids);
@@ -883,7 +884,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         if (maxname) {
             names = vshMalloc(ctl, sizeof(char *) * maxname);
 
-            if ((maxname = virConnectListDefinedDomains(ctl->conn, names, maxname)) < 0) {
+            if ((maxname = virConnectListDefinedDomains(conn, names, maxname)) < 0) {
                 vshError(ctl, "%s", _("Failed to list inactive domains"));
                 VIR_FREE(ids);
                 VIR_FREE(names);
@@ -897,7 +898,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     vshPrintExtra(ctl, "----------------------------------\n");
 
     for (i = 0; i < maxid; i++) {
-        virDomainPtr dom = virDomainLookupByID(ctl->conn, ids[i]);
+        virDomainPtr dom = virDomainLookupByID(conn, ids[i]);
 
         /* this kind of work with domains is not atomic operation */
         if (!dom)
@@ -910,7 +911,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         virDomainFree(dom);
     }
     for (i = 0; i < maxname; i++) {
-        virDomainPtr dom = virDomainLookupByName(ctl->conn, names[i]);
+        virDomainPtr dom = virDomainLookupByName(conn, names[i]);
 
         /* this kind of work with domains is not atomic operation */
         if (!dom) {
@@ -954,7 +955,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd)
     int showReason = vshCommandOptBool(cmd, "reason");
     int state, reason;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -1000,7 +1001,7 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     virDomainControlInfo info;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -1047,7 +1048,7 @@ cmdDomblkstat (vshControl *ctl, const vshCmd *cmd)
     const char *name = NULL, *device = NULL;
     struct _virDomainBlockStats stats;
 
-    if (!vshConnectionUsability (ctl, ctl->conn))
+    if (!vshConnectionUsability (ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
@@ -1104,7 +1105,7 @@ cmdDomIfstat (vshControl *ctl, const vshCmd *cmd)
     const char *name = NULL, *device = NULL;
     struct _virDomainInterfaceStats stats;
 
-    if (!vshConnectionUsability (ctl, ctl->conn))
+    if (!vshConnectionUsability (ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
@@ -1171,7 +1172,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
     struct _virDomainMemoryStat stats[VIR_DOMAIN_MEMORY_STAT_NR];
     unsigned int nr_stats, i;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
@@ -1228,7 +1229,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *device = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -1273,7 +1274,7 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd)
     const char *name;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
@@ -1321,7 +1322,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
 #endif
     unsigned int flags = VIR_DOMAIN_NONE;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -1335,7 +1336,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptBool(cmd, "autodestroy"))
         flags |= VIR_DOMAIN_START_AUTODESTROY;
 
-    dom = virDomainCreateXML(ctl->conn, buffer, flags);
+    dom = virDomainCreateXML(conn, buffer, flags);
     VIR_FREE(buffer);
 
     if (dom != NULL) {
@@ -1375,7 +1376,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *buffer;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -1384,7 +1385,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    dom = virDomainDefineXML(ctl->conn, buffer);
+    dom = virDomainDefineXML(conn, buffer);
     VIR_FREE(buffer);
 
     if (dom != NULL) {
@@ -1420,14 +1421,14 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
     const char *name = NULL;
     int id;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "domain", &name) <= 0)
         return false;
 
     if (name && virStrToLong_i(name, NULL, 10, &id) == 0
-        && id >= 0 && (dom = virDomainLookupByID(ctl->conn, id))) {
+        && id >= 0 && (dom = virDomainLookupByID(conn, id))) {
         vshError(ctl,
                  _("a running domain like %s cannot be undefined;\n"
                    "to undefine, first shutdown then undefine"
@@ -1483,7 +1484,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
 #endif
     unsigned int flags = VIR_DOMAIN_NONE;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
@@ -1541,7 +1542,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
     const char *to = NULL;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &to) <= 0)
@@ -1585,7 +1586,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
     const char *name;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
@@ -1624,7 +1625,7 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     int hassave;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
@@ -1798,7 +1799,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
             flags |= VIR_DOMAIN_AFFECT_LIVE;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -1933,13 +1934,13 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
     const char *from = NULL;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
         return false;
 
-    if (virDomainRestore(ctl->conn, from) == 0) {
+    if (virDomainRestore(conn, from) == 0) {
         vshPrint(ctl, _("Domain restored from %s\n"), from);
     } else {
         vshError(ctl, _("Failed to restore domain from %s"), from);
@@ -1974,7 +1975,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     int flags = 0;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &to) <= 0)
@@ -2035,7 +2036,7 @@ vshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime)
 
     /* We should be already connected, but doesn't
      * hurt to check */
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return NULL;
 
     if (!dom) {
@@ -2077,7 +2078,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
     bool generated = false;
     char *mime = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", (const char **) &file) < 0) {
@@ -2093,7 +2094,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
         return false;
 
-    st = virStreamNew(ctl->conn, 0);
+    st = virStreamNew(conn, 0);
 
     mime = virDomainScreenshot(dom, st, screen, flags);
     if (!mime) {
@@ -2167,7 +2168,7 @@ cmdResume(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
@@ -2205,7 +2206,7 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
@@ -2243,7 +2244,7 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
@@ -2281,7 +2282,7 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
@@ -2325,7 +2326,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
     unsigned int id;
     char *str, uuid[VIR_UUID_STRING_BUFLEN];
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -2390,7 +2391,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
 
     /* Security model and label information */
     memset(&secmodel, 0, sizeof secmodel);
-    if (virNodeGetSecurityModel(ctl->conn, &secmodel) == -1) {
+    if (virNodeGetSecurityModel(conn, &secmodel) == -1) {
         if (last_error->code != VIR_ERR_NO_SUPPORT) {
             virDomainFree(dom);
             return false;
@@ -2449,7 +2450,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -2530,7 +2531,7 @@ cmdDomjobabort(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -2576,7 +2577,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
     xmlXPathContextPtr ctxt = NULL;
 
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if ( (cell_given = vshCommandOptInt(cmd, "cellno", &cell)) < 0) {
@@ -2592,7 +2593,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (all_given) {
-        cap_xml = virConnectGetCapabilities(ctl->conn);
+        cap_xml = virConnectGetCapabilities(conn);
         if (!cap_xml) {
             vshError(ctl, "%s", _("unable to get node capabilities"));
             goto cleanup;
@@ -2630,7 +2631,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
             }
             VIR_FREE(val);
             nodes_id[i]=id;
-            ret = virNodeGetCellsFreeMemory(ctl->conn, &(nodes_free[i]), id, 1);
+            ret = virNodeGetCellsFreeMemory(conn, &(nodes_free[i]), id, 1);
             if (ret != 1) {
                 vshError(ctl, _("failed to get free memory for NUMA node "
                                 "number: %lu"), id);
@@ -2649,11 +2650,11 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
         vshPrintExtra(ctl, "%5s: %10llu kB\n", _("Total"), memory/1024);
     } else {
         if (!cell_given) {
-            memory = virNodeGetFreeMemory(ctl->conn);
+            memory = virNodeGetFreeMemory(conn);
             if (memory == 0)
                 goto cleanup;
         } else {
-            ret = virNodeGetCellsFreeMemory(ctl->conn, &memory, cell, 1);
+            ret = virNodeGetCellsFreeMemory(conn, &memory, cell, 1);
             if (ret != 1)
                 goto cleanup;
         }
@@ -2702,10 +2703,10 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    vcpus = virConnectGetMaxVcpus(ctl->conn, type);
+    vcpus = virConnectGetMaxVcpus(conn, type);
     if (vcpus < 0)
         return false;
     vshPrint(ctl, "%d\n", vcpus);
@@ -2765,7 +2766,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -2915,13 +2916,13 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     int n, m;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
 
-    if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
+    if (virNodeGetInfo(conn, &nodeinfo) != 0) {
         virDomainFree(dom);
         return false;
     }
@@ -3052,7 +3053,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
             flags = -1;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -3073,7 +3074,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
+    if (virNodeGetInfo(conn, &nodeinfo) != 0) {
         virDomainFree(dom);
         return false;
     }
@@ -3269,7 +3270,7 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
                  (config ? VIR_DOMAIN_AFFECT_CONFIG : 0) |
                  (live ? VIR_DOMAIN_AFFECT_LIVE : 0));
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -3335,7 +3336,7 @@ cmdInjectNMI(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom;
     int ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -3394,7 +3395,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
             flags = -1;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -3482,7 +3483,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
             flags = -1;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -3564,7 +3565,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
             flags |= VIR_DOMAIN_AFFECT_LIVE;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -3721,7 +3722,7 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
             flags |= VIR_DOMAIN_AFFECT_LIVE;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -3870,10 +3871,10 @@ cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     virNodeInfo info;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    if (virNodeGetInfo(ctl->conn, &info) < 0) {
+    if (virNodeGetInfo(conn, &info) < 0) {
         vshError(ctl, "%s", _("failed to get node information"));
         return false;
     }
@@ -3924,7 +3925,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
     double user_time, sys_time, idle_time, iowait_time, total_time;
     double usage;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptInt(cmd, "cpu", &cpuNum) < 0) {
@@ -3932,7 +3933,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    if (virNodeGetCPUStats(ctl->conn, cpuNum, NULL, &nparams, 0) != 0) {
+    if (virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, 0) != 0) {
         vshError(ctl, "%s",
                  _("Unable to get number of cpu stats"));
         return false;
@@ -3947,7 +3948,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
 
     i = 0;
     do {
-        if (virNodeGetCPUStats(ctl->conn, cpuNum, params, &nparams, 0) != 0) {
+        if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, 0) != 0) {
             vshError(ctl, "%s", _("Unable to get node cpu stats"));
             goto cleanup;
         }
@@ -4041,7 +4042,7 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
     virNodeMemoryStatsPtr params = NULL;
     bool ret = false;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptInt(cmd, "cell", &cellNum) < 0) {
@@ -4050,7 +4051,7 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
     }
 
     /* get the number of memory parameters */
-    if (virNodeGetMemoryStats(ctl->conn, cellNum, NULL, &nparams, 0) != 0) {
+    if (virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, 0) != 0) {
         vshError(ctl, "%s",
                  _("Unable to get number of memory stats"));
         goto cleanup;
@@ -4064,7 +4065,7 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
 
     /* now go get all the memory parameters */
     params = vshCalloc(ctl, nparams, sizeof(*params));
-    if (virNodeGetMemoryStats(ctl->conn, cellNum, params, &nparams, 0) != 0) {
+    if (virNodeGetMemoryStats(conn, cellNum, params, &nparams, 0) != 0) {
         vshError(ctl, "%s", _("Unable to get memory stats"));
         goto cleanup;
     }
@@ -4093,10 +4094,10 @@ cmdCapabilities (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     char *caps;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    if ((caps = virConnectGetCapabilities (ctl->conn)) == NULL) {
+    if ((caps = virConnectGetCapabilities (conn)) == NULL) {
         vshError(ctl, "%s", _("failed to get capabilities"));
         return false;
     }
@@ -4141,7 +4142,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
     if (update)
         flags |= VIR_DOMAIN_XML_UPDATE_CPU;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -4184,7 +4185,7 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
     char *xmlData;
     int flags = 0;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "format", &format) < 0 ||
@@ -4194,7 +4195,7 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(configFile, 1024*1024, &configData) < 0)
         return false;
 
-    xmlData = virConnectDomainXMLFromNative(ctl->conn, format, configData, flags);
+    xmlData = virConnectDomainXMLFromNative(conn, format, configData, flags);
     if (xmlData != NULL) {
         vshPrint(ctl, "%s", xmlData);
         VIR_FREE(xmlData);
@@ -4230,7 +4231,7 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
     char *xmlData;
     int flags = 0;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "format", &format) < 0
@@ -4240,7 +4241,7 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(xmlFile, 1024*1024, &xmlData) < 0)
         return false;
 
-    configData = virConnectDomainXMLToNative(ctl->conn, format, xmlData, flags);
+    configData = virConnectDomainXMLToNative(conn, format, xmlData, flags);
     if (configData != NULL) {
         vshPrint(ctl, "%s", configData);
         VIR_FREE(configData);
@@ -4270,7 +4271,7 @@ cmdDomname(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
                                       VSH_BYID|VSH_BYUUID)))
@@ -4301,7 +4302,7 @@ cmdDomid(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom;
     unsigned int id;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
                                       VSH_BYNAME|VSH_BYUUID)))
@@ -4336,7 +4337,7 @@ cmdDomuuid(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom;
     char uuid[VIR_UUID_STRING_BUFLEN];
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
                                       VSH_BYNAME|VSH_BYID)))
@@ -4409,7 +4410,7 @@ doMigrate (void *opaque)
         goto out_sig;
 #endif
 
-    if (!vshConnectionUsability (ctl, ctl->conn))
+    if (!vshConnectionUsability (ctl))
         goto out;
 
     if (!(dom = vshCommandOptDomain (ctl, cmd, NULL)))
@@ -4676,7 +4677,7 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd)
     long long downtime = 0;
     bool ret = false;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -4721,7 +4722,7 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd)
     unsigned long bandwidth = 0;
     bool ret = false;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -4765,7 +4766,7 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd)
     const char *name;
     int autostart;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
@@ -4813,7 +4814,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *buffer;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -4822,7 +4823,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    network = virNetworkCreateXML(ctl->conn, buffer);
+    network = virNetworkCreateXML(conn, buffer);
     VIR_FREE(buffer);
 
     if (network != NULL) {
@@ -4859,7 +4860,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *buffer;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -4868,7 +4869,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    network = virNetworkDefineXML(ctl->conn, buffer);
+    network = virNetworkDefineXML(conn, buffer);
     VIR_FREE(buffer);
 
     if (network != NULL) {
@@ -4904,7 +4905,7 @@ cmdNetworkDestroy(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
@@ -4943,7 +4944,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *dump;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
@@ -4985,7 +4986,7 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
     int active = -1;
     char *bridge = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
@@ -5045,7 +5046,7 @@ cmdInterfaceEdit (vshControl *ctl, const vshCmd *cmd)
     char *doc_reread = NULL;
     int flags = VIR_INTERFACE_XML_INACTIVE;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     iface = vshCommandOptInterface (ctl, cmd, NULL);
@@ -5092,7 +5093,7 @@ cmdInterfaceEdit (vshControl *ctl, const vshCmd *cmd)
 
     /* Everything checks out, so redefine the interface. */
     virInterfaceFree (iface);
-    iface = virInterfaceDefineXML (ctl->conn, doc_edited, 0);
+    iface = virInterfaceDefineXML (conn, doc_edited, 0);
     if (!iface)
         goto cleanup;
 
@@ -5142,11 +5143,11 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     char **activeNames = NULL, **inactiveNames = NULL;
     inactive |= all;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (active) {
-        maxactive = virConnectNumOfNetworks(ctl->conn);
+        maxactive = virConnectNumOfNetworks(conn);
         if (maxactive < 0) {
             vshError(ctl, "%s", _("Failed to list active networks"));
             return false;
@@ -5154,7 +5155,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         if (maxactive) {
             activeNames = vshMalloc(ctl, sizeof(char *) * maxactive);
 
-            if ((maxactive = virConnectListNetworks(ctl->conn, activeNames,
+            if ((maxactive = virConnectListNetworks(conn, activeNames,
                                                     maxactive)) < 0) {
                 vshError(ctl, "%s", _("Failed to list active networks"));
                 VIR_FREE(activeNames);
@@ -5165,7 +5166,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         }
     }
     if (inactive) {
-        maxinactive = virConnectNumOfDefinedNetworks(ctl->conn);
+        maxinactive = virConnectNumOfDefinedNetworks(conn);
         if (maxinactive < 0) {
             vshError(ctl, "%s", _("Failed to list inactive networks"));
             VIR_FREE(activeNames);
@@ -5175,7 +5176,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
             inactiveNames = vshMalloc(ctl, sizeof(char *) * maxinactive);
 
             if ((maxinactive =
-                     virConnectListDefinedNetworks(ctl->conn, inactiveNames,
+                     virConnectListDefinedNetworks(conn, inactiveNames,
                                                    maxinactive)) < 0) {
                 vshError(ctl, "%s", _("Failed to list inactive networks"));
                 VIR_FREE(activeNames);
@@ -5192,7 +5193,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
     for (i = 0; i < maxactive; i++) {
         virNetworkPtr network =
-            virNetworkLookupByName(ctl->conn, activeNames[i]);
+            virNetworkLookupByName(conn, activeNames[i]);
         const char *autostartStr;
         int autostart = 0;
 
@@ -5215,7 +5216,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         VIR_FREE(activeNames[i]);
     }
     for (i = 0; i < maxinactive; i++) {
-        virNetworkPtr network = virNetworkLookupByName(ctl->conn, inactiveNames[i]);
+        virNetworkPtr network = virNetworkLookupByName(conn, inactiveNames[i]);
         const char *autostartStr;
         int autostart = 0;
 
@@ -5263,7 +5264,7 @@ cmdNetworkName(vshControl *ctl, const vshCmd *cmd)
 {
     virNetworkPtr network;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
                                            VSH_BYUUID)))
@@ -5295,7 +5296,7 @@ cmdNetworkStart(vshControl *ctl, const vshCmd *cmd)
     virNetworkPtr network;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL, VSH_BYNAME)))
@@ -5335,7 +5336,7 @@ cmdNetworkUndefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
@@ -5373,7 +5374,7 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd)
     virNetworkPtr network;
     char uuid[VIR_UUID_STRING_BUFLEN];
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
@@ -5415,11 +5416,11 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     char **activeNames = NULL, **inactiveNames = NULL;
     inactive |= all;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (active) {
-        maxactive = virConnectNumOfInterfaces(ctl->conn);
+        maxactive = virConnectNumOfInterfaces(conn);
         if (maxactive < 0) {
             vshError(ctl, "%s", _("Failed to list active interfaces"));
             return false;
@@ -5427,7 +5428,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         if (maxactive) {
             activeNames = vshMalloc(ctl, sizeof(char *) * maxactive);
 
-            if ((maxactive = virConnectListInterfaces(ctl->conn, activeNames,
+            if ((maxactive = virConnectListInterfaces(conn, activeNames,
                                                     maxactive)) < 0) {
                 vshError(ctl, "%s", _("Failed to list active interfaces"));
                 VIR_FREE(activeNames);
@@ -5438,7 +5439,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         }
     }
     if (inactive) {
-        maxinactive = virConnectNumOfDefinedInterfaces(ctl->conn);
+        maxinactive = virConnectNumOfDefinedInterfaces(conn);
         if (maxinactive < 0) {
             vshError(ctl, "%s", _("Failed to list inactive interfaces"));
             VIR_FREE(activeNames);
@@ -5448,7 +5449,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
             inactiveNames = vshMalloc(ctl, sizeof(char *) * maxinactive);
 
             if ((maxinactive =
-                     virConnectListDefinedInterfaces(ctl->conn, inactiveNames,
+                     virConnectListDefinedInterfaces(conn, inactiveNames,
                                                      maxinactive)) < 0) {
                 vshError(ctl, "%s", _("Failed to list inactive interfaces"));
                 VIR_FREE(activeNames);
@@ -5465,7 +5466,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
     for (i = 0; i < maxactive; i++) {
         virInterfacePtr iface =
-            virInterfaceLookupByName(ctl->conn, activeNames[i]);
+            virInterfaceLookupByName(conn, activeNames[i]);
 
         /* this kind of work with interfaces is not atomic */
         if (!iface) {
@@ -5482,7 +5483,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     }
     for (i = 0; i < maxinactive; i++) {
         virInterfacePtr iface =
-            virInterfaceLookupByName(ctl->conn, inactiveNames[i]);
+            virInterfaceLookupByName(conn, inactiveNames[i]);
 
         /* this kind of work with interfaces is not atomic */
         if (!iface) {
@@ -5522,7 +5523,7 @@ cmdInterfaceName(vshControl *ctl, const vshCmd *cmd)
 {
     virInterfacePtr iface;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (!(iface = vshCommandOptInterfaceBy(ctl, cmd, NULL,
                                            VSH_BYMAC)))
@@ -5552,7 +5553,7 @@ cmdInterfaceMAC(vshControl *ctl, const vshCmd *cmd)
 {
     virInterfacePtr iface;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (!(iface = vshCommandOptInterfaceBy(ctl, cmd, NULL,
                                            VSH_BYNAME)))
@@ -5590,7 +5591,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
     if (inactive)
         flags |= VIR_INTERFACE_XML_INACTIVE;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(iface = vshCommandOptInterface(ctl, cmd, NULL)))
@@ -5630,7 +5631,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *buffer;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -5639,7 +5640,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    iface = virInterfaceDefineXML(ctl->conn, buffer, 0);
+    iface = virInterfaceDefineXML(conn, buffer, 0);
     VIR_FREE(buffer);
 
     if (iface != NULL) {
@@ -5674,7 +5675,7 @@ cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(iface = vshCommandOptInterface(ctl, cmd, &name)))
@@ -5712,7 +5713,7 @@ cmdInterfaceStart(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(iface = vshCommandOptInterface(ctl, cmd, &name)))
@@ -5750,7 +5751,7 @@ cmdInterfaceDestroy(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(iface = vshCommandOptInterface(ctl, cmd, &name)))
@@ -5785,10 +5786,10 @@ static const vshCmdOptDef opts_interface_begin[] = {
 static bool
 cmdInterfaceBegin(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    if (virInterfaceChangeBegin(ctl->conn, 0) < 0) {
+    if (virInterfaceChangeBegin(conn, 0) < 0) {
         vshError(ctl, "%s", _("Failed to begin network config change transaction"));
         return false;
     }
@@ -5813,10 +5814,10 @@ static const vshCmdOptDef opts_interface_commit[] = {
 static bool
 cmdInterfaceCommit(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    if (virInterfaceChangeCommit(ctl->conn, 0) < 0) {
+    if (virInterfaceChangeCommit(conn, 0) < 0) {
         vshError(ctl, "%s", _("Failed to commit network config change transaction"));
         return false;
     }
@@ -5841,10 +5842,10 @@ static const vshCmdOptDef opts_interface_rollback[] = {
 static bool
 cmdInterfaceRollback(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    if (virInterfaceChangeRollback(ctl->conn, 0) < 0) {
+    if (virInterfaceChangeRollback(conn, 0) < 0) {
         vshError(ctl, "%s", _("Failed to rollback network config change transaction"));
         return false;
     }
@@ -5875,7 +5876,7 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *buffer;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -5884,7 +5885,7 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    nwfilter = virNWFilterDefineXML(ctl->conn, buffer);
+    nwfilter = virNWFilterDefineXML(conn, buffer);
     VIR_FREE(buffer);
 
     if (nwfilter != NULL) {
@@ -5920,7 +5921,7 @@ cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(nwfilter = vshCommandOptNWFilter(ctl, cmd, &name)))
@@ -5959,7 +5960,7 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *dump;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(nwfilter = vshCommandOptNWFilter(ctl, cmd, NULL)))
@@ -5997,10 +5998,10 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     char **names;
     char uuid[VIR_UUID_STRING_BUFLEN];
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    numfilters = virConnectNumOfNWFilters(ctl->conn);
+    numfilters = virConnectNumOfNWFilters(conn);
     if (numfilters < 0) {
         vshError(ctl, "%s", _("Failed to list network filters"));
         return false;
@@ -6008,7 +6009,7 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
     names = vshMalloc(ctl, sizeof(char *) * numfilters);
 
-    if ((numfilters = virConnectListNWFilters(ctl->conn, names,
+    if ((numfilters = virConnectListNWFilters(conn, names,
                                               numfilters)) < 0) {
         vshError(ctl, "%s", _("Failed to list network filters"));
         VIR_FREE(names);
@@ -6023,7 +6024,7 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
     for (i = 0; i < numfilters; i++) {
         virNWFilterPtr nwfilter =
-            virNWFilterLookupByName(ctl->conn, names[i]);
+            virNWFilterLookupByName(conn, names[i]);
 
         /* this kind of work with networks is not atomic operation */
         if (!nwfilter) {
@@ -6068,7 +6069,7 @@ cmdNWFilterEdit (vshControl *ctl, const vshCmd *cmd)
     char *doc_edited = NULL;
     char *doc_reread = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     nwfilter = vshCommandOptNWFilter (ctl, cmd, NULL);
@@ -6115,7 +6116,7 @@ cmdNWFilterEdit (vshControl *ctl, const vshCmd *cmd)
 
     /* Everything checks out, so redefine the interface. */
     virNWFilterFree (nwfilter);
-    nwfilter = virNWFilterDefineXML (ctl->conn, doc_edited);
+    nwfilter = virNWFilterDefineXML (conn, doc_edited);
     if (!nwfilter)
         goto cleanup;
 
@@ -6165,7 +6166,7 @@ cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd)
     const char *name;
     int autostart;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
@@ -6214,7 +6215,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *buffer;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -6223,7 +6224,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    pool = virStoragePoolCreateXML(ctl->conn, buffer, 0);
+    pool = virStoragePoolCreateXML(conn, buffer, 0);
     VIR_FREE(buffer);
 
     if (pool != NULL) {
@@ -6264,7 +6265,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *buffer;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -6273,7 +6274,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0);
+    dev = virNodeDeviceCreateXML(conn, buffer, 0);
     VIR_FREE(buffer);
 
     if (dev != NULL) {
@@ -6312,14 +6313,14 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn)) {
+    if (!vshConnectionUsability(ctl)) {
         return false;
     }
 
     if (vshCommandOptString(cmd, "name", &name) <= 0)
         return false;
 
-    dev = virNodeDeviceLookupByName(ctl->conn, name);
+    dev = virNodeDeviceLookupByName(conn, name);
 
     if (virNodeDeviceDestroy(dev) == 0) {
         vshPrint(ctl, _("Destroyed node device '%s'\n"), name);
@@ -6426,7 +6427,7 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
     char *xml;
     int printXML = vshCommandOptBool(cmd, "print-xml");
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!buildPoolXML(cmd, &name, &xml))
@@ -6436,7 +6437,7 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", xml);
         VIR_FREE(xml);
     } else {
-        pool = virStoragePoolCreateXML(ctl->conn, xml, 0);
+        pool = virStoragePoolCreateXML(conn, xml, 0);
         VIR_FREE(xml);
 
         if (pool != NULL) {
@@ -6473,7 +6474,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *buffer;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -6482,7 +6483,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    pool = virStoragePoolDefineXML(ctl->conn, buffer, 0);
+    pool = virStoragePoolDefineXML(conn, buffer, 0);
     VIR_FREE(buffer);
 
     if (pool != NULL) {
@@ -6514,7 +6515,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
     char *xml;
     int printXML = vshCommandOptBool(cmd, "print-xml");
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!buildPoolXML(cmd, &name, &xml))
@@ -6524,7 +6525,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", xml);
         VIR_FREE(xml);
     } else {
-        pool = virStoragePoolDefineXML(ctl->conn, xml, 0);
+        pool = virStoragePoolDefineXML(conn, xml, 0);
         VIR_FREE(xml);
 
         if (pool != NULL) {
@@ -6560,7 +6561,7 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
@@ -6600,7 +6601,7 @@ cmdPoolDestroy(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
@@ -6639,7 +6640,7 @@ cmdPoolDelete(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
@@ -6678,7 +6679,7 @@ cmdPoolRefresh(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
@@ -6717,7 +6718,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *dump;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
@@ -6782,12 +6783,12 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     inactive |= all;
 
     /* Check the connection to libvirtd daemon is still working */
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     /* Retrieve the number of active storage pools */
     if (active) {
-        numActivePools = virConnectNumOfStoragePools(ctl->conn);
+        numActivePools = virConnectNumOfStoragePools(conn);
         if (numActivePools < 0) {
             vshError(ctl, "%s", _("Failed to list active pools"));
             return false;
@@ -6796,7 +6797,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
     /* Retrieve the number of inactive storage pools */
     if (inactive) {
-        numInactivePools = virConnectNumOfDefinedStoragePools(ctl->conn);
+        numInactivePools = virConnectNumOfDefinedStoragePools(conn);
         if (numInactivePools < 0) {
             vshError(ctl, "%s", _("Failed to list inactive pools"));
             return false;
@@ -6813,7 +6814,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
     /* Retrieve a list of active storage pool names */
     if (active) {
-        if ((virConnectListStoragePools(ctl->conn,
+        if ((virConnectListStoragePools(conn,
                                         poolNames, numActivePools)) < 0) {
             vshError(ctl, "%s", _("Failed to list active pools"));
             VIR_FREE(poolInfoTexts);
@@ -6824,7 +6825,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
     /* Add the inactive storage pools to the end of the name list */
     if (inactive) {
-        if ((virConnectListDefinedStoragePools(ctl->conn,
+        if ((virConnectListDefinedStoragePools(conn,
                                                &poolNames[numActivePools],
                                                numInactivePools)) < 0) {
             vshError(ctl, "%s", _("Failed to list inactive pools"));
@@ -6842,7 +6843,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         int autostart = 0, persistent = 0;
 
         /* Retrieve a pool object, looking it up by name */
-        virStoragePoolPtr pool = virStoragePoolLookupByName(ctl->conn,
+        virStoragePoolPtr pool = virStoragePoolLookupByName(conn,
                                                             poolNames[i]);
         if (!pool) {
             VIR_FREE(poolNames[i]);
@@ -7178,7 +7179,7 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
         return false;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (host) {
@@ -7208,7 +7209,7 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
         srcSpec = virBufferContentAndReset(&buf);
     }
 
-    srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0);
+    srcList = virConnectFindStoragePoolSources(conn, type, srcSpec, 0);
     VIR_FREE(srcSpec);
     if (srcList == NULL) {
         vshError(ctl, _("Failed to find any %s pool sources"), type);
@@ -7252,13 +7253,13 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
         return false;
     }
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (srcSpecFile && virFileReadAll(srcSpecFile, VIRSH_MAX_XML_FILE, &srcSpec) < 0)
         return false;
 
-    srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0);
+    srcList = virConnectFindStoragePoolSources(conn, type, srcSpec, 0);
     VIR_FREE(srcSpec);
     if (srcList == NULL) {
         vshError(ctl, _("Failed to find any %s pool sources"), type);
@@ -7295,7 +7296,7 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char uuid[VIR_UUID_STRING_BUFLEN];
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
@@ -7387,7 +7388,7 @@ cmdPoolName(vshControl *ctl, const vshCmd *cmd)
 {
     virStoragePoolPtr pool;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
                                            VSH_BYUUID)))
@@ -7419,7 +7420,7 @@ cmdPoolStart(vshControl *ctl, const vshCmd *cmd)
     virStoragePoolPtr pool;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL, VSH_BYNAME)))
@@ -7500,7 +7501,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
     unsigned long long capacity, allocation = 0;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
@@ -7555,7 +7556,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
              *  backing-vol parameter as a key */
             vshDebug(ctl, 5, "%s: Look up backing store volume '%s' as key\n",
                      cmd->def->name, snapshotStrVol);
-            snapVol = virStorageVolLookupByKey(ctl->conn, snapshotStrVol);
+            snapVol = virStorageVolLookupByKey(conn, snapshotStrVol);
             if (snapVol)
                 vshDebug(ctl, 5, "%s: Backing store volume found using '%s' as key\n",
                          cmd->def->name, snapshotStrVol);
@@ -7565,7 +7566,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
              *  backing-vol parameter as a path */
             vshDebug(ctl, 5, "%s: Look up backing store volume '%s' as path\n",
                      cmd->def->name, snapshotStrVol);
-            snapVol = virStorageVolLookupByPath(ctl->conn, snapshotStrVol);
+            snapVol = virStorageVolLookupByPath(conn, snapshotStrVol);
             if (snapVol)
                 vshDebug(ctl, 5, "%s: Backing store volume found using '%s' as path\n",
                          cmd->def->name, snapshotStrVol);
@@ -7641,7 +7642,7 @@ cmdPoolUndefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
@@ -7679,7 +7680,7 @@ cmdPoolUuid(vshControl *ctl, const vshCmd *cmd)
     virStoragePoolPtr pool;
     char uuid[VIR_UUID_STRING_BUFLEN];
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
@@ -7720,7 +7721,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *buffer;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
@@ -7779,7 +7780,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     char *buffer = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL, VSH_BYNAME)))
@@ -7877,7 +7878,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
     xmlChar *newxml = NULL;
     bool ret = false;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     if (!(origvol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
@@ -7966,7 +7967,7 @@ cmdVolUpload (vshControl *ctl, const vshCmd *cmd)
     const char *name = NULL;
     unsigned long long offset = 0, length = 0;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     if (vshCommandOptULongLong(cmd, "offset", &offset) < 0) {
@@ -7993,7 +7994,7 @@ cmdVolUpload (vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    st = virStreamNew(ctl->conn, 0);
+    st = virStreamNew(conn, 0);
     if (virStorageVolUpload(vol, st, offset, length, 0) < 0) {
         vshError(ctl, _("cannot upload to volume %s"), name);
         goto cleanup;
@@ -8058,7 +8059,7 @@ cmdVolDownload (vshControl *ctl, const vshCmd *cmd)
     unsigned long long offset = 0, length = 0;
     bool created = false;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptULongLong(cmd, "offset", &offset) < 0) {
@@ -8089,7 +8090,7 @@ cmdVolDownload (vshControl *ctl, const vshCmd *cmd)
         created = true;
     }
 
-    st = virStreamNew(ctl->conn, 0);
+    st = virStreamNew(conn, 0);
     if (virStorageVolDownload(vol, st, offset, length, 0) < 0) {
         vshError(ctl, _("cannot download from volume %s"), name);
         goto cleanup;
@@ -8147,7 +8148,7 @@ cmdVolDelete(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) {
@@ -8188,7 +8189,7 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     const char *name;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) {
@@ -8229,7 +8230,7 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
     virStorageVolPtr vol;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
@@ -8280,7 +8281,7 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
     bool ret = true;
     char *dump;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
@@ -8340,7 +8341,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     struct volInfoText *volInfoTexts = NULL;
 
     /* Check the connection to libvirtd daemon is still working */
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     /* Look up the pool information given to us by the user */
@@ -8602,7 +8603,7 @@ cmdVolName(vshControl *ctl, const vshCmd *cmd)
 {
     virStorageVolPtr vol;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(vol = vshCommandOptVolBy(ctl, cmd, "vol", "pool", NULL,
@@ -8638,7 +8639,7 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd)
     char uuid[VIR_UUID_STRING_BUFLEN];
 
     /* Check the connection to libvirtd daemon is still working */
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     /* Use the supplied string to locate the volume */
@@ -8692,7 +8693,7 @@ cmdVolKey(vshControl *ctl, const vshCmd *cmd)
 {
     virStorageVolPtr vol;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
@@ -8726,7 +8727,7 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd)
     virStorageVolPtr vol;
     const char *name = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) {
@@ -8761,7 +8762,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
     virSecretPtr res;
     char uuid[VIR_UUID_STRING_BUFLEN];
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -8770,7 +8771,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    res = virSecretDefineXML(ctl->conn, buffer, 0);
+    res = virSecretDefineXML(conn, buffer, 0);
     VIR_FREE(buffer);
 
     if (res == NULL) {
@@ -8808,7 +8809,7 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     char *xml;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     secret = vshCommandOptSecret(ctl, cmd, NULL);
@@ -8852,7 +8853,7 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
     int res;
     bool ret = false;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     secret = vshCommandOptSecret(ctl, cmd, NULL);
@@ -8910,7 +8911,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
     size_t value_size;
     bool ret = false;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     secret = vshCommandOptSecret(ctl, cmd, NULL);
@@ -8960,7 +8961,7 @@ cmdSecretUndefine(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     const char *uuid;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     secret = vshCommandOptSecret(ctl, cmd, &uuid);
@@ -8994,17 +8995,17 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     int maxuuids = 0, i;
     char **uuids = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    maxuuids = virConnectNumOfSecrets(ctl->conn);
+    maxuuids = virConnectNumOfSecrets(conn);
     if (maxuuids < 0) {
         vshError(ctl, "%s", _("Failed to list secrets"));
         return false;
     }
     uuids = vshMalloc(ctl, sizeof(*uuids) * maxuuids);
 
-    maxuuids = virConnectListSecrets(ctl->conn, uuids, maxuuids);
+    maxuuids = virConnectListSecrets(conn, uuids, maxuuids);
     if (maxuuids < 0) {
         vshError(ctl, "%s", _("Failed to list secrets"));
         VIR_FREE(uuids);
@@ -9017,7 +9018,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     vshPrintExtra(ctl, "-----------------------------------------------------------\n");
 
     for (i = 0; i < maxuuids; i++) {
-        virSecretPtr sec = virSecretLookupByUUIDString(ctl->conn, uuids[i]);
+        virSecretPtr sec = virSecretLookupByUUIDString(conn, uuids[i]);
         const char *usageType = NULL;
 
         if (!sec) {
@@ -9075,10 +9076,10 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     unsigned int minor;
     unsigned int rel;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    hvType = virConnectGetType(ctl->conn);
+    hvType = virConnectGetType(conn);
     if (hvType == NULL) {
         vshError(ctl, "%s", _("failed to get hypervisor type"));
         return false;
@@ -9111,7 +9112,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     vshPrint(ctl, _("Using API: %s %d.%d.%d\n"), hvType,
              major, minor, rel);
 
-    ret = virConnectGetVersion(ctl->conn, &hvVersion);
+    ret = virConnectGetVersion(conn, &hvVersion);
     if (ret < 0) {
         vshError(ctl, "%s", _("failed to get the hypervisor version"));
         return false;
@@ -9130,7 +9131,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     }
 
     if (vshCommandOptBool(cmd, "daemon")) {
-        ret = virConnectGetLibVersion(ctl->conn, &daemonVersion);
+        ret = virConnectGetLibVersion(conn, &daemonVersion);
         if (ret < 0) {
             vshError(ctl, "%s", _("failed to get the daemon version"));
         } else {
@@ -9249,13 +9250,13 @@ cmdNodeListDevices (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     int num_devices, i;
     int tree = vshCommandOptBool(cmd, "tree");
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "cap", &cap) <= 0)
         cap = NULL;
 
-    num_devices = virNodeNumOfDevices(ctl->conn, cap, 0);
+    num_devices = virNodeNumOfDevices(conn, cap, 0);
     if (num_devices < 0) {
         vshError(ctl, "%s", _("Failed to count node devices"));
         return false;
@@ -9265,7 +9266,7 @@ cmdNodeListDevices (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 
     devices = vshMalloc(ctl, sizeof(char *) * num_devices);
     num_devices =
-        virNodeListDevices(ctl->conn, cap, devices, num_devices, 0);
+        virNodeListDevices(conn, cap, devices, num_devices, 0);
     if (num_devices < 0) {
         vshError(ctl, "%s", _("Failed to list node devices"));
         VIR_FREE(devices);
@@ -9276,7 +9277,7 @@ cmdNodeListDevices (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         char indentBuf[INDENT_BUFLEN];
         char **parents = vshMalloc(ctl, sizeof(char *) * num_devices);
         for (i = 0; i < num_devices; i++) {
-            virNodeDevicePtr dev = virNodeDeviceLookupByName(ctl->conn, devices[i]);
+            virNodeDevicePtr dev = virNodeDeviceLookupByName(conn, devices[i]);
             if (dev && STRNEQ(devices[i], "computer")) {
                 const char *parent = virNodeDeviceGetParent(dev);
                 parents[i] = parent ? vshStrdup(ctl, parent) : NULL;
@@ -9335,11 +9336,11 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)
     virNodeDevicePtr device;
     char *xml;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (vshCommandOptString(cmd, "device", &name) <= 0)
         return false;
-    if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
+    if (!(device = virNodeDeviceLookupByName(conn, name))) {
         vshError(ctl, "%s '%s'", _("Could not find matching device"), name);
         return false;
     }
@@ -9378,11 +9379,11 @@ cmdNodeDeviceDettach (vshControl *ctl, const vshCmd *cmd)
     virNodeDevicePtr device;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (vshCommandOptString(cmd, "device", &name) <= 0)
         return false;
-    if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
+    if (!(device = virNodeDeviceLookupByName(conn, name))) {
         vshError(ctl, "%s '%s'", _("Could not find matching device"), name);
         return false;
     }
@@ -9419,11 +9420,11 @@ cmdNodeDeviceReAttach (vshControl *ctl, const vshCmd *cmd)
     virNodeDevicePtr device;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (vshCommandOptString(cmd, "device", &name) <= 0)
         return false;
-    if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
+    if (!(device = virNodeDeviceLookupByName(conn, name))) {
         vshError(ctl, "%s '%s'", _("Could not find matching device"), name);
         return false;
     }
@@ -9460,11 +9461,11 @@ cmdNodeDeviceReset (vshControl *ctl, const vshCmd *cmd)
     virNodeDevicePtr device;
     bool ret = true;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
     if (vshCommandOptString(cmd, "device", &name) <= 0)
         return false;
-    if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
+    if (!(device = virNodeDeviceLookupByName(conn, name))) {
         vshError(ctl, "%s '%s'", _("Could not find matching device"), name);
         return false;
     }
@@ -9493,10 +9494,10 @@ cmdHostname (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     char *hostname;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    hostname = virConnectGetHostname (ctl->conn);
+    hostname = virConnectGetHostname (conn);
     if (hostname == NULL) {
         vshError(ctl, "%s", _("failed to get hostname"));
         return false;
@@ -9522,10 +9523,10 @@ cmdURI (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     char *uri;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    uri = virConnectGetURI (ctl->conn);
+    uri = virConnectGetURI (conn);
     if (uri == NULL) {
         vshError(ctl, "%s", _("failed to get URI"));
         return false;
@@ -9552,10 +9553,10 @@ cmdSysinfo (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 {
     char *sysinfo;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
-    sysinfo = virConnectGetSysinfo (ctl->conn, 0);
+    sysinfo = virConnectGetSysinfo (conn, 0);
     if (sysinfo == NULL) {
         vshError(ctl, "%s", _("failed to get sysinfo"));
         return false;
@@ -9592,7 +9593,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
     int port = 0;
     char *doc;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -9666,7 +9667,7 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     char *doc;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -9728,7 +9729,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
     int ret;
     unsigned int flags;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -9793,7 +9794,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
     int ret;
     unsigned int flags;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -9859,7 +9860,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
     int ret;
     unsigned int flags;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -9937,7 +9938,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     char *xml;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -10051,7 +10052,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
     int functionReturn = false;
     unsigned int flags;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -10196,7 +10197,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     char *xml;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -10326,7 +10327,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
     bool functionReturn = false;
     unsigned int flags;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
@@ -10443,7 +10444,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
     char *buffer;
     int result;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -10452,7 +10453,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    result = virConnectCompareCPU(ctl->conn, buffer, 0);
+    result = virConnectCompareCPU(conn, buffer, 0);
     VIR_FREE(buffer);
 
     switch (result) {
@@ -10514,7 +10515,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
     xmlXPathObjectPtr obj = NULL;
     int res, i;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         return false;
 
     if (vshCommandOptString(cmd, "file", &from) <= 0)
@@ -10572,7 +10573,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    result = virConnectBaselineCPU(ctl->conn, list, count, 0);
+    result = virConnectBaselineCPU(conn, list, count, 0);
 
     if (result)
         vshPrint(ctl, "%s", result);
@@ -10885,7 +10886,7 @@ cmdEdit (vshControl *ctl, const vshCmd *cmd)
     char *doc_reread = NULL;
     int flags = VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_INACTIVE;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     dom = vshCommandOptDomain (ctl, cmd, NULL);
@@ -10932,7 +10933,7 @@ cmdEdit (vshControl *ctl, const vshCmd *cmd)
 
     /* Everything checks out, so redefine the domain. */
     virDomainFree (dom);
-    dom = virDomainDefineXML (ctl->conn, doc_edited);
+    dom = virDomainDefineXML (conn, doc_edited);
     if (!dom)
         goto cleanup;
 
@@ -11036,7 +11037,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
     char *doc = NULL;
     char *name = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     dom = vshCommandOptDomain(ctl, cmd, NULL);
@@ -11138,7 +11139,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
     char *parsed_name = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     dom = vshCommandOptDomain(ctl, cmd, NULL);
@@ -11235,7 +11236,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
     int current;
     virDomainSnapshotPtr snapshot = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     dom = vshCommandOptDomain(ctl, cmd, NULL);
@@ -11303,7 +11304,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
     char timestr[100];
     struct tm time_info;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     dom = vshCommandOptDomain(ctl, cmd, NULL);
@@ -11417,7 +11418,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd)
     virDomainSnapshotPtr snapshot = NULL;
     char *xml = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     dom = vshCommandOptDomain(ctl, cmd, NULL);
@@ -11472,7 +11473,7 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd)
     const char *name = NULL;
     virDomainSnapshotPtr snapshot = NULL;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     dom = vshCommandOptDomain(ctl, cmd, NULL);
@@ -11525,7 +11526,7 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd)
     virDomainSnapshotPtr snapshot = NULL;
     unsigned int flags = 0;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     dom = vshCommandOptDomain(ctl, cmd, NULL);
@@ -11581,7 +11582,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
     char *result = NULL;
     unsigned int flags = 0;
 
-    if (!vshConnectionUsability(ctl, ctl->conn))
+    if (!vshConnectionUsability(ctl))
         goto cleanup;
 
     dom = vshCommandOptDomain(ctl, cmd, NULL);
@@ -12463,20 +12464,20 @@ vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
         if (virStrToLong_i(n, NULL, 10, &id) == 0 && id >= 0) {
             vshDebug(ctl, 5, "%s: <%s> seems like domain ID\n",
                      cmd->def->name, optname);
-            dom = virDomainLookupByID(ctl->conn, id);
+            dom = virDomainLookupByID(conn, id);
         }
     }
     /* try it by UUID */
     if (dom==NULL && (flag & VSH_BYUUID) && strlen(n)==VIR_UUID_STRING_BUFLEN-1) {
         vshDebug(ctl, 5, "%s: <%s> trying as domain UUID\n",
                  cmd->def->name, optname);
-        dom = virDomainLookupByUUIDString(ctl->conn, n);
+        dom = virDomainLookupByUUIDString(conn, n);
     }
     /* try it by NAME */
     if (dom==NULL && (flag & VSH_BYNAME)) {
         vshDebug(ctl, 5, "%s: <%s> trying as domain NAME\n",
                  cmd->def->name, optname);
-        dom = virDomainLookupByName(ctl->conn, n);
+        dom = virDomainLookupByName(conn, n);
     }
 
     if (!dom)
@@ -12508,13 +12509,13 @@ vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
     if ((flag & VSH_BYUUID) && (strlen(n) == VIR_UUID_STRING_BUFLEN-1)) {
         vshDebug(ctl, 5, "%s: <%s> trying as network UUID\n",
                  cmd->def->name, optname);
-        network = virNetworkLookupByUUIDString(ctl->conn, n);
+        network = virNetworkLookupByUUIDString(conn, n);
     }
     /* try it by NAME */
     if (network==NULL && (flag & VSH_BYNAME)) {
         vshDebug(ctl, 5, "%s: <%s> trying as network NAME\n",
                  cmd->def->name, optname);
-        network = virNetworkLookupByName(ctl->conn, n);
+        network = virNetworkLookupByName(conn, n);
     }
 
     if (!network)
@@ -12547,13 +12548,13 @@ vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
     if ((flag & VSH_BYUUID) && (strlen(n) == VIR_UUID_STRING_BUFLEN-1)) {
         vshDebug(ctl, 5, "%s: <%s> trying as nwfilter UUID\n",
                  cmd->def->name, optname);
-        nwfilter = virNWFilterLookupByUUIDString(ctl->conn, n);
+        nwfilter = virNWFilterLookupByUUIDString(conn, n);
     }
     /* try it by NAME */
     if (nwfilter == NULL && (flag & VSH_BYNAME)) {
         vshDebug(ctl, 5, "%s: <%s> trying as nwfilter NAME\n",
                  cmd->def->name, optname);
-        nwfilter = virNWFilterLookupByName(ctl->conn, n);
+        nwfilter = virNWFilterLookupByName(conn, n);
     }
 
     if (!nwfilter)
@@ -12585,13 +12586,13 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
     if ((flag & VSH_BYNAME)) {
         vshDebug(ctl, 5, "%s: <%s> trying as interface NAME\n",
                  cmd->def->name, optname);
-        iface = virInterfaceLookupByName(ctl->conn, n);
+        iface = virInterfaceLookupByName(conn, n);
     }
     /* try it by MAC */
     if ((iface == NULL) && (flag & VSH_BYMAC)) {
         vshDebug(ctl, 5, "%s: <%s> trying as interface MAC\n",
                  cmd->def->name, optname);
-        iface = virInterfaceLookupByMACString(ctl->conn, n);
+        iface = virInterfaceLookupByMACString(conn, n);
     }
 
     if (!iface)
@@ -12620,13 +12621,13 @@ vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
     if ((flag & VSH_BYUUID) && (strlen(n) == VIR_UUID_STRING_BUFLEN-1)) {
         vshDebug(ctl, 5, "%s: <%s> trying as pool UUID\n",
                  cmd->def->name, optname);
-        pool = virStoragePoolLookupByUUIDString(ctl->conn, n);
+        pool = virStoragePoolLookupByUUIDString(conn, n);
     }
     /* try it by NAME */
     if (pool == NULL && (flag & VSH_BYNAME)) {
         vshDebug(ctl, 5, "%s: <%s> trying as pool NAME\n",
                  cmd->def->name, optname);
-        pool = virStoragePoolLookupByName(ctl->conn, n);
+        pool = virStoragePoolLookupByName(conn, n);
     }
 
     if (!pool)
@@ -12672,13 +12673,13 @@ vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
     if (vol == NULL && (flag & VSH_BYUUID)) {
         vshDebug(ctl, 5, "%s: <%s> trying as vol key\n",
                  cmd->def->name, optname);
-        vol = virStorageVolLookupByKey(ctl->conn, n);
+        vol = virStorageVolLookupByKey(conn, n);
     }
     /* try it by path */
     if (vol == NULL && (flag & VSH_BYUUID)) {
         vshDebug(ctl, 5, "%s: <%s> trying as vol path\n",
                  cmd->def->name, optname);
-        vol = virStorageVolLookupByPath(ctl->conn, n);
+        vol = virStorageVolLookupByPath(conn, n);
     }
 
     if (!vol)
@@ -12708,7 +12709,7 @@ vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
     if (name != NULL)
         *name = n;
 
-    secret = virSecretLookupByUUIDString(ctl->conn, n);
+    secret = virSecretLookupByUUIDString(conn, n);
 
     if (secret == NULL)
         vshError(ctl, _("failed to get secret '%s'"), n);
@@ -12728,7 +12729,7 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd)
         struct timeval before, after;
         bool enable_timing = ctl->timing;
 
-        if ((ctl->conn == NULL || disconnected) &&
+        if ((conn == NULL || disconnected) &&
             !(cmd->def->flags & VSH_CMD_FLAG_NOCONNECT))
             vshReconnect(ctl);
 
@@ -13252,7 +13253,7 @@ vshDomainVcpuStateToString(int state)
 }
 
 static bool
-vshConnectionUsability(vshControl *ctl, virConnectPtr conn)
+vshConnectionUsability(vshControl *ctl)
 {
     /* TODO: use something like virConnectionState() to
      *       check usability of the connection
@@ -13342,7 +13343,7 @@ vshInit(vshControl *ctl)
 {
     char *debugEnv;
 
-    if (ctl->conn)
+    if (conn)
         return false;
 
     if (ctl->debug == -1) {
@@ -13378,9 +13379,9 @@ vshInit(vshControl *ctl)
         return false;
 
     if (ctl->name) {
-        ctl->conn = virConnectOpenAuth(ctl->name,
-                                       virConnectAuthPtrDefault,
-                                       ctl->readonly ? VIR_CONNECT_RO : 0);
+        conn = virConnectOpenAuth(ctl->name,
+                                  virConnectAuthPtrDefault,
+                                  ctl->readonly ? VIR_CONNECT_RO : 0);
 
         /* Connecting to a named connection must succeed, but we delay
          * connecting to the default connection until we need it
@@ -13388,7 +13389,7 @@ vshInit(vshControl *ctl)
          * non-default connection, or might be 'help' which needs no
          * connection).
          */
-        if (!ctl->conn) {
+        if (!conn) {
             virshReportError(ctl);
             vshError(ctl, "%s", _("failed to connect to the hypervisor"));
             return false;
@@ -13768,9 +13769,9 @@ vshDeinit(vshControl *ctl)
     vshReadlineDeinit(ctl);
     vshCloseLogFile(ctl);
     VIR_FREE(ctl->name);
-    if (ctl->conn) {
+    if (conn) {
         int ret;
-        if ((ret = virConnectClose(ctl->conn)) != 0) {
+        if ((ret = virConnectClose(conn)) != 0) {
             vshError(ctl, _("Failed to disconnect from the hypervisor, %d leaked reference(s)"), ret);
         }
     }
-- 
1.7.5.rc3


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