diff --git a/README.md b/README.md index 688f09d..58fd020 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Options: -r,--clearall Clears GUARD states for all resources. -s,-clearresolvedrecord Delete GUARD states for oldest resolved resource -p,--listresolvedrecords Listing of resolved GUARDed resources + -e,--eraseall Erase all the GUARDed resources -v,--version Version of GUARD tool. ``` **Note:** Physical path can be fetched from device tree, using ATTR_PHYS_DEV_PATH @@ -83,3 +84,7 @@ guard -p ID | ERROR | Type | Path ffffffff | 00000000 | manual | /sys-0/node-0/dimm-0 ``` +* To erase all the guard records +``` +guard -e +``` diff --git a/guard.cpp b/guard.cpp index 3e8c648..8d909c7 100644 --- a/guard.cpp +++ b/guard.cpp @@ -108,6 +108,11 @@ void guardCreate(const std::string& physicalPath) std::cout << "Success" << std::endl; } +void guardErase() +{ + eraseAllRecords(); +} + static void exitWithError(const std::string& help, const char* err) { std::cerr << "ERROR: " << err << std::endl << help << std::endl; @@ -123,8 +128,8 @@ int main(int argc, char** argv) std::optional deleteGuardStr; bool listGuardRecords = false; bool clearAll = false; - bool clearResolvedRecord = false; bool listResolvedGuardRecords = false; + bool eraseall = false; bool gversion = false; app.set_help_flag("-h, --help", @@ -141,6 +146,8 @@ int main(int argc, char** argv) "Clears GUARD states for all resources"); app.add_flag("-p, --listresolvedrecords", listResolvedGuardRecords, "Listing of resolved GUARDed resources"); + app.add_flag("-e, --eraseall", eraseall, + "Erase all the GUARDed resources"); app.add_flag("-v, --version", gversion, "Version of GUARD tool"); CLI11_PARSE(app, argc, argv); @@ -167,6 +174,10 @@ int main(int argc, char** argv) { guardList(true); } + else if (eraseall) + { + guardErase(); + } else if (gversion) { std::cout << "GUARD Tool version is " << GUARD_VERSION << std::endl; diff --git a/libguard/guard_interface.cpp b/libguard/guard_interface.cpp index a748b7c..01786b5 100644 --- a/libguard/guard_interface.cpp +++ b/libguard/guard_interface.cpp @@ -386,6 +386,13 @@ int clearResolvedRecord() return delpos; } +void eraseAllRecords() +{ + GuardFile file(guardFilePath); + + file.erase(0, file.size()); +} + void libguard_init(bool enableDevtree) { initialize(); diff --git a/libguard/guard_interface.hpp b/libguard/guard_interface.hpp index 43415d7..21640f2 100644 --- a/libguard/guard_interface.hpp +++ b/libguard/guard_interface.hpp @@ -97,6 +97,13 @@ void libguard_init(bool enableDevtree = true); */ const fs::path& getGuardFilePath(); +/** + * @brief Erase/wipeout all the guard records from GUARD file + * + * @return NULL + */ +void eraseAllRecords(); + namespace utest { void setGuardFile(const fs::path& file); diff --git a/test/guard_intf_test.cpp b/test/guard_intf_test.cpp index ae0827c..0ff679e 100644 --- a/test/guard_intf_test.cpp +++ b/test/guard_intf_test.cpp @@ -297,3 +297,17 @@ TEST_F(TestGuardRecord, ClearResolvedGuardRecord) openpower::guard::GuardRecords records = openpower::guard::getAll(); EXPECT_EQ(records.size(), 2); } + +TEST_F(TestGuardRecord, EraseAllRecordsTest) +{ + openpower::guard::libguard_init(); + std::string phyPath = "/sys-0/node-0/proc-1/eq-0/fc-0/core-0"; + std::optional entityPath = + openpower::guard::getEntityPath(phyPath); + openpower::guard::create(*entityPath); + openpower::guard::GuardRecords records = openpower::guard::getAll(); + EXPECT_EQ(records.size(), 1); + openpower::guard::eraseAllRecords(); + openpower::guard::GuardRecords records = openpower::guard::getAll(); + EXPECT_EQ(records.size(), 0); +}