blob: 82ffcddd7605dcf445a79d73e365cc31e4508fcf [file] [log] [blame]
John Wedig2098dab2021-09-14 13:56:28 -07001
2#include "estoraged.hpp"
3
4#include <unistd.h>
5
John Edward Broadbent4e13b0a2021-11-15 15:21:59 -08006#include <phosphor-logging/lg2.hpp>
John Wedig2098dab2021-09-14 13:56:28 -07007#include <sdbusplus/bus.hpp>
John Edward Broadbente35e7362022-03-22 16:14:24 -07008#include <util.hpp>
John Wedig2098dab2021-09-14 13:56:28 -07009
10#include <filesystem>
11#include <iostream>
12#include <string>
13
14static void usage(std::string_view name)
15{
16 std::cerr
17 << "Usage: " << name
18 << "eStorageD service on the BMC\n\n"
19 " -b <blockDevice> The phyical encrypted device\n"
20 " If omitted, default is /dev/mmcblk0.\n"
21 " -c <containerName> The LUKS container name to be created\n"
22 " If omitted, default is luks-<devName>";
23}
24
25int main(int argc, char** argv)
26{
27
28 std::string physicalBlockDev = "/dev/mmcblk0";
29 std::string containerBlockDev;
Ed Tanous82897c32022-02-21 14:11:59 -080030 int opt = 0;
John Wedig2098dab2021-09-14 13:56:28 -070031 while ((opt = getopt(argc, argv, "b:c:")) != -1)
32 {
33 switch (opt)
34 {
35 case 'b':
36 physicalBlockDev = optarg;
37 break;
38 case 'c':
39 containerBlockDev = optarg;
40 break;
41 default:
Ed Tanous82897c32022-02-21 14:11:59 -080042 usage(*argv);
John Wedig2098dab2021-09-14 13:56:28 -070043 exit(EXIT_FAILURE);
44 }
45 }
Ed Tanous82897c32022-02-21 14:11:59 -080046 try
John Wedig2098dab2021-09-14 13:56:28 -070047 {
Ed Tanous82897c32022-02-21 14:11:59 -080048 /* Get the filename of the device (without "/dev/"). */
49 std::string deviceName =
50 std::filesystem::path(physicalBlockDev).filename().string();
51 /* If containerName arg wasn't provided, create one based on deviceName.
52 */
53 if (containerBlockDev.empty())
54 {
55 containerBlockDev = "luks-" + deviceName;
56 }
57
58 /* DBus path location to place the object. */
John Edward Broadbenta1e0eb02022-03-15 13:05:01 -070059 std::string path =
60 "/xyz/openbmc_project/inventory/storage/" + deviceName;
Ed Tanous82897c32022-02-21 14:11:59 -080061 /*
62 * Create a new bus and affix an object manager for the subtree path we
63 * intend to place objects at.
64 */
65 auto b = sdbusplus::bus::new_default();
66 sdbusplus::server::manager_t m{b, path.c_str()};
67
68 /* Reserve the dbus service name. */
69 std::string busName = "xyz.openbmc_project.eStoraged." + deviceName;
70 b.request_name(busName.c_str());
71
72 /* Create an eStoraged object. */
John Edward Broadbente35e7362022-03-22 16:14:24 -070073 estoraged::EStoraged esObject{
74 b, path.c_str(), physicalBlockDev, containerBlockDev,
75 estoraged::util::Util::findSizeOfBlockDevice(physicalBlockDev)};
Ed Tanous82897c32022-02-21 14:11:59 -080076 lg2::info("Storage management service is running", "REDFISH_MESSAGE_ID",
77 std::string("OpenBMC.1.0.ServiceStarted"));
78
79 while (true)
80 {
81 b.wait();
82 b.process_discard();
83 }
John Wedig2098dab2021-09-14 13:56:28 -070084 }
Ed Tanous82897c32022-02-21 14:11:59 -080085 catch (const std::exception& e)
John Wedig2098dab2021-09-14 13:56:28 -070086 {
Ed Tanous82897c32022-02-21 14:11:59 -080087 lg2::error(e.what(), "REDFISH_MESSAGE_ID",
88 std::string("OpenBMC.1.0.ServiceException"));
John Wedig2098dab2021-09-14 13:56:28 -070089
Ed Tanous82897c32022-02-21 14:11:59 -080090 return 2;
91 }
John Wedig2098dab2021-09-14 13:56:28 -070092 return 1;
93}