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 5/8] trace-cmd library: Have tracecmd_tsync_with_guest() not depend on cid/port
Date: Thu, 14 Apr 2022 21:00:04 -0400	[thread overview]
Message-ID: <20220415010007.938408-6-rostedt@goodmis.org> (raw)
In-Reply-To: <20220415010007.938408-1-rostedt@goodmis.org>

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

Have tracecmd_tsync_with_guest() get passed a file descriptor for
connecting with the guest instead of passing in the cid and port, as
this will allow it to be used for network connections as well.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 .../include/private/trace-cmd-private.h       |  2 +-
 lib/trace-cmd/trace-timesync.c                | 36 ++-----------------
 tracecmd/trace-record.c                       |  7 ++--
 3 files changed, 9 insertions(+), 36 deletions(-)

diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index 24295e4e09d3..06906b04fbd9 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -493,7 +493,7 @@ tracecmd_tsync_with_host(const struct tracecmd_tsync_protos *tsync_protos,
 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,
-			  unsigned int cid, unsigned int port, int guest_pid,
+			  unsigned int fd, int guest_pid,
 			  int guest_cpus, const char *proto_name, const char *clock);
 int tracecmd_tsync_with_guest_stop(struct tracecmd_time_sync *tsync);
 int tracecmd_tsync_get_offsets(struct tracecmd_time_sync *tsync, int cpu,
diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index b41aece82082..2f812ca5fc74 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -345,25 +345,6 @@ error:
 }
 
 #ifdef VSOCK
-static int vsock_open(unsigned int cid, unsigned int port)
-{
-	struct sockaddr_vm addr = {
-		.svm_family = AF_VSOCK,
-		.svm_cid = cid,
-		.svm_port = port,
-	};
-	int sd;
-
-	sd = socket(AF_VSOCK, SOCK_STREAM, 0);
-	if (sd < 0)
-		return -errno;
-
-	if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)))
-		return -errno;
-
-	return sd;
-}
-
 static int vsock_make(void)
 {
 	struct sockaddr_vm addr = {
@@ -388,7 +369,7 @@ static int vsock_make(void)
 	return sd;
 }
 
-int __hidden vsock_get_port(int sd, unsigned int *port)
+static int vsock_get_port(int sd, unsigned int *port)
 {
 	struct sockaddr_vm addr;
 	socklen_t addr_len = sizeof(addr);
@@ -406,11 +387,6 @@ int __hidden vsock_get_port(int sd, unsigned int *port)
 }
 
 #else
-static int vsock_open(unsigned int cid, unsigned int port)
-{
-	return -ENOTSUP;
-}
-
 static int vsock_make(void)
 {
 	return -ENOTSUP;
@@ -811,8 +787,7 @@ static void *tsync_host_thread(void *data)
  * tracecmd_tsync_with_guest - Synchronize timestamps with guest
  *
  * @trace_id: Local ID for the current trace session
- * @cid: CID of the guest
- * @port: VSOCKET port, on which the guest listens for tsync requests
+ * @fd: file descriptor of guest
  * @guest_pid: PID of the host OS process, running the guest
  * @guest_cpus: Number of the guest VCPUs
  * @proto_name: Name of the negotiated time synchronization protocol
@@ -826,14 +801,13 @@ static void *tsync_host_thread(void *data)
  */
 struct tracecmd_time_sync *
 tracecmd_tsync_with_guest(unsigned long long trace_id, int loop_interval,
-			  unsigned int cid, unsigned int port, int guest_pid,
+			  unsigned int fd, int guest_pid,
 			  int guest_cpus, const char *proto_name, const char *clock)
 {
 	struct tracecmd_time_sync *tsync;
 	cpu_set_t *pin_mask = NULL;
 	pthread_attr_t attrib;
 	size_t mask_size = 0;
-	int fd = -1;
 	int ret;
 
 	if (!proto_name)
@@ -846,9 +820,6 @@ tracecmd_tsync_with_guest(unsigned long long trace_id, int loop_interval,
 	tsync->trace_id = trace_id;
 	tsync->loop_interval = loop_interval;
 	tsync->proto_name = strdup(proto_name);
-	fd = vsock_open(cid, port);
-	if (fd < 0)
-		goto error;
 
 	tsync->msg_handle = tracecmd_msg_handle_alloc(fd, 0);
 	if (!tsync->msg_handle) {
@@ -1034,7 +1005,6 @@ out:
 
 /**
  * tracecmd_tsync_with_host - Synchronize timestamps with host
- *
  * @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
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index c3e52a48fa07..56fa5a798dcc 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3976,19 +3976,22 @@ static int host_tsync(struct common_record_context *ctx,
 		      unsigned int tsync_port, char *proto)
 {
 	struct trace_guest *guest;
+	int fd;
 
 	if (!proto)
 		return -1;
+
 	guest = trace_get_guest(instance->cid, NULL);
 	if (guest == NULL)
 		return -1;
 
 	start_mapping_vcpus(guest);
 
+	fd = trace_open_vsock(instance->cid, tsync_port);
 	instance->tsync = tracecmd_tsync_with_guest(top_instance.trace_id,
 						    instance->tsync_loop_interval,
-						    instance->cid, tsync_port,
-						    guest->pid, instance->cpu_count,
+						    fd, guest->pid,
+						    instance->cpu_count,
 						    proto, ctx->clock);
 	stop_mapping_vcpus(instance, guest);
 
-- 
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 ` [PATCH 4/8] trace-cmd library: Remove dependency on vsocks for sync identifiers Steven Rostedt
2022-04-15  1:00 ` Steven Rostedt [this message]
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-6-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.