Update readme
[lttng-modules.git] / ltt-context.c
CommitLineData
2dccf128
MD
1/*
2 * ltt-context.c
3 *
4 * Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng trace/channel/event context management.
17baffe2
MD
7 *
8 * Dual LGPL v2.1/GPL v2 license.
2dccf128
MD
9 */
10
11#include <linux/module.h>
12#include <linux/list.h>
13#include <linux/mutex.h>
14#include <linux/slab.h>
15#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
16#include "ltt-events.h"
17#include "ltt-tracer.h"
18
44252f0f
MD
19int lttng_find_context(struct lttng_ctx *ctx, const char *name)
20{
21 unsigned int i;
22
23 for (i = 0; i < ctx->nr_fields; i++) {
4b58a8e4
MD
24 /* Skip allocated (but non-initialized) contexts */
25 if (!ctx->fields[i].event_field.name)
26 continue;
44252f0f
MD
27 if (!strcmp(ctx->fields[i].event_field.name, name))
28 return 1;
29 }
30 return 0;
31}
32EXPORT_SYMBOL_GPL(lttng_find_context);
33
2dccf128
MD
34struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p)
35{
36 struct lttng_ctx_field *field;
37 struct lttng_ctx *ctx;
38
39 if (!*ctx_p) {
40 *ctx_p = kzalloc(sizeof(struct lttng_ctx), GFP_KERNEL);
41 if (!*ctx_p)
42 return NULL;
43 }
44 ctx = *ctx_p;
45 if (ctx->nr_fields + 1 > ctx->allocated_fields) {
46 struct lttng_ctx_field *new_fields;
47
0f034e0f 48 ctx->allocated_fields = max_t(size_t, 1, 2 * ctx->allocated_fields);
2dccf128
MD
49 new_fields = kzalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field), GFP_KERNEL);
50 if (!new_fields)
51 return NULL;
52 if (ctx->fields)
77aefe99 53 memcpy(new_fields, ctx->fields, sizeof(*ctx->fields) * ctx->nr_fields);
2dccf128
MD
54 kfree(ctx->fields);
55 ctx->fields = new_fields;
56 }
57 field = &ctx->fields[ctx->nr_fields];
58 ctx->nr_fields++;
59 return field;
60}
61EXPORT_SYMBOL_GPL(lttng_append_context);
62
8289661d
MD
63void lttng_remove_context_field(struct lttng_ctx **ctx_p,
64 struct lttng_ctx_field *field)
65{
66 struct lttng_ctx *ctx;
67
68 ctx = *ctx_p;
69 ctx->nr_fields--;
70 memset(&ctx->fields[ctx->nr_fields], 0, sizeof(struct lttng_ctx_field));
71}
72EXPORT_SYMBOL_GPL(lttng_remove_context_field);
73
2dccf128
MD
74void lttng_destroy_context(struct lttng_ctx *ctx)
75{
76 int i;
77
8070f5c0
MD
78 if (!ctx)
79 return;
9e7e4892
MD
80 for (i = 0; i < ctx->nr_fields; i++) {
81 if (ctx->fields[i].destroy)
82 ctx->fields[i].destroy(&ctx->fields[i]);
83 }
2dccf128
MD
84 kfree(ctx->fields);
85 kfree(ctx);
86}
This page took 0.027479 seconds and 4 git commands to generate.