The table of kernel taint flags has been extended to include the flag name, and it has been exposed in the koops header so other compilation units can use it.
Signed-off-by: Martin Milata mmilata@redhat.com --- lib/koops_stacktrace.c | 83 ++++++++++++++++++++++---------------------------- lib/koops_stacktrace.h | 11 +++++++ 2 files changed, 47 insertions(+), 47 deletions(-)
diff --git a/lib/koops_stacktrace.c b/lib/koops_stacktrace.c index e094bf6..822d99a 100644 --- a/lib/koops_stacktrace.c +++ b/lib/koops_stacktrace.c @@ -26,6 +26,31 @@ #include <string.h> #include <stddef.h>
+/* http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/kernel/... */ + +#define FLAG_OFFSET(flag) offsetof(struct sr_koops_stacktrace, taint_ ## flag) +#define FLAG(letter, name) { letter, FLAG_OFFSET(name), #name } + +struct sr_taint_flag sr_flags[] = { + FLAG('P', module_proprietary), + FLAG('F', forced_module), + FLAG('S', smp_unsafe), + FLAG('R', forced_removal), + FLAG('M', mce), + FLAG('B', page_release), + FLAG('U', userspace), + FLAG('D', died_recently), + FLAG('A', acpi_overridden), + FLAG('W', warning), + FLAG('C', staging_driver), + FLAG('I', firmware_workaround), + FLAG('O', module_out_of_tree), + { '\0', 0, NULL} /* sentinel */ +}; + +#undef FLAG +#undef FLAG_OFFSET + struct sr_koops_stacktrace * sr_koops_stacktrace_new() { @@ -103,32 +128,6 @@ sr_koops_stacktrace_remove_frame(struct sr_koops_stacktrace *stacktrace,
}
-struct taint_flag { - char letter; - size_t member_offset; -}; - -/* http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/kernel/... */ - -#define FLAG_OFFSET(flag) offsetof(struct sr_koops_stacktrace, taint_ ## flag) -static struct taint_flag flags[] = { - { 'P', FLAG_OFFSET(module_proprietary) }, - { 'F', FLAG_OFFSET(forced_module) }, - { 'S', FLAG_OFFSET(smp_unsafe) }, - { 'R', FLAG_OFFSET(forced_removal) }, - { 'M', FLAG_OFFSET(mce) }, - { 'B', FLAG_OFFSET(page_release) }, - { 'U', FLAG_OFFSET(userspace) }, - { 'D', FLAG_OFFSET(died_recently) }, - { 'A', FLAG_OFFSET(acpi_overridden) }, - { 'W', FLAG_OFFSET(warning) }, - { 'C', FLAG_OFFSET(staging_driver) }, - { 'I', FLAG_OFFSET(firmware_workaround) }, - { 'O', FLAG_OFFSET(module_out_of_tree) }, - { '\0', 0 /* sentinel */ } -}; -#undef FLAG_OFFSET - /* Based on function kernel_tainted_short from abrt/src/lib/kernel.c */ static bool parse_taint_flags(const char *input, struct sr_koops_stacktrace *stacktrace) @@ -145,8 +144,8 @@ parse_taint_flags(const char *input, struct sr_koops_stacktrace *stacktrace) if (tainted[0] >= 'A' && tainted[0] <= 'Z') { /* set the appropriate flag */ - struct taint_flag *f; - for (f = flags; f->letter; f++) + struct sr_taint_flag *f; + for (f = sr_flags; f->letter; f++) { if (tainted[0] == f->letter) { @@ -373,25 +372,15 @@ taint_flags_to_json(struct sr_koops_stacktrace *stacktrace) { struct sr_strbuf *strbuf = sr_strbuf_new();
-#define FLAG_APPEND(flag) \ - if (stacktrace->taint_ ## flag) \ - sr_strbuf_append_strf(strbuf, ", "" #flag ""\n"); \ - - FLAG_APPEND(module_proprietary) - FLAG_APPEND(forced_module) - FLAG_APPEND(forced_removal) - FLAG_APPEND(smp_unsafe) - FLAG_APPEND(mce) - FLAG_APPEND(page_release) - FLAG_APPEND(userspace) - FLAG_APPEND(died_recently) - FLAG_APPEND(acpi_overridden) - FLAG_APPEND(warning) - FLAG_APPEND(staging_driver) - FLAG_APPEND(firmware_workaround) - FLAG_APPEND(module_out_of_tree) - -#undef FLAG_APPEND + struct sr_taint_flag *f; + for (f = sr_flags; f->letter; f++) + { + bool val = *(bool *)((void *)stacktrace + f->member_offset); + if (val == true) + { + sr_strbuf_append_strf(strbuf, ", "%s"\n", f->name); + } + }
if (strbuf->len == 0) return sr_strdup("[]"); diff --git a/lib/koops_stacktrace.h b/lib/koops_stacktrace.h index 4d77b31..580610f 100644 --- a/lib/koops_stacktrace.h +++ b/lib/koops_stacktrace.h @@ -33,6 +33,7 @@ extern "C" { #include "report_type.h" #include <stdbool.h> #include <inttypes.h> +#include <stddef.h>
struct sr_location;
@@ -158,6 +159,16 @@ sr_koops_stacktrace_get_reason(struct sr_koops_stacktrace *stacktrace); char * sr_koops_stacktrace_to_json(struct sr_koops_stacktrace *stacktrace);
+ +/* TODO: this needs to go in a _private_ header and should not be exported */ +struct sr_taint_flag +{ + char letter; + size_t member_offset; + char *name; +}; +extern struct sr_taint_flag sr_flags[]; + #ifdef __cplusplus } #endif
Closes #85.
Signed-off-by: Martin Milata mmilata@redhat.com --- python/py_koops_stacktrace.c | 28 ++++++++++++++++++++++++++++ python/py_koops_stacktrace.h | 3 +++ tests/python/koops.py | 14 ++++++++++++++ 3 files changed, 45 insertions(+)
diff --git a/python/py_koops_stacktrace.c b/python/py_koops_stacktrace.c index 39c43c9..301aaf2 100644 --- a/python/py_koops_stacktrace.c +++ b/python/py_koops_stacktrace.c @@ -1,5 +1,6 @@ #include "py_koops_frame.h" #include "py_koops_stacktrace.h" +#include "py_common.h" #include "lib/strbuf.h" #include "lib/koops_frame.h" #include "lib/koops_stacktrace.h" @@ -25,6 +26,8 @@ "specified, the result includes only that much topmost frames.\n"
#define b_frames_doc "A list containing frames" +#define b_taint_flags_doc "Dictionary of kernel taint flags. Keys are the flag names,\n" \ + "values are booleans indicating whether the flag is set." #define b_modules_doc "Modules loaded at the time of the event (list of strings)"
@@ -49,6 +52,7 @@ static PyGetSetDef koops_stacktrace_getset[] = { { (char*)"modules", sr_py_koops_stacktrace_get_modules, sr_py_koops_stacktrace_set_modules, (char*)b_modules_doc, NULL }, + { (char*)"taint_flags", sr_py_koops_stacktrace_get_taint_flags, sr_py_koops_stacktrace_set_taint_flags, (char*)b_taint_flags_doc, NULL }, { NULL }, };
@@ -170,6 +174,30 @@ sr_py_koops_stacktrace_set_modules(PyObject *self, PyObject *rhs, void *data) }
PyObject * +sr_py_koops_stacktrace_get_taint_flags(PyObject *self, void *data) +{ + struct sr_koops_stacktrace *st = ((struct sr_py_koops_stacktrace*)self)->stacktrace; + PyObject *flags = PyDict_New(); + + struct sr_taint_flag *f; + for (f = sr_flags; f->letter; f++) + { + PyObject *val = MEMB_T(bool, st, f->member_offset) ? Py_True : Py_False; + if (PyDict_SetItemString(flags, f->name, val) == -1) + return NULL; + } + + return flags; +} + +int +sr_py_koops_stacktrace_set_taint_flags(PyObject *self, PyObject *rhs, void *data) +{ + PyErr_SetString(PyExc_NotImplementedError, "Setting taint flags is not implemented."); + return -1; +} + +PyObject * koops_frame_linked_list_to_python_list(struct sr_koops_stacktrace *stacktrace) { PyObject *result = PyList_New(0); diff --git a/python/py_koops_stacktrace.h b/python/py_koops_stacktrace.h index 28d7cba..100be66 100644 --- a/python/py_koops_stacktrace.h +++ b/python/py_koops_stacktrace.h @@ -38,6 +38,7 @@ struct sr_py_koops_stacktrace { PyObject_HEAD PyObject *frames; + PyObject *taint_flags; struct sr_koops_stacktrace *stacktrace; };
@@ -55,6 +56,8 @@ PyObject *sr_py_koops_stacktrace_str(PyObject *self); /* getters & setters */ PyObject *sr_py_koops_stacktrace_get_modules(PyObject *self, void *data); int sr_py_koops_stacktrace_set_modules(PyObject *self, PyObject *rhs, void *data); +PyObject *sr_py_koops_stacktrace_get_taint_flags(PyObject *self, void *data); +int sr_py_koops_stacktrace_set_taint_flags(PyObject *self, PyObject *rhs, void *data);
/* methods */ PyObject *sr_py_koops_stacktrace_dup(PyObject *self, PyObject *args); diff --git a/tests/python/koops.py b/tests/python/koops.py index 4f4cafa..58189c8 100755 --- a/tests/python/koops.py +++ b/tests/python/koops.py @@ -41,6 +41,20 @@ class TestKerneloops(BindingsTestCase): #self.assertEqual(len(self.koops.modules), 2) self.assertRaises(NotImplementedError, self.koops.__delattr__, 'modules')
+ def test_correct_taint_flags(self): + for val in self.koops.taint_flags.values(): + self.assertFalse(val); + path = '../kerneloopses/rhbz-827868-modified' + if not os.path.isfile(path): + path = '../' + path + with file(path) as f: + contents = f.read() + tainted_koops = satyr.Kerneloops(contents) + + true_flags = { f for (f, v) in tainted_koops.taint_flags.items() if v == True} + self.assertEqual(true_flags, + set(['module_proprietary', 'page_release', 'died_recently', 'module_out_of_tree'])) + def test_dup(self): dup = self.koops.dup() self.assertNotEqual(id(dup.frames), id(self.koops.frames))
Ack. Pushed.
On 06/07/2013 12:48 PM, Martin Milata wrote:
The table of kernel taint flags has been extended to include the flag name, and it has been exposed in the koops header so other compilation units can use it.
Signed-off-by: Martin Milata mmilata@redhat.com
lib/koops_stacktrace.c | 83 ++++++++++++++++++++++---------------------------- lib/koops_stacktrace.h | 11 +++++++ 2 files changed, 47 insertions(+), 47 deletions(-)
diff --git a/lib/koops_stacktrace.c b/lib/koops_stacktrace.c index e094bf6..822d99a 100644 --- a/lib/koops_stacktrace.c +++ b/lib/koops_stacktrace.c @@ -26,6 +26,31 @@ #include <string.h> #include <stddef.h>
+/* http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/kernel/... */
+#define FLAG_OFFSET(flag) offsetof(struct sr_koops_stacktrace, taint_ ## flag) +#define FLAG(letter, name) { letter, FLAG_OFFSET(name), #name }
+struct sr_taint_flag sr_flags[] = {
- FLAG('P', module_proprietary),
- FLAG('F', forced_module),
- FLAG('S', smp_unsafe),
- FLAG('R', forced_removal),
- FLAG('M', mce),
- FLAG('B', page_release),
- FLAG('U', userspace),
- FLAG('D', died_recently),
- FLAG('A', acpi_overridden),
- FLAG('W', warning),
- FLAG('C', staging_driver),
- FLAG('I', firmware_workaround),
- FLAG('O', module_out_of_tree),
- { '\0', 0, NULL} /* sentinel */
+};
+#undef FLAG +#undef FLAG_OFFSET
struct sr_koops_stacktrace * sr_koops_stacktrace_new() { @@ -103,32 +128,6 @@ sr_koops_stacktrace_remove_frame(struct sr_koops_stacktrace *stacktrace,
}
-struct taint_flag {
- char letter;
- size_t member_offset;
-};
-/* http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/kernel/... */
-#define FLAG_OFFSET(flag) offsetof(struct sr_koops_stacktrace, taint_ ## flag) -static struct taint_flag flags[] = {
- { 'P', FLAG_OFFSET(module_proprietary) },
- { 'F', FLAG_OFFSET(forced_module) },
- { 'S', FLAG_OFFSET(smp_unsafe) },
- { 'R', FLAG_OFFSET(forced_removal) },
- { 'M', FLAG_OFFSET(mce) },
- { 'B', FLAG_OFFSET(page_release) },
- { 'U', FLAG_OFFSET(userspace) },
- { 'D', FLAG_OFFSET(died_recently) },
- { 'A', FLAG_OFFSET(acpi_overridden) },
- { 'W', FLAG_OFFSET(warning) },
- { 'C', FLAG_OFFSET(staging_driver) },
- { 'I', FLAG_OFFSET(firmware_workaround) },
- { 'O', FLAG_OFFSET(module_out_of_tree) },
- { '\0', 0 /* sentinel */ }
-}; -#undef FLAG_OFFSET
/* Based on function kernel_tainted_short from abrt/src/lib/kernel.c */ static bool parse_taint_flags(const char *input, struct sr_koops_stacktrace *stacktrace) @@ -145,8 +144,8 @@ parse_taint_flags(const char *input, struct sr_koops_stacktrace *stacktrace) if (tainted[0] >= 'A' && tainted[0] <= 'Z') { /* set the appropriate flag */
struct taint_flag *f;
for (f = flags; f->letter; f++)
struct sr_taint_flag *f;
for (f = sr_flags; f->letter; f++) { if (tainted[0] == f->letter) {
@@ -373,25 +372,15 @@ taint_flags_to_json(struct sr_koops_stacktrace *stacktrace) { struct sr_strbuf *strbuf = sr_strbuf_new();
-#define FLAG_APPEND(flag) \
- if (stacktrace->taint_ ## flag) \
sr_strbuf_append_strf(strbuf, ", \"" #flag "\"\n"); \
- FLAG_APPEND(module_proprietary)
- FLAG_APPEND(forced_module)
- FLAG_APPEND(forced_removal)
- FLAG_APPEND(smp_unsafe)
- FLAG_APPEND(mce)
- FLAG_APPEND(page_release)
- FLAG_APPEND(userspace)
- FLAG_APPEND(died_recently)
- FLAG_APPEND(acpi_overridden)
- FLAG_APPEND(warning)
- FLAG_APPEND(staging_driver)
- FLAG_APPEND(firmware_workaround)
- FLAG_APPEND(module_out_of_tree)
-#undef FLAG_APPEND
struct sr_taint_flag *f;
for (f = sr_flags; f->letter; f++)
{
bool val = *(bool *)((void *)stacktrace + f->member_offset);
if (val == true)
{
sr_strbuf_append_strf(strbuf, ", \"%s\"\n", f->name);
}
}
if (strbuf->len == 0) return sr_strdup("[]");
diff --git a/lib/koops_stacktrace.h b/lib/koops_stacktrace.h index 4d77b31..580610f 100644 --- a/lib/koops_stacktrace.h +++ b/lib/koops_stacktrace.h @@ -33,6 +33,7 @@ extern "C" { #include "report_type.h" #include <stdbool.h> #include <inttypes.h> +#include <stddef.h>
struct sr_location;
@@ -158,6 +159,16 @@ sr_koops_stacktrace_get_reason(struct sr_koops_stacktrace *stacktrace); char * sr_koops_stacktrace_to_json(struct sr_koops_stacktrace *stacktrace);
+/* TODO: this needs to go in a _private_ header and should not be exported */ +struct sr_taint_flag +{
- char letter;
- size_t member_offset;
- char *name;
+}; +extern struct sr_taint_flag sr_flags[];
#ifdef __cplusplus } #endif
crash-catcher@lists.fedorahosted.org