@@ -499,9 +499,8 @@ int tracecmd_tsync_with_guest_stop(struct tracecmd_time_sync *tsync);
int tracecmd_tsync_get_offsets(struct tracecmd_time_sync *tsync, int cpu,
int *count, long long **ts,
long long **offsets, long long **scalings, long long **frac);
-int tracecmd_tsync_get_session_params(struct tracecmd_time_sync *tsync,
- char **selected_proto,
- unsigned int *tsync_port);
+int tracecmd_tsync_get_selected_proto(struct tracecmd_time_sync *tsync,
+ char **selected_proto);
void tracecmd_tsync_free(struct tracecmd_time_sync *tsync);
int tracecmd_write_guest_time_shift(struct tracecmd_output *handle,
struct tracecmd_time_sync *tsync);
@@ -1098,37 +1098,23 @@ int tracecmd_tsync_with_host_stop(struct tracecmd_time_sync *tsync)
}
/**
- * tracecmd_tsync_get_session_params - Get parameters of established time sync session
- *
+ * tracecmd_tsync_get_selected_proto - Return the seleceted time sync protocol
* @tsync: Time sync context, representing a running time sync session
* @selected_proto: return, name of the selected time sync protocol for this session
- * @tsync_port: return, a VSOCK port on which new time sync requests are accepted.
*
* Returns 0 on success, or -1 in case of an error.
*
*/
-int tracecmd_tsync_get_session_params(struct tracecmd_time_sync *tsync,
- char **selected_proto,
- unsigned int *tsync_port)
+int tracecmd_tsync_get_selected_proto(struct tracecmd_time_sync *tsync,
+ char **selected_proto)
{
- int ret;
-
if (!tsync)
return -1;
- if (tsync_port) {
- if (!tsync->msg_handle)
- return -1;
- ret = vsock_get_port(tsync->msg_handle->fd, tsync_port);
- if (ret < 0)
- return ret;
- }
if (selected_proto) {
if (!tsync->proto_name)
return -1;
(*selected_proto) = strdup(tsync->proto_name);
-
}
-
return 0;
}
@@ -163,10 +163,32 @@ static int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rcid)
return 0;
}
+
+static int vsock_get_port(int sd, unsigned int *port)
+{
+ struct sockaddr_vm addr;
+ socklen_t addr_len = sizeof(addr);
+
+ if (getsockname(sd, (struct sockaddr *)&addr, &addr_len))
+ return -errno;
+
+ if (addr.svm_family != AF_VSOCK)
+ return -EINVAL;
+
+ if (port)
+ *port = addr.svm_port;
+
+ return 0;
+}
#else
static inline int get_vsocket_params(int fd, unsigned int *lcid, unsigned int *rcid) {
return -1;
}
+
+static int vsock_get_port(int sd, unsigned int *port)
+{
+ return -ENOTSUP;
+}
#endif
static void agent_handle(int sd, int nr_cpus, int page_size)
@@ -214,11 +236,15 @@ static void agent_handle(int sd, int nr_cpus, int page_size)
remote_id = -1;
local_id = -2;
}
- tsync = tracecmd_tsync_with_host(tsync_protos,
- get_clock(argc, argv),
- remote_id, local_id);
+ if (vsock_get_port(msg_handle->fd, &tsync_port) >= 0) {
+ tsync = tracecmd_tsync_with_host(tsync_protos,
+ get_clock(argc, argv),
+ remote_id, local_id);
+ } else {
+ tsync = NULL;
+ }
if (tsync)
- tracecmd_tsync_get_session_params(tsync, &tsync_proto, &tsync_port);
+ tracecmd_tsync_get_selected_proto(tsync, &tsync_proto);
else
warning("Failed to negotiate timestamps synchronization with the host");
}