Replace explicit rcu_read_lock/unlock with lttng::urcu::read_lock_guard
[lttng-tools.git] / src / bin / lttng-sessiond / save.cpp
index c3d4c06ed4ac8e6f9c85d41e68e33f35d9babba1..e8205bf7f1ff76e7aff37f84c25649948539d19e 100644 (file)
@@ -17,6 +17,7 @@
 #include <common/defaults.hpp>
 #include <common/error.hpp>
 #include <common/runas.hpp>
+#include <common/urcu.hpp>
 #include <common/utils.hpp>
 
 #include <lttng/save-internal.hpp>
@@ -1105,21 +1106,22 @@ static int save_ust_events(struct config_writer *writer, struct lttng_ht *events
                goto end;
        }
 
-       rcu_read_lock();
-       cds_lfht_for_each_entry (events->ht, &iter.iter, node, node) {
-               event = lttng::utils::container_of(node, &ltt_ust_event::node);
+       {
+               lttng::urcu::read_lock_guard read_lock;
 
-               if (event->internal) {
-                       /* Internal events must not be exposed to clients */
-                       continue;
-               }
-               ret = save_ust_event(writer, event);
-               if (ret != LTTNG_OK) {
-                       rcu_read_unlock();
-                       goto end;
+               cds_lfht_for_each_entry (events->ht, &iter.iter, node, node) {
+                       event = lttng::utils::container_of(node, &ltt_ust_event::node);
+
+                       if (event->internal) {
+                               /* Internal events must not be exposed to clients */
+                               continue;
+                       }
+                       ret = save_ust_event(writer, event);
+                       if (ret != LTTNG_OK) {
+                               goto end;
+                       }
                }
        }
-       rcu_read_unlock();
 
        /* /events */
        ret = config_writer_close_element(writer);
@@ -1185,32 +1187,32 @@ static int save_agent_events(struct config_writer *writer, struct agent *agent)
                goto end;
        }
 
-       rcu_read_lock();
-       cds_lfht_for_each_entry (agent->events->ht, &iter.iter, node, node) {
-               struct agent_event *agent_event;
-               struct ltt_ust_event fake_event;
-
-               memset(&fake_event, 0, sizeof(fake_event));
-               agent_event = lttng::utils::container_of(node, &agent_event::node);
-
-               /*
-                * Initialize a fake ust event to reuse the same serialization
-                * function since UST and agent events contain the same info
-                * (and one could wonder why they don't reuse the same
-                * structures...).
-                */
-               ret = init_ust_event_from_agent_event(&fake_event, agent_event);
-               if (ret != LTTNG_OK) {
-                       rcu_read_unlock();
-                       goto end;
-               }
-               ret = save_ust_event(writer, &fake_event);
-               if (ret != LTTNG_OK) {
-                       rcu_read_unlock();
-                       goto end;
+       {
+               lttng::urcu::read_lock_guard read_lock;
+
+               cds_lfht_for_each_entry (agent->events->ht, &iter.iter, node, node) {
+                       struct agent_event *agent_event;
+                       struct ltt_ust_event fake_event;
+
+                       memset(&fake_event, 0, sizeof(fake_event));
+                       agent_event = lttng::utils::container_of(node, &agent_event::node);
+
+                       /*
+                        * Initialize a fake ust event to reuse the same serialization
+                        * function since UST and agent events contain the same info
+                        * (and one could wonder why they don't reuse the same
+                        * structures...).
+                        */
+                       ret = init_ust_event_from_agent_event(&fake_event, agent_event);
+                       if (ret != LTTNG_OK) {
+                               goto end;
+                       }
+                       ret = save_ust_event(writer, &fake_event);
+                       if (ret != LTTNG_OK) {
+                               goto end;
+                       }
                }
        }
-       rcu_read_unlock();
 
        /* /events */
        ret = config_writer_close_element(writer);
@@ -2034,19 +2036,20 @@ static int save_ust_domain(struct config_writer *writer,
                goto end;
        }
 
-       rcu_read_lock();
-       cds_lfht_for_each_entry (
-               session->ust_session->domain_global.channels->ht, &iter.iter, node, node) {
-               ust_chan = lttng::utils::container_of(node, &ltt_ust_channel::node);
-               if (domain == ust_chan->domain) {
-                       ret = save_ust_channel(writer, ust_chan, session->ust_session);
-                       if (ret != LTTNG_OK) {
-                               rcu_read_unlock();
-                               goto end;
+       {
+               lttng::urcu::read_lock_guard read_lock;
+
+               cds_lfht_for_each_entry (
+                       session->ust_session->domain_global.channels->ht, &iter.iter, node, node) {
+                       ust_chan = lttng::utils::container_of(node, &ltt_ust_channel::node);
+                       if (domain == ust_chan->domain) {
+                               ret = save_ust_channel(writer, ust_chan, session->ust_session);
+                               if (ret != LTTNG_OK) {
+                                       goto end;
+                               }
                        }
                }
        }
-       rcu_read_unlock();
 
        /* /channels */
        ret = config_writer_close_element(writer);
@@ -2314,40 +2317,43 @@ static int save_snapshot_outputs(struct config_writer *writer, struct snapshot *
                goto end;
        }
 
-       rcu_read_lock();
-       cds_lfht_for_each_entry (snapshot->output_ht->ht, &iter.iter, output, node.node) {
-               ret = config_writer_open_element(writer, config_element_output);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end_unlock;
-               }
+       {
+               lttng::urcu::read_lock_guard read_lock;
 
-               ret = config_writer_write_element_string(writer, config_element_name, output->name);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end_unlock;
-               }
+               cds_lfht_for_each_entry (snapshot->output_ht->ht, &iter.iter, output, node.node) {
+                       ret = config_writer_open_element(writer, config_element_output);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end_unlock;
+                       }
 
-               ret = config_writer_write_element_unsigned_int(
-                       writer, config_element_max_size, output->max_size);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end_unlock;
-               }
+                       ret = config_writer_write_element_string(
+                               writer, config_element_name, output->name);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end_unlock;
+                       }
 
-               ret = save_consumer_output(writer, output->consumer);
-               if (ret != LTTNG_OK) {
-                       goto end_unlock;
-               }
+                       ret = config_writer_write_element_unsigned_int(
+                               writer, config_element_max_size, output->max_size);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end_unlock;
+                       }
 
-               /* /output */
-               ret = config_writer_close_element(writer);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end_unlock;
+                       ret = save_consumer_output(writer, output->consumer);
+                       if (ret != LTTNG_OK) {
+                               goto end_unlock;
+                       }
+
+                       /* /output */
+                       ret = config_writer_close_element(writer);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end_unlock;
+                       }
                }
        }
-       rcu_read_unlock();
 
        /* /snapshot_outputs */
        ret = config_writer_close_element(writer);
@@ -2360,7 +2366,6 @@ static int save_snapshot_outputs(struct config_writer *writer, struct snapshot *
 end:
        return ret;
 end_unlock:
-       rcu_read_unlock();
        return ret;
 }
 
This page took 0.025566 seconds and 4 git commands to generate.