diff --git a/README.md b/README.md index 834b363..edac83b 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Options: -l,--list Listing of GUARDed resources. -r,--clearall Clears GUARD states for all resources. -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 @@ -52,6 +53,10 @@ Physical path formats supported by guard tool:- * /sys-0/node-0/proc-0/mc-0/mi-0/mcc-0 * sys-0/node-0/proc-0/mc-0/mi-0/mcc-0 +**Note:** +-r option will mark recordId of existing records in GUARD file as 0xffffffff +-e option will delete all records present in the GUARD file. + ### Examples * To create a guard record. @@ -79,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 6bea6d3..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; @@ -124,6 +129,7 @@ int main(int argc, char** argv) bool listGuardRecords = false; bool clearAll = false; bool listResolvedGuardRecords = false; + bool eraseall = false; bool gversion = false; app.set_help_flag("-h, --help", @@ -140,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); @@ -166,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 851f345..b0fd7c6 100644 --- a/libguard/guard_interface.cpp +++ b/libguard/guard_interface.cpp @@ -320,6 +320,13 @@ void clearAll() } } +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 efb4172..7cb5b0d 100644 --- a/libguard/guard_interface.hpp +++ b/libguard/guard_interface.hpp @@ -88,6 +88,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 4b5a2a0..687b29c 100644 --- a/test/guard_intf_test.cpp +++ b/test/guard_intf_test.cpp @@ -264,7 +264,7 @@ TEST_F(TestGuardRecord, GetGuardFilePathWhenLibguradDidNotInitTC) // Checking without libguard_init() call. EXPECT_THROW({ openpower::guard::getGuardFilePath(); }, - openpower::guard::exception::InvalidEntry); + openpower::guard::exception::GuardFileOpenFailed); // Set the guard file since UT reached the end openpower::guard::utest::setGuardFile(guardFile); @@ -299,3 +299,17 @@ TEST_F(TestGuardRecord, ClearResolvedGuardRecord) openpower::guard::GuardRecords records = openpower::guard::getAll(); EXPECT_EQ(records.size(), 4); } + +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(); + records = openpower::guard::getAll(); + EXPECT_EQ(records.size(), 0); +}