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

Add the tun mounting with vhost is requested #394

Merged
merged 1 commit into from
Nov 16, 2021
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 @@ -232,7 +232,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() {
Copy link
Contributor

@adrianchiris adrianchiris Nov 2, 2021

Choose a reason for hiding this comment

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

This means we now require /dev/net/tun to exist when needVhostNet is set to true in resource config.

is there no use-case for vhost-net without tun device ? (there must be because that how it was working before :))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the comment!

That was my question I am not aware from our side of any use case that we use vhost until now.
Now we have a use-case (dpdk slow path/ vpp) there is a need to create a tap device and for that, the tun device should be available inside the pod.

The other solution is to have a new flag for the tun device but I will like to know if there is a use-case for only vhost-net mount if not I don't see a reason to create another flag to will be always equal to the vhost one

Copy link
Contributor

Choose a reason for hiding this comment

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

With our use case, we also need /dev/net/tun, it is exported to via:
volumes:
- hostPath:
path: /dev/net/tun
type: ""
name: net

Copy link
Contributor

Choose a reason for hiding this comment

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

@amorenoz I see you also participated in discussions on the original vhostNet support PR #228
any thoughts on this ? do you see a case where we need vhost but not /dev/net/tun ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not with upstream DPDK. The vhost-net (virtio-user) PMD creates a tap device and configures it as the backend of the vhost-net device.

Copy link
Contributor

Choose a reason for hiding this comment

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

ack, thanks for the input. if all use-cases sift down to needing tun as well, to me it makes sense to provide it as a mount when needVhostNet is specified.

lets see if we get additional inputs, maybe raise this in one of the NPWG network resource mgmt meeting ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will do it at the next meeting thanks everyone for the inputs!

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
}