#include <common/kernel-ctl/kernel-ctl.h>
#include <common/dynamic-buffer.h>
#include <common/buffer-view.h>
+#include <common/trace-chunk.h>
#include <lttng/trigger/trigger-internal.h>
#include <lttng/condition/condition.h>
#include <lttng/action/action.h>
struct lttng_uri *relayd_uri,
struct consumer_output *consumer,
struct consumer_socket *consumer_sock,
- char *session_name, char *hostname, int session_live_timer)
+ const char *session_name, const char *hostname,
+ int session_live_timer)
{
int ret;
struct lttcomm_relayd_sock *rsock = NULL;
static enum lttng_error_code send_consumer_relayd_sockets(
enum lttng_domain_type domain,
unsigned int session_id, struct consumer_output *consumer,
- struct consumer_socket *sock, char *session_name,
- char *hostname, int session_live_timer)
+ struct consumer_socket *sock, const char *session_name,
+ const char *hostname, int session_live_timer)
{
enum lttng_error_code status = LTTNG_OK;
return ret;
}
-static
-int session_mkdir(const struct ltt_session *session)
-{
- int ret;
- struct consumer_output *output;
- uid_t uid;
- gid_t gid;
-
- /*
- * Unsupported feature in lttng-relayd before 2.11, not an error since it
- * is only needed for session rotation and the user will get an error
- * on rotate.
- */
- if (session->consumer->type == CONSUMER_DST_NET &&
- session->consumer->relay_major_version == 2 &&
- session->consumer->relay_minor_version < 11) {
- ret = 0;
- goto end;
- }
-
- if (session->kernel_session) {
- output = session->kernel_session->consumer;
- uid = session->kernel_session->uid;
- gid = session->kernel_session->gid;
- ret = domain_mkdir(output, session, uid, gid);
- if (ret) {
- ERR("Mkdir kernel");
- goto end;
- }
- }
-
- if (session->ust_session) {
- output = session->ust_session->consumer;
- uid = session->ust_session->uid;
- gid = session->ust_session->gid;
- ret = domain_mkdir(output, session, uid, gid);
- if (ret) {
- ERR("Mkdir UST");
- goto end;
- }
- }
-
- ret = 0;
-
-end:
- return ret;
-}
-
/*
* Command LTTNG_START_TRACE processed by the client thread.
*
*/
int cmd_start_trace(struct ltt_session *session)
{
- int ret;
+ enum lttng_error_code ret;
unsigned long nb_chan = 0;
struct ltt_kernel_session *ksession;
struct ltt_ust_session *usess;
goto error;
}
- /*
- * Record the timestamp of the first time the session is started for
- * an eventual session rotation call.
- */
- if (!session->has_been_started) {
- session->current_chunk_start_ts = time(NULL);
- if (session->current_chunk_start_ts == (time_t) -1) {
- PERROR("Failed to retrieve the \"%s\" session's start time",
- session->name);
- ret = LTTNG_ERR_FATAL;
+ if (!session->has_been_started && session->output_traces) {
+ ret = session_switch_trace_chunk(session, NULL, NULL);
+ if (ret != LTTNG_OK) {
goto error;
}
- if (!session->snapshot_mode && session->output_traces) {
- ret = session_mkdir(session);
- if (ret) {
- ERR("Failed to create the session directories");
- ret = LTTNG_ERR_CREATE_DIR_FAIL;
- goto error;
- }
- }
}
/* Kernel tracing */
/* Flag session that trace should start automatically */
if (usess) {
- ret = ust_app_start_trace_all(usess);
- if (ret < 0) {
+ int int_ret = ust_app_start_trace_all(usess);
+
+ if (int_ret < 0) {
ret = LTTNG_ERR_UST_START_FAIL;
goto error;
}
session->rotated_after_last_stop = false;
if (session->rotate_timer_period) {
- ret = timer_session_rotation_schedule_timer_start(session,
- session->rotate_timer_period);
- if (ret < 0) {
+ int int_ret = timer_session_rotation_schedule_timer_start(
+ session, session->rotate_timer_period);
+
+ if (int_ret < 0) {
ERR("Failed to enable rotate timer");
ret = LTTNG_ERR_UNK;
goto error;
*/
static enum lttng_error_code set_relayd_for_snapshot(
struct consumer_output *consumer,
- struct snapshot_output *snap_output,
- struct ltt_session *session)
+ const struct snapshot_output *snap_output,
+ const struct ltt_session *session)
{
enum lttng_error_code status = LTTNG_OK;
struct lttng_ht_iter iter;
*
* Return LTTNG_OK on success or a LTTNG_ERR code.
*/
-static enum lttng_error_code record_kernel_snapshot(struct ltt_kernel_session *ksess,
- struct snapshot_output *output, struct ltt_session *session,
+static enum lttng_error_code record_kernel_snapshot(
+ struct ltt_kernel_session *ksess,
+ const struct snapshot_output *output,
+ const struct ltt_session *session,
int wait, uint64_t nb_packets_per_stream)
{
int ret;
* Returns LTTNG_OK on success or a LTTNG_ERR error code.
*/
static enum lttng_error_code record_ust_snapshot(struct ltt_ust_session *usess,
- struct snapshot_output *output, struct ltt_session *session,
- int wait, uint64_t nb_packets_per_stream)
+ const struct snapshot_output *output,
+ const struct ltt_session *session, int wait,
+ uint64_t nb_packets_per_stream)
{
int ret;
enum lttng_error_code status;
goto error_snapshot;
}
- status = ust_app_snapshot_record(usess, output, wait, nb_packets_per_stream);
+ status = ust_app_snapshot_record(usess, output, wait,
+ nb_packets_per_stream);
if (status != LTTNG_OK) {
goto error_snapshot;
}
}
static
-uint64_t get_session_size_one_more_packet_per_stream(struct ltt_session *session,
- uint64_t cur_nr_packets)
+uint64_t get_session_size_one_more_packet_per_stream(
+ const struct ltt_session *session, uint64_t cur_nr_packets)
{
uint64_t tot_size = 0;
if (session->kernel_session) {
struct ltt_kernel_channel *chan;
- struct ltt_kernel_session *ksess = session->kernel_session;
+ const struct ltt_kernel_session *ksess =
+ session->kernel_session;
cds_list_for_each_entry(chan, &ksess->channel_list.head, list) {
if (cur_nr_packets >= chan->channel->attr.num_subbuf) {
}
if (session->ust_session) {
- struct ltt_ust_session *usess = session->ust_session;
+ const struct ltt_ust_session *usess = session->ust_session;
tot_size += ust_app_get_size_one_more_packet_per_stream(usess,
cur_nr_packets);
* in between this call and actually grabbing data.
*/
static
-int64_t get_session_nb_packets_per_stream(struct ltt_session *session, uint64_t max_size)
+int64_t get_session_nb_packets_per_stream(const struct ltt_session *session,
+ uint64_t max_size)
{
int64_t size_left;
uint64_t cur_nb_packets = 0;
for (;;) {
uint64_t one_more_packet_tot_size;
- one_more_packet_tot_size = get_session_size_one_more_packet_per_stream(session,
- cur_nb_packets);
+ one_more_packet_tot_size = get_session_size_one_more_packet_per_stream(
+ session, cur_nb_packets);
if (!one_more_packet_tot_size) {
/* We are already grabbing all packets. */
break;
return cur_nb_packets;
}
+static
+enum lttng_error_code snapshot_record(const struct ltt_session *session,
+ const struct snapshot_output *snapshot_output, int wait)
+{
+ int64_t nb_packets_per_stream;
+ enum lttng_error_code ret = LTTNG_OK;
+
+ nb_packets_per_stream = get_session_nb_packets_per_stream(session,
+ snapshot_output->max_size);
+ if (nb_packets_per_stream < 0) {
+ ret = LTTNG_ERR_MAX_SIZE_INVALID;
+ goto end;
+ }
+
+ if (session->kernel_session) {
+ ret = record_kernel_snapshot(session->kernel_session,
+ snapshot_output, session,
+ wait, nb_packets_per_stream);
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+ }
+
+ if (session->ust_session) {
+ ret = record_ust_snapshot(session->ust_session,
+ snapshot_output, session,
+ wait, nb_packets_per_stream);
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+ }
+end:
+ return ret;
+}
+
/*
* Command LTTNG_SNAPSHOT_RECORD from lib lttng ctl.
*
}
if (use_tmp_output) {
- int64_t nb_packets_per_stream;
-
- nb_packets_per_stream = get_session_nb_packets_per_stream(session,
- tmp_output.max_size);
- if (nb_packets_per_stream < 0) {
- cmd_ret = LTTNG_ERR_MAX_SIZE_INVALID;
+ cmd_ret = snapshot_record(session, &tmp_output, wait);
+ if (cmd_ret != LTTNG_OK) {
goto error;
}
-
- if (session->kernel_session) {
- cmd_ret = record_kernel_snapshot(session->kernel_session,
- &tmp_output, session,
- wait, nb_packets_per_stream);
- if (cmd_ret != LTTNG_OK) {
- goto error;
- }
- }
-
- if (session->ust_session) {
- cmd_ret = record_ust_snapshot(session->ust_session,
- &tmp_output, session,
- wait, nb_packets_per_stream);
- if (cmd_ret != LTTNG_OK) {
- goto error;
- }
- }
-
snapshot_success = 1;
} else {
struct snapshot_output *sout;
rcu_read_lock();
cds_lfht_for_each_entry(session->snapshot.output_ht->ht,
&iter.iter, sout, node.node) {
- int64_t nb_packets_per_stream;
-
/*
- * Make a local copy of the output and assign the possible
- * temporary value given by the caller.
+ * 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));
if (output->max_size != (uint64_t) -1ULL) {
tmp_output.max_size = output->max_size;
}
- nb_packets_per_stream = get_session_nb_packets_per_stream(session,
- tmp_output.max_size);
- if (nb_packets_per_stream < 0) {
- cmd_ret = LTTNG_ERR_MAX_SIZE_INVALID;
- rcu_read_unlock();
- goto error;
- }
+ tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
+ memcpy(tmp_output.datetime, datetime, sizeof(datetime));
/* Use temporary name. */
if (*output->name != '\0') {
}
}
- tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
- memcpy(tmp_output.datetime, datetime, sizeof(datetime));
-
- if (session->kernel_session) {
- cmd_ret = record_kernel_snapshot(session->kernel_session,
- &tmp_output, session,
- wait, nb_packets_per_stream);
- if (cmd_ret != LTTNG_OK) {
- rcu_read_unlock();
- goto error;
- }
- }
-
- if (session->ust_session) {
- cmd_ret = record_ust_snapshot(session->ust_session,
- &tmp_output, session,
- wait, nb_packets_per_stream);
- if (cmd_ret != LTTNG_OK) {
- rcu_read_unlock();
- goto error;
- }
+ cmd_ret = snapshot_record(session, &tmp_output, wait);
+ if (cmd_ret != LTTNG_OK) {
+ rcu_read_unlock();
+ goto error;
}
snapshot_success = 1;
}