-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: P11_Dev
Are you sure you want to change the base?
Keyword VPD: Read from hardware and update the same on D-bus #457
Conversation
Am confused about what this commit "read & update DBus" ? |
* @return On success return the value read. On failure throw exception. | ||
*/ | ||
types::DbusVariantType | ||
readKeywordFromHardware(const types::ReadVpdParams i_paramsToReadData); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
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
- It avoids any possible error calculations made at return statement.
- For developer testing or in future code debugging, you can add print statement to print the value for debugging.
- in case we need logging, we can easily add without rewriting the return statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
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. -
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. -
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not == ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
it is similar to how we implemented writes for other types of VPD.
|
21ccd5f
to
163ad8a
Compare
163ad8a
to
3322dd8
Compare
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]>
3322dd8
to
4b744f2
Compare
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