| From 8079e1e39e1953458bd2e59c7f546a3d879558db Mon Sep 17 00:00:00 2001 |
| From: "Jason M. Bills" <jason.m.bills@linux.intel.com> |
| Date: Thu, 30 Jan 2020 16:02:39 -0800 |
| Subject: [PATCH 2/3] Update Host State Transition function |
| |
| This updates the Host State Transition function to use the new |
| IPMI DBus APIs for transition requests. |
| |
| Tested: |
| Ran each IPMI chassis control command to confirm the expected |
| behavior: |
| ipmitool power on: system is powered-on |
| ipmitool power off: system is forced off |
| ipmitool power cycle: system is forced off then powered-on |
| ipmitool power reset: system is hard reset |
| ipmitool power soft: soft power-off requested from system software |
| |
| Change-Id: Id2253a9c0060e892bc318dd02a6221ac1a2ae2d9 |
| Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com> |
| --- |
| chassishandler.cpp | 64 +++++++++++++--------------------------------- |
| 1 file changed, 18 insertions(+), 46 deletions(-) |
| |
| diff --git a/chassishandler.cpp b/chassishandler.cpp |
| index fdbb9fa5..af9cba72 100644 |
| --- a/chassishandler.cpp |
| +++ b/chassishandler.cpp |
| @@ -811,59 +811,31 @@ ipmi::RspType<> ipmiSetChassisCap(bool intrusion, bool fpLockout, |
| //------------------------------------------ |
| // Calls into Host State Manager Dbus object |
| //------------------------------------------ |
| -int initiate_state_transition(State::Host::Transition transition) |
| +int initiateHostStateTransition(State::Host::Transition transition) |
| { |
| // OpenBMC Host State Manager dbus framework |
| - constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0"; |
| - constexpr auto HOST_STATE_MANAGER_IFACE = "xyz.openbmc_project.State.Host"; |
| - constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| - constexpr auto PROPERTY = "RequestedHostTransition"; |
| + constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0"; |
| + constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host"; |
| |
| - // sd_bus error |
| - int rc = 0; |
| - char* busname = NULL; |
| - |
| - // SD Bus error report mechanism. |
| - sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
| - |
| - // Gets a hook onto either a SYSTEM or SESSION bus |
| - sd_bus* bus_type = ipmid_get_sd_bus_connection(); |
| - rc = mapper_get_service(bus_type, HOST_STATE_MANAGER_ROOT, &busname); |
| - if (rc < 0) |
| - { |
| - log<level::ERR>( |
| - "Failed to get bus name", |
| - entry("ERRNO=0x%X, OBJPATH=%s", -rc, HOST_STATE_MANAGER_ROOT)); |
| - return rc; |
| - } |
| + auto service = ipmi::getService(*getSdBus(), hostStateIntf, hostStatePath); |
| |
| // Convert to string equivalent of the passed in transition enum. |
| auto request = State::convertForMessage(transition); |
| |
| - rc = sd_bus_call_method(bus_type, // On the system bus |
| - busname, // Service to contact |
| - HOST_STATE_MANAGER_ROOT, // Object path |
| - DBUS_PROPERTY_IFACE, // Interface name |
| - "Set", // Method to be called |
| - &bus_error, // object to return error |
| - nullptr, // Response buffer if any |
| - "ssv", // Takes 3 arguments |
| - HOST_STATE_MANAGER_IFACE, PROPERTY, "s", |
| - request.c_str()); |
| - if (rc < 0) |
| + try |
| { |
| - log<level::ERR>("Failed to initiate transition", |
| - entry("ERRNO=0x%X, REQUEST=%s", -rc, request.c_str())); |
| + ipmi::setDbusProperty(*getSdBus(), service, hostStatePath, |
| + hostStateIntf, "RequestedHostTransition", |
| + request); |
| } |
| - else |
| + catch (std::exception& e) |
| { |
| - log<level::INFO>("Transition request initiated successfully"); |
| + log<level::ERR>( |
| + "Failed to initiate transition", |
| + entry("EXCEPTION=%s, REQUEST=%s", e.what(), request.c_str())); |
| + return -1; |
| } |
| - |
| - sd_bus_error_free(&bus_error); |
| - free(busname); |
| - |
| - return rc; |
| + return 0; |
| } |
| |
| //------------------------------------------ |
| @@ -1411,7 +1383,7 @@ ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl) |
| switch (chassisControl) |
| { |
| case CMD_POWER_ON: |
| - rc = initiate_state_transition(State::Host::Transition::On); |
| + rc = initiateHostStateTransition(State::Host::Transition::On); |
| break; |
| case CMD_POWER_OFF: |
| // This path would be hit in 2 conditions. |
| @@ -1439,7 +1411,7 @@ ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl) |
| indicate_no_softoff_needed(); |
| |
| // Now request the shutdown |
| - rc = initiate_state_transition(State::Host::Transition::Off); |
| + rc = initiateHostStateTransition(State::Host::Transition::Off); |
| } |
| else |
| { |
| @@ -1460,12 +1432,12 @@ ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl) |
| // originating via a soft power off SMS request) |
| indicate_no_softoff_needed(); |
| |
| - rc = initiate_state_transition(State::Host::Transition::Reboot); |
| + rc = initiateHostStateTransition(State::Host::Transition::Reboot); |
| break; |
| |
| case CMD_SOFT_OFF_VIA_OVER_TEMP: |
| // Request Host State Manager to do a soft power off |
| - rc = initiate_state_transition(State::Host::Transition::Off); |
| + rc = initiateHostStateTransition(State::Host::Transition::Off); |
| break; |
| |
| case CMD_PULSE_DIAGNOSTIC_INTR: |
| -- |
| 2.21.0 |
| |