Merge pull request #1670 from xs3c/fix-vfio-hang

shim v2: Close vhostfd after vm get vhostfd
This commit is contained in:
Fupan Li
2019-05-21 14:53:26 +08:00
committed by GitHub
4 changed files with 34 additions and 0 deletions

View File

@@ -108,6 +108,8 @@ func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, f
}
}()
s.postCreatedNetwork()
if err = s.getAndStoreGuestDetails(); err != nil {
return nil, err
}

View File

@@ -1448,6 +1448,32 @@ func (n *Network) Add(ctx context.Context, config *NetworkConfig, hypervisor hyp
return endpoints, nil
}
func (n *Network) PostAdd(ctx context.Context, ns *NetworkNamespace, hotplug bool) error {
if hotplug {
return nil
}
if ns.Endpoints == nil {
return nil
}
endpoints := ns.Endpoints
for _, endpoint := range endpoints {
netPair := endpoint.NetworkPair()
if netPair == nil {
continue
}
if netPair.VhostFds != nil {
for _, VhostFd := range netPair.VhostFds {
VhostFd.Close()
}
}
}
return nil
}
// Remove network endpoints in the network namespace. It also deletes the network
// namespace in case the namespace has been created by us.
func (n *Network) Remove(ctx context.Context, ns *NetworkNamespace, hypervisor hypervisor, hotunplug bool) error {

View File

@@ -1042,6 +1042,7 @@ func (q *qemu) hotAddNetDevice(name, hardAddr string, VMFds, VhostFds []*os.File
if err := q.qmpMonitorCh.qmp.ExecuteGetFD(q.qmpMonitorCh.ctx, fdName, VhostFd); err != nil {
return err
}
VhostFd.Close()
VhostFdNames = append(VhostFdNames, fdName)
}
return q.qmpMonitorCh.qmp.ExecuteNetdevAddByFds(q.qmpMonitorCh.ctx, "tap", name, VMFdNames, VhostFdNames)

View File

@@ -840,6 +840,11 @@ func (s *Sandbox) createNetwork() error {
return s.store.Store(store.Network, s.networkNS)
}
func (s *Sandbox) postCreatedNetwork() error {
return s.network.PostAdd(s.ctx, &s.networkNS, s.factory != nil)
}
func (s *Sandbox) removeNetwork() error {
span, _ := s.trace("removeNetwork")
defer span.Finish()