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

Commit 03fb9c5

Browse files
committed
clh: Set 'Id' explicitly while hotplugging block device
To support unplug block device, we need to set the 'Id' explicitly while hotplugging devices with cloud-hypervisor HTTP API. Fixes: #2832 Signed-off-by: Bo Chen <[email protected]>
1 parent d4be90a commit 03fb9c5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

virtcontainers/clh.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ func (clh *cloudHypervisor) getThreadIDs() (vcpuThreadIDs, error) {
402402
return vcpuInfo, nil
403403
}
404404

405-
func (clh *cloudHypervisor) hotplugBlockDevice(drive *config.BlockDrive) error {
405+
func clhDriveIndexToID(i int) string {
406+
return "clh_drive_" + strconv.Itoa(i)
407+
}
408+
409+
func (clh *cloudHypervisor) hotplugAddBlockDevice(drive *config.BlockDrive) error {
406410
if clh.config.BlockDeviceDriver != config.VirtioBlock {
407411
return fmt.Errorf("incorrect hypervisor configuration on 'block_device_driver':"+
408412
" using '%v' but only support '%v'", clh.config.BlockDeviceDriver, config.VirtioBlock)
@@ -417,6 +421,8 @@ func (clh *cloudHypervisor) hotplugBlockDevice(drive *config.BlockDrive) error {
417421
return openAPIClientError(err)
418422
}
419423

424+
driveID := clhDriveIndexToID(drive.Index)
425+
420426
//Explicitly set PCIAddr to NULL, so that VirtPath can be used
421427
drive.PCIAddr = ""
422428

@@ -427,6 +433,7 @@ func (clh *cloudHypervisor) hotplugBlockDevice(drive *config.BlockDrive) error {
427433
Path: drive.File,
428434
Readonly: drive.ReadOnly,
429435
VhostUser: false,
436+
Id: driveID,
430437
}
431438
_, _, err = cl.VmAddDiskPut(ctx, blkDevice)
432439
}
@@ -461,7 +468,7 @@ func (clh *cloudHypervisor) hotplugAddDevice(devInfo interface{}, devType device
461468
switch devType {
462469
case blockDev:
463470
drive := devInfo.(*config.BlockDrive)
464-
return nil, clh.hotplugBlockDevice(drive)
471+
return nil, clh.hotplugAddBlockDevice(drive)
465472
case vfioDev:
466473
device := devInfo.(*config.VFIODev)
467474
return nil, clh.hotPlugVFIODevice(*device)

0 commit comments

Comments
 (0)