Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel' of newskysaw.cs.northwestern.edu:/home/palacios/palacios into...
[palacios.git] / linux_module / inspector.c
1 /* 
2  * DebugFS interface
3  * (c) Jack Lange, 2011
4  */
5
6 #include <linux/kernel.h>
7 #include <linux/fs.h>
8 #include <linux/debugfs.h>
9 #include <linux/uaccess.h>
10
11 #include <interfaces/inspector.h>
12
13 #include "palacios.h"
14 #include "vm.h"
15 #include "linux-exts.h"
16
17 static struct dentry * v3_dir = NULL;
18
19
20
21
22
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;
26
27     while (tmp_node) {
28         tmp_value = v3_inspection_value(tmp_node);
29
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);
41         } else {
42
43             // buffer
44         }
45
46         tmp_node = v3_inspection_node_next(tmp_node);
47
48     }
49
50     return 0;
51 }
52
53
54 static int inspect_vm(struct v3_guest * guest, unsigned int cmd, unsigned long arg,
55                       void * priv_data) {
56     v3_inspect_node_t * root = v3_get_inspection_root(guest->v3_ctx);
57     struct dentry * guest_dir = NULL;
58
59
60     if (root == NULL) {
61         printk("No inspection root found\n");
62         return -1;
63     }
64
65     guest_dir = debugfs_create_dir(guest->name, v3_dir);
66
67     if (IS_ERR(guest_dir)) {
68         printk("Error Creating inspector tree for VM \"%s\"\n", guest->name);
69         return -1;
70     }
71
72     dfs_register_tree(guest_dir, root);
73     return 0;
74 }
75
76
77
78 static int init_inspector( void ) {
79
80     v3_dir = debugfs_create_dir("v3vee", NULL);
81
82     if (IS_ERR(v3_dir)) {
83         printk("Error creating v3vee debugfs directory\n");
84         return -1;
85     }
86
87     return 0;
88 }
89
90
91 static int deinit_inspector( void ) {
92     debugfs_remove(v3_dir);
93     return 0;
94 }
95
96
97 static int guest_init(struct v3_guest * guest, void ** vm_data) {
98
99     add_guest_ctrl(guest, V3_VM_INSPECT, inspect_vm, NULL);
100     return 0;
101 }
102
103 static int guest_deinit(struct v3_guest * guest, void * vm_data) {
104     
105     return 0;
106 }
107
108
109 struct linux_ext inspector_ext = {
110     .name = "INSPECTOR",
111     .init = init_inspector, 
112     .deinit = deinit_inspector,
113     .guest_init = guest_init, 
114     .guest_deinit = guest_deinit
115 };
116
117
118 register_extension(&inspector_ext);