X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsnapshot.cpp;h=e7a0033541a5d07d5cdafd77d5f4306e462e2662;hp=e0ffe69c0b1a5303cebfe908ab99cee7eb2220d1;hb=HEAD;hpb=0114db0ec2407029052eb61a0189c9b1cd64d520 diff --git a/src/bin/lttng-sessiond/snapshot.cpp b/src/bin/lttng-sessiond/snapshot.cpp index e0ffe69c0..e7a003354 100644 --- a/src/bin/lttng-sessiond/snapshot.cpp +++ b/src/bin/lttng-sessiond/snapshot.cpp @@ -6,14 +6,15 @@ */ #define _LGPL_SOURCE -#include -#include -#include +#include "snapshot.hpp" +#include "utils.hpp" #include +#include -#include "snapshot.hpp" -#include "utils.hpp" +#include +#include +#include /* * Return the atomically incremented value of next_output_id. @@ -29,10 +30,13 @@ static inline unsigned long get_next_output_id(struct snapshot *snapshot) * Return 0 on success or else a negative value. */ static int output_init(const struct ltt_session *session, - uint64_t max_size, const char *name, - struct lttng_uri *uris, size_t nb_uri, - struct consumer_output *consumer, struct snapshot_output *output, - struct snapshot *snapshot) + uint64_t max_size, + const char *name, + struct lttng_uri *uris, + size_t nb_uri, + struct consumer_output *consumer, + struct snapshot_output *output, + struct snapshot *snapshot) { int ret = 0, i; @@ -58,8 +62,11 @@ static int output_init(const struct ltt_session *session, } } else { /* Set default name. */ - ret = snprintf(output->name, sizeof(output->name), "%s-%" PRIu32, - DEFAULT_SNAPSHOT_NAME, output->id); + ret = snprintf(output->name, + sizeof(output->name), + "%s-%" PRIu32, + DEFAULT_SNAPSHOT_NAME, + output->id); if (ret < 0) { ret = -ENOMEM; goto error; @@ -84,11 +91,12 @@ static int output_init(const struct ltt_session *session, } if (uris[0].dtype == LTTNG_DST_PATH) { - memset(output->consumer->dst.session_root_path, 0, - sizeof(output->consumer->dst.session_root_path)); + memset(output->consumer->dst.session_root_path, + 0, + sizeof(output->consumer->dst.session_root_path)); if (lttng_strncpy(output->consumer->dst.session_root_path, - uris[0].dst.path, - sizeof(output->consumer->dst.session_root_path))) { + uris[0].dst.path, + sizeof(output->consumer->dst.session_root_path))) { ret = -LTTNG_ERR_INVALID; goto error; } @@ -103,10 +111,9 @@ static int output_init(const struct ltt_session *session, goto error; } - for (i = 0; i < nb_uri; i ++) { + for (i = 0; i < nb_uri; i++) { /* Network URIs */ - ret = consumer_set_network_uri(session, output->consumer, - &uris[i]); + ret = consumer_set_network_uri(session, output->consumer, &uris[i]); if (ret < 0) { goto error; } @@ -124,13 +131,15 @@ end: * Return 0 on success or else a negative value. */ int snapshot_output_init_with_uri(const struct ltt_session *session, - uint64_t max_size, const char *name, - struct lttng_uri *uris, size_t nb_uri, - struct consumer_output *consumer, struct snapshot_output *output, - struct snapshot *snapshot) + uint64_t max_size, + const char *name, + struct lttng_uri *uris, + size_t nb_uri, + struct consumer_output *consumer, + struct snapshot_output *output, + struct snapshot *snapshot) { - return output_init(session, max_size, name, uris, nb_uri, consumer, - output, snapshot); + return output_init(session, max_size, name, uris, nb_uri, consumer, output, snapshot); } /* @@ -140,13 +149,16 @@ int snapshot_output_init_with_uri(const struct ltt_session *session, * Return 0 on success or else a negative value. */ int snapshot_output_init(const struct ltt_session *session, - uint64_t max_size, const char *name, - const char *ctrl_url, const char *data_url, - struct consumer_output *consumer, struct snapshot_output *output, - struct snapshot *snapshot) + uint64_t max_size, + const char *name, + const char *ctrl_url, + const char *data_url, + struct consumer_output *consumer, + struct snapshot_output *output, + struct snapshot *snapshot) { int ret = 0, nb_uri; - struct lttng_uri *uris = NULL; + struct lttng_uri *uris = nullptr; /* Create an array of URIs from URLs. */ nb_uri = uri_parse_str_urls(ctrl_url, data_url, &uris); @@ -155,15 +167,14 @@ int snapshot_output_init(const struct ltt_session *session, goto error; } - ret = output_init(session, max_size, name, uris, nb_uri, consumer, - output, snapshot); + ret = output_init(session, max_size, name, uris, nb_uri, consumer, output, snapshot); error: free(uris); return ret; } -struct snapshot_output *snapshot_output_alloc(void) +struct snapshot_output *snapshot_output_alloc() { return zmalloc(); } @@ -171,8 +182,7 @@ struct snapshot_output *snapshot_output_alloc(void) /* * Delete output from the snapshot object. */ -void snapshot_delete_output(struct snapshot *snapshot, - struct snapshot_output *output) +void snapshot_delete_output(struct snapshot *snapshot, struct snapshot_output *output) { int ret; struct lttng_ht_iter iter; @@ -182,9 +192,8 @@ void snapshot_delete_output(struct snapshot *snapshot, LTTNG_ASSERT(output); iter.iter.node = &output->node.node; - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; ret = lttng_ht_del(snapshot->output_ht, &iter); - rcu_read_unlock(); LTTNG_ASSERT(!ret); /* * This is safe because the ownership of a snapshot object is in a session @@ -196,16 +205,14 @@ void snapshot_delete_output(struct snapshot *snapshot, /* * Add output object to the snapshot. */ -void snapshot_add_output(struct snapshot *snapshot, - struct snapshot_output *output) +void snapshot_add_output(struct snapshot *snapshot, struct snapshot_output *output) { LTTNG_ASSERT(snapshot); LTTNG_ASSERT(snapshot->output_ht); LTTNG_ASSERT(output); - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; lttng_ht_add_unique_ulong(snapshot->output_ht, &output->node); - rcu_read_unlock(); /* * This is safe because the ownership of a snapshot object is in a session * for which the session lock need to be acquired to read and modify it. @@ -233,25 +240,23 @@ void snapshot_output_destroy(struct snapshot_output *obj) * * Return the reference on success or else NULL. */ -struct snapshot_output *snapshot_find_output_by_name(const char *name, - struct snapshot *snapshot) +struct snapshot_output *snapshot_find_output_by_name(const char *name, struct snapshot *snapshot) { struct lttng_ht_iter iter; - struct snapshot_output *output = NULL; + struct snapshot_output *output = nullptr; LTTNG_ASSERT(snapshot); LTTNG_ASSERT(name); ASSERT_RCU_READ_LOCKED(); - cds_lfht_for_each_entry(snapshot->output_ht->ht, &iter.iter, output, - node.node) { + cds_lfht_for_each_entry (snapshot->output_ht->ht, &iter.iter, output, node.node) { if (!strncmp(output->name, name, strlen(name))) { return output; } } /* Not found */ - return NULL; + return nullptr; } /* @@ -260,17 +265,16 @@ struct snapshot_output *snapshot_find_output_by_name(const char *name, * * Return the reference on success or else NULL. */ -struct snapshot_output *snapshot_find_output_by_id(uint32_t id, - struct snapshot *snapshot) +struct snapshot_output *snapshot_find_output_by_id(uint32_t id, struct snapshot *snapshot) { struct lttng_ht_node_ulong *node; struct lttng_ht_iter iter; - struct snapshot_output *output = NULL; + struct snapshot_output *output = nullptr; LTTNG_ASSERT(snapshot); ASSERT_RCU_READ_LOCKED(); - lttng_ht_lookup(snapshot->output_ht, (void *)((unsigned long) id), &iter); + lttng_ht_lookup(snapshot->output_ht, (void *) ((unsigned long) id), &iter); node = lttng_ht_iter_get_node_ulong(&iter); if (!node) { DBG3("Snapshot output not found with id %" PRId32, id); @@ -320,12 +324,14 @@ void snapshot_destroy(struct snapshot *obj) return; } - rcu_read_lock(); - cds_lfht_for_each_entry(obj->output_ht->ht, &iter.iter, output, - node.node) { - snapshot_delete_output(obj, output); - snapshot_output_destroy(output); + { + lttng::urcu::read_lock_guard read_lock; + + cds_lfht_for_each_entry (obj->output_ht->ht, &iter.iter, output, node.node) { + snapshot_delete_output(obj, output); + snapshot_output_destroy(output); + } } - rcu_read_unlock(); + lttng_ht_destroy(obj->output_ht); }