Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
qemu: close tap fd properly
Browse files Browse the repository at this point in the history
Still need to pass tap fd around to keep it open until nic is removed.

Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Oct 13, 2017
1 parent 8292ffb commit 7ec7d7b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hypervisor/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type InterfaceCreated struct {
Id string //user specified in (ref api.InterfaceDescription: a user identifier of interface, user may use this to specify a nic, normally you can use IPAddr as an Id.)
Index int
PCIAddr int
TapFd int
Bridge string
HostDevice string
DeviceName string
Expand All @@ -73,6 +74,7 @@ type NetDevInsertedEvent struct {
Index int
DeviceName string
Address int
TapFd int
}

func (ne *NetDevInsertedEvent) ResultId() string {
Expand Down
2 changes: 2 additions & 0 deletions hypervisor/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ func (nc *NetworkContext) addInterface(inf *api.InterfaceDescription, result cha
result <- fe
return
} else if ni, ok := ev.(*NetDevInsertedEvent); ok {
created := nc.idMap[inf.Id]
created.TapFd = ni.TapFd
nc.sandbox.Log(DEBUG, "nic insert success: %s", ni.Id)
result <- ni
return
Expand Down
1 change: 1 addition & 0 deletions hypervisor/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func (qc *QemuContext) AddNic(ctx *hypervisor.VmContext, host *hypervisor.HostNi
}

func (qc *QemuContext) RemoveNic(ctx *hypervisor.VmContext, n *hypervisor.InterfaceCreated, callback hypervisor.VmEvent, result chan<- hypervisor.VmEvent) {
syscall.Close(n.TapFd)
newNetworkDelSession(ctx, qc, n.NewName, callback, result)
}

Expand Down
1 change: 1 addition & 0 deletions hypervisor/qemu/qmp_wrapper_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func newNetworkAddSession(ctx *hypervisor.VmContext, qc *QemuContext, fd int, ho
Index: guest.Index,
DeviceName: guest.Device,
Address: guest.Busaddr,
TapFd: fd,
}),
}
}
1 change: 1 addition & 0 deletions hypervisor/qemu/qmp_wrapper_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func newNetworkAddSession(ctx *hypervisor.VmContext, qc *QemuContext, fd int, ho
Index: guest.Index,
DeviceName: guest.Device,
Address: guest.Busaddr,
TapFd: fd,
}),
}
}
1 change: 1 addition & 0 deletions hypervisor/qemu/qmp_wrapper_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func newNetworkAddSession(ctx *hypervisor.VmContext, qc *QemuContext, fd int, ho
Index: guest.Index,
DeviceName: guest.Device,
Address: guest.Busaddr,
TapFd: fd,
}),
}
}
1 change: 1 addition & 0 deletions hypervisor/qemu/qmp_wrapper_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func newNetworkAddSession(ctx *hypervisor.VmContext, qc *QemuContext, fd int, ho
Index: guest.Index,
DeviceName: guest.Device,
Address: guest.Busaddr,
TapFd: fd,
}),
}
}

0 comments on commit 7ec7d7b

Please sign in to comment.