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