Add kernel open metadata support to session daemon
authorDavid Goulet <david.goulet@polymtl.ca>
Tue, 24 May 2011 17:12:28 +0000 (13:12 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Tue, 24 May 2011 17:12:28 +0000 (13:12 -0400)
Signed-off-by: David Goulet <david.goulet@polymtl.ca>
liblttsessiondcomm/liblttsessiondcomm.c
liblttsessiondcomm/liblttsessiondcomm.h
ltt-sessiond/kernel-ctl.c
ltt-sessiond/kernel-ctl.h
ltt-sessiond/main.c
ltt-sessiond/trace.h

index 5cd0f1203d594a10e565dc8e95143b225df17b64..ddee7bcae512bc4a116506c3bc054a378117c0fc 100644 (file)
@@ -53,6 +53,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_FAIL) ] = "Kernel create channel failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_ENABLE_FAIL) ] = "Enable kernel event failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_DISABLE_FAIL) ] = "Disable kernel event failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_META_FAIL) ] = "Opening metadata failed",
        [ LTTCOMM_ERR_INDEX(KCONSUMERD_COMMAND_SOCK_READY) ] = "Kconsumerd command socket ready",
        [ LTTCOMM_ERR_INDEX(KCONSUMERD_SUCCESS_RECV_FD) ] = "Kconsumerd success on receiving fds",
        [ LTTCOMM_ERR_INDEX(KCONSUMERD_ERROR_RECV_FD) ] = "Kconsumerd error on receiving fds",
