From 8e1e0fef83afb27944c1ed7a28c1f10b19120d95 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Wed, 6 Jul 2022 17:46:32 +0900 Subject: [PATCH] Move "checking and modifying partition status" to reboot_recovery_handler Change-Id: I17207783af711ef7ffb279381dca71baa76ee88d Signed-off-by: SangYoun Kwak --- src/storage/storage.c | 88 +++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/src/storage/storage.c b/src/storage/storage.c index 0be8829..99dc516 100644 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -709,18 +709,54 @@ static void storage_poweroff(GDBusConnection *conn, unregister_udev_uevent_control(&dm_verity_uh); } -static gboolean reboot_recovery_callback(void *data) +static int is_recovery_available() +{ + int ret_board_api; + int cloned; + + /* check if a/b partitions are cloned */ + ret_board_api = device_board_get_partition_ab_cloned(&cloned); + if (ret_board_api != 0) { + CRITICAL_LOG("device_board_get_partition_ab_cloned failed: %d", ret_board_api); + return 0; + } + if(cloned != 1) { + CRITICAL_LOG("Partition a/b are not cloned"); + return 0; + } + + return 1; +} + +static gboolean reboot_recovery_handler(void *data) { int ret_board_api; int ret_dbus; + int recovery_available; gint poweroff_retval; + GVariant *poweroff_param = NULL; + + recovery_available = is_recovery_available(); - GVariant *poweroff_param = g_variant_new("(ss)", "reboot", "recovery"); + /* set current partition status as "corrupted" */ + ret_board_api = device_board_set_partition_status('\0', "corrupted"); + CRITICAL_LOG("device_board_set_partition_status: (%d)", ret_board_api); + /* clear partition ab cloned */ + ret_board_api = device_board_clear_partition_ab_cloned(); + CRITICAL_LOG("device_board_clear_partition_ab_cloned: (%d)", ret_board_api); + + if (!recovery_available) { + CRITICAL_LOG("Recovery is not available, do not reboot/recovery"); + return G_SOURCE_REMOVE; + } /* toggle partition */ ret_board_api = device_board_switch_partition('\0'); CRITICAL_LOG("device_board_switch_partition: (%d)", ret_board_api); + /* call method for reboot recovery */ + poweroff_param = g_variant_new("(ss)", "reboot", "recovery"); + ret_dbus = gdbus_call_sync_with_reply_int("org.tizen.system.deviced", "/Org/Tizen/System/DeviceD/PowerOff", "org.tizen.system.deviced.PowerOff", @@ -739,43 +775,11 @@ static gboolean reboot_recovery_callback(void *data) return G_SOURCE_REMOVE; } -static int is_recovery_available() -{ - int ret_board_api; - int cloned; - int status; - - /* check if a/b partitions are cloned */ - ret_board_api = device_board_get_partition_ab_cloned(&cloned); - if (ret_board_api != 0) { - CRITICAL_LOG("device_board_get_partition_ab_cloned failed: %d", ret_board_api); - return 0; - } - if(cloned != 1) { - CRITICAL_LOG("Partition a/b are not cloned"); - return 0; - } - - /* check if fota is running (upgrade status is 1~99) */ - ret_board_api = device_board_get_upgrade_status(&status); - if (ret_board_api != 0) { - CRITICAL_LOG("device_board_get_upgrade_status failed: %d", ret_board_api); - return 0; - } - if (status >= 1 && status <= 99) { - CRITICAL_LOG("Upgrade is in progress: %d", status); - return 0; - } - - return 1; -} - static void dm_verity_uevent_block_handler(struct udev_device *dev) { static int dm_verity_corrupted_cnt = 0; const char *dm_name = NULL; const char *dm_verity_err_block_nr = NULL; - int ret_board_api = 0; /* if dm_name is rootfs and DM_VERITY_ERR_BLOCK_NR exist, then reboot recovery */ dm_name = udev_device_get_property_value(dev, "DM_NAME"); @@ -812,23 +816,9 @@ static void dm_verity_uevent_block_handler(struct udev_device *dev) /* action: reboot,recovery */ if (storage_rootfs_recovery_info.action == RECOVERY_ACTION_REBOOT_RECOVERY && poweroff_g_timeout_event_source_id <= 0) { - int recovery_available = is_recovery_available(); - - /* set current partition status as "corrupted" */ - ret_board_api = device_board_set_partition_status('\0', "corrupted"); - CRITICAL_LOG("device_board_set_partition_status: (%d)", ret_board_api); - /* clear partition ab cloned */ - ret_board_api = device_board_clear_partition_ab_cloned(); - CRITICAL_LOG("device_board_clear_partition_ab_cloned: (%d)", ret_board_api); - - if (!recovery_available) { - CRITICAL_LOG("Recovery is not available, do not reboot/recovery"); - return; - } - poweroff_g_timeout_event_source_id = g_timeout_add(storage_rootfs_recovery_info.dm_verity_corrupted_timeout, - reboot_recovery_callback, NULL); + reboot_recovery_handler, NULL); _I("g_timeout_add event source id: (%u)", poweroff_g_timeout_event_source_id); } -- 2.7.4