All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Subject: [PATCH v3 2/5] trace-cmd listen: Replace bool use_tcp with enum type
Date: Sun, 17 Apr 2022 14:33:51 -0400	[thread overview]
Message-ID: <20220417183354.1042657-3-rostedt@goodmis.org> (raw)
In-Reply-To: <20220417183354.1042657-1-rostedt@goodmis.org>

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

To allow listen to use vsockets as a connection interface, using a
boolean "use_tcp" is not flexible enough, as now there are three kinds
of connections. In preparation for adding vsockets have trace-cmd listen
use an enum instead of a boolean.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/include/trace-local.h |  5 +++++
 tracecmd/trace-listen.c        | 27 +++++++++++++++------------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 863635886769..d23cbf24cc06 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -42,6 +42,11 @@ extern int show_status;
 
 int trace_set_verbose(char *level);
 
+enum port_type {
+	USE_UDP,
+	USE_TCP,
+};
+
 struct pid_record_data {
 	int			pid;
 	int			brass[2];
diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c
index b2ab05bc3068..a5d4ec64f77c 100644
--- a/tracecmd/trace-listen.c
+++ b/tracecmd/trace-listen.c
@@ -138,7 +138,7 @@ static void remove_pid_file(void)
 }
 
 static int process_child(int sfd, const char *host, const char *port,
-			 int cpu, int page_size, int use_tcp)
+			 int cpu, int page_size, enum port_type type)
 {
 	struct sockaddr_storage peer_addr;
 	socklen_t peer_addr_len;
@@ -160,7 +160,7 @@ static int process_child(int sfd, const char *host, const char *port,
 	if (fd < 0)
 		pdie("creating %s", tempfile);
 
-	if (use_tcp) {
+	if (type == USE_TCP) {
 		if (listen(sfd, backlog) < 0)
 			pdie("listen");
 		peer_addr_len = sizeof(peer_addr);
@@ -184,7 +184,7 @@ static int process_child(int sfd, const char *host, const char *port,
 		if (!r)
 			break;
 		/* UDP requires that we get the full size in one go */
-		if (!use_tcp && r < page_size && !once) {
+		if (type == USE_UDP && r < page_size && !once) {
 			once = 1;
 			warning("read %d bytes, expected %d", r, page_size);
 		}
@@ -205,7 +205,7 @@ static int process_child(int sfd, const char *host, const char *port,
 #define START_PORT_SEARCH 1500
 #define MAX_PORT_SEARCH 6000
 
-static int bind_a_port(int start_port, int *sfd, int use_tcp)
+static int bind_a_port(int start_port, int *sfd, enum port_type type)
 {
 	struct addrinfo hints;
 	struct addrinfo *result, *rp;
@@ -218,7 +218,7 @@ static int bind_a_port(int start_port, int *sfd, int use_tcp)
 
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_UNSPEC;
-	hints.ai_socktype = use_tcp ? SOCK_STREAM : SOCK_DGRAM;
+	hints.ai_socktype = type == USE_TCP ? SOCK_STREAM : SOCK_DGRAM;
 	hints.ai_flags = AI_PASSIVE;
 
 	s = getaddrinfo(NULL, buf, &hints, &result);
@@ -250,7 +250,7 @@ static int bind_a_port(int start_port, int *sfd, int use_tcp)
 }
 
 static void fork_reader(int sfd, const char *node, const char *port,
-			int *pid, int cpu, int pagesize, int use_tcp)
+			int *pid, int cpu, int pagesize, enum port_type type)
 {
 	int ret;
 
@@ -260,7 +260,7 @@ static void fork_reader(int sfd, const char *node, const char *port,
 		pdie("creating reader");
 
 	if (!*pid) {
-		ret = process_child(sfd, node, port, cpu, pagesize, use_tcp);
+		ret = process_child(sfd, node, port, cpu, pagesize, type);
 		if (ret < 0)
 			pdie("Problem with reader %d", ret);
 	}
@@ -269,7 +269,7 @@ static void fork_reader(int sfd, const char *node, const char *port,
 }
 
 static int open_port(const char *node, const char *port, int *pid,
-		     int cpu, int pagesize, int start_port, int use_tcp)
+		     int cpu, int pagesize, int start_port, enum port_type type)
 {
 	int sfd;
 	int num_port;
@@ -278,11 +278,11 @@ static int open_port(const char *node, const char *port, int *pid,
 	 * bind_a_port() currently does not return an error, but if that
 	 * changes in the future, we have a check for it now.
 	 */
-	num_port = bind_a_port(start_port, &sfd, use_tcp);
+	num_port = bind_a_port(start_port, &sfd, type);
 	if (num_port < 0)
 		return num_port;
 
-	fork_reader(sfd, node, port, pid, cpu, pagesize, use_tcp);
+	fork_reader(sfd, node, port, pid, cpu, pagesize, type);
 
 	return num_port;
 }
@@ -463,7 +463,7 @@ static void destroy_all_readers(int cpus, int *pid_array, const char *node,
 static int *create_all_readers(const char *node, const char *port,
 			       int pagesize, struct tracecmd_msg_handle *msg_handle)
 {
-	int use_tcp = msg_handle->flags & TRACECMD_MSG_FL_USE_TCP;
+	enum port_type port_type = USE_UDP;
 	char buf[BUFSIZ];
 	unsigned int *port_array;
 	int *pid_array;
@@ -476,6 +476,9 @@ static int *create_all_readers(const char *node, const char *port,
 	if (!pagesize)
 		return NULL;
 
+	if (msg_handle->flags & TRACECMD_MSG_FL_USE_TCP)
+		port_type = USE_TCP;
+
 	port_array = malloc(sizeof(*port_array) * cpus);
 	if (!port_array)
 		return NULL;
@@ -493,7 +496,7 @@ static int *create_all_readers(const char *node, const char *port,
 	/* Now create a port for each CPU */
 	for (cpu = 0; cpu < cpus; cpu++) {
 		connect_port = open_port(node, port, &pid, cpu,
-					 pagesize, start_port, use_tcp);
+					 pagesize, start_port, port_type);
 		if (connect_port < 0)
 			goto out_free;
 		port_array[cpu] = connect_port;
-- 
2.35.1


  parent reply	other threads:[~2022-04-17 18:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-17 18:33 [PATCH v3 0/5] trace-cmd: Have trace-cmd listen work with vsockets Steven Rostedt
2022-04-17 18:33 ` [PATCH v3 1/5] trace-cmd listen: Remove UDP from function names Steven Rostedt
2022-04-17 18:33 ` Steven Rostedt [this message]
2022-04-17 18:33 ` [PATCH v3 3/5] trace-cmd record: Replace bool use_tcp with enum type Steven Rostedt
2022-04-17 18:33 ` [PATCH v3 4/5] trace-cmd listen: Add vsocket usage Steven Rostedt
2022-04-17 18:33 ` [PATCH v3 5/5] trace-cmd listen: Add documentation on " Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220417183354.1042657-3-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.