X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;h=165fef4dc5c412392fe49daec62be947d4de3853;hp=f503fd1cbf42a25660a990d869c7adeb467cc823;hb=09b72f7aa737f46196db18bcdf3bc947a08c27a2;hpb=d9f484bc6f074842bc4ac3eab0127fe3aaa10909 diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index f503fd1cb..165fef4dc 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -287,6 +287,50 @@ end: return ret; } +static int check_enough_available_memory(size_t num_bytes_requested_per_cpu) +{ + int ret; + long num_cpu; + size_t best_mem_info; + size_t num_bytes_requested_total; + + /* + * Get the number of CPU currently online to compute the amount of + * memory needed to create a buffer for every CPU. + */ + num_cpu = sysconf(_SC_NPROCESSORS_ONLN); + if (num_cpu == -1) { + goto error; + } + + num_bytes_requested_total = num_bytes_requested_per_cpu * num_cpu; + + /* + * Try to get the `MemAvail` field of `/proc/meminfo`. This is the most + * reliable estimate we can get but it is only exposed by the kernel + * since 3.14. (See Linux kernel commit: + * 34e431b0ae398fc54ea69ff85ec700722c9da773) + */ + ret = utils_get_memory_available(&best_mem_info); + if (ret >= 0) { + goto success; + } + + /* + * As a backup plan, use `MemTotal` field of `/proc/meminfo`. This + * is a sanity check for obvious user error. + */ + ret = utils_get_memory_total(&best_mem_info); + if (ret >= 0) { + goto success; + } + +error: + return -1; +success: + return best_mem_info >= num_bytes_requested_total; +} + /* * Try connect to session daemon with sock_path. * @@ -1475,6 +1519,7 @@ int lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *in_chan) { struct lttcomm_session_msg lsm; + size_t total_buffer_size_needed_per_cpu = 0; /* NULL arguments are forbidden. No default values. */ if (handle == NULL || in_chan == NULL) { @@ -1510,6 +1555,16 @@ int lttng_enable_channel(struct lttng_handle *handle, memcpy(&lsm.u.channel.extended, extended, sizeof(*extended)); } + /* + * Verify that the amount of memory required to create the requested + * buffer is available on the system at the moment. + */ + total_buffer_size_needed_per_cpu = lsm.u.channel.chan.attr.num_subbuf * + lsm.u.channel.chan.attr.subbuf_size; + if (!check_enough_available_memory(total_buffer_size_needed_per_cpu)) { + return -LTTNG_ERR_NOMEM; + } + lsm.cmd_type = LTTNG_ENABLE_CHANNEL; lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain); @@ -2039,7 +2094,6 @@ int lttng_list_events(struct lttng_handle *handle, probe_storage_req = ret; comm_ext_at += ext_comm->userspace_probe_location_len; - ret = 0; } storage_req += sizeof(struct lttng_event_extended); @@ -2115,6 +2169,7 @@ int lttng_list_events(struct lttng_handle *handle, ext_comm->nb_exclusions * LTTNG_SYMBOL_NAME_LEN); if (ret) { ret = -LTTNG_ERR_NOMEM; + goto free_dynamic_buffer; } comm_ext_at += ext_comm->nb_exclusions * LTTNG_SYMBOL_NAME_LEN; } @@ -2744,6 +2799,9 @@ int lttng_list_tracker_pids(struct lttng_handle *handle, return ret; } nr_pids = ret / sizeof(int32_t); + if (nr_pids > 0 && !pids) { + return -LTTNG_ERR_UNK; + } if (nr_pids == 1 && pids[0] == -1) { free(pids); pids = NULL; @@ -2890,50 +2948,6 @@ end: return ret; } -int lttng_session_get_current_archive_location(const char *session_name, - char **chunk_path) -{ - struct lttcomm_session_msg lsm; - struct lttng_session_get_current_output_return *output_return = NULL; - int ret; - size_t path_len; - - memset(&lsm, 0, sizeof(lsm)); - lsm.cmd_type = LTTNG_SESSION_GET_CURRENT_OUTPUT; - ret = lttng_strncpy(lsm.session.name, session_name, - sizeof(lsm.session.name)); - if (ret) { - ret = -LTTNG_ERR_INVALID; - goto end; - } - - ret = lttng_ctl_ask_sessiond(&lsm, (void **) &output_return); - if (ret < 0) { - ret = -1; - goto end; - } - - path_len = lttng_strnlen(output_return->path, - sizeof(output_return->path)); - if (path_len == 0 || path_len == sizeof(output_return->path)) { - ret = -LTTNG_ERR_NO_SESSION_OUTPUT; - goto end; - } - - *chunk_path = zmalloc(path_len + 1); - if (!*chunk_path) { - ret = -1; - goto end; - } - memcpy(*chunk_path, output_return->path, path_len); - - ret = 0; - -end: - free(output_return); - return ret; -} - /* * lib constructor. */