Check if channel has closed stream in channel poll for CPU hotplug
[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++) {
24 if (!strcmp(ctx->fields[i].event_field.name, name))
25 return 1;
26 }
27 return 0;
28}
29EXPORT_SYMBOL_GPL(lttng_find_context);
30
2dccf128
MD
31struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p)
32{
33 struct lttng_ctx_field *field;
34 struct lttng_ctx *ctx;
35
36 if (!*ctx_p) {
37 *ctx_p = kzalloc(sizeof(struct lttng_ctx), GFP_KERNEL);
38 if (!*ctx_p)
39 return NULL;
40 }
41 ctx = *ctx_p;
42 if (ctx->nr_fields + 1 > ctx->allocated_fields) {
43 struct lttng_ctx_field *new_fields;
44
0f034e0f 45 ctx->allocated_fields = max_t(size_t, 1, 2 * ctx->allocated_fields);
2dccf128
MD
46 new_fields = kzalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field), GFP_KERNEL);
47 if (!new_fields)
48 return NULL;
49 if (ctx->fields)
77aefe99 50 memcpy(new_fields, ctx->fields, sizeof(*ctx->fields) * ctx->nr_fields);
2dccf128
MD
51 kfree(ctx->fields);
52 ctx->fields = new_fields;
53 }
54 field = &ctx->fields[ctx->nr_fields];
55 ctx->nr_fields++;
56 return field;
57}
58EXPORT_SYMBOL_GPL(lttng_append_context);
59
8289661d
MD
60void lttng_remove_context_field(struct lttng_ctx **ctx_p,
61 struct lttng_ctx_field *field)
62{
63 struct lttng_ctx *ctx;
64
65 ctx = *ctx_p;
66 ctx->nr_fields--;
67 memset(&ctx->fields[ctx->nr_fields], 0, sizeof(struct lttng_ctx_field));
68}
69EXPORT_SYMBOL_GPL(lttng_remove_context_field);
70
2dccf128
MD
71void lttng_destroy_context(struct lttng_ctx *ctx)
72{
73 int i;
74
8070f5c0
MD
75 if (!ctx)
76 return;
9e7e4892
MD
77 for (i = 0; i < ctx->nr_fields; i++) {
78 if (ctx->fields[i].destroy)
79 ctx->fields[i].destroy(&ctx->fields[i]);
80 }
2dccf128
MD
81 kfree(ctx->fields);
82 kfree(ctx);
83}
This page took 0.026029 seconds and 4 git commands to generate.