X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Ftrace-chunk.cpp;h=488d0814620f32e4351913231d7596abff0fbdae;hb=0114db0ec2407029052eb61a0189c9b1cd64d520;hp=9e804ce0197b25c74a66a0b211cce3fa8f77768a;hpb=c26d615c0c49dd994a687c8e1afe670809100765;p=lttng-tools.git diff --git a/src/common/trace-chunk.cpp b/src/common/trace-chunk.cpp index 9e804ce01..488d08146 100644 --- a/src/common/trace-chunk.cpp +++ b/src/common/trace-chunk.cpp @@ -5,23 +5,23 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -64,10 +64,12 @@ static enum lttng_trace_chunk_status lttng_trace_chunk_rename_path_no_lock( struct lttng_trace_chunk *chunk, const char *path); +namespace { struct chunk_credentials { bool use_current_user; struct lttng_credentials user; }; +} /* namespace */ /* * NOTE: Make sure to update: @@ -120,6 +122,7 @@ struct lttng_trace_chunk { struct fd_tracker *fd_tracker; }; +namespace { /* A trace chunk is uniquely identified by its (session id, chunk id) tuple. */ struct lttng_trace_chunk_registry_element { struct lttng_trace_chunk chunk; @@ -130,11 +133,13 @@ struct lttng_trace_chunk_registry_element { /* call_rcu delayed reclaim. */ struct rcu_head rcu_node; }; +} /* namespace */ struct lttng_trace_chunk_registry { struct cds_lfht *ht; }; +namespace { struct fs_handle_untracked { struct fs_handle parent; int fd; @@ -143,6 +148,7 @@ struct fs_handle_untracked { char *path; } location; }; +} /* namespace */ static int fs_handle_untracked_get_fd(struct fs_handle *handle); @@ -171,7 +177,7 @@ const char *lttng_trace_chunk_command_type_str( }; static -const chunk_command close_command_get_post_release_func( +chunk_command close_command_get_post_release_func( lttng_trace_chunk_command_type type) { switch (type) { case LTTNG_TRACE_CHUNK_COMMAND_TYPE_MOVE_TO_COMPLETED: @@ -203,7 +209,7 @@ struct fs_handle *fs_handle_untracked_create( goto end; } - handle = (fs_handle_untracked *) zmalloc(sizeof(typeof(*handle))); + handle = zmalloc(); if (!handle) { PERROR("Failed to allocate untracked filesystem handle"); goto end; @@ -231,14 +237,14 @@ end: static int fs_handle_untracked_get_fd(struct fs_handle *_handle) { - struct fs_handle_untracked *handle = container_of( - _handle, struct fs_handle_untracked, parent); + struct fs_handle_untracked *handle = lttng::utils::container_of( + _handle, &fs_handle_untracked::parent); return handle->fd; } static -void fs_handle_untracked_put_fd(struct fs_handle *_handle) +void fs_handle_untracked_put_fd(struct fs_handle *_handle __attribute__((unused))) { /* no-op. */ } @@ -246,8 +252,8 @@ void fs_handle_untracked_put_fd(struct fs_handle *_handle) static int fs_handle_untracked_unlink(struct fs_handle *_handle) { - struct fs_handle_untracked *handle = container_of( - _handle, struct fs_handle_untracked, parent); + struct fs_handle_untracked *handle = lttng::utils::container_of( + _handle, &fs_handle_untracked::parent); return lttng_directory_handle_unlink_file( handle->location.directory_handle, @@ -265,8 +271,8 @@ void fs_handle_untracked_destroy(struct fs_handle_untracked *handle) static int fs_handle_untracked_close(struct fs_handle *_handle) { - struct fs_handle_untracked *handle = container_of( - _handle, struct fs_handle_untracked, parent); + struct fs_handle_untracked *handle = lttng::utils::container_of( + _handle, &fs_handle_untracked::parent); int ret = close(handle->fd); fs_handle_untracked_destroy(handle); @@ -346,7 +352,7 @@ char *generate_chunk_name(uint64_t chunk_id, time_t creation_timestamp, goto error; } } - new_name = (char *) zmalloc(GENERATED_CHUNK_NAME_LEN); + new_name = calloc(GENERATED_CHUNK_NAME_LEN); if (!new_name) { ERR("Failed to allocate buffer for automatically-generated trace chunk name"); goto error; @@ -399,7 +405,7 @@ struct lttng_trace_chunk *lttng_trace_chunk_allocate(void) { struct lttng_trace_chunk *chunk = NULL; - chunk = (lttng_trace_chunk *) zmalloc(sizeof(*chunk)); + chunk = zmalloc(); if (!chunk) { ERR("Failed to allocate trace chunk"); goto end; @@ -1007,6 +1013,7 @@ enum lttng_trace_chunk_status lttng_trace_chunk_set_credentials_current_user( enum lttng_trace_chunk_status status = LTTNG_TRACE_CHUNK_STATUS_OK; const struct chunk_credentials credentials = { .use_current_user = true, + .user = {}, }; pthread_mutex_lock(&chunk->lock); @@ -1455,8 +1462,8 @@ enum lttng_trace_chunk_status lttng_trace_chunk_open_file( /* * Does not close the fd; we just "unbox" it from the fs_handle. */ - fs_handle_untracked_destroy(container_of( - fs_handle, struct fs_handle_untracked, parent)); + fs_handle_untracked_destroy(lttng::utils::container_of( + fs_handle, &fs_handle_untracked::parent)); } return status; @@ -1639,7 +1646,7 @@ end: } static -int lttng_trace_chunk_no_operation(struct lttng_trace_chunk *trace_chunk) +int lttng_trace_chunk_no_operation(struct lttng_trace_chunk *trace_chunk __attribute__((unused))) { return 0; } @@ -1854,8 +1861,8 @@ bool lttng_trace_chunk_get(struct lttng_trace_chunk *chunk) static void free_lttng_trace_chunk_registry_element(struct rcu_head *node) { - struct lttng_trace_chunk_registry_element *element = - container_of(node, typeof(*element), rcu_node); + struct lttng_trace_chunk_registry_element *element = lttng::utils::container_of( + node, <tng_trace_chunk_registry_element::rcu_node); free(element); } @@ -1863,8 +1870,7 @@ void free_lttng_trace_chunk_registry_element(struct rcu_head *node) static void lttng_trace_chunk_release(struct urcu_ref *ref) { - struct lttng_trace_chunk *chunk = container_of(ref, typeof(*chunk), - ref); + struct lttng_trace_chunk *chunk = lttng::utils::container_of(ref, <tng_trace_chunk::ref); if (chunk->close_command.is_set) { chunk_command func = close_command_get_post_release_func(chunk->close_command.value); @@ -1896,7 +1902,8 @@ void lttng_trace_chunk_release(struct urcu_ref *ref) */ lttng_trace_chunk_fini(chunk); - element = container_of(chunk, typeof(*element), chunk); + element = lttng::utils::container_of( + chunk, <tng_trace_chunk_registry_element::chunk); if (element->registry) { rcu_read_lock(); cds_lfht_del(element->registry->ht, @@ -1929,7 +1936,7 @@ struct lttng_trace_chunk_registry *lttng_trace_chunk_registry_create(void) { struct lttng_trace_chunk_registry *registry; - registry = (lttng_trace_chunk_registry *) zmalloc(sizeof(*registry)); + registry = zmalloc(); if (!registry) { goto end; } @@ -1965,7 +1972,7 @@ lttng_trace_chunk_registry_element_create_from_chunk( struct lttng_trace_chunk *chunk, uint64_t session_id) { struct lttng_trace_chunk_registry_element *element = - (lttng_trace_chunk_registry_element *) zmalloc(sizeof(*element)); + zmalloc(); if (!element) { goto end; @@ -2069,9 +2076,8 @@ lttng_trace_chunk_registry_publish_chunk( * already published and release the reference to the copy we * created if successful. */ - published_element = container_of(published_node, - typeof(*published_element), - trace_chunk_registry_ht_node); + published_element = lttng::utils::container_of(published_node, + <tng_trace_chunk_registry_element::trace_chunk_registry_ht_node); published_chunk = &published_element->chunk; if (lttng_trace_chunk_get(published_chunk)) { lttng_trace_chunk_put(&element->chunk); @@ -2129,9 +2135,8 @@ struct lttng_trace_chunk *_lttng_trace_chunk_registry_find_chunk( goto end; } - published_element = container_of(published_node, - typeof(*published_element), - trace_chunk_registry_ht_node); + published_element = lttng::utils::container_of(published_node, + <tng_trace_chunk_registry_element::trace_chunk_registry_ht_node); if (lttng_trace_chunk_get(&published_element->chunk)) { published_chunk = &published_element->chunk; }