John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 1 | |
| 2 | #include "estoraged.hpp" |
| 3 | |
| 4 | #include <unistd.h> |
| 5 | |
John Edward Broadbent | 4e13b0a | 2021-11-15 15:21:59 -0800 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.hpp> |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 7 | #include <sdbusplus/bus.hpp> |
| 8 | |
| 9 | #include <filesystem> |
| 10 | #include <iostream> |
| 11 | #include <string> |
| 12 | |
| 13 | static void usage(std::string_view name) |
| 14 | { |
| 15 | std::cerr |
| 16 | << "Usage: " << name |
| 17 | << "eStorageD service on the BMC\n\n" |
| 18 | " -b <blockDevice> The phyical encrypted device\n" |
| 19 | " If omitted, default is /dev/mmcblk0.\n" |
| 20 | " -c <containerName> The LUKS container name to be created\n" |
| 21 | " If omitted, default is luks-<devName>"; |
| 22 | } |
| 23 | |
| 24 | int main(int argc, char** argv) |
| 25 | { |
| 26 | |
| 27 | std::string physicalBlockDev = "/dev/mmcblk0"; |
| 28 | std::string containerBlockDev; |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 29 | int opt = 0; |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 30 | while ((opt = getopt(argc, argv, "b:c:")) != -1) |
| 31 | { |
| 32 | switch (opt) |
| 33 | { |
| 34 | case 'b': |
| 35 | physicalBlockDev = optarg; |
| 36 | break; |
| 37 | case 'c': |
| 38 | containerBlockDev = optarg; |
| 39 | break; |
| 40 | default: |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 41 | usage(*argv); |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 42 | exit(EXIT_FAILURE); |
| 43 | } |
| 44 | } |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 45 | try |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 46 | { |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 47 | /* Get the filename of the device (without "/dev/"). */ |
| 48 | std::string deviceName = |
| 49 | std::filesystem::path(physicalBlockDev).filename().string(); |
| 50 | /* If containerName arg wasn't provided, create one based on deviceName. |
| 51 | */ |
| 52 | if (containerBlockDev.empty()) |
| 53 | { |
| 54 | containerBlockDev = "luks-" + deviceName; |
| 55 | } |
| 56 | |
| 57 | /* DBus path location to place the object. */ |
John Edward Broadbent | a1e0eb0 | 2022-03-15 13:05:01 -0700 | [diff] [blame] | 58 | std::string path = |
| 59 | "/xyz/openbmc_project/inventory/storage/" + deviceName; |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 60 | /* |
| 61 | * Create a new bus and affix an object manager for the subtree path we |
| 62 | * intend to place objects at. |
| 63 | */ |
| 64 | auto b = sdbusplus::bus::new_default(); |
| 65 | sdbusplus::server::manager_t m{b, path.c_str()}; |
| 66 | |
| 67 | /* Reserve the dbus service name. */ |
| 68 | std::string busName = "xyz.openbmc_project.eStoraged." + deviceName; |
| 69 | b.request_name(busName.c_str()); |
| 70 | |
| 71 | /* Create an eStoraged object. */ |
| 72 | estoraged::EStoraged esObject{b, path.c_str(), physicalBlockDev, |
| 73 | containerBlockDev}; |
| 74 | lg2::info("Storage management service is running", "REDFISH_MESSAGE_ID", |
| 75 | std::string("OpenBMC.1.0.ServiceStarted")); |
| 76 | |
| 77 | while (true) |
| 78 | { |
| 79 | b.wait(); |
| 80 | b.process_discard(); |
| 81 | } |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 82 | } |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 83 | catch (const std::exception& e) |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 84 | { |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 85 | lg2::error(e.what(), "REDFISH_MESSAGE_ID", |
| 86 | std::string("OpenBMC.1.0.ServiceException")); |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 87 | |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 88 | return 2; |
| 89 | } |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 90 | return 1; |
| 91 | } |