create proc_probes files
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 28 Jan 2013 08:06:55 +0000 (12:06 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 28 Jan 2013 08:06:55 +0000 (12:06 +0400)
driver/Kbuild
driver/device_driver.c
driver/new_dpf.h
driver/struct/proc_probes.c [new file with mode: 0644]
driver/struct/proc_probes.h [new file with mode: 0644]

index ea3f613..2c93d88 100644 (file)
@@ -2,4 +2,4 @@ EXTRA_CFLAGS := $(extra_cflags)
 
 obj-m := swap_driver.o
 swap_driver-y := device_driver.o ec.o legacy.o module.o probes.o probes_manager.o storage.o us_proc_inst.o \
-                 struct/ip.o struct/page_probes.o struct/file_probes.o
+                 struct/ip.o struct/page_probes.o struct/file_probes.o struct/proc_probes.o
index e2e3180..c3871d4 100644 (file)
@@ -19,6 +19,7 @@
 #include "device_driver.h"     // device driver
 #include "handlers_core.h"
 #include <linux/notifier.h>
+#include "struct/proc_probes.h"
 
 #ifdef OVERHEAD_DEBUG
 extern unsigned long swap_sum_time;
@@ -50,8 +51,6 @@ static int device_release(struct inode *, struct file *);
 static ssize_t device_read(struct file *, char *, size_t, loff_t *);
 static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
 
-void proc_p_free_all(void);
-
 static int gl_nDeviceOpened = 0;
 static struct file_operations device_fops = {
        .owner = THIS_MODULE,
index 27bbf33..63f6c38 100644 (file)
@@ -7,6 +7,7 @@
 #include "struct/ip.h"
 #include "struct/page_probes.h"
 #include "struct/file_probes.h"
+#include "struct/proc_probes.h"
 
 enum US_FLAGS {
        US_UNREGS_PROBE,
@@ -16,12 +17,6 @@ enum US_FLAGS {
 
 
 
-struct proc_probes {
-       struct list_head list;
-       pid_t tgid;
-       struct dentry *dentry;
-       struct list_head file_list;
-};
 
 
 
@@ -46,111 +41,6 @@ static void page_p_set_all_kp_addr(struct page_probes *page_p, const struct file
 }
 
 
-
-
-// proc_probes
-static struct proc_probes *proc_p_create(struct dentry* dentry, pid_t tgid)
-{
-       struct proc_probes *proc_p = kmalloc(sizeof(*proc_p), GFP_ATOMIC);
-
-       if (proc_p) {
-               INIT_LIST_HEAD(&proc_p->list);
-               proc_p->tgid = tgid;
-               proc_p->dentry = dentry;
-               INIT_LIST_HEAD(&proc_p->file_list);
-       }
-
-       return proc_p;
-}
-
-static void proc_p_free(struct proc_probes *proc_p)
-{
-       struct file_probes *file_p, *n;
-       list_for_each_entry_safe(file_p, n, &proc_p->file_list, list) {
-               list_del(&file_p->list);
-               file_p_del(file_p);
-       }
-
-       kfree(proc_p);
-}
-
-extern struct list_head proc_probes_list;
-
-void proc_p_free_all(void)
-{
-       if (strcmp(us_proc_info.path,"*") == 0) {
-               // app
-               proc_p_free(us_proc_info.pp);
-               us_proc_info.pp = NULL;
-       } else {
-               // libonly
-               struct proc_probes *proc_p, *tmp;
-               list_for_each_entry_safe(proc_p, tmp, &proc_probes_list, list) {
-                       list_del(&proc_p->list);
-                       proc_p_free(proc_p);
-               }
-       }
-}
-
-static void proc_p_add_file_p(struct proc_probes *proc_p, struct file_probes *file_p)
-{
-       list_add(&file_p->list, &proc_p->file_list);
-}
-
-static struct file_probes *proc_p_find_file_p_by_dentry(struct proc_probes *proc_p,
-               const char *pach, struct dentry *dentry)
-{
-       struct file_probes *file_p;
-
-       list_for_each_entry(file_p, &proc_p->file_list, list) {
-               if (file_p->dentry == dentry) {
-                       return file_p;
-               }
-       }
-
-       file_p = file_p_new(pach, dentry, 10);
-       proc_p_add_file_p(proc_p, file_p);
-
-       return file_p;
-}
-
-static void proc_p_add_dentry_probes(struct proc_probes *proc_p, const char *pach,
-               struct dentry* dentry, struct ip_data *ip_d, int cnt)
-{
-       int i;
-       struct file_probes *file_p = proc_p_find_file_p_by_dentry(proc_p, pach, dentry);
-
-       for (i = 0; i < cnt; ++i) {
-               file_p_add_probe(file_p, &ip_d[i]);
-       }
-}
-
-static struct proc_probes *proc_p_copy(struct proc_probes *proc_p, struct task_struct *task)
-{
-       struct file_probes *file_p;
-       struct proc_probes *proc_p_out = proc_p_create(proc_p->dentry, task->tgid);
-
-       list_for_each_entry(file_p, &proc_p->file_list, list) {
-               proc_p_add_file_p(proc_p_out, file_p_copy(file_p));
-       }
-
-       return proc_p_out;
-}
-
-static struct file_probes *proc_p_find_file_p(struct proc_probes *proc_p, struct vm_area_struct *vma)
-{
-       struct file_probes *file_p;
-
-       list_for_each_entry(file_p, &proc_p->file_list, list) {
-               if (vma->vm_file->f_dentry == file_p->dentry) {
-                       return file_p;
-               }
-       }
-
-       return NULL;
-}
-// proc_probes
-
 #include "storage.h"
 
 static void print_proc_probes(const struct proc_probes *proc_p);
diff --git a/driver/struct/proc_probes.c b/driver/struct/proc_probes.c
new file mode 100644 (file)
index 0000000..66ae3ab
--- /dev/null
@@ -0,0 +1,108 @@
+#include "proc_probes.h"
+#include <linux/slab.h>
+#include <linux/list.h>
+
+extern struct list_head proc_probes_list;
+
+struct proc_probes *proc_p_create(struct dentry* dentry, pid_t tgid)
+{
+       struct proc_probes *proc_p = kmalloc(sizeof(*proc_p), GFP_ATOMIC);
+
+       if (proc_p) {
+               INIT_LIST_HEAD(&proc_p->list);
+               proc_p->tgid = tgid;
+               proc_p->dentry = dentry;
+               INIT_LIST_HEAD(&proc_p->file_list);
+       }
+
+       return proc_p;
+}
+
+void proc_p_free(struct proc_probes *proc_p)
+{
+       struct file_probes *file_p, *n;
+       list_for_each_entry_safe(file_p, n, &proc_p->file_list, list) {
+               list_del(&file_p->list);
+               file_p_del(file_p);
+       }
+
+       kfree(proc_p);
+}
+
+// TODO: remove "us_proc_info"
+#include "../storage.h"
+extern inst_us_proc_t us_proc_info;
+
+void proc_p_free_all(void)
+{
+       if (strcmp(us_proc_info.path,"*") == 0) {
+               // app
+               proc_p_free(us_proc_info.pp);
+               us_proc_info.pp = NULL;
+       } else {
+               // libonly
+               struct proc_probes *proc_p, *n;
+               list_for_each_entry_safe(proc_p, n, &proc_probes_list, list) {
+                       list_del(&proc_p->list);
+                       proc_p_free(proc_p);
+               }
+       }
+}
+
+static void proc_p_add_file_p(struct proc_probes *proc_p, struct file_probes *file_p)
+{
+       list_add(&file_p->list, &proc_p->file_list);
+}
+
+struct file_probes *proc_p_find_file_p_by_dentry(struct proc_probes *proc_p,
+               const char *pach, struct dentry *dentry)
+{
+       struct file_probes *file_p;
+
+       list_for_each_entry(file_p, &proc_p->file_list, list) {
+               if (file_p->dentry == dentry) {
+                       return file_p;
+               }
+       }
+
+       file_p = file_p_new(pach, dentry, 10);
+       proc_p_add_file_p(proc_p, file_p);
+
+       return file_p;
+}
+
+void proc_p_add_dentry_probes(struct proc_probes *proc_p, const char *pach,
+               struct dentry* dentry, struct ip_data *ip_d, int cnt)
+{
+       int i;
+       struct file_probes *file_p = proc_p_find_file_p_by_dentry(proc_p, pach, dentry);
+
+       for (i = 0; i < cnt; ++i) {
+               file_p_add_probe(file_p, &ip_d[i]);
+       }
+}
+
+struct proc_probes *proc_p_copy(struct proc_probes *proc_p, struct task_struct *task)
+{
+       struct file_probes *file_p;
+       struct proc_probes *proc_p_out = proc_p_create(proc_p->dentry, task->tgid);
+
+       list_for_each_entry(file_p, &proc_p->file_list, list) {
+               proc_p_add_file_p(proc_p_out, file_p_copy(file_p));
+       }
+
+       return proc_p_out;
+}
+
+struct file_probes *proc_p_find_file_p(struct proc_probes *proc_p, struct vm_area_struct *vma)
+{
+       struct file_probes *file_p;
+
+       list_for_each_entry(file_p, &proc_p->file_list, list) {
+               if (vma->vm_file->f_dentry == file_p->dentry) {
+                       return file_p;
+               }
+       }
+
+       return NULL;
+}
diff --git a/driver/struct/proc_probes.h b/driver/struct/proc_probes.h
new file mode 100644 (file)
index 0000000..0fe9eaf
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef __PROC_PROBES__
+#define __PROC_PROBES__
+
+#include <linux/types.h>
+#include "file_probes.h"
+
+struct proc_probes {
+       struct list_head list;
+       pid_t tgid;
+       struct dentry *dentry;
+       struct list_head file_list;
+};
+
+
+struct proc_probes *proc_p_create(struct dentry* dentry, pid_t tgid);
+struct proc_probes *proc_p_copy(struct proc_probes *proc_p, struct task_struct *task);
+void proc_p_free(struct proc_probes *proc_p);
+void proc_p_free_all(void);
+
+void proc_p_add_dentry_probes(struct proc_probes *proc_p, const char *pach,
+               struct dentry* dentry, struct ip_data *ip_d, int cnt);
+struct file_probes *proc_p_find_file_p_by_dentry(struct proc_probes *proc_p,
+               const char *pach, struct dentry *dentry);
+struct file_probes *proc_p_find_file_p(struct proc_probes *proc_p, struct vm_area_struct *vma);
+
+#endif /* __PROC_PROBES__ */