@@ -1320,64 +1320,66 @@ protected boolean checkDetachSuccess(String diskPath, Domain dm) throws LibvirtE
13201320
13211321 /**
13221322 * Attaches or detaches a disk to an instance.
1323- * @param conn libvirt connection
1324- * @param attach boolean that determines whether the device will be attached or detached
1325- * @param vmName instance name
1326- * @param attachingDisk kvm physical disk
1327- * @param devId device id in instance
1323+ * @param conn libvirt connection
1324+ * @param attach boolean that determines whether the device will be attached or detached
1325+ * @param vmName instance name
1326+ * @param attachingDisk kvm physical disk
1327+ * @param devId device id in instance
13281328 * @param serial
1329- * @param bytesReadRate bytes read rate
1330- * @param bytesReadRateMax bytes read rate max
1331- * @param bytesReadRateMaxLength bytes read rate max length
1332- * @param bytesWriteRate bytes write rate
1333- * @param bytesWriteRateMax bytes write rate amx
1329+ * @param bytesReadRate bytes read rate
1330+ * @param bytesReadRateMax bytes read rate max
1331+ * @param bytesReadRateMaxLength bytes read rate max length
1332+ * @param bytesWriteRate bytes write rate
1333+ * @param bytesWriteRateMax bytes write rate amx
13341334 * @param bytesWriteRateMaxLength bytes write rate max length
1335- * @param iopsReadRate iops read rate
1336- * @param iopsReadRateMax iops read rate max
1337- * @param iopsReadRateMaxLength iops read rate max length
1338- * @param iopsWriteRate iops write rate
1339- * @param iopsWriteRateMax iops write rate max
1340- * @param iopsWriteRateMaxLength iops write rate max length
1341- * @param cacheMode cache mode
1342- * @param encryptDetails encrypt details
1335+ * @param iopsReadRate iops read rate
1336+ * @param iopsReadRateMax iops read rate max
1337+ * @param iopsReadRateMaxLength iops read rate max length
1338+ * @param iopsWriteRate iops write rate
1339+ * @param iopsWriteRateMax iops write rate max
1340+ * @param iopsWriteRateMaxLength iops write rate max length
1341+ * @param cacheMode cache mode
1342+ * @param encryptDetails encrypt details
1343+ * @param controllerInfo
13431344 * @throws LibvirtException
13441345 * @throws InternalErrorException
13451346 */
13461347 protected synchronized void attachOrDetachDisk (final Connect conn , final boolean attach , final String vmName , final KVMPhysicalDisk attachingDisk , final int devId ,
13471348 final String serial , final Long bytesReadRate , final Long bytesReadRateMax , final Long bytesReadRateMaxLength ,
13481349 final Long bytesWriteRate , final Long bytesWriteRateMax , final Long bytesWriteRateMaxLength , final Long iopsReadRate ,
13491350 final Long iopsReadRateMax , final Long iopsReadRateMaxLength , final Long iopsWriteRate , final Long iopsWriteRateMax ,
1350- final Long iopsWriteRateMaxLength , final String cacheMode , final DiskDef .LibvirtDiskEncryptDetails encryptDetails , Map <String , String > details )
1351+ final Long iopsWriteRateMaxLength , final String cacheMode , final DiskDef .LibvirtDiskEncryptDetails encryptDetails , Map <String , String > details , Map < String , String > controllerInfo )
13511352 throws LibvirtException , InternalErrorException {
13521353 attachOrDetachDisk (conn , attach , vmName , attachingDisk , devId , serial , bytesReadRate , bytesReadRateMax , bytesReadRateMaxLength ,
13531354 bytesWriteRate , bytesWriteRateMax , bytesWriteRateMaxLength , iopsReadRate , iopsReadRateMax , iopsReadRateMaxLength , iopsWriteRate ,
1354- iopsWriteRateMax , iopsWriteRateMaxLength , cacheMode , encryptDetails , 0l , details );
1355+ iopsWriteRateMax , iopsWriteRateMaxLength , cacheMode , encryptDetails , 0l , details , controllerInfo );
13551356 }
13561357
13571358 /**
13581359 *
13591360 * Attaches or detaches a disk to an instance.
1360- * @param conn libvirt connection
1361- * @param attach boolean that determines whether the device will be attached or detached
1362- * @param vmName instance name
1363- * @param attachingDisk kvm physical disk
1364- * @param devId device id in instance
1361+ * @param conn libvirt connection
1362+ * @param attach boolean that determines whether the device will be attached or detached
1363+ * @param vmName instance name
1364+ * @param attachingDisk kvm physical disk
1365+ * @param devId device id in instance
13651366 * @param serial
1366- * @param bytesReadRate bytes read rate
1367- * @param bytesReadRateMax bytes read rate max
1368- * @param bytesReadRateMaxLength bytes read rate max length
1369- * @param bytesWriteRate bytes write rate
1370- * @param bytesWriteRateMax bytes write rate amx
1367+ * @param bytesReadRate bytes read rate
1368+ * @param bytesReadRateMax bytes read rate max
1369+ * @param bytesReadRateMaxLength bytes read rate max length
1370+ * @param bytesWriteRate bytes write rate
1371+ * @param bytesWriteRateMax bytes write rate amx
13711372 * @param bytesWriteRateMaxLength bytes write rate max length
1372- * @param iopsReadRate iops read rate
1373- * @param iopsReadRateMax iops read rate max
1374- * @param iopsReadRateMaxLength iops read rate max length
1375- * @param iopsWriteRate iops write rate
1376- * @param iopsWriteRateMax iops write rate max
1377- * @param iopsWriteRateMaxLength iops write rate max length
1378- * @param cacheMode cache mode
1379- * @param encryptDetails encrypt details
1380- * @param waitDetachDevice value set in milliseconds to wait before assuming device removal failed
1373+ * @param iopsReadRate iops read rate
1374+ * @param iopsReadRateMax iops read rate max
1375+ * @param iopsReadRateMaxLength iops read rate max length
1376+ * @param iopsWriteRate iops write rate
1377+ * @param iopsWriteRateMax iops write rate max
1378+ * @param iopsWriteRateMaxLength iops write rate max length
1379+ * @param cacheMode cache mode
1380+ * @param encryptDetails encrypt details
1381+ * @param waitDetachDevice value set in milliseconds to wait before assuming device removal failed
1382+ * @param controllerInfo
13811383 * @throws LibvirtException
13821384 * @throws InternalErrorException
13831385 */
@@ -1386,7 +1388,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
13861388 final Long bytesWriteRate , final Long bytesWriteRateMax , final Long bytesWriteRateMaxLength , final Long iopsReadRate ,
13871389 final Long iopsReadRateMax , final Long iopsReadRateMaxLength , final Long iopsWriteRate , final Long iopsWriteRateMax ,
13881390 final Long iopsWriteRateMaxLength , final String cacheMode , final DiskDef .LibvirtDiskEncryptDetails encryptDetails ,
1389- long waitDetachDevice , Map <String , String > details )
1391+ long waitDetachDevice , Map <String , String > details , Map < String , String > controllerInfo )
13901392 throws LibvirtException , InternalErrorException {
13911393
13921394 List <DiskDef > disks = null ;
@@ -1423,17 +1425,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
14231425 return ;
14241426 }
14251427 } else {
1426- DiskDef .DiskBus busT = DiskDef .DiskBus .VIRTIO ;
1427- for (final DiskDef disk : disks ) {
1428- if (disk .getDeviceType () == DeviceType .DISK ) {
1429- if (disk .getBusType () == DiskDef .DiskBus .SCSI ) {
1430- busT = DiskDef .DiskBus .SCSI ;
1431- } else if (disk .getBusType () == DiskDef .DiskBus .VIRTIOBLK ) {
1432- busT = DiskDef .DiskBus .VIRTIOBLK ;
1433- }
1434- break ;
1435- }
1436- }
1428+ DiskDef .DiskBus busT = getAttachDiskBusType (devId , disks , controllerInfo );
14371429 diskdef = new DiskDef ();
14381430 if (busT == DiskDef .DiskBus .SCSI || busT == DiskDef .DiskBus .VIRTIOBLK ) {
14391431 diskdef .setQemuDriver (true );
@@ -1538,6 +1530,28 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean
15381530 }
15391531 }
15401532
1533+ protected DiskDef .DiskBus getAttachDiskBusType (int deviceId , List <DiskDef > disks , Map <String , String > controllerInfo ) {
1534+ String controllerKey = deviceId == 0 ? VmDetailConstants .ROOT_DISK_CONTROLLER : VmDetailConstants .DATA_DISK_CONTROLLER ;
1535+ String diskController = MapUtils .getString (controllerInfo , controllerKey );
1536+ DiskDef .DiskBus busType = DiskDef .DiskBus .fromValue (diskController );
1537+ if (diskController != null ) {
1538+ logger .debug ("Using controller '{}' from command specified as {} while attaching disk (deviceId={})" ,
1539+ diskController , controllerKey , deviceId );
1540+ return busType ;
1541+ }
1542+ for (final DiskDef disk : disks ) {
1543+ if (disk .getDeviceType () != DeviceType .DISK ) {
1544+ continue ;
1545+ }
1546+ if (disk .getBusType () == DiskDef .DiskBus .SCSI ) {
1547+ return DiskDef .DiskBus .SCSI ;
1548+ } else if (disk .getBusType () == DiskDef .DiskBus .VIRTIOBLK ) {
1549+ return DiskDef .DiskBus .VIRTIOBLK ;
1550+ }
1551+ }
1552+ return DiskDef .DiskBus .VIRTIO ;
1553+ }
1554+
15411555 @ Override
15421556 public Answer attachVolume (final AttachCommand cmd ) {
15431557 final DiskTO disk = cmd .getDisk ();
@@ -1565,7 +1579,8 @@ public Answer attachVolume(final AttachCommand cmd) {
15651579 vol .getBytesReadRate (), vol .getBytesReadRateMax (), vol .getBytesReadRateMaxLength (),
15661580 vol .getBytesWriteRate (), vol .getBytesWriteRateMax (), vol .getBytesWriteRateMaxLength (),
15671581 vol .getIopsReadRate (), vol .getIopsReadRateMax (), vol .getIopsReadRateMaxLength (),
1568- vol .getIopsWriteRate (), vol .getIopsWriteRateMax (), vol .getIopsWriteRateMaxLength (), volCacheMode , encryptDetails , disk .getDetails ());
1582+ vol .getIopsWriteRate (), vol .getIopsWriteRateMax (), vol .getIopsWriteRateMaxLength (), volCacheMode ,
1583+ encryptDetails , disk .getDetails (), cmd .getControllerInfo ());
15691584
15701585 return new AttachAnswer (disk );
15711586 } catch (final LibvirtException e ) {
@@ -1602,7 +1617,7 @@ public Answer dettachVolume(final DettachCommand cmd) {
16021617 vol .getBytesReadRate (), vol .getBytesReadRateMax (), vol .getBytesReadRateMaxLength (),
16031618 vol .getBytesWriteRate (), vol .getBytesWriteRateMax (), vol .getBytesWriteRateMaxLength (),
16041619 vol .getIopsReadRate (), vol .getIopsReadRateMax (), vol .getIopsReadRateMaxLength (),
1605- vol .getIopsWriteRate (), vol .getIopsWriteRateMax (), vol .getIopsWriteRateMaxLength (), volCacheMode , null , waitDetachDevice , null );
1620+ vol .getIopsWriteRate (), vol .getIopsWriteRateMax (), vol .getIopsWriteRateMaxLength (), volCacheMode , null , waitDetachDevice , null , null );
16061621
16071622 storagePoolMgr .disconnectPhysicalDisk (primaryStore .getPoolType (), primaryStore .getUuid (), vol .getPath ());
16081623
0 commit comments