From: David Goulet Date: Tue, 24 May 2011 17:12:28 +0000 (-0400) Subject: Add kernel open metadata support to session daemon X-Git-Tag: v2.0-pre1~124 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=aaf267147df386f0438de88782296077ff5b5861;p=lttng-tools.git Add kernel open metadata support to session daemon Signed-off-by: David Goulet --- diff --git a/liblttsessiondcomm/liblttsessiondcomm.c b/liblttsessiondcomm/liblttsessiondcomm.c index 5cd0f1203..ddee7bcae 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.c +++ b/liblttsessiondcomm/liblttsessiondcomm.c @@ -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", diff --git a/liblttsessiondcomm/liblttsessiondcomm.h b/liblttsessiondcomm/liblttsessiondcomm.h index 879982101..9a31aacce 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.h +++ b/liblttsessiondcomm/liblttsessiondcomm.h @@ -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 */ diff --git a/ltt-sessiond/kernel-ctl.c b/ltt-sessiond/kernel-ctl.c index 02e87e340..969acfbf4 100644 --- a/ltt-sessiond/kernel-ctl.c +++ b/ltt-sessiond/kernel-ctl.c @@ -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; +} diff --git a/ltt-sessiond/kernel-ctl.h b/ltt-sessiond/kernel-ctl.h index b8f41e7d9..a1ab0c25c 100644 --- a/ltt-sessiond/kernel-ctl.h +++ b/ltt-sessiond/kernel-ctl.h @@ -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 */ diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 88a43d968..9b76a56ad 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -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); } /* diff --git a/ltt-sessiond/trace.h b/ltt-sessiond/trace.h index 5b4ff68ff..910d38f04 100644 --- a/ltt-sessiond/trace.h +++ b/ltt-sessiond/trace.h @@ -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; };