Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 3 | #include <analyzer/analyzer_main.hpp> |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 4 | #include <attn/attn_common.hpp> |
Ben Tyner | 188f109 | 2021-02-01 09:33:06 -0600 | [diff] [blame] | 5 | #include <attn/attn_dbus.hpp> |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 6 | #include <attn/attn_dump.hpp> |
Ben Tyner | b797b3e | 2020-06-29 10:12:05 -0500 | [diff] [blame] | 7 | #include <attn/attn_logging.hpp> |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 8 | #include <attn/pel/pel_minimal.hpp> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/log.hpp> |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 10 | #include <util/trace.hpp> |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 11 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 12 | namespace attn |
| 13 | { |
| 14 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 15 | /** @brief Tuple containing information about ffdc files */ |
| 16 | using FFDCTuple = |
| 17 | std::tuple<util::FFDCFormat, uint8_t, uint8_t, sdbusplus::message::unix_fd>; |
| 18 | |
| 19 | /** @brief Gather messages from the journal */ |
| 20 | std::vector<std::string> sdjGetMessages(const std::string& field, |
| 21 | const std::string& fieldValue, |
| 22 | unsigned int max); |
| 23 | |
| 24 | /** |
| 25 | * Create FFDCTuple objects corresponding to the specified FFDC files. |
| 26 | * |
| 27 | * The D-Bus method to create an error log requires a vector of tuples to |
| 28 | * pass in the FFDC file information. |
| 29 | * |
| 30 | * @param files - FFDC files |
| 31 | * @return vector of FFDCTuple objects |
| 32 | */ |
| 33 | std::vector<FFDCTuple> |
| 34 | createFFDCTuples(const std::vector<util::FFDCFile>& files) |
| 35 | { |
| 36 | std::vector<FFDCTuple> ffdcTuples{}; |
Zane Shelley | a79f6c8 | 2021-01-12 16:38:49 -0600 | [diff] [blame] | 37 | util::transformFFDC(files, ffdcTuples); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 38 | |
| 39 | return ffdcTuples; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @brief Create an FFDCFile object containing raw data |
| 44 | * |
| 45 | * Throws an exception if an error occurs. |
| 46 | * |
| 47 | * @param i_buffer - raw data to add to ffdc faw data file |
| 48 | * @param i_size - size of the raw data |
| 49 | * @return FFDCFile object |
| 50 | */ |
| 51 | util::FFDCFile createFFDCRawFile(void* i_buffer, size_t i_size) |
| 52 | { |
| 53 | util::FFDCFile file{util::FFDCFormat::Custom}; |
| 54 | |
| 55 | // Write buffer to file and then reset file description file offset |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 56 | int fd = file.getFileDescriptor(); |
| 57 | size_t numBytes = write(fd, static_cast<char*>(i_buffer), i_size); |
| 58 | if (i_size != numBytes) |
| 59 | { |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 60 | trace::err("%s only %u of %u bytes written", file.getPath().c_str(), |
| 61 | numBytes, i_size); |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 62 | } |
| 63 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 64 | lseek(fd, 0, SEEK_SET); |
| 65 | |
| 66 | return file; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @brief Create an FFDCFile object containing the specified lines of text data |
| 71 | * |
| 72 | * Throws an exception if an error occurs. |
| 73 | * |
| 74 | * @param lines - lines of text data to write to file |
| 75 | * @return FFDCFile object |
| 76 | */ |
| 77 | util::FFDCFile createFFDCTraceFile(const std::vector<std::string>& lines) |
| 78 | { |
| 79 | // Create FFDC file of type Text |
| 80 | util::FFDCFile file{util::FFDCFormat::Text}; |
| 81 | int fd = file.getFileDescriptor(); |
| 82 | |
| 83 | // Write FFDC lines to file |
| 84 | std::string buffer; |
| 85 | for (const std::string& line : lines) |
| 86 | { |
| 87 | // Copy line to buffer. Add newline if necessary. |
| 88 | buffer = line; |
| 89 | if (line.empty() || (line.back() != '\n')) |
| 90 | { |
| 91 | buffer += '\n'; |
| 92 | } |
| 93 | |
| 94 | // write buffer to file |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 95 | size_t numBytes = write(fd, buffer.c_str(), buffer.size()); |
| 96 | if (buffer.size() != numBytes) |
| 97 | { |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 98 | trace::err("%s only %u of %u bytes written", file.getPath().c_str(), |
| 99 | numBytes, buffer.size()); |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 100 | } |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // Seek to beginning of file so error logging system can read data |
| 104 | lseek(fd, 0, SEEK_SET); |
| 105 | |
| 106 | return file; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Create FDDC files from journal messages of relevant executables |
| 111 | * |
| 112 | * Parse the system journal looking for log entries created by the executables |
| 113 | * of interest for logging. For each of these entries create a ffdc trace file |
| 114 | * that will be used to create ffdc log entries. These files will be pushed |
| 115 | * onto the stack of ffdc files. |
| 116 | * |
| 117 | * @param i_files - vector of ffdc files that will become log entries |
| 118 | */ |
| 119 | void createFFDCTraceFiles(std::vector<util::FFDCFile>& i_files) |
| 120 | { |
| 121 | // Executables of interest |
| 122 | std::vector<std::string> executables{"openpower-hw-diags"}; |
| 123 | |
| 124 | for (const std::string& executable : executables) |
| 125 | { |
| 126 | try |
| 127 | { |
| 128 | // get journal messages |
| 129 | std::vector<std::string> messages = |
| 130 | sdjGetMessages("SYSLOG_IDENTIFIER", executable, 30); |
| 131 | |
| 132 | // Create FFDC file containing the journal messages |
| 133 | if (!messages.empty()) |
| 134 | { |
| 135 | i_files.emplace_back(createFFDCTraceFile(messages)); |
| 136 | } |
| 137 | } |
| 138 | catch (const std::exception& e) |
| 139 | { |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 140 | trace::inf("createFFDCTraceFiles exception"); |
| 141 | trace::inf(e.what()); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Create FFDCFile objects containing debug data to store in the error log. |
| 148 | * |
| 149 | * If an error occurs, the error is written to the journal but an exception |
| 150 | * is not thrown. |
| 151 | * |
| 152 | * @param i_buffer - raw data (if creating raw dump ffdc entry in log) |
| 153 | * @return vector of FFDCFile objects |
| 154 | */ |
| 155 | std::vector<util::FFDCFile> createFFDCFiles(char* i_buffer = nullptr, |
| 156 | size_t i_size = 0) |
| 157 | { |
| 158 | std::vector<util::FFDCFile> files{}; |
| 159 | |
| 160 | // Create raw dump file |
| 161 | if ((nullptr != i_buffer) && (0 != i_size)) |
| 162 | { |
| 163 | files.emplace_back(createFFDCRawFile(i_buffer, i_size)); |
| 164 | } |
| 165 | |
| 166 | // Create trace dump file |
| 167 | createFFDCTraceFiles(files); |
| 168 | |
| 169 | return files; |
| 170 | } |
| 171 | |
| 172 | /** |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 173 | * Create a PEL from an existing PEL |
| 174 | * |
| 175 | * Create a new PEL based on the specified raw PEL and submit the new PEL |
| 176 | * to the backend logging code as a raw PEL. Note that additional data map |
| 177 | * here contains data to be committed to the PEL and it can also be used to |
| 178 | * create the PEL as it contains needed information. |
| 179 | * |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 180 | * @param i_rawPel - buffer containing a raw PEL |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 181 | * @param i_additional - additional data to be added to the new PEL |
| 182 | */ |
| 183 | void createPelCustom(std::vector<uint8_t>& i_rawPel, |
| 184 | std::map<std::string, std::string> i_additional) |
| 185 | { |
| 186 | // create PEL object from buffer |
| 187 | auto tiPel = std::make_unique<pel::PelMinimal>(i_rawPel); |
| 188 | |
| 189 | // The additional data contains the TI info as well as the value for the |
| 190 | // subystem that provided the TI info. Get the subystem from additional |
| 191 | // data and then populate the prmary SRC and SRC words for the custom PEL |
| 192 | // based on the sybsystem's TI info. |
| 193 | uint8_t subsystem = std::stoi(i_additional["Subsystem"]); |
| 194 | tiPel->setSubsystem(subsystem); |
| 195 | |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 196 | // If recoverable attentions are active we will call the analyzer and |
| 197 | // then link the custom pel to analyzer pel. |
| 198 | std::map<std::string, std::string>::iterator it; |
| 199 | it = i_additional.find("recoverables"); |
| 200 | if (it != i_additional.end() && "true" == it->second) |
| 201 | { |
| 202 | DumpParameters dumpParameters; |
Zane Shelley | ebff0d3 | 2021-11-21 10:52:07 -0600 | [diff] [blame] | 203 | auto plid = analyzer::analyzeHardware( |
| 204 | analyzer::AnalysisType::TERMINATE_IMMEDIATE, dumpParameters); |
Zane Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 205 | if (0 != plid) |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 206 | { |
Zane Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 207 | // Link the PLID if an attention was found and a PEL was generated. |
| 208 | tiPel->setPlid(plid); |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 212 | if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) == subsystem) |
| 213 | { |
| 214 | // populate hypervisor SRC words |
| 215 | tiPel->setSrcWords(std::array<uint32_t, pel::numSrcWords>{ |
| 216 | (uint32_t)std::stoul(i_additional["0x10 SRC Word 12"], 0, 16), |
| 217 | (uint32_t)std::stoul(i_additional["0x14 SRC Word 13"], 0, 16), |
| 218 | (uint32_t)std::stoul(i_additional["0x18 SRC Word 14"], 0, 16), |
| 219 | (uint32_t)std::stoul(i_additional["0x1c SRC Word 15"], 0, 16), |
| 220 | (uint32_t)std::stoul(i_additional["0x20 SRC Word 16"], 0, 16), |
| 221 | (uint32_t)std::stoul(i_additional["0x24 SRC Word 17"], 0, 16), |
| 222 | (uint32_t)std::stoul(i_additional["0x28 SRC Word 18"], 0, 16), |
| 223 | (uint32_t)std::stoul(i_additional["0x2c SRC Word 19"], 0, 16)}); |
| 224 | |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 225 | // Populate phyp primary SRC |
| 226 | |
| 227 | // char array for raw pel src |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 228 | std::array<char, pel::asciiStringSize> srcChars{'0'}; |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 229 | |
| 230 | // src from TI info |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 231 | std::string srcString = i_additional["SrcAscii"]; |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 232 | |
| 233 | // copy from string to char array |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 234 | srcString.copy(srcChars.data(), |
| 235 | std::min(srcString.size(), pel::asciiStringSize), 0); |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 236 | |
| 237 | tiPel->setAsciiString(srcChars); // pel object src is char array |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 238 | |
| 239 | // set symptom-id |
| 240 | auto symptomId = (i_additional["SrcAscii"].substr(0, 8) + '_'); |
| 241 | |
| 242 | symptomId += (i_additional["0x10 SRC Word 12"]); |
| 243 | symptomId += (i_additional["0x14 SRC Word 13"] + '_'); |
| 244 | symptomId += (i_additional["0x18 SRC Word 14"]); |
| 245 | symptomId += (i_additional["0x1c SRC Word 15"] + '_'); |
| 246 | symptomId += (i_additional["0x20 SRC Word 16"]); |
| 247 | symptomId += (i_additional["0x24 SRC Word 17"] + '_'); |
| 248 | symptomId += (i_additional["0x28 SRC Word 18"]); |
| 249 | symptomId += (i_additional["0x2c SRC Word 19"]); |
| 250 | |
| 251 | // setSymptomId will take care of required null-terminate and padding |
| 252 | tiPel->setSymptomId(symptomId); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 253 | } |
| 254 | else |
| 255 | { |
| 256 | // Populate hostboot SRC words - note HB word 0 from the shared info |
| 257 | // data (additional data "0x10 HB Word") is reflected in the PEL as |
| 258 | // "reason code" so we zero it here. Also note that the first word |
| 259 | // in this group of words starts at word 0 and word 1 does not exits. |
| 260 | tiPel->setSrcWords(std::array<uint32_t, pel::numSrcWords>{ |
| 261 | (uint32_t)0x00000000, |
| 262 | (uint32_t)std::stoul(i_additional["0x14 HB Word 2"], 0, 16), |
| 263 | (uint32_t)std::stoul(i_additional["0x18 HB Word 3"], 0, 16), |
| 264 | (uint32_t)std::stoul(i_additional["0x1c HB Word 4"], 0, 16), |
| 265 | (uint32_t)std::stoul(i_additional["0x20 HB Word 5"], 0, 16), |
| 266 | (uint32_t)std::stoul(i_additional["0x24 HB Word 6"], 0, 16), |
| 267 | (uint32_t)std::stoul(i_additional["0x28 HB Word 7"], 0, 16), |
| 268 | (uint32_t)std::stoul(i_additional["0x2c HB Word 8"], 0, 16)}); |
| 269 | |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 270 | // Populate hostboot primary SRC |
| 271 | |
| 272 | // char array for raw pel src |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 273 | std::array<char, pel::asciiStringSize> srcChars{'0'}; |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 274 | |
| 275 | // src from TI info |
| 276 | std::string srcString = i_additional["SrcAscii"]; |
| 277 | |
| 278 | // copy from string to char array |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 279 | srcString.copy(srcChars.data(), |
| 280 | std::min(srcString.size(), pel::asciiStringSize), 0); |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 281 | |
| 282 | tiPel->setAsciiString(srcChars); // pel object src is char array |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 283 | |
| 284 | // set symptom-id |
| 285 | auto symptomId = (i_additional["SrcAscii"].substr(0, 8) + '_'); |
| 286 | |
| 287 | symptomId += (i_additional["0x10 HB Word 0"]); // note: word 1 |
| 288 | symptomId += (i_additional["0x14 HB Word 2"] + '_'); // does not exist |
| 289 | symptomId += (i_additional["0x18 HB Word 3"]); |
| 290 | symptomId += (i_additional["0x1c HB Word 4"] + '_'); |
| 291 | symptomId += (i_additional["0x20 HB Word 5"]); |
| 292 | symptomId += (i_additional["0x24 HB Word 6"] + '_'); |
| 293 | symptomId += (i_additional["0x28 HB Word 7"]); |
| 294 | symptomId += (i_additional["0x2c HB Word 8"]); |
| 295 | |
| 296 | // setSymptomId will take care of required null-terminate and padding |
| 297 | tiPel->setSymptomId(symptomId); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | // set severity, event type and action flags |
| 301 | tiPel->setSeverity(static_cast<uint8_t>(pel::Severity::termination)); |
| 302 | tiPel->setType(static_cast<uint8_t>(pel::EventType::na)); |
| 303 | tiPel->setAction(static_cast<uint16_t>(pel::ActionFlags::service | |
| 304 | pel::ActionFlags::report | |
| 305 | pel::ActionFlags::call)); |
| 306 | |
| 307 | // The raw PEL that we used as the basis for this custom PEL contains the |
| 308 | // attention handler trace data and does not needed to be in this PEL so |
| 309 | // we remove it here. |
| 310 | tiPel->setSectionCount(tiPel->getSectionCount() - 1); |
| 311 | |
| 312 | // Update the raw PEL with the new custom PEL data |
| 313 | tiPel->raw(i_rawPel); |
| 314 | |
| 315 | // create PEL from raw data |
| 316 | createPelRaw(i_rawPel); |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Log an event handled by the attention handler |
| 321 | * |
| 322 | * Basic (non TI) events will generate a standard message-registry based PEL |
| 323 | * |
| 324 | * TI events will create two PEL's. One PEL will be informational and will |
| 325 | * contain trace information relevent to attention handler. The second PEL |
| 326 | * will be specific to the TI type (including the primary SRC) and will be |
| 327 | * based off of the TI information provided to the attention handler through |
| 328 | * shared TI info data area. |
| 329 | * |
| 330 | * @param i_event - The event type |
| 331 | * @param i_additional - Additional PEL data |
| 332 | * @param i_ffdc - FFDC PEL data |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 333 | * @return Event log Id (0 if no event log generated) |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 334 | */ |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 335 | uint32_t event(EventType i_event, |
| 336 | std::map<std::string, std::string>& i_additional, |
| 337 | const std::vector<util::FFDCFile>& i_ffdc) |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 338 | { |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 339 | uint32_t pelId = 0; // assume no event log generated |
| 340 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 341 | bool eventValid = false; // assume no event created |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 342 | bool tiEvent = false; // assume not a terminate event |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 343 | |
| 344 | std::string eventName; |
| 345 | |
| 346 | switch (i_event) |
| 347 | { |
| 348 | case EventType::Checkstop: |
| 349 | eventName = "org.open_power.HwDiags.Error.Checkstop"; |
| 350 | eventValid = true; |
| 351 | break; |
| 352 | case EventType::Terminate: |
| 353 | eventName = "org.open_power.Attn.Error.Terminate"; |
| 354 | eventValid = true; |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 355 | tiEvent = true; |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 356 | break; |
| 357 | case EventType::Vital: |
| 358 | eventName = "org.open_power.Attn.Error.Vital"; |
| 359 | eventValid = true; |
| 360 | break; |
| 361 | case EventType::HwDiagsFail: |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 362 | case EventType::AttentionFail: |
| 363 | eventName = "org.open_power.Attn.Error.Fail"; |
| 364 | eventValid = true; |
| 365 | break; |
| 366 | default: |
| 367 | eventValid = false; |
| 368 | break; |
| 369 | } |
| 370 | |
| 371 | if (true == eventValid) |
| 372 | { |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 373 | // Create PEL with additional data and FFDC data. The newly created |
| 374 | // PEL's platform log-id will be returned. |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 375 | pelId = createPel(eventName, i_additional, createFFDCTuples(i_ffdc)); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 376 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 377 | // If this is a TI event we will create an additional PEL that is |
| 378 | // specific to the subsystem that generated the TI. |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 379 | if ((0 != pelId) && (true == tiEvent)) |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 380 | { |
| 381 | // get file descriptor and size of information PEL |
Ben Tyner | 188f109 | 2021-02-01 09:33:06 -0600 | [diff] [blame] | 382 | int pelFd = getPel(pelId); |
Ben Tyner | 1b1915e | 2020-10-23 15:13:38 -0500 | [diff] [blame] | 383 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 384 | // if PEL found, read into buffer |
| 385 | if (-1 != pelFd) |
| 386 | { |
| 387 | auto pelSize = lseek(pelFd, 0, SEEK_END); |
| 388 | lseek(pelFd, 0, SEEK_SET); |
Ben Tyner | 1b1915e | 2020-10-23 15:13:38 -0500 | [diff] [blame] | 389 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 390 | // read information PEL into buffer |
| 391 | std::vector<uint8_t> buffer(pelSize); |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 392 | size_t numBytes = read(pelFd, buffer.data(), buffer.size()); |
| 393 | if (buffer.size() != numBytes) |
| 394 | { |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 395 | trace::err("Error reading event log: %u of %u bytes read", |
| 396 | numBytes, buffer.size()); |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 397 | } |
| 398 | else |
| 399 | { |
| 400 | // create PEL from buffer |
| 401 | createPelCustom(buffer, i_additional); |
| 402 | } |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 403 | |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 404 | close(pelFd); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 405 | } |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 406 | |
Ben Tyner | 6bc43c9 | 2021-05-27 15:08:02 -0500 | [diff] [blame] | 407 | uint8_t subsystem = std::stoi(i_additional["Subsystem"]); |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 408 | |
Ben Tyner | 6bc43c9 | 2021-05-27 15:08:02 -0500 | [diff] [blame] | 409 | // If not hypervisor TI |
| 410 | if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) != subsystem) |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 411 | { |
Ben Tyner | 6bc43c9 | 2021-05-27 15:08:02 -0500 | [diff] [blame] | 412 | // Request a dump and transition the host |
| 413 | if ("true" == i_additional["Dump"]) |
| 414 | { |
| 415 | // will not return until dump is complete |
Zane Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 416 | requestDump(pelId, DumpParameters{0, DumpType::Hostboot}); |
Ben Tyner | 6bc43c9 | 2021-05-27 15:08:02 -0500 | [diff] [blame] | 417 | } |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 418 | } |
| 419 | } |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 420 | } |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 421 | return pelId; |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 422 | } |
| 423 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 424 | /** |
| 425 | * Commit special attention TI event to log |
| 426 | * |
| 427 | * Create a event log with provided additional information and standard |
| 428 | * FFDC data plus TI FFDC data |
| 429 | * |
| 430 | * @param i_additional - Additional log data |
| 431 | * @param i_ti_InfoData - TI FFDC data |
| 432 | */ |
| 433 | void eventTerminate(std::map<std::string, std::string> i_additionalData, |
| 434 | char* i_tiInfoData) |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 435 | { |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 436 | |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 437 | uint32_t tiInfoSize = 0; // assume TI info was not available |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 438 | |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 439 | if (nullptr != i_tiInfoData) |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 440 | { |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 441 | tiInfoSize = 56; // assume not hypervisor TI |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 442 | |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 443 | uint8_t subsystem = std::stoi(i_additionalData["Subsystem"]); |
| 444 | |
| 445 | // If hypervisor |
| 446 | if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) == subsystem) |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 447 | { |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 448 | tiInfoSize = 1024; // assume hypervisor max |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 449 | |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 450 | // hypervisor may just want some of the data |
| 451 | if (0 == (*(i_tiInfoData + 0x09) & 0x01)) |
| 452 | { |
| 453 | uint32_t* additionalLength = (uint32_t*)(i_tiInfoData + 0x50); |
| 454 | uint32_t tiAdditional = be32toh(*additionalLength); |
| 455 | tiInfoSize = std::min(tiInfoSize, (84 + tiAdditional)); |
| 456 | } |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 460 | trace::inf("TI info size = %u", tiInfoSize); |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 461 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 462 | event(EventType::Terminate, i_additionalData, |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 463 | createFFDCFiles(i_tiInfoData, tiInfoSize)); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 464 | } |
| 465 | |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 466 | /** @brief Commit SBE vital event to log, returns event log ID */ |
| 467 | uint32_t eventVital() |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 468 | { |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 469 | // Additional data for log |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 470 | std::map<std::string, std::string> additionalData; |
| 471 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 472 | // Create log event with additional data and FFDC data |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 473 | return event(EventType::Vital, additionalData, createFFDCFiles(nullptr, 0)); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 474 | } |
| 475 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 476 | /** |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 477 | * Commit attention handler failure event to log |
| 478 | * |
| 479 | * Create an event log containing the specified error code. |
| 480 | * |
| 481 | * @param i_error - Error code |
| 482 | */ |
| 483 | void eventAttentionFail(int i_error) |
| 484 | { |
| 485 | // Additional data for log |
| 486 | std::map<std::string, std::string> additionalData; |
| 487 | additionalData["ERROR_CODE"] = std::to_string(i_error); |
| 488 | |
| 489 | // Create log event with additional data and FFDC data |
| 490 | event(EventType::AttentionFail, additionalData, |
| 491 | createFFDCFiles(nullptr, 0)); |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Parse systemd journal message field |
| 496 | * |
| 497 | * Parse the journal looking for the specified field and return the journal |
| 498 | * data for that field. |
| 499 | * |
| 500 | * @param journal - The journal to parse |
| 501 | * @param field - Field containing the data to retrieve |
| 502 | * @return Data for the speciefied field |
| 503 | */ |
Ben Tyner | 1b1915e | 2020-10-23 15:13:38 -0500 | [diff] [blame] | 504 | std::string sdjGetFieldValue(sd_journal* journal, const char* field) |
| 505 | { |
| 506 | const char* data{nullptr}; |
| 507 | size_t length{0}; |
Ben Tyner | 1b1915e | 2020-10-23 15:13:38 -0500 | [diff] [blame] | 508 | |
| 509 | // get field value |
| 510 | if (0 == sd_journal_get_data(journal, field, (const void**)&data, &length)) |
| 511 | { |
Zane Shelley | 9fb657f | 2021-01-12 15:30:58 -0600 | [diff] [blame] | 512 | size_t prefix{0}; |
| 513 | |
Ben Tyner | 1b1915e | 2020-10-23 15:13:38 -0500 | [diff] [blame] | 514 | // The data returned by sd_journal_get_data will be prefixed with the |
| 515 | // field name and "=" |
| 516 | const void* eq = memchr(data, '=', length); |
| 517 | if (nullptr != eq) |
| 518 | { |
| 519 | // get just data following the "=" |
| 520 | prefix = (const char*)eq - data + 1; |
| 521 | } |
| 522 | else |
| 523 | { |
| 524 | // all the data (should not happen) |
| 525 | prefix = 0; |
| 526 | std::string value{}; // empty string |
| 527 | } |
| 528 | |
| 529 | return std::string{data + prefix, length - prefix}; |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | return std::string{}; // empty string |
| 534 | } |
| 535 | } |
| 536 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 537 | /** |
| 538 | * Gather messages from the journal |
| 539 | * |
| 540 | * Fetch journal entry data for all entries with the specified field equal to |
| 541 | * the specified value. |
| 542 | * |
| 543 | * @param field - Field to search on |
| 544 | * @param fieldValue - Value to search for |
| 545 | * @param max - Maximum number of messages fetch |
| 546 | * @return Vector of journal entry data |
| 547 | */ |
Ben Tyner | 1b1915e | 2020-10-23 15:13:38 -0500 | [diff] [blame] | 548 | std::vector<std::string> sdjGetMessages(const std::string& field, |
| 549 | const std::string& fieldValue, |
| 550 | unsigned int max) |
| 551 | { |
| 552 | sd_journal* journal; |
| 553 | std::vector<std::string> messages; |
| 554 | |
| 555 | if (0 == sd_journal_open(&journal, SD_JOURNAL_LOCAL_ONLY)) |
| 556 | { |
| 557 | SD_JOURNAL_FOREACH_BACKWARDS(journal) |
| 558 | { |
| 559 | // Get input field |
| 560 | std::string value = sdjGetFieldValue(journal, field.c_str()); |
| 561 | |
| 562 | // Compare field value and read data |
| 563 | if (value == fieldValue) |
| 564 | { |
| 565 | // Get SYSLOG_IDENTIFIER field (process that logged message) |
| 566 | std::string syslog = |
| 567 | sdjGetFieldValue(journal, "SYSLOG_IDENTIFIER"); |
| 568 | |
| 569 | // Get _PID field |
| 570 | std::string pid = sdjGetFieldValue(journal, "_PID"); |
| 571 | |
| 572 | // Get MESSAGE field |
| 573 | std::string message = sdjGetFieldValue(journal, "MESSAGE"); |
| 574 | |
| 575 | // Get timestamp |
| 576 | uint64_t usec{0}; |
| 577 | if (0 == sd_journal_get_realtime_usec(journal, &usec)) |
| 578 | { |
| 579 | |
| 580 | // Convert realtime microseconds to date format |
| 581 | char dateBuffer[80]; |
| 582 | std::string date; |
| 583 | std::time_t timeInSecs = usec / 1000000; |
| 584 | strftime(dateBuffer, sizeof(dateBuffer), "%b %d %H:%M:%S", |
| 585 | std::localtime(&timeInSecs)); |
| 586 | date = dateBuffer; |
| 587 | |
| 588 | // Store value to messages |
| 589 | value = date + " " + syslog + "[" + pid + "]: " + message; |
| 590 | messages.insert(messages.begin(), value); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | // limit maximum number of messages |
| 595 | if (messages.size() >= max) |
| 596 | { |
| 597 | break; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | sd_journal_close(journal); // close journal when done |
| 602 | } |
| 603 | |
| 604 | return messages; |
| 605 | } |
| 606 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 607 | } // namespace attn |