Merge pull request #211 from amshinde/assign-bridge-addr

Assign address to a pci bridge while appending it
This commit is contained in:
Sebastien Boeuf 2018-04-20 14:52:31 -07:00 committed by GitHub
commit de32be7eed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 38 additions and 9 deletions

4
Gopkg.lock generated
View File

@ -85,7 +85,7 @@
[[projects]] [[projects]]
name = "github.com/intel/govmm" name = "github.com/intel/govmm"
packages = ["qemu"] packages = ["qemu"]
revision = "1509acf1862ae5154c5c096f9318bd3eb434d816" revision = "9cf8ce6c6dda19d4a6d529e73714e231f6156820"
[[projects]] [[projects]]
name = "github.com/kata-containers/agent" name = "github.com/kata-containers/agent"
@ -257,6 +257,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "d8a31fdf495bbc93a234bdb9abd5250e2688e50c1c2ac88ae80d4b481cafba0d" inputs-digest = "1d1c6e1edc48dac73618d0ce04d505e22276ad5a3e299dd0964eca608fe8e2f1"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

@ -56,7 +56,7 @@
[[constraint]] [[constraint]]
name = "github.com/intel/govmm" name = "github.com/intel/govmm"
revision = "1509acf1862ae5154c5c096f9318bd3eb434d816" revision = "9cf8ce6c6dda19d4a6d529e73714e231f6156820"
[[constraint]] [[constraint]]
name = "github.com/kata-containers/agent" name = "github.com/kata-containers/agent"

View File

@ -907,6 +907,9 @@ type BridgeDevice struct {
// SHPC is used to enable or disable the standard hot plug controller // SHPC is used to enable or disable the standard hot plug controller
SHPC bool SHPC bool
// PCI Slot
Addr string
} }
// Valid returns true if the BridgeDevice structure is valid and complete. // Valid returns true if the BridgeDevice structure is valid and complete.
@ -941,6 +944,13 @@ func (bridgeDev BridgeDevice) QemuParams(config *Config) []string {
} }
deviceParam := fmt.Sprintf("%s,bus=%s,id=%s,chassis_nr=%d,shpc=%s", deviceName, bridgeDev.Bus, bridgeDev.ID, bridgeDev.Chassis, shpc) deviceParam := fmt.Sprintf("%s,bus=%s,id=%s,chassis_nr=%d,shpc=%s", deviceName, bridgeDev.Bus, bridgeDev.ID, bridgeDev.Chassis, shpc)
if bridgeDev.Addr != "" {
addr, err := strconv.Atoi(bridgeDev.Addr)
if err == nil && addr >= 0 {
deviceParam += fmt.Sprintf(",addr=%x", addr)
}
}
qemuParams = append(qemuParams, "-device") qemuParams = append(qemuParams, "-device")
qemuParams = append(qemuParams, deviceParam) qemuParams = append(qemuParams, deviceParam)

View File

@ -26,6 +26,9 @@ type Bridge struct {
//ID is used to identify the bridge in the hypervisor //ID is used to identify the bridge in the hypervisor
ID string 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 // 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) assert := assert.New(t)
// create a bridge // create a bridge
bridges := []*Bridge{{make(map[uint32]string), pciBridge, "rgb123"}} bridges := []*Bridge{{make(map[uint32]string), pciBridge, "rgb123", 5}}
// add device // add device
devID := "abc123" 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.append9PVolumes(devices, sandboxConfig.Volumes)
devices = q.arch.appendConsole(devices, q.getSandboxConsole(sandboxConfig.ID)) 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 var ioThread *govmmQemu.IOThread
if q.config.BlockDeviceDriver == VirtioSCSI { if q.config.BlockDeviceDriver == VirtioSCSI {
devices, ioThread = q.arch.appendSCSIController(devices, q.config.EnableIOThreads) devices, ioThread = q.arch.appendSCSIController(devices, q.config.EnableIOThreads)

View File

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

View File

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

View File

@ -9,6 +9,7 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"os" "os"
"strconv"
govmmQemu "github.com/intel/govmm/qemu" govmmQemu "github.com/intel/govmm/qemu"
) )
@ -100,6 +101,12 @@ const (
defaultMsize9p = 8192 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 ( const (
// VirtioBlock means use virtio-blk for hotplugging drives // VirtioBlock means use virtio-blk for hotplugging drives
VirtioBlock = "virtio-blk" VirtioBlock = "virtio-blk"
@ -321,6 +328,8 @@ func (q *qemuArchBase) appendBridges(devices []govmmQemu.Device, bridges []Bridg
t = govmmQemu.PCIEBridge t = govmmQemu.PCIEBridge
} }
b.Addr = bridgePCIStartAddr + idx
devices = append(devices, devices = append(devices,
govmmQemu.BridgeDevice{ govmmQemu.BridgeDevice{
Type: t, 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 // Each bridge is required to be assigned a unique chassis id > 0
Chassis: (idx + 1), Chassis: (idx + 1),
SHPC: true, SHPC: true,
Addr: strconv.FormatInt(int64(b.Addr), 10),
}, },
) )
} }

View File

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