Nvmed: Modernize Boost.Asio usage Update deprecated Boost.Asio API calls to their modern equivalents: - Replace io.post(callback) with boost::asio::post(io, callback). - Replace timer->expires_from_now(duration) with timer->expires_after(duration). - Add (void) cast to boost::asio::spawn to acknowledge the return value. These changes align with modern Boost.Asio practices and help reduce deprecation warnings during compilation. Tested: Verified that the package builds successfully and unit tests pass. Google-Bug-Id: 476239885 Change-Id: I912e79c1f517bbc779b8643d76f4ec5c53657b5d Signed-off-by: GG Chen <guangzong@google.com>
diff --git a/src/NVMeBasic.cpp b/src/NVMeBasic.cpp index f8fca8b..832745a 100644 --- a/src/NVMeBasic.cpp +++ b/src/NVMeBasic.cpp
@@ -347,7 +347,7 @@ is.read(data->data(), static_cast<int64_t>(response->size())); /* Process the callback */ - self->io.post([data, cb{std::move(cb)}]() { + boost::asio::post(self->io, [data, cb{std::move(cb)}]() { if (data->size() < sizeof(DriveStatus)) { cb(std::make_error_code(std::errc::message_size), nullptr);
diff --git a/src/NVMeMi.cpp b/src/NVMeMi.cpp index 06d7c2d..015d968 100644 --- a/src/NVMeMi.cpp +++ b/src/NVMeMi.cpp
@@ -359,7 +359,7 @@ if (!workerStop) { workerIsNotified = true; - workerIO.post(std::move(func)); + boost::asio::post(workerIO, std::move(func)); workerCv.notify_all(); return; } @@ -394,7 +394,7 @@ if (mctpStatus == Status::Reset || mctpStatus == Status::Terminating) { lg2::error("nvme endpoint is invalid", "DEVICE", device->describe()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device)); }); return; @@ -425,12 +425,12 @@ } if (rc != 0) { - self->io.post([cb{std::move(cb)}]() { + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::bad_message)); }); return; } - self->io.post([cb{std::move(cb)}]() { cb({}); }); + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb({}); }); }); } catch (const std::runtime_error& e) @@ -447,7 +447,7 @@ if (mctpStatus == Status::Reset || mctpStatus == Status::Terminating) { lg2::error("nvme endpoint is invalid", "DEVICE", device->describe()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device)); }); return; @@ -465,7 +465,7 @@ { lg2::error("failed to set remote MCTP MTU for port: {PORT}", "DEVICE", self->device->describe(), "PORT", port); - self->io.post([cb{std::move(cb)}]() { + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::bad_message)); }); return; @@ -473,20 +473,20 @@ self->mtu = mtu; if (maxSupportedFreq >= 2) { - self->io.post([self, port, maxSupportedFreq, - cb{std::move(cb)}]() mutable { + boost::asio::post(self->io, [self, port, maxSupportedFreq, + cb{std::move(cb)}]() mutable { self->miConfigureSMBusFrequency(port, maxSupportedFreq, std::move(cb)); }); return; } - self->io.post([cb{std::move(cb)}]() { cb({}); }); + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb({}); }); }); } catch (const std::runtime_error& e) { lg2::error("{ERROR}", "DEVICE", device->describe(), "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device)); }); return; @@ -499,7 +499,7 @@ if (mctpStatus == Status::Reset || mctpStatus == Status::Terminating) { lg2::error("nvme endpoint is invalid", "DEVICE", device->describe()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device)); }); return; @@ -516,7 +516,7 @@ { lg2::error("Failed reading subsystem info failing", "DEVICE", self->device->describe()); - self->io.post([cb{std::move(cb)}]() { + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::bad_message)); }); return; @@ -538,8 +538,9 @@ { uint16_t supportedMtu = portInfo.mmctptus; uint8_t supportedFreq = portInfo.smb.mme_freq; // NOLINT - self->io.post([self, portId, supportedMtu, supportedFreq, - cb{std::move(cb)}]() mutable { + boost::asio::post(self->io, [self, portId, supportedMtu, + supportedFreq, + cb{std::move(cb)}]() mutable { self->miConfigureRemoteMCTP( portId, supportedMtu, supportedFreq, std::move(cb)); }); @@ -547,7 +548,7 @@ } } // Didn't find the SMbus port - self->io.post([cb{std::move(cb)}]() { + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device)); }); }); @@ -555,7 +556,7 @@ catch (const std::runtime_error& e) { lg2::error("{ERROR}", "DEVICE", device->describe(), "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device)); }); return; @@ -610,7 +611,7 @@ lg2::error("MCTP connection is not established", "DEVICE", device->describe()); - io.post([cb{std::move(cb)}, errc{degraded.value()}]() { + boost::asio::post(io, [cb{std::move(cb)}, errc{degraded.value()}]() { cb(errc, nullptr); }); return; @@ -627,7 +628,8 @@ lg2::error("fail to subsystem_health_status_poll: {ERROR}", "ENDPOINT", ep->describe(), "ERROR", strerror(errno)); - self->io.post([cb{cb}, lastErrno{errno}]() mutable { + boost::asio::post(self->io, + [cb{cb}, lastErrno{errno}]() mutable { cb(std::make_error_code(static_cast<std::errc>(lastErrno)), nullptr); }); @@ -639,20 +641,21 @@ statusToString(static_cast<nvme_mi_resp_status>(rc)); lg2::error("fail to subsystem_health_status_poll: {ERROR}", "ENDPOINT", ep->describe(), "ERROR", errMsg.data()); - self->io.post([cb{cb}]() mutable { + boost::asio::post(self->io, [cb{cb}]() mutable { cb(std::make_error_code(std::errc::bad_message), nullptr); }); return; } - self->io.post( - [cb{cb}, ssHealth{ssHealth}]() mutable { cb({}, &ssHealth); }); + boost::asio::post(self->io, [cb{cb}, ssHealth{ssHealth}]() mutable { + cb({}, &ssHealth); + }); }); } catch (const std::runtime_error& e) { lg2::error("{ERROR}", "DEVICE", device->describe(), "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), {}); }); return; @@ -668,8 +671,9 @@ lg2::error("MCTP connection is not established", "DEVICE", device->describe()); - io.post( - [cb{std::move(cb)}, errc{degraded.value()}]() { cb(errc, {}); }); + boost::asio::post(io, [cb{std::move(cb)}, errc{degraded.value()}]() { + cb(errc, {}); + }); return; } @@ -681,7 +685,8 @@ { lg2::error("fail to scan controllers: {ERROR}", "ENDPOINT", ep->describe(), "ERROR", strerror(errno)); - self->io.post([cb{cb}, lastErrno{errno}]() mutable { + boost::asio::post(self->io, + [cb{cb}, lastErrno{errno}]() mutable { cb(std::make_error_code(static_cast<std::errc>(lastErrno)), {}); }); @@ -693,7 +698,7 @@ statusToString(static_cast<nvme_mi_resp_status>(rc)); lg2::error("fail to scan controllers: {ERROR}", "ENDPOINT", ep->describe(), "ERROR", errMsg.data()); - self->io.post([cb{cb}]() mutable { + boost::asio::post(self->io, [cb{cb}]() mutable { cb(std::make_error_code(std::errc::bad_message), {}); }); return; @@ -705,7 +710,8 @@ { list.push_back(c); } - self->io.post( + boost::asio::post( + self->io, [cb{cb}, list{std::move(list)}]() mutable { cb({}, list); }); }); } @@ -713,7 +719,7 @@ { lg2::error("{ERROR}", "ENDPOINT", endpoint->describe(), "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), {}); }); return; @@ -725,7 +731,7 @@ try { post([self{shared_from_this()}, cb{std::move(cb)}]() { - self->io.post(cb); + boost::asio::post(self->io, cb); }); return true; @@ -745,7 +751,7 @@ { lg2::error("MCTP connection is not established", "DEVICE", device->describe()); - io.post([cb{std::move(cb)}, errc{degraded.value()}]() { + boost::asio::post(io, [cb{std::move(cb)}, errc{degraded.value()}]() { cb(makeLibNVMeError("nvme endpoint is degraded"), {}); }); return; @@ -818,7 +824,8 @@ ex->description()); } - self->io.post([cb{cb}, ex, data{std::move(data)}]() mutable { + boost::asio::post(self->io, + [cb{cb}, ex, data{std::move(data)}]() mutable { std::span<uint8_t> span{data.data(), data.size()}; cb(ex, span); }); @@ -830,7 +837,8 @@ e.what()); auto msg = std::string("Runtime error: ") + e.what(); lg2::error("{MSG}", "MSG", msg); - io.post([cb{std::move(cb)}, msg]() { cb(makeLibNVMeError(msg), {}); }); + boost::asio::post( + io, [cb{std::move(cb)}, msg]() { cb(makeLibNVMeError(msg), {}); }); return; } } @@ -967,8 +975,8 @@ { // Propagates the final success status and the final propagated failure // state - this->io.post([finalCb, lastNvmeStatus, lastCompletionDw0, - lastFailureScope, lastFailureId]() { + boost::asio::post(this->io, [finalCb, lastNvmeStatus, lastCompletionDw0, + lastFailureScope, lastFailureId]() { finalCb(std::error_code(), lastNvmeStatus, lastCompletionDw0, lastFailureScope, lastFailureId); }); @@ -1056,8 +1064,8 @@ // Call the final D-Bus callback with the specific failure context (current // status is the error status). - this->io.post([finalCb, currentErrno, nvmeStatus, completionDw0, - failureScope, failureId]() { + boost::asio::post(this->io, [finalCb, currentErrno, nvmeStatus, + completionDw0, failureScope, failureId]() { finalCb(std::make_error_code(static_cast<std::errc>(currentErrno)), nvmeStatus, completionDw0, failureScope, failureId); }); @@ -1072,8 +1080,9 @@ { lg2::error("MCTP connection is not established", "DEVICE", device->describe()); - io.post( - [cb{std::move(cb)}, errc{degraded.value()}]() { cb(errc, {}); }); + boost::asio::post(io, [cb{std::move(cb)}, errc{degraded.value()}]() { + cb(errc, {}); + }); return; } @@ -1311,7 +1320,7 @@ { lg2::error("NVMeMi adminGetLogPage throws: {ERROR}", "ENDPOINT", endpoint->describe(), "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), {}); }); return; @@ -1353,7 +1362,8 @@ lg2::error("adminLockdownInband post failed: {ERROR}", "DEVICE", device->describe(), "ERROR", postErr.message()); - io.post([cb{std::move(cb)}, postErr]() { cb(postErr, -1, 0, "", 0); }); + boost::asio::post( + io, [cb{std::move(cb)}, postErr]() { cb(postErr, -1, 0, "", 0); }); } } @@ -1367,7 +1377,7 @@ { lg2::error("MCTP connection is not established", "DEVICE", device->describe()); - io.post([cb{std::move(cb)}, errc{degraded.value()}]() { + boost::asio::post(io, [cb{std::move(cb)}, errc{degraded.value()}]() { cb(errc, {}, {}); }); return; @@ -1415,7 +1425,8 @@ { lg2::error("failed to nvme_mi_admin_xfer", "ENDPOINT", ep->describe()); - self->io.post([cb{std::move(cb)}, lastErrno{errno}]() { + boost::asio::post(self->io, + [cb{std::move(cb)}, lastErrno{errno}]() { cb(std::make_error_code(static_cast<std::errc>(lastErrno)), {}, {}); }); @@ -1427,7 +1438,8 @@ // value (cdw0) is also client's job. buf.resize(sizeof(nvme_mi_admin_resp_hdr) + respDataSize); - self->io.post([cb{std::move(cb)}, data{std::move(buf)}]() mutable { + boost::asio::post( + self->io, [cb{std::move(cb)}, data{std::move(buf)}]() mutable { std::span<uint8_t> span( data.begin() + sizeof(nvme_mi_admin_resp_hdr), data.end()); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) @@ -1440,7 +1452,7 @@ { lg2::error("{ERROR}", "ENDPOINT", endpoint->describe(), "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), {}, {}); }); return; @@ -1455,7 +1467,7 @@ { lg2::error("MCTP connection is not established", "DEVICE", device->describe()); - io.post([cb{std::move(cb)}, errc{degraded.value()}]() { + boost::asio::post(io, [cb{std::move(cb)}, errc{degraded.value()}]() { cb(errc, nvme_status_field::NVME_SC_MASK); }); return; @@ -1468,15 +1480,16 @@ args.action = action; args.slot = slot; args.bpid = bpid; - io.post([ctrl, args, cb{std::move(cb)}, ep{endpoint}, - self{shared_from_this()}]() mutable { + boost::asio::post(io, [ctrl, args, cb{std::move(cb)}, ep{endpoint}, + self{shared_from_this()}]() mutable { int rc = nvme_mi_admin_fw_commit(ctrl, &args); if (rc < 0) { lg2::error("fail to nvme_mi_admin_fw_commit: {ERROR}", "ENDPOINT", ep->describe(), "ERROR", strerror(errno)); - self->io.post([cb{std::move(cb)}, lastErrno{errno}]() { + boost::asio::post(self->io, + [cb{std::move(cb)}, lastErrno{errno}]() { cb(std::make_error_code(static_cast<std::errc>(lastErrno)), nvme_status_field::NVME_SC_MASK); }); @@ -1490,7 +1503,7 @@ case NVME_SC_FW_NEEDS_CONV_RESET: case NVME_SC_FW_NEEDS_SUBSYS_RESET: case NVME_SC_FW_NEEDS_RESET: - self->io.post([rc, cb{std::move(cb)}]() { + boost::asio::post(self->io, [rc, cb{std::move(cb)}]() { cb({}, static_cast<nvme_status_field>(rc)); }); break; @@ -1499,7 +1512,7 @@ static_cast<nvme_mi_resp_status>(rc)); lg2::error("fail to nvme_mi_admin_fw_commit: {ERROR}", "ERROR", errMsg.data()); - self->io.post([rc, cb{std::move(cb)}]() { + boost::asio::post(self->io, [rc, cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::bad_message), static_cast<nvme_status_field>(rc)); }); @@ -1512,7 +1525,7 @@ { lg2::error("{ERROR}", "ENDPOINT", endpoint->describe(), "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), nvme_status_field::NVME_SC_MASK); }); @@ -1529,7 +1542,7 @@ { lg2::error("MCTP connection is not established", "DEVICE", device->describe()); - io.post([cb{std::move(cb)}, errc{degraded.value()}]() { + boost::asio::post(io, [cb{std::move(cb)}, errc{degraded.value()}]() { cb(errc, nvme_status_field::NVME_SC_MASK); }); return; @@ -1544,7 +1557,7 @@ { lg2::error("fail to open fw image file: {FILE}, {ERROR}", "FILE", firmwarefile, "ERROR", strerror(errno)); - self->io.post([cb{std::move(cb)}]() { + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb(std::make_error_code(static_cast<std::errc>(errno)), nvme_status_field::NVME_SC_MASK); }); @@ -1578,7 +1591,7 @@ { lg2::error("fail to nvme_mi_admin_fw_download: {ERROR}", "ERROR", strerror(errno)); - self->io.post([cb{std::move(cb)}]() { + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb(std::make_error_code(static_cast<std::errc>(errno)), nvme_status_field::NVME_SC_MASK); }); @@ -1595,13 +1608,14 @@ lg2::info( "Successfully transferred the firmware. Transfer Size: {XFER}, Total Size: {SIZE}", "XFER", offset, "SIZE", size); - self->io.post([rc, cb{std::move(cb)}]() { + boost::asio::post(self->io, [rc, cb{std::move(cb)}]() { cb({}, static_cast<nvme_status_field>(rc)); }); return; } - self->io.post([self, ctrl, firmwarefile, size, offset, attemptCount, - cb{std::move(cb)}]() mutable { + boost::asio::post(self->io, + [self, ctrl, firmwarefile, size, offset, + attemptCount, cb{std::move(cb)}]() mutable { self->adminFwDownloadChunk(ctrl, firmwarefile, size, offset, attemptCount, std::move(cb)); }); @@ -1610,7 +1624,7 @@ catch (const std::runtime_error& e) { lg2::error("{ERROR}", "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), nvme_status_field::NVME_SC_MASK); }); @@ -1630,7 +1644,7 @@ { lg2::error("Can't open the firmware file: {ERROR}", "ERROR", strerror(errno)); - io.post([cb{cb}]() { + boost::asio::post(io, [cb{cb}]() { cb(std::make_error_code(std::errc::no_such_device), nvme_status_field::NVME_SC_MASK); }); @@ -1663,7 +1677,8 @@ int status = nvme_mi_admin_security_send(ctrl, &args); nvme_mi_ep_set_timeout(self->nvmeEP, timeout); - self->io.post([cb{cb}, nvmeErrno{errno}, status]() mutable { + boost::asio::post(self->io, + [cb{cb}, nvmeErrno{errno}, status]() mutable { auto err = std::make_error_code(static_cast<std::errc>(nvmeErrno)); cb(err, status); }); @@ -1672,7 +1687,8 @@ { lg2::error("adminSecuritySend post failed: {ERROR}", "DEVICE", device->describe(), "ERROR", postErr.message()); - io.post([cb{std::move(cb)}, postErr]() { cb(postErr, -1); }); + boost::asio::post(io, + [cb{std::move(cb)}, postErr]() { cb(postErr, -1); }); } } @@ -1713,14 +1729,15 @@ lg2::error( "nvme_mi_admin_security_send returned excess data, {LEN}", "DEVICE", self->device->describe(), "LEN", args.data_len); - self->io.post([cb]() { + boost::asio::post(self->io, [cb]() { cb(std::make_error_code(std::errc::protocol_error), -1, {}); }); return; } data.resize(args.data_len); - self->io.post([cb{cb}, nvmeErrno{errno}, status, data]() mutable { + boost::asio::post(self->io, + [cb{cb}, nvmeErrno{errno}, status, data]() mutable { std::span<uint8_t> span{data.data(), data.size()}; auto err = std::make_error_code(static_cast<std::errc>(nvmeErrno)); cb(err, status, span); @@ -1730,7 +1747,8 @@ { lg2::error("adminSecurityReceive post failed: {ERROR}", "DEVICE", device->describe(), "ERROR", postErr.message()); - io.post([cb{std::move(cb)}, postErr]() { cb(postErr, -1, {}); }); + boost::asio::post( + io, [cb{std::move(cb)}, postErr]() { cb(postErr, -1, {}); }); } } @@ -1748,8 +1766,8 @@ int nvmeStatus = nvme_mi_admin_admin_passthru( ctrl, opcode, 0, 0, cdw1, cdw2, cdw3, cdw10, cdw11, cdw12, cdw13, cdw14, cdw15, 0, nullptr, 0, nullptr, 10 * 1000, &comptionDw0); - self->io.post( - [cb{cb}, nvmeErrno{errno}, nvmeStatus, comptionDw0]() mutable { + boost::asio::post(self->io, [cb{cb}, nvmeErrno{errno}, nvmeStatus, + comptionDw0]() mutable { auto err = std::make_error_code(static_cast<std::errc>(nvmeErrno)); cb(err, nvmeStatus, comptionDw0); }); @@ -1758,7 +1776,8 @@ { lg2::error("adminNonDataCmd post failed: {ERROR}", "DEVICE", device->describe(), "ERROR", postErr.message()); - io.post([cb{std::move(cb)}, postErr]() { cb(postErr, -1, 0); }); + boost::asio::post( + io, [cb{std::move(cb)}, postErr]() { cb(postErr, -1, 0); }); } } @@ -1855,7 +1874,7 @@ // submission has been verified. Handle the cb in main thread // concurrently. - self->io.post([submittedCb{submittedCb}]() mutable { + boost::asio::post(self->io, [submittedCb{submittedCb}]() mutable { submittedCb(nvme_ex_ptr()); }); lg2::debug("after submitted_cb {TID}", "TID", (int)gettid()); @@ -1876,7 +1895,8 @@ .metadataAtEnd = metadataAtEnd, }; - self->io.post([finishedCb{finishedCb}, e, newns]() mutable { + boost::asio::post(self->io, + [finishedCb{finishedCb}, e, newns]() mutable { finishedCb(e, newns); }); @@ -1903,7 +1923,8 @@ lg2::error("createNamespace post failed: {ERROR}", "ERROR", postErr.message()); auto e = makeLibNVMeError(postErr, -1, "createVolume"); - io.post([submittedCb{std::move(submittedCb)}, e]() { submittedCb(e); }); + boost::asio::post( + io, [submittedCb{std::move(submittedCb)}, e]() { submittedCb(e); }); } } @@ -1919,7 +1940,8 @@ int status = nvme_mi_admin_ns_mgmt_delete(ctrl, nsid); nvme_mi_ep_set_timeout(self->nvmeEP, timeout); - self->io.post([cb{cb}, nvmeErrno{errno}, status]() mutable { + boost::asio::post(self->io, + [cb{cb}, nvmeErrno{errno}, status]() mutable { auto err = std::make_error_code(static_cast<std::errc>(nvmeErrno)); cb(err, status); }); @@ -1928,7 +1950,8 @@ { lg2::error("deleteNamespace post failed: {ERROR}", "ERROR", postErr.message()); - io.post([cb{std::move(cb)}, postErr]() { cb(postErr, -1); }); + boost::asio::post(io, + [cb{std::move(cb)}, postErr]() { cb(postErr, -1); }); } } @@ -1977,12 +2000,13 @@ } auto ex = makeLibNVMeError(nvmeErrno, status, "adminListNamespaces"); - self->io.post([cb{cb}, ex, ns]() mutable { cb(ex, ns); }); + boost::asio::post(self->io, [cb{cb}, ex, ns]() mutable { cb(ex, ns); }); }); if (postErr) { auto ex = makeLibNVMeError("post failed"); - io.post([cb{std::move(cb)}, ex]() { cb(ex, std::vector<uint32_t>()); }); + boost::asio::post( + io, [cb{std::move(cb)}, ex]() { cb(ex, std::vector<uint32_t>()); }); } } @@ -2017,7 +2041,8 @@ nvme_mi_ep_set_timeout(self->nvmeEP, namespaceDefaultTimeoutMS); int status = nvme_mi_admin_ns_attach(ctrl, &args); nvme_mi_ep_set_timeout(self->nvmeEP, timeout); - self->io.post([cb{cb}, nvmeErrno{errno}, status]() mutable { + boost::asio::post(self->io, + [cb{cb}, nvmeErrno{errno}, status]() mutable { auto err = std::make_error_code(static_cast<std::errc>(nvmeErrno)); cb(err, status); }); @@ -2026,7 +2051,8 @@ { lg2::error("adminAttachDetachNamespace post failed: {ERROR}", "ERROR", postErr.message()); - io.post([cb{std::move(cb)}, postErr]() { cb(postErr, -1); }); + boost::asio::post(io, + [cb{std::move(cb)}, postErr]() { cb(postErr, -1); }); } } @@ -2052,11 +2078,11 @@ "ERRNO", errno); auto ex = makeLibNVMeError(errno, status, "adminSanitize"); - self->io.post([cb{cb}, ex]() mutable { cb(ex); }); + boost::asio::post(self->io, [cb{cb}, ex]() mutable { cb(ex); }); }); if (postErr) { auto ex = makeLibNVMeError("post failed"); - io.post([cb{std::move(cb)}, ex]() { cb(ex); }); + boost::asio::post(io, [cb{std::move(cb)}, ex]() { cb(ex); }); } }
diff --git a/src/NVMeMiFake.hpp b/src/NVMeMiFake.hpp index 3766582..091e16b 100644 --- a/src/NVMeMiFake.hpp +++ b/src/NVMeMiFake.hpp
@@ -95,7 +95,7 @@ std::function<void(const std::error_code&, nvme_mi_nvm_ss_health_status*)>&& cb) override { - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { nvme_mi_nvm_ss_health_status status{}; status.nss = 1 << 5; status.ctemp = 24; @@ -111,7 +111,7 @@ { lg2::error("worker thread for nvme endpoint is stopped"); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), {}); }); return; @@ -119,7 +119,8 @@ post([self{shared_from_this()}, cb = std::move(cb)] { lg2::info("libnvme: scan"); - self->io.post([self{self->shared_from_this()}, cb{cb}]() mutable { + boost::asio::post( + self->io, [self{self->shared_from_this()}, cb{cb}]() mutable { auto& ctrl1 = self->ctrls[0]; auto& ctrl2 = self->ctrls[1]; auto& ctrl3 = self->ctrls[2]; @@ -135,7 +136,7 @@ bool flushOperations(std::function<void()>&& cb) override { post([self{shared_from_this()}, cb{std::move(cb)}]() { - self->io.post(cb); + boost::asio::post(self->io, cb); }); return true; } @@ -148,7 +149,7 @@ lg2::info("identify"); post([self{shared_from_this()}, cb = std::move(cb), cns, nsid]() { lg2::info("libnvme: identify"); - self->io.post([cb{cb}, cns, nsid]() mutable { + boost::asio::post(self->io, [cb{cb}, cns, nsid]() mutable { std::vector<uint8_t> data; switch (cns) { @@ -271,11 +272,13 @@ } catch (const ::std::system_error& e) { - self->io.post( + boost::asio::post( + self->io, [cb{cb}, ec = e.code()]() mutable { cb(ec, {}); }); return; } - self->io.post([cb{cb}, data{std::move(data)}]() mutable { + boost::asio::post(self->io, + [cb{cb}, data{std::move(data)}]() mutable { std::span<uint8_t> span{data.data(), data.size()}; cb({}, span); }); @@ -284,7 +287,7 @@ catch (const std::runtime_error& e) { lg2::error("{ERROR}", "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), {}); }); return; @@ -302,14 +305,15 @@ args.action = action; args.slot = slot; args.bpid = bpid; - io.post([cb{std::move(cb)}, self{shared_from_this()}]() mutable { + boost::asio::post( + io, [cb{std::move(cb)}, self{shared_from_this()}]() mutable { // int rc = nvme_mi_admin_fw_commit(ctrl, &args); int rc = 1; if (rc < 0) { lg2::error("fail to subsystem_health_status_poll: {ERROR}", "ERROR", strerror(errno)); - self->io.post([cb{std::move(cb)}]() { + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb(std::make_error_code(static_cast<std::errc>(errno)), nvme_status_field::NVME_SC_MASK); }); @@ -322,7 +326,8 @@ case NVME_SC_FW_NEEDS_CONV_RESET: case NVME_SC_FW_NEEDS_SUBSYS_RESET: case NVME_SC_FW_NEEDS_RESET: - self->io.post([rc, cb{std::move(cb)}]() { + boost::asio::post(self->io, + [rc, cb{std::move(cb)}]() { cb({}, static_cast<nvme_status_field>(rc)); }); break; @@ -332,7 +337,8 @@ lg2::error( "fail to subsystem_health_status_poll: {ERROR}", "ERROR", errMsg.data()); - self->io.post([rc, cb{std::move(cb)}]() { + boost::asio::post(self->io, + [rc, cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::bad_message), static_cast<nvme_status_field>(rc)); }); @@ -344,7 +350,7 @@ catch (const std::runtime_error& e) { lg2::error("{ERROR}", "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), nvme_status_field::NVME_SC_MASK); }); @@ -392,7 +398,7 @@ if (rc < 0) { lg2::error("failed to nvme_mi_admin_xfer"); - self->io.post([cb{std::move(cb)}]() { + boost::asio::post(self->io, [cb{std::move(cb)}]() { cb(std::make_error_code(static_cast<std::errc>(errno)), {}, {}); }); @@ -404,8 +410,8 @@ // value (cdw0) is also client's job. buf.resize(sizeof(nvme_mi_admin_resp_hdr) + respDataSize); - self->io.post( - [cb{std::move(cb)}, data{std::move(buf)}]() mutable { + boost::asio::post(self->io, [cb{std::move(cb)}, + data{std::move(buf)}]() mutable { std::span<uint8_t> span(data.begin() + sizeof(nvme_mi_admin_resp_hdr), data.end()); @@ -425,7 +431,7 @@ catch (const std::runtime_error& e) { lg2::error("{ERROR}", "ERROR", e.what()); - io.post([cb{std::move(cb)}]() { + boost::asio::post(io, [cb{std::move(cb)}]() { cb(std::make_error_code(std::errc::no_such_device), {}, {}); }); return; @@ -440,7 +446,7 @@ const std::error_code&, int nvmeStatus, uint32_t comptionDw0, const std::string& failureScope, uint32_t failureId)>&& cb) override { - io.post([cb = std::move(cb)]() mutable { + boost::asio::post(io, [cb = std::move(cb)]() mutable { cb(std::make_error_code(std::errc::not_supported), -1, 0, "", 0); }); }
diff --git a/src/NVMeSensorMain.cpp b/src/NVMeSensorMain.cpp index 111dffb..953a349 100644 --- a/src/NVMeSensorMain.cpp +++ b/src/NVMeSensorMain.cpp
@@ -216,7 +216,7 @@ return; } // Setup failed, wait a bit and try again - timer->expires_from_now(std::chrono::seconds(5)); + timer->expires_after(std::chrono::seconds(5)); timer->async_wait([=](const boost::system::error_code& ec) { if (!ec) { @@ -260,7 +260,7 @@ std::cout << "[" << ep->describe() << "]: Removed" << '\n'; miIntf->stop(); // Start polling for the return of the device - timer->expires_from_now(std::chrono::seconds(5)); + timer->expires_after(std::chrono::seconds(5)); timer->async_wait([=](const boost::system::error_code& ec) { if (!ec) { @@ -639,7 +639,8 @@ objectServer.add_manager("/xyz/openbmc_project/sensors"); objectServer.add_manager("/xyz/openbmc_project/inventory"); - io.post([&]() { createNVMeSubsystems(io, objectServer, systemBus); }); + boost::asio::post( + io, [&]() { createNVMeSubsystems(io, objectServer, systemBus); }); boost::asio::steady_timer filterTimer(io); std::function<void(sdbusplus::message_t&)> eventHandler =
diff --git a/src/NVMeSubsys.cpp b/src/NVMeSubsys.cpp index a507174..e4eb2ab 100644 --- a/src/NVMeSubsys.cpp +++ b/src/NVMeSubsys.cpp
@@ -225,8 +225,8 @@ } primaryController->setPrimary(secCntrls); - boost::asio::spawn(io, [self{shared_from_this()}]( - const boost::asio::yield_context& yield) { + (void)boost::asio::spawn(io, [self{shared_from_this()}]( + const boost::asio::yield_context& yield) { try { self->fillDrive(yield);
diff --git a/tests/test_nvme_mi.cpp b/tests/test_nvme_mi.cpp index bf8d03e..77e4927 100644 --- a/tests/test_nvme_mi.cpp +++ b/tests/test_nvme_mi.cpp
@@ -396,7 +396,7 @@ cb) { std::cerr << "mock device not functional health poll" << '\n'; // return status.nss.df = 0 - return io.post([cb = std::move(cb)]() { + return boost::asio::post(io, [cb = std::move(cb)]() { nvme_mi_nvm_ss_health_status status{}; status.nss = 0; cb({}, &status); @@ -511,7 +511,7 @@ cb) { std::cerr << "mock device absent health poll" << '\n'; // return no_such_device - return io.post([cb = std::move(cb)]() { + return boost::asio::post(io, [cb = std::move(cb)]() { cb(std::make_error_code(std::errc::no_such_device), nullptr); });