12098dabeSJohn Wedig 22098dabeSJohn Wedig #include "estoraged.hpp" 32098dabeSJohn Wedig 42098dabeSJohn Wedig #include <unistd.h> 52098dabeSJohn Wedig 64e13b0a1SJohn Edward Broadbent #include <phosphor-logging/lg2.hpp> 72098dabeSJohn Wedig #include <sdbusplus/bus.hpp> 82098dabeSJohn Wedig 92098dabeSJohn Wedig #include <filesystem> 102098dabeSJohn Wedig #include <iostream> 112098dabeSJohn Wedig #include <string> 122098dabeSJohn Wedig 132098dabeSJohn Wedig static void usage(std::string_view name) 142098dabeSJohn Wedig { 152098dabeSJohn Wedig std::cerr 162098dabeSJohn Wedig << "Usage: " << name 172098dabeSJohn Wedig << "eStorageD service on the BMC\n\n" 182098dabeSJohn Wedig " -b <blockDevice> The phyical encrypted device\n" 192098dabeSJohn Wedig " If omitted, default is /dev/mmcblk0.\n" 202098dabeSJohn Wedig " -c <containerName> The LUKS container name to be created\n" 212098dabeSJohn Wedig " If omitted, default is luks-<devName>"; 222098dabeSJohn Wedig } 232098dabeSJohn Wedig 242098dabeSJohn Wedig int main(int argc, char** argv) 252098dabeSJohn Wedig { 262098dabeSJohn Wedig 272098dabeSJohn Wedig std::string physicalBlockDev = "/dev/mmcblk0"; 282098dabeSJohn Wedig std::string containerBlockDev; 29*82897c35SEd Tanous int opt = 0; 302098dabeSJohn Wedig while ((opt = getopt(argc, argv, "b:c:")) != -1) 312098dabeSJohn Wedig { 322098dabeSJohn Wedig switch (opt) 332098dabeSJohn Wedig { 342098dabeSJohn Wedig case 'b': 352098dabeSJohn Wedig physicalBlockDev = optarg; 362098dabeSJohn Wedig break; 372098dabeSJohn Wedig case 'c': 382098dabeSJohn Wedig containerBlockDev = optarg; 392098dabeSJohn Wedig break; 402098dabeSJohn Wedig default: 41*82897c35SEd Tanous usage(*argv); 422098dabeSJohn Wedig exit(EXIT_FAILURE); 432098dabeSJohn Wedig } 442098dabeSJohn Wedig } 45*82897c35SEd Tanous try 46*82897c35SEd Tanous { 472098dabeSJohn Wedig /* Get the filename of the device (without "/dev/"). */ 48*82897c35SEd Tanous std::string deviceName = 492098dabeSJohn Wedig std::filesystem::path(physicalBlockDev).filename().string(); 50*82897c35SEd Tanous /* If containerName arg wasn't provided, create one based on deviceName. 51*82897c35SEd Tanous */ 522098dabeSJohn Wedig if (containerBlockDev.empty()) 532098dabeSJohn Wedig { 542098dabeSJohn Wedig containerBlockDev = "luks-" + deviceName; 552098dabeSJohn Wedig } 562098dabeSJohn Wedig 572098dabeSJohn Wedig /* DBus path location to place the object. */ 582098dabeSJohn Wedig std::string path = "/xyz/openbmc_project/storage/" + deviceName; 592098dabeSJohn Wedig 602098dabeSJohn Wedig /* 612098dabeSJohn Wedig * Create a new bus and affix an object manager for the subtree path we 622098dabeSJohn Wedig * intend to place objects at. 632098dabeSJohn Wedig */ 642098dabeSJohn Wedig auto b = sdbusplus::bus::new_default(); 652098dabeSJohn Wedig sdbusplus::server::manager_t m{b, path.c_str()}; 662098dabeSJohn Wedig 672098dabeSJohn Wedig /* Reserve the dbus service name. */ 682098dabeSJohn Wedig std::string busName = "xyz.openbmc_project.eStoraged." + deviceName; 692098dabeSJohn Wedig b.request_name(busName.c_str()); 702098dabeSJohn Wedig 712098dabeSJohn Wedig /* Create an eStoraged object. */ 72*82897c35SEd Tanous estoraged::EStoraged esObject{b, path.c_str(), physicalBlockDev, 732098dabeSJohn Wedig containerBlockDev}; 744e13b0a1SJohn Edward Broadbent lg2::info("Storage management service is running", "REDFISH_MESSAGE_ID", 75e6ffe704SJohn Edward Broadbent std::string("OpenBMC.1.0.ServiceStarted")); 762098dabeSJohn Wedig 772098dabeSJohn Wedig while (true) 782098dabeSJohn Wedig { 792098dabeSJohn Wedig b.wait(); 802098dabeSJohn Wedig b.process_discard(); 812098dabeSJohn Wedig } 82*82897c35SEd Tanous } 83*82897c35SEd Tanous catch (const std::exception& e) 84*82897c35SEd Tanous { 85*82897c35SEd Tanous lg2::error(e.what(), "REDFISH_MESSAGE_ID", 86*82897c35SEd Tanous std::string("OpenBMC.1.0.ServiceException")); 872098dabeSJohn Wedig 88*82897c35SEd Tanous return 2; 89*82897c35SEd Tanous } 902098dabeSJohn Wedig return 1; 912098dabeSJohn Wedig } 92