Skip to content

Commit

Permalink
tool: Adding options in guard tool
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Chirag Sharma committed Aug 17, 2021
1 parent e23e7df commit d508468
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 35 deletions.
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
```
106 changes: 79 additions & 27 deletions guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,76 @@
using namespace std;
using namespace openpower::guard;

void guardList()
void guardList(bool displayResolved)
{
auto records = getAll();
if (!records.size())
{
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<std::string> gReasonToStr =
guardReasonToStr(elem.errType);
std::cout << *gReasonToStr;

std::cout << " | ";
std::optional<std::string> 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<std::string> gReasonToStr =
guardReasonToStr(elem.errType);
std::cout << *gReasonToStr;
std::cout << " | ";
std::optional<std::string> 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;
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -90,6 +128,8 @@ int main(int argc, char** argv)
std::optional<std::string> deleteGuardStr;
bool listGuardRecords = false;
bool clearAll = false;
bool clearResolvedRecord = false;
bool listResolvedGuardRecords = false;
bool gversion = false;

app.set_help_flag("-h, --help",
Expand All @@ -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);
Expand All @@ -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)
{
Expand Down

0 comments on commit d508468

Please sign in to comment.