| 1 | /* |
| 2 | * probes/lttng-types.c |
| 3 | * |
| 4 | * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | * |
| 6 | * LTTng types. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/seq_file.h> |
| 12 | #include <linux/jbd.h> /* tid_t */ |
| 13 | #include <linux/debugfs.h> |
| 14 | #include "lttng-types.h" |
| 15 | |
| 16 | struct dentry *lttng_types_dentry; |
| 17 | |
| 18 | #define ATYPE_ENTRY(name) [atype_##name] = #name |
| 19 | |
| 20 | const char * const astract_types[NR_ABSTRACT_TYPES] = { |
| 21 | ATYPE_ENTRY(integer), |
| 22 | ATYPE_ENTRY(enum), |
| 23 | ATYPE_ENTRY(array), |
| 24 | }; |
| 25 | |
| 26 | #define STAGE_EXPORT_ENUMS |
| 27 | #include "lttng-types.h" |
| 28 | #include "lttng-type-list.h" |
| 29 | #undef STAGE_EXPORT_ENUMS |
| 30 | |
| 31 | struct lttng_type lttng_types[] = { |
| 32 | #define STAGE_EXPORT_TYPES |
| 33 | #include "lttng-types.h" |
| 34 | #include "lttng-type-list.h" |
| 35 | #undef STAGE_EXPORT_TYPES |
| 36 | }; |
| 37 | |
| 38 | static void print_enum(struct seq_file *m, const struct lttng_enum *lttng_enum) |
| 39 | { |
| 40 | int i; |
| 41 | |
| 42 | for (i = 0; i < lttng_enum->len; i++) { |
| 43 | if (lttng_enum->entries[i].start == lttng_enum->entries[i].end) |
| 44 | seq_printf(m, "\t\t{ %llu, %s },\n", |
| 45 | lttng_enum->entries[i].start, |
| 46 | lttng_enum->entries[i].string); |
| 47 | else |
| 48 | seq_printf(m, "\t\t{ { %llu, %llu }, %s },\n", |
| 49 | lttng_enum->entries[i].start, |
| 50 | lttng_enum->entries[i].end, |
| 51 | lttng_enum->entries[i].string); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | static void print_event_type(struct seq_file *m, const struct lttng_type *type) |
| 56 | { |
| 57 | switch(type->atype) { |
| 58 | case atype_integer: |
| 59 | seq_printf(m, "type %s {\n" |
| 60 | "\tparent = %s;\n" |
| 61 | "\tsize = %u;\n" |
| 62 | "\tsigned = %u;\n" |
| 63 | "\talign = %u;\n" |
| 64 | "};\n", type->name, |
| 65 | astract_types[type->atype], |
| 66 | type->u.integer.size, |
| 67 | type->u.integer.signedness, |
| 68 | type->u.integer.alignment); |
| 69 | break; |
| 70 | case atype_enum: |
| 71 | seq_printf(m, "type %s {\n" |
| 72 | "\tparent = %s;\n" |
| 73 | "\tparent.parent = %s;\n" |
| 74 | "\tmap = {\n", |
| 75 | type->name, |
| 76 | astract_types[type->atype], |
| 77 | type->u.enumeration.parent_type); |
| 78 | print_enum(m, &type->u.enumeration.def); |
| 79 | seq_printf(m, "\t};\n" |
| 80 | "};\n"); |
| 81 | break; |
| 82 | case atype_array: |
| 83 | seq_printf(m, "type %s {\n" |
| 84 | "\tparent = %s;\n" |
| 85 | "\telem_type = %s;\n" |
| 86 | "\tlength = %u;\n" |
| 87 | "};\n", type->name, |
| 88 | astract_types[type->atype], |
| 89 | type->u.array.elem_type, |
| 90 | type->u.array.length); |
| 91 | break; |
| 92 | default: |
| 93 | seq_printf(m, "<<< unknown abstract type %s for type %s >>>\n", |
| 94 | astract_types[type->atype], |
| 95 | type->name); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | static void *lttng_seq_start(struct seq_file *m, loff_t *pos) |
| 100 | { |
| 101 | struct lttng_type *type = <tng_types[*pos]; |
| 102 | |
| 103 | if (type > <tng_types[ARRAY_SIZE(lttng_types) - 1]) |
| 104 | return NULL; |
| 105 | return type; |
| 106 | } |
| 107 | |
| 108 | static void *lttng_seq_next(struct seq_file *m, void *v, loff_t *ppos) |
| 109 | { |
| 110 | struct lttng_type *type = <tng_types[++(*ppos)]; |
| 111 | |
| 112 | if (type > <tng_types[ARRAY_SIZE(lttng_types) - 1]) |
| 113 | return NULL; |
| 114 | return type; |
| 115 | } |
| 116 | |
| 117 | static void lttng_seq_stop(struct seq_file *m, void *v) |
| 118 | { |
| 119 | } |
| 120 | |
| 121 | static int lttng_seq_show(struct seq_file *m, void *v) |
| 122 | { |
| 123 | struct lttng_type *type = v; |
| 124 | |
| 125 | print_event_type(m, type); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static const struct seq_operations lttng_types_seq_ops = { |
| 130 | .start = lttng_seq_start, |
| 131 | .next = lttng_seq_next, |
| 132 | .stop = lttng_seq_stop, |
| 133 | .show = lttng_seq_show, |
| 134 | }; |
| 135 | |
| 136 | static int |
| 137 | lttng_types_open(struct inode *inode, struct file *file) |
| 138 | { |
| 139 | return seq_open(file, <tng_types_seq_ops); |
| 140 | } |
| 141 | |
| 142 | static const struct file_operations lttng_types_fops = { |
| 143 | .open = lttng_types_open, |
| 144 | .read = seq_read, |
| 145 | .llseek = seq_lseek, |
| 146 | .release = seq_release_private, |
| 147 | }; |
| 148 | |
| 149 | static int lttng_types_init(void) |
| 150 | { |
| 151 | int ret = 0; |
| 152 | |
| 153 | lttng_types_dentry = debugfs_create_file("lttng-types", S_IWUSR, |
| 154 | NULL, NULL, <tng_types_fops); |
| 155 | if (IS_ERR(lttng_types_dentry) || !lttng_types_dentry) { |
| 156 | printk(KERN_ERR "Error creating LTTng type export file\n"); |
| 157 | ret = -ENOMEM; |
| 158 | goto error; |
| 159 | } |
| 160 | error: |
| 161 | return ret; |
| 162 | } |
| 163 | |
| 164 | module_init(lttng_types_init); |
| 165 | |
| 166 | static void lttng_types_exit(void) |
| 167 | { |
| 168 | debugfs_remove(lttng_types_dentry); |
| 169 | } |
| 170 | |
| 171 | module_exit(lttng_types_exit); |
| 172 | |
| 173 | MODULE_LICENSE("GPL and additional rights"); |
| 174 | MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>"); |
| 175 | MODULE_DESCRIPTION("LTTng types"); |