*/
#define _LGPL_SOURCE
-#include <inttypes.h>
-#include <string.h>
-#include <urcu/uatomic.h>
+#include "snapshot.hpp"
+#include "utils.hpp"
#include <common/defaults.hpp>
+#include <common/urcu.hpp>
-#include "snapshot.hpp"
-#include "utils.hpp"
+#include <inttypes.h>
+#include <string.h>
+#include <urcu/uatomic.h>
/*
* Return the atomically incremented value of next_output_id.
* 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;
}
} 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;
}
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;
}
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;
}
* 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);
}
/*
* 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);
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<snapshot_output>();
}
/*
* 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;
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
/*
* 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.
*
* 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;
}
/*
*
* 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);
goto error;
}
- output = caa_container_of(node, struct snapshot_output, node);
+ output = lttng::utils::container_of(node, &snapshot_output::node);
error:
return output;
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);
}