Skip to content

Commit

Permalink
vhost-vdpa: fix env val not show
Browse files Browse the repository at this point in the history
vdpaPath is now assigned a value in NewVdpaInfoProvider.

Signed-off-by: Ziteng Liu <[email protected]>
  • Loading branch information
makoto126 committed Aug 22, 2024
1 parent cb2802b commit 1621075
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
22 changes: 12 additions & 10 deletions pkg/infoprovider/vdpaInfoProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ func NewVdpaInfoProvider(vdpaType types.VdpaType, vdpaDev types.VdpaDevice) type
dev: vdpaDev,
vdpaType: vdpaType,
}
if vdpaType == types.VdpaVhostType && vdpaDev != nil {
vdpaPath, err := vdpaDev.GetPath()
if err != nil {
glog.Errorf("Unexpected error when fetching the vdpa device path: %s", err)
}
vdpaInfoProvider.vdpaPath = vdpaPath
}

return vdpaInfoProvider
}

Expand All @@ -58,20 +66,14 @@ func (vip *vdpaInfoProvider) GetDeviceSpecs() []*pluginapi.DeviceSpec {
}
devSpecs := make([]*pluginapi.DeviceSpec, 0)

// DeviceSpecs only required for vhost vdpa type as the
if vip.vdpaType == types.VdpaVhostType {
vdpaPath, err := vip.dev.GetPath()
if err != nil {
glog.Errorf("Unexpected error when fetching the vdpa device path: %s", err)
return nil
}
if vip.vdpaPath != "" {
devSpecs = append(devSpecs, &pluginapi.DeviceSpec{
HostPath: vdpaPath,
ContainerPath: vdpaPath,
HostPath: vip.vdpaPath,
ContainerPath: vip.vdpaPath,
Permissions: "rw",
})
vip.vdpaPath = vdpaPath
}

return devSpecs
}

Expand Down
1 change: 0 additions & 1 deletion pkg/infoprovider/vdpaInfoProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ var _ = Describe("vdpaInfoProvider", func() {
vdpa.On("GetType").Return(types.VdpaVhostType).
On("GetPath").Return("/dev/vhost-vdpa1", nil)
dip := infoprovider.NewVdpaInfoProvider(types.VdpaVhostType, vdpa)
dip.GetDeviceSpecs()
envs := dip.GetEnvVal()
Expect(len(envs)).To(Equal(1))
mount, exist := envs["mount"]
Expand Down

0 comments on commit 1621075

Please sign in to comment.