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
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);
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;
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 */
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; \
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:
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);
}
}
-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) {
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);
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);
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;
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;
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) {
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;
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;
}
* 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;
}
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;
/*
* 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;
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)
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;
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)
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);
+}