-
Notifications
You must be signed in to change notification settings - Fork 189
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
pci: JSON device marshalling fixes #210
pci: JSON device marshalling fixes #210
Conversation
The current marshaller can't properly deal with nested characters. This is easily verifiable trying to marshal this device: {"subsystem": {"id":"a801","name":"SM963 2.5" NVMe PCIe SSD"} this is demonstrated by the test added in this patch. Minimal refactoring to pci functions is performed to enable the test. Signed-off-by: Francesco Romani <[email protected]>
I added |
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.
Very nice work @fromanirh! Just a little copy/pasta mistake to fix up otherwise, lgtm.
pkg/pci/pci.go
Outdated
type devMarshallable struct { | ||
Address string `json:"address"` | ||
Vendor devIdent `json:"vendor"` | ||
Product devIdent `json:"vendor"` |
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.
copy/paste mistake ... the json tag should be "product" :)
pkg/pci/pci.go
Outdated
Address string `json:"address"` | ||
Vendor devIdent `json:"vendor"` | ||
Product devIdent `json:"vendor"` | ||
Subsystem devIdent `json:"vendor"` |
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 this should be "subsystem"
// ParseDevice returns a pointer to a Device given its describing data. | ||
// The PCI device obtained this way may not exist in the system; | ||
// use GetDevice to get a *Device which is found in the system | ||
func (info *Info) ParseDevice(address, modalias string) *Device { |
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.
technically this is introducing a public exported interface, and I realize you did this in order to unit-test it in the pci_test.go file which imports the pkg/pci
package in order to test the exported interfaces. So, I'm OK with this.
Yup, I'm cool with it :) |
We can reuse the "encoding/json" marshaller for our needs, using internal throaway types. This should make the marshaller more robust, and hopefully a bit easier to maintain. Signed-off-by: Francesco Romani <[email protected]>
d344f0a
to
9b03d75
Compare
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.
\o/ thanks @fromanirh!
PR #209 exposed a mashalling issue with some devices.
The issue is the quoting of " from the description of some devices (e.g. 2.5" device).
Add a test to demonstrate the bug and a possible fix.