Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
device: fix detach function to remove hot plugged devices
Browse files Browse the repository at this point in the history
use PCI bridges to remove devices, the bridge will update its list
of devices and addressese to be able to reuse empty slots

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Oct 30, 2017
1 parent ec37047 commit c5741a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ func (c *Container) attachDevices() error {

func (c *Container) detachDevices() error {
for _, device := range c.devices {
if err := device.detach(c.pod.hypervisor); err != nil {
if err := device.detach(c.pod.hypervisor, c); err != nil {
return err
}
}
Expand Down
21 changes: 14 additions & 7 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (
// Device is the virtcontainers device interface.
type Device interface {
attach(hypervisor, *Container) error
detach(hypervisor) error
detach(hypervisor, *Container) error
deviceType() string
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func (device *VFIODevice) attach(h hypervisor, c *Container) error {
return nil
}

func (device *VFIODevice) detach(h hypervisor) error {
func (device *VFIODevice) detach(h hypervisor, c *Container) error {
return nil
}

Expand Down Expand Up @@ -252,19 +252,26 @@ func (device *BlockDevice) attach(h hypervisor, c *Container) (err error) {
return nil
}

func (device BlockDevice) detach(h hypervisor) error {
func (device BlockDevice) detach(h hypervisor, c *Container) error {
if device.DeviceInfo.Hotplugged {
deviceLogger().WithField("device", device.DeviceInfo.HostPath).Info("Unplugging block device")

drive := Drive{
ID: makeBlockDevIDForHypervisor(device.DeviceInfo.ID),
}

if err := h.hotplugRemoveDevice(drive, blockDev); err != nil {
deviceLogger().WithError(err).Error("Failed to unplug block device")
return err
var err error
for _, b := range c.pod.config.VMConfig.Bridges {
err = b.hotplugRemovePCIDevice(h, drive, blockDev)
if err == nil {
// devices was hot unplugged correctly
break
}
}

if err != nil {
return err
}
}
return nil
}
Expand All @@ -290,7 +297,7 @@ func (device *GenericDevice) attach(h hypervisor, c *Container) error {
return nil
}

func (device *GenericDevice) detach(h hypervisor) error {
func (device *GenericDevice) detach(h hypervisor, c *Container) error {
return nil
}

Expand Down

0 comments on commit c5741a6

Please sign in to comment.