From c3bed545386e44f5dc138fede5b6df3441288fc1 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Fri, 6 Apr 2018 17:22:57 +0200 Subject: [PATCH] Add support for fast reload (#312) --- syncd/syncd.cpp | 59 ++++++++++++++++++++++++++------ syncd/syncd_request_shutdown.cpp | 14 +++++--- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index 5de74e8429..b3cd06ccd3 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -2265,7 +2265,6 @@ sai_status_t processFdbFlush( SWSS_LOG_ENTER(); const std::string &key = kfvKey(kco); - const std::string &str_object_type = key.substr(0, key.find(":")); const std::string &str_object_id = key.substr(key.find(":") + 1); sai_object_id_t switch_vid; @@ -2917,7 +2916,17 @@ void handlePortMap(const std::string& portMapFile) } #endif // SAITHRIFT -bool handleRestartQuery(swss::NotificationConsumer &restartQuery) +typedef enum _syncd_restart_type_t +{ + SYNCD_RESTART_TYPE_COLD, + + SYNCD_RESTART_TYPE_WARM, + + SYNCD_RESTART_TYPE_FAST, + +} syncd_restart_type_t; + +syncd_restart_type_t handleRestartQuery(swss::NotificationConsumer &restartQuery) { SWSS_LOG_ENTER(); @@ -2932,17 +2941,23 @@ bool handleRestartQuery(swss::NotificationConsumer &restartQuery) if (op == "COLD") { SWSS_LOG_NOTICE("received COLD switch shutdown event"); - return false; + return SYNCD_RESTART_TYPE_COLD; } if (op == "WARM") { SWSS_LOG_NOTICE("received WARM switch shutdown event"); - return true; + return SYNCD_RESTART_TYPE_WARM; + } + + if (op == "FAST") + { + SWSS_LOG_NOTICE("received FAST switch shutdown event"); + return SYNCD_RESTART_TYPE_FAST; } SWSS_LOG_WARN("received '%s' unknown switch shutdown event, assuming COLD", op.c_str()); - return false; + return SYNCD_RESTART_TYPE_COLD; } bool isVeryFirstRun() @@ -3318,7 +3333,7 @@ int syncd_main(int argc, char **argv) SWSS_LOG_NOTICE("syncd started"); - bool warmRestartHint = false; + syncd_restart_type_t restartType = SYNCD_RESTART_TYPE_COLD; try { @@ -3357,7 +3372,7 @@ int syncd_main(int argc, char **argv) * lead to unable to find some objects. */ - warmRestartHint = handleRestartQuery(*restartQuery); + restartType = handleRestartQuery(*restartQuery); break; } else if (sel == flexCounter.get()) @@ -3381,7 +3396,7 @@ int syncd_main(int argc, char **argv) exit_and_notify(EXIT_FAILURE); } - if (warmRestartHint) + if (restartType == SYNCD_RESTART_TYPE_WARM) { const char *warmBootWriteFile = profile_get_value(0, SAI_KEY_WARM_BOOT_WRITE_FILE); @@ -3391,17 +3406,41 @@ int syncd_main(int argc, char **argv) { SWSS_LOG_WARN("user requested warm shutdown but warmBootWriteFile is not specified, forcing cold shutdown"); - warmRestartHint = false; + restartType = 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) + { + SWSS_LOG_NOTICE("Fast Reboot requested, keeping data plane running"); + + sai_attribute_t attr; + + attr.id = SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL; + attr.value.booldata = false; + + status = sai_switch_api->set_switch_attribute(gSwitchId, &attr); + + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to set SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL=false: %s", + sai_serialize_status(status).c_str()); + } + } + +#endif + status = sai_switch_api->remove_switch(gSwitchId); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_NOTICE("Can't delete a switch. gSwitchId=0x%lx status=0xx", gSwitchId, status); + SWSS_LOG_NOTICE("Can't delete a switch. gSwitchId=0x%lx status=%s", gSwitchId, + sai_serialize_status(status).c_str()); } SWSS_LOG_NOTICE("calling api uninitialize"); diff --git a/syncd/syncd_request_shutdown.cpp b/syncd/syncd_request_shutdown.cpp index 959dc1a123..78d5d4810b 100644 --- a/syncd/syncd_request_shutdown.cpp +++ b/syncd/syncd_request_shutdown.cpp @@ -19,7 +19,7 @@ int main(int argc, char **argv) { "warm", no_argument, 0, 'w' } }; - bool warmRestartHint = false; + std::string op; bool optionSpecified = false; while(true) @@ -34,12 +34,17 @@ int main(int argc, char **argv) switch (c) { case 'c': - warmRestartHint = false; + op = "COLD"; optionSpecified = true; break; case 'w': - warmRestartHint = true; + op = "WARM"; + optionSpecified = true; + break; + + case 'f': + op = "FAST"; optionSpecified = true; break; @@ -57,6 +62,7 @@ int main(int argc, char **argv) std::cerr << "---------------------------------" << std::endl; std::cerr << " --warm -w for warm restart" << std::endl; std::cerr << " --cold -c for cold restart" << std::endl; + std::cerr << " --fast -f for fast restart" << std::endl; exit(EXIT_FAILURE); } @@ -66,8 +72,6 @@ int main(int argc, char **argv) std::vector values; - std::string op = warmRestartHint ? "WARM" : "COLD"; - SWSS_LOG_NOTICE("requested %s shutdown", op.c_str()); std::cerr << "requested " << op << " shutdown" << std::endl;