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

pci: JSON device marshalling fixes #210

Merged
merged 2 commits into from
Jan 15, 2021

Conversation

ffromani
Copy link
Collaborator

@ffromani ffromani commented Jan 15, 2021

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.

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]>
@ffromani
Copy link
Collaborator Author

ffromani commented Jan 15, 2021

I added pci.ParseDevice because it seems a good compromise and an acceptable addition to the API (ok, ok, disclosure: it's the lazy way!); I can add a ghw snapshot which highlights the issue and which allows us to demonstrate the bug without API changes, but it will take me some more time.

Copy link
Owner

@jaypipes jaypipes left a 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"`
Copy link
Owner

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"`
Copy link
Owner

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 {
Copy link
Owner

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.

@jaypipes
Copy link
Owner

I added pci.ParseDevice because it seems a good compromise and an acceptable addition to the API (ok, ok, disclosure: it's the lazy way!); I can add a ghw snapshot which highlights the issue and which allows us to demonstrate the bug without API changes, but it will take me some more time.

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]>
@ffromani ffromani force-pushed the pci-device-marshalling-fixes branch from d344f0a to 9b03d75 Compare January 15, 2021 14:34
Copy link
Owner

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

\o/ thanks @fromanirh!

@jaypipes jaypipes merged commit efbe6fd into jaypipes:master Jan 15, 2021
@ffromani ffromani deleted the pci-device-marshalling-fixes branch May 24, 2021 06:52
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