diff options
| author | Paul Lawrence <paullawrence@google.com> | 2019-01-30 11:34:33 -0800 |
|---|---|---|
| committer | Paul Lawrence <paullawrence@google.com> | 2019-01-30 13:29:41 -0800 |
| commit | 605fef0e17facd3c415b6469801cd9e7c89a4b7c (patch) | |
| tree | 69d8f041c58101429a752cc73604378aa448348d | |
| parent | c8b83f3874cdef096b37e01ded8a15a47dbfa1c2 (diff) | |
| download | system_core-605fef0e17facd3c415b6469801cd9e7c89a4b7c.tar.gz system_core-605fef0e17facd3c415b6469801cd9e7c89a4b7c.tar.bz2 system_core-605fef0e17facd3c415b6469801cd9e7c89a4b7c.zip | |
Improved libdm and dmctl to handle very large numbers of extents
Enables performance testing with very large numbers of dm-linear devices
Test: Can create device with 16384 extents, and can get its table
Bug: 123261135
Change-Id: I0e78a659eb7616e4db6a8276031e25a0d84f52ba
| -rw-r--r-- | fs_mgr/libdm/dm.cpp | 35 | ||||
| -rw-r--r-- | fs_mgr/tools/dmctl.cpp | 32 |
2 files changed, 50 insertions, 17 deletions
diff --git a/fs_mgr/libdm/dm.cpp b/fs_mgr/libdm/dm.cpp index c6a9e0bcc..a4614d02f 100644 --- a/fs_mgr/libdm/dm.cpp +++ b/fs_mgr/libdm/dm.cpp @@ -299,24 +299,25 @@ bool DeviceMapper::GetTableInfo(const std::string& name, std::vector<TargetInfo> // private methods of DeviceMapper bool DeviceMapper::GetTable(const std::string& name, uint32_t flags, std::vector<TargetInfo>* table) { - char buffer[4096]; - struct dm_ioctl* io = reinterpret_cast<struct dm_ioctl*>(buffer); - - InitIo(io, name); - io->data_size = sizeof(buffer); - io->data_start = sizeof(*io); - io->flags = flags; - if (ioctl(fd_, DM_TABLE_STATUS, io) < 0) { - PLOG(ERROR) << "DM_TABLE_STATUS failed for " << name; - return false; - } - if (io->flags & DM_BUFFER_FULL_FLAG) { - PLOG(ERROR) << "DM_TABLE_STATUS result for " << name << " was too large"; - return false; + std::vector<char> buffer; + struct dm_ioctl* io = nullptr; + + for (buffer.resize(4096);; buffer.resize(buffer.size() * 2)) { + io = reinterpret_cast<struct dm_ioctl*>(&buffer[0]); + + InitIo(io, name); + io->data_size = buffer.size(); + io->data_start = sizeof(*io); + io->flags = flags; + if (ioctl(fd_, DM_TABLE_STATUS, io) < 0) { + PLOG(ERROR) << "DM_TABLE_STATUS failed for " << name; + return false; + } + if (!(io->flags & DM_BUFFER_FULL_FLAG)) break; } uint32_t cursor = io->data_start; - uint32_t data_end = std::min(io->data_size, uint32_t(sizeof(buffer))); + uint32_t data_end = std::min(io->data_size, uint32_t(buffer.size())); for (uint32_t i = 0; i < io->target_count; i++) { if (cursor + sizeof(struct dm_target_spec) > data_end) { break; @@ -324,14 +325,14 @@ bool DeviceMapper::GetTable(const std::string& name, uint32_t flags, // After each dm_target_spec is a status string. spec->next is an // offset from |io->data_start|, and we clamp it to the size of our // buffer. - struct dm_target_spec* spec = reinterpret_cast<struct dm_target_spec*>(buffer + cursor); + struct dm_target_spec* spec = reinterpret_cast<struct dm_target_spec*>(&buffer[cursor]); uint32_t data_offset = cursor + sizeof(dm_target_spec); uint32_t next_cursor = std::min(io->data_start + spec->next, data_end); std::string data; if (next_cursor > data_offset) { // Note: we use c_str() to eliminate any extra trailing 0s. - data = std::string(buffer + data_offset, next_cursor - data_offset).c_str(); + data = std::string(&buffer[data_offset], next_cursor - data_offset).c_str(); } table->emplace_back(*spec, data); cursor = next_cursor; diff --git a/fs_mgr/tools/dmctl.cpp b/fs_mgr/tools/dmctl.cpp index 3b6ff9b95..63661f0aa 100644 --- a/fs_mgr/tools/dmctl.cpp +++ b/fs_mgr/tools/dmctl.cpp @@ -27,6 +27,7 @@ #include <android-base/unique_fd.h> #include <libdm/dm.h> +#include <fstream> #include <functional> #include <iomanip> #include <ios> @@ -50,6 +51,7 @@ using DmBlockDevice = ::android::dm::DeviceMapper::DmBlockDevice; static int Usage(void) { std::cerr << "usage: dmctl <command> [command options]" << std::endl; + std::cerr << " dmctl -f file" << std::endl; std::cerr << "commands:" << std::endl; std::cerr << " create <dm-name> [-ro] <targets...>" << std::endl; std::cerr << " delete <dm-name>" << std::endl; @@ -58,6 +60,8 @@ static int Usage(void) { std::cerr << " table <dm-name>" << std::endl; std::cerr << " help" << std::endl; std::cerr << std::endl; + std::cerr << "-f file reads command and all parameters from named file" << std::endl; + std::cerr << std::endl; std::cerr << "Target syntax:" << std::endl; std::cerr << " <target_type> <start_sector> <num_sectors> [target_data]" << std::endl; return -EINVAL; @@ -340,12 +344,40 @@ static std::map<std::string, std::function<int(int, char**)>> cmdmap = { // clang-format on }; +static bool ReadFile(const char* filename, std::vector<std::string>* args, + std::vector<char*>* arg_ptrs) { + std::ifstream file(filename); + if (!file) return false; + + std::string arg; + while (file >> arg) args->push_back(arg); + + for (auto const& i : *args) arg_ptrs->push_back(const_cast<char*>(i.c_str())); + return true; +} + int main(int argc, char** argv) { android::base::InitLogging(argv, &android::base::StderrLogger); if (argc < 2) { return Usage(); } + std::vector<std::string> args; + std::vector<char*> arg_ptrs; + if (std::string("-f") == argv[1]) { + if (argc != 3) { + return Usage(); + } + + args.push_back(argv[0]); + if (!ReadFile(argv[2], &args, &arg_ptrs)) { + return Usage(); + } + + argc = arg_ptrs.size(); + argv = &arg_ptrs[0]; + } + for (const auto& cmd : cmdmap) { if (cmd.first == argv[1]) { return cmd.second(argc - 2, argv + 2); |
