blob: 9fa9c7da5f56b5ae8c5992d2846a8ea96350d5a8 [file] [log] [blame]
John Wedig2098dab2021-09-14 13:56:28 -07001
2#include "estoraged.hpp"
3
4#include <unistd.h>
5
6#include <sdbusplus/bus.hpp>
7
8#include <filesystem>
9#include <iostream>
10#include <string>
11
12static void usage(std::string_view name)
13{
14 std::cerr
15 << "Usage: " << name
16 << "eStorageD service on the BMC\n\n"
17 " -b <blockDevice> The phyical encrypted device\n"
18 " If omitted, default is /dev/mmcblk0.\n"
19 " -c <containerName> The LUKS container name to be created\n"
20 " If omitted, default is luks-<devName>";
21}
22
23int main(int argc, char** argv)
24{
25
26 std::string physicalBlockDev = "/dev/mmcblk0";
27 std::string containerBlockDev;
28 int opt;
29 while ((opt = getopt(argc, argv, "b:c:")) != -1)
30 {
31 switch (opt)
32 {
33 case 'b':
34 physicalBlockDev = optarg;
35 break;
36 case 'c':
37 containerBlockDev = optarg;
38 break;
39 default:
40 usage(argv[0]);
41 exit(EXIT_FAILURE);
42 }
43 }
44
45 /* Get the filename of the device (without "/dev/"). */
46 auto deviceName =
47 std::filesystem::path(physicalBlockDev).filename().string();
48
49 /* If containerName arg wasn't provided, create one based on deviceName. */
50 if (containerBlockDev.empty())
51 {
52 containerBlockDev = "luks-" + deviceName;
53 }
54
55 /* DBus path location to place the object. */
56 std::string path = "/xyz/openbmc_project/storage/" + deviceName;
57
58 /*
59 * Create a new bus and affix an object manager for the subtree path we
60 * intend to place objects at.
61 */
62 auto b = sdbusplus::bus::new_default();
63 sdbusplus::server::manager_t m{b, path.c_str()};
64
65 /* Reserve the dbus service name. */
66 std::string busName = "xyz.openbmc_project.eStoraged." + deviceName;
67 b.request_name(busName.c_str());
68
69 /* Create an eStoraged object. */
70 estoraged::eStoraged esObject{b, path.c_str(), physicalBlockDev,
71 containerBlockDev};
72
73 std::cerr << "eStoraged has started" << std::endl;
74
75 while (true)
76 {
77 b.wait();
78 b.process_discard();
79 }
80
81 return 1;
82}