diff --git a/README.md b/README.md index 0f3a6dd..62199ad 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 Guard CLI tool options + -c,--create TEXT Create Guard record, expects physical path as input + -i,--invalidate TEXT Invalidate a single Guard record, expects physical + path as input + -I,--invalidate-all Invalidates all the Guard records + -l,--list List all the GUARD'ed resources + -r,--reset Erase all the Guard records + -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. @@ -64,11 +65,15 @@ guard -l ID | ERROR | Type | Path 00000001 | 00000000 | manual | physical:sys-0/node-0/proc-0/mc-0/mi-0/mcc-0 ``` -* To clear all the guard records +* To erase all the guard records ``` guard -r ``` -* To clear a particular guard record +* To invalidate a single guard record +``` +guard -i sys-0/node-0/proc-0/mc-0/mi-0/mcc-0 +``` +* To invalidate all the guard records ``` -guard -d sys-0/node-0/proc-0/mc-0/mi-0/mcc-0 +guard -I ``` diff --git a/guard.cpp b/guard.cpp index 3a49025..73bc451 100644 --- a/guard.cpp +++ b/guard.cpp @@ -2,12 +2,14 @@ #include "libguard/guard_interface.hpp" #include "libguard/include/guard_record.hpp" +#include + #include using namespace std; using namespace openpower::guard; -void guardList() +void guardList(bool displayResolved) { auto records = getAll(); if (!records.size()) @@ -15,35 +17,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; } } @@ -63,6 +98,11 @@ void guardClear() clearAll(); } +void guardInvalidateAll() +{ + invalidateAll(); +} + void guardCreate(const std::string& physicalPath) { std::optional entityPath = getEntityPath(physicalPath); @@ -85,25 +125,29 @@ int main(int argc, char** argv) { try { - CLI::App app{"GUARD Tool"}; + CLI::App app{"Guard Tool"}; std::optional createGuardStr; std::optional deleteGuardStr; bool listGuardRecords = false; bool clearAll = false; + bool listResolvedGuardRecords = false; + bool invalidateAll = false; bool gversion = false; - app.set_help_flag("-h, --help", - "Use the below listed functions.\n" - "Warning: Don't try guard on non guardable units " - "(sys, perv)"); + app.set_help_flag("-h, --help", "Guard CLI tool options"); app.add_option("-c, --create", createGuardStr, - "Create GUARD record, expects physical path as input"); - app.add_option("-d, --delete", deleteGuardStr, - "Delete GUARD record, expects physical path as input"); + "Create Guard record, expects physical path as input"); + app.add_option( + "-i, --invalidate", deleteGuardStr, + "Invalidate a single Guard record, expects physical path as input"); + app.add_flag("-I, --invalidate-all", invalidateAll, + "Invalidates all the Guard records"); app.add_flag("-l, --list", listGuardRecords, - "Listing of GUARDed resources."); - app.add_flag("-r, --clearall", clearAll, - "Clears GUARD states for all resources"); + "List all the Guard'ed resources"); + app.add_flag("-r, --reset", clearAll, "Erase all the Guard records"); + app.add_flag("-a, --listresolvedrecords", listResolvedGuardRecords, + "List all the resolved Guard'ed resources") + ->group(""); app.add_flag("-v, --version", gversion, "Version of GUARD tool"); CLI11_PARSE(app, argc, argv); @@ -124,11 +168,19 @@ int main(int argc, char** argv) } else if (listGuardRecords) { - guardList(); + guardList(false); + } + else if (listResolvedGuardRecords) + { + guardList(true); + } + else if (invalidateAll) + { + guardInvalidateAll(); } else if (gversion) { - std::cout << "GUARD Tool version is " << GUARD_VERSION << std::endl; + std::cout << "Guard tool " << GUARD_VERSION << std::endl; } else { diff --git a/meson.build b/meson.build index 63d71b7..55bed5c 100644 --- a/meson.build +++ b/meson.build @@ -28,6 +28,10 @@ conf_data.set_quoted('GUARD_PRSV_PATH', get_option('GUARD_PRSV_PATH'), description : 'GUARD file in pnor prsv partition' ) +conf_data.set_quoted('GUARD_VERSION', 'v1.0', + description : 'Setting guard tool version' + ) + conf_data.set('DEV_TREE', get_option('devtree').enabled(), description : 'Use device tree to get physical path value' ) @@ -40,8 +44,6 @@ configure_file(output: 'config.h', ) #add_project_arguments('-DPGUARD', language : 'cpp') -add_project_arguments('-DGUARD_VERSION', language : 'cpp') -set_variable('GUARD_VERSION', '1.0') subdir('libguard')