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 4/8] trace-cmd library: Remove dependency on vsocks for sync identifiers
Date: Thu, 14 Apr 2022 21:00:03 -0400	[thread overview]
Message-ID: <20220415010007.938408-5-rostedt@goodmis.org> (raw)
In-Reply-To: <20220415010007.938408-1-rostedt@goodmis.org>

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

In an effort to remove the dependency on vsockets from libtracecmd
and synchronization, move the creation of remote and local ids out of
the library and change tracecmd_tsync_with_host() to pass in those
identifiers.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 .../include/private/trace-cmd-private.h       |  2 +-
 lib/trace-cmd/include/trace-tsync-local.h     |  2 +
 lib/trace-cmd/trace-timesync.c                | 42 ++++---------------
 tracecmd/trace-agent.c                        | 41 +++++++++++++++++-
 4 files changed, 50 insertions(+), 37 deletions(-)

diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index 69343765c5ff..24295e4e09d3 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -489,7 +489,7 @@ int tracecmd_tsync_proto_getall(struct tracecmd_tsync_protos **protos, const cha
 bool tsync_proto_is_supported(const char *proto_name);
 struct tracecmd_time_sync *
 tracecmd_tsync_with_host(const struct tracecmd_tsync_protos *tsync_protos,
-			 const char *clock);
+			 const char *clock, int remote_id, int local_id);
 int tracecmd_tsync_with_host_stop(struct tracecmd_time_sync *tsync);
 struct tracecmd_time_sync *
 tracecmd_tsync_with_guest(unsigned long long trace_id, int loop_interval,
diff --git a/lib/trace-cmd/include/trace-tsync-local.h b/lib/trace-cmd/include/trace-tsync-local.h
index 4340dfaf80ca..697c076c43a6 100644
--- a/lib/trace-cmd/include/trace-tsync-local.h
+++ b/lib/trace-cmd/include/trace-tsync-local.h
@@ -22,6 +22,8 @@ struct tracecmd_time_sync {
 	void				*context;
 	int				guest_pid;
 	int				vcpu_count;
+	int				remote_id;
+	int				local_id;
 };
 
 struct clock_sync_offsets {
diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index 594f660e2a40..b41aece82082 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -405,29 +405,6 @@ int __hidden vsock_get_port(int sd, unsigned int *port)
 	return 0;
 }
 
-static int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rcid)
-{
-	struct sockaddr_vm addr;
-	socklen_t addr_len = sizeof(addr);
-
-	memset(&addr, 0, sizeof(addr));
-	if (getsockname(fd, (struct sockaddr *)&addr, &addr_len))
-		return -1;
-	if (addr.svm_family != AF_VSOCK)
-		return -1;
-	*lcid = addr.svm_cid;
-
-	memset(&addr, 0, sizeof(addr));
-	addr_len = sizeof(addr);
-	if (getpeername(fd, (struct sockaddr *)&addr, &addr_len))
-		return -1;
-	if (addr.svm_family != AF_VSOCK)
-		return -1;
-	*rcid = addr.svm_cid;
-
-	return 0;
-}
-
 #else
 static int vsock_open(unsigned int cid, unsigned int port)
 {
@@ -444,12 +421,6 @@ static int vsock_get_port(int sd, unsigned int *port)
 {
 	return -ENOTSUP;
 }
-
-static int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rcid)
-{
-	return -ENOTSUP;
-}
-
 #endif /* VSOCK */
 
 static struct tracefs_instance *
@@ -498,12 +469,8 @@ static int clock_context_init(struct tracecmd_time_sync *tsync,
 	clock->is_guest = guest;
 	clock->is_server = clock->is_guest;
 
-	if (get_vsocket_params(tsync->msg_handle->fd, &clock->local_id,
-			       &clock->remote_id))
-		goto error;
-
 	clock->instance = clock_synch_create_instance(tsync->clock_str,
-						      clock->remote_id);
+						      tsync->remote_id);
 	if (!clock->instance)
 		goto error;
 
@@ -1071,6 +1038,8 @@ out:
  * @tsync_protos: List of tsync protocols, supported by the host
  * @clock: Trace clock, used for that session
  * @port: returned, VSOCKET port, on which the guest listens for tsync requests
+ * @remote_id: Identifier to uniquely identify the remote host
+ * @local_id: Identifier to uniquely identify the local machine
  *
  * On success, a pointer to time sync context is returned, or NULL in
  * case of an error. The context must be freed with tracecmd_tsync_free()
