From f26aa13ee927f765f764d9165255241e2eb31050 Mon Sep 17 00:00:00 2001 From: Chirag Sharma Date: Sun, 11 Jul 2021 09:12:59 -0500 Subject: [PATCH] tool: Adding options in guard tool Changes: -Adding -p option to list the resolved guard records -Adding -s option to clear the resolved guard record -Clearing oldest resolved guard record if no space is left in GUARD file. Test: -creating and deleting guard records, checking if its getting displayed with new options or not. Signed-off-by: Chirag Sharma --- README.md | 31 +++++++++++----- guard.cpp | 106 ++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 102 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 0f3a6dd..f3e1226 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,16 @@ GUARD Tool Usage: guard [OPTIONS] Options: - -h,--help Use the below listed functions. - Warning: Don't try guard on non guardable units - (sys, perv) - -c,--create TEXT Create GUARD record, expects physical path as input. - -d,--delete TEXT Delete GUARD record, expects physical path as input. - -l,--list Listing of GUARDed resources. - -r,--clearall Clears GUARD states for all resources. - -v,--version Version of GUARD tool. + -h,--help Use the below listed functions. + Warning: Don't try guard on non guardable units + (sys, perv) + -c,--create TEXT Create GUARD record, expects physical path as input. + -d,--delete TEXT Delete GUARD record, expects physical path as input. + -l,--list Listing of GUARDed resources. + -r,--clearall Clears GUARD states for all resources. + -s,-clearresolvedrecord Delete GUARD states for oldest resolved resource + -p,--listresolvedrecords Listing of resolved GUARDed resources + -v,--version Version of GUARD tool. ``` **Note:** Physical path can be fetched from device tree, using ATTR_PHYS_DEV_PATH attribute of the corresponding target. @@ -51,6 +53,9 @@ 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:** clearresolvedrecord option will delete the oldest/first resolved +guard record present in GUARD file. + ### Examples * To create a guard record. @@ -72,3 +77,13 @@ guard -r ``` guard -d sys-0/node-0/proc-0/mc-0/mi-0/mcc-0 ``` +* To list the resolved guard records present in a system. +``` +guard -p +ID | ERROR | Type | Path +ffffffff | 00000000 | manual | /sys-0/node-0/dimm-0 +``` +* To clear oldest resolved guard record +``` +guard -s +``` diff --git a/guard.cpp b/guard.cpp index 3a49025..dfb242e 100644 --- a/guard.cpp +++ b/guard.cpp @@ -7,7 +7,7 @@ using namespace std; using namespace openpower::guard; -void guardList() +void guardList(bool displayResolved) { auto records = getAll(); if (!records.size()) @@ -15,35 +15,68 @@ void guardList() std::cout << "No Records to display" << std::endl; return; } - std::cout << "ID | ERROR | Type | Path " << std::endl; + + bool isHeaderPrinted = false; for (const auto& elem : records) { - if ((elem.errType != GARD_Reconfig) && - (elem.recordId != GUARD_RESOLVED)) + // Not to print guard records with errorlog type set as GARD_Reconfig + // As guard below type records are for internal usage only. + if (elem.errType == GARD_Reconfig) + { + continue; + } + // To list resolved records as user wants to list resolved records + else if (displayResolved && (elem.recordId != GUARD_RESOLVED)) + { + continue; + } + // To list unresolved records as user wants to list unresolved records + else if (!displayResolved && (elem.recordId == GUARD_RESOLVED)) + { + continue; + } + + // Don't print the header if already printed header since + // records mixed of resolved and unresolved records so if have + // only either one in retrieved records and user tried to see opposite + // one then we should not print header else user will get confused. + if (!isHeaderPrinted) + { + std::cout << "ID | ERROR | Type | Path " << std::endl; + isHeaderPrinted = true; + } + + std::cout << std::hex << std::setw(8) << std::setfill('0') + << elem.recordId; + + std::cout << " | "; + std::cout << std::hex << std::setw(8) << std::setfill('0') + << elem.elogId; + + std::cout << " | "; + std::optional gReasonToStr = + guardReasonToStr(elem.errType); + std::cout << *gReasonToStr; + + std::cout << " | "; + std::optional physicalPath = + getPhysicalPath(elem.targetId); + if (!physicalPath) { - std::cout << std::hex << std::setw(8) << std::setfill('0') - << elem.recordId; - std::cout << " | "; - std::cout << std::hex << std::setw(8) << std::setfill('0') - << elem.elogId; - - std::cout << " | "; - std::optional gReasonToStr = - guardReasonToStr(elem.errType); - std::cout << *gReasonToStr; - std::cout << " | "; - std::optional physicalPath = - getPhysicalPath(elem.targetId); - if (!physicalPath) - { - std::cout << "Unknown "; - } - else - { - std::cout << *physicalPath; - } - std::cout << std::endl; + std::cout << "Unknown "; } + else + { + std::cout << *physicalPath; + } + std::cout << std::endl; + } + + if (!isHeaderPrinted) + { + std::cout << "No " + << (displayResolved == true ? "resolved" : "unresolved") + << " records to display" << std::endl; } } @@ -75,6 +108,11 @@ void guardCreate(const std::string& physicalPath) std::cout << "Success" << std::endl; } +void guardClearResolved() +{ + clearResolvedRecord(); +} + static void exitWithError(const std::string& help, const char* err) { std::cerr << "ERROR: " << err << std::endl << help << std::endl; @@ -90,6 +128,8 @@ int main(int argc, char** argv) std::optional deleteGuardStr; bool listGuardRecords = false; bool clearAll = false; + bool clearResolvedRecord = false; + bool listResolvedGuardRecords = false; bool gversion = false; app.set_help_flag("-h, --help", @@ -104,6 +144,10 @@ int main(int argc, char** argv) "Listing of GUARDed resources."); app.add_flag("-r, --clearall", clearAll, "Clears GUARD states for all resources"); + app.add_flag("-s, --clearresolvedrecord", clearResolvedRecord, + "Delete GUARD states for oldest resolved resource"); + app.add_flag("-p, --listresolvedrecords", listResolvedGuardRecords, + "Listing of resolved GUARDed resources"); app.add_flag("-v, --version", gversion, "Version of GUARD tool"); CLI11_PARSE(app, argc, argv); @@ -124,7 +168,15 @@ int main(int argc, char** argv) } else if (listGuardRecords) { - guardList(); + guardList(false); + } + else if (clearResolvedRecord) + { + guardClearResolved(); + } + else if (listResolvedGuardRecords) + { + guardList(true); } else if (gversion) {