Skip to content

Commit

Permalink
Merge pull request sonic-net#347 from yxieca/warmshut
Browse files Browse the repository at this point in the history
[syncd] initiate warm shutdown when requested
  • Loading branch information
yxieca authored Oct 1, 2018
2 parents b9424f0 + bee3196 commit 1e74e71
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3528,12 +3528,12 @@ int syncd_main(int argc, char **argv)

SWSS_LOG_NOTICE("syncd started");

syncd_restart_type_t restartType = SYNCD_RESTART_TYPE_COLD;
syncd_restart_type_t shutdownType = SYNCD_RESTART_TYPE_COLD;

try
{
SWSS_LOG_NOTICE("before onSyncdStart");
onSyncdStart(options.startType == SAI_WARM_BOOT);
onSyncdStart(false);
SWSS_LOG_NOTICE("after onSyncdStart");

startNotificationsProcessingThread();
Expand Down Expand Up @@ -3565,7 +3565,7 @@ int syncd_main(int argc, char **argv)
* lead to unable to find some objects.
*/

restartType = handleRestartQuery(*restartQuery);
shutdownType = handleRestartQuery(*restartQuery);
break;
}
else if (sel == flexCounter.get())
Expand All @@ -3589,7 +3589,10 @@ int syncd_main(int argc, char **argv)
exit_and_notify(EXIT_FAILURE);
}

if (restartType == SYNCD_RESTART_TYPE_WARM)
sai_switch_api_t *sai_switch_api = NULL;
sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api);

if (shutdownType == SYNCD_RESTART_TYPE_WARM)
{
const char *warmBootWriteFile = profile_get_value(0, SAI_KEY_WARM_BOOT_WRITE_FILE);

Expand All @@ -3599,17 +3602,33 @@ int syncd_main(int argc, char **argv)
{
SWSS_LOG_WARN("user requested warm shutdown but warmBootWriteFile is not specified, forcing cold shutdown");

restartType = SYNCD_RESTART_TYPE_COLD;
shutdownType = SYNCD_RESTART_TYPE_COLD;
}
else
{
SWSS_LOG_NOTICE("Warm Reboot requested, keeping data plane running");

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_RESTART_WARM;
attr.value.booldata = true;

status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set SAI_SWITCH_ATTR_RESTART_WARM=true: %s, fall back to cold restart",
sai_serialize_status(status).c_str());
shutdownType = SYNCD_RESTART_TYPE_COLD;
}
}
}

SWSS_LOG_NOTICE("Removing the switch gSwitchId=0x%lx", gSwitchId);
sai_switch_api_t *sai_switch_api = NULL;
sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api);

#ifdef SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL

if (restartType == SYNCD_RESTART_TYPE_FAST)
if (shutdownType == SYNCD_RESTART_TYPE_FAST)
{
SWSS_LOG_NOTICE("Fast Reboot requested, keeping data plane running");

Expand Down

0 comments on commit 1e74e71

Please sign in to comment.