A utility function for mem-stream is introduced. It replaces the usage
in dpdk and later for doca.

Signed-off-by: Eli Britstein <[email protected]>
---
 acinclude.m4  |  4 ++++
 configure.ac  |  3 ++-
 lib/dpdk.c    | 32 ++++----------------------------
 lib/unixctl.c | 43 +++++++++++++++++++++++++++++++++++++++----
 lib/unixctl.h |  3 +++
 5 files changed, 52 insertions(+), 33 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 060c416f8..54d7c3e0e 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -494,6 +494,10 @@ AC_DEFUN([OVS_CHECK_DPDK], [
           non-standard location.]))
       ])
 
+    AS_IF([test "$ac_cv_func_open_memstream" != yes],
+      [AC_MSG_ERROR(m4_normalize([
+        open_memstream is required when building with DPDK.]))])
+
     CFLAGS="$ovs_save_CFLAGS"
     LDFLAGS="$ovs_save_LDFLAGS"
     # Stripping out possible instruction set specific configuration that DPDK
diff --git a/configure.ac b/configure.ac
index 56eacbbc7..2a488600a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -115,7 +115,8 @@ AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_scope_id], [], 
[],
   [[#include <sys/socket.h>
 #include <sys/types.h>
 #include <netinet/in.h>]])
-AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r sendmmsg 
clock_gettime])
+AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r sendmmsg \
+                clock_gettime open_memstream])
 AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h])
 AC_CHECK_HEADERS([linux/net_namespace.h stdatomic.h bits/floatn-common.h])
 AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include <sys/types.h>
diff --git a/lib/dpdk.c b/lib/dpdk.c
index 3685baf00..67a1a2898 100644
--- a/lib/dpdk.c
+++ b/lib/dpdk.c
@@ -273,30 +273,6 @@ static cookie_io_functions_t dpdk_log_func = {
     .write = dpdk_log_write,
 };
 
-static void
-dpdk_unixctl_mem_stream(struct unixctl_conn *conn, int argc OVS_UNUSED,
-                        const char *argv[] OVS_UNUSED, void *aux)
-{
-    void (*callback)(FILE *) = aux;
-    char *response = NULL;
-    FILE *stream;
-    size_t size;
-
-    stream = open_memstream(&response, &size);
-    if (!stream) {
-        response = xasprintf("Unable to open memstream: %s.",
-                             ovs_strerror(errno));
-        unixctl_command_reply_error(conn, response);
-        goto out;
-    }
-
-    callback(stream);
-    fclose(stream);
-    unixctl_command_reply(conn, response);
-out:
-    free(response);
-}
-
 static int
 dpdk_parse_log_level(const char *s)
 {
@@ -522,16 +498,16 @@ dpdk_init__(const struct smap *ovs_other_config)
     }
 
     unixctl_command_register("dpdk/lcore-list", "", 0, 0,
-                             dpdk_unixctl_mem_stream, rte_lcore_dump);
+                             unixctl_mem_stream, rte_lcore_dump);
     unixctl_command_register("dpdk/log-list", "", 0, 0,
-                             dpdk_unixctl_mem_stream, rte_log_dump);
+                             unixctl_mem_stream, rte_log_dump);
     unixctl_command_register("dpdk/log-set", "{level | pattern:level}", 0,
                              INT_MAX, dpdk_unixctl_log_set, NULL);
     unixctl_command_register("dpdk/get-malloc-stats", "", 0, 0,
-                             dpdk_unixctl_mem_stream,
+                             unixctl_mem_stream,
                              malloc_dump_stats_wrapper);
     unixctl_command_register("dpdk/get-memzone-stats", "", 0, 0,
-                             dpdk_unixctl_mem_stream, rte_memzone_dump);
+                             unixctl_mem_stream, rte_memzone_dump);
 
     /* We are called from the main thread here */
     RTE_PER_LCORE(_lcore_id) = NON_PMD_CORE_ID;
diff --git a/lib/unixctl.c b/lib/unixctl.c
index 4fd150959..f37116896 100644
--- a/lib/unixctl.c
+++ b/lib/unixctl.c
@@ -15,22 +15,27 @@
  */
 
 #include <config.h>
+
 #include "unixctl.h"
+
 #include <errno.h>
 #include <getopt.h>
+#include <stdio.h>
 #include <unistd.h>
+
 #include "command-line.h"
 #include "coverage.h"
 #include "dirs.h"
+#include "jsonrpc.h"
+#include "stream.h"
+#include "stream-provider.h"
+#include "svec.h"
+
 #include "openvswitch/dynamic-string.h"
 #include "openvswitch/json.h"
-#include "jsonrpc.h"
 #include "openvswitch/list.h"
 #include "openvswitch/poll-loop.h"
 #include "openvswitch/shash.h"
-#include "stream.h"
-#include "stream-provider.h"
-#include "svec.h"
 #include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(unixctl);
@@ -643,3 +648,33 @@ unixctl_client_transact(struct jsonrpc *client, const char 
*command, int argc,
     jsonrpc_msg_destroy(reply);
     return error;
 }
+
+#ifdef HAVE_OPEN_MEMSTREAM
+
+void
+unixctl_mem_stream(struct unixctl_conn *conn, int argc OVS_UNUSED,
+                   const char *argv[] OVS_UNUSED, void *aux)
+{
+    void (*callback)(FILE *) = aux;
+    char *response = NULL;
+    FILE *stream;
+    size_t size;
+
+    ovs_assert(callback);
+
+    stream = open_memstream(&response, &size);
+    if (!stream) {
+        response = xasprintf("Unable to open memstream: %s.",
+                             ovs_strerror(errno));
+        unixctl_command_reply_error(conn, response);
+        goto out;
+    }
+
+    callback(stream);
+    fclose(stream);
+    unixctl_command_reply(conn, response);
+out:
+    free(response);
+}
+
+#endif
diff --git a/lib/unixctl.h b/lib/unixctl.h
index 1965f100d..377ecd0a9 100644
--- a/lib/unixctl.h
+++ b/lib/unixctl.h
@@ -62,6 +62,9 @@ void unixctl_command_reply_error(struct unixctl_conn *, const 
char *error);
 void unixctl_command_reply(struct unixctl_conn *, const char *body);
 void unixctl_command_reply_json(struct unixctl_conn *,
                                 struct json *body);
+#ifdef HAVE_OPEN_MEMSTREAM
+unixctl_cb_func unixctl_mem_stream;
+#endif
 
 #ifdef  __cplusplus
 }
-- 
2.34.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to