X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=850bac508fb4972793c5991050d5c39f56a3f9fd;hb=2cbf8fedb374f6a029811d685eca59b3c435f47e;hp=903dfd36defb5f8591aa7532f7b0a202d8be863d;hpb=af706bb7e9bda5d6b95414165681abe422f1541e;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 903dfd36d..850bac508 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -2160,6 +2160,7 @@ void cmd_list_lttng_sessions(struct lttng_session *sessions, uid_t uid, strncpy(sessions[i].name, session->name, NAME_MAX); sessions[i].name[NAME_MAX - 1] = '\0'; sessions[i].enabled = session->enabled; + sessions[i].snapshot_mode = session->snapshot_mode; i++; } } @@ -2441,7 +2442,8 @@ error: * Return 0 on success or else a negative value. */ static int record_kernel_snapshot(struct ltt_kernel_session *ksess, - struct snapshot_output *output, struct ltt_session *session, int wait) + struct snapshot_output *output, struct ltt_session *session, + int wait, int nb_streams) { int ret; @@ -2471,8 +2473,12 @@ static int record_kernel_snapshot(struct ltt_kernel_session *ksess, goto error_snapshot; } - ret = kernel_snapshot_record(ksess, output, wait); + ret = kernel_snapshot_record(ksess, output, wait, nb_streams); if (ret < 0) { + ret = -LTTNG_ERR_SNAPSHOT_FAIL; + if (ret == -EINVAL) { + ret = -LTTNG_ERR_INVALID; + } goto error_snapshot; } @@ -2489,7 +2495,8 @@ error: * Return 0 on success or else a negative value. */ static int record_ust_snapshot(struct ltt_ust_session *usess, - struct snapshot_output *output, struct ltt_session *session, int wait) + struct snapshot_output *output, struct ltt_session *session, + int wait, int nb_streams) { int ret; @@ -2519,8 +2526,12 @@ static int record_ust_snapshot(struct ltt_ust_session *usess, goto error_snapshot; } - ret = ust_app_snapshot_record(usess, output, wait); + ret = ust_app_snapshot_record(usess, output, wait, nb_streams); if (ret < 0) { + ret = -LTTNG_ERR_SNAPSHOT_FAIL; + if (ret == -EINVAL) { + ret = -LTTNG_ERR_INVALID; + } goto error_snapshot; } @@ -2531,6 +2542,29 @@ error: return ret; } +/* + * Returns the total number of streams for a session or a negative value + * on error. + */ +static unsigned int get_total_nb_stream(struct ltt_session *session) +{ + unsigned int total_streams = 0; + + if (session->kernel_session) { + struct ltt_kernel_session *ksess = session->kernel_session; + + total_streams += ksess->stream_count_global; + } + + if (session->ust_session) { + struct ltt_ust_session *usess = session->ust_session; + + total_streams += ust_app_get_nb_stream(usess); + } + + return total_streams; +} + /* * Command LTTNG_SNAPSHOT_RECORD from lib lttng ctl. * @@ -2543,7 +2577,9 @@ int cmd_snapshot_record(struct ltt_session *session, struct lttng_snapshot_output *output, int wait) { int ret = LTTNG_OK; - struct snapshot_output *tmp_sout = NULL; + unsigned int use_tmp_output = 0; + struct snapshot_output tmp_output; + unsigned int nb_streams; assert(session); @@ -2566,15 +2602,9 @@ int cmd_snapshot_record(struct ltt_session *session, /* Use temporary output for the session. */ if (output && *output->ctrl_url != '\0') { - tmp_sout = snapshot_output_alloc(); - if (!tmp_sout) { - ret = LTTNG_ERR_NOMEM; - goto error; - } - ret = snapshot_output_init(output->max_size, output->name, output->ctrl_url, output->data_url, session->consumer, - tmp_sout, NULL); + &tmp_output, NULL); if (ret < 0) { if (ret == -ENOMEM) { ret = LTTNG_ERR_NOMEM; @@ -2583,13 +2613,21 @@ int cmd_snapshot_record(struct ltt_session *session, } goto error; } + use_tmp_output = 1; } + /* + * Get the total number of stream of that session which is used by the + * maximum size of the snapshot feature. + */ + nb_streams = get_total_nb_stream(session); + if (session->kernel_session) { struct ltt_kernel_session *ksess = session->kernel_session; - if (tmp_sout) { - ret = record_kernel_snapshot(ksess, tmp_sout, session, wait); + if (use_tmp_output) { + ret = record_kernel_snapshot(ksess, &tmp_output, session, + wait, nb_streams); if (ret < 0) { goto error; } @@ -2600,7 +2638,26 @@ int cmd_snapshot_record(struct ltt_session *session, rcu_read_lock(); cds_lfht_for_each_entry(session->snapshot.output_ht->ht, &iter.iter, sout, node.node) { - ret = record_kernel_snapshot(ksess, sout, session, wait); + /* + * Make a local copy of the output and assign the possible + * temporary value given by the caller. + */ + memset(&tmp_output, 0, sizeof(tmp_output)); + memcpy(&tmp_output, sout, sizeof(tmp_output)); + + /* Use temporary max size. */ + if (output->max_size != (uint64_t) -1ULL) { + tmp_output.max_size = output->max_size; + } + + /* Use temporary name. */ + if (*output->name != '\0') { + strncpy(tmp_output.name, output->name, + sizeof(tmp_output.name)); + } + + ret = record_kernel_snapshot(ksess, &tmp_output, + session, wait, nb_streams); if (ret < 0) { rcu_read_unlock(); goto error; @@ -2613,8 +2670,9 @@ int cmd_snapshot_record(struct ltt_session *session, if (session->ust_session) { struct ltt_ust_session *usess = session->ust_session; - if (tmp_sout) { - ret = record_ust_snapshot(usess, tmp_sout, session, wait); + if (use_tmp_output) { + ret = record_ust_snapshot(usess, &tmp_output, session, + wait, nb_streams); if (ret < 0) { goto error; } @@ -2625,7 +2683,28 @@ int cmd_snapshot_record(struct ltt_session *session, rcu_read_lock(); cds_lfht_for_each_entry(session->snapshot.output_ht->ht, &iter.iter, sout, node.node) { - ret = record_ust_snapshot(usess, sout, session, wait); + /* + * Make a local copy of the output and assign the possible + * temporary value given by the caller. + */ + memset(&tmp_output, 0, sizeof(tmp_output)); + memcpy(&tmp_output, sout, sizeof(tmp_output)); + + fprintf(stderr, "Name: %s\n", output->name); + + /* Use temporary max size. */ + if (output->max_size != (uint64_t) -1ULL) { + tmp_output.max_size = output->max_size; + } + + /* Use temporary name. */ + if (*output->name != '\0') { + strncpy(tmp_output.name, output->name, + sizeof(tmp_output.name)); + } + + ret = record_ust_snapshot(usess, &tmp_output, session, + wait, nb_streams); if (ret < 0) { rcu_read_unlock(); goto error; @@ -2636,9 +2715,6 @@ int cmd_snapshot_record(struct ltt_session *session, } error: - if (tmp_sout) { - snapshot_output_destroy(tmp_sout); - } return ret; }