X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=1404e7f33f68d0e5ecec0f1d9544f330c7493526;hb=fb54cdbf2a8ff53e9dc11403a8aca643bbdde9c0;hp=06bf0f4f386832a199a199862e2416301d42e521;hpb=c7d620a2a00e1da14a0d06752b9055d9de6017b5;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 06bf0f4f3..1404e7f33 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -553,6 +553,13 @@ static int send_consumer_relayd_socket(int domain, struct ltt_session *session, goto close_sock; } + /* Flag that the corresponding socket was sent. */ + if (relayd_uri->stype == LTTNG_STREAM_CONTROL) { + consumer->dst.net.control_sock_sent = 1; + } else if (relayd_uri->stype == LTTNG_STREAM_DATA) { + consumer->dst.net.data_sock_sent = 1; + } + ret = LTTNG_OK; /* @@ -577,34 +584,29 @@ close_sock: static int send_consumer_relayd_sockets(int domain, struct ltt_session *session, struct consumer_output *consumer, int fd) { - int ret; + int ret = LTTNG_OK; assert(session); assert(consumer); - /* Don't resend the sockets to the consumer. */ - if (consumer->dst.net.relayd_socks_sent) { - ret = LTTNG_OK; - goto error; - } - /* Sending control relayd socket. */ - ret = send_consumer_relayd_socket(domain, session, - &consumer->dst.net.control, consumer, fd); - if (ret != LTTNG_OK) { - goto error; + if (!consumer->dst.net.control_sock_sent) { + ret = send_consumer_relayd_socket(domain, session, + &consumer->dst.net.control, consumer, fd); + if (ret != LTTNG_OK) { + goto error; + } } /* Sending data relayd socket. */ - ret = send_consumer_relayd_socket(domain, session, - &consumer->dst.net.data, consumer, fd); - if (ret != LTTNG_OK) { - goto error; + if (!consumer->dst.net.data_sock_sent) { + ret = send_consumer_relayd_socket(domain, session, + &consumer->dst.net.data, consumer, fd); + if (ret != LTTNG_OK) { + goto error; + } } - /* Flag that all relayd sockets were sent to the consumer. */ - consumer->dst.net.relayd_socks_sent = 1; - error: return ret; } @@ -638,7 +640,7 @@ static int setup_relayd(struct ltt_session *session) assert(socket->fd >= 0); pthread_mutex_lock(socket->lock); - send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session, + ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session, usess->consumer, socket->fd); pthread_mutex_unlock(socket->lock); if (ret != LTTNG_OK) { @@ -655,7 +657,7 @@ static int setup_relayd(struct ltt_session *session) assert(socket->fd >= 0); pthread_mutex_lock(socket->lock); - send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session, + ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session, ksess->consumer, socket->fd); pthread_mutex_unlock(socket->lock); if (ret != LTTNG_OK) { @@ -1526,11 +1528,6 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session, goto error; } - if (!session->start_consumer) { - ret = LTTNG_ERR_NO_CONSUMER; - goto error; - } - /* * This case switch makes sure the domain session has a temporary consumer * so the URL can be set. @@ -1594,10 +1591,13 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session, /* * Don't send relayd socket if URI is NOT remote or if the relayd - * sockets for the session are already sent. + * socket for the session was already sent. */ if (uris[i].dtype == LTTNG_DST_PATH || - consumer->dst.net.relayd_socks_sent) { + (uris[i].stype == LTTNG_STREAM_CONTROL && + consumer->dst.net.control_sock_sent) || + (uris[i].stype == LTTNG_STREAM_DATA && + consumer->dst.net.data_sock_sent)) { continue; } @@ -2137,11 +2137,6 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) goto error; } - if (!session->start_consumer) { - ret = LTTNG_ERR_NO_CONSUMER; - goto error; - } - switch (domain) { case 0: assert(session->consumer); @@ -2208,11 +2203,6 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) break; } - /* Append default kernel trace dir to subdir */ - strncat(ksess->consumer->subdir, DEFAULT_KERNEL_TRACE_DIR, - sizeof(ksess->consumer->subdir) - - strlen(ksess->consumer->subdir) - 1); - /* * @session-lock * This is race free for now since the session lock is acquired before @@ -2221,6 +2211,7 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) * is valid. */ rcu_read_lock(); + /* Destroy current consumer. We are about to replace it */ consumer_destroy_output(ksess->consumer); rcu_read_unlock(); ksess->consumer = consumer; @@ -2294,11 +2285,6 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) break; } - /* Append default kernel trace dir to subdir */ - strncat(usess->consumer->subdir, DEFAULT_UST_TRACE_DIR, - sizeof(usess->consumer->subdir) - - strlen(usess->consumer->subdir) - 1); - /* * @session-lock * This is race free for now since the session lock is acquired before @@ -2307,6 +2293,7 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) * is valid. */ rcu_read_lock(); + /* Destroy current consumer. We are about to replace it */ consumer_destroy_output(usess->consumer); rcu_read_unlock(); usess->consumer = consumer; @@ -2315,6 +2302,8 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) break; } + session->start_consumer = 1; + /* Enable it */ if (consumer) { consumer->enabled = 1; @@ -2329,6 +2318,47 @@ error: return ret; } +/* + * Command LTTNG_DATA_PENDING returning 0 if the data is NOT pending meaning + * ready for trace analysis (or anykind of reader) or else 1 for pending data. + */ +int cmd_data_pending(struct ltt_session *session) +{ + int ret; + struct ltt_kernel_session *ksess = session->kernel_session; + struct ltt_ust_session *usess = session->ust_session; + + assert(session); + + /* Session MUST be stopped to ask for data availability. */ + if (session->enabled) { + ret = LTTNG_ERR_SESSION_STARTED; + goto error; + } + + if (ksess && ksess->consumer) { + ret = consumer_is_data_pending(ksess->id, ksess->consumer); + if (ret == 1) { + /* Data is still being extracted for the kernel. */ + goto error; + } + } + + if (usess && usess->consumer) { + ret = consumer_is_data_pending(usess->id, usess->consumer); + if (ret == 1) { + /* Data is still being extracted for the kernel. */ + goto error; + } + } + + /* Data is ready to be read by a viewer */ + ret = 0; + +error: + return ret; +} + /* * Init command subsystem. */