index 879982101dd901838065cfb9205a7353cf5e035b..9a31aacce04e7e72a8e2445c8c3e91eb01936ac9 100644 (file)
@@ -52,6 +52,7 @@ enum lttcomm_sessiond_command {
        KERNEL_CREATE_SESSION,
        KERNEL_DISABLE_EVENT,
        KERNEL_ENABLE_EVENT,
+       KERNEL_OPEN_METADATA,
        KERNEL_START_TRACE,
        KERNEL_STOP_TRACE,
        LTTNG_CREATE_SESSION,
@@ -105,6 +106,7 @@ enum lttcomm_return_code {
        LTTCOMM_KERN_CHAN_FAIL,                 /* Kernel create channel failed */
        LTTCOMM_KERN_ENABLE_FAIL,               /* Kernel enable event failed */
        LTTCOMM_KERN_DISABLE_FAIL,              /* Kernel disable event failed */
+       LTTCOMM_KERN_META_FAIL,                 /* Kernel open metadata failed */
        KCONSUMERD_COMMAND_SOCK_READY,  /* when kconsumerd command socket ready */
        KCONSUMERD_SUCCESS_RECV_FD,             /* success on receiving fds */
        KCONSUMERD_ERROR_RECV_FD,               /* error on receiving fds */
index 02e87e3401b88d1e6f81b999dd71e6f81a2d4438..969acfbf437deb51de608fcba7d991e9ba8353b6 100644 (file)
@@ -88,6 +88,7 @@ int kernel_create_channel(struct command_ctx *cmd_ctx)
 
        ret = kernctl_create_channel(cmd_ctx->session->kernel_session->fd, chan);
        if (ret < 0) {
+               perror("ioctl create channel");
                goto error;
        }
 
@@ -141,3 +142,44 @@ int kernel_enable_event(struct ltt_kernel_channel *channel, char *name)
 error:
        return ret;
 }
+
+/*
+ *  kernel_open_metadata
+ *
+ *  Open metadata stream.
+ */
+int kernel_open_metadata(struct ltt_kernel_session *session)
+{
+       int ret;
+       struct ltt_kernel_metadata *lkm;
+       struct lttng_kernel_channel *conf;
+
+       lkm = malloc(sizeof(struct ltt_kernel_metadata));
+       conf = malloc(sizeof(struct lttng_kernel_channel));
+
+       if (lkm == NULL || conf == NULL) {
+               perror("kernel open metadata malloc");
+               ret = -errno;
+               goto error;
+       }
+
+       conf->overwrite = DEFAULT_KERNEL_OVERWRITE;
+       conf->subbuf_size = DEFAULT_KERNEL_SUBBUF_SIZE;
+       conf->num_subbuf = DEFAULT_KERNEL_SUBBUF_NUM;
+       conf->switch_timer_interval = DEFAULT_KERNEL_SWITCH_TIMER;
+       conf->read_timer_interval = DEFAULT_KERNEL_READ_TIMER;
+
+       ret = kernctl_open_metadata(session->fd, conf);
+       if (ret < 0) {
+               goto error;
+       }
+
+       session->metadata = lkm;
+       session->metadata->fd = ret;
+       session->metadata->conf = conf;
+
+       return 0;
+
+error:
+       return ret;
+}
index b8f41e7d98bb08af0ea9cd8ccab5cdf0e0a37d05..a1ab0c25cccbf5b052a421cf1f301befad442170 100644 (file)
@@ -24,5 +24,6 @@
 int kernel_create_session(struct command_ctx *cmd_ctx, int tracer_fd);
 int kernel_create_channel(struct command_ctx *cmd_ctx);
 int kernel_enable_event(struct ltt_kernel_channel *channel, char *name);
+int kernel_open_metadata(struct ltt_kernel_session *session);
 
 #endif /* _LTT_KERNEL_CTL_H */
index 88a43d9683975d5c4657e977b16662a869177699..9b76a56adce2486efca5aecd66f29b2aca1343e3 100644 (file)
@@ -461,6 +461,13 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        switch (cmd_ctx->lsm->cmd_type) {
        case KERNEL_CREATE_SESSION:
        case KERNEL_CREATE_CHANNEL:
+       case KERNEL_DISABLE_EVENT:
+       case KERNEL_ENABLE_EVENT:
+       case KERNEL_OPEN_METADATA:
+       case KERNEL_START_TRACE:
+       case KERNEL_STOP_TRACE:
+               /* TODO: reconnect to kernel tracer to check if
+                * it's loadded */
                if (kernel_tracer_fd == 0) {
                        ret = LTTCOMM_KERN_NA;
                        goto error;
@@ -535,6 +542,25 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                ret = LTTCOMM_OK;
                break;
        }
+       case KERNEL_OPEN_METADATA:
+       {
+               /* Setup lttng message with no payload */
+               ret = setup_lttng_msg(cmd_ctx, 0);
+               if (ret < 0) {
+                       goto setup_error;
+               }
+
+               DBG("Open kernel metadata");
+
+               ret = kernel_open_metadata(cmd_ctx->session->kernel_session);
+               if (ret < 0) {
+                       ret = LTTCOMM_KERN_META_FAIL;
+                       goto error;
+               }
+
+               ret = LTTCOMM_OK;
+               break;
+       }
        case LTTNG_CREATE_SESSION:
        {
                /* Setup lttng message with no payload */
@@ -1120,6 +1146,9 @@ static void cleanup()
        if (ret < 0) {
                ERR("Unable to clean " LTTNG_RUNDIR);
        }
+
+       // TODO Clean kernel trace fds
+       close(kernel_tracer_fd);
 }
 
 /*
index 5b4ff68ff3a0c2718d90c5f5c8f377551e81e052..910d38f041d55649742adf97588ae0e2b514d075 100644 (file)
@@ -42,9 +42,16 @@ struct ltt_kernel_channel {
        struct ltt_kernel_event_list events_list;
 };
 
+/* Metadata */
+struct ltt_kernel_metadata {
+       int fd;
+       struct lttng_kernel_channel *conf;
+};
+
 /* Kernel session */
 struct ltt_kernel_session {
        int fd;
+       struct ltt_kernel_metadata *metadata;
        struct ltt_kernel_channel *channel;
 };
 
This page took 0.039084 seconds and 4 git commands to generate.