From 79338406e07ab3fc8d94761b673a965cd2abd53d Mon Sep 17 00:00:00 2001 From: Alessio Balsini Date: Mon, 29 Jul 2019 19:49:55 +0100 Subject: [PATCH] dmctl: suspend and resume devices Export suspend and resume functionalities of libdm to command line through dmctl. Change-Id: I8e1dd7d67d8814631e4174d3ba169e705efc1df6 Bug: 137759376 Test: manual Signed-off-by: Alessio Balsini --- fs_mgr/tools/dmctl.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/fs_mgr/tools/dmctl.cpp b/fs_mgr/tools/dmctl.cpp index 7e6ad5bf8..d6fb006fa 100644 --- a/fs_mgr/tools/dmctl.cpp +++ b/fs_mgr/tools/dmctl.cpp @@ -50,6 +50,8 @@ static int Usage(void) { std::cerr << " list [-v]" << std::endl; std::cerr << " getpath " << std::endl; std::cerr << " status " << std::endl; + std::cerr << " resume " << std::endl; + std::cerr << " suspend " << std::endl; std::cerr << " table " << std::endl; std::cerr << " help" << std::endl; std::cerr << std::endl; @@ -399,6 +401,34 @@ static int StatusCmdHandler(int argc, char** argv) { return DumpTable("status", argc, argv); } +static int ResumeCmdHandler(int argc, char** argv) { + if (argc != 1) { + std::cerr << "Invalid arguments, see \'dmctl help\'" << std::endl; + return -EINVAL; + } + + DeviceMapper& dm = DeviceMapper::Instance(); + if (!dm.ChangeState(argv[0], DmDeviceState::ACTIVE)) { + std::cerr << "Could not resume device \"" << argv[0] << "\"." << std::endl; + return -EINVAL; + } + return 0; +} + +static int SuspendCmdHandler(int argc, char** argv) { + if (argc != 1) { + std::cerr << "Invalid arguments, see \'dmctl help\'" << std::endl; + return -EINVAL; + } + + DeviceMapper& dm = DeviceMapper::Instance(); + if (!dm.ChangeState(argv[0], DmDeviceState::SUSPENDED)) { + std::cerr << "Could not suspend device \"" << argv[0] << "\"." << std::endl; + return -EINVAL; + } + return 0; +} + static std::map> cmdmap = { // clang-format off {"create", DmCreateCmdHandler}, @@ -408,6 +438,8 @@ static std::map> cmdmap = { {"getpath", GetPathCmdHandler}, {"table", TableCmdHandler}, {"status", StatusCmdHandler}, + {"resume", ResumeCmdHandler}, + {"suspend", SuspendCmdHandler}, // clang-format on };