From 5f1bc4926323281653aee5934b6551111f6b76e4 Mon Sep 17 00:00:00 2001 From: Archana Shinde Date: Tue, 20 Mar 2018 10:34:38 -0700 Subject: [PATCH] virtcontainers: qemu: Call removeDeviceFromBridge for virtio-blk In case of virtio-block, we hotplug devices to a bridge. We need to remove device from bridge while stopping a container. Fixes #82 Signed-off-by: Archana Shinde --- virtcontainers/qemu.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 90004c0938..c7025230a2 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -559,6 +559,19 @@ func (q *qemu) addDeviceToBridge(ID string) (string, string, error) { return "", "", err } +func (q *qemu) removeDeviceFromBridge(ID string) error { + var err error + for _, b := range q.state.Bridges { + err = b.removeDevice(ID) + if err == nil { + // device was removed correctly + return nil + } + } + + return err +} + func (q *qemu) hotplugBlockDevice(drive Drive, op operation) error { defer func(qemu *qemu) { if q.qmpMonitorCh.qmp != nil { @@ -607,6 +620,12 @@ func (q *qemu) hotplugBlockDevice(drive Drive, op operation) error { } } } else { + if q.config.BlockDeviceDriver == VirtioBlock { + if err := q.removeDeviceFromBridge(drive.ID); err != nil { + return err + } + } + if err := q.qmpMonitorCh.qmp.ExecuteDeviceDel(q.qmpMonitorCh.ctx, devID); err != nil { return err }