diff --git a/README.md b/README.md index 0f3a6dd..834b363 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,15 @@ 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. + -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. @@ -72,3 +73,9 @@ 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 +``` diff --git a/guard.cpp b/guard.cpp index 3a49025..6bea6d3 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 << "Unknown "; + } + else { - 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 << *physicalPath; } + std::cout << std::endl; + } + + if (!isHeaderPrinted) + { + std::cout << "No " + << (displayResolved == true ? "resolved" : "unresolved") + << " records to display" << std::endl; } } @@ -90,6 +123,7 @@ int main(int argc, char** argv) std::optional deleteGuardStr; bool listGuardRecords = false; bool clearAll = false; + bool listResolvedGuardRecords = false; bool gversion = false; app.set_help_flag("-h, --help", @@ -104,6 +138,8 @@ 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("-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 +160,11 @@ int main(int argc, char** argv) } else if (listGuardRecords) { - guardList(); + guardList(false); + } + else if (listResolvedGuardRecords) + { + guardList(true); } else if (gversion) {