George Hung | 9d538eb | 2021-04-28 10:26:40 +0800 | [diff] [blame^] | 1 | From 8079e1e39e1953458bd2e59c7f546a3d879558db Mon Sep 17 00:00:00 2001 |
| 2 | From: "Jason M. Bills" <jason.m.bills@linux.intel.com> |
| 3 | Date: Thu, 30 Jan 2020 16:02:39 -0800 |
| 4 | Subject: [PATCH 2/3] Update Host State Transition function |
| 5 | |
| 6 | This updates the Host State Transition function to use the new |
| 7 | IPMI DBus APIs for transition requests. |
| 8 | |
| 9 | Tested: |
| 10 | Ran each IPMI chassis control command to confirm the expected |
| 11 | behavior: |
| 12 | ipmitool power on: system is powered-on |
| 13 | ipmitool power off: system is forced off |
| 14 | ipmitool power cycle: system is forced off then powered-on |
| 15 | ipmitool power reset: system is hard reset |
| 16 | ipmitool power soft: soft power-off requested from system software |
| 17 | |
| 18 | Change-Id: Id2253a9c0060e892bc318dd02a6221ac1a2ae2d9 |
| 19 | Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com> |
| 20 | --- |
| 21 | chassishandler.cpp | 64 +++++++++++++--------------------------------- |
| 22 | 1 file changed, 18 insertions(+), 46 deletions(-) |
| 23 | |
| 24 | diff --git a/chassishandler.cpp b/chassishandler.cpp |
| 25 | index fdbb9fa5..af9cba72 100644 |
| 26 | --- a/chassishandler.cpp |
| 27 | +++ b/chassishandler.cpp |
| 28 | @@ -811,59 +811,31 @@ ipmi::RspType<> ipmiSetChassisCap(bool intrusion, bool fpLockout, |
| 29 | //------------------------------------------ |
| 30 | // Calls into Host State Manager Dbus object |
| 31 | //------------------------------------------ |
| 32 | -int initiate_state_transition(State::Host::Transition transition) |
| 33 | +int initiateHostStateTransition(State::Host::Transition transition) |
| 34 | { |
| 35 | // OpenBMC Host State Manager dbus framework |
| 36 | - constexpr auto HOST_STATE_MANAGER_ROOT = "/xyz/openbmc_project/state/host0"; |
| 37 | - constexpr auto HOST_STATE_MANAGER_IFACE = "xyz.openbmc_project.State.Host"; |
| 38 | - constexpr auto DBUS_PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
| 39 | - constexpr auto PROPERTY = "RequestedHostTransition"; |
| 40 | + constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0"; |
| 41 | + constexpr auto hostStateIntf = "xyz.openbmc_project.State.Host"; |
| 42 | |
| 43 | - // sd_bus error |
| 44 | - int rc = 0; |
| 45 | - char* busname = NULL; |
| 46 | - |
| 47 | - // SD Bus error report mechanism. |
| 48 | - sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
| 49 | - |
| 50 | - // Gets a hook onto either a SYSTEM or SESSION bus |
| 51 | - sd_bus* bus_type = ipmid_get_sd_bus_connection(); |
| 52 | - rc = mapper_get_service(bus_type, HOST_STATE_MANAGER_ROOT, &busname); |
| 53 | - if (rc < 0) |
| 54 | - { |
| 55 | - log<level::ERR>( |
| 56 | - "Failed to get bus name", |
| 57 | - entry("ERRNO=0x%X, OBJPATH=%s", -rc, HOST_STATE_MANAGER_ROOT)); |
| 58 | - return rc; |
| 59 | - } |
| 60 | + auto service = ipmi::getService(*getSdBus(), hostStateIntf, hostStatePath); |
| 61 | |
| 62 | // Convert to string equivalent of the passed in transition enum. |
| 63 | auto request = State::convertForMessage(transition); |
| 64 | |
| 65 | - rc = sd_bus_call_method(bus_type, // On the system bus |
| 66 | - busname, // Service to contact |
| 67 | - HOST_STATE_MANAGER_ROOT, // Object path |
| 68 | - DBUS_PROPERTY_IFACE, // Interface name |
| 69 | - "Set", // Method to be called |
| 70 | - &bus_error, // object to return error |
| 71 | - nullptr, // Response buffer if any |
| 72 | - "ssv", // Takes 3 arguments |
| 73 | - HOST_STATE_MANAGER_IFACE, PROPERTY, "s", |
| 74 | - request.c_str()); |
| 75 | - if (rc < 0) |
| 76 | + try |
| 77 | { |
| 78 | - log<level::ERR>("Failed to initiate transition", |
| 79 | - entry("ERRNO=0x%X, REQUEST=%s", -rc, request.c_str())); |
| 80 | + ipmi::setDbusProperty(*getSdBus(), service, hostStatePath, |
| 81 | + hostStateIntf, "RequestedHostTransition", |
| 82 | + request); |
| 83 | } |
| 84 | - else |
| 85 | + catch (std::exception& e) |
| 86 | { |
| 87 | - log<level::INFO>("Transition request initiated successfully"); |
| 88 | + log<level::ERR>( |
| 89 | + "Failed to initiate transition", |
| 90 | + entry("EXCEPTION=%s, REQUEST=%s", e.what(), request.c_str())); |
| 91 | + return -1; |
| 92 | } |
| 93 | - |
| 94 | - sd_bus_error_free(&bus_error); |
| 95 | - free(busname); |
| 96 | - |
| 97 | - return rc; |
| 98 | + return 0; |
| 99 | } |
| 100 | |
| 101 | //------------------------------------------ |
| 102 | @@ -1411,7 +1383,7 @@ ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl) |
| 103 | switch (chassisControl) |
| 104 | { |
| 105 | case CMD_POWER_ON: |
| 106 | - rc = initiate_state_transition(State::Host::Transition::On); |
| 107 | + rc = initiateHostStateTransition(State::Host::Transition::On); |
| 108 | break; |
| 109 | case CMD_POWER_OFF: |
| 110 | // This path would be hit in 2 conditions. |
| 111 | @@ -1439,7 +1411,7 @@ ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl) |
| 112 | indicate_no_softoff_needed(); |
| 113 | |
| 114 | // Now request the shutdown |
| 115 | - rc = initiate_state_transition(State::Host::Transition::Off); |
| 116 | + rc = initiateHostStateTransition(State::Host::Transition::Off); |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | @@ -1460,12 +1432,12 @@ ipmi::RspType<> ipmiChassisControl(uint8_t chassisControl) |
| 121 | // originating via a soft power off SMS request) |
| 122 | indicate_no_softoff_needed(); |
| 123 | |
| 124 | - rc = initiate_state_transition(State::Host::Transition::Reboot); |
| 125 | + rc = initiateHostStateTransition(State::Host::Transition::Reboot); |
| 126 | break; |
| 127 | |
| 128 | case CMD_SOFT_OFF_VIA_OVER_TEMP: |
| 129 | // Request Host State Manager to do a soft power off |
| 130 | - rc = initiate_state_transition(State::Host::Transition::Off); |
| 131 | + rc = initiateHostStateTransition(State::Host::Transition::Off); |
| 132 | break; |
| 133 | |
| 134 | case CMD_PULSE_DIAGNOSTIC_INTR: |
| 135 | -- |
| 136 | 2.21.0 |
| 137 | |