From: Ilya Maximets Date: Fri, 15 Jul 2016 11:54:53 +0000 (+0300) Subject: util: Expose function nullable_string_is_equal. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=aacf18c3a79502d124ebdbb3b0523668a011cd5e util: Expose function nullable_string_is_equal. Implementation of 'nullable_string_is_equal()' moved to util.c and reused inside dpif-netdev. Signed-off-by: Ilya Maximets Acked-by: Daniele Di Proietto --- diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index d5d7b7e6e..f05ca4e61 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -2514,16 +2514,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 @@ -2531,7 +2521,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); } @@ -2741,7 +2731,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 e1dc3d239..241a7f19d 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 5049d159e..3f6b690f7 100644 --- a/lib/util.h +++ b/lib/util.h @@ -114,6 +114,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 0128c91a6..abea49249 100644 --- a/ofproto/ofproto-dpif-ipfix.c +++ b/ofproto/ofproto-dpif-ipfix.c @@ -463,12 +463,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, diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c index 8a19d1584..1252d39f5 100644 --- a/ofproto/ofproto-dpif-sflow.c +++ b/ofproto/ofproto-dpif-sflow.c @@ -91,12 +91,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)