dmctl: return detailed device information
Return detailed information for devices, i.e.:
- active
- access
- activeTable
- inactiveTable
- bufferFull
Bug: 137759376
Test: manual test
Change-Id: I6aa4ae319adbb5c4ca98823f24010e68e6a0b719
Signed-off-by: Alessio Balsini <balsini@google.com>
diff --git a/fs_mgr/tools/dmctl.cpp b/fs_mgr/tools/dmctl.cpp
index d6fb006..4fb0b83 100644
--- a/fs_mgr/tools/dmctl.cpp
+++ b/fs_mgr/tools/dmctl.cpp
@@ -49,6 +49,7 @@
std::cerr << " delete <dm-name>" << std::endl;
std::cerr << " list <devices | targets> [-v]" << std::endl;
std::cerr << " getpath <dm-name>" << std::endl;
+ std::cerr << " info <dm-name>" << std::endl;
std::cerr << " status <dm-name>" << std::endl;
std::cerr << " resume <dm-name>" << std::endl;
std::cerr << " suspend <dm-name>" << std::endl;
@@ -359,6 +360,41 @@
return 0;
}
+static int InfoCmdHandler(int argc, char** argv) {
+ if (argc != 1) {
+ std::cerr << "Invalid arguments, see \'dmctl help\'" << std::endl;
+ return -EINVAL;
+ }
+
+ DeviceMapper& dm = DeviceMapper::Instance();
+ auto info = dm.GetDetailedInfo(argv[0]);
+ if (!info) {
+ std::cerr << "Invalid device \"" << argv[0] << "\"." << std::endl;
+ return -EINVAL;
+ }
+
+ constexpr int spacing = 14;
+ std::cout << std::left << std::setw(spacing) << "device"
+ << ": " << argv[0] << std::endl;
+ std::cout << std::left << std::setw(spacing) << "active"
+ << ": " << std::boolalpha << !info->IsSuspended() << std::endl;
+ std::cout << std::left << std::setw(spacing) << "access"
+ << ": ";
+ if (info->IsReadOnly()) {
+ std::cout << "ro ";
+ } else {
+ std::cout << "rw ";
+ }
+ std::cout << std::endl;
+ std::cout << std::left << std::setw(spacing) << "activeTable"
+ << ": " << std::boolalpha << info->IsActiveTablePresent() << std::endl;
+ std::cout << std::left << std::setw(spacing) << "inactiveTable"
+ << ": " << std::boolalpha << info->IsInactiveTablePresent() << std::endl;
+ std::cout << std::left << std::setw(spacing) << "bufferFull"
+ << ": " << std::boolalpha << info->IsBufferFull() << std::endl;
+ return 0;
+}
+
static int DumpTable(const std::string& mode, int argc, char** argv) {
if (argc != 1) {
std::cerr << "Invalid arguments, see \'dmctl help\'" << std::endl;
@@ -436,6 +472,7 @@
{"list", DmListCmdHandler},
{"help", HelpCmdHandler},
{"getpath", GetPathCmdHandler},
+ {"info", InfoCmdHandler},
{"table", TableCmdHandler},
{"status", StatusCmdHandler},
{"resume", ResumeCmdHandler},