1 2 #include "estoraged.hpp" 3 4 #include <unistd.h> 5 6 #include <boost/asio/io_context.hpp> 7 #include <phosphor-logging/lg2.hpp> 8 #include <sdbusplus/asio/connection.hpp> 9 #include <sdbusplus/asio/object_server.hpp> 10 #include <sdbusplus/bus.hpp> 11 #include <util.hpp> 12 13 #include <filesystem> 14 #include <iostream> 15 #include <memory> 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 " -s <sysfsDevice> The interface to kernel data\n" 28 " structures dealing with this drive.\n" 29 " If omitted, default is\n" 30 " /sys/block/mmcblk0/device/\n"; 31 } 32 33 int main(int argc, char** argv) 34 { 35 std::string physicalBlockDev = "/dev/mmcblk0"; 36 std::string sysfsDev = "/sys/block/mmcblk0/device"; 37 std::string containerBlockDev; 38 int opt = 0; 39 while ((opt = getopt(argc, argv, "b:c:s:")) != -1) 40 { 41 switch (opt) 42 { 43 case 'b': 44 physicalBlockDev = optarg; 45 break; 46 case 'c': 47 containerBlockDev = optarg; 48 break; 49 case 's': 50 sysfsDev = optarg; 51 break; 52 default: 53 usage(*argv); 54 exit(EXIT_FAILURE); 55 } 56 } 57 try 58 { 59 /* Get the filename of the device (without "/dev/"). */ 60 std::string deviceName = 61 std::filesystem::path(physicalBlockDev).filename().string(); 62 /* If containerName arg wasn't provided, create one based on deviceName. 63 */ 64 if (containerBlockDev.empty()) 65 { 66 containerBlockDev = "luks-" + deviceName; 67 } 68 69 // setup connection to dbus 70 boost::asio::io_context io; 71 auto conn = std::make_shared<sdbusplus::asio::connection>(io); 72 // request D-Bus server name. 73 std::string busName = "xyz.openbmc_project.eStoraged"; 74 conn->request_name(busName.c_str()); 75 auto server = sdbusplus::asio::object_server(conn); 76 77 estoraged::EStoraged esObject{ 78 server, physicalBlockDev, containerBlockDev, 79 estoraged::util::findSizeOfBlockDevice(physicalBlockDev), 80 estoraged::util::findPredictedMediaLifeLeftPercent(sysfsDev)}; 81 lg2::info("Storage management service is running", "REDFISH_MESSAGE_ID", 82 std::string("OpenBMC.1.0.ServiceStarted")); 83 84 io.run(); 85 return 0; 86 } 87 catch (const std::exception& e) 88 { 89 lg2::error(e.what(), "REDFISH_MESSAGE_ID", 90 std::string("OpenBMC.1.0.ServiceException")); 91 92 return 2; 93 } 94 return 1; 95 } 96