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> |
John Edward Broadbent | e35e736 | 2022-03-22 16:14:24 -0700 | [diff] [blame] | 8 | #include <util.hpp> |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 9 | |
| 10 | #include <filesystem> |
| 11 | #include <iostream> |
| 12 | #include <string> |
| 13 | |
| 14 | static 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 | |
| 25 | int main(int argc, char** argv) |
| 26 | { |
| 27 | |
| 28 | std::string physicalBlockDev = "/dev/mmcblk0"; |
| 29 | std::string containerBlockDev; |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 30 | int opt = 0; |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 31 | 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 Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 42 | usage(*argv); |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 43 | exit(EXIT_FAILURE); |
| 44 | } |
| 45 | } |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 46 | try |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 47 | { |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 48 | /* 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 Broadbent | a1e0eb0 | 2022-03-15 13:05:01 -0700 | [diff] [blame] | 59 | std::string path = |
| 60 | "/xyz/openbmc_project/inventory/storage/" + deviceName; |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 61 | /* |
| 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 Broadbent | e35e736 | 2022-03-22 16:14:24 -0700 | [diff] [blame] | 73 | estoraged::EStoraged esObject{ |
| 74 | b, path.c_str(), physicalBlockDev, containerBlockDev, |
| 75 | estoraged::util::Util::findSizeOfBlockDevice(physicalBlockDev)}; |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 76 | 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 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 | catch (const std::exception& e) |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 86 | { |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 87 | lg2::error(e.what(), "REDFISH_MESSAGE_ID", |
| 88 | std::string("OpenBMC.1.0.ServiceException")); |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 89 | |
Ed Tanous | 82897c3 | 2022-02-21 14:11:59 -0800 | [diff] [blame] | 90 | return 2; |
| 91 | } |
John Wedig | 2098dab | 2021-09-14 13:56:28 -0700 | [diff] [blame] | 92 | return 1; |
| 93 | } |