From 56fff0907d3a752030f384e6037d16ea7978de71 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 27 Sep 2011 10:06:42 -0400 Subject: [PATCH] Rename traceable-app and change ust app call Rename traceable-app to ust-app.c/.h and all calls to ust_app_* to be consistent with the code base. Add a channel_ust_copy() to copy UST channel and event list. Mostly used for channel copy between ust session and ust app. Signed-off-by: David Goulet --- ltt-sessiond/Makefile.am | 2 +- ltt-sessiond/channel.c | 30 ++++++ ltt-sessiond/channel.h | 2 + ltt-sessiond/ltt-sessiond.h | 2 +- ltt-sessiond/main.c | 98 +++++++++-------- ltt-sessiond/{traceable-app.c => ust-app.c} | 110 ++++++++++---------- ltt-sessiond/{traceable-app.h => ust-app.h} | 21 ++-- 7 files changed, 151 insertions(+), 114 deletions(-) rename ltt-sessiond/{traceable-app.c => ust-app.c} (64%) rename ltt-sessiond/{traceable-app.h => ust-app.h} (84%) diff --git a/ltt-sessiond/Makefile.am b/ltt-sessiond/Makefile.am index 5b7093371..cdcdfc60e 100644 --- a/ltt-sessiond/Makefile.am +++ b/ltt-sessiond/Makefile.am @@ -15,7 +15,7 @@ ltt_sessiond_SOURCES = utils.c utils.h \ compat/poll.h $(COMPAT) \ trace-kernel.c trace-kernel.h \ trace-ust.c trace-ust.h \ - traceable-app.c traceable-app.h \ + ust-app.c ust-app.h \ ust-comm.c ust-comm.h \ ust-ctl.c ust-ctl.h \ kernel-ctl.c kernel-ctl.h \ diff --git a/ltt-sessiond/channel.c b/ltt-sessiond/channel.c index 818f6dcfd..350bab6ab 100644 --- a/ltt-sessiond/channel.c +++ b/ltt-sessiond/channel.c @@ -15,6 +15,7 @@ * Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include #include #include @@ -72,6 +73,35 @@ error_alloc: return NULL; } +/* + * Copy two ltt ust channel. Dst and src must be already allocated. + */ +int channel_ust_copy(struct ltt_ust_channel *dst, + struct ltt_ust_channel *src) +{ + struct ltt_ust_event *uevent, *new_uevent; + + memcpy(dst, src, sizeof(struct ltt_ust_channel)); + CDS_INIT_LIST_HEAD(&dst->events.head); + + cds_list_for_each_entry(uevent, &src->events.head, list) { + new_uevent = malloc(sizeof(struct ltt_ust_event)); + if (new_uevent == NULL) { + perror("malloc ltt_ust_event"); + goto error; + } + + memcpy(new_uevent, uevent, sizeof(struct ltt_ust_event)); + cds_list_add(&new_uevent->list, &dst->events.head); + dst->events.count++; + } + + return 0; + +error: + return -1; +} + /* * Disable kernel channel of the kernel session. */ diff --git a/ltt-sessiond/channel.h b/ltt-sessiond/channel.h index f9a6fbd85..4c368e619 100644 --- a/ltt-sessiond/channel.h +++ b/ltt-sessiond/channel.h @@ -32,6 +32,8 @@ int channel_kernel_create(struct ltt_kernel_session *ksession, int channel_ust_create(struct ltt_ust_session *usession, struct lttng_channel *chan, int sock); +int channel_ust_copy(struct ltt_ust_channel *dst, + struct ltt_ust_channel *src); int channel_ust_disable(struct ltt_ust_session *usession, struct ltt_ust_channel *uchan, int sock); int channel_ust_enable(struct ltt_ust_session *usession, diff --git a/ltt-sessiond/ltt-sessiond.h b/ltt-sessiond/ltt-sessiond.h index 617ca54c4..c28572a86 100644 --- a/ltt-sessiond/ltt-sessiond.h +++ b/ltt-sessiond/ltt-sessiond.h @@ -22,7 +22,7 @@ #define _LGPL_SOURCE #include -#include "traceable-app.h" +#include "ust-app.h" #define DEFAULT_HOME_DIR "/tmp" #define DEFAULT_UST_SOCK_DIR DEFAULT_HOME_DIR "/ust-app-socks" diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 825fa4371..e1bf1e416 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -50,7 +50,7 @@ #include "kernel-ctl.h" #include "ltt-sessiond.h" #include "shm.h" -#include "traceable-app.h" +#include "ust-app.h" #include "ust-ctl.h" #include "utils.h" #include "ust-ctl.h" @@ -344,7 +344,7 @@ static void cleanup(void) } DBG("Closing all UST sockets"); - clean_traceable_apps_list(); + ust_app_clean_list(); pthread_mutex_destroy(&kconsumerd_pid_mutex); @@ -986,7 +986,7 @@ static void *thread_manage_apps(void *data) } /* Register applicaton to the session daemon */ - ret = register_traceable_app(&ust_cmd.reg_msg, + ret = ust_app_register(&ust_cmd.reg_msg, ust_cmd.sock); if (ret < 0) { /* Only critical ENOMEM error can be returned here */ @@ -999,7 +999,7 @@ static void *thread_manage_apps(void *data) * If the registration is not possible, we simply * unregister the apps and continue */ - unregister_traceable_app(ust_cmd.sock); + ust_app_unregister(ust_cmd.sock); } else { /* * We just need here to monitor the close of the UST @@ -1028,7 +1028,7 @@ static void *thread_manage_apps(void *data) } /* Socket closed */ - unregister_traceable_app(pollfd); + ust_app_unregister(pollfd); break; } } @@ -1566,11 +1566,11 @@ static int create_ust_session(struct ltt_session *session, { int ret; struct ltt_ust_session *lus; - struct ltt_traceable_app *app; + struct ust_app *app; switch (domain->type) { case LTTNG_DOMAIN_UST_PID: - app = traceable_app_get_by_pid(domain->attr.pid); + app = ust_app_get_by_pid(domain->attr.pid); if (app == NULL) { ret = LTTCOMM_APP_NOT_FOUND; goto error; @@ -1775,6 +1775,42 @@ error: return ret; } +/* + * 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); + if (uchan == NULL) { + ret = LTTCOMM_FATAL; + goto error; + } + + new_chan = trace_ust_create_channel(attr, usess->path); + if (new_chan == NULL) { + PERROR("malloc ltt_ust_channel"); + ret = LTTCOMM_FATAL; + goto error; + } + + ret = channel_ust_copy(new_chan, uchan); + if (ret < 0) { + ret = LTTCOMM_FATAL; + 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. */ @@ -1806,10 +1842,10 @@ static int cmd_enable_channel(struct ltt_session *session, } case LTTNG_DOMAIN_UST_PID: { - struct ltt_ust_event *uevent, *new_uevent; + int sock; + struct ltt_ust_channel *uchan; struct ltt_ust_session *usess; - struct ltt_ust_channel *uchan, *app_chan; - struct ltt_traceable_app *app; + struct ust_app *app; usess = trace_ust_get_session_by_pid(&session->ust_session_list, domain->attr.pid); @@ -1818,59 +1854,29 @@ static int cmd_enable_channel(struct ltt_session *session, goto error; } - app = traceable_app_get_by_pid(domain->attr.pid); + app = ust_app_get_by_pid(domain->attr.pid); if (app == NULL) { ret = LTTCOMM_APP_NOT_FOUND; goto error; } + sock = app->sock; uchan = trace_ust_get_channel_by_name(attr->name, usess); if (uchan == NULL) { - ret = channel_ust_create(usess, attr, app->sock); + ret = channel_ust_create(usess, attr, sock); } else { - ret = channel_ust_enable(usess, uchan, app->sock); + ret = channel_ust_enable(usess, uchan, sock); } if (ret != LTTCOMM_OK) { goto error; } - /*TODO: This should be put in an external function */ - - /* Copy UST channel to add to the traceable app */ - uchan = trace_ust_get_channel_by_name(attr->name, usess); - if (uchan == NULL) { - ret = LTTCOMM_FATAL; - goto error; - } - - app_chan = trace_ust_create_channel(attr, session->path); - if (app_chan == NULL) { - PERROR("malloc ltt_ust_channel"); - ret = LTTCOMM_FATAL; + ret = copy_ust_channel_to_app(usess, attr, app); + if (ret != LTTCOMM_OK) { goto error; } - memcpy(app_chan, uchan, sizeof(struct ltt_ust_channel)); - CDS_INIT_LIST_HEAD(&app_chan->events.head); - - cds_list_for_each_entry(uevent, &uchan->events.head, list) { - new_uevent = malloc(sizeof(struct ltt_ust_event)); - if (new_uevent == NULL) { - PERROR("malloc ltt_ust_event"); - ret = LTTCOMM_FATAL; - goto error; - } - - memcpy(new_uevent, uevent, sizeof(struct ltt_ust_event)); - cds_list_add(&new_uevent->list, &app_chan->events.head); - app_chan->events.count++; - } - - /* Add channel to traceable_app */ - cds_list_add(&app_chan->list, &app->channels.head); - app->channels.count++; - DBG("UST channel %s created for app sock %d with pid %d", attr->name, app->sock, domain->attr.pid); break; diff --git a/ltt-sessiond/traceable-app.c b/ltt-sessiond/ust-app.c similarity index 64% rename from ltt-sessiond/traceable-app.c rename to ltt-sessiond/ust-app.c index 41dc51111..ea062557e 100644 --- a/ltt-sessiond/traceable-app.c +++ b/ltt-sessiond/ust-app.c @@ -26,11 +26,11 @@ #include -#include "traceable-app.h" +#include "ust-app.h" -/* Init ust traceabl application's list */ -static struct ltt_traceable_app_list ltt_traceable_app_list = { - .head = CDS_LIST_HEAD_INIT(ltt_traceable_app_list.head), +/* Init ust traceable application's list */ +static struct ust_app_list ust_app_list = { + .head = CDS_LIST_HEAD_INIT(ust_app_list.head), .lock = PTHREAD_MUTEX_INITIALIZER, .count = 0, }; @@ -38,23 +38,23 @@ static struct ltt_traceable_app_list ltt_traceable_app_list = { /* * Add a traceable application structure to the global list. */ -static void add_traceable_app(struct ltt_traceable_app *lta) +static void add_app_to_list(struct ust_app *lta) { - cds_list_add(<a->list, <t_traceable_app_list.head); - ltt_traceable_app_list.count++; + cds_list_add(<a->list, &ust_app_list.head); + ust_app_list.count++; } /* * Delete a traceable application structure from the global list. */ -static void del_traceable_app(struct ltt_traceable_app *lta) +static void del_app_from_list(struct ust_app *lta) { struct ltt_ust_channel *chan; cds_list_del(<a->list); /* Sanity check */ - if (ltt_traceable_app_list.count > 0) { - ltt_traceable_app_list.count--; + if (ust_app_list.count > 0) { + ust_app_list.count--; } cds_list_for_each_entry(chan, <a->channels.head, list) { @@ -63,56 +63,56 @@ static void del_traceable_app(struct ltt_traceable_app *lta) } /* - * Return pointer to traceable apps list. + * Iterate over the traceable apps list and return a pointer or NULL if not + * found. */ -struct ltt_traceable_app_list *get_traceable_apps_list(void) +static struct ust_app *find_app_by_sock(int sock) { - return <t_traceable_app_list; + struct ust_app *iter; + + cds_list_for_each_entry(iter, &ust_app_list.head, list) { + if (iter->sock == sock) { + /* Found */ + return iter; + } + } + + return NULL; } /* - * Acquire traceable apps list lock. + * Return pointer to traceable apps list. */ -void lock_apps_list(void) +struct ust_app_list *ust_app_get_list(void) { - pthread_mutex_lock(<t_traceable_app_list.lock); + return &ust_app_list; } /* - * Release traceable apps list lock. + * Acquire traceable apps list lock. */ -void unlock_apps_list(void) +void ust_app_lock_list(void) { - pthread_mutex_unlock(<t_traceable_app_list.lock); + pthread_mutex_lock(&ust_app_list.lock); } /* - * Iterate over the traceable apps list and return a pointer or NULL if not - * found. + * Release traceable apps list lock. */ -static struct ltt_traceable_app *find_app_by_sock(int sock) +void ust_app_unlock_list(void) { - struct ltt_traceable_app *iter; - - cds_list_for_each_entry(iter, <t_traceable_app_list.head, list) { - if (iter->sock == sock) { - /* Found */ - return iter; - } - } - - return NULL; + pthread_mutex_unlock(&ust_app_list.lock); } /* * Iterate over the traceable apps list and return a pointer or NULL if not * found. */ -struct ltt_traceable_app *traceable_app_get_by_pid(pid_t pid) +struct ust_app *ust_app_get_by_pid(pid_t pid) { - struct ltt_traceable_app *iter; + struct ust_app *iter; - cds_list_for_each_entry(iter, <t_traceable_app_list.head, list) { + cds_list_for_each_entry(iter, &ust_app_list.head, list) { if (iter->pid == pid) { /* Found */ DBG2("Found traceable app by pid %d", pid); @@ -126,16 +126,16 @@ struct ltt_traceable_app *traceable_app_get_by_pid(pid_t pid) } /* - * Using pid and uid (of the app), allocate a new ltt_traceable_app struct and + * Using pid and uid (of the app), allocate a new ust_app struct and * add it to the global traceable app list. * * On success, return 0, else return malloc ENOMEM. */ -int register_traceable_app(struct ust_register_msg *msg, int sock) +int ust_app_register(struct ust_register_msg *msg, int sock) { - struct ltt_traceable_app *lta; + struct ust_app *lta; - lta = malloc(sizeof(struct ltt_traceable_app)); + lta = malloc(sizeof(struct ust_app)); if (lta == NULL) { perror("malloc"); return -ENOMEM; @@ -152,9 +152,9 @@ int register_traceable_app(struct ust_register_msg *msg, int sock) lta->name[16] = '\0'; CDS_INIT_LIST_HEAD(<a->channels.head); - lock_apps_list(); - add_traceable_app(lta); - unlock_apps_list(); + ust_app_lock_list(); + add_app_to_list(lta); + ust_app_unlock_list(); DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s" " (version %d.%d)", lta->pid, lta->ppid, lta->uid, lta->gid, @@ -169,31 +169,31 @@ int register_traceable_app(struct ust_register_msg *msg, int sock) * * The socket is already closed at this point so no close to sock. */ -void unregister_traceable_app(int sock) +void ust_app_unregister(int sock) { - struct ltt_traceable_app *lta; + struct ust_app *lta; - lock_apps_list(); + ust_app_lock_list(); lta = find_app_by_sock(sock); if (lta) { DBG("PID %d unregistered with sock %d", lta->pid, sock); - del_traceable_app(lta); + del_app_from_list(lta); close(lta->sock); free(lta); } - unlock_apps_list(); + ust_app_unlock_list(); } /* * Return traceable_app_count */ -unsigned int get_app_count(void) +unsigned int ust_app_list_count(void) { unsigned int count; - lock_apps_list(); - count = ltt_traceable_app_list.count; - unlock_apps_list(); + ust_app_lock_list(); + count = ust_app_list.count; + ust_app_unlock_list(); return count; } @@ -201,16 +201,16 @@ unsigned int get_app_count(void) /* * Free and clean all traceable apps of the global list. */ -void clean_traceable_apps_list(void) +void ust_app_clean_list(void) { - struct ltt_traceable_app *iter, *tmp; + struct ust_app *iter, *tmp; /* * Don't acquire list lock here. This function should be called from * cleanup() functions meaning that the program will exit. */ - cds_list_for_each_entry_safe(iter, tmp, <t_traceable_app_list.head, list) { - del_traceable_app(iter); + cds_list_for_each_entry_safe(iter, tmp, &ust_app_list.head, list) { + del_app_from_list(iter); close(iter->sock); free(iter); } diff --git a/ltt-sessiond/traceable-app.h b/ltt-sessiond/ust-app.h similarity index 84% rename from ltt-sessiond/traceable-app.h rename to ltt-sessiond/ust-app.h index 39f97f2a2..f2d3d261c 100644 --- a/ltt-sessiond/traceable-app.h +++ b/ltt-sessiond/ust-app.h @@ -40,7 +40,7 @@ struct ust_register_msg { /* * Traceable application list. */ -struct ltt_traceable_app_list { +struct ust_app_list{ /* * This lock protects any read/write access to the list and count (which is * basically the list size). All public functions in traceable-app.c @@ -63,7 +63,7 @@ struct ltt_traceable_app_list { /* Registered traceable applications. Libust registers to the session daemon * and a linked list is kept of all running traceable app. */ -struct ltt_traceable_app { +struct ust_app { int sock; /* Communication socket with the application */ pid_t pid; pid_t ppid; @@ -76,15 +76,14 @@ struct ltt_traceable_app { struct cds_list_head list; }; -int register_traceable_app(struct ust_register_msg *msg, int sock); -void unregister_traceable_app(int sock); -unsigned int get_app_count(void); +int ust_app_register(struct ust_register_msg *msg, int sock); +void ust_app_unregister(int sock); +unsigned int ust_app_list_count(void); -void lock_apps_list(void); -void unlock_apps_list(void); -void clean_traceable_apps_list(void); -struct ltt_traceable_app_list *get_traceable_apps_list(void); - -struct ltt_traceable_app *traceable_app_get_by_pid(pid_t pid); +void ust_app_lock_list(void); +void ust_app_unlock_list(void); +void ust_app_clean_list(void); +struct ust_app_list *ust_app_get_list(void); +struct ust_app *ust_app_get_by_pid(pid_t pid); #endif /* _TRACEABLE_APP_H */ -- 2.34.1