X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=46a758e27eab8f9b01c502256bde42a60b32702d;hb=979e618e0c03933b16cba3a83285938b25045bdc;hp=b1e66e755bf0f621fb8c78f84a6d8c9043cedc55;hpb=c890b720e435173420cac747c5701147ff7ead99;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index b1e66e755..46a758e27 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -584,7 +584,7 @@ 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); @@ -640,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) { @@ -657,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) { @@ -939,12 +939,23 @@ error: * Command LTTNG_ADD_CONTEXT processed by the client thread. */ int cmd_add_context(struct ltt_session *session, int domain, - char *channel_name, char *event_name, struct lttng_event_context *ctx) + char *channel_name, char *event_name, struct lttng_event_context *ctx, + int kwpipe) { int ret; switch (domain) { case LTTNG_DOMAIN_KERNEL: + assert(session->kernel_session); + + if (session->kernel_session->channel_count == 0) { + /* Create default channel */ + ret = channel_kernel_create(session->kernel_session, NULL, kwpipe); + if (ret != LTTNG_OK) { + goto error; + } + } + /* Add kernel context to kernel tracer */ ret = context_kernel_add(session->kernel_session, ctx, event_name, channel_name); @@ -955,9 +966,28 @@ int cmd_add_context(struct ltt_session *session, int domain, case LTTNG_DOMAIN_UST: { struct ltt_ust_session *usess = session->ust_session; - assert(usess); + unsigned int chan_count = + lttng_ht_get_count(usess->domain_global.channels); + if (chan_count == 0) { + struct lttng_channel *attr; + /* Create default channel */ + attr = channel_new_default_attr(domain); + if (attr == NULL) { + ret = LTTNG_ERR_FATAL; + goto error; + } + + ret = channel_ust_create(usess, domain, attr); + if (ret != LTTNG_OK) { + free(attr); + goto error; + } + free(attr); + } + + ret = context_ust_add(usess, domain, ctx, event_name, channel_name); if (ret != LTTNG_OK) { goto error; @@ -1528,11 +1558,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. @@ -2142,11 +2167,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); @@ -2213,11 +2233,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 @@ -2226,6 +2241,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; @@ -2299,11 +2315,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 @@ -2312,6 +2323,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; @@ -2320,6 +2332,8 @@ int cmd_enable_consumer(int domain, struct ltt_session *session) break; } + session->start_consumer = 1; + /* Enable it */ if (consumer) { consumer->enabled = 1; @@ -2334,6 +2348,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. */