Skip to content

pci: use the PCI database passed with WithPCIDB - #479

Merged
jaypipes merged 1 commit into
jaypipes:mainfrom
rucoder:fix/pci-custom-pcidb
Oct 23, 2026
Merged

jaypipes merged 1 commit into
jaypipes:mainfrom
rucoder:fix/pci-custom-pcidb

Conversation

@rucoder

@rucoder rucoder commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

#415 let callers pass their own PCI database with option.WithPCIDB, for example a preloaded one, or an empty one when only the IDs are needed. The rework of the options in 257865f ("remove pkg/context, overhaul snapshot handling") dropped the lines in pci.New that used it. Since then the database is stored in the context, but nothing reads it, and ghw always loads its own pci.ids.

This PR:

  • makes pci.New take the database from the context when one is set;
  • exports the modifier behind it, config.WithPCIDB, as ghw.WithPCIDB, like the other modifiers (until now a caller outside ghw had only the deprecated option);
  • points the deprecation note of option.WithPCIDB at ghw.WithPCIDB instead of the removed pkg/context;
  • documents ghw.WithPCIDB in the README's PCI section.

TestPCICustomPCIDB passes a database with a custom vendor name, through the modifier and through the old option, and checks a snapshot device's vendor name comes from it. It fails on main for both and passes with the fix.

TestPCIEmptyPCIDB covers callers that need only the IDs: with an empty database every ID stays as the device reports it and every vendor and product name is unknown. On main it fails, because ghw ignores the empty database and fills in names from its own pci.ids.

jaypipes#415 let callers pass their own PCI database, for example a preloaded
one or an empty one when only the IDs are needed. The rework of the
options in 257865f ("remove pkg/context, overhaul snapshot handling")
dropped the lines that handed it to the PCI info, so since then
option.WithPCIDB stores the database in the context, nothing reads it,
and ghw always loads its own.

pci.New now takes the database from the context when one is set. The
modifier behind it, config.WithPCIDB, is exported as ghw.WithPCIDB, as
the other modifiers are, and the deprecated option.WithPCIDB points to
it instead of the removed pkg/context.

Tests cover a database passed with the modifier and with the old option,
and an empty database, which keeps every ID as the device reports it and
leaves every name unknown.

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>

@jaypipes jaypipes left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@rucoder thanks so much for this contribution! all lgtm :)

@jaypipes
jaypipes merged commit 3275d27 into jaypipes:main Oct 23, 2026
15 checks passed
rucoder added a commit to zededa/ghw that referenced this pull request Oct 23, 2026
jaypipes#415 let callers pass their own PCI database, for example a preloaded
one or an empty one when only the IDs are needed. The rework of the
options in 257865f ("remove pkg/context, overhaul snapshot handling")
dropped the lines that handed it to the PCI info, so since then
option.WithPCIDB stores the database in the context, nothing reads it,
and ghw always loads its own.

pci.New now takes the database from the context when one is set. The
modifier behind it, config.WithPCIDB, is exported as ghw.WithPCIDB, as
the other modifiers are, and the deprecated option.WithPCIDB points to
it instead of the removed pkg/context.

Tests cover a database passed with the modifier and with the old option,
and an empty database, which keeps every ID as the device reports it and
leaves every name unknown.

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
(cherry picked from commit 07c7bc0, jaypipes#479)
rucoder added a commit to rucoder/eve that referenced this pull request Oct 23, 2026
zededa/ghw now keeps one branch per release of the upstream
jaypipes/ghw: the release, EVE's changes ported onto it, and the module
rename last. eve/v0.26.0 is jaypipes v0.26.0 plus those changes; pillar
was on the fork's main, which sat on jaypipes v0.21.0.

The hardware inventory is unchanged except for what upstream fixed in
between:
- the CPU entries come in package order rather than Go map order;
- on boards without DMI, BIOS, chassis, product and baseboard come from
  the device tree, and the CPU model from the SoC's compatible string
  when /proc/cpuinfo names none.

The branch also carries upstream's fix for WithPCIDB (jaypipes/ghw#479).
Since the fork took upstream's rework of the options, ghw stored the
PCI database passed in but never used it. hardware passes an empty one
because it needs only the IDs, and ghw loaded the full pci.ids for
every inventory instead. It now uses the empty database; the inventory
carries only the IDs, so it does not change.

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
rene pushed a commit to lf-edge/eve that referenced this pull request Oct 27, 2026
zededa/ghw now keeps one branch per release of the upstream
jaypipes/ghw: the release, EVE's changes ported onto it, and the module
rename last. eve/v0.26.0 is jaypipes v0.26.0 plus those changes; pillar
was on the fork's main, which sat on jaypipes v0.21.0.

The hardware inventory is unchanged except for what upstream fixed in
between:
- the CPU entries come in package order rather than Go map order;
- on boards without DMI, BIOS, chassis, product and baseboard come from
  the device tree, and the CPU model from the SoC's compatible string
  when /proc/cpuinfo names none.

The branch also carries upstream's fix for WithPCIDB (jaypipes/ghw#479).
Since the fork took upstream's rework of the options, ghw stored the
PCI database passed in but never used it. hardware passes an empty one
because it needs only the IDs, and ghw loaded the full pci.ids for
every inventory instead. It now uses the empty database; the inventory
carries only the IDs, so it does not change.

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
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