storage: Check /opt partition storage size and add NeedCleanup signal 11/181011/3 accepted/tizen/unified/20180614.150828 submit/tizen/20180614.073228
authorpr.jung <pr.jung@samsung.com>
Thu, 7 Jun 2018 08:30:50 +0000 (17:30 +0900)
committerpr.jung <pr.jung@samsung.com>
Thu, 7 Jun 2018 09:52:37 +0000 (18:52 +0900)
- Check /opt/usr, /tmp, /opt size
- Broadcast NeedCleanup signal when memory level is changed
   normal -> warning/critical/full
   warning -> critical/full
   critical -> full

Change-Id: I39d42624be0dbe4923f79c5e744502f2661a2103
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/storage/storage.c

index 3106eae..de66353 100644 (file)
@@ -39,6 +39,7 @@
 #include "module-intf.h"
 
 #define MEMORY_STATUS_TMP_PATH  "/tmp"
+#define MEMORY_STATUS_OPT_PATH  "/opt"
 #define MEMNOTI_TMP_CRITICAL_VALUE (20)
 
 #define MEMORY_MEGABYTE_VALUE   1048576
@@ -47,6 +48,7 @@
 #define MEMNOTI_CRITICAL_VALUE (0.1) /* 0.1% under */
 #define MEMNOTI_FULL_VALUE     (0.0) /* 0.0% under */
 
