blob: 41085ebeffc23d520185a8fc9249c404df485a0f [file] [log] [blame]
#include "estoraged.hpp"
#include <unistd.h>
#include <boost/asio/io_context.hpp>
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/bus.hpp>
#include <util.hpp>
#include <filesystem>
#include <iostream>
#include <memory>
#include <string>
static void usage(std::string_view name)
{
std::cerr
<< "Usage: " << name
<< "eStorageD service on the BMC\n\n"
" -b <blockDevice> The phyical encrypted device\n"
" If omitted, default is /dev/mmcblk0.\n"
" -c <containerName> The LUKS container name to be created\n"
" If omitted, default is luks-<devName>"
" -s <sysfsDevice> The interface to kernel data\n"
" structures dealing with this drive.\n"
" If omitted, default is\n"
" /sys/block/mmcblk0/device/\n";
}
int main(int argc, char** argv)
{
std::string physicalBlockDev = "/dev/mmcblk0";
std::string sysfsDev = "/sys/block/mmcblk0/device";
std::string containerBlockDev;
int opt = 0;
while ((opt = getopt(argc, argv, "b:c:s:")) != -1)
{
switch (opt)
{
case 'b':
physicalBlockDev = optarg;
break;
case 'c':
containerBlockDev = optarg;
break;
case 's':
sysfsDev = optarg;
break;
default:
usage(*argv);
exit(EXIT_FAILURE);
}
}
try
{
/* Get the filename of the device (without "/dev/"). */
std::string deviceName =
std::filesystem::path(physicalBlockDev).filename().string();
/* If containerName arg wasn't provided, create one based on deviceName.
*/
if (containerBlockDev.empty())
{
containerBlockDev = "luks-" + deviceName;
}
// setup connection to dbus
boost::asio::io_context io;
auto conn = std::make_shared<sdbusplus::asio::connection>(io);
// request D-Bus server name.
std::string busName = "xyz.openbmc_project.eStoraged";
conn->request_name(busName.c_str());
auto server = sdbusplus::asio::object_server(conn);
estoraged::EStoraged esObject{
server, physicalBlockDev, containerBlockDev,
estoraged::util::findSizeOfBlockDevice(physicalBlockDev),
estoraged::util::findPredictedMediaLifeLeftPercent(sysfsDev)};
lg2::info("Storage management service is running", "REDFISH_MESSAGE_ID",
std::string("OpenBMC.1.0.ServiceStarted"));
io.run();
return 0;
}
catch (const std::exception& e)
{
lg2::error(e.what(), "REDFISH_MESSAGE_ID",
std::string("OpenBMC.1.0.ServiceException"));
return 2;
}
return 1;
}