@@ -1374,64 +1374,66 @@ protected boolean checkDetachSuccess(String diskPath, Domain dm) throws LibvirtE
13741374
13751375 /**
13761376 * Attaches or detaches a disk to an instance.
1377- * @param conn libvirt connection
1378- * @param attach boolean that determines whether the device will be attached or detached
1379- * @param vmName instance name
1380- * @param attachingDisk kvm physical disk
1381- * @param devId device id in instance
1377+ * @param conn libvirt connection
1378+ * @param attach boolean that determines whether the device will be attached or detached
1379+ * @param vmName instance name
1380+ * @param attachingDisk kvm physical disk
1381+ * @param devId device id in instance
13821382 * @param serial
1383- * @param bytesReadRate bytes read rate
1384- * @param bytesReadRateMax bytes read rate max
1385- * @param bytesReadRateMaxLength bytes read rate max length
1386- * @param bytesWriteRate bytes write rate
1387- * @param bytesWriteRateMax bytes write rate amx
1383+ * @param bytesReadRate bytes read rate
1384+ * @param bytesReadRateMax bytes read rate max
1385+ * @param bytesReadRateMaxLength bytes read rate max length
1386+ * @param bytesWriteRate bytes write rate
1387+ * @param bytesWriteRateMax bytes write rate amx
13881388 * @param bytesWriteRateMaxLength bytes write rate max length
1389- * @param iopsReadRate iops read rate
1390- * @param iopsReadRateMax iops read rate max
1391- * @param iopsReadRateMaxLength iops read rate max length
1392- * @param iopsWriteRate iops write rate
1393- * @param iopsWriteRateMax iops write rate max
1394- * @param iopsWriteRateMaxLength iops write rate max length
1395- * @param cacheMode cache mode
1396- * @param encryptDetails encrypt details
1389+ * @param iopsReadRate iops read rate
1390+ * @param iopsReadRateMax iops read rate max
1391+ * @param iopsReadRateMaxLength iops read rate max length
1392+ * @param iopsWriteRate iops write rate
1393+ * @param iopsWriteRateMax iops write rate max
1394+ * @param iopsWriteRateMaxLength iops write rate max length
1395+ * @param cacheMode cache mode
1396+ * @param encryptDetails encrypt details
1397+ * @param controllerInfo
13971398 * @throws LibvirtException
13981399 * @throws InternalErrorException
13991400 */
14001401 protected synchronized void attachOrDetachDisk (final Connect conn , final boolean attach , final String vmName , final KVMPhysicalDisk attachingDisk , final int devId ,
14011402 final String serial , final Long bytesReadRate , final Long bytesReadRateMax , final Long bytesReadRateMaxLength ,
14021403 final Long bytesWriteRate , final Long bytesWriteRateMax , final Long bytesWriteRateMaxLength , final Long iopsReadRate ,
14031404 final Long iopsReadRateMax , final Long iopsReadRateMaxLength , final Long iopsWriteRate , final Long iopsWriteRateMax ,
1404- final Long iopsWriteRateMaxLength , final String cacheMode , final DiskDef .LibvirtDiskEncryptDetails encryptDetails , Map <String , String > details )
1405+ final Long iopsWriteRateMaxLength , final String cacheMode , final DiskDef .LibvirtDiskEncryptDetails encryptDetails , Map <String , String > details , Map < String , String > controllerInfo )
14051406 throws LibvirtException , InternalErrorException {
14061407 attachOrDetachDisk (conn , attach , vmName , attachingDisk , devId , serial , bytesReadRate , bytesReadRateMax , bytesReadRateMaxLength ,
14071408 bytesWriteRate , bytesWriteRateMax , bytesWriteRateMaxLength , iopsReadRate , iopsReadRateMax , iopsReadRateMaxLength , iopsWriteRate ,
1408- iopsWriteRateMax , iopsWriteRateMaxLength , cacheMode , encryptDetails , 0l , details );
1409+ iopsWriteRateMax , iopsWriteRateMaxLength , cacheMode , encryptDetails , 0l , details , controllerInfo );
14091410 }
14101411
14111412 /**
14121413 *
14131414 * Attaches or detaches a disk to an instance.
1414- * @param conn libvirt connection
1415- * @param attach boolean that determines whether the device will be attached or detached
1416- * @param vmName instance name
1417- * @param attachingDisk kvm physical disk
1418- * @param devId device id in instance
1415+ * @param conn libvirt connection
1416+ * @param attach boolean that determines whether the device will be attached or detached
1417+ * @param vmName instance name
1418+ * @param attachingDisk kvm physical disk
1419+ * @param devId device id in instance
14191420 * @param serial
1420- * @param bytesReadRate bytes read rate
1421- * @param bytesReadRateMax bytes read rate max
1422- * @param bytesReadRateMaxLength bytes read rate max length
1423- * @param bytesWriteRate bytes write rate
1424- * @param bytesWriteRateMax bytes write rate amx
1421+ * @param bytesReadRate bytes read rate
1422+ * @param bytesReadRateMax bytes read rate max
1423+ * @param bytesReadRateMaxLength bytes read rate max length
1424+ * @param bytesWriteRate bytes write rate
1425+ * @param bytesWriteRateMax bytes write rate amx
14251426 * @param bytesWriteRateMaxLength bytes write rate max length
1426- * @param iopsReadRate iops read rate
1427- * @param iopsReadRateMax iops read rate max
1428- * @param iopsReadRateMaxLength iops read rate max length
1429- * @param iopsWriteRate iops write rate
1430- * @param iopsWriteRateMax iops write rate max
1431- * @param iopsWriteRateMaxLength iops write rate max length
1432- * @param cacheMode cache mode
1433- * @param encryptDetails encrypt details
1434- * @param waitDetachDevice value set in milliseconds to wait before assuming device removal failed
1427+ * @param iopsReadRate iops read rate
1428+ * @param iopsReadRateMax iops read rate max
1429+ * @param iopsReadRateMaxLength iops read rate max length
1430+ * @param iopsWriteRate iops write rate
1431+ * @param iopsWriteRateMax iops write rate max
1432+ * @param iopsWriteRateMaxLength iops write rate max length
1433+ * @param cacheMode cache mode
1434+ * @param encryptDetails encrypt details
1435+ * @param waitDetachDevice value set in milliseconds to wait before assuming device removal failed
1436+ * @param controllerInfo
14351437 * @throws LibvirtException
14361438 * @throws InternalErrorException
14371439 */
@@ -1440,7 +1442,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
14401442 final Long bytesWriteRate , final Long bytesWriteRateMax , final Long bytesWriteRateMaxLength , final Long iopsReadRate ,
14411443 final Long iopsReadRateMax , final Long iopsReadRateMaxLength , final Long iopsWriteRate , final Long iopsWriteRateMax ,
14421444 final Long iopsWriteRateMaxLength , final String cacheMode , final DiskDef .LibvirtDiskEncryptDetails encryptDetails ,
1443- long waitDetachDevice , Map <String , String > details )
1445+ long waitDetachDevice , Map <String , String > details , Map < String , String > controllerInfo )
14441446 throws LibvirtException , InternalErrorException {
14451447
14461448 List <DiskDef > disks = null ;
@@ -1477,17 +1479,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
14771479 return ;
14781480 }
14791481 } else {
1480- DiskDef .DiskBus busT = DiskDef .DiskBus .VIRTIO ;
1481- for (final DiskDef disk : disks ) {
1482- if (disk .getDeviceType () == DeviceType .DISK ) {
1483- if (disk .getBusType () == DiskDef .DiskBus .SCSI ) {
1484- busT = DiskDef .DiskBus .SCSI ;
1485- } else if (disk .getBusType () == DiskDef .DiskBus .VIRTIOBLK ) {
1486- busT = DiskDef .DiskBus .VIRTIOBLK ;
1487- }
1488- break ;
1489- }
1490- }
1482+ DiskDef .DiskBus busT = getAttachDiskBusType (devId , disks , controllerInfo );
14911483 diskdef = new DiskDef ();
14921484 if (busT == DiskDef .DiskBus .SCSI || busT == DiskDef .DiskBus .VIRTIOBLK ) {
14931485 diskdef .setQemuDriver (true );
@@ -1592,6 +1584,28 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
15921584 }
15931585 }
15941586
1587+ protected DiskDef .DiskBus getAttachDiskBusType (int deviceId , List <DiskDef > disks , Map <String , String > controllerInfo ) {
1588+ String controllerKey = deviceId == 0 ? VmDetailConstants .ROOT_DISK_CONTROLLER : VmDetailConstants .DATA_DISK_CONTROLLER ;
1589+ String diskController = MapUtils .getString (controllerInfo , controllerKey );
1590+ DiskDef .DiskBus busType = DiskDef .DiskBus .fromValue (diskController );
1591+ if (diskController != null ) {
1592+ logger .debug ("Using controller '{}' from command specified as {} while attaching disk (deviceId={})" ,
1593+ diskController , controllerKey , deviceId );
1594+ return busType ;
1595+ }
1596+ for (final DiskDef disk : disks ) {
1597+ if (disk .getDeviceType () != DeviceType .DISK ) {
1598+ continue ;
1599+ }
1600+ if (disk .getBusType () == DiskDef .DiskBus .SCSI ) {
1601+ return DiskDef .DiskBus .SCSI ;
1602+ } else if (disk .getBusType () == DiskDef .DiskBus .VIRTIOBLK ) {
1603+ return DiskDef .DiskBus .VIRTIOBLK ;
1604+ }
1605+ }
1606+ return DiskDef .DiskBus .VIRTIO ;
1607+ }
1608+
15951609 @ Override
15961610 public Answer attachVolume (final AttachCommand cmd ) {
15971611 final DiskTO disk = cmd .getDisk ();
@@ -1619,7 +1633,8 @@ public Answer attachVolume(final AttachCommand cmd) {
16191633 vol .getBytesReadRate (), vol .getBytesReadRateMax (), vol .getBytesReadRateMaxLength (),
16201634 vol .getBytesWriteRate (), vol .getBytesWriteRateMax (), vol .getBytesWriteRateMaxLength (),
16211635 vol .getIopsReadRate (), vol .getIopsReadRateMax (), vol .getIopsReadRateMaxLength (),
1622- vol .getIopsWriteRate (), vol .getIopsWriteRateMax (), vol .getIopsWriteRateMaxLength (), volCacheMode , encryptDetails , disk .getDetails ());
1636+ vol .getIopsWriteRate (), vol .getIopsWriteRateMax (), vol .getIopsWriteRateMaxLength (), volCacheMode ,
1637+ encryptDetails , disk .getDetails (), cmd .getControllerInfo ());
16231638
16241639 resource .recreateCheckpointsOnVm (List .of ((VolumeObjectTO ) disk .getData ()), vmName , conn );
16251640
@@ -1658,7 +1673,7 @@ public Answer dettachVolume(final DettachCommand cmd) {
16581673 vol .getBytesReadRate (), vol .getBytesReadRateMax (), vol .getBytesReadRateMaxLength (),
16591674 vol .getBytesWriteRate (), vol .getBytesWriteRateMax (), vol .getBytesWriteRateMaxLength (),
16601675 vol .getIopsReadRate (), vol .getIopsReadRateMax (), vol .getIopsReadRateMaxLength (),
1661- vol .getIopsWriteRate (), vol .getIopsWriteRateMax (), vol .getIopsWriteRateMaxLength (), volCacheMode , null , waitDetachDevice , null );
1676+ vol .getIopsWriteRate (), vol .getIopsWriteRateMax (), vol .getIopsWriteRateMaxLength (), volCacheMode , null , waitDetachDevice , null , null );
16621677
16631678 storagePoolMgr .disconnectPhysicalDisk (primaryStore .getPoolType (), primaryStore .getUuid (), vol .getPath ());
16641679
0 commit comments