channels[i].attr.read_timer_interval =
uchan->attr.read_timer_interval;
channels[i].enabled = uchan->enabled;
+ channels[i].attr.tracefile_size = uchan->tracefile_size;
+ channels[i].attr.tracefile_count = uchan->tracefile_count;
switch (uchan->attr.output) {
case LTTNG_UST_MMAP:
default:
strncpy(tmp_events[i].name, event->name, sizeof(tmp_events[i].name));
tmp_events[i].name[sizeof(tmp_events[i].name) - 1] = '\0';
tmp_events[i].enabled = event->enabled;
+ tmp_events[i].loglevel = event->loglevel;
+ tmp_events[i].loglevel_type = event->loglevel_type;
i++;
}
rcu_read_unlock();
attr->attr.switch_timer_interval = 0;
}
+ /*
+ * The ringbuffer (both in user space and kernel) behave badly in overwrite
+ * mode and with less than 2 subbuf so block it right away and send back an
+ * invalid attribute error.
+ */
+ if (attr->attr.overwrite && attr->attr.num_subbuf < 2) {
+ ret = LTTNG_ERR_INVALID;
+ goto error;
+ }
+
switch (domain->type) {
case LTTNG_DOMAIN_KERNEL:
{
tmp_dom.type = LTTNG_DOMAIN_UST;
ret = cmd_enable_event(session, &tmp_dom, DEFAULT_JUL_CHANNEL_NAME,
- &uevent, NULL, NULL, NULL, wpipe);
+ &uevent, filter_expression, filter, NULL, wpipe);
if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) {
goto error;
}
/* The wild card * means that everything should be enabled. */
if (strncmp(event->name, "*", 1) == 0 && strlen(event->name) == 1) {
- ret = event_jul_enable_all(usess, event);
+ ret = event_jul_enable_all(usess, event, filter);
} else {
- ret = event_jul_enable(usess, event);
+ ret = event_jul_enable(usess, event, filter);
}
if (ret != LTTNG_OK) {
goto error;
strncpy(event.name, "*", sizeof(event.name));
event.name[sizeof(event.name) - 1] = '\0';
- ret = event_jul_enable_all(usess, &event);
+ ret = event_jul_enable_all(usess, &event, filter);
if (ret != LTTNG_OK) {
goto error;
}
}
}
+ /*
+ * Make sure to set the session in output mode after we set URI since a
+ * session can be created without URL (thus flagged in no output mode).
+ */
+ session->output_traces = 1;
+ if (ksess) {
+ ksess->output_traces = 1;
+ } else if (usess) {
+ usess->output_traces = 1;
+ }
+
/* All good! */
ret = LTTNG_OK;
*/
static int record_kernel_snapshot(struct ltt_kernel_session *ksess,
struct snapshot_output *output, struct ltt_session *session,
- int wait, int nb_streams)
+ int wait, uint64_t max_stream_size)
{
int ret;
goto error_snapshot;
}
- ret = kernel_snapshot_record(ksess, output, wait, nb_streams);
+ ret = kernel_snapshot_record(ksess, output, wait, max_stream_size);
if (ret != LTTNG_OK) {
goto error_snapshot;
}
*/
static int record_ust_snapshot(struct ltt_ust_session *usess,
struct snapshot_output *output, struct ltt_session *session,
- int wait, int nb_streams)
+ int wait, uint64_t max_stream_size)
{
int ret;
goto error_snapshot;
}
- ret = ust_app_snapshot_record(usess, output, wait, nb_streams);
+ ret = ust_app_snapshot_record(usess, output, wait, max_stream_size);
if (ret < 0) {
switch (-ret) {
case EINVAL:
return ret;
}
+/*
+ * Return the biggest subbuffer size of all channels in the given session.
+ */
+static uint64_t get_session_max_subbuf_size(struct ltt_session *session)
+{
+ uint64_t max_size = 0;
+
+ assert(session);
+
+ if (session->kernel_session) {
+ struct ltt_kernel_channel *chan;
+ struct ltt_kernel_session *ksess = session->kernel_session;
+
+ /*
+ * For each channel, add to the max size the size of each subbuffer
+ * multiplied by their sized.
+ */
+ cds_list_for_each_entry(chan, &ksess->channel_list.head, list) {
+ if (chan->channel->attr.subbuf_size > max_size) {
+ max_size = chan->channel->attr.subbuf_size;
+ }
+ }
+ }
+
+ if (session->ust_session) {
+ struct lttng_ht_iter iter;
+ struct ltt_ust_channel *uchan;
+ struct ltt_ust_session *usess = session->ust_session;
+
+ cds_lfht_for_each_entry(usess->domain_global.channels->ht, &iter.iter,
+ uchan, node.node) {
+ if (uchan->attr.subbuf_size > max_size) {
+ max_size = uchan->attr.subbuf_size;
+ }
+ }
+ }
+
+ return max_size;
+}
+
/*
* 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)
+static unsigned int get_session_nb_streams(struct ltt_session *session)
{
unsigned int total_streams = 0;
unsigned int use_tmp_output = 0;
struct snapshot_output tmp_output;
unsigned int nb_streams, snapshot_success = 0;
+ uint64_t session_max_size = 0, max_stream_size = 0;
assert(session);
}
/*
- * Get the total number of stream of that session which is used by the
- * maximum size of the snapshot feature.
+ * Get the session maximum size for a snapshot meaning it will compute the
+ * size of all streams from all domain.
*/
- nb_streams = get_total_nb_stream(session);
+ max_stream_size = get_session_max_subbuf_size(session);
+
+ nb_streams = get_session_nb_streams(session);
+ if (nb_streams) {
+ /*
+ * The maximum size of the snapshot is the number of streams multiplied
+ * by the biggest subbuf size of all channels in a session which is the
+ * maximum stream size available for each stream. The session max size
+ * is now checked against the snapshot max size value given by the user
+ * and if lower, an error is returned.
+ */
+ session_max_size = max_stream_size * nb_streams;
+ }
+
+ DBG3("Snapshot max size is %" PRIu64 " for max stream size of %" PRIu64,
+ session_max_size, max_stream_size);
+
+ /*
+ * If we use a temporary output, check right away if the max size fits else
+ * for each output the max size will be checked.
+ */
+ if (use_tmp_output &&
+ (tmp_output.max_size != 0 &&
+ tmp_output.max_size < session_max_size)) {
+ ret = LTTNG_ERR_MAX_SIZE_INVALID;
+ goto error;
+ }
if (session->kernel_session) {
struct ltt_kernel_session *ksess = session->kernel_session;
if (use_tmp_output) {
ret = record_kernel_snapshot(ksess, &tmp_output, session,
- wait, nb_streams);
+ wait, max_stream_size);
if (ret != LTTNG_OK) {
goto error;
}
tmp_output.max_size = output->max_size;
}
+ if (tmp_output.max_size != 0 &&
+ tmp_output.max_size < session_max_size) {
+ rcu_read_unlock();
+ ret = LTTNG_ERR_MAX_SIZE_INVALID;
+ goto error;
+ }
+
/* Use temporary name. */
if (*output->name != '\0') {
strncpy(tmp_output.name, output->name,
tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
ret = record_kernel_snapshot(ksess, &tmp_output,
- session, wait, nb_streams);
+ session, wait, max_stream_size);
if (ret != LTTNG_OK) {
rcu_read_unlock();
goto error;
if (use_tmp_output) {
ret = record_ust_snapshot(usess, &tmp_output, session,
- wait, nb_streams);
+ wait, max_stream_size);
if (ret != LTTNG_OK) {
goto error;
}
tmp_output.max_size = output->max_size;
}
+ if (tmp_output.max_size != 0 &&
+ tmp_output.max_size < session_max_size) {
+ rcu_read_unlock();
+ ret = LTTNG_ERR_MAX_SIZE_INVALID;
+ goto error;
+ }
+
/* Use temporary name. */
if (*output->name != '\0') {
strncpy(tmp_output.name, output->name,
tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
ret = record_ust_snapshot(usess, &tmp_output, session,
- wait, nb_streams);
+ wait, max_stream_size);
if (ret != LTTNG_OK) {
rcu_read_unlock();
goto error;