centralize sessiond config option handling
[lttng-tools.git] / src / bin / lttng-sessiond / save.c
index 3df1f2828f17d275efcc69930030d1bd4cd25936..3c6b5b8a01931540cbd050a9600f969e0076b471 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <common/defaults.h>
 #include <common/error.h>
-#include <common/config/config.h>
+#include <common/config/session-config.h>
 #include <common/utils.h>
 #include <common/runas.h>
 #include <lttng/save-internal.h>
@@ -104,6 +104,26 @@ int save_kernel_channel_attributes(struct config_writer *writer,
        if (ret) {
                goto end;
        }
+
+       if (attr->extended.ptr) {
+               struct lttng_channel_extended *ext = NULL;
+
+               ext = (struct lttng_channel_extended *) attr->extended.ptr;
+               ret = config_writer_write_element_unsigned_int(writer,
+                               config_element_monitor_timer_interval,
+                               ext->monitor_timer_interval);
+               if (ret) {
+                       goto end;
+               }
+
+               ret = config_writer_write_element_signed_int(writer,
+                               config_element_blocking_timeout,
+                               ext->blocking_timeout);
+               if (ret) {
+                       goto end;
+               }
+       }
+
 end:
        return ret ? LTTNG_ERR_SAVE_IO_FAIL : 0;
 }
@@ -113,6 +133,7 @@ int save_ust_channel_attributes(struct config_writer *writer,
        struct lttng_ust_channel_attr *attr)
 {
        int ret;
+       struct ltt_ust_channel *channel = NULL;
 
        ret = config_writer_write_element_string(writer,
                config_element_overwrite_mode,
@@ -156,6 +177,26 @@ int save_ust_channel_attributes(struct config_writer *writer,
        if (ret) {
                goto end;
        }
+
+       ret = config_writer_write_element_signed_int(writer,
+                       config_element_blocking_timeout,
+                       attr->u.s.blocking_timeout);
+       if (ret) {
+               goto end;
+       }
+
+       /*
+        * Fetch the monitor timer which is located in the parent of
+        * lttng_ust_channel_attr
+        */
+       channel = caa_container_of(attr, struct ltt_ust_channel, attr);
+       ret = config_writer_write_element_unsigned_int(writer,
+               config_element_monitor_timer_interval,
+               channel->monitor_timer_interval);
+       if (ret) {
+               goto end;
+       }
+
 end:
        return ret ? LTTNG_ERR_SAVE_IO_FAIL : 0;
 }
@@ -232,6 +273,18 @@ const char *get_kernel_context_type_string(
        case LTTNG_KERNEL_CONTEXT_HOSTNAME:
                context_type_string = config_event_context_hostname;
                break;
+       case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE:
+               context_type_string = config_event_context_interruptible;
+               break;
+       case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE:
+               context_type_string = config_event_context_preemptible;
+               break;
+       case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE:
+               context_type_string = config_event_context_need_reschedule;
+               break;
+       case LTTNG_KERNEL_CONTEXT_MIGRATABLE:
+               context_type_string = config_event_context_migratable;
+               break;
        default:
                context_type_string = NULL;
        }
@@ -261,6 +314,9 @@ const char *get_ust_context_type_string(
        case LTTNG_UST_CONTEXT_PTHREAD_ID:
                context_type_string = config_event_context_pthread_id;
                break;
+       case LTTNG_UST_CONTEXT_APP_CONTEXT:
+               context_type_string = config_event_context_app;
+               break;
        case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
                /*
                 * Error, should not be stored in the XML, perf contexts
@@ -499,57 +555,6 @@ end:
        return ret;
 }
 
-static
-int save_kernel_syscall(struct config_writer *writer,
-               struct ltt_kernel_channel *kchan)
-{
-       int ret, i;
-       ssize_t count;
-       struct lttng_event *events = NULL;
-
-       assert(writer);
-       assert(kchan);
-
-       count = syscall_list_channel(kchan, &events, 0);
-       if (!count) {
-               /* No syscalls, just gracefully return. */
-               ret = 0;
-               goto end;
-       }
-
-       for (i = 0; i < count; i++) {
-               struct ltt_kernel_event *kevent;
-
-               /* Create a temporary kevent in order to save it. */
-               /*
-                * TODO: struct lttng_event does not really work for a filter,
-                * but unfortunately, it is exposed as external API (and used as
-                * internal representation. Using NULL meanwhile.
-                */
-               kevent = trace_kernel_create_event(&events[i],
-                       NULL, NULL);
-               if (!kevent) {
-                       ret = -ENOMEM;
-                       goto end;
-               }
-               /* Init list in order so the destroy call can del the node. */
-               CDS_INIT_LIST_HEAD(&kevent->list);
-
-               ret = save_kernel_event(writer, kevent);
-               trace_kernel_destroy_event(kevent);
-               if (ret) {
-                       goto end;
-               }
-       }
-
-       /* Everything went well */
-       ret = 0;
-
-end:
-       free(events);
-       return ret;
-}
-
 static
 int save_kernel_events(struct config_writer *writer,
        struct ltt_kernel_channel *kchan)
@@ -570,12 +575,6 @@ int save_kernel_events(struct config_writer *writer,
                }
        }
 
