qemu: Pass the pci/e address for qemu bridge

Pass the slot address while attaching bridges. This is needed
to determine the pci/e address of devices that are attached
to the bridge.

Fixes #210

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde
2018-04-04 09:32:06 -07:00
parent ee2e15c724
commit 05c4ea39d0
7 changed files with 25 additions and 6 deletions

View File

@@ -26,6 +26,9 @@ type Bridge struct {
//ID is used to identify the bridge in the hypervisor
ID string
// Addr is the PCI/e slot of the bridge
Addr int
}
// addDevice on success adds the device ID to the bridge and return the address

View File

@@ -16,7 +16,7 @@ func TestAddRemoveDevice(t *testing.T) {
assert := assert.New(t)
// create a bridge
bridges := []*Bridge{{make(map[uint32]string), pciBridge, "rgb123"}}
bridges := []*Bridge{{make(map[uint32]string), pciBridge, "rgb123", 5}}
// add device
devID := "abc123"

View File

@@ -353,6 +353,10 @@ func (q *qemu) createSandbox(sandboxConfig SandboxConfig) error {
},
}
// Add bridges before any other devices. This way we make sure that
// bridge gets the first available PCI address i.e bridgePCIStartAddr
devices = q.arch.appendBridges(devices, q.state.Bridges)
devices = q.arch.append9PVolumes(devices, sandboxConfig.Volumes)
devices = q.arch.appendConsole(devices, q.getSandboxConsole(sandboxConfig.ID))
@@ -363,11 +367,6 @@ func (q *qemu) createSandbox(sandboxConfig SandboxConfig) error {
}
}
devices = q.arch.appendBridges(devices, q.state.Bridges)
if err != nil {
return err
}
var ioThread *govmmQemu.IOThread
if q.config.BlockDeviceDriver == VirtioSCSI {
devices, ioThread = q.arch.appendSCSIController(devices, q.config.EnableIOThreads)

View File

@@ -8,6 +8,7 @@ package virtcontainers
import (
"fmt"
"os"
"strconv"
govmmQemu "github.com/intel/govmm/qemu"
)
@@ -204,6 +205,8 @@ func (q *qemuAmd64) appendBridges(devices []govmmQemu.Device, bridges []Bridge)
t = govmmQemu.PCIEBridge
}
b.Addr = bridgePCIStartAddr + idx
devices = append(devices,
govmmQemu.BridgeDevice{
Type: t,
@@ -212,6 +215,7 @@ func (q *qemuAmd64) appendBridges(devices []govmmQemu.Device, bridges []Bridge)
// Each bridge is required to be assigned a unique chassis id > 0
Chassis: (idx + 1),
SHPC: true,
Addr: strconv.FormatInt(int64(b.Addr), 10),
},
)
}

View File

@@ -146,6 +146,7 @@ func TestQemuAmd64AppendBridges(t *testing.T) {
ID: bridges[0].ID,
Chassis: 1,
SHPC: true,
Addr: "2",
},
}
@@ -168,6 +169,7 @@ func TestQemuAmd64AppendBridges(t *testing.T) {
ID: bridges[0].ID,
Chassis: 1,
SHPC: true,
Addr: "2",
},
}

View File

@@ -9,6 +9,7 @@ import (
"encoding/hex"
"fmt"
"os"
"strconv"
govmmQemu "github.com/intel/govmm/qemu"
)
@@ -100,6 +101,12 @@ const (
defaultMsize9p = 8192
)
// This is the PCI start address assigned to the first bridge that
// is added on the qemu command line. In case of x86_64, the first two PCI
// addresses (0 and 1) are used by the platform while in case of ARM, address
// 0 is reserved.
const bridgePCIStartAddr = 2
const (
// VirtioBlock means use virtio-blk for hotplugging drives
VirtioBlock = "virtio-blk"
@@ -321,6 +328,8 @@ func (q *qemuArchBase) appendBridges(devices []govmmQemu.Device, bridges []Bridg
t = govmmQemu.PCIEBridge
}
b.Addr = bridgePCIStartAddr + idx
devices = append(devices,
govmmQemu.BridgeDevice{
Type: t,
@@ -329,6 +338,7 @@ func (q *qemuArchBase) appendBridges(devices []govmmQemu.Device, bridges []Bridg
// Each bridge is required to be assigned a unique chassis id > 0
Chassis: (idx + 1),
SHPC: true,
Addr: strconv.FormatInt(int64(b.Addr), 10),
},
)
}

View File

@@ -327,6 +327,7 @@ func TestQemuArchBaseAppendBridges(t *testing.T) {
ID: bridges[0].ID,
Chassis: 1,
SHPC: true,
Addr: "2",
},
}