X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-app.c;h=63b106ae43a2de504df24aff7e6a070000bb5045;hb=f37d259d342af1ff8855d9eaa578cb7a3cfcc4f2;hp=79526fceb61f5d712174baaad97562d6cdae889e;hpb=a2c0da862b4c3286fa919b96556bc30e8914e28b;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 79526fceb..63b106ae4 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -31,6 +31,7 @@ #include "ust-app.h" #include "ust-consumer.h" #include "ust-ctl.h" +#include "fd-limit.h" /* * Delete ust context safely. RCU read lock must be held before calling @@ -82,6 +83,7 @@ void delete_ust_app_stream(int sock, struct ltt_ust_stream *stream) { if (stream->obj) { ustctl_release_object(sock, stream->obj); + lttng_fd_put(LTTNG_FD_APPS, 2); free(stream->obj); } free(stream); @@ -125,6 +127,7 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan) if (ua_chan->obj != NULL) { ustctl_release_object(sock, ua_chan->obj); + lttng_fd_put(LTTNG_FD_APPS, 2); free(ua_chan->obj); } free(ua_chan); @@ -144,10 +147,12 @@ void delete_ust_app_session(int sock, struct ust_app_session *ua_sess) if (ua_sess->metadata) { if (ua_sess->metadata->stream_obj) { ustctl_release_object(sock, ua_sess->metadata->stream_obj); + lttng_fd_put(LTTNG_FD_APPS, 2); free(ua_sess->metadata->stream_obj); } if (ua_sess->metadata->obj) { ustctl_release_object(sock, ua_sess->metadata->obj); + lttng_fd_put(LTTNG_FD_APPS, 2); free(ua_sess->metadata->obj); } trace_ust_destroy_metadata(ua_sess->metadata); @@ -210,6 +215,7 @@ void delete_ust_app(struct ust_app *app) if (ret) { PERROR("close"); } + lttng_fd_put(LTTNG_FD_APPS, 1); DBG2("UST app pid %d deleted", app->pid); free(app); @@ -536,6 +542,12 @@ static int open_ust_metadata(struct ust_app *app, ua_sess->metadata->attr.read_timer_interval; uattr.output = ua_sess->metadata->attr.output; + /* We are going to receive 2 fds, we need to reserve them. */ + ret = lttng_fd_get(LTTNG_FD_APPS, 2); + if (ret < 0) { + ERR("Exhausted number of available FD upon metadata open"); + goto error; + } /* UST tracer metadata creation */ ret = ustctl_open_metadata(app->sock, ua_sess->handle, &uattr, &ua_sess->metadata->obj); @@ -559,6 +571,12 @@ static int create_ust_stream(struct ust_app *app, { int ret; + /* We are going to receive 2 fds, we need to reserve them. */ + ret = lttng_fd_get(LTTNG_FD_APPS, 2); + if (ret < 0) { + ERR("Exhausted number of available FD upon metadata stream create"); + goto error; + } ret = ustctl_create_stream(app->sock, ua_sess->metadata->obj, &ua_sess->metadata->stream_obj); if (ret < 0) { @@ -579,6 +597,13 @@ static int create_ust_channel(struct ust_app *app, int ret; /* TODO: remove cast and use lttng-ust-abi.h */ + + /* We are going to receive 2 fds, we need to reserve them. */ + ret = lttng_fd_get(LTTNG_FD_APPS, 2); + if (ret < 0) { + ERR("Exhausted number of available FD upon create channel"); + goto error; + } ret = ustctl_create_channel(app->sock, ua_sess->handle, (struct lttng_ust_channel_attr *)&ua_chan->attr, &ua_chan->obj); if (ret < 0) { @@ -586,6 +611,7 @@ static int create_ust_channel(struct ust_app *app, "and session handle %d with ret %d", ua_chan->name, app->pid, app->sock, ua_sess->handle, ret); + lttng_fd_put(LTTNG_FD_APPS, 2); goto error; } @@ -1281,6 +1307,7 @@ int ust_app_register(struct ust_register_msg *msg, int sock) if (ret) { PERROR("close"); } + lttng_fd_put(LTTNG_FD_APPS, 1); return -EINVAL; } if (msg->major != LTTNG_UST_COMM_MAJOR) { @@ -1291,6 +1318,7 @@ int ust_app_register(struct ust_register_msg *msg, int sock) if (ret) { PERROR("close"); } + lttng_fd_put(LTTNG_FD_APPS, 1); return -EINVAL; } lta = zmalloc(sizeof(struct ust_app)); @@ -1451,7 +1479,7 @@ int ust_app_list_events(struct lttng_event **events) } memcpy(tmp[count].name, uiter.name, LTTNG_UST_SYM_NAME_LEN); tmp[count].loglevel = uiter.loglevel; - tmp[count].type = LTTNG_UST_TRACEPOINT; + tmp[count].type = (enum lttng_event_type) LTTNG_UST_TRACEPOINT; tmp[count].pid = app->pid; tmp[count].enabled = -1; count++; @@ -1469,6 +1497,82 @@ error: return ret; } +/* + * Fill events array with all events name of all registered apps. + */ +int ust_app_list_event_fields(struct lttng_event_field **fields) +{ + int ret, handle; + size_t nbmem, count = 0; + struct lttng_ht_iter iter; + struct ust_app *app; + struct lttng_event_field *tmp; + + nbmem = UST_APP_EVENT_LIST_SIZE; + tmp = zmalloc(nbmem * sizeof(struct lttng_event_field)); + if (tmp == NULL) { + PERROR("zmalloc ust app event fields"); + ret = -ENOMEM; + goto error; + } + + rcu_read_lock(); + + cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) { + struct lttng_ust_field_iter uiter; + + if (!app->compatible) { + /* + * TODO: In time, we should notice the caller of this error by + * telling him that this is a version error. + */ + continue; + } + handle = ustctl_tracepoint_field_list(app->sock); + if (handle < 0) { + ERR("UST app list event fields getting handle failed for app pid %d", + app->pid); + continue; + } + + while ((ret = ustctl_tracepoint_field_list_get(app->sock, handle, + &uiter)) != -ENOENT) { + if (count >= nbmem) { + DBG2("Reallocating event field list from %zu to %zu entries", nbmem, + 2 * nbmem); + nbmem *= 2; + tmp = realloc(tmp, nbmem * sizeof(struct lttng_event_field)); + if (tmp == NULL) { + PERROR("realloc ust app event fields"); + ret = -ENOMEM; + goto rcu_error; + } + } + + + memcpy(tmp[count].field_name, uiter.field_name, LTTNG_UST_SYM_NAME_LEN); + tmp[count].type = uiter.type; + + memcpy(tmp[count].event.name, uiter.event_name, LTTNG_UST_SYM_NAME_LEN); + tmp[count].event.loglevel = uiter.loglevel; + tmp[count].event.type = LTTNG_UST_TRACEPOINT; + tmp[count].event.pid = app->pid; + tmp[count].event.enabled = -1; + count++; + } + } + + ret = count; + *fields = tmp; + + DBG2("UST app list event fields done (%zu events)", count); + +rcu_error: + rcu_read_unlock(); +error: + return ret; +} + /* * Free and clean all traceable apps of the global list. */ @@ -1977,10 +2081,18 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app) goto error_rcu_unlock; } + /* We are going to receive 2 fds, we need to reserve them. */ + ret = lttng_fd_get(LTTNG_FD_APPS, 2); + if (ret < 0) { + ERR("Exhausted number of available FD upon stream create"); + free(ustream); + goto error_rcu_unlock; + } ret = ustctl_create_stream(app->sock, ua_chan->obj, &ustream->obj); if (ret < 0) { /* Got all streams */ + lttng_fd_put(LTTNG_FD_APPS, 2); free(ustream); break; }