-
Notifications
You must be signed in to change notification settings - Fork 21
/
bmcstored_dump_entry.cpp
147 lines (134 loc) · 4.67 KB
/
bmcstored_dump_entry.cpp
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
138
139
140
141
142
143
144
145
146
147
#include "bmc_dump_entry.hpp"
#include "dump_manager_bmcstored.hpp"
#include "dump_offload.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
#include <fmt/core.h>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
#include <sdeventplus/exception.hpp>
#include <sdeventplus/source/base.hpp>
namespace phosphor
{
namespace dump
{
namespace bmc_stored
{
using namespace phosphor::logging;
using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
void Entry::delete_()
{
if (isOffloadInProgress())
{
log<level::ERR>(
fmt::format("Dump offload is in progress, cannot delete id({})", id)
.c_str());
elog<sdbusplus::xyz::openbmc_project::Common::Error::Unavailable>();
}
// Delete Dump file from Permanent location but before that copy the dump
// file name to be put in the PEL message
const auto strDumpFileName = path();
log<level::ERR>(
fmt::format("Deleting dump id({}) path({})", id, path()).c_str());
try
{
std::filesystem::remove_all(
std::filesystem::path(path()).parent_path());
}
catch (const std::filesystem::filesystem_error& e)
{
// Log Error message and continue
log<level::ERR>(
fmt::format("Failed to delete dump file({}), errormsg({})", path(),
e.what())
.c_str());
}
// Remove Dump entry D-bus object
phosphor::dump::Entry::delete_();
// Log PEL for dump delete/offload
log<level::INFO>("Log PEL for dump delete or offload");
phosphor::dump::createPEL(
strDumpFileName, "BMC Dump", id,
"xyz.openbmc_project.Logging.Entry.Level.Informational",
"xyz.openbmc_project.Dump.Error.Invalidate");
}
void Entry::initiateOffload(std::string uri)
{
if (isOffloadInProgress())
{
log<level::ERR>(
fmt::format(
"Another offload is in progress URI({}) id({}) cannot continue",
offloadUri(), id)
.c_str());
elog<NotAllowed>(
Reason("Another offload is in progress, please try later"));
}
setOffloadInProgress();
log<level::INFO>(
fmt::format("offload started id({}) uri({})", id, uri).c_str());
phosphor::dump::Entry::initiateOffload(uri);
pid_t pid = fork();
if (pid == 0)
{
execl("/usr/bin/phosphor-offload-handler", "phosphor-offload-handler",
"--id", std::to_string(id).c_str(), "--path", path().c_str(),
"--uri", uri.c_str(), nullptr);
log<level::ERR>(fmt::format("Dump offload failure: Error occured while "
"starting offload id({})",
id)
.c_str());
std::exit(EXIT_FAILURE);
}
if (pid > 0)
{
Child::Callback callback = [this](Child&, const siginfo_t* si) {
this->resetOffloadInProgress();
if (si->si_status == 0)
{
this->offloaded(true);
log<level::ERR>(fmt::format("Dump offload completed id({})",
this->getDumpId())
.c_str());
}
else
{
log<level::ERR>(
fmt::format("Dump offload failed id({})", this->getDumpId())
.c_str());
}
this->childPtr.reset();
};
try
{
childPtr = std::make_unique<Child>(
dynamic_cast<phosphor::dump::bmc_stored::Manager&>(parent)
.eventLoop.get(),
pid, WEXITED | WSTOPPED, std::move(callback));
}
catch (const sdeventplus::SdEventError& ex)
{
// Failed to add to event loop
log<level::ERR>(
fmt::format("Dump offload: Error occurred during "
"the sdeventplus::source::Child creation, ex({})",
ex.what())
.c_str());
throw std::runtime_error("Dump offload: Error occurred during the "
"sdeventplus::source::Child call");
}
}
else
{
auto error = errno;
log<level::ERR>(
fmt::format("Dump offload: Error occurred during fork, errno({})",
error)
.c_str());
throw std::runtime_error("Dump offload: Error occurred during fork");
}
}
} // namespace bmc_stored
} // namespace dump
} // namespace phosphor