diff --git a/docs/usage/cli.en.md b/docs/usage/cli.en.md index e304bea3..ae9f37a6 100644 --- a/docs/usage/cli.en.md +++ b/docs/usage/cli.en.md @@ -355,7 +355,7 @@ Set OSD reweight, tags or noout flag. See detail description in [OSD config docu ## pg-list -`vitastor-cli pg-list|pg-ls|list-pg|ls-pg|ls-pgs [OPTIONS] [state1+state2] [^state3] [...]` +`vitastor-cli pg-list|pg-ls|list-pg|ls-pg|ls-pgs|pgs [OPTIONS] [state1+state2] [^state3] [...]` List PGs with any of listed state filters (^ or ! in the beginning is negation). Options: @@ -363,6 +363,7 @@ List PGs with any of listed state filters (^ or ! in the beginning is negation). --pool Only list PGs of the given pool. --min Only list PGs with number >= min. --max Only list PGs with number <= max. +--osd 1,2,... Only list PGs with some data on specified OSD(s). ``` Examples: diff --git a/docs/usage/cli.ru.md b/docs/usage/cli.ru.md index 2cc11880..0b94ea60 100644 --- a/docs/usage/cli.ru.md +++ b/docs/usage/cli.ru.md @@ -375,9 +375,10 @@ OSD PARENT UP SIZE USED% TAGS WEIGHT BLOCK BITMAP в начале фильтра означает отрицание). Опции: ``` ---pool Only list PGs of the given pool. ---min Only list PGs with number >= min. ---max Only list PGs with number <= max. +--pool Вывести только PG в заданном пуле. +--min Вывести только PG с номерами >= min. +--max Вывести только PG с номерами <= max. +--osd 1,2,... Вывести только PG с данными на заданных OSD. ``` Примеры: diff --git a/src/cmd/cli.cpp b/src/cmd/cli.cpp index 001706d9..49996292 100644 --- a/src/cmd/cli.cpp +++ b/src/cmd/cli.cpp @@ -160,11 +160,12 @@ static const char* help_text = "vitastor-cli modify-osd [--tags tag1,tag2,...] [--reweight ] [--noout true/false] \n" " Set OSD reweight, tags or noout flag.\n" "\n" - "vitastor-cli pg-list|pg-ls|list-pg|ls-pg|ls-pgs [OPTIONS] [state1+state2] [^state3] [...]\n" + "vitastor-cli pg-list|pg-ls|list-pg|ls-pg|ls-pgs|pgs [OPTIONS] [state1+state2] [^state3] [...]\n" " List PGs with any of listed state filters (^ or ! in the beginning is negation). Options:\n" " --pool Only list PGs of the given pool.\n" " --min Only list PGs with number >= min.\n" " --max Only list PGs with number <= max.\n" + " --osd 1,2,... Only list PGs with some data on specified OSD(s).\n" " Examples:\n" " vitastor-cli pg-list active+degraded\n" " vitastor-cli pg-list ^active\n" @@ -483,7 +484,7 @@ static int run(cli_tool_t *p, json11::Json::object cfg) cfg["osd_num"] = cmd[1]; action_cb = p->start_modify_osd(cfg); } - else if (cmd[0] == "pg-list" || cmd[0] == "pg-ls" || cmd[0] == "list-pg" || cmd[0] == "ls-pg" || cmd[0] == "ls-pgs") + else if (cmd[0] == "pg-list" || cmd[0] == "pg-ls" || cmd[0] == "list-pg" || cmd[0] == "ls-pg" || cmd[0] == "ls-pgs" || cmd[0] == "pgs") { // Modify OSD configuration if (cmd.size() > 1) diff --git a/src/cmd/cli_pg_ls.cpp b/src/cmd/cli_pg_ls.cpp index 281e7383..8ef0752b 100644 --- a/src/cmd/cli_pg_ls.cpp +++ b/src/cmd/cli_pg_ls.cpp @@ -11,6 +11,7 @@ struct pg_lister_t cli_tool_t *parent; uint64_t pool_id = 0; + std::set osd_nums; std::string pool_name; std::vector pg_state; uint64_t min_pg_num = 0; @@ -137,6 +138,22 @@ resume_1: { continue; } + if (osd_nums.size()) + { + bool found = false; + for (int i = 0; !found && i < pgp.second.target_set.size(); i++) + if (osd_nums.find(pgp.second.target_set[i]) != osd_nums.end()) + found = true; + for (int i = 0; !found && i < pgp.second.target_history.size(); i++) + for (int j = 0; !found && j < pgp.second.target_history[i].size(); j++) + if (osd_nums.find(pgp.second.target_history[i][j]) != osd_nums.end()) + found = true; + for (int i = 0; !found && i < pgp.second.all_peers.size(); i++) + if (osd_nums.find(pgp.second.all_peers[i]) != osd_nums.end()) + found = true; + if (!found) + continue; + } if (masks.size()) { bool found = false; @@ -274,6 +291,14 @@ std::function cli_tool_t::start_pg_list(json11::Json cfg) pg_lister->pg_state.push_back(cfg["pg_state"].string_value()); pg_lister->min_pg_num = cfg["min"].uint64_value(); pg_lister->max_pg_num = cfg["max"].uint64_value(); + if (cfg["osd"].is_array()) + for (auto & osd_num_json: cfg["osd"].array_items()) + pg_lister->osd_nums.insert(osd_num_json.uint64_value()); + else if (cfg["osd"].is_string()) + for (auto & osd_num_str: explode(",", cfg["osd"].string_value(), true)) + pg_lister->osd_nums.insert(stoull_full(osd_num_str)); + else if (cfg["osd"].uint64_value()) + pg_lister->osd_nums.insert(cfg["osd"].uint64_value()); return [pg_lister](cli_result_t & result) { pg_lister->loop();