Commit | Line | Data |
---|---|---|
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 | ||
19 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p) | |
20 | { | |
21 | struct lttng_ctx_field *field; | |
22 | struct lttng_ctx *ctx; | |
23 | ||
24 | if (!*ctx_p) { | |
25 | *ctx_p = kzalloc(sizeof(struct lttng_ctx), GFP_KERNEL); | |
26 | if (!*ctx_p) | |
27 | return NULL; | |
28 | } | |
29 | ctx = *ctx_p; | |
30 | if (ctx->nr_fields + 1 > ctx->allocated_fields) { | |
31 | struct lttng_ctx_field *new_fields; | |
32 | ||
0f034e0f | 33 | ctx->allocated_fields = max_t(size_t, 1, 2 * ctx->allocated_fields); |
2dccf128 MD |
34 | new_fields = kzalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field), GFP_KERNEL); |
35 | if (!new_fields) | |
36 | return NULL; | |
37 | if (ctx->fields) | |
77aefe99 | 38 | memcpy(new_fields, ctx->fields, sizeof(*ctx->fields) * ctx->nr_fields); |
2dccf128 MD |
39 | kfree(ctx->fields); |
40 | ctx->fields = new_fields; | |
41 | } | |
42 | field = &ctx->fields[ctx->nr_fields]; | |
43 | ctx->nr_fields++; | |
44 | return field; | |
45 | } | |
46 | EXPORT_SYMBOL_GPL(lttng_append_context); | |
47 | ||
48 | void lttng_destroy_context(struct lttng_ctx *ctx) | |
49 | { | |
50 | int i; | |
51 | ||
8070f5c0 MD |
52 | if (!ctx) |
53 | return; | |
9e7e4892 MD |
54 | for (i = 0; i < ctx->nr_fields; i++) { |
55 | if (ctx->fields[i].destroy) | |
56 | ctx->fields[i].destroy(&ctx->fields[i]); | |
57 | } | |
2dccf128 MD |
58 | kfree(ctx->fields); |
59 | kfree(ctx); | |
60 | } |