chassis-state-manager: Add multi-chassis support
Add multi-chassis management support, each chassis bus separates by
giving a unique chassis id.
Current code only support single chassis, and alway assume bus name is
"xyz.openbmc_project.State.Chassis".
This patch allow user to launch chassis-state-manager with a chassis id,
and chassis id is added into service bus name for identification.
Because there are many places hardcode with bus name
"xyz.openbmc_project.State.Chassis", if chassis id is 0,
chassis-state-manager will request both
"xyz.openbmc_project.State.Chassis" and
"xyz.openbmc_project.State.Chassis0" bus name to meet backwards
compatibility.
Tested on Bletchley:
root@bletchley:~# busctl tree xyz.openbmc_project.State.Chassis
`-/xyz
`-/xyz/openbmc_project
`-/xyz/openbmc_project/state
`-/xyz/openbmc_project/state/chassis0
root@bletchley:~# busctl tree xyz.openbmc_project.State.Chassis0
`-/xyz
`-/xyz/openbmc_project
`-/xyz/openbmc_project/state
`-/xyz/openbmc_project/state/chassis0
root@bletchley:~# busctl tree xyz.openbmc_project.State.Chassis1
`-/xyz
`-/xyz/openbmc_project
`-/xyz/openbmc_project/state
`-/xyz/openbmc_project/state/chassis1
......
patch dependencies:
https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-state-manager/+/51465
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I2ce3e9ab2c95a2688143f4e3775da164a5c33c19
diff --git a/chassis_state_manager_main.cpp b/chassis_state_manager_main.cpp
index c78eea4..eac4fd4 100644
--- a/chassis_state_manager_main.cpp
+++ b/chassis_state_manager_main.cpp
@@ -2,26 +2,53 @@
#include "chassis_state_manager.hpp"
+#include <getopt.h>
+
#include <sdbusplus/bus.hpp>
#include <cstdlib>
#include <exception>
#include <iostream>
-int main()
+int main(int argc, char** argv)
{
+ size_t chassisId = 0;
+ int arg;
+ int optIndex = 0;
+ static struct option longOpts[] = {{"chassis", required_argument, 0, 'c'},
+ {0, 0, 0, 0}};
+
+ while ((arg = getopt_long(argc, argv, "c:", longOpts, &optIndex)) != -1)
+ {
+ switch (arg)
+ {
+ case 'c':
+ chassisId = std::stoul(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
auto bus = sdbusplus::bus::new_default();
- // For now, we only have one instance of the chassis
- auto objPathInst = std::string{CHASSIS_OBJPATH} + '0';
+ auto chassisBusName =
+ std::string{CHASSIS_BUSNAME} + std::to_string(chassisId);
+ auto objPathInst = std::string{CHASSIS_OBJPATH} + std::to_string(chassisId);
// Add sdbusplus ObjectManager.
sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
+ phosphor::state::manager::Chassis manager(bus, objPathInst.c_str(),
+ chassisId);
- phosphor::state::manager::Chassis manager(bus, objPathInst.c_str());
+ // For backwards compatibility, request a busname without chassis id if
+ // input id is 0.
+ if (chassisId == 0)
+ {
+ bus.request_name(CHASSIS_BUSNAME);
+ }
- bus.request_name(CHASSIS_BUSNAME);
+ bus.request_name(chassisBusName.c_str());
manager.startPOHCounter();
-
return 0;
}