mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh: Don't clear old connection if 'connect $uri' fails
virsh # list --all Id Name State ---------------------------------------------------- 1 test running virsh # connect frob error: Failed to connect to the hypervisor error: no connection driver available for frob virsh # list --all error: failed to connect to the hypervisor error: no valid connection error: no connection driver available for frob Seems sensible IMO to just not clear out the old connection state until the new virConnectOpen succeeds. https://bugzilla.redhat.com/show_bug.cgi?id=829160
This commit is contained in:
parent
f1bae376b7
commit
a02a859be4
@ -292,6 +292,17 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ro = vshCommandOptBool(cmd, "readonly");
|
bool ro = vshCommandOptBool(cmd, "readonly");
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
virshControlPtr priv = ctl->privData;
|
virshControlPtr priv = ctl->privData;
|
||||||
|
virConnectPtr conn;
|
||||||
|
|
||||||
|
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
conn = virshConnect(ctl, name, ro);
|
||||||
|
|
||||||
|
if (!conn) {
|
||||||
|
vshError(ctl, "%s", _("Failed to connect to the hypervisor"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (priv->conn) {
|
if (priv->conn) {
|
||||||
int ret;
|
int ret;
|
||||||
@ -303,13 +314,10 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
|
|||||||
else if (ret > 0)
|
else if (ret > 0)
|
||||||
vshError(ctl, "%s", _("One or more references were leaked after "
|
vshError(ctl, "%s", _("One or more references were leaked after "
|
||||||
"disconnect from the hypervisor"));
|
"disconnect from the hypervisor"));
|
||||||
priv->conn = NULL;
|
|
||||||
}
|
}
|
||||||
|
priv->conn = conn;
|
||||||
|
|
||||||
VIR_FREE(ctl->connname);
|
VIR_FREE(ctl->connname);
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ctl->connname = vshStrdup(ctl, name);
|
ctl->connname = vshStrdup(ctl, name);
|
||||||
|
|
||||||
priv->useGetInfo = false;
|
priv->useGetInfo = false;
|
||||||
@ -317,13 +325,6 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
|
|||||||
priv->blockJobNoBytes = false;
|
priv->blockJobNoBytes = false;
|
||||||
priv->readonly = ro;
|
priv->readonly = ro;
|
||||||
|
|
||||||
priv->conn = virshConnect(ctl, ctl->connname, priv->readonly);
|
|
||||||
|
|
||||||
if (!priv->conn) {
|
|
||||||
vshError(ctl, "%s", _("Failed to connect to the hypervisor"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virConnectRegisterCloseCallback(priv->conn, virshCatchDisconnect,
|
if (virConnectRegisterCloseCallback(priv->conn, virshCatchDisconnect,
|
||||||
ctl, NULL) < 0)
|
ctl, NULL) < 0)
|
||||||
vshError(ctl, "%s", _("Unable to register disconnect callback"));
|
vshError(ctl, "%s", _("Unable to register disconnect callback"));
|
||||||
|
Loading…
Reference in New Issue
Block a user