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]> --- configure.ac | 2 +- lib/dpdk.c | 32 ++++---------------------------- lib/unixctl.c | 44 +++++++++++++++++++++++++++++++++++++++----- lib/unixctl.h | 3 +++ 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/configure.ac b/configure.ac index 56eacbbc7..cd063f811 100644 --- a/configure.ac +++ b/configure.ac @@ -115,7 +115,7 @@ 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 d27b95cd9..edd07e3ac 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) { @@ -491,16 +467,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..b8499394f 100644 --- a/lib/unixctl.c +++ b/lib/unixctl.c @@ -15,22 +15,26 @@ */ #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 "unixctl.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 +647,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
