summaryrefslogtreecommitdiff
path: root/meta-quanta/meta-gbs/recipes-phosphor/ipmi/phosphor-ipmi-host/0002-Update-Host-State-Transition-function.patch
blob: 156327b9cb8905c9e9d00700729a0730143abaae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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