blob: 5ca69ac8b55aca514bdc5cb1bc35f82aae43ff1c [file] [log] [blame] [edit]
From 7bf1e5702c953531e1a1aaa22519216a12c6b4c4 Mon Sep 17 00:00:00 2001
From: Hao Jiang <jianghao@google.com>
Date: Thu, 29 Sep 2022 18:47:09 +0000
Subject: [PATCH 09/44] Add Identify method to NVMeAdmin interface
This method is used to send NVMe admin command `Identify` to the target
controller. It will return a fd to read the raw data field of the
NVMe-MI admin response message.
Signed-off-by: Hao Jiang <jianghao@google.com>
Change-Id: I5109af51d6e50e53bda2498bf34656fad4dbe557
---
src/NVMeController.cpp | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/NVMeController.cpp b/src/NVMeController.cpp
index 0479723..dc88cf6 100644
--- a/src/NVMeController.cpp
+++ b/src/NVMeController.cpp
@@ -54,6 +54,39 @@ NVMeController::NVMeController(
});
return sdbusplus::message::unix_fd{pipe[0]};
});
+
+ adminIntf->register_method(
+ "Identify",
+ [nvmeIntf, nvmeCtrl{ctrl}](uint8_t cns, uint16_t cntid, uint32_t nsid) {
+ std::array<int, 2> pipe;
+ if (::pipe(pipe.data()) < 0)
+ {
+ std::cerr << "Identify fails to open pipe: " << std::strerror(errno)
+ << std::endl;
+ throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open();
+ }
+
+ nvmeIntf->adminIdentify(
+ nvmeCtrl, static_cast<nvme_identify_cns>(cns), nsid, cntid,
+ [pipe](const std::error_code& ec, std::span<uint8_t> data) {
+ ::close(pipe[0]);
+ int fd = pipe[1];
+ if (ec)
+ {
+ std::cerr << "fail to Identify: " << ec.message() << std::endl;
+ close(fd);
+ return;
+ }
+ if (write(fd, data.data(), data.size()) < 0)
+ {
+ std::cerr << "Identify fails to write fd: "
+ << std::strerror(errno) << std::endl;
+ };
+ close(fd);
+ });
+ return sdbusplus::message::unix_fd{pipe[0]};
+ });
+
adminIntf->initialize();
}
--
2.34.1