+ /*
+ * 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 (use_tmp_output) {
+ ret = record_kernel_snapshot(ksess, &tmp_output, session,
+ wait, nb_streams);
+ if (ret != LTTNG_OK) {
+ goto error;
+ }
+ snapshot_success = 1;
+ } else {
+ struct snapshot_output *sout;
+ struct lttng_ht_iter iter;
+
+ rcu_read_lock();
+ cds_lfht_for_each_entry(session->snapshot.output_ht->ht,
+ &iter.iter, sout, node.node) {
+ /*
+ * 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));
+ }
+
+ tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
+
+ ret = record_kernel_snapshot(ksess, &tmp_output,
+ session, wait, nb_streams);
+ if (ret != LTTNG_OK) {
+ rcu_read_unlock();
+ goto error;
+ }
+ snapshot_success = 1;
+ }
+ rcu_read_unlock();
+ }
+ }
+
+ if (session->ust_session) {
+ struct ltt_ust_session *usess = session->ust_session;
+
+ if (use_tmp_output) {
+ ret = record_ust_snapshot(usess, &tmp_output, session,
+ wait, nb_streams);
+ if (ret != LTTNG_OK) {
+ goto error;
+ }
+ snapshot_success = 1;
+ } else {
+ struct snapshot_output *sout;
+ struct lttng_ht_iter iter;
+
+ rcu_read_lock();
+ cds_lfht_for_each_entry(session->snapshot.output_ht->ht,
+ &iter.iter, sout, node.node) {
+ /*
+ * 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));
+ }
+
+ tmp_output.nb_snapshot = session->snapshot.nb_snapshot;
+
+ ret = record_ust_snapshot(usess, &tmp_output, session,
+ wait, nb_streams);
+ if (ret != LTTNG_OK) {
+ rcu_read_unlock();
+ goto error;
+ }
+ snapshot_success = 1;
+ }
+ rcu_read_unlock();
+ }
+ }
+
+ if (snapshot_success) {
+ session->snapshot.nb_snapshot++;
+ } else {
+ ret = LTTNG_ERR_SNAPSHOT_FAIL;
+ }