Split ID tracker into public/private structures
[lttng-modules.git] / src / lttng-tracker-id.c
index 205c4af4d9dffb5e2af65f0a0a5c9f78d967f106..8c1b008d2b2fd1b379eab52f7f31998d160ca916 100644 (file)
@@ -19,6 +19,7 @@
 #include <wrapper/rcu.h>
 #include <wrapper/list.h>
 #include <lttng/events.h>
+#include <lttng/events-internal.h>
 
 /*
  * Hash table is allocated and freed when there are no possible
@@ -40,7 +41,7 @@ int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node)
  * protected by preemption off at the tracepoint call site.
  * Return true if found, false if not found.
  */
-bool lttng_id_tracker_lookup(struct lttng_id_tracker_rcu *p, int id)
+bool lttng_id_tracker_lookup(struct lttng_kernel_id_tracker_rcu *p, int id)
 {
        struct hlist_head *head;
        struct lttng_id_hash_node *e;
@@ -55,11 +56,11 @@ bool lttng_id_tracker_lookup(struct lttng_id_tracker_rcu *p, int id)
 }
 EXPORT_SYMBOL_GPL(lttng_id_tracker_lookup);
 
-static struct lttng_id_tracker_rcu *lttng_id_tracker_rcu_create(void)
+static struct lttng_kernel_id_tracker_rcu *lttng_id_tracker_rcu_create(void)
 {
-       struct lttng_id_tracker_rcu *tracker;
+       struct lttng_kernel_id_tracker_rcu *tracker;
 
-       tracker = kzalloc(sizeof(struct lttng_id_tracker_rcu), GFP_KERNEL);
+       tracker = kzalloc(sizeof(struct lttng_kernel_id_tracker_rcu), GFP_KERNEL);
        if (!tracker)
                return NULL;
        return tracker;
@@ -68,13 +69,14 @@ static struct lttng_id_tracker_rcu *lttng_id_tracker_rcu_create(void)
 /*
  * Tracker add and del operations support concurrent RCU lookups.
  */
-int lttng_id_tracker_add(struct lttng_id_tracker *lf, int id)
+int lttng_id_tracker_add(struct lttng_kernel_id_tracker *lf, int id)
 {
        struct hlist_head *head;
        struct lttng_id_hash_node *e;
-       struct lttng_id_tracker_rcu *p = lf->p;
+       struct lttng_kernel_id_tracker_rcu *p = lf->p;
        uint32_t hash = hash_32(id, 32);
        bool allocated = false;
+       int ret;
 
        if (!p) {
                p = lttng_id_tracker_rcu_create();
@@ -84,18 +86,28 @@ int lttng_id_tracker_add(struct lttng_id_tracker *lf, int id)
        }
        head = &p->id_hash[hash & (LTTNG_ID_TABLE_SIZE - 1)];
        lttng_hlist_for_each_entry(e, head, hlist) {
-               if (id == e->id)
-                       return -EEXIST;
+               if (id == e->id) {
+                       ret = -EEXIST;
+                       goto error;
+               }
        }
        e = kmalloc(sizeof(struct lttng_id_hash_node), GFP_KERNEL);
-       if (!e)
-               return -ENOMEM;
+       if (!e) {
+               ret = -ENOMEM;
+               goto error;
+       }
        e->id = id;
        hlist_add_head_rcu(&e->hlist, head);
        if (allocated) {
                rcu_assign_pointer(lf->p, p);
        }
        return 0;
+
+error:
+       if (allocated) {
+               kfree(p);
+       }
+       return ret;
 }
 
 static
@@ -125,11 +137,11 @@ void id_tracker_del_node(struct lttng_id_hash_node *e)
        kfree(e);
 }
 
-int lttng_id_tracker_del(struct lttng_id_tracker *lf, int id)
+int lttng_id_tracker_del(struct lttng_kernel_id_tracker *lf, int id)
 {
        struct hlist_head *head;
        struct lttng_id_hash_node *e;
-       struct lttng_id_tracker_rcu *p = lf->p;
+       struct lttng_kernel_id_tracker_rcu *p = lf->p;
        uint32_t hash = hash_32(id, 32);
 
        if (!p)
@@ -148,7 +160,7 @@ int lttng_id_tracker_del(struct lttng_id_tracker *lf, int id)
        return -ENOENT; /* Not found */
 }
 
-static void lttng_id_tracker_rcu_destroy(struct lttng_id_tracker_rcu *p)
+static void lttng_id_tracker_rcu_destroy(struct lttng_kernel_id_tracker_rcu *p)
 {
        int i;
 
@@ -165,9 +177,9 @@ static void lttng_id_tracker_rcu_destroy(struct lttng_id_tracker_rcu *p)
        kfree(p);
 }
 
-int lttng_id_tracker_empty_set(struct lttng_id_tracker *lf)
+int lttng_id_tracker_empty_set(struct lttng_kernel_id_tracker *lf)
 {
-       struct lttng_id_tracker_rcu *p, *oldp;
+       struct lttng_kernel_id_tracker_rcu *p, *oldp;
 
        p = lttng_id_tracker_rcu_create();
        if (!p)
@@ -179,14 +191,34 @@ int lttng_id_tracker_empty_set(struct lttng_id_tracker *lf)
        return 0;
 }
 
-void lttng_id_tracker_destroy(struct lttng_id_tracker *lf, bool rcu)
+int lttng_id_tracker_init(struct lttng_kernel_id_tracker *lf,
+               struct lttng_kernel_session *session,
+               enum tracker_type type)
+{
+       lf->priv = kzalloc(sizeof(*lf->priv), GFP_KERNEL);
+       if (!lf->priv)
+               return -ENOMEM;
+       lf->priv->session = session;
+       lf->priv->tracker_type = type;
+       return 0;
+}
+
+void lttng_id_tracker_destroy(struct lttng_kernel_id_tracker *lf, bool rcu)
 {
-       struct lttng_id_tracker_rcu *p = lf->p;
+       struct lttng_kernel_id_tracker_rcu *p = lf->p;
 
-       if (!lf->p)
+       if (!p)
                return;
        rcu_assign_pointer(lf->p, NULL);
        if (rcu)
                synchronize_trace();
        lttng_id_tracker_rcu_destroy(p);
 }
+
+void lttng_id_tracker_fini(struct lttng_kernel_id_tracker *lf)
+{
+       if (!lf)
+               return;
+       lttng_id_tracker_destroy(lf, false);
+       kfree(lf->priv);
+}
This page took 0.02654 seconds and 4 git commands to generate.