-       /* Save syscalls if any. */
-       ret = save_kernel_syscall(writer, kchan);
-       if (ret) {
-               goto end;
-       }
-
        /* /events */
        ret = config_writer_close_element(writer);
        if (ret) {
@@ -674,7 +673,8 @@ int save_ust_event(struct config_writer *writer,
                for (i = 0; i < event->exclusion->count; i++) {
                        ret = config_writer_write_element_string(writer,
                                config_element_exclusion,
-                               &event->exclusion->names[0][i]);
+                               LTTNG_EVENT_EXCLUSION_NAME_AT(
+                                       event->exclusion, i));
                        if (ret) {
                                ret = LTTNG_ERR_SAVE_IO_FAIL;
                                goto end;
@@ -749,7 +749,11 @@ int init_ust_event_from_agent_event(struct ltt_ust_event *ust_event,
 
        ust_event->enabled = agent_event->enabled;
        ust_event->attr.instrumentation = LTTNG_UST_TRACEPOINT;
-       strncpy(ust_event->attr.name, agent_event->name, LTTNG_SYMBOL_NAME_LEN);
+       if (lttng_strncpy(ust_event->attr.name, agent_event->name,
+                       LTTNG_SYMBOL_NAME_LEN)) {
+               ret = -1;
+               goto end;
+       }
        switch (agent_event->loglevel_type) {
        case LTTNG_EVENT_LOGLEVEL_ALL:
                ust_loglevel_type = LTTNG_UST_LOGLEVEL_ALL;
@@ -844,7 +848,8 @@ int save_kernel_context(struct config_writer *writer,
        }
 
        if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER) {
-               ret = config_writer_open_element(writer, config_element_perf);
+               ret = config_writer_open_element(writer,
+                               config_element_context_perf);
                if (ret) {
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
@@ -941,6 +946,124 @@ end:
        return ret;
 }
 
+static
+int save_ust_context_perf_thread_counter(struct config_writer *writer,
+               struct ltt_ust_context *ctx)
+{
+       int ret;
+
+       assert(writer);
+       assert(ctx);
+
+       /* Perf contexts are saved as event_perf_context_type */
+       ret = config_writer_open_element(writer, config_element_context_perf);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_unsigned_int(writer,
+                       config_element_type, ctx->ctx.u.perf_counter.type);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_unsigned_int(writer,
+                       config_element_config, ctx->ctx.u.perf_counter.config);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_string(writer, config_element_name,
+                       ctx->ctx.u.perf_counter.name);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       /* /perf */
+       ret = config_writer_close_element(writer);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+end:
+       return ret;
+}
+
+static
+int save_ust_context_app_ctx(struct config_writer *writer,
+               struct ltt_ust_context *ctx)
+{
+       int ret;
+
+       assert(writer);
+       assert(ctx);
+
+       /* Application contexts are saved as application_context_type */
+       ret = config_writer_open_element(writer, config_element_context_app);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_string(writer,
+                       config_element_context_app_provider_name,
+                       ctx->ctx.u.app_ctx.provider_name);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_string(writer,
+                       config_element_context_app_ctx_name,
+                       ctx->ctx.u.app_ctx.ctx_name);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       /* /app */
+       ret = config_writer_close_element(writer);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+end:
+       return ret;
+}
+
+static
+int save_ust_context_generic(struct config_writer *writer,
+               struct ltt_ust_context *ctx)
+{
+       int ret;
+       const char *context_type_string;
+
+       assert(writer);
+       assert(ctx);
+
+       /* Save context as event_context_type_type */
+       context_type_string = get_ust_context_type_string(
+                       ctx->ctx.ctx);
+       if (!context_type_string) {
+               ERR("Unsupported UST context type.");
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+
+       ret = config_writer_write_element_string(writer,
+                       config_element_type, context_type_string);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
+       }
+end:
+       return ret;
+}
+
 static
 int save_ust_context(struct config_writer *writer,
        struct cds_list_head *ctx_list)
@@ -958,9 +1081,6 @@ int save_ust_context(struct config_writer *writer,
        }
 
        cds_list_for_each_entry(ctx, ctx_list, list) {
-               const char *context_type_string;
-
-
                ret = config_writer_open_element(writer,
                        config_element_context);
                if (ret) {
@@ -968,61 +1088,19 @@ int save_ust_context(struct config_writer *writer,
                        goto end;
                }
 
-               if (ctx->ctx.ctx == LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER) {
-                       /* Perf contexts are saved as event_perf_context_type */
-                       ret = config_writer_open_element(writer,
-                               config_element_perf);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       ret = config_writer_write_element_unsigned_int(writer,
-                               config_element_type,
-                               ctx->ctx.u.perf_counter.type);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       ret = config_writer_write_element_unsigned_int(writer,
-                               config_element_config,
-                               ctx->ctx.u.perf_counter.config);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       ret = config_writer_write_element_string(writer,
-                               config_element_name,
-                               ctx->ctx.u.perf_counter.name);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       /* /perf */
-                       ret = config_writer_close_element(writer);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-               } else {
-                       /* Save context as event_context_type_type */
-                       context_type_string = get_ust_context_type_string(
-                               ctx->ctx.ctx);
-                       if (!context_type_string) {
-                               ERR("Unsupported UST context type.")
-                                       ret = LTTNG_ERR_INVALID;
-                               goto end;
-                       }
-
-                       ret = config_writer_write_element_string(writer,
-                               config_element_type, context_type_string);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
+               switch (ctx->ctx.ctx) {
+               case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
+                       ret = save_ust_context_perf_thread_counter(writer, ctx);
+                       break;
+               case LTTNG_UST_CONTEXT_APP_CONTEXT:
+                       ret = save_ust_context_app_ctx(writer, ctx);
+                       break;
+               default:
+                       /* Save generic context. */
+                       ret = save_ust_context_generic(writer, ctx);
+               }
+               if (ret) {
+                       goto end;
                }
 
                /* /context */
@@ -2016,6 +2094,13 @@ end:
                }
        }
 
+       if (file_opened) {
+               ret = close(fd);
+               if (ret) {
+                       PERROR("Closing XML session configuration");
+               }
+       }
+
        return ret;
 }
 
This page took 0.029554 seconds and 5 git commands to generate.