This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hypervisor: add hot plugging support for Qemu Q35
Qemu Q35 machine type does not support to hot plug devices directly on pcie.0, hence we have to find a way to allow users hot plug N devices. The only way to hot plug devices in Qemu Q35 is through PCI brdiges. Each PCI bridge is able to support until 32 devices, therefore we have a limitation in the amount of devices we can hot plug. This patch adds support for hot plugging devices on PCI bridges in pc and q35 machine types. Signed-off-by: Julio Montes <julio.montes@intel.com>
- Loading branch information
Julio Montes
committed
Nov 13, 2017
1 parent
506f076
commit 1a1208f
Showing
7 changed files
with
265 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
// Copyright (c) 2017 Intel Corporation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package virtcontainers | ||
|
||
import "fmt" | ||
|
||
type bridgeType string | ||
|
||
const ( | ||
pciBridge bridgeType = "pci" | ||
pcieBridge = "pcie" | ||
) | ||
|
||
const pciBridgeMaxCapacity = 30 | ||
|
||
// Bridge is a bridge where devices can be hot plugged | ||
type Bridge struct { | ||
// Address contains information about devices plugged and its address in the bridge | ||
Address map[uint32]string | ||
|
||
// Type is the type of the bridge (pci, pcie, etc) | ||
Type bridgeType | ||
|
||
//ID is used to identify the bridge in the hypervisor | ||
ID string | ||
} | ||
|
||
// NewBridges creates n new pci(e) bridges depending of the machine type | ||
func NewBridges(n uint32, machine string) []Bridge { | ||
var bridges []Bridge | ||
var bt bridgeType | ||
|
||
switch machine { | ||
case QemuQ35: | ||
// currently only pci bridges are supported | ||
// qemu-2.10 will introduce pcie bridges | ||
fallthrough | ||
case QemuPC: | ||
bt = pciBridge | ||
default: | ||
return nil | ||
} | ||
|
||
for i := uint32(0); i < n; i++ { | ||
bridges = append(bridges, Bridge{ | ||
Type: bt, | ||
ID: fmt.Sprintf("%s-bridge-%d", bt, i), | ||
Address: make(map[uint32]string), | ||
}) | ||
} | ||
|
||
return bridges | ||
} | ||
|
||
// addDevice on success adds the device ID to the bridge and return the address | ||
// where the device was added, otherwise an error is returned | ||
func (b *Bridge) addDevice(ID string) (uint32, error) { | ||
var addr uint32 | ||
|
||
// looking for the first available address | ||
for i := uint32(1); i <= pciBridgeMaxCapacity; i++ { | ||
if _, ok := b.Address[i]; !ok { | ||
addr = i | ||
break | ||
} | ||
} | ||
|
||
if addr == 0 { | ||
return 0, fmt.Errorf("Unable to hot plug device on bridge: there are not empty slots") | ||
} | ||
|
||
// save address and device | ||
b.Address[addr] = ID | ||
return addr, nil | ||
} | ||
|
||
// removeDevice on success removes the device ID from the bridge and return nil, | ||
// otherwise an error is returned | ||
func (b *Bridge) removeDevice(ID string) error { | ||
// check if the device was hot plugged in the bridge | ||
for addr, devID := range b.Address { | ||
if devID == ID { | ||
// free address to re-use the same slot with other devices | ||
delete(b.Address, addr) | ||
return nil | ||
} | ||
} | ||
|
||
return fmt.Errorf("Unable to hot unplug device %s: not present on bridge", ID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.