+#define SIGNAL_NEED_CLEANUP     "NeedCleanup"
 #define SIGNAL_LOWMEM_STATE     "ChangeState"
 #define SIGNAL_LOWMEM_FULL      "Full"
 #define MEMNOTI_TIMER_INTERVAL  5000 /* milliseconds */
 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
 
 enum memnoti_level {
-       MEMNOTI_LEVEL_CRITICAL = 0,
+       MEMNOTI_LEVEL_FULL = 0,
+       MEMNOTI_LEVEL_CRITICAL,
        MEMNOTI_LEVEL_WARNING,
        MEMNOTI_LEVEL_NORMAL,
-       MEMNOTI_LEVEL_FULL,
 };
 
 enum memnoti_status {
@@ -69,7 +71,14 @@ enum memnoti_status {
        MEMNOTI_ENABLE,
 };
 
+enum memory_id {
+       MEMORY_INTERNAL = 0,
+       MEMORY_TMP,
+       MEMORY_OPT,
+};
+
 struct storage_config_info {
+       enum memory_id mem_id;
        enum memnoti_level current_noti_level;
        double warning_level;
        double critical_level;
@@ -82,6 +91,7 @@ static guint id_booting_done;
 static guint id_storage_poweroff;
 
 static struct storage_config_info storage_internal_info = {
+       .mem_id                 = MEMORY_INTERNAL,
        .current_noti_level = MEMNOTI_LEVEL_NORMAL,
        .warning_level      = MEMNOTI_WARNING_VALUE,
        .critical_level     = MEMNOTI_CRITICAL_VALUE,
@@ -89,19 +99,63 @@ static struct storage_config_info storage_internal_info = {
 };
 
 static struct storage_config_info storage_tmp_info = {
+       .mem_id                 = MEMORY_TMP,
        .current_noti_level = MEMNOTI_LEVEL_NORMAL,
        .warning_level      = MEMNOTI_TMP_CRITICAL_VALUE,
        .critical_level     = MEMNOTI_TMP_CRITICAL_VALUE,
        .full_level         = MEMNOTI_FULL_VALUE,
 };
 
-static void memnoti_send_broadcast(char *signal, int status)
+static struct storage_config_info storage_opt_info = {
+       .mem_id                 = MEMORY_OPT,
+       .current_noti_level = MEMNOTI_LEVEL_NORMAL,
+       .warning_level      = MEMNOTI_WARNING_VALUE,
+       .critical_level     = MEMNOTI_CRITICAL_VALUE,
+       .full_level         = MEMNOTI_FULL_VALUE,
+};
+
+static void memstatus_send_broadcast(enum memory_id no, char *signal, int status)
 {
+       if (no == MEMORY_OPT)
+               return;
+
        _I("signal %s status %d", signal, status);
        dbus_handle_broadcast_dbus_signal_var(STORAGED_PATH_LOWMEM, STORAGED_INTERFACE_LOWMEM,
                        signal, g_variant_new("(i)", status));
 }
 
+static void memcleanup_send_broadcast(struct storage_config_info *info, enum memnoti_level level, enum memnoti_level prev_level)
+{
+       const char *path;
+       char *value;
+
+       if (info->mem_id == MEMORY_INTERNAL)
+               path = tzplatform_getenv(TZ_SYS_HOME);
+       else if (info->mem_id == MEMORY_TMP)
+               path = MEMORY_STATUS_TMP_PATH;
+       else if (info->mem_id == MEMORY_OPT)
+               path = MEMORY_STATUS_OPT_PATH;
+       else
+               return;
+
+       if (prev_level <= level)
+               return;
+
+       if (level == MEMNOTI_LEVEL_WARNING)
+               value = "warning";
+       else if (level == MEMNOTI_LEVEL_CRITICAL)
+               value = "critical";
+       else if (level == MEMNOTI_LEVEL_FULL)
+               value = "full";
+       else
+               return;
+
+       _I("%s level: %s", path, value);
+       dbus_handle_broadcast_dbus_signal_var(STORAGED_PATH_LOWMEM, STORAGED_INTERFACE_LOWMEM,
+                       SIGNAL_NEED_CLEANUP, g_variant_new("(ss)", path, value));
+
+}
+
 static int launch_memory_popup(int num, ...)
 {
        int ret;
@@ -150,15 +204,20 @@ static void storage_status_broadcast(struct storage_config_info *info, double to
 {
        double level = (avail/total)*100;
        int status = MEMNOTI_DISABLE;
+       enum memnoti_level prev_noti_level;
 
+       prev_noti_level = info->current_noti_level;
        if (level <= info->full_level) {
                if (info->current_noti_level == MEMNOTI_LEVEL_FULL)
                        return;
                info->current_noti_level = MEMNOTI_LEVEL_FULL;
                status = MEMNOTI_ENABLE;
-               memnoti_send_broadcast(SIGNAL_LOWMEM_FULL, status);
-               _I("current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
-                       level, info->warning_level, info->critical_level, info->full_level);
+               memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_FULL, status);
+
+               memcleanup_send_broadcast(info, info->current_noti_level, prev_noti_level);
+
+               _I("%d current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
+                       info->mem_id, level, info->warning_level, info->critical_level, info->full_level);
                return;
        }
 
@@ -166,23 +225,32 @@ static void storage_status_broadcast(struct storage_config_info *info, double to
                if (info->current_noti_level == MEMNOTI_LEVEL_CRITICAL)
                        return;
                if (info->current_noti_level == MEMNOTI_LEVEL_FULL)
-                       memnoti_send_broadcast(SIGNAL_LOWMEM_FULL, status);
+                       memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_FULL, status);
                info->current_noti_level = MEMNOTI_LEVEL_CRITICAL;
                status = MEMNOTI_ENABLE;
-               memnoti_send_broadcast(SIGNAL_LOWMEM_STATE, status);
-               _I("current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
-                       level, info->warning_level, info->critical_level, info->full_level);
+               memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_STATE, status);
+
+               memcleanup_send_broadcast(info, info->current_noti_level, prev_noti_level);
+
+               _I("%d current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
+                       info->mem_id, level, info->warning_level, info->critical_level, info->full_level);
                return;
        }
 
        if (info->current_noti_level == MEMNOTI_LEVEL_FULL)
-               memnoti_send_broadcast(SIGNAL_LOWMEM_FULL, status);
+               memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_FULL, status);
        if (info->current_noti_level == MEMNOTI_LEVEL_CRITICAL)
-               memnoti_send_broadcast(SIGNAL_LOWMEM_STATE, status);
-       if (level <= info->warning_level)
+               memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_STATE, status);
+
+       if (level <= info->warning_level) {
                info->current_noti_level = MEMNOTI_LEVEL_WARNING;
-       else
+               _I("%d current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
+                       info->mem_id, level, info->warning_level, info->critical_level, info->full_level);
+
+               memcleanup_send_broadcast(info, info->current_noti_level, prev_noti_level);
+       } else
                info->current_noti_level = MEMNOTI_LEVEL_NORMAL;
+
 }
 
 static int storage_get_memory_size(const char *path, struct statvfs *s)
@@ -258,6 +326,11 @@ static gboolean check_storage_status(gpointer data)
        dTotal = (double)s.f_frsize * s.f_blocks;
        dAvail = (double)s.f_bsize * s.f_bavail;
        storage_status_broadcast(&storage_tmp_info, dTotal, dAvail);
+       /* check opt */
+       storage_get_memory_size(MEMORY_STATUS_OPT_PATH, &s);
+       dTotal = (double)s.f_frsize * s.f_blocks;
+       dAvail = (double)s.f_bsize * s.f_bavail;
+       storage_status_broadcast(&storage_opt_info, dTotal, dAvail);
 
        if (memnoti_timer) {
                g_source_remove(memnoti_timer);
@@ -272,6 +345,7 @@ static int init_storage_config_info_all(void)
 {
        init_storage_config_info(tzplatform_getenv(TZ_SYS_HOME), &storage_internal_info);
        init_storage_config_info(MEMORY_STATUS_TMP_PATH, &storage_tmp_info);
+       init_storage_config_info(MEMORY_STATUS_OPT_PATH, &storage_opt_info);
        memnoti_timer = g_timeout_add(MEMNOTI_TIMER_INTERVAL,
                                check_storage_status, NULL);
        if (memnoti_timer == 0)