X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=ltt-sessiond%2Fmain.c;h=2c2fe44bf52771c54415e58766f03bd385e4c9ec;hp=c288afbb049f4a078f049756fce9c20094f1d705;hb=1316184615e422526ef4fae68f980443414969c1;hpb=2bdd86d4c47902237c691d3c5409f32f205df81e diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index c288afbb0..2c2fe44bf 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -42,13 +42,6 @@ #include #include -#ifdef CONFIG_LTTNG_TOOLS_HAVE_UST -#include -#else -#include "lttng-ust-ctl.h" -#endif - - #include #include "channel.h" @@ -56,13 +49,13 @@ #include "context.h" #include "event.h" #include "futex.h" +#include "hashtable.h" #include "kernel-ctl.h" #include "ltt-sessiond.h" #include "shm.h" #include "ust-app.h" #include "ust-ctl.h" #include "utils.h" -#include "ust-ctl.h" struct consumer_data { enum lttng_consumer_type type; @@ -218,16 +211,16 @@ static int modprobe_remove_kernel_modules(void) for (i = ARRAY_SIZE(kernel_modules_list) - 1; i >= 0; i--) { ret = snprintf(modprobe, sizeof(modprobe), - "/sbin/modprobe --remove --quiet %s", + "/sbin/modprobe -r -q %s", kernel_modules_list[i].name); if (ret < 0) { - perror("snprintf modprobe --remove"); + perror("snprintf modprobe -r"); goto error; } modprobe[sizeof(modprobe) - 1] = '\0'; ret = system(modprobe); if (ret == -1) { - ERR("Unable to launch modprobe --remove for module %s", + ERR("Unable to launch modprobe -r for module %s", kernel_modules_list[i].name); } else if (kernel_modules_list[i].required && WEXITSTATUS(ret) != 0) { @@ -304,6 +297,17 @@ static void teardown_kernel_session(struct ltt_session *session) } } +/* + * Complete teardown of all UST sessions. This will free everything on his path + * and destroy the core essence of all ust sessions :) + */ +static void teardown_ust_session(struct ltt_session *session) +{ + DBG("Tearing down UST session(s)"); + + trace_ust_destroy_session(session->ust_session); +} + /* * Stop all threads by closing the thread quit pipe. */ @@ -364,7 +368,8 @@ static void cleanup(void) cds_list_for_each_entry_safe(sess, stmp, &session_list_ptr->head, list) { teardown_kernel_session(sess); - // TODO complete session cleanup (including UST) + teardown_ust_session(sess); + free(sess); } } @@ -477,80 +482,6 @@ error: return ret; } -/* - * Send all stream fds of UST channel to the consumer. - */ -static int send_ustconsumer_channel_streams(struct consumer_data *consumer_data, - int sock, struct ltt_ust_channel *channel) -{ - int ret, fds[2]; - struct ltt_ust_stream *stream; - struct lttcomm_consumer_msg lum; - - DBG("Sending streams of channel %s to UST consumer", - channel->name); - - /* Send channel */ - lum.cmd_type = LTTNG_CONSUMER_ADD_CHANNEL; - /* - * We need to keep shm_fd open to make sure this key stays - * unique within the session daemon. - */ - lum.u.channel.channel_key = channel->obj->shm_fd; - lum.u.channel.max_sb_size = channel->attr.subbuf_size; - lum.u.channel.mmap_len = channel->obj->memory_map_size; - DBG("Sending channel %d to consumer", lum.u.channel.channel_key); - ret = lttcomm_send_unix_sock(sock, &lum, sizeof(lum)); - if (ret < 0) { - perror("send consumer channel"); - goto error; - } - fds[0] = channel->obj->shm_fd; - fds[1] = channel->obj->wait_fd; - ret = lttcomm_send_fds_unix_sock(sock, fds, 2); - if (ret < 0) { - perror("send consumer channel ancillary data"); - goto error; - } - - /* Send streams */ - cds_list_for_each_entry(stream, &channel->stream_list.head, list) { - int fds[2]; - - if (!stream->obj->shm_fd) { - continue; - } - lum.cmd_type = LTTNG_CONSUMER_ADD_STREAM; - lum.u.stream.channel_key = channel->obj->shm_fd; - lum.u.stream.stream_key = stream->obj->shm_fd; - lum.u.stream.state = LTTNG_CONSUMER_ACTIVE_STREAM; - lum.u.stream.output = channel->attr.output; - lum.u.stream.mmap_len = stream->obj->memory_map_size; - strncpy(lum.u.stream.path_name, stream->pathname, PATH_MAX - 1); - lum.u.stream.path_name[PATH_MAX - 1] = '\0'; - DBG("Sending stream %d to consumer", lum.u.stream.stream_key); - ret = lttcomm_send_unix_sock(sock, &lum, sizeof(lum)); - if (ret < 0) { - perror("send consumer stream"); - goto error; - } - fds[0] = stream->obj->shm_fd; - fds[1] = stream->obj->wait_fd; - ret = lttcomm_send_fds_unix_sock(sock, fds, 2); - if (ret < 0) { - perror("send consumer stream ancillary data"); - goto error; - } - } - - DBG("consumer channel streams sent"); - - return 0; - -error: - return ret; -} - /* * Send all stream fds of the kernel session to the consumer. */ @@ -619,85 +550,6 @@ error: return ret; } -/* - * Send all stream fds of the UST session to the consumer. - */ -static int send_ustconsumer_session_streams(struct consumer_data *consumer_data, - struct ltt_ust_session *session) -{ - int ret; - struct ltt_ust_channel *chan; - struct lttcomm_consumer_msg lum; - int sock = session->consumer_fd; - - DBG("Sending metadata stream fd"); - - /* Extra protection. It's NOT supposed to be set to 0 at this point */ - if (session->consumer_fd == 0) { - session->consumer_fd = consumer_data->cmd_sock; - } - - if (session->metadata->obj->shm_fd != 0) { - int fds[2]; - - /* Send metadata channel fd */ - lum.cmd_type = LTTNG_CONSUMER_ADD_CHANNEL; - lum.u.channel.channel_key = session->metadata->obj->shm_fd; - lum.u.channel.max_sb_size = session->metadata->attr.subbuf_size; - lum.u.channel.mmap_len = 0; /* for kernel */ - DBG("Sending metadata channel %d to consumer", lum.u.stream.stream_key); - ret = lttcomm_send_unix_sock(sock, &lum, sizeof(lum)); - if (ret < 0) { - perror("send consumer channel"); - goto error; - } - fds[0] = session->metadata->obj->shm_fd; - fds[1] = session->metadata->obj->wait_fd; - ret = lttcomm_send_fds_unix_sock(sock, fds, 2); - if (ret < 0) { - perror("send consumer metadata channel"); - goto error; - } - - /* Send metadata stream fd */ - lum.cmd_type = LTTNG_CONSUMER_ADD_STREAM; - lum.u.stream.channel_key = session->metadata->obj->shm_fd; - lum.u.stream.stream_key = session->metadata->stream_obj->shm_fd; - lum.u.stream.state = LTTNG_CONSUMER_ACTIVE_STREAM; - lum.u.stream.output = DEFAULT_UST_CHANNEL_OUTPUT; - lum.u.stream.mmap_len = session->metadata->stream_obj->memory_map_size; - strncpy(lum.u.stream.path_name, session->metadata->pathname, PATH_MAX - 1); - lum.u.stream.path_name[PATH_MAX - 1] = '\0'; - DBG("Sending metadata stream %d to consumer", lum.u.stream.stream_key); - ret = lttcomm_send_unix_sock(sock, &lum, sizeof(lum)); - if (ret < 0) { - perror("send consumer metadata stream"); - goto error; - } - fds[0] = session->metadata->stream_obj->shm_fd; - fds[1] = session->metadata->stream_obj->wait_fd; - ret = lttcomm_send_fds_unix_sock(sock, fds, 2); - if (ret < 0) { - perror("send consumer stream"); - goto error; - } - } - - cds_list_for_each_entry(chan, &session->channels.head, list) { - ret = send_ustconsumer_channel_streams(consumer_data, sock, chan); - if (ret < 0) { - goto error; - } - } - - DBG("consumer fds (metadata and channel streams) sent"); - - return 0; - -error: - return ret; -} - /* * Notify UST applications using the shm mmap futex. */ @@ -1042,7 +894,7 @@ static void *thread_manage_consumer(void *data) lttcomm_connect_unix_sock(consumer_data->cmd_unix_sock_path); if (consumer_data->cmd_sock < 0) { sem_post(&consumer_data->sem); - perror("consumer connect"); + PERROR("consumer connect"); goto error; } /* Signal condition to tell that the kconsumerd is ready */ @@ -1131,6 +983,9 @@ static void *thread_manage_apps(void *data) DBG("[thread] Manage application started"); + rcu_register_thread(); + rcu_thread_online(); + ret = create_thread_poll_set(&events, 2); if (ret < 0) { goto error; @@ -1236,6 +1091,8 @@ error: lttng_poll_clean(&events); + rcu_thread_offline(); + rcu_unregister_thread(); return NULL; } @@ -1605,7 +1462,7 @@ static int start_consumerd(struct consumer_data *consumer_data) /* Setting up the consumer_data pid */ consumer_data->pid = ret; - DBG2("consumer pid %d", consumer_data->pid); + DBG2("Consumer pid %d", consumer_data->pid); pthread_mutex_unlock(&consumer_data->pid_mutex); DBG2("Spawning consumer control thread"); @@ -1633,7 +1490,7 @@ static int modprobe_kernel_modules(void) for (i = 0; i < ARRAY_SIZE(kernel_modules_list); i++) { ret = snprintf(modprobe, sizeof(modprobe), "/sbin/modprobe %s%s", - kernel_modules_list[i].required ? "" : "--quiet ", + kernel_modules_list[i].required ? "" : "-q ", kernel_modules_list[i].name); if (ret < 0) { perror("snprintf modprobe"); @@ -1796,36 +1653,6 @@ error: return ret; } -/* - * Init tracing by creating trace directory and sending fds ust consumer. - */ -static int init_ust_tracing(struct ltt_ust_session *session) -{ - int ret = 0; - - if (session->consumer_fds_sent == 0) { - /* - * Assign default ust consumer socket if no consumer assigned to the - * ust session. At this point, it's NOT suppose to be 0 but this is - * an extra security check. - */ - if (session->consumer_fd == 0) { - session->consumer_fd = ustconsumer_data.cmd_sock; - } - - ret = send_ustconsumer_session_streams(&ustconsumer_data, session); - if (ret < 0) { - ret = LTTCOMM_UST_CONSUMER_FAIL; - goto error; - } - - session->consumer_fds_sent = 1; - } - -error: - return ret; -} - /* * Create an UST session and add it to the session ust list. */ @@ -1833,16 +1660,11 @@ static int create_ust_session(struct ltt_session *session, struct lttng_domain *domain) { int ret; + unsigned int uid; struct ltt_ust_session *lus = NULL; - struct ust_app *app; switch (domain->type) { - case LTTNG_DOMAIN_UST_PID: - app = ust_app_get_by_pid(domain->attr.pid); - if (app == NULL) { - ret = LTTCOMM_APP_NOT_FOUND; - goto error; - } + case LTTNG_DOMAIN_UST: break; default: ret = LTTCOMM_UNKNOWN_DOMAIN; @@ -1851,13 +1673,17 @@ static int create_ust_session(struct ltt_session *session, DBG("Creating UST session"); - lus = trace_ust_create_session(session->path, domain->attr.pid, domain); + session_lock_list(); + uid = session_list_ptr->count; + session_unlock_list(); + + lus = trace_ust_create_session(session->path, uid, domain); if (lus == NULL) { ret = LTTCOMM_UST_SESS_FAIL; goto error; } - ret = mkdir_recursive(lus->path, S_IRWXU | S_IRWXG, + ret = mkdir_recursive(lus->pathname, S_IRWXU | S_IRWXG, geteuid(), allowed_group()); if (ret < 0) { if (ret != -EEXIST) { @@ -1867,17 +1693,15 @@ static int create_ust_session(struct ltt_session *session, } } - /* Create session on the UST tracer */ - ret = ustctl_create_session(app->sock); - if (ret < 0) { - ret = LTTCOMM_UST_SESS_FAIL; + /* The domain type dictate different actions on session creation */ + switch (domain->type) { + case LTTNG_DOMAIN_UST: + /* No ustctl for the global UST domain */ + break; + default: goto error; } - lus->handle = ret; - lus->sock = app->sock; - - cds_list_add(&lus->list, &session->ust_session_list.head); - session->ust_session_list.count++; + session->ust_session = lus; return LTTCOMM_OK; @@ -2052,13 +1876,14 @@ error: /* * Copy channel from attributes and set it in the application channel list. */ +/* static int copy_ust_channel_to_app(struct ltt_ust_session *usess, struct lttng_channel *attr, struct ust_app *app) { int ret; struct ltt_ust_channel *uchan, *new_chan; - uchan = trace_ust_get_channel_by_name(attr->name, usess); + uchan = trace_ust_get_channel_by_key(usess->channels, attr->name); if (uchan == NULL) { ret = LTTCOMM_FATAL; goto error; @@ -2077,13 +1902,10 @@ static int copy_ust_channel_to_app(struct ltt_ust_session *usess, goto error; } - /* Add channel to the ust app channel list */ - cds_list_add(&new_chan->list, &app->channels.head); - app->channels.count++; - error: return ret; } +*/ /* * Command LTTNG_ENABLE_CHANNEL processed by the client thread. @@ -2092,6 +1914,9 @@ static int cmd_enable_channel(struct ltt_session *session, struct lttng_domain *domain, struct lttng_channel *attr) { int ret; + struct ltt_ust_session *usess = session->ust_session; + + DBG("Enabling channel %s for session %s", session->name, attr->name); switch (domain->type) { case LTTNG_DOMAIN_KERNEL: @@ -2114,8 +1939,40 @@ static int cmd_enable_channel(struct ltt_session *session, kernel_wait_quiescent(kernel_tracer_fd); break; } + case LTTNG_DOMAIN_UST: + { + struct ltt_ust_channel *uchan; + + DBG2("Enabling channel for LTTNG_DOMAIN_UST"); + + /* Get channel in global UST domain HT */ + uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, + attr->name); + if (uchan == NULL) { + uchan = trace_ust_create_channel(attr, usess->pathname); + if (uchan == NULL) { + ret = LTTCOMM_UST_CHAN_FAIL; + goto error; + } + rcu_read_lock(); + hashtable_add_unique(usess->domain_global.channels, &uchan->node); + rcu_read_unlock(); + DBG2("UST channel %s added to global domain HT", attr->name); + } else { + ret = LTTCOMM_UST_CHAN_EXIST; + goto error; + } + + ret = ust_app_add_channel(usess, uchan); + if (ret != LTTCOMM_OK) { + goto error; + } + + break; + } case LTTNG_DOMAIN_UST_PID: { + /* int sock; struct ltt_ust_channel *uchan; struct ltt_ust_session *usess; @@ -2153,7 +2010,9 @@ static int cmd_enable_channel(struct ltt_session *session, DBG("UST channel %s created for app sock %d with pid %d", attr->name, app->sock, domain->attr.pid); - break; + */ + ret = LTTCOMM_NOT_IMPLEMENTED; + goto error; } default: ret = LTTCOMM_UNKNOWN_DOMAIN; @@ -2195,27 +2054,6 @@ static int cmd_disable_event(struct ltt_session *session, int domain, break; } case LTTNG_DOMAIN_UST: - { - struct ltt_ust_session *ustsession; - - cds_list_for_each_entry(ustsession, &session->ust_session_list.head, list) { - struct ltt_ust_channel *ustchan; - - ustchan = trace_ust_get_channel_by_name(channel_name, - ustsession); - if (ustchan == NULL) { - ret = LTTCOMM_KERN_CHAN_NOT_FOUND; - goto error; - } - ret = event_ust_disable_tracepoint(ustsession, ustchan, event_name); - if (ret != LTTCOMM_OK) { - goto error; - } - - ustctl_wait_quiescent(ustsession->sock); - } - break; - } case LTTNG_DOMAIN_UST_EXEC_NAME: case LTTNG_DOMAIN_UST_PID: case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: @@ -2287,17 +2125,18 @@ static int cmd_add_context(struct ltt_session *session, int domain, break; case LTTNG_DOMAIN_UST: { - struct ltt_ust_session *ustsession; + /* + struct ltt_ust_session *usess; - cds_list_for_each_entry(ustsession, &session->ust_session_list.head, list) { - /* Add UST context to UST tracer */ - ret = context_ust_add(ustsession, ctx, - event_name, channel_name); + cds_list_for_each_entry(usess, &session->ust_session_list.head, list) { + ret = context_ust_add(usess, ctx, + event_name, channel_name, domain); if (ret != LTTCOMM_OK) { goto error; } } break; + */ } default: /* TODO: UST other domains */ @@ -2319,6 +2158,7 @@ static int cmd_enable_event(struct ltt_session *session, int domain, { int ret; struct lttng_channel *attr; + struct ltt_ust_session *usess = session->ust_session; switch (domain) { case LTTNG_DOMAIN_KERNEL: @@ -2352,7 +2192,8 @@ static int cmd_enable_event(struct ltt_session *session, int domain, goto error; } - ret = event_kernel_enable_tracepoint(session->kernel_session, kchan, event); + ret = event_kernel_enable_tracepoint(session->kernel_session, kchan, + event); if (ret != LTTCOMM_OK) { goto error; } @@ -2362,43 +2203,30 @@ static int cmd_enable_event(struct ltt_session *session, int domain, } case LTTNG_DOMAIN_UST: { - struct ltt_ust_session *ustsession; - - cds_list_for_each_entry(ustsession, &session->ust_session_list.head, list) { - struct ltt_ust_channel *ustchan; - - ustchan = trace_ust_get_channel_by_name(channel_name, - ustsession); - if (ustchan == NULL) { - attr = channel_new_default_attr(domain); - if (attr == NULL) { - ret = LTTCOMM_FATAL; - goto error; - } - snprintf(attr->name, NAME_MAX, "%s", channel_name); + struct ltt_ust_channel *uchan; + struct ltt_ust_event *uevent; - ret = channel_ust_create(ustsession, - attr, ustsession->sock); - if (ret != LTTCOMM_OK) { - goto error; - } - } + uchan = trace_ust_find_channel_by_name(usess->domain_global.channels, + channel_name); + if (uchan == NULL) { + /* TODO: Create default channel */ + ret = LTTCOMM_UST_CHAN_NOT_FOUND; + goto error; + } - /* Get the newly created ust channel pointer */ - ustchan = trace_ust_get_channel_by_name(channel_name, - ustsession); - if (ustchan == NULL) { - /* This sould not happen... */ + uevent = trace_ust_find_event_by_name(uchan->events, event->name); + if (uevent == NULL) { + uevent = trace_ust_create_event(event); + if (uevent == NULL) { ret = LTTCOMM_FATAL; goto error; } + } - ret = event_ust_enable_tracepoint(ustsession, ustchan, event); - if (ret != LTTCOMM_OK) { - goto error; - } - - ustctl_wait_quiescent(ustsession->sock); + ret = ust_app_add_event(usess, uchan, uevent); + if (ret < 0) { + ret = LTTCOMM_UST_ENABLE_FAIL; + goto error; } break; } @@ -2406,7 +2234,6 @@ static int cmd_enable_event(struct ltt_session *session, int domain, case LTTNG_DOMAIN_UST_PID: case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: default: - /* TODO: UST other domains */ ret = LTTCOMM_NOT_IMPLEMENTED; goto error; } @@ -2524,7 +2351,7 @@ static int cmd_start_trace(struct ltt_session *session) { int ret; struct ltt_kernel_session *ksession; - struct ltt_ust_session *ustsession; + struct ltt_ust_session *usess = session->ust_session; /* Short cut */ ksession = session->kernel_session; @@ -2583,100 +2410,10 @@ static int cmd_start_trace(struct ltt_session *session) kernel_wait_quiescent(kernel_tracer_fd); } - /* Start all UST traces */ - cds_list_for_each_entry(ustsession, &session->ust_session_list.head, list) { - struct ltt_ust_channel *ustchan; - - /* Open kernel metadata */ - if (ustsession->metadata == NULL) { - struct lttng_ust_channel_attr ustattr; - - /* Allocate UST metadata */ - ustsession->metadata = trace_ust_create_metadata(ustsession->path); - if (ustsession->metadata == NULL) { - ret = LTTCOMM_UST_META_FAIL; - goto error; - } - - ustattr.overwrite = ustsession->metadata->attr.overwrite; - ustattr.subbuf_size = ustsession->metadata->attr.subbuf_size; - ustattr.num_subbuf = ustsession->metadata->attr.num_subbuf; - ustattr.switch_timer_interval = ustsession->metadata->attr.switch_timer_interval; - ustattr.read_timer_interval = ustsession->metadata->attr.read_timer_interval; - ustattr.output = ustsession->metadata->attr.output; - - /* UST tracer metadata creation */ - ret = ustctl_open_metadata(ustsession->sock, - ustsession->handle, &ustattr, - &ustsession->metadata->obj); - if (ret < 0) { - ret = LTTCOMM_UST_META_FAIL; - goto error; - } - } - - /* Open UST metadata stream */ - if (ustsession->metadata->stream_obj == NULL) { - ret = ustctl_create_stream(ustsession->sock, - ustsession->metadata->obj, - &ustsession->metadata->stream_obj); - if (ret < 0) { - ERR("UST create metadata stream failed"); - ret = LTTCOMM_UST_STREAM_FAIL; - goto error; - } - ret = asprintf(&ustsession->metadata->pathname, "%s/%s", - ustsession->path, "metadata"); - if (ret < 0) { - perror("asprintf UST create stream"); - goto error; - } - } - - /* For each channel */ - cds_list_for_each_entry(ustchan, &ustsession->channels.head, list) { - if (ustchan->stream_count == 0) { - struct ltt_ust_stream *ustream; - - ustream = zmalloc(sizeof(*ustream)); - if (!ustream) { - ret = LTTCOMM_UST_STREAM_FAIL; - goto error; - } - ret = ustctl_create_stream(ustsession->sock, - ustchan->obj, &ustream->obj); - if (ret < 0) { - ret = LTTCOMM_UST_STREAM_FAIL; - goto error; - } - ret = asprintf(&ustream->pathname, "%s/%s_%d", - ustchan->trace_path, ustchan->name, - ustchan->stream_count); - if (ret < 0) { - perror("asprintf UST create stream"); - goto error; - } - cds_list_add(&ustream->list, &ustchan->stream_list.head); - ustchan->stream_count++; - } - } - - /* Setup UST consumer socket and send fds to it */ - ret = init_ust_tracing(ustsession); - if (ret < 0) { - ret = LTTCOMM_UST_START_FAIL; - goto error; - } - - /* This start the UST tracing */ - ret = ustctl_start_session(ustsession->sock, ustsession->handle); - if (ret < 0) { - ret = LTTCOMM_UST_START_FAIL; - goto error; - } - - /* Quiescent wait after starting trace */ - ustctl_wait_quiescent(ustsession->sock); + ret = ust_app_start_trace(usess); + if (ret < 0) { + ret = LTTCOMM_UST_START_FAIL; + goto error; } ret = LTTCOMM_OK; @@ -2693,8 +2430,8 @@ static int cmd_stop_trace(struct ltt_session *session) int ret; struct ltt_kernel_channel *kchan; struct ltt_kernel_session *ksession; - struct ltt_ust_session *ustsession; - struct ltt_ust_channel *ustchan; + //struct ltt_ust_session *usess; + //struct ltt_ust_channel *ustchan; /* Short cut */ ksession = session->kernel_session; @@ -2725,30 +2462,32 @@ static int cmd_stop_trace(struct ltt_session *session) kernel_wait_quiescent(kernel_tracer_fd); } +#ifdef DISABLE /* Stop each UST session */ DBG("Stop UST tracing"); - cds_list_for_each_entry(ustsession, &session->ust_session_list.head, list) { + cds_list_for_each_entry(usess, &session->ust_session_list.head, list) { /* Flush all buffers before stopping */ - ret = ustctl_flush_buffer(ustsession->sock, ustsession->metadata->obj); + ret = ustctl_flush_buffer(usess->sock, usess->metadata->obj); if (ret < 0) { ERR("UST metadata flush failed"); } - cds_list_for_each_entry(ustchan, &ustsession->channels.head, list) { - ret = ustctl_flush_buffer(ustsession->sock, ustchan->obj); + cds_list_for_each_entry(ustchan, &usess->channels.head, list) { + ret = ustctl_flush_buffer(usess->sock, ustchan->obj); if (ret < 0) { ERR("UST flush buffer error"); } } - ret = ustctl_stop_session(ustsession->sock, ustsession->handle); + ret = ustctl_stop_session(usess->sock, usess->handle); if (ret < 0) { ret = LTTCOMM_KERN_STOP_FAIL; goto error; } - ustctl_wait_quiescent(ustsession->sock); + ustctl_wait_quiescent(usess->sock); } +#endif ret = LTTCOMM_OK; @@ -2879,7 +2618,7 @@ static ssize_t cmd_list_domains(struct ltt_session *session, nb_dom++; } - nb_dom += session->ust_session_list.count; + /* TODO: User-space tracer domain support */ *domains = malloc(nb_dom * sizeof(struct lttng_domain)); if (*domains == NULL) { @@ -2889,8 +2628,6 @@ static ssize_t cmd_list_domains(struct ltt_session *session, (*domains)[0].type = LTTNG_DOMAIN_KERNEL; - /* TODO: User-space tracer domain support */ - return nb_dom; error: @@ -3065,17 +2802,9 @@ static int process_client_msg(struct command_ctx *cmd_ctx) } break; case LTTNG_DOMAIN_UST: - case LTTNG_DOMAIN_UST_EXEC_NAME: - case LTTNG_DOMAIN_UST_PID: - case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: { - struct ltt_ust_session *usess; - if (need_tracing_session) { - usess = trace_ust_get_session_by_pid( - &cmd_ctx->session->ust_session_list, - cmd_ctx->lsm->domain.attr.pid); - if (usess == NULL) { + if (cmd_ctx->session->ust_session == NULL) { ret = create_ust_session(cmd_ctx->session, &cmd_ctx->lsm->domain); if (ret != LTTCOMM_OK) { @@ -3092,6 +2821,9 @@ static int process_client_msg(struct command_ctx *cmd_ctx) ret = LTTCOMM_KERN_CONSUMER_FAIL; goto error; } + + cmd_ctx->session->ust_session->consumer_fd = + ustconsumer_data.cmd_sock; } pthread_mutex_unlock(&ustconsumer_data.pid_mutex); } @@ -3355,6 +3087,8 @@ static void *thread_manage_clients(void *data) DBG("[thread] Manage client started"); + rcu_register_thread(); + ret = lttcomm_listen_unix_sock(client_sock); if (ret < 0) { goto error; @@ -3455,6 +3189,7 @@ static void *thread_manage_clients(void *data) // TODO: Validate cmd_ctx including sanity check for // security purpose. + rcu_thread_online(); /* * This function dispatch the work to the kernel or userspace tracer * libs and fill the lttcomm_lttng_msg data structure of all the needed @@ -3462,6 +3197,7 @@ static void *thread_manage_clients(void *data) * everything this function may needs. */ ret = process_client_msg(cmd_ctx); + rcu_thread_offline(); if (ret < 0) { /* * TODO: Inform client somehow of the fatal error. At @@ -3494,6 +3230,8 @@ error: lttng_poll_clean(&events); clean_command_ctx(&cmd_ctx); + + rcu_unregister_thread(); return NULL; } @@ -3922,6 +3660,8 @@ int main(int argc, char **argv) void *status; const char *home_path; + rcu_register_thread(); + /* Create thread quit pipe */ if ((ret = init_thread_quit_pipe()) < 0) { goto error; @@ -4021,6 +3761,7 @@ int main(int argc, char **argv) if (ret < 0) { goto exit; } + ret = set_consumer_sockets(&ustconsumer_data); if (ret < 0) { goto exit; @@ -4064,6 +3805,9 @@ int main(int argc, char **argv) /* Init UST command queue. */ cds_wfq_init(&ust_cmd_queue.queue); + /* Init UST app hash table */ + ust_app_ht_alloc(); + /* * Get session list pointer. This pointer MUST NOT be free(). This list is * statically declared in session.c @@ -4158,7 +3902,10 @@ exit: /* * cleanup() is called when no other thread is running. */ + rcu_thread_online(); cleanup(); + rcu_thread_offline(); + rcu_unregister_thread(); if (!ret) exit(EXIT_SUCCESS); error: