blob: aea7904a78229762dc9f7e150258cebf6b491b05 [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>";
}
int main(int argc, char** argv)
{
std::string physicalBlockDev = "/dev/mmcblk0";
std::string containerBlockDev;
int opt = 0;
while ((opt = getopt(argc, argv, "b:c:")) != -1)
{
switch (opt)
{
case 'b':
physicalBlockDev = optarg;
break;
case 'c':
containerBlockDev = 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." + deviceName;
conn->request_name(busName.c_str());
auto server = sdbusplus::asio::object_server(conn);
estoraged::EStoraged esObject{
server, physicalBlockDev, containerBlockDev,
estoraged::util::Util::findSizeOfBlockDevice(physicalBlockDev)};
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;
}