@@ -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,
@@ -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 {
@@ -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);
@@ -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