@@ -1080,7 +1049,7 @@ out:
  */
 struct tracecmd_time_sync *
 tracecmd_tsync_with_host(const struct tracecmd_tsync_protos *tsync_protos,
-			 const char *clock)
+			 const char *clock, int remote_id, int local_id)
 {
 	struct tracecmd_time_sync *tsync;
 	cpu_set_t *pin_mask = NULL;
@@ -1110,6 +1079,9 @@ tracecmd_tsync_with_host(const struct tracecmd_tsync_protos *tsync_protos,
 	if (clock)
 		tsync->clock_str = strdup(clock);
 
+	tsync->remote_id = remote_id;
+	tsync->local_id = local_id;
+
 	pthread_attr_init(&attrib);
 	tsync->vcpu_count = tracecmd_count_cpus();
 	pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE);
diff --git a/tracecmd/trace-agent.c b/tracecmd/trace-agent.c
index a46feea3d3c7..151ca19c2270 100644
--- a/tracecmd/trace-agent.c
+++ b/tracecmd/trace-agent.c
@@ -140,6 +140,35 @@ static char *get_clock(int argc, char **argv)
 	return NULL;
 }
 
+#ifdef VSOCK
+static int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rcid)
+{
+	struct sockaddr_vm addr;
+	socklen_t addr_len = sizeof(addr);
+
+	memset(&addr, 0, sizeof(addr));
+	if (getsockname(fd, (struct sockaddr *)&addr, &addr_len))
+		return -1;
+	if (addr.svm_family != AF_VSOCK)
+		return -1;
+	*lcid = addr.svm_cid;
+
+	memset(&addr, 0, sizeof(addr));
+	addr_len = sizeof(addr);
+	if (getpeername(fd, (struct sockaddr *)&addr, &addr_len))
+		return -1;
+	if (addr.svm_family != AF_VSOCK)
+		return -1;
+	*rcid = addr.svm_cid;
+
+	return 0;
+}
+#else
+static inline int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rcid) {
+	return -1;
+}
+#endif
+
 static void agent_handle(int sd, int nr_cpus, int page_size)
 {
 	struct tracecmd_tsync_protos *tsync_protos = NULL;
@@ -147,6 +176,8 @@ static void agent_handle(int sd, int nr_cpus, int page_size)
 	struct tracecmd_msg_handle *msg_handle;
 	char *tsync_proto = NULL;
 	unsigned long long trace_id;
+	unsigned int remote_id;
+	unsigned int local_id;
 	unsigned int tsync_port = 0;
 	unsigned int *ports;
 	char **argv = NULL;
@@ -176,8 +207,16 @@ static void agent_handle(int sd, int nr_cpus, int page_size)
 	if (!use_fifos)
 		make_vsocks(nr_cpus, fds, ports);
 	if (tsync_protos && tsync_protos->names) {
+		if (get_vsocket_params(msg_handle->fd, &local_id,
+				       &remote_id)) {
+			warning("Failed to get local and remote ids");
+			/* Just make something up */
+			remote_id = -1;
+			local_id = -2;
+		}
 		tsync = tracecmd_tsync_with_host(tsync_protos,
-						 get_clock(argc, argv));
+						 get_clock(argc, argv),
+						 remote_id, local_id);
 		if (tsync)
 			tracecmd_tsync_get_session_params(tsync, &tsync_proto, &tsync_port);
 		else
-- 
2.35.1


  parent reply	other threads:[~2022-04-15  1:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15  0:59 [PATCH 0/8] trace-cmd library: Remove dependency to vsockets Steven Rostedt
2022-04-15  1:00 ` [PATCH 1/8] trace-cmd: Add NO_VSOCK make option to force vsock code off Steven Rostedt
2022-04-15  1:00 ` [PATCH 2/8] trace-cmd library: Remove ports from clock context Steven Rostedt
2022-04-15  1:00 ` [PATCH 3/8] trace-cmd library: Remove vsocket dependency on P2P protocol Steven Rostedt
2022-04-15  1:00 ` Steven Rostedt [this message]
2022-04-15  1:00 ` [PATCH 5/8] trace-cmd library: Have tracecmd_tsync_with_guest() not depend on cid/port Steven Rostedt
2022-04-15  1:00 ` [PATCH 6/8] trace-cmd library: Remove dependency on vsocks from tracecmd_tsync_get_session_params() Steven Rostedt
2022-04-15  1:00 ` [PATCH 7/8] trace-cmd library: Remove vsock dependency from tracecmd_tsync_with_host() Steven Rostedt
2022-04-15  1:00 ` [PATCH 8/8] trace-cmd: Move vsocket code into its own file 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=20220415010007.938408-5-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.