Skip to content

Commit

Permalink
pci: don't pass chroot to pcidb with snapshots
Browse files Browse the repository at this point in the history
Snapshot implementation leverages chroot and transparently set it
to the unpacked snapshot root. This is the intentional behaviour
and ghw supports it.
But the `pci` package passes throu the chroot settings to `pcidb`
and the latter doesn't know or care about ghw snapshots - and rightly
so!

hence, we need to pass through the `chroot` setting only if explicitely
set by client code - so if no snapshot settings are present.

Signed-off-by: Francesco Romani <fromani@redhat.com>
  • Loading branch information
ffromani committed Apr 12, 2021
1 parent bb543ff commit 4ce4fec
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/pci/pci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@ import (

"github.com/jaypipes/ghw/pkg/context"
"github.com/jaypipes/ghw/pkg/linuxpath"
"github.com/jaypipes/ghw/pkg/option"
pciaddr "github.com/jaypipes/ghw/pkg/pci/address"
"github.com/jaypipes/ghw/pkg/topology"
"github.com/jaypipes/ghw/pkg/util"
)

func (i *Info) load() error {
db, err := pcidb.New(pcidb.WithChroot(i.ctx.Chroot))
// when consuming snapshots - most notably, but not only, in tests,
// the context pkg forces the chroot value to the unpacked snapshot root.
// This is intentional, intentionally transparent and ghw is prepared to handle this case.
// However, `pcidb` is not. It doesn't know about ghw snaphots, nor it should.
// so we need to complicate things a bit. If the user explicitely supplied
// a chroot option, then we should honor it all across the stack, and passing down
// the chroot to pcidb is the right thing to do. If, however, the chroot was
// implcitely set by snapshot support, then this must be consumed by ghw only.
// In this case we should NOT pass it down to pcidb.
chroot := i.ctx.Chroot
if i.ctx.SnapshotPath != "" {
chroot = option.DefaultChroot
}
db, err := pcidb.New(pcidb.WithChroot(chroot))
if err != nil {
return err
}
Expand Down

0 comments on commit 4ce4fec

Please sign in to comment.