From 227635f6ea121f99f111d54e06491778460ca4a1 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Thu, 6 Nov 2014 16:53:03 +0400 Subject: [PATCH] [REFACTOR] move dentry_by_path() form parser/us_inst.c to us_manager/pf/pf_group.c Change-Id: I4a9d6fe017debe743874180edd8ec27c7c2db7ec Signed-off-by: Vyacheslav Cherkashin --- parser/us_inst.c | 30 ------------------------------ us_manager/pf/pf_group.c | 36 ++++++++++++++++++++++++++++++++++++ us_manager/pf/pf_group.h | 3 +++ webprobe/webprobe_prof.c | 14 -------------- 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/parser/us_inst.c b/parser/us_inst.c index ea0b306..4bf143e 100644 --- a/parser/us_inst.c +++ b/parser/us_inst.c @@ -31,42 +31,12 @@ #include #include #include -#include #include #include #include "msg_parser.h" #include "us_inst.h" -/* FIXME: create get_dentry() and put_dentry() */ -static struct dentry *dentry_by_path(const char *path) -{ - struct dentry *dentry; -#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) - struct path st_path; - if (kern_path(path, LOOKUP_FOLLOW, &st_path) != 0) { -#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ - struct nameidata nd; - if (path_lookup(path, LOOKUP_FOLLOW, &nd) != 0) { -#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ - printk(KERN_INFO "failed to lookup dentry for path %s!\n", - path); - return NULL; - } - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) - dentry = nd.dentry; - path_release(&nd); -#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 38) - dentry = nd.path.dentry; - path_put(&nd.path); -#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ - dentry = st_path.dentry; - path_put(&st_path); -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) */ - return dentry; -} - static int mod_func_inst(struct func_inst_data *func, struct pf_group *pfg, struct dentry *dentry, enum MOD_TYPE mt) diff --git a/us_manager/pf/pf_group.c b/us_manager/pf/pf_group.c index 86d44cc..927b82d 100644 --- a/us_manager/pf/pf_group.c +++ b/us_manager/pf/pf_group.c @@ -26,6 +26,8 @@ #include #include #include +#include + #include "proc_filters.h" #include #include @@ -205,6 +207,40 @@ static void subsequent_install(struct task_struct *task, } /** + * @brief Get dentry struct by path + * + * @param path Path to file + * @return Pointer on dentry struct on NULL + */ +struct dentry *dentry_by_path(const char *path) +{ + struct dentry *dentry; +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) + struct path st_path; + if (kern_path(path, LOOKUP_FOLLOW, &st_path) != 0) { +#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ + struct nameidata nd; + if (path_lookup(path, LOOKUP_FOLLOW, &nd) != 0) { +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ + printk("failed to lookup dentry for path %s!\n", path); + return NULL; + } + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) + dentry = nd.dentry; + path_release(&nd); +#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 38) + dentry = nd.path.dentry; + path_put(&nd.path); +#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ + dentry = st_path.dentry; + path_put(&st_path); +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) */ + return dentry; +} +EXPORT_SYMBOL_GPL(dentry_by_path); + +/** * @brief Get pf_group struct by dentry * * @param dentry Dentry of file diff --git a/us_manager/pf/pf_group.h b/us_manager/pf/pf_group.h index f69bd0b..9a053d1 100644 --- a/us_manager/pf/pf_group.h +++ b/us_manager/pf/pf_group.h @@ -32,6 +32,9 @@ struct pf_group; struct sspt_proc; struct probe_info; +/* FIXME: create and use get_dentry() and put_dentry() */ +struct dentry *dentry_by_path(const char *path); + struct pf_group *get_pf_group_by_dentry(struct dentry *dentry, void *priv); struct pf_group *get_pf_group_by_tgid(pid_t tgid, void *priv); struct pf_group *get_pf_group_by_comm(char *comm, void *priv); diff --git a/webprobe/webprobe_prof.c b/webprobe/webprobe_prof.c index f105def..1c325b2 100644 --- a/webprobe/webprobe_prof.c +++ b/webprobe/webprobe_prof.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -48,19 +47,6 @@ struct web_prof_data { static const char *LIBEWEBKIT2_PATH = "/usr/lib/libewebkit2.so.0"; static struct web_prof_data *web_data; -static struct dentry *dentry_by_path(const char *path) -{ - struct dentry *dentry; - struct path st_path; - if (kern_path(path, LOOKUP_FOLLOW, &st_path) != 0) { - pr_err("failed to lookup dentry for path %s!\n", path); - return NULL; - } - dentry = st_path.dentry; - path_put(&st_path); - - return dentry; -} u64 *web_prof_addr_ptr(enum web_prof_addr_t type) { -- 2.7.4