Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword VPD: Read from hardware and update the same on D-bus #457

Open
wants to merge 1 commit into
base: P11_Dev
Choose a base branch
from

Conversation

PriyangaRamasamy
Copy link

@PriyangaRamasamy PriyangaRamasamy commented Nov 6, 2024

Keyword's value gets updated on D-bus irrespective of verifying the keyword size.

For example, For a 4 byte keyword, if user gives more than 4 bytes of data to
update, hardware update will accept only 4 bytes but D-bus update will accept
every extra byte given by the user. This will create a mismatch between hardware
and D-bus.

So to avoid such mismatches we came up with the design of updating the keyword's
value in hardware first ( which takes care of size checks) and copy the same
in other sources. With this approach we maintain the reliability of keyword
updates across all other sources.

This commit implements the portion where we read the keyword's value from hardware
(assuming the hardware write is already done from Manager class) and write the same
on D-bus.

Test:
busctl call com.ibm.VPD.Manager /com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv "/tmp/keyword.dat" s "SN"
v ay 12 89 72 51 48 66 71 55 56 66 48 49 52

@branupama
Copy link

branupama commented Nov 18, 2024

Am confused about what this commit "read & update DBus" ?
because Test result shows read Keyword value and prints it on console.

* @return On success return the value read. On failure throw exception.
*/
types::DbusVariantType
readKeywordFromHardware(const types::ReadVpdParams i_paramsToReadData);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "readKeywordFromHardware"
as parser itself is on hardware, should it be "readKeyword" ?

or this parser class reads keyword from DBus as well ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the method overriden from parser_interface class.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I know,
but are we going to introduce readKeywordFrom DBus in the future ?. I wanted to understand the reason.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am not sure about the future :)
either IBM/any other company can implement readKeywordFromDBus.

Now If we focus on present, this API reads keyword's value from hardware. that's it.

* @brief API to iterate through the VPD vector to find the given keyword.
*
* This API iterates through VPD vector using m_vpdIterator and finds the
* given keyword. m_vpdIterator points to the keyword name if find is

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its findKeyword API, why "m_vpdIterator" should be modified ?
instead you can return the pointer of the found keyword(or the position), incase if you need this data.

And also we can't parse() or populateVpdMap() on this object as 'm_vpdIterator' is moved.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also we can't parse() or populateVpdMap() on this object as 'm_vpdIterator' is moved.

why can't you move again?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the API name is findKeyword(), getter API's shouldn't modify anything.

why can't you move again?
is this is a suggestion or asking we can move it. ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a getter API. this just checks if the keyword is found or not. since we have m_iterator as a member variable which is common to any member of the class, this API uses it to iterate through the vector.

Remember findKeyword() is not modifying the content of the vector. It is using the iterator variable to iterate through the vector. If m_iterator shouldn't be modified, then give me the purpose of having it as a non-const class member.

Also this API acts as a common API to perform both read and write keyword. PR for write keyword #459

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't you move again?
is this is a suggestion or asking we can move it. ?

Am telling you, if you wish to perform parse/populateVPDMap - you can move the iterator wherever you want to.

