us_manager: implement dentry manipulation interface 25/191025/1
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 25 Sep 2018 17:47:59 +0000 (20:47 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 10 Oct 2018 16:57:08 +0000 (19:57 +0300)
Change-Id: Ia71d79a88c8e351e15fdd8761f89d2793baaaf20
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
modules/us_manager/Kbuild
modules/us_manager/swap_dcache.c [new file with mode: 0644]
modules/us_manager/swap_dcache.h [new file with mode: 0644]
modules/us_manager/us_manager.c

index a3f8629a366a5d61703b502cb2c971966b5f993e..1112b0169b33144b0049e0383c439c70b39cb660 100644 (file)
@@ -22,5 +22,6 @@ swap_us_manager-y := \
     img/img_proc.o \
     probes/probes.o \
     probes/probe_info_new.o \
+    swap_dcache.o \
     callbacks.o \
     usm_hook.o
diff --git a/modules/us_manager/swap_dcache.c b/modules/us_manager/swap_dcache.c
new file mode 100644 (file)
index 0000000..6392164
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2018
+ *
+ *   2018  Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#include <linux/dcache.h>
+#include <linux/namei.h>
+#include "swap_dcache.h"
+
+
+static atomic_t g_counter = ATOMIC_INIT(0);
+
+
+struct dentry *swap_dget_by_path(const char *filepath)
+{
+       struct path path;
+       struct dentry *dentry = NULL;
+
+       if (kern_path(filepath, LOOKUP_FOLLOW, &path) == 0) {
+               dentry = swap_dget(path.dentry);
+               path_put(&path);
+       }
+
+       return dentry;
+}
+EXPORT_SYMBOL_GPL(swap_dget_by_path);
+
+struct dentry *swap_dget(struct dentry *dentry)
+{
+       if (dentry) {
+               atomic_inc(&g_counter);
+               dget(dentry);
+       }
+
+       return dentry;
+}
+EXPORT_SYMBOL_GPL(swap_dget);
+
+void swap_dput(struct dentry *dentry)
+{
+       if (dentry) {
+               dput(dentry);
+               atomic_dec(&g_counter);
+       }
+}
+EXPORT_SYMBOL_GPL(swap_dput);
+
+int swap_dentry_init(void)
+{
+       return 0;
+}
+
+void swap_dentry_uninit(void)
+{
+       int counter = atomic_read(&g_counter);
+
+       WARN(counter, "Incorrect dentry usage, counter=%d", counter);
+       BUG_ON(counter < 0);
+}
diff --git a/modules/us_manager/swap_dcache.h b/modules/us_manager/swap_dcache.h
new file mode 100644 (file)
index 0000000..fd717e1
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2018
+ *
+ *   2018  Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+#ifndef _SWAP_DCACHE_H
+#define _SWAP_DCACHE_H
+
+
+struct dentry;
+
+
+struct dentry *swap_dget_by_path(const char *filepath);
+struct dentry *swap_dget(struct dentry *dentry);
+void swap_dput(struct dentry *dentry);
+
+int swap_dentry_init(void);
+void swap_dentry_uninit(void);
+
+
+#endif /* _SWAP_DCACHE_H */
index 09325baf57ebdcc69f562c2b4bb4cde650e77478..b81947ce3b49b9418c8e0c4fb5d6b2ab18618d53 100644 (file)
@@ -32,6 +32,7 @@
 #include "us_manager.h"
 #include "debugfs_us_manager.h"
 #include "callbacks.h"
+#include "swap_dcache.h"
 #include <writer/event_filter.h>
 #include <master/swap_initializer.h>
 
@@ -245,10 +246,14 @@ static int init_us_manager(void)
 {
        int ret;
 
-       ret = helper_init();
+       ret = swap_dentry_init();
        if (ret)
                return ret;
 
+       ret = helper_init();
+       if (ret)
+               goto uninit_dentry;
+
        ret = sspt_proc_init();
        if (ret)
                goto uninit_helper;
@@ -275,6 +280,8 @@ uninit_proc:
        sspt_proc_uninit();
 uninit_helper:
        helper_uninit();
+uninit_dentry:
+       swap_dentry_uninit();
 
        return ret;
 }
@@ -291,6 +298,7 @@ static void exit_us_manager(void)
        pin_exit();
        sspt_proc_uninit();
        helper_uninit();
+       swap_dentry_uninit();
 
        WARN_ON(!pfg_is_unloadable());
 }