-
Notifications
You must be signed in to change notification settings - Fork 182
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: add and use LookupDevice #240
Conversation
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.
See inline comments @fromanirh; I'm concerned about introducing another method instead of just modifying the implementation of the existing PCIInfo.GetDevice
method.
README.md
Outdated
|
||
The difference between the two methods is that `LookupDevice` will use | ||
cached data, while `GetDevice` will attempt every time to get informations | ||
from the system. |
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 caching behaviour of any ghw
struct should be entirely transparent to the user, so I'm going to push back on this particular change. The user should not need to know the internal implementation details in order to know to call a different method of ghw.PCIInfo
depending on whether an underlying sysfs/filesystem mount is present.
In other words, just change the PCIInfo.GetDevice
method implementation to look up the device in PCIInfo.Devices
by address before searching a filesystem :)
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 good point.
for _, dev := range info.Devices { | ||
if dev.Address == address { | ||
return dev | ||
} | ||
} | ||
return nil |
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.
just move this into GetDevice.
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.
sure thing!
Add a simple helper to find a device among the `pci.Info.Devices`. This is needed because `GetDevice` accesses the system every time. In most cases, besides a tiny performance hit, this is no issue. When consuming snapshots, however, this may lead to surprising behaviour because the caller need to ensure the snapshot is available when `GetDevice` is called, or it will return unpredictable result (!!!). The wrong code looks like that: 1. PCI info is created supplying snapshot data with automatic management 1.a ghw unpacks the snapshot on a temporary directory. 1.b ghw loads all the info from the snapshot. info.Devices contains correct data. 1.c ghw cleans up the snapshot (see: jaypipes#236) 2. the client (test) code calls GetDevice 2.a GetDevice will try to access the unpacked snapshot data, which is gone. 2.b GetDevice will fail. Signed-off-by: Francesco Romani <fromani@redhat.com>
c31cda6
to
c126558
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.
👍
update to the tip of ghe main branch to pull in the latest fixes, most notably to avoid to leak temporary directories when consuming snapshots: jaypipes/ghw#236 jaypipes/ghw#240 Signed-off-by: Francesco Romani <fromani@redhat.com>
update to the tip of ghe main branch to pull in the latest fixes, most notably to avoid to leak temporary directories when consuming snapshots: jaypipes/ghw#236 jaypipes/ghw#240 Signed-off-by: Francesco Romani <fromani@redhat.com>
update to the tip of ghe main branch to pull in the latest fixes, most notably to avoid to leak temporary directories when consuming snapshots: jaypipes/ghw#236 jaypipes/ghw#240 Signed-off-by: Francesco Romani <fromani@redhat.com>
update to the tip of ghe main branch to pull in the latest fixes, most notably to avoid to leak temporary directories when consuming snapshots: jaypipes/ghw#236 jaypipes/ghw#240 Signed-off-by: Francesco Romani <fromani@redhat.com>
Add a simple helper to find a device among the
pci.Info.Devices
.Up until now, client code had to reimplement the find function
every time, or to call
GetDevice
. Problem is:GetDevice
access the system every time.In most cases, besides a tiny performance hit, this is no issue.
When consuming snapshots, however, this may lead to surprising behaviour
because the caller need to ensure the snapshot is available when
GetDevice
is called, or it will return unpredictable result (!!!).The wrong code looks like that:
1.a ghw unpacks the snapshot on a temporary dir
1.b ghw loads all the info from the snapshot. info.Devices contains
correct data
1.c ghw cleans up the snapshot (see:
context: Fix directory leakage for snapshots contexts #236)
2.a GetDevice will try to access the unpacked snapshot data, which is
gone
2.b GetDevice will fail
Signed-off-by: Francesco Romani fromani@redhat.com