forked from openbmc/phosphor-debug-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump_offload.cpp
87 lines (76 loc) · 2.85 KB
/
dump_offload.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
#include "config.h"
#include "dump_offload.hpp"
#include <fstream>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <xyz/openbmc_project/Common/File/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace phosphor
{
namespace dump
{
namespace offload
{
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace phosphor::logging;
void requestOffload(fs::path file, uint32_t dumpId, std::string writePath)
{
using namespace sdbusplus::xyz::openbmc_project::Common::File::Error;
using ErrnoOpen = xyz::openbmc_project::Common::File::Open::ERRNO;
using PathOpen = xyz::openbmc_project::Common::File::Open::PATH;
using ErrnoWrite = xyz::openbmc_project::Common::File::Write::ERRNO;
using PathWrite = xyz::openbmc_project::Common::File::Write::PATH;
// open a dump file for a transfer.
fs::path dumpPath(BMC_DUMP_PATH);
dumpPath /= std::to_string(dumpId);
dumpPath /= file.filename();
std::ifstream infile{dumpPath, std::ios::in | std::ios::binary};
if (!infile.good())
{
// Unable to open the dump file
log<level::ERR>("Failed to open the dump from file ",
entry("ERR=%d", errno),
entry("DUMPFILE=%s", dumpPath.c_str()));
elog<InternalFailure>();
}
std::ofstream outfile{writePath, std::ios::out | std::ios::binary};
if (!outfile.good())
{
// Unable to open the write interface
auto err = errno;
log<level::ERR>("Write device path does not exist at ",
entry("ERR=%d", errno),
entry("WRITEINTERFACE=%s", writePath.c_str()));
elog<Open>(ErrnoOpen(err), PathOpen(writePath.c_str()));
}
infile.exceptions(std::ifstream::failbit | std::ifstream::badbit |
std::ifstream::eofbit);
outfile.exceptions(std::ifstream::failbit | std::ifstream::badbit |
std::ifstream::eofbit);
try
{
log<level::INFO>("Opening File for RW ",
entry("FILENAME=%s", file.filename().c_str()));
outfile << infile.rdbuf() << std::flush;
infile.close();
outfile.close();
}
catch (std::ofstream::failure& oe)
{
auto err = errno;
log<level::ERR>("Failed to write to write interface ",
entry("ERR=%s", oe.what()),
entry("WRITEINTERFACE=%s", writePath.c_str()));
elog<Write>(ErrnoWrite(err), PathWrite(writePath.c_str()));
}
catch (const std::exception& e)
{
log<level::ERR>("Failed get the dump from file ",
entry("ERR=%s", e.what()),
entry("DUMPFILE=%s", dumpPath.c_str()));
elog<InternalFailure>();
}
}
} // namespace offload
} // namespace dump
} // namespace phosphor