Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust / lttng-probes.c
index f028ccab8cadd967971cb3f673b883f622b03f7e..e7dab9fce49c2603392a9362311aff3a88ee39d3 100644 (file)
@@ -1,25 +1,12 @@
 /*
- * lttng-probes.c
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
- * Holds LTTng probes registry.
- *
- * Copyright 2010-2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; only
- * version 2.1 of the License.
+ * Copyright 2010-2012 (C) Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Holds LTTng probes registry.
  */
 
+#define _LGPL_SOURCE
 #include <string.h>
 #include <errno.h>
 #include <urcu/list.h>
@@ -34,6 +21,7 @@
 #include "lttng-tracer-core.h"
 #include "jhash.h"
 #include "error.h"
+#include "ust-events-internal.h"
 
 /*
  * probe list is protected by ust_lock()/ust_unlock().
@@ -147,32 +135,50 @@ struct cds_list_head *lttng_get_probe_list_head(void)
 }
 
 static
-const struct lttng_probe_desc *find_provider(const char *provider)
+int check_provider_version(struct lttng_probe_desc *desc)
 {
-       struct lttng_probe_desc *iter;
-       struct cds_list_head *probe_list;
-
-       probe_list = lttng_get_probe_list_head();
-       cds_list_for_each_entry(iter, probe_list, head) {
-               if (!strcmp(iter->provider, provider))
-                       return iter;
+       /*
+        * Check tracepoint provider version compatibility.
+        */
+       if (desc->major <= LTTNG_UST_PROVIDER_MAJOR) {
+               DBG("Provider \"%s\" accepted, version %u.%u is compatible "
+                       "with LTTng UST provider version %u.%u.",
+                       desc->provider, desc->major, desc->minor,
+                       LTTNG_UST_PROVIDER_MAJOR,
+                       LTTNG_UST_PROVIDER_MINOR);
+               if (desc->major < LTTNG_UST_PROVIDER_MAJOR) {
+                       DBG("However, some LTTng UST features might not be "
+                               "available for this provider unless it is "
+                               "recompiled against a more recent LTTng UST.");
+               }
+               return 1;               /* accept */
+       } else {
+               ERR("Provider \"%s\" rejected, version %u.%u is incompatible "
+                       "with LTTng UST provider version %u.%u. Please upgrade "
+                       "LTTng UST.",
+                       desc->provider, desc->major, desc->minor,
+                       LTTNG_UST_PROVIDER_MAJOR,
+                       LTTNG_UST_PROVIDER_MINOR);
+               return 0;               /* reject */
        }
-       return NULL;
 }
 
+
 int lttng_probe_register(struct lttng_probe_desc *desc)
 {
        int ret = 0;
 
-       ust_lock();
+       lttng_ust_fixup_tls();
 
        /*
-        * Check if the provider has already been registered.
+        * If version mismatch, don't register, but don't trigger assert
+        * on caller. The version check just prints an error.
         */
-       if (find_provider(desc->provider)) {
-               ret = -EEXIST;
-               goto end;
-       }
+       if (!check_provider_version(desc))
+               return 0;
+
+       ust_lock_nocheck();
+
        cds_list_add(&desc->lazy_init_head, &lazy_probe_init);
        desc->lazy = 1;
        DBG("adding probe %s containing %u events to lazy registration list",
@@ -184,32 +190,30 @@ int lttng_probe_register(struct lttng_probe_desc *desc)
         */
        if (lttng_session_active())
                fixup_lazy_probes();
-end:
+
+       lttng_fix_pending_event_notifiers();
+
        ust_unlock();
        return ret;
 }
 
-/* Backward compatibility with UST 2.0 */
-int ltt_probe_register(struct lttng_probe_desc *desc)
-{
-       return lttng_probe_register(desc);
-}
-
 void lttng_probe_unregister(struct lttng_probe_desc *desc)
 {
-       ust_lock();
+       lttng_ust_fixup_tls();
+
+       if (!check_provider_version(desc))
+               return;
+
+       ust_lock_nocheck();
        if (!desc->lazy)
                cds_list_del(&desc->head);
        else
                cds_list_del(&desc->lazy_init_head);
-       DBG("just unregistered probe %s", desc->provider);
-       ust_unlock();
-}
 
-/* Backward compatibility with UST 2.0 */
-void ltt_probe_unregister(struct lttng_probe_desc *desc)
-{
-       lttng_probe_unregister(desc);
+       lttng_probe_provider_unregister_events(desc);
+       DBG("just unregistered probes of provider %s", desc->provider);
+
+       ust_unlock();
 }
 
 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list)
@@ -358,15 +362,29 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list)
                                        list_entry->field.type = LTTNG_UST_FIELD_STRING;
                                        break;
                                case atype_array:
-                                       if (event_field->type.u.array.elem_type.atype != atype_integer
-                                               || event_field->type.u.array.elem_type.u.basic.integer.encoding == lttng_encode_none)
+                                       if (event_field->type.u.legacy.array.elem_type.atype != atype_integer
+                                               || event_field->type.u.legacy.array.elem_type.u.basic.integer.encoding == lttng_encode_none)
+                                               list_entry->field.type = LTTNG_UST_FIELD_OTHER;
+                                       else
+                                               list_entry->field.type = LTTNG_UST_FIELD_STRING;
+                                       break;
+                               case atype_array_nestable:
+                                       if (event_field->type.u.array_nestable.elem_type->atype != atype_integer
+                                               || event_field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none)
                                                list_entry->field.type = LTTNG_UST_FIELD_OTHER;
                                        else
                                                list_entry->field.type = LTTNG_UST_FIELD_STRING;
                                        break;
                                case atype_sequence:
-                                       if (event_field->type.u.sequence.elem_type.atype != atype_integer
-                                               || event_field->type.u.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none)
+                                       if (event_field->type.u.legacy.sequence.elem_type.atype != atype_integer
+                                               || event_field->type.u.legacy.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none)
+                                               list_entry->field.type = LTTNG_UST_FIELD_OTHER;
+                                       else
+                                               list_entry->field.type = LTTNG_UST_FIELD_STRING;
+                                       break;
+                               case atype_sequence_nestable:
+                                       if (event_field->type.u.sequence_nestable.elem_type->atype != atype_integer
+                                               || event_field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none)
                                                list_entry->field.type = LTTNG_UST_FIELD_OTHER;
                                        else
                                                list_entry->field.type = LTTNG_UST_FIELD_STRING;
@@ -374,7 +392,8 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list)
                                case atype_float:
                                        list_entry->field.type = LTTNG_UST_FIELD_FLOAT;
                                        break;
-                               case atype_enum:
+                               case atype_enum:        /* Fall-through */
+                               case atype_enum_nestable:
                                        list_entry->field.type = LTTNG_UST_FIELD_ENUM;
                                        break;
                                default:
This page took 0.025819 seconds and 4 git commands to generate.