diff options
author | Ed Tanous <ed@tanous.net> | 2024-04-06 19:24:01 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-04-10 20:17:16 +0300 |
commit | 3cd7072b9fff77731b959b2f7b3e3750e50abfe4 (patch) | |
tree | 25705154706cef4ca837f718854c0ab1c86e8889 /src | |
parent | 1827b4f1de1e42bb3e2f53f584f07bb7119a3ed2 (diff) | |
download | bmcweb-3cd7072b9fff77731b959b2f7b3e3750e50abfe4.tar.xz |
Move run and redfish to compile units
Meson supports unity builds[1] natively. There's no reason to continue
with the pseudo unity build we've been using by putting implementations
in header files.
This commit is the first in a long series of starting to break this up
into smaller compile units, in the hopes of dropping incremental compile
times for developers, and reduce the total per-core memory usage that
gcc requires.
This commit breaks out the run() function from main() and the
constructor of RedfishService from redfish.hpp into their own compile
units. According to tracing, even after broken out, these are still by
far the two longest to compile units in the build.
Tested: Code compiles. Debug build on a 24 core build server results in
a decrease in compile time for compiling just bmcweb from 1m38s to
1m22s.
[1] https://mesonbuild.com/Unity-builds.html
Change-Id: Ibf352e8aba61d64c9a41a7a76e94ab3b5a0dde4b
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/webserver_main.cpp | 151 | ||||
-rw-r--r-- | src/webserver_run.cpp | 153 |
2 files changed, 155 insertions, 149 deletions
diff --git a/src/webserver_main.cpp b/src/webserver_main.cpp index cc8e1bcfcf..ee752b0239 100644 --- a/src/webserver_main.cpp +++ b/src/webserver_main.cpp @@ -1,159 +1,12 @@ -#include "bmcweb_config.h" -#include "app.hpp" -#include "cors_preflight.hpp" -#include "dbus_monitor.hpp" -#include "dbus_singleton.hpp" -#include "event_service_manager.hpp" -#include "google/google_service_root.hpp" -#include "hostname_monitor.hpp" -#include "ibm/management_console_rest.hpp" -#include "image_upload.hpp" -#include "kvm_websocket.hpp" -#include "login_routes.hpp" -#include "nbd_proxy.hpp" -#include "obmc_console.hpp" -#include "openbmc_dbus_rest.hpp" -#include "redfish.hpp" -#include "redfish_aggregator.hpp" -#include "security_headers.hpp" -#include "ssl_key_handler.hpp" -#include "user_monitor.hpp" -#include "vm_websocket.hpp" -#include "webassets.hpp" -#include <systemd/sd-daemon.h> - -#include <boost/asio/io_context.hpp> -#include <sdbusplus/asio/connection.hpp> -#include <sdbusplus/bus.hpp> -#include <sdbusplus/server.hpp> +#include "logging.hpp" +#include "webserver_run.hpp" #include <exception> #include <memory> #include <string> -constexpr int defaultPort = 18080; - -inline void setupSocket(crow::App& app) -{ - int listenFd = sd_listen_fds(0); - if (1 == listenFd) - { - BMCWEB_LOG_INFO("attempting systemd socket activation"); - if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, - 0) != 0) - { - BMCWEB_LOG_INFO("Starting webserver on socket handle {}", - SD_LISTEN_FDS_START); - app.socket(SD_LISTEN_FDS_START); - } - else - { - BMCWEB_LOG_INFO( - "bad incoming socket, starting webserver on port {}", - defaultPort); - app.port(defaultPort); - } - } - else - { - BMCWEB_LOG_INFO("Starting webserver on port {}", defaultPort); - app.port(defaultPort); - } -} - -static int run() -{ - auto io = std::make_shared<boost::asio::io_context>(); - App app(io); - - sdbusplus::asio::connection systemBus(*io); - crow::connections::systemBus = &systemBus; - - // Static assets need to be initialized before Authorization, because auth - // needs to build the whitelist from the static routes - -#ifdef BMCWEB_ENABLE_STATIC_HOSTING - crow::webassets::requestRoutes(app); -#endif - -#ifdef BMCWEB_ENABLE_KVM - crow::obmc_kvm::requestRoutes(app); -#endif - -#ifdef BMCWEB_ENABLE_REDFISH - redfish::RedfishService redfish(app); - - // Create EventServiceManager instance and initialize Config - redfish::EventServiceManager::getInstance(&*io); - -#ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION - // Create RedfishAggregator instance and initialize Config - redfish::RedfishAggregator::getInstance(&*io); -#endif -#endif - -#ifdef BMCWEB_ENABLE_DBUS_REST - crow::dbus_monitor::requestRoutes(app); - crow::image_upload::requestRoutes(app); - crow::openbmc_mapper::requestRoutes(app); -#endif - -#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET - crow::obmc_console::requestRoutes(app); -#endif - -#ifdef BMCWEB_ENABLE_VM_WEBSOCKET - crow::obmc_vm::requestRoutes(app); -#endif - -#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE - crow::ibm_mc::requestRoutes(app); - crow::ibm_mc_lock::Lock::getInstance(); -#endif - -#ifdef BMCWEB_ENABLE_GOOGLE_API - crow::google_api::requestRoutes(app); -#endif - - if (bmcwebInsecureDisableXssPrevention != 0) - { - cors_preflight::requestRoutes(app); - } - - crow::login_routes::requestRoutes(app); - - setupSocket(app); - -#ifdef BMCWEB_ENABLE_VM_NBDPROXY - crow::nbd_proxy::requestRoutes(app); -#endif - -#ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES - int rc = redfish::EventServiceManager::startEventLogMonitor(*io); - if (rc != 0) - { - BMCWEB_LOG_ERROR("Redfish event handler setup failed..."); - return rc; - } -#endif - -#ifdef BMCWEB_ENABLE_SSL - BMCWEB_LOG_INFO("Start Hostname Monitor Service..."); - crow::hostname_monitor::registerHostnameSignal(); -#endif - - bmcweb::registerUserRemovedSignal(); - - app.run(); - io->run(); - - crow::connections::systemBus = nullptr; - - return 0; -} - int main(int /*argc*/, char** /*argv*/) { try diff --git a/src/webserver_run.cpp b/src/webserver_run.cpp new file mode 100644 index 0000000000..e5d272ead8 --- /dev/null +++ b/src/webserver_run.cpp @@ -0,0 +1,153 @@ +#include "webserver_run.hpp" + +#include "bmcweb_config.h" + +#include "app.hpp" +#include "cors_preflight.hpp" +#include "dbus_monitor.hpp" +#include "dbus_singleton.hpp" +#include "event_service_manager.hpp" +#include "google/google_service_root.hpp" +#include "hostname_monitor.hpp" +#include "ibm/management_console_rest.hpp" +#include "image_upload.hpp" +#include "kvm_websocket.hpp" +#include "login_routes.hpp" +#include "nbd_proxy.hpp" +#include "obmc_console.hpp" +#include "openbmc_dbus_rest.hpp" +#include "redfish.hpp" +#include "redfish_aggregator.hpp" +#include "security_headers.hpp" +#include "ssl_key_handler.hpp" +#include "user_monitor.hpp" +#include "vm_websocket.hpp" +#include "webassets.hpp" + +#include <systemd/sd-daemon.h> + +#include <boost/asio/io_context.hpp> +#include <sdbusplus/asio/connection.hpp> +#include <sdbusplus/bus.hpp> +#include <sdbusplus/server.hpp> + +constexpr int defaultPort = 18080; + +static void setupSocket(crow::App& app) +{ + int listenFd = sd_listen_fds(0); + if (1 == listenFd) + { + BMCWEB_LOG_INFO("attempting systemd socket activation"); + if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, + 0) != 0) + { + BMCWEB_LOG_INFO("Starting webserver on socket handle {}", + SD_LISTEN_FDS_START); + app.socket(SD_LISTEN_FDS_START); + } + else + { + BMCWEB_LOG_INFO( + "bad incoming socket, starting webserver on port {}", + defaultPort); + app.port(defaultPort); + } + } + else + { + BMCWEB_LOG_INFO("Starting webserver on port {}", defaultPort); + app.port(defaultPort); + } +} + +int run() +{ + auto io = std::make_shared<boost::asio::io_context>(); + App app(io); + + sdbusplus::asio::connection systemBus(*io); + crow::connections::systemBus = &systemBus; + + // Static assets need to be initialized before Authorization, because auth + // needs to build the whitelist from the static routes + +#ifdef BMCWEB_ENABLE_STATIC_HOSTING + crow::webassets::requestRoutes(app); +#endif + +#ifdef BMCWEB_ENABLE_KVM + crow::obmc_kvm::requestRoutes(app); +#endif + +#ifdef BMCWEB_ENABLE_REDFISH + redfish::RedfishService redfish(app); + + // Create EventServiceManager instance and initialize Config + redfish::EventServiceManager::getInstance(&*io); + +#ifdef BMCWEB_ENABLE_REDFISH_AGGREGATION + // Create RedfishAggregator instance and initialize Config + redfish::RedfishAggregator::getInstance(&*io); +#endif +#endif + +#ifdef BMCWEB_ENABLE_DBUS_REST + crow::dbus_monitor::requestRoutes(app); + crow::image_upload::requestRoutes(app); + crow::openbmc_mapper::requestRoutes(app); +#endif + +#ifdef BMCWEB_ENABLE_HOST_SERIAL_WEBSOCKET + crow::obmc_console::requestRoutes(app); +#endif + +#ifdef BMCWEB_ENABLE_VM_WEBSOCKET + crow::obmc_vm::requestRoutes(app); +#endif + +#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE + crow::ibm_mc::requestRoutes(app); + crow::ibm_mc_lock::Lock::getInstance(); +#endif + +#ifdef BMCWEB_ENABLE_GOOGLE_API + crow::google_api::requestRoutes(app); +#endif + + if (bmcwebInsecureDisableXssPrevention != 0) + { + cors_preflight::requestRoutes(app); + } + + crow::login_routes::requestRoutes(app); + + setupSocket(app); + +#ifdef BMCWEB_ENABLE_VM_NBDPROXY + crow::nbd_proxy::requestRoutes(app); +#endif + +#ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES + int rc = redfish::EventServiceManager::startEventLogMonitor(*io); + if (rc != 0) + { + BMCWEB_LOG_ERROR("Redfish event handler setup failed..."); + return rc; + } +#endif + +#ifdef BMCWEB_ENABLE_SSL + BMCWEB_LOG_INFO("Start Hostname Monitor Service..."); + crow::hostname_monitor::registerHostnameSignal(); +#endif + + bmcweb::registerUserRemovedSignal(); + + app.run(); + io->run(); + + crow::connections::systemBus = nullptr; + + return 0; +} |