[libvirt] [PATCH 2/7] parallels: fix parallelsLoadNetworks

2015-03-18 Thread Maxim Nestratov
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 
---
 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..1d0ee1c 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 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;
@@ -230,14 +243,16 @@ parallelsLoadNetwork(parallelsConnPtr privconn, 
virJSONValuePtr jobj)
 goto cleanup;
 net->active = 1;
 net->autostart = 1;
-return net;
+virNetworkObjEndAPI(&net);
+ret = 0;
+def = NULL;
 
  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;
 }
 
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/7] parallels: fix parallelsLoadNetworks

2015-03-17 Thread Michal Privoznik
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 
> ---
>  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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/7] parallels: fix parallelsLoadNetworks

2015-03-13 Thread Maxim Nestratov
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 
---
 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 */
+if (!STREQ(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 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;
 
  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;
 }
 
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/7] parallels: fix parallelsLoadNetworks

2015-03-10 Thread Maxim Nestratov
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 
---
 src/parallels/parallels_network.c |   29 +
 1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/parallels/parallels_network.c 
b/src/parallels/parallels_network.c
index 26767c0..24fdb70 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 */
+if (!STREQ(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 required to be configured completely */
+if (!STREQ(def->name, PARALLELS_REQUIRED_HOSTONLY_NETWORK))
+ret = 0;
+
 goto cleanup;
+}
 } else {
 parallelsParseError();
 goto cleanup;
@@ -231,11 +244,12 @@ parallelsLoadNetwork(parallelsConnPtr privconn, 
virJSONValuePtr jobj)
 net->active = 1;
 net->autostart = 1;
 virNetworkObjUnlock(net);
-return net;
+ret = 0;
+return ret;
 
  cleanup:
 virNetworkDefFree(def);
-return NULL;
+return ret;
 }
 
 static virNetworkObjPtr
@@ -277,7 +291,6 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn)
 static int parallelsLoadNetworks(parallelsConnPtr privconn)
 {
 virJSONValuePtr jobj, jobj2;
-virNetworkObjPtr net;
 int ret = -1;
 int count;
 size_t i;
@@ -302,8 +315,8 @@ static int parallelsLoadNetworks(parallelsConnPtr privconn)
 goto cleanup;
 }
 
-net = parallelsLoadNetwork(privconn, jobj2);
-if (!net)
+ret = parallelsLoadNetwork(privconn, jobj2);
+if (!ret)
 goto cleanup;
 
 }
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list