if (const types::Keyword* l_kwData =
std::get_if<types::Keyword>(&i_paramsToReadData))
{
l_keyword = *l_kwData;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check is this value is empty or not .

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

std::advance(m_vpdIterator, constants::ONE_BYTE);

// Read the keyword's value and return
return types::DbusVariantType{types::BinaryVector(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't do operation on return statement, just return the value instead found from the operation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do the operation and send the final value in the return statement, Dont do multiple things in return statement.
This is the review comment got it for my PR.

What I realised from this is

  1. It avoids any possible error calculations made at return statement.
  2. For developer testing or in future code debugging, you can add print statement to print the value for debugging.
  3. in case we need logging, we can easily add without rewriting the return statement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It avoids any possible error calculations made at return statement.
    it's developer's responsibility to check on the calculations. if there are any errors we can fix it with defect. Having a separate variable doesn't guarantee that the calculation will be error free.

  2. For developer testing or in future code debugging, you can add print statement to print the value for debugging.
    Code doesn't stop you to add print statements for debugging.

  3. in case we need logging, we can easily add without rewriting the return statement.
    Now in this case is it required to log a message with variant<vector<uint8_t> contents?

In my case, I don't need to construct an object for std::vector and std::variant just to return it back to the caller. In place construction optimises the memory usage.


int KeywordVpdParser::findKeyword(const std::string& i_keyword)
{
m_vpdIterator = m_keywordVpdVector.begin();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check i_keyword is empty or not before doing further operations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

if (findKeyword(l_keyword) != 0)
{
logging::logMessage("Keyword " + l_keyword + " not found.");
throw types::DbusInvalidArgument();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why DBUs error thrown here ?
its h/w operation right .

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the request is from Dbus

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is KeywordVpdParser class, Reader can't know its request from DBus.
Request can come from any where, we can't use DBus error here.

We should keep API's generic and shouldn't bind to one use case. Future needs may come from different place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPZ read/write also has similar logging when it fails. So let's discuss this as part of error logging story.

std::string l_keywordName(m_vpdIterator,
m_vpdIterator + constants::TWO_BYTES);

if (l_keywordName == i_keyword)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use STR_CMP_SUCCESS here ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not == ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do same thing in number of ways,
if we are following certain things it should be followed every where.

For string comparison we are using compare() api only in the current code.
As I couldn't recall when this is introduced, we can get clarity from the team

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If == still comes under C++ standard, then why we should restrict using it?

@@ -133,4 +133,91 @@ void KeywordVpdParser::checkNextBytesValidity(uint8_t i_numberOfBytes)
}
}

types::DbusVariantType KeywordVpdParser::readKeywordFromHardware(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make it simple,
use populateVpdMap() which gets the keyword map for us.
use this map to get the particular keyword value.

In this way we no need to implement reading logic here .

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that won't be simple when there is a read keyword request from D-bus. as for each and every request, populateVpdMap() creates the complete map of keyword-value pairs which is not required in this case.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the where the keywond, it can be found at the beginning or can be found at the end.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't need a map with all keyword values for my case. so why should I use populateVpdMap()

@PriyangaRamasamy
Copy link
Author

Am confused about what this commit "read & update DBus" ?
because Test result shows read Keyword value and prints it on console.

it is similar to how we implemented writes for other types of VPD.
there is an order of execution for writeKeyword request:

  1. write on hardware -> if it succeeds then,
  2. read the written value from hardware -> if it succeeds then,
  3. write the value (found from step2) on D-bus --> by this way we update the Dbus with correct size of the keyword irrespective of what the user gave.

Keyword's value gets updated on D-bus irrespective of verifying the keyword size.

For example, For a 4 byte keyword, if user gives more than 4 bytes of data to
update, hardware update will accept only 4 bytes but D-bus update will accept
every extra byte given by the user. This will create a mismatch between hardware
and D-bus.

So to avoid such mismatches we came up with the design of updating the keyword's
value in hardware first ( which takes care of size checks) and copy the same
in other sources. With this approach we maintain the reliability of keyword
updates across all other sources.

This commit implements the portion where we read the keyword's value from hardware
(assuming the hardware write is already done from Manager class) and write the same
on D-bus.

Test:
busctl call com.ibm.VPD.Manager /com/ibm/VPD/Manager com.ibm.VPD.Manager  ReadKeyword sv "/tmp/keyword.dat" s "SN"
v ay 12 89 72 51 48 66 71 55 56 66 48 49 52

Change-Id: I60d7a2b418ad5e451e46f288bde3477794145ec0
Signed-off-by: Priyanga Ramasamy <[email protected]>
@PriyangaRamasamy PriyangaRamasamy changed the title Keyword VPD: Read from hardware and update on D-bus Keyword VPD: Read from hardware and update the same on D-bus Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants