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

Commit

Permalink
qemu: Pass the pci/e address for qemu bridge
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
amshinde committed Apr 19, 2018
1 parent ee2e15c commit 05c4ea3
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions virtcontainers/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions virtcontainers/qemu_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package virtcontainers
import (
"fmt"
"os"
"strconv"

govmmQemu "github.com/intel/govmm/qemu"
)
Expand Down Expand Up @@ -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,
Expand All @@ -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),
},
)
}
Expand Down
2 changes: 2 additions & 0 deletions virtcontainers/qemu_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestQemuAmd64AppendBridges(t *testing.T) {
ID: bridges[0].ID,
Chassis: 1,
SHPC: true,
Addr: "2",
},
}

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

Expand Down
10 changes: 10 additions & 0 deletions virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/hex"
"fmt"
"os"
"strconv"

govmmQemu "github.com/intel/govmm/qemu"
)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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),
},
)
}
Expand Down
1 change: 1 addition & 0 deletions virtcontainers/qemu_arch_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ func TestQemuArchBaseAppendBridges(t *testing.T) {
ID: bridges[0].ID,
Chassis: 1,
SHPC: true,
Addr: "2",
},
}

Expand Down

0 comments on commit 05c4ea3

Please sign in to comment.