Skip to content

Commit 1621075

Browse files
committed
vhost-vdpa: fix env val not show
vdpaPath is now assigned a value in NewVdpaInfoProvider. Signed-off-by: Ziteng Liu <[email protected]>
1 parent cb2802b commit 1621075

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

pkg/infoprovider/vdpaInfoProvider.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func NewVdpaInfoProvider(vdpaType types.VdpaType, vdpaDev types.VdpaDevice) type
3939
dev: vdpaDev,
4040
vdpaType: vdpaType,
4141
}
42+
if vdpaType == types.VdpaVhostType && vdpaDev != nil {
43+
vdpaPath, err := vdpaDev.GetPath()
44+
if err != nil {
45+
glog.Errorf("Unexpected error when fetching the vdpa device path: %s", err)
46+
}
47+
vdpaInfoProvider.vdpaPath = vdpaPath
48+
}
49+
4250
return vdpaInfoProvider
4351
}
4452

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

61-
// DeviceSpecs only required for vhost vdpa type as the
62-
if vip.vdpaType == types.VdpaVhostType {
63-
vdpaPath, err := vip.dev.GetPath()
64-
if err != nil {
65-
glog.Errorf("Unexpected error when fetching the vdpa device path: %s", err)
66-
return nil
67-
}
69+
if vip.vdpaPath != "" {
6870
devSpecs = append(devSpecs, &pluginapi.DeviceSpec{
69-
HostPath: vdpaPath,
70-
ContainerPath: vdpaPath,
71+
HostPath: vip.vdpaPath,
72+
ContainerPath: vip.vdpaPath,
7173
Permissions: "rw",
7274
})
73-
vip.vdpaPath = vdpaPath
7475
}
76+
7577
return devSpecs
7678
}
7779

pkg/infoprovider/vdpaInfoProvider_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ var _ = Describe("vdpaInfoProvider", func() {
8686
vdpa.On("GetType").Return(types.VdpaVhostType).
8787
On("GetPath").Return("/dev/vhost-vdpa1", nil)
8888
dip := infoprovider.NewVdpaInfoProvider(types.VdpaVhostType, vdpa)
89-
dip.GetDeviceSpecs()
9089
envs := dip.GetEnvVal()
9190
Expect(len(envs)).To(Equal(1))
9291
mount, exist := envs["mount"]

0 commit comments

Comments
 (0)