On 13.03.2015 16:52, Maxim Nestratov wrote:
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 incompletenes can be ignored.
Signed-off-by: Maxim Nestratov <mnestratov(a)parallels.com>
---
src/parallels/parallels_network.c | 43 +++++++++++++++++++++++-------------
1 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/src/parallels/parallels_network.c b/src/parallels/parallels_network.c
index bb7ec5e..4dc7115 100644
--- a/src/parallels/parallels_network.c
+++ b/src/parallels/parallels_network.c
@@ -180,9 +180,10 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const
char *name)
return ret;
}
-static virNetworkObjPtr
+static int
parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj)
{
+ int ret = -1;
virNetworkObjPtr net;
virNetworkDefPtr def;
const char *tmp;
@@ -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 required to be configured completely */
s/networks required/networks are required/
+ if (!STREQ(def->name,
PARALLELS_REQUIRED_BRIDGED_NETWORK))
s/!STREQ/STRNEQ/
+ 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 required to be configured completely */
+ if (!STREQ(def->name, PARALLELS_REQUIRED_HOSTONLY_NETWORK))
+ ret = 0;
+
goto cleanup;
+ }
} else {
parallelsParseError();
goto cleanup;
@@ -230,14 +243,16 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr
jobj)
goto cleanup;
net->active = 1;
net->autostart = 1;
- return net;
+ virNetworkObjEndAPI(&net);
+ ret = 0;
+ return ret;
This doesn't make much sense. drop return, let it fall through cleanup,
and move virNetworkObjEndAPI() under the label. Of course, @def should
be set to NULL as soon as virNetworkAssignDef() succeeds.
cleanup:
virNetworkDefFree(def);
- return NULL;
+ return ret;
}
-static virNetworkObjPtr
+static int
parallelsAddRoutedNetwork(parallelsConnPtr privconn)
{
virNetworkObjPtr net = NULL;
@@ -264,18 +279,18 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn)
}
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 +315,18 @@ static int parallelsLoadNetworks(parallelsConnPtr privconn)
goto cleanup;
}
- net = parallelsLoadNetwork(privconn, jobj2);
- if (!net)
+ ret = parallelsLoadNetwork(privconn, jobj2);
+ if (!ret)
goto cleanup;
- else
- virNetworkObjEndAPI(&net);
-
}
- if (!(net = parallelsAddRoutedNetwork(privconn)))
+ if (!(ret = parallelsAddRoutedNetwork(privconn)))
goto cleanup;
ret = 0;
cleanup:
virJSONValueFree(jobj);
- virNetworkObjEndAPI(&net);
return ret;
}
ACK with nits fixed.
Michal