Skip to content

Commit 1a7076e

Browse files
committed
incusd/instance/qemu: Add indirection level to detachDisk
Signed-off-by: Benjamin Somers <benjamin.somers@imt-atlantique.fr>
1 parent 24d6085 commit 1a7076e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

internal/server/instance/drivers/driver_qemu.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ type qemu struct {
359359

360360
// qmpConnect connects to the QMP monitor.
361361
func (d *qemu) qmpConnect() (*qmp.Monitor, error) {
362-
return qmp.Connect(d.monitorPath(), qemuSerialChardevName, d.getMonitorEventHandler(), d.QMPLogFilePath(), d.detachDisk)
362+
return qmp.Connect(d.monitorPath(), qemuSerialChardevName, d.getMonitorEventHandler(), d.QMPLogFilePath(), qemuDetachDisk(d.state, d.id))
363363
}
364364

365365
// getAgentClient returns the current agent client handle.
@@ -5827,6 +5827,23 @@ func (d *qemu) Rename(newName string, applyTemplateTrigger bool) error {
58275827
return nil
58285828
}
58295829

5830+
// Indirection to detachDisk.
5831+
func qemuDetachDisk(s *state.State, id int) func(string) error {
5832+
return func(name string) error {
5833+
inst, err := instance.LoadByID(s, id)
5834+
if err != nil {
5835+
return err
5836+
}
5837+
5838+
qemuInst, ok := inst.(*qemu)
5839+
if !ok {
5840+
return fmt.Errorf("Couldn't assert QEMU object from interface")
5841+
}
5842+
5843+
return qemuInst.detachDisk(name)
5844+
}
5845+
}
5846+
58305847
// Detach a disk from the instance.
58315848
func (d *qemu) detachDisk(name string) error {
58325849
diskName := strings.TrimPrefix(name, qemuDeviceIDPrefix)

0 commit comments

Comments
 (0)