Fix: Apply consumer URI changes to all domains
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index 2c6f6f4a7bcb443d4a7e6638e489bd04d395e8bc..c1e33693f913076d58d8dba938975be23e10d4bc 100644 (file)
@@ -220,7 +220,9 @@ static int list_lttng_agent_events(struct agent *agt,
 
        DBG3("Listing agent events");
 
+       rcu_read_lock();
        nb_event = lttng_ht_get_count(agt->events);
+       rcu_read_unlock();
        if (nb_event == 0) {
                ret = nb_event;
                goto error;
@@ -1040,7 +1042,8 @@ int cmd_disable_event(struct ltt_session *session, int domain,
 
        event_name = event->name;
 
-       if (event->loglevel_type || event->loglevel || event->enabled
+       /* Error out on unhandled search criteria */
+       if (event->loglevel_type || event->loglevel != -1 || event->enabled
                        || event->pid || event->filter || event->exclusion) {
                return LTTNG_ERR_UNK;
        }
@@ -2004,13 +2007,12 @@ error:
 /*
  * Command LTTNG_SET_CONSUMER_URI processed by the client thread.
  */
-int cmd_set_consumer_uri(int domain, struct ltt_session *session,
-               size_t nb_uri, struct lttng_uri *uris)
+int cmd_set_consumer_uri(struct ltt_session *session, size_t nb_uri,
+               struct lttng_uri *uris)
 {
        int ret, i;
        struct ltt_kernel_session *ksess = session->kernel_session;
        struct ltt_ust_session *usess = session->ust_session;
-       struct consumer_output *consumer = NULL;
 
        assert(session);
        assert(uris);
@@ -2022,41 +2024,41 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session,
                goto error;
        }
 
-       /*
-        * This case switch makes sure the domain session has a temporary consumer
-        * so the URL can be set.
-        */
-       switch (domain) {
-       case 0:
-               /* Code flow error. A session MUST always have a consumer object */
-               assert(session->consumer);
-               /*
-                * The URL will be added to the tracing session consumer instead of a
-                * specific domain consumer.
-                */
-               consumer = session->consumer;
-               break;
-       case LTTNG_DOMAIN_KERNEL:
-               /* Code flow error if we don't have a kernel session here. */
-               assert(ksess);
-               assert(ksess->consumer);
-               consumer = ksess->consumer;
-               break;
-       case LTTNG_DOMAIN_UST:
-               /* Code flow error if we don't have a kernel session here. */
-               assert(usess);
-               assert(usess->consumer);
-               consumer = usess->consumer;
-               break;
-       }
-
+       /* Set the "global" consumer URIs */
        for (i = 0; i < nb_uri; i++) {
-               ret = add_uri_to_consumer(consumer, &uris[i], domain, session->name);
+               ret = add_uri_to_consumer(session->consumer,
+                               &uris[i], 0, session->name);
                if (ret != LTTNG_OK) {
                        goto error;
                }
        }
 
+       /* Set UST session URIs */
+       if (session->ust_session) {
+               for (i = 0; i < nb_uri; i++) {
+                       ret = add_uri_to_consumer(
+                                       session->ust_session->consumer,
+                                       &uris[i], LTTNG_DOMAIN_UST,
+                                       session->name);
+                       if (ret != LTTNG_OK) {
+                               goto error;
+                       }
+               }
+       }
+
+       /* Set kernel session URIs */
+       if (session->kernel_session) {
+               for (i = 0; i < nb_uri; i++) {
+                       ret = add_uri_to_consumer(
+                                       session->kernel_session->consumer,
+                                       &uris[i], LTTNG_DOMAIN_KERNEL,
+                                       session->name);
+                       if (ret != LTTNG_OK) {
+                               goto error;
+                       }
+               }
+       }
+
        /*
         * Make sure to set the session in output mode after we set URI since a
         * session can be created without URL (thus flagged in no output mode).
@@ -2064,7 +2066,9 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session,
        session->output_traces = 1;
        if (ksess) {
                ksess->output_traces = 1;
-       } else if (usess) {
+       }
+
+       if (usess) {
                usess->output_traces = 1;
        }
 
@@ -2126,7 +2130,7 @@ int cmd_create_session_uri(char *name, struct lttng_uri *uris,
        }
 
        if (uris) {
-               ret = cmd_set_consumer_uri(0, session, nb_uri, uris);
+               ret = cmd_set_consumer_uri(session, nb_uri, uris);
                if (ret != LTTNG_OK) {
                        goto consumer_error;
                }
@@ -2415,12 +2419,14 @@ ssize_t cmd_list_domains(struct ltt_session *session,
                DBG3("Listing domains found UST global domain");
                nb_dom++;
 
+               rcu_read_lock();
                cds_lfht_for_each_entry(session->ust_session->agents->ht, &iter.iter,
                                agt, node.node) {
                        if (agt->being_used) {
                                nb_dom++;
                        }
                }
+               rcu_read_unlock();
        }
 
        if (!nb_dom) {
@@ -2443,6 +2449,7 @@ ssize_t cmd_list_domains(struct ltt_session *session,
                (*domains)[index].buf_type = session->ust_session->buffer_type;
                index++;
 
+               rcu_read_lock();
                cds_lfht_for_each_entry(session->ust_session->agents->ht, &iter.iter,
                                agt, node.node) {
                        if (agt->being_used) {
@@ -2451,6 +2458,7 @@ ssize_t cmd_list_domains(struct ltt_session *session,
                                index++;
                        }
                }
+               rcu_read_unlock();
        }
 end:
        return nb_dom;
@@ -2482,8 +2490,10 @@ ssize_t cmd_list_channels(int domain, struct ltt_session *session,
                break;
        case LTTNG_DOMAIN_UST:
                if (session->ust_session != NULL) {
+                       rcu_read_lock();
                        nb_chan = lttng_ht_get_count(
-                                       session->ust_session->domain_global.channels);
+                               session->ust_session->domain_global.channels);
+                       rcu_read_unlock();
                }
                DBG3("Number of UST global channels %zd", nb_chan);
                if (nb_chan < 0) {
@@ -2544,10 +2554,12 @@ ssize_t cmd_list_events(int domain, struct ltt_session *session,
                        struct lttng_ht_iter iter;
                        struct agent *agt;
 
+                       rcu_read_lock();
                        cds_lfht_for_each_entry(session->ust_session->agents->ht,
                                        &iter.iter, agt, node.node) {
                                nb_event = list_lttng_agent_events(agt, events);
                        }
+                       rcu_read_unlock();
                }
                break;
        default:
@@ -2796,7 +2808,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
                struct lttng_snapshot_output **outputs)
 {
        int ret, idx = 0;
-       struct lttng_snapshot_output *list;
+       struct lttng_snapshot_output *list = NULL;
        struct lttng_ht_iter iter;
        struct snapshot_output *output;
 
@@ -2810,7 +2822,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
         * set in no output mode.
         */
        if (session->output_traces) {
-               ret = LTTNG_ERR_EPERM;
+               ret = -LTTNG_ERR_EPERM;
                goto error;
        }
 
@@ -2821,11 +2833,12 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
 
        list = zmalloc(session->snapshot.nb_output * sizeof(*list));
        if (!list) {
-               ret = LTTNG_ERR_NOMEM;
+               ret = -LTTNG_ERR_NOMEM;
                goto error;
        }
 
        /* Copy list from session to the new list object. */
+       rcu_read_lock();
        cds_lfht_for_each_entry(session->snapshot.output_ht->ht, &iter.iter,
                        output, node.node) {
                assert(output->consumer);
@@ -2840,28 +2853,28 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
                        ret = uri_to_str_url(&output->consumer->dst.net.control,
                                        list[idx].ctrl_url, sizeof(list[idx].ctrl_url));
                        if (ret < 0) {
-                               ret = LTTNG_ERR_NOMEM;
-                               goto free_error;
+                               ret = -LTTNG_ERR_NOMEM;
+                               goto error;
                        }
 
                        /* Data URI. */
                        ret = uri_to_str_url(&output->consumer->dst.net.data,
                                        list[idx].data_url, sizeof(list[idx].data_url));
                        if (ret < 0) {
-                               ret = LTTNG_ERR_NOMEM;
-                               goto free_error;
+                               ret = -LTTNG_ERR_NOMEM;
+                               goto error;
                        }
                }
                idx++;
        }
 
        *outputs = list;
-       return session->snapshot.nb_output;
-
-free_error:
-       free(list);
+       list = NULL;
+       ret = session->snapshot.nb_output;
 error:
-       return -ret;
+       free(list);
+       rcu_read_unlock();
+       return ret;
 }
 
 /*
This page took 0.02739 seconds and 4 git commands to generate.