Split ID tracker into public/private structures
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 3 May 2021 16:46:04 +0000 (12:46 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 4 May 2021 14:38:39 +0000 (10:38 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ic17da38eb96d734110b59656d0fedce1bacd570a

include/lttng/events-internal.h
include/lttng/events.h
include/lttng/tracepoint-event-impl.h
src/lttng-events.c
src/lttng-tracker-id.c

index 177198870da16fd2a45c948861e57ddf7abcf67e..869ea70d050a6f41fac612af18a6cc09aa57995d 100644 (file)
@@ -415,6 +415,24 @@ struct lttng_id_hash_node {
        int id;
 };
 
+enum tracker_type {
+       TRACKER_PID,
+       TRACKER_VPID,
+       TRACKER_UID,
+       TRACKER_VUID,
+       TRACKER_GID,
+       TRACKER_VGID,
+
+       TRACKER_UNKNOWN,
+};
+
+struct lttng_kernel_id_tracker_private {
+       struct lttng_kernel_id_tracker *pub;    /* Public interface */
+
+       struct lttng_kernel_session *session;
+       enum tracker_type tracker_type;
+};
+
 extern struct lttng_kernel_ctx *lttng_static_ctx;
 
 static inline
@@ -1062,10 +1080,14 @@ int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
                struct channel *chan, bool *coherent);
 
 int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node);
-int lttng_id_tracker_empty_set(struct lttng_id_tracker *lf);
-void lttng_id_tracker_destroy(struct lttng_id_tracker *lf, bool rcu);
-int lttng_id_tracker_add(struct lttng_id_tracker *lf, int id);
-int lttng_id_tracker_del(struct lttng_id_tracker *lf, int id);
+int lttng_id_tracker_empty_set(struct lttng_kernel_id_tracker *lf);
+int lttng_id_tracker_init(struct lttng_kernel_id_tracker *lf,
+               struct lttng_kernel_session *session,
+               enum tracker_type type);
+void lttng_id_tracker_fini(struct lttng_kernel_id_tracker *lf);
+void lttng_id_tracker_destroy(struct lttng_kernel_id_tracker *lf, bool rcu);
+int lttng_id_tracker_add(struct lttng_kernel_id_tracker *lf, int id);
+int lttng_id_tracker_del(struct lttng_kernel_id_tracker *lf, int id);
 
 int lttng_session_track_id(struct lttng_kernel_session *session,
                enum tracker_type tracker_type, int id);
index c6c46b4acbdcab8ce8daaa4f1e039143f74997d5..157aaca7ad07e7f792ebd44305abe4e70c1bb106 100644 (file)
@@ -445,31 +445,20 @@ struct lttng_dynamic_len_stack {
 DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack);
 
 /*
- * struct lttng_id_tracker declared in header due to deferencing of *v
+ * struct lttng_kernel_id_tracker declared in header due to deferencing of *v
  * in RCU_INITIALIZER(v).
  */
 #define LTTNG_ID_HASH_BITS     6
 #define LTTNG_ID_TABLE_SIZE    (1 << LTTNG_ID_HASH_BITS)
 
-enum tracker_type {
-       TRACKER_PID,
-       TRACKER_VPID,
-       TRACKER_UID,
-       TRACKER_VUID,
-       TRACKER_GID,
-       TRACKER_VGID,
-
-       TRACKER_UNKNOWN,
-};
-
-struct lttng_id_tracker_rcu {
+struct lttng_kernel_id_tracker_rcu {
        struct hlist_head id_hash[LTTNG_ID_TABLE_SIZE];
 };
 
-struct lttng_id_tracker {
-       struct lttng_kernel_session *session;
-       enum tracker_type tracker_type;
-       struct lttng_id_tracker_rcu *p; /* RCU dereferenced. */
+struct lttng_kernel_id_tracker {
+       struct lttng_kernel_id_tracker_private *priv;   /* Private API */
+
+       struct lttng_kernel_id_tracker_rcu *p;  /* RCU dereferenced. */
 };
 
 struct lttng_kernel_session_private;
@@ -479,17 +468,17 @@ struct lttng_kernel_session {
 
        int active;                     /* Is trace session active ? */
 
-       struct lttng_id_tracker pid_tracker;
-       struct lttng_id_tracker vpid_tracker;
-       struct lttng_id_tracker uid_tracker;
-       struct lttng_id_tracker vuid_tracker;
-       struct lttng_id_tracker gid_tracker;
-       struct lttng_id_tracker vgid_tracker;
+       struct lttng_kernel_id_tracker pid_tracker;
+       struct lttng_kernel_id_tracker vpid_tracker;
+       struct lttng_kernel_id_tracker uid_tracker;
+       struct lttng_kernel_id_tracker vuid_tracker;
+       struct lttng_kernel_id_tracker gid_tracker;
+       struct lttng_kernel_id_tracker vgid_tracker;
 };
 
 int lttng_kernel_probe_register(struct lttng_kernel_probe_desc *desc);
 void lttng_kernel_probe_unregister(struct lttng_kernel_probe_desc *desc);
 
-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);
 
 #endif /* _LTTNG_EVENTS_H */
index 83d65e6f1236a668b92d8a711fa0c7c78d3a7bfe..4df71ff2b0b47a11e72fd380844ba5b4569b2a6d 100644 (file)
@@ -1023,8 +1023,8 @@ static void __event_probe__##_name(_data_proto)                                           \
                struct lttng_kernel_event_recorder *__event_recorder =                  \
                        container_of(__event, struct lttng_kernel_event_recorder, parent); \
                struct lttng_channel *__chan = __event_recorder->chan;                  \
-               struct lttng_kernel_session *__session = __chan->session;                       \
-               struct lttng_id_tracker_rcu *__lf;                                      \
+               struct lttng_kernel_session *__session = __chan->session;               \
+               struct lttng_kernel_id_tracker_rcu *__lf;                               \
                                                                                        \
                if (!_TP_SESSION_CHECK(session, __session))                             \
                        return;                                                         \
index 842beac1d6844377da47778dc7f41625b6b06cac..2c007ad4d339fe2570b088c95a11920291aae603 100644 (file)
@@ -185,22 +185,30 @@ struct lttng_kernel_session *lttng_session_create(void)
                INIT_HLIST_HEAD(&session_priv->events_ht.table[i]);
        list_add(&session_priv->list, &sessions);
 
-       session->pid_tracker.session = session;
-       session->pid_tracker.tracker_type = TRACKER_PID;
-       session->vpid_tracker.session = session;
-       session->vpid_tracker.tracker_type = TRACKER_VPID;
-       session->uid_tracker.session = session;
-       session->uid_tracker.tracker_type = TRACKER_UID;
-       session->vuid_tracker.session = session;
-       session->vuid_tracker.tracker_type = TRACKER_VUID;
-       session->gid_tracker.session = session;
-       session->gid_tracker.tracker_type = TRACKER_GID;
-       session->vgid_tracker.session = session;
-       session->vgid_tracker.tracker_type = TRACKER_VGID;
+       if (lttng_id_tracker_init(&session->pid_tracker, session, TRACKER_PID))
+               goto tracker_alloc_error;
+       if (lttng_id_tracker_init(&session->vpid_tracker, session, TRACKER_VPID))
+               goto tracker_alloc_error;
+       if (lttng_id_tracker_init(&session->uid_tracker, session, TRACKER_UID))
+               goto tracker_alloc_error;
+       if (lttng_id_tracker_init(&session->vuid_tracker, session, TRACKER_VUID))
+               goto tracker_alloc_error;
+       if (lttng_id_tracker_init(&session->gid_tracker, session, TRACKER_GID))
+               goto tracker_alloc_error;
+       if (lttng_id_tracker_init(&session->vgid_tracker, session, TRACKER_VGID))
+               goto tracker_alloc_error;
+
        mutex_unlock(&sessions_mutex);
 
        return session;
 
+tracker_alloc_error:
+       lttng_id_tracker_fini(&session->pid_tracker);
+       lttng_id_tracker_fini(&session->vpid_tracker);
+       lttng_id_tracker_fini(&session->uid_tracker);
+       lttng_id_tracker_fini(&session->vuid_tracker);
+       lttng_id_tracker_fini(&session->gid_tracker);
+       lttng_id_tracker_fini(&session->vgid_tracker);
 err_free_cache:
        kfree(metadata_cache);
 err_free_session_private:
@@ -376,12 +384,12 @@ void lttng_session_destroy(struct lttng_kernel_session *session)
        list_for_each_entry(metadata_stream, &session->priv->metadata_cache->metadata_stream, list)
                _lttng_metadata_channel_hangup(metadata_stream);
        mutex_unlock(&session->priv->metadata_cache->lock);
-       lttng_id_tracker_destroy(&session->pid_tracker, false);
-       lttng_id_tracker_destroy(&session->vpid_tracker, false);
-       lttng_id_tracker_destroy(&session->uid_tracker, false);
-       lttng_id_tracker_destroy(&session->vuid_tracker, false);
-       lttng_id_tracker_destroy(&session->gid_tracker, false);
-       lttng_id_tracker_destroy(&session->vgid_tracker, false);
+       lttng_id_tracker_fini(&session->pid_tracker);
+       lttng_id_tracker_fini(&session->vpid_tracker);
+       lttng_id_tracker_fini(&session->uid_tracker);
+       lttng_id_tracker_fini(&session->vuid_tracker);
+       lttng_id_tracker_fini(&session->gid_tracker);
+       lttng_id_tracker_fini(&session->vgid_tracker);
        kref_put(&session->priv->metadata_cache->refcount, metadata_cache_destroy);
        list_del(&session->priv->list);
        mutex_unlock(&sessions_mutex);
@@ -1644,7 +1652,7 @@ void _lttng_event_destroy(struct lttng_kernel_event_common *event)
        }
 }
 
-struct lttng_id_tracker *get_tracker(struct lttng_kernel_session *session,
+struct lttng_kernel_id_tracker *get_tracker(struct lttng_kernel_session *session,
                enum tracker_type tracker_type)
 {
        switch (tracker_type) {
@@ -1669,7 +1677,7 @@ struct lttng_id_tracker *get_tracker(struct lttng_kernel_session *session,
 int lttng_session_track_id(struct lttng_kernel_session *session,
                enum tracker_type tracker_type, int id)
 {
-       struct lttng_id_tracker *tracker;
+       struct lttng_kernel_id_tracker *tracker;
        int ret;
 
        tracker = get_tracker(session, tracker_type);
@@ -1692,7 +1700,7 @@ int lttng_session_track_id(struct lttng_kernel_session *session,
 int lttng_session_untrack_id(struct lttng_kernel_session *session,
                enum tracker_type tracker_type, int id)
 {
-       struct lttng_id_tracker *tracker;
+       struct lttng_kernel_id_tracker *tracker;
        int ret;
 
        tracker = get_tracker(session, tracker_type);
@@ -1714,8 +1722,8 @@ int lttng_session_untrack_id(struct lttng_kernel_session *session,
 static
 void *id_list_start(struct seq_file *m, loff_t *pos)
 {
-       struct lttng_id_tracker *id_tracker = m->private;
-       struct lttng_id_tracker_rcu *id_tracker_p = id_tracker->p;
+       struct lttng_kernel_id_tracker *id_tracker = m->private;
+       struct lttng_kernel_id_tracker_rcu *id_tracker_p = id_tracker->p;
        struct lttng_id_hash_node *e;
        int iter = 0, i;
 
@@ -1744,8 +1752,8 @@ void *id_list_start(struct seq_file *m, loff_t *pos)
 static
 void *id_list_next(struct seq_file *m, void *p, loff_t *ppos)
 {
-       struct lttng_id_tracker *id_tracker = m->private;
-       struct lttng_id_tracker_rcu *id_tracker_p = id_tracker->p;
+       struct lttng_kernel_id_tracker *id_tracker = m->private;
+       struct lttng_kernel_id_tracker_rcu *id_tracker_p = id_tracker->p;
        struct lttng_id_hash_node *e;
        int iter = 0, i;
 
@@ -1779,8 +1787,8 @@ void id_list_stop(struct seq_file *m, void *p)
 static
 int id_list_show(struct seq_file *m, void *p)
 {
-       struct lttng_id_tracker *id_tracker = m->private;
-       struct lttng_id_tracker_rcu *id_tracker_p = id_tracker->p;
+       struct lttng_kernel_id_tracker *id_tracker = m->private;
+       struct lttng_kernel_id_tracker_rcu *id_tracker_p = id_tracker->p;
        int id;
 
        if (p == id_tracker_p) {
@@ -1791,7 +1799,7 @@ int id_list_show(struct seq_file *m, void *p)
 
                id = lttng_id_tracker_get_node_id(e);
        }
-       switch (id_tracker->tracker_type) {
+       switch (id_tracker->priv->tracker_type) {
        case TRACKER_PID:
                seq_printf(m,   "process { pid = %d; };\n", id);
                break;
@@ -1834,13 +1842,13 @@ static
 int lttng_tracker_ids_list_release(struct inode *inode, struct file *file)
 {
        struct seq_file *m = file->private_data;
-       struct lttng_id_tracker *id_tracker = m->private;
+       struct lttng_kernel_id_tracker *id_tracker = m->private;
        int ret;
 
        WARN_ON_ONCE(!id_tracker);
        ret = seq_release(inode, file);
        if (!ret)
-               fput(id_tracker->session->priv->file);
+               fput(id_tracker->priv->session->priv->file);
        return ret;
 }
 
index 4fc23b85d7e1adeeb16bd7291ecbb044df60a83a..8c1b008d2b2fd1b379eab52f7f31998d160ca916 100644 (file)
@@ -41,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;
@@ -56,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;
@@ -69,11 +69,11 @@ 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;
@@ -137,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)
@@ -160,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;
 
@@ -177,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)
@@ -191,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)
 {
-       struct lttng_id_tracker_rcu *p = lf->p;
+       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_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.033109 seconds and 4 git commands to generate.