Skip to content
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

Bug 2027672: Add the tun mounting with vhost is requested #50

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ This selector is applicable when "deviceType" is "netDevice"(note: this is defau
| "linkTypes" | N | The link type of the net device associated with the PCI device | `string` list Default: `null` | "linkTypes": ["ether"] |
| "ddpProfiles" | N | A map of device selectors | `string` list Default: `null` | "ddpProfiles": ["GTPv1-C/U IPv4/IPv6 payload"] |
| "isRdma" | N | Mount RDMA resources | `bool` values `true` or `false` Default: `false` | "isRdma": `true` |
| "needVhostNet"| N | Share /dev/vhost-net | `bool` values `true` or `false` Default: `false` | "needVhostNet": `true` |
| "needVhostNet"| N | Share /dev/vhost-net and /dev/net/tun | `bool` values `true` or `false` Default: `false` | "needVhostNet": `true` |


[//]: # (The tables above generated using: https://ozh.github.io/ascii-tables/)
Expand Down
10 changes: 9 additions & 1 deletion pkg/netdevice/netInfoProviders.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ func (rip *vhostNetInfoProvider) GetDeviceSpecs() []*pluginapi.DeviceSpec {
glog.Errorf("GetDeviceSpecs(): /dev/vhost-net doesn't exist")
return nil
}
return GetVhostNetDeviceSpec()
deviceSpec := GetVhostNetDeviceSpec()

if !TunDeviceExist() {
glog.Errorf("GetDeviceSpecs(): /dev/net/tun doesn't exist")
return nil
}
deviceSpec = append(deviceSpec, GetTunDeviceSpec()...)

return deviceSpec
}

func (rip *vhostNetInfoProvider) GetEnvVal() string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/netdevice/pciNetDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ var _ = Describe("PciNetDevice", func() {
Expect(dev.GetDriver()).To(Equal("vfio-pci"))
Expect(dev.GetNetName()).To(Equal(""))
Expect(dev.GetEnvVal()).To(Equal("0000:00:00.1"))
Expect(dev.GetDeviceSpecs()).To(HaveLen(3)) // /dev/vfio/vfio0 and default /dev/vfio/vfio + vhost-net
Expect(dev.GetDeviceSpecs()).To(HaveLen(4)) // /dev/vfio/vfio0 and default /dev/vfio/vfio + vhost-net + tun
Expect(dev.GetRdmaSpec().IsRdma()).To(BeFalse())
Expect(dev.GetRdmaSpec().GetRdmaDeviceSpec()).To(HaveLen(0))
Expect(dev.GetLinkType()).To(Equal(""))
Expand Down
18 changes: 18 additions & 0 deletions pkg/netdevice/vhostNet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,21 @@ func GetVhostNetDeviceSpec() []*pluginapi.DeviceSpec {

return deviceSpec
}

// TunDeviceExist returns true if /dev/net/tun exists
func TunDeviceExist() bool {
_, err := os.Stat("/dev/net/tun")
return err == nil
}

// GetTunDeviceSpec returns an instance of DeviceSpec for Tun
func GetTunDeviceSpec() []*pluginapi.DeviceSpec {
deviceSpec := make([]*pluginapi.DeviceSpec, 0)
deviceSpec = append(deviceSpec, &pluginapi.DeviceSpec{
HostPath: "/dev/net/tun",
ContainerPath: "/dev/net/tun",
Permissions: "mrw",
})

return deviceSpec
}