diff mbox

[ovs-dev,v3,2/3] util: Expose function nullable_string_is_equal.

Message ID 1468583694-12296-3-git-send-email-i.maximets@samsung.com
State Accepted
Delegated to: Daniele Di Proietto
Headers show

Commit Message

Ilya Maximets July 15, 2016, 11:54 a.m. UTC
Implementation of 'nullable_string_is_equal()' moved to util.c and
reused inside dpif-netdev.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
---
 lib/dpif-netdev.c            | 14 ++------------
 lib/util.c                   |  6 ++++++
 lib/util.h                   |  1 +
 ofproto/ofproto-dpif-ipfix.c |  6 ------
 ofproto/ofproto-dpif-sflow.c |  6 ------
 5 files changed, 9 insertions(+), 24 deletions(-)

Comments

Daniele Di Proietto July 26, 2016, 1:45 a.m. UTC | #1
Nice!

Applied to master, thanks



On 15/07/2016 04:54, "Ilya Maximets" <i.maximets@samsung.com> wrote:

>Implementation of 'nullable_string_is_equal()' moved to util.c and

>reused inside dpif-netdev.

>

>Signed-off-by: Ilya Maximets <i.maximets@samsung.com>

>---

> lib/dpif-netdev.c            | 14 ++------------

> lib/util.c                   |  6 ++++++

> lib/util.h                   |  1 +

> ofproto/ofproto-dpif-ipfix.c |  6 ------

> ofproto/ofproto-dpif-sflow.c |  6 ------

> 5 files changed, 9 insertions(+), 24 deletions(-)

>

>diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c

>index 4643cce..18ce316 100644

>--- a/lib/dpif-netdev.c

>+++ b/lib/dpif-netdev.c

>@@ -2524,16 +2524,6 @@ dpif_netdev_operate(struct dpif *dpif, struct dpif_op **ops, size_t n_ops)

>     }

> }

> 

>-static bool

>-cmask_equals(const char *a, const char *b)

>-{

>-    if (a && b) {

>-        return !strcmp(a, b);

>-    }

>-

>-    return a == NULL && b == NULL;

>-}

>-

> /* Changes the number or the affinity of pmd threads.  The changes are actually

>  * applied in dpif_netdev_run(). */

> static int

>@@ -2541,7 +2531,7 @@ dpif_netdev_pmd_set(struct dpif *dpif, const char *cmask)

> {

>     struct dp_netdev *dp = get_dp_netdev(dpif);

> 

>-    if (!cmask_equals(dp->requested_pmd_cmask, cmask)) {

>+    if (!nullable_string_is_equal(dp->requested_pmd_cmask, cmask)) {

>         free(dp->requested_pmd_cmask);

>         dp->requested_pmd_cmask = nullable_xstrdup(cmask);

>     }

>@@ -2756,7 +2746,7 @@ dpif_netdev_run(struct dpif *dpif)

> 

>     dp_netdev_pmd_unref(non_pmd);

> 

>-    if (!cmask_equals(dp->pmd_cmask, dp->requested_pmd_cmask)

>+    if (!nullable_string_is_equal(dp->pmd_cmask, dp->requested_pmd_cmask)

>         || ports_require_restart(dp)) {

>         reconfigure_pmd_threads(dp);

>     }

>diff --git a/lib/util.c b/lib/util.c

>index e1dc3d2..241a7f1 100644

>--- a/lib/util.c

>+++ b/lib/util.c

>@@ -157,6 +157,12 @@ nullable_xstrdup(const char *s)

>     return s ? xstrdup(s) : NULL;

> }

> 

>+bool

>+nullable_string_is_equal(const char *a, const char *b)

>+{

>+    return a ? b && !strcmp(a, b) : !b;

>+}

>+

> char *

> xvasprintf(const char *format, va_list args)

> {

>diff --git a/lib/util.h b/lib/util.h

>index e738c9f..6a61dde 100644

>--- a/lib/util.h

>+++ b/lib/util.h

>@@ -113,6 +113,7 @@ void *xmemdup(const void *, size_t) MALLOC_LIKE;

> char *xmemdup0(const char *, size_t) MALLOC_LIKE;

> char *xstrdup(const char *) MALLOC_LIKE;

> char *nullable_xstrdup(const char *) MALLOC_LIKE;

>+bool nullable_string_is_equal(const char *a, const char *b);

> char *xasprintf(const char *format, ...) OVS_PRINTF_FORMAT(1, 2) MALLOC_LIKE;

> char *xvasprintf(const char *format, va_list) OVS_PRINTF_FORMAT(1, 0) MALLOC_LIKE;

> void *x2nrealloc(void *p, size_t *n, size_t s);

>diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c

>index 5744abb..d9069cb 100644

>--- a/ofproto/ofproto-dpif-ipfix.c

>+++ b/ofproto/ofproto-dpif-ipfix.c

>@@ -464,12 +464,6 @@ static void get_export_time_now(uint64_t *, uint32_t *);

> static void dpif_ipfix_cache_expire_now(struct dpif_ipfix_exporter *, bool);

> 

> static bool

>-nullable_string_is_equal(const char *a, const char *b)

>-{

>-    return a ? b && !strcmp(a, b) : !b;

>-}

>-

>-static bool

> ofproto_ipfix_bridge_exporter_options_equal(

>     const struct ofproto_ipfix_bridge_exporter_options *a,

>     const struct ofproto_ipfix_bridge_exporter_options *b)

>diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c

>index 7d0aa36..8ede492 100644

>--- a/ofproto/ofproto-dpif-sflow.c

>+++ b/ofproto/ofproto-dpif-sflow.c

>@@ -92,12 +92,6 @@ static void dpif_sflow_del_port__(struct dpif_sflow *,

> static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);

> 

> static bool

>-nullable_string_is_equal(const char *a, const char *b)

>-{

>-    return a ? b && !strcmp(a, b) : !b;

>-}

>-

>-static bool

> ofproto_sflow_options_equal(const struct ofproto_sflow_options *a,

>                          const struct ofproto_sflow_options *b)

> {

>-- 

>2.7.4
diff mbox

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 4643cce..18ce316 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -2524,16 +2524,6 @@  dpif_netdev_operate(struct dpif *dpif, struct dpif_op **ops, size_t n_ops)
     }
 }
 
-static bool
-cmask_equals(const char *a, const char *b)
-{
-    if (a && b) {
-        return !strcmp(a, b);
-    }
-
-    return a == NULL && b == NULL;
-}
-
 /* Changes the number or the affinity of pmd threads.  The changes are actually
  * applied in dpif_netdev_run(). */
 static int
@@ -2541,7 +2531,7 @@  dpif_netdev_pmd_set(struct dpif *dpif, const char *cmask)
 {
     struct dp_netdev *dp = get_dp_netdev(dpif);
 
-    if (!cmask_equals(dp->requested_pmd_cmask, cmask)) {
+    if (!nullable_string_is_equal(dp->requested_pmd_cmask, cmask)) {
         free(dp->requested_pmd_cmask);
         dp->requested_pmd_cmask = nullable_xstrdup(cmask);
     }
@@ -2756,7 +2746,7 @@  dpif_netdev_run(struct dpif *dpif)
 
     dp_netdev_pmd_unref(non_pmd);
 
-    if (!cmask_equals(dp->pmd_cmask, dp->requested_pmd_cmask)
+    if (!nullable_string_is_equal(dp->pmd_cmask, dp->requested_pmd_cmask)
         || ports_require_restart(dp)) {
         reconfigure_pmd_threads(dp);
     }
diff --git a/lib/util.c b/lib/util.c
index e1dc3d2..241a7f1 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -157,6 +157,12 @@  nullable_xstrdup(const char *s)
     return s ? xstrdup(s) : NULL;
 }
 
+bool
+nullable_string_is_equal(const char *a, const char *b)
+{
+    return a ? b && !strcmp(a, b) : !b;
+}
+
 char *
 xvasprintf(const char *format, va_list args)
 {
diff --git a/lib/util.h b/lib/util.h
index e738c9f..6a61dde 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -113,6 +113,7 @@  void *xmemdup(const void *, size_t) MALLOC_LIKE;
 char *xmemdup0(const char *, size_t) MALLOC_LIKE;
 char *xstrdup(const char *) MALLOC_LIKE;
 char *nullable_xstrdup(const char *) MALLOC_LIKE;
+bool nullable_string_is_equal(const char *a, const char *b);
 char *xasprintf(const char *format, ...) OVS_PRINTF_FORMAT(1, 2) MALLOC_LIKE;
 char *xvasprintf(const char *format, va_list) OVS_PRINTF_FORMAT(1, 0) MALLOC_LIKE;
 void *x2nrealloc(void *p, size_t *n, size_t s);
diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c
index 5744abb..d9069cb 100644
--- a/ofproto/ofproto-dpif-ipfix.c
+++ b/ofproto/ofproto-dpif-ipfix.c
@@ -464,12 +464,6 @@  static void get_export_time_now(uint64_t *, uint32_t *);
 static void dpif_ipfix_cache_expire_now(struct dpif_ipfix_exporter *, bool);
 
 static bool
-nullable_string_is_equal(const char *a, const char *b)
-{
-    return a ? b && !strcmp(a, b) : !b;
-}
-
-static bool
 ofproto_ipfix_bridge_exporter_options_equal(
     const struct ofproto_ipfix_bridge_exporter_options *a,
     const struct ofproto_ipfix_bridge_exporter_options *b)
diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c
index 7d0aa36..8ede492 100644
--- a/ofproto/ofproto-dpif-sflow.c
+++ b/ofproto/ofproto-dpif-sflow.c
@@ -92,12 +92,6 @@  static void dpif_sflow_del_port__(struct dpif_sflow *,
 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
 
 static bool
-nullable_string_is_equal(const char *a, const char *b)
-{
-    return a ? b && !strcmp(a, b) : !b;
-}
-
-static bool
 ofproto_sflow_options_equal(const struct ofproto_sflow_options *a,
                          const struct ofproto_sflow_options *b)
 {