4 * Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * LTTng trace/channel/event context management.
8 * Dual LGPL v2.1/GPL v2 license.
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"
19 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
)
23 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
24 if (!strcmp(ctx
->fields
[i
].event_field
.name
, name
))
29 EXPORT_SYMBOL_GPL(lttng_find_context
);
31 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
)
33 struct lttng_ctx_field
*field
;
34 struct lttng_ctx
*ctx
;
37 *ctx_p
= kzalloc(sizeof(struct lttng_ctx
), GFP_KERNEL
);
42 if (ctx
->nr_fields
+ 1 > ctx
->allocated_fields
) {
43 struct lttng_ctx_field
*new_fields
;
45 ctx
->allocated_fields
= max_t(size_t, 1, 2 * ctx
->allocated_fields
);
46 new_fields
= kzalloc(ctx
->allocated_fields
* sizeof(struct lttng_ctx_field
), GFP_KERNEL
);
50 memcpy(new_fields
, ctx
->fields
, sizeof(*ctx
->fields
) * ctx
->nr_fields
);
52 ctx
->fields
= new_fields
;
54 field
= &ctx
->fields
[ctx
->nr_fields
];
58 EXPORT_SYMBOL_GPL(lttng_append_context
);
60 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
61 struct lttng_ctx_field
*field
)
63 struct lttng_ctx
*ctx
;
67 memset(&ctx
->fields
[ctx
->nr_fields
], 0, sizeof(struct lttng_ctx_field
));
69 EXPORT_SYMBOL_GPL(lttng_remove_context_field
);
71 void lttng_destroy_context(struct lttng_ctx
*ctx
)
77 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
78 if (ctx
->fields
[i
].destroy
)
79 ctx
->fields
[i
].destroy(&ctx
->fields
[i
]);