6 #include <linux/kernel.h>
8 #include <linux/debugfs.h>
9 #include <linux/uaccess.h>
11 #include <interfaces/inspector.h>
15 #include "linux-exts.h"
17 static struct dentry * v3_dir = NULL;
23 static int dfs_register_tree(struct dentry * dir, v3_inspect_node_t * root) {
24 v3_inspect_node_t * tmp_node = v3_inspection_first_child(root);
25 struct v3_inspection_value tmp_value;
28 tmp_value = v3_inspection_value(tmp_node);
30 if (tmp_value.size == 0) {
31 struct dentry * new_dir = debugfs_create_dir(tmp_value.name, dir);
32 dfs_register_tree(new_dir, tmp_node);
33 } else if (tmp_value.size == 1) {
34 debugfs_create_u8(tmp_value.name, 0644, dir, (u8 *)tmp_value.value);
35 } else if (tmp_value.size == 2) {
36 debugfs_create_u16(tmp_value.name, 0644, dir, (u16 *)tmp_value.value);
37 } else if (tmp_value.size == 4) {
38 debugfs_create_u32(tmp_value.name, 0644, dir, (u32 *)tmp_value.value);
39 } else if (tmp_value.size == 8) {
40 debugfs_create_u64(tmp_value.name, 0644, dir, (u64 *)tmp_value.value);
46 tmp_node = v3_inspection_node_next(tmp_node);
54 static int inspect_vm(struct v3_guest * guest, unsigned int cmd, unsigned long arg,
56 v3_inspect_node_t * root = v3_get_inspection_root(guest->v3_ctx);
57 struct dentry * guest_dir = NULL;
61 ERROR("No inspection root found\n");
65 guest_dir = debugfs_create_dir(guest->name, v3_dir);
67 if (!guest_dir || IS_ERR(guest_dir)) {
68 ERROR("Error Creating inspector tree for VM \"%s\"\n", guest->name);
72 dfs_register_tree(guest_dir, root);
78 static int init_inspector( void ) {
80 v3_dir = debugfs_create_dir("v3vee", NULL);
82 if (!v3_dir || IS_ERR(v3_dir)) {
83 ERROR("Error creating v3vee debugfs directory\n");
91 static int deinit_inspector( void ) {
92 debugfs_remove(v3_dir);
97 static int guest_init(struct v3_guest * guest, void ** vm_data) {
99 add_guest_ctrl(guest, V3_VM_INSPECT, inspect_vm, NULL);
103 static int guest_deinit(struct v3_guest * guest, void * vm_data) {
109 struct linux_ext inspector_ext = {
111 .init = init_inspector,
112 .deinit = deinit_inspector,
113 .guest_init = guest_init,
114 .guest_deinit = guest_deinit
118 register_extension(&inspector_ext);