X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fcmd.c;h=139133210406882cf8e3359287a892bb228c9c5b;hb=aecf2da5ff4c92398b58af71ec10a3c2a311076e;hp=7af855eacb14e13b204730cdd2848f888c3bc352;hpb=343defc2671db532be8a9eed84907fd2e4044f0e;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 7af855eac..139133210 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1,19 +1,9 @@ /* - * Copyright (C) 2012 - David Goulet - * Copyright (C) 2016 - Jérémie Galarneau + * Copyright (C) 2012 David Goulet + * Copyright (C) 2016 Jérémie Galarneau * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define _LGPL_SOURCE @@ -1442,12 +1432,14 @@ error: } /* - * Command LTTNG_TRACK_PID processed by the client thread. + * Command LTTNG_TRACK_ID processed by the client thread. * * Called with session lock held. */ -int cmd_track_pid(struct ltt_session *session, enum lttng_domain_type domain, - int pid) +int cmd_track_id(struct ltt_session *session, + enum lttng_tracker_type tracker_type, + enum lttng_domain_type domain, + const struct lttng_tracker_id *id) { int ret; @@ -1460,7 +1452,7 @@ int cmd_track_pid(struct ltt_session *session, enum lttng_domain_type domain, ksess = session->kernel_session; - ret = kernel_track_pid(ksess, pid); + ret = kernel_track_id(tracker_type, ksess, id); if (ret != LTTNG_OK) { goto error; } @@ -1474,7 +1466,7 @@ int cmd_track_pid(struct ltt_session *session, enum lttng_domain_type domain, usess = session->ust_session; - ret = trace_ust_track_pid(usess, pid); + ret = trace_ust_track_id(tracker_type, usess, id); if (ret != LTTNG_OK) { goto error; } @@ -1493,12 +1485,14 @@ error: } /* - * Command LTTNG_UNTRACK_PID processed by the client thread. + * Command LTTNG_UNTRACK_ID processed by the client thread. * * Called with session lock held. */ -int cmd_untrack_pid(struct ltt_session *session, enum lttng_domain_type domain, - int pid) +int cmd_untrack_id(struct ltt_session *session, + enum lttng_tracker_type tracker_type, + enum lttng_domain_type domain, + const struct lttng_tracker_id *id) { int ret; @@ -1511,7 +1505,7 @@ int cmd_untrack_pid(struct ltt_session *session, enum lttng_domain_type domain, ksess = session->kernel_session; - ret = kernel_untrack_pid(ksess, pid); + ret = kernel_untrack_id(tracker_type, ksess, id); if (ret != LTTNG_OK) { goto error; } @@ -1525,7 +1519,7 @@ int cmd_untrack_pid(struct ltt_session *session, enum lttng_domain_type domain, usess = session->ust_session; - ret = trace_ust_untrack_pid(usess, pid); + ret = trace_ust_untrack_id(tracker_type, usess, id); if (ret != LTTNG_OK) { goto error; } @@ -2573,15 +2567,16 @@ ssize_t cmd_list_syscalls(struct lttng_event **events) } /* - * Command LTTNG_LIST_TRACKER_PIDS processed by the client thread. + * Command LTTNG_LIST_TRACKER_IDS processed by the client thread. * * Called with session lock held. */ -ssize_t cmd_list_tracker_pids(struct ltt_session *session, - enum lttng_domain_type domain, int32_t **pids) +int cmd_list_tracker_ids(enum lttng_tracker_type tracker_type, + struct ltt_session *session, + enum lttng_domain_type domain, + struct lttng_tracker_ids **ids) { - int ret; - ssize_t nr_pids = 0; + int ret = LTTNG_OK; switch (domain) { case LTTNG_DOMAIN_KERNEL: @@ -2589,9 +2584,9 @@ ssize_t cmd_list_tracker_pids(struct ltt_session *session, struct ltt_kernel_session *ksess; ksess = session->kernel_session; - nr_pids = kernel_list_tracker_pids(ksess, pids); - if (nr_pids < 0) { - ret = LTTNG_ERR_KERN_LIST_FAIL; + ret = kernel_list_tracker_ids(tracker_type, ksess, ids); + if (ret != LTTNG_OK) { + ret = -LTTNG_ERR_KERN_LIST_FAIL; goto error; } break; @@ -2601,9 +2596,9 @@ ssize_t cmd_list_tracker_pids(struct ltt_session *session, struct ltt_ust_session *usess; usess = session->ust_session; - nr_pids = trace_ust_list_tracker_pids(usess, pids); - if (nr_pids < 0) { - ret = LTTNG_ERR_UST_LIST_FAIL; + ret = trace_ust_list_tracker_ids(tracker_type, usess, ids); + if (ret != LTTNG_OK) { + ret = -LTTNG_ERR_UST_LIST_FAIL; goto error; } break; @@ -2612,15 +2607,13 @@ ssize_t cmd_list_tracker_pids(struct ltt_session *session, case LTTNG_DOMAIN_JUL: case LTTNG_DOMAIN_PYTHON: default: - ret = LTTNG_ERR_UND; + ret = -LTTNG_ERR_UND; goto error; } - return nr_pids; - error: /* Return negative value to differentiate return code */ - return -ret; + return ret; } /* @@ -2636,6 +2629,8 @@ int cmd_start_trace(struct ltt_session *session) struct ltt_ust_session *usess; const bool session_rotated_after_last_stop = session->rotated_after_last_stop; + const bool session_cleared_after_last_stop = + session->cleared_after_last_stop; assert(session); @@ -2646,7 +2641,8 @@ int cmd_start_trace(struct ltt_session *session) /* Is the session already started? */ if (session->active) { ret = LTTNG_ERR_TRACE_ALREADY_STARTED; - goto error; + /* Perform nothing */ + goto end; } if (session->rotation_state == LTTNG_ROTATION_STATE_ONGOING && @@ -2682,6 +2678,7 @@ int cmd_start_trace(struct ltt_session *session) session->active = 1; session->rotated_after_last_stop = false; + session->cleared_after_last_stop = false; if (session->output_traces && !session->current_trace_chunk) { if (!session->has_been_started) { struct lttng_trace_chunk *trace_chunk; @@ -2770,7 +2767,10 @@ error: /* Restore initial state on error. */ session->rotated_after_last_stop = session_rotated_after_last_stop; + session->cleared_after_last_stop = + session_cleared_after_last_stop; } +end: return ret; } @@ -3323,9 +3323,7 @@ int cmd_destroy_session(struct ltt_session *session, session->rotate_size = 0; } - if (session->most_recent_chunk_id.is_set && - session->most_recent_chunk_id.value != 0 && - session->current_trace_chunk && session->output_traces) { + if (session->rotated && session->current_trace_chunk && session->output_traces) { /* * Perform a last rotation on destruction if rotations have * occurred during the session's lifetime. @@ -4576,7 +4574,7 @@ int64_t get_session_nb_packets_per_stream(const struct ltt_session *session, } cur_nb_packets++; } - if (!cur_nb_packets) { + if (!cur_nb_packets && size_left != max_size) { /* Not enough room to grab one packet of each stream, error. */ return -1; } @@ -4710,7 +4708,13 @@ enum lttng_error_code snapshot_record(struct ltt_session *session, } } - if (session_close_trace_chunk(session, session->current_trace_chunk, + if (session_set_trace_chunk(session, NULL, &snapshot_trace_chunk)) { + ERR("Failed to release the current trace chunk of session \"%s\"", + session->name); + ret_code = LTTNG_ERR_UNK; + } + + if (session_close_trace_chunk(session, snapshot_trace_chunk, LTTNG_TRACE_CHUNK_COMMAND_TYPE_NO_OPERATION, NULL)) { /* * Don't goto end; make sure the chunk is closed for the session @@ -4720,11 +4724,6 @@ enum lttng_error_code snapshot_record(struct ltt_session *session, session->name); ret_code = LTTNG_ERR_CLOSE_TRACE_CHUNK_FAIL_CONSUMER; } - if (session_set_trace_chunk(session, NULL, NULL)) { - ERR("Failed to release the current trace chunk of session \"%s\"", - session->name); - ret_code = LTTNG_ERR_UNK; - } error: if (original_ust_consumer_output) { session->ust_session->consumer = original_ust_consumer_output; @@ -4967,6 +4966,18 @@ int cmd_rotate_session(struct ltt_session *session, cmd_ret = LTTNG_ERR_ROTATION_MULTIPLE_AFTER_STOP; goto end; } + + /* + * After a stop followed by a clear, disallow following rotations a they would + * generate empty chunks. + */ + if (session->cleared_after_last_stop) { + DBG("Session \"%s\" was already cleared after stop, refusing rotation", + session->name); + cmd_ret = LTTNG_ERR_ROTATION_AFTER_STOP_CLEAR; + goto end; + } + if (session->active) { new_trace_chunk = session_create_new_trace_chunk(session, NULL, NULL, NULL);