4 * LTTng trace/channel/event context management.
6 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/module.h>
24 #include <linux/list.h>
25 #include <linux/mutex.h>
26 #include <linux/slab.h>
27 #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
28 #include "lttng-events.h"
29 #include "lttng-tracer.h"
31 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
)
35 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
36 /* Skip allocated (but non-initialized) contexts */
37 if (!ctx
->fields
[i
].event_field
.name
)
39 if (!strcmp(ctx
->fields
[i
].event_field
.name
, name
))
44 EXPORT_SYMBOL_GPL(lttng_find_context
);
47 * Note: as we append context information, the pointer location may change.
49 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
)
51 struct lttng_ctx_field
*field
;
52 struct lttng_ctx
*ctx
;
55 *ctx_p
= kzalloc(sizeof(struct lttng_ctx
), GFP_KERNEL
);
60 if (ctx
->nr_fields
+ 1 > ctx
->allocated_fields
) {
61 struct lttng_ctx_field
*new_fields
;
63 ctx
->allocated_fields
= max_t(size_t, 1, 2 * ctx
->allocated_fields
);
64 new_fields
= kzalloc(ctx
->allocated_fields
* sizeof(struct lttng_ctx_field
), GFP_KERNEL
);
68 memcpy(new_fields
, ctx
->fields
, sizeof(*ctx
->fields
) * ctx
->nr_fields
);
70 ctx
->fields
= new_fields
;
72 field
= &ctx
->fields
[ctx
->nr_fields
];
76 EXPORT_SYMBOL_GPL(lttng_append_context
);
79 * Remove last context field.
81 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
82 struct lttng_ctx_field
*field
)
84 struct lttng_ctx
*ctx
;
88 WARN_ON_ONCE(&ctx
->fields
[ctx
->nr_fields
] != field
);
89 memset(&ctx
->fields
[ctx
->nr_fields
], 0, sizeof(struct lttng_ctx_field
));
91 EXPORT_SYMBOL_GPL(lttng_remove_context_field
);
93 void lttng_destroy_context(struct lttng_ctx
*ctx
)
99 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
100 if (ctx
->fields
[i
].destroy
)
101 ctx
->fields
[i
].destroy(&ctx
->fields
[i
]);