main.cpp (c0d66eb78bdeaf8e9689b1ed07f819a5984aecf0) | main.cpp (15b63e12bdc3f3116fb841349dd4f1cd17a8398b) |
---|---|
1 2#include "estoraged.hpp" 3#include "getConfig.hpp" 4#include "util.hpp" 5 6#include <boost/asio/deadline_timer.hpp> 7#include <boost/asio/io_context.hpp> 8#include <boost/asio/post.hpp> --- 27 unchanged lines hidden (view full) --- 36 boost::container::flat_map< 37 std::string, std::unique_ptr<estoraged::EStoraged>>& storageObjects, 38 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection) 39{ 40 auto getter = std::make_shared<estoraged::GetStorageConfiguration>( 41 dbusConnection, 42 [&objectServer, &storageObjects]( 43 const estoraged::ManagedStorageType& storageConfigurations) { | 1 2#include "estoraged.hpp" 3#include "getConfig.hpp" 4#include "util.hpp" 5 6#include <boost/asio/deadline_timer.hpp> 7#include <boost/asio/io_context.hpp> 8#include <boost/asio/post.hpp> --- 27 unchanged lines hidden (view full) --- 36 boost::container::flat_map< 37 std::string, std::unique_ptr<estoraged::EStoraged>>& storageObjects, 38 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection) 39{ 40 auto getter = std::make_shared<estoraged::GetStorageConfiguration>( 41 dbusConnection, 42 [&objectServer, &storageObjects]( 43 const estoraged::ManagedStorageType& storageConfigurations) { |
44 size_t numConfigObj = storageConfigurations.size(); 45 if (numConfigObj > 1) 46 { 47 lg2::error("eStoraged can only manage 1 eMMC device; found {NUM}", 48 "NUM", numConfigObj, "REDFISH_MESSAGE_ID", 49 std::string("OpenBMC.0.1.CreateStorageObjectsFail")); 50 return; 51 } 52 53 for (const std::pair<sdbusplus::message::object_path, 54 estoraged::StorageData>& storage : 55 storageConfigurations) 56 { 57 const std::string& path = storage.first.str; 58 59 if (storageObjects.find(path) != storageObjects.end()) | 44 size_t numConfigObj = storageConfigurations.size(); 45 if (numConfigObj > 1) |
60 { | 46 { |
61 /* 62 * We've already created this object, or at least 63 * attempted to. 64 */ 65 continue; | 47 lg2::error( 48 "eStoraged can only manage 1 eMMC device; found {NUM}", 49 "NUM", numConfigObj, "REDFISH_MESSAGE_ID", 50 std::string("OpenBMC.0.1.CreateStorageObjectsFail")); 51 return; |
66 } 67 | 52 } 53 |
68 /* Get the properties from the config object. */ 69 const estoraged::StorageData& data = storage.second; 70 71 /* Look for the device file. */ 72 const std::filesystem::path blockDevDir{"/sys/block"}; 73 auto deviceInfo = estoraged::util::findDevice(data, blockDevDir); 74 if (!deviceInfo) | 54 for (const std::pair<sdbusplus::message::object_path, 55 estoraged::StorageData>& storage : 56 storageConfigurations) |
75 { | 57 { |
76 lg2::error("Device not found for path {PATH}", "PATH", path, 77 "REDFISH_MESSAGE_ID", 78 std::string("OpenBMC.0.1.CreateStorageObjectsFail")); 79 /* 80 * Set a NULL pointer as a placeholder, so that we don't 81 * try and fail again later. 82 */ 83 storageObjects[path] = nullptr; 84 continue; 85 } | 58 const std::string& path = storage.first.str; |
86 | 59 |
87 std::filesystem::path deviceFile = 88 std::move(deviceInfo->deviceFile); 89 std::filesystem::path sysfsDir = std::move(deviceInfo->sysfsDir); 90 std::string luksName = std::move(deviceInfo->luksName); 91 std::string locationCode = std::move(deviceInfo->locationCode); 92 uint64_t eraseMaxGeometry = deviceInfo->eraseMaxGeometry; 93 uint64_t eraseMinGeometry = deviceInfo->eraseMinGeometry; | 60 if (storageObjects.find(path) != storageObjects.end()) 61 { 62 /* 63 * We've already created this object, or at least 64 * attempted to. 65 */ 66 continue; 67 } |
94 | 68 |
95 uint64_t size = estoraged::util::findSizeOfBlockDevice(deviceFile); | 69 /* Get the properties from the config object. */ 70 const estoraged::StorageData& data = storage.second; |
96 | 71 |
97 uint8_t lifeleft = 98 estoraged::util::findPredictedMediaLifeLeftPercent(sysfsDir); 99 std::string partNumber = estoraged::util::getPartNumber(sysfsDir); 100 std::string serialNumber = 101 estoraged::util::getSerialNumber(sysfsDir); 102 const std::string& driveType = deviceInfo->driveType; 103 const std::string& driveProtocol = deviceInfo->driveProtocol; 104 /* Create the storage object. */ 105 storageObjects[path] = std::make_unique<estoraged::EStoraged>( 106 objectServer, path, deviceFile, luksName, size, lifeleft, 107 partNumber, serialNumber, locationCode, eraseMaxGeometry, 108 eraseMinGeometry, driveType, driveProtocol); 109 lg2::info("Created eStoraged object for path {PATH}", "PATH", path, 110 "REDFISH_MESSAGE_ID", 111 std::string("OpenBMC.0.1.CreateStorageObjects")); 112 } 113 }); | 72 /* Look for the device file. */ 73 const std::filesystem::path blockDevDir{"/sys/block"}; 74 auto deviceInfo = 75 estoraged::util::findDevice(data, blockDevDir); 76 if (!deviceInfo) 77 { 78 lg2::error( 79 "Device not found for path {PATH}", "PATH", path, 80 "REDFISH_MESSAGE_ID", 81 std::string("OpenBMC.0.1.CreateStorageObjectsFail")); 82 /* 83 * Set a NULL pointer as a placeholder, so that we don't 84 * try and fail again later. 85 */ 86 storageObjects[path] = nullptr; 87 continue; 88 } 89 90 std::filesystem::path deviceFile = 91 std::move(deviceInfo->deviceFile); 92 std::filesystem::path sysfsDir = 93 std::move(deviceInfo->sysfsDir); 94 std::string luksName = std::move(deviceInfo->luksName); 95 std::string locationCode = std::move(deviceInfo->locationCode); 96 uint64_t eraseMaxGeometry = deviceInfo->eraseMaxGeometry; 97 uint64_t eraseMinGeometry = deviceInfo->eraseMinGeometry; 98 99 uint64_t size = 100 estoraged::util::findSizeOfBlockDevice(deviceFile); 101 102 uint8_t lifeleft = 103 estoraged::util::findPredictedMediaLifeLeftPercent( 104 sysfsDir); 105 std::string partNumber = 106 estoraged::util::getPartNumber(sysfsDir); 107 std::string serialNumber = 108 estoraged::util::getSerialNumber(sysfsDir); 109 const std::string& driveType = deviceInfo->driveType; 110 const std::string& driveProtocol = deviceInfo->driveProtocol; 111 /* Create the storage object. */ 112 storageObjects[path] = std::make_unique<estoraged::EStoraged>( 113 objectServer, path, deviceFile, luksName, size, lifeleft, 114 partNumber, serialNumber, locationCode, eraseMaxGeometry, 115 eraseMinGeometry, driveType, driveProtocol); 116 lg2::info("Created eStoraged object for path {PATH}", "PATH", 117 path, "REDFISH_MESSAGE_ID", 118 std::string("OpenBMC.0.1.CreateStorageObjects")); 119 } 120 }); |
114 getter->getConfiguration(); 115} 116 117int main(void) 118{ 119 try 120 { 121 // setup connection to dbus 122 boost::asio::io_context io; 123 auto conn = std::make_shared<sdbusplus::asio::connection>(io); 124 // request D-Bus server name. 125 conn->request_name("xyz.openbmc_project.eStoraged"); 126 sdbusplus::asio::object_server server(conn); 127 boost::container::flat_map<std::string, 128 std::unique_ptr<estoraged::EStoraged>> 129 storageObjects; 130 | 121 getter->getConfiguration(); 122} 123 124int main(void) 125{ 126 try 127 { 128 // setup connection to dbus 129 boost::asio::io_context io; 130 auto conn = std::make_shared<sdbusplus::asio::connection>(io); 131 // request D-Bus server name. 132 conn->request_name("xyz.openbmc_project.eStoraged"); 133 sdbusplus::asio::object_server server(conn); 134 boost::container::flat_map<std::string, 135 std::unique_ptr<estoraged::EStoraged>> 136 storageObjects; 137 |
131 boost::asio::post( 132 io, [&]() { createStorageObjects(server, storageObjects, conn); }); | 138 boost::asio::post(io, [&]() { 139 createStorageObjects(server, storageObjects, conn); 140 }); |
133 134 /* 135 * Set up an event handler to process any new configuration objects 136 * that show up later. 137 */ 138 boost::asio::deadline_timer filterTimer(io); 139 std::function<void(sdbusplus::message_t&)> eventHandler = 140 [&](sdbusplus::message_t& message) { | 141 142 /* 143 * Set up an event handler to process any new configuration objects 144 * that show up later. 145 */ 146 boost::asio::deadline_timer filterTimer(io); 147 std::function<void(sdbusplus::message_t&)> eventHandler = 148 [&](sdbusplus::message_t& message) { |
141 if (message.is_method_error()) 142 { 143 lg2::error("eventHandler callback method error"); 144 return; 145 } 146 /* 147 * This implicitly cancels the timer, if it's already pending. 148 * If there's a burst of events within a short period, we want 149 * to handle them all at once. So, we will wait this long for no 150 * more events to occur, before processing them. 151 */ 152 filterTimer.expires_from_now(boost::posix_time::seconds(1)); 153 154 filterTimer.async_wait([&](const boost::system::error_code& ec) { 155 if (ec == boost::asio::error::operation_aborted) | 149 if (message.is_method_error()) |
156 { | 150 { |
157 /* we were canceled */ | 151 lg2::error("eventHandler callback method error"); |
158 return; 159 } | 152 return; 153 } |
160 if (ec) 161 { 162 lg2::error("timer error"); 163 return; 164 } 165 createStorageObjects(server, storageObjects, conn); 166 }); 167 }; | 154 /* 155 * This implicitly cancels the timer, if it's already pending. 156 * If there's a burst of events within a short period, we want 157 * to handle them all at once. So, we will wait this long for no 158 * more events to occur, before processing them. 159 */ 160 filterTimer.expires_from_now(boost::posix_time::seconds(1)); |
168 | 161 |
162 filterTimer.async_wait( 163 [&](const boost::system::error_code& ec) { 164 if (ec == boost::asio::error::operation_aborted) 165 { 166 /* we were canceled */ 167 return; 168 } 169 if (ec) 170 { 171 lg2::error("timer error"); 172 return; 173 } 174 createStorageObjects(server, storageObjects, conn); 175 }); 176 }; 177 |
|
169 auto match = std::make_unique<sdbusplus::bus::match_t>( 170 static_cast<sdbusplus::bus_t&>(*conn), 171 "type='signal',member='PropertiesChanged',path_namespace='" + 172 std::string("/xyz/openbmc_project/inventory") + 173 "',arg0namespace='" + estoraged::emmcConfigInterface + "'", 174 eventHandler); 175 176 lg2::info("Storage management service is running", "REDFISH_MESSAGE_ID", --- 14 unchanged lines hidden --- | 178 auto match = std::make_unique<sdbusplus::bus::match_t>( 179 static_cast<sdbusplus::bus_t&>(*conn), 180 "type='signal',member='PropertiesChanged',path_namespace='" + 181 std::string("/xyz/openbmc_project/inventory") + 182 "',arg0namespace='" + estoraged::emmcConfigInterface + "'", 183 eventHandler); 184 185 lg2::info("Storage management service is running", "REDFISH_MESSAGE_ID", --- 14 unchanged lines hidden --- |