From 725bffa7825d7b22f330f7ad2375bc5e8aa61ca0 Mon Sep 17 00:00:00 2001 From: Maxim Nestratov Date: Wed, 18 Mar 2015 11:33:52 +0300 Subject: [PATCH] parallels: fix parallelsLoadNetworks Don't fail initialization of parallels driver if parallelsLoadNetwork fails for optional networks. This can happen when some of them are added manually and configured incompletely. PCS requires only two networks created automatically (named Host-Only and Bridged), others are optional and their incompleteness can be ignored. Signed-off-by: Maxim Nestratov Signed-off-by: Michal Privoznik --- src/parallels/parallels_network.c | 49 ++++++++++++++++++------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/parallels/parallels_network.c b/src/parallels/parallels_network.c index bb7ec5ef7c..8cc0582f26 100644 --- a/src/parallels/parallels_network.c +++ b/src/parallels/parallels_network.c @@ -180,10 +180,11 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name) return ret; } -static virNetworkObjPtr +static int parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj) { - virNetworkObjPtr net; + int ret = -1; + virNetworkObjPtr net = NULL; virNetworkDefPtr def; const char *tmp; /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */ @@ -214,13 +215,25 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj) if (STREQ(tmp, PARALLELS_BRIDGED_NETWORK_TYPE)) { def->forward.type = VIR_NETWORK_FORWARD_BRIDGE; - if (parallelsGetBridgedNetInfo(def, jobj) < 0) + if (parallelsGetBridgedNetInfo(def, jobj) < 0) { + + /* Only mandatory networks are required to be configured completely */ + if (STRNEQ(def->name, PARALLELS_REQUIRED_BRIDGED_NETWORK)) + ret = 0; + goto cleanup; + } } else if (STREQ(tmp, PARALLELS_HOSTONLY_NETWORK_TYPE)) { def->forward.type = VIR_NETWORK_FORWARD_NONE; - if (parallelsGetHostOnlyNetInfo(def, def->name) < 0) + if (parallelsGetHostOnlyNetInfo(def, def->name) < 0) { + + /* Only mandatory networks are required to be configured completely */ + if (STRNEQ(def->name, PARALLELS_REQUIRED_HOSTONLY_NETWORK)) + ret = 0; + goto cleanup; + } } else { parallelsParseError(); goto cleanup; @@ -228,16 +241,18 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj) if (!(net = virNetworkAssignDef(privconn->networks, def, false))) goto cleanup; + def = NULL; net->active = 1; net->autostart = 1; - return net; + ret = 0; cleanup: + virNetworkObjEndAPI(&net); virNetworkDefFree(def); - return NULL; + return ret; } -static virNetworkObjPtr +static int parallelsAddRoutedNetwork(parallelsConnPtr privconn) { virNetworkObjPtr net = NULL; @@ -258,24 +273,23 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn) } def->uuid_specified = 1; - if (!(net = virNetworkAssignDef(privconn->networks, def, false))) { - virNetworkDefFree(def); + if (!(net = virNetworkAssignDef(privconn->networks, def, false))) goto cleanup; - } + net->active = 1; net->autostart = 1; + virNetworkObjEndAPI(&net); - return net; + return 0; cleanup: virNetworkDefFree(def); - return NULL; + return -1; } static int parallelsLoadNetworks(parallelsConnPtr privconn) { virJSONValuePtr jobj, jobj2; - virNetworkObjPtr net = NULL; int ret = -1; int count; size_t i; @@ -300,22 +314,17 @@ static int parallelsLoadNetworks(parallelsConnPtr privconn) goto cleanup; } - net = parallelsLoadNetwork(privconn, jobj2); - if (!net) + if (parallelsLoadNetwork(privconn, jobj2) < 0) goto cleanup; - else - virNetworkObjEndAPI(&net); - } - if (!(net = parallelsAddRoutedNetwork(privconn))) + if (parallelsAddRoutedNetwork(privconn) < 0) goto cleanup; ret = 0; cleanup: virJSONValueFree(jobj); - virNetworkObjEndAPI(&net); return ret; }