From c7ace4b4bc74c4824c7d1b84b7ea94e0499f9d24 Mon Sep 17 00:00:00 2001 From: Ace-Tang Date: Tue, 11 Dec 2018 13:57:42 +0800 Subject: [PATCH] qemu: throw error when fail to get addr from bridges Return error soon when addDeviceToBridge() can not get empty address from bridges, or the error will thrown by qemu, this is not obvious. Fixes: #1005 Signed-off-by: Ace-Tang --- virtcontainers/qemu.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 7ee216433f..3625206a4c 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -8,6 +8,7 @@ package virtcontainers import ( "context" "encoding/json" + "errors" "fmt" "io/ioutil" "math" @@ -755,6 +756,10 @@ func (q *qemu) addDeviceToBridge(ID string) (string, types.PCIBridge, error) { var err error var addr uint32 + if len(q.state.Bridges) == 0 { + return "", types.PCIBridge{}, errors.New("failed to get available address from bridges") + } + // looking for an empty address in the bridges for _, b := range q.state.Bridges { addr, err = b.AddDevice(ID)