swap: prepare modulization of swap devices 96/187496/3
authorByungSoo Kim <bs1770.kim@samsung.com>
Mon, 12 Jun 2017 14:22:18 +0000 (23:22 +0900)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Mon, 24 Sep 2018 12:58:33 +0000 (14:58 +0200)
Resourced swap can support multiple swap devices.
It makes new structure with each callback and new api for adding modules.

Change-Id: I1b243f00032541ee2a5d320c1aff322a599a9a39
Signed-off-by: ByungSoo Kim <bs1770.kim@samsung.com>
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
src/common/swap-common.h
src/swap/swap.c

index 77ba0a3..6228cb9 100644 (file)
 #ifndef __SWAP_COMMON_H__
 #define __SWAP_COMMON_H__
 
+#include <stdio.h>
+#include "resourced.h"
 #include "memory-common.h"
 
 #define SWAP_ZRAM_SYSFILE      "/sys/block/zram0/"
+#define SWAP_CONF_FILE         RD_CONFIG_FILE(swap)
 
 enum swap_state {
        SWAP_ARG_START = -1,
@@ -36,6 +39,12 @@ enum swap_state {
        SWAP_ARG_END,
 };
 
+enum swap_type {
+       SWAP_TYPE_NONE = 0x0,
+       SWAP_TYPE_ZRAM = 0x1,
+       SWAP_TYPE_MAX,
+};
+
 struct swap_status_msg {
        enum memcg_type type;
        struct memcg_info *info;
@@ -58,4 +67,29 @@ static inline enum swap_state swap_get_state(void)
 }
 #endif
 
+struct swap_module_ops {
+       char *name;
+       enum swap_type type;
+       char *path;
+       int priority;
+       unsigned int k_size;
+       int (*init)(void *data);
+       int (*exit) (void *data);
+       int (*activate)(void *data);
+       int (*reclaim)(void *data);
+};
+
+void swap_add(const struct swap_module_ops *swap);
+void swap_remove(const struct swap_module_ops *swap);
+
+#define SWAP_MODLE_REGISTER(swap)                                      \
+static void __attribute__ ((constructor)) swap_module_register(void)           \
+{                                                      \
+       swap_add(swap);                                 \
+}                                                      \
+static void __attribute__ ((destructor)) swap_module_unregister(void)  \
+{                                                      \
+       swap_remove(swap);                              \
+}
+
 #endif /* __SWAP_COMMON_H__ */
index dac0481..02117c1 100644 (file)
@@ -59,7 +59,6 @@
 #define SWAP_OFF_EXEC_PATH             "/sbin/swapoff"
 #define SWAP_MKSWAP_EXEC_PATH          "/sbin/mkswap"
 
-#define SWAP_CONF_FILE                 RD_CONFIG_FILE(swap)
 #define SWAP_CONTROL_SECTION           "CONTROL"
 #define SWAP_CONF_ENABLE               "SWAP_ENABLE"
 #define SWAP_CONF_STREAMS              "MAX_COMP_STREAMS"