125125import com .cloud .hypervisor .kvm .resource .LibvirtVMDef .InputDef ;
126126import com .cloud .hypervisor .kvm .resource .LibvirtVMDef .InterfaceDef ;
127127import com .cloud .hypervisor .kvm .resource .LibvirtVMDef .InterfaceDef .GuestNetType ;
128+ import com .cloud .hypervisor .kvm .resource .LibvirtVMDef .SCSIDef ;
128129import com .cloud .hypervisor .kvm .resource .LibvirtVMDef .SerialDef ;
129130import com .cloud .hypervisor .kvm .resource .LibvirtVMDef .TermPolicy ;
130131import com .cloud .hypervisor .kvm .resource .LibvirtVMDef .VideoDef ;
@@ -2015,7 +2016,7 @@ So if getMinSpeed() returns null we fall back to getSpeed().
20152016 if (vmTO .getOs ().startsWith ("Windows" )) {
20162017 clock .setClockOffset (ClockDef .ClockOffset .LOCALTIME );
20172018 clock .setTimer ("rtc" , "catchup" , null );
2018- } else if (vmTO .getType () != VirtualMachine .Type .User || isGuestPVEnabled (vmTO .getOs ()). equals ( "VIRTIO" ) || isGuestPVEnabled ( vmTO . getOs ()). equals ( "SCSI" ) ) {
2019+ } else if (vmTO .getType () != VirtualMachine .Type .User || isGuestPVEnabled (vmTO .getOs ())) {
20192020 if (_hypervisorLibvirtVersion >= 9 * 1000 + 10 ) {
20202021 clock .setTimer ("kvmclock" , null , null , _noKvmClock );
20212022 }
@@ -2059,6 +2060,13 @@ So if getMinSpeed() returns null we fall back to getSpeed().
20592060 final InputDef input = new InputDef ("tablet" , "usb" );
20602061 devices .addDevice (input );
20612062
2063+ // If we're using virtio scsi, then we need to add a virtual scsi controller
2064+ if (getGuestDiskModel (vmTO .getPlatformEmulator ()) == DiskDef .DiskBus .SCSI ) {
2065+ final SCSIDef sd = new SCSIDef ((short )0 , 0 , 0 , 9 , 0 );
2066+ devices .addDevice (sd );
2067+ s_logger .debug ("Adding scsi definition:\n " + sd .toString ());
2068+ }
2069+
20622070 vm .addComp (devices );
20632071
20642072 return vm ;
@@ -2158,6 +2166,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
21582166
21592167 if (diskBusType == null ) {
21602168 diskBusType = getGuestDiskModel (vmSpec .getPlatformEmulator ());
2169+ s_logger .debug ("disk bus type derived from getPlatformEmulator: " + vmSpec .getPlatformEmulator () + ", diskbustype is: " +diskBusType .toString ());
21612170 }
21622171 final DiskDef disk = new DiskDef ();
21632172 if (volume .getType () == Volume .Type .ISO ) {
@@ -2216,6 +2225,8 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
22162225 disk .setCacheMode (DiskDef .DiskCacheMode .valueOf (volumeObjectTO .getCacheMode ().toString ().toUpperCase ()));
22172226 }
22182227 }
2228+
2229+ s_logger .debug ("Adding disk: " + disk .toString ());
22192230 vm .getDevices ().addDevice (disk );
22202231 }
22212232
@@ -2334,13 +2345,13 @@ public synchronized String attachOrDetachDisk(final Connect conn,
23342345 DiskDef diskdef = null ;
23352346 final KVMStoragePool attachingPool = attachingDisk .getPool ();
23362347 try {
2337- if (!attach ) {
2338- dm = conn .domainLookupByName (vmName );
2339- final LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser ();
2340- final String xml = dm .getXMLDesc (0 );
2341- parser .parseDomainXML (xml );
2342- disks = parser .getDisks ();
2348+ dm = conn .domainLookupByName (vmName );
2349+ final LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser ();
2350+ final String domXml = dm .getXMLDesc (0 );
2351+ parser .parseDomainXML (domXml );
2352+ disks = parser .getDisks ();
23432353
2354+ if (!attach ) {
23442355 for (final DiskDef disk : disks ) {
23452356 final String file = disk .getDiskPath ();
23462357 if (file != null && file .equalsIgnoreCase (attachingDisk .getPath ())) {
@@ -2352,17 +2363,29 @@ public synchronized String attachOrDetachDisk(final Connect conn,
23522363 throw new InternalErrorException ("disk: " + attachingDisk .getPath () + " is not attached before" );
23532364 }
23542365 } else {
2366+ DiskDef .DiskBus busT = DiskDef .DiskBus .VIRTIO ;
2367+ for (final DiskDef disk : disks ) {
2368+ s_logger .debug ("disk is type : " +disk .toString ());
2369+ if (disk .getDeviceType () == DeviceType .DISK ) {
2370+ if (disk .getBusType () == DiskDef .DiskBus .SCSI ) {
2371+ busT = DiskDef .DiskBus .SCSI ;
2372+ }
2373+ s_logger .debug ("Disk bus type: " + disk .getDeviceType ().toString () + ", busT: " +busT .toString ());
2374+ break ;
2375+ }
2376+ }
2377+
23552378 diskdef = new DiskDef ();
23562379 if (attachingPool .getType () == StoragePoolType .RBD ) {
23572380 diskdef .defNetworkBasedDisk (attachingDisk .getPath (), attachingPool .getSourceHost (), attachingPool .getSourcePort (), attachingPool .getAuthUserName (),
2358- attachingPool .getUuid (), devId , DiskDef . DiskBus . VIRTIO , DiskProtocol .RBD , DiskDef .DiskFmtType .RAW );
2381+ attachingPool .getUuid (), devId , busT , DiskProtocol .RBD , DiskDef .DiskFmtType .RAW );
23592382 } else if (attachingPool .getType () == StoragePoolType .Gluster ) {
23602383 diskdef .defNetworkBasedDisk (attachingDisk .getPath (), attachingPool .getSourceHost (), attachingPool .getSourcePort (), null ,
2361- null , devId , DiskDef . DiskBus . VIRTIO , DiskProtocol .GLUSTER , DiskDef .DiskFmtType .QCOW2 );
2384+ null , devId , busT , DiskProtocol .GLUSTER , DiskDef .DiskFmtType .QCOW2 );
23622385 } else if (attachingDisk .getFormat () == PhysicalDiskFormat .QCOW2 ) {
2363- diskdef .defFileBasedDisk (attachingDisk .getPath (), devId , DiskDef . DiskBus . VIRTIO , DiskDef .DiskFmtType .QCOW2 );
2386+ diskdef .defFileBasedDisk (attachingDisk .getPath (), devId , busT , DiskDef .DiskFmtType .QCOW2 );
23642387 } else if (attachingDisk .getFormat () == PhysicalDiskFormat .RAW ) {
2365- diskdef .defBlockBasedDisk (attachingDisk .getPath (), devId , DiskDef . DiskBus . VIRTIO );
2388+ diskdef .defBlockBasedDisk (attachingDisk .getPath (), devId , busT );
23662389 }
23672390 if (bytesReadRate != null && bytesReadRate > 0 ) {
23682391 diskdef .setBytesReadRate (bytesReadRate );
@@ -2960,23 +2983,9 @@ private String getHypervisorPath(final Connect conn) {
29602983 return parser .getEmulator ();
29612984 }
29622985
2963- private String isGuestPVEnabled (final String guestOSName ) {
2964- if (guestOSName == null ) {
2965- return "IDE" ;
2966- }
2967- if (guestOSName .startsWith ("Ubuntu" ) || guestOSName .startsWith ("Fedora 13" ) || guestOSName .startsWith ("Fedora 12" ) || guestOSName .startsWith ("Fedora 11" ) ||
2968- guestOSName .startsWith ("Fedora 10" ) || guestOSName .startsWith ("Fedora 9" ) || guestOSName .startsWith ("CentOS 5.3" ) || guestOSName .startsWith ("CentOS 5.4" ) ||
2969- guestOSName .startsWith ("CentOS 5.5" ) || guestOSName .startsWith ("CentOS" ) || guestOSName .startsWith ("Fedora" ) ||
2970- guestOSName .startsWith ("Red Hat Enterprise Linux 5.3" ) || guestOSName .startsWith ("Red Hat Enterprise Linux 5.4" ) ||
2971- guestOSName .startsWith ("Red Hat Enterprise Linux 5.5" ) || guestOSName .startsWith ("Red Hat Enterprise Linux 6" ) || guestOSName .startsWith ("Debian GNU/Linux" ) ||
2972- guestOSName .startsWith ("FreeBSD 10" ) || guestOSName .startsWith ("Oracle" ) || guestOSName .startsWith ("Other PV" )) {
2973- return "VIRTIO" ;
2974- }
2975- else if (guestOSName .startsWith ("Other PV Virtio-SCSI" )) {
2976- return "SCSI" ;
2977- } else {
2978- return "IDE:" ;
2979- }
2986+ boolean isGuestPVEnabled (final String guestOSName ) {
2987+ DiskDef .DiskBus db = getGuestDiskModel (guestOSName );
2988+ return db != DiskDef .DiskBus .IDE ;
29802989 }
29812990
29822991 public boolean isCentosHost () {
@@ -2988,17 +2997,22 @@ public boolean isCentosHost() {
29882997 }
29892998
29902999 private DiskDef .DiskBus getGuestDiskModel (final String platformEmulator ) {
2991- if (isGuestPVEnabled (platformEmulator ).equals ("VIRTIO" )) {
2992- return DiskDef .DiskBus .VIRTIO ;
2993- } else if (isGuestPVEnabled (platformEmulator ).equals ("SCSI" )) {
2994- return DiskDef .DiskBus .SCSI ;
2995- } else if (isGuestPVEnabled (platformEmulator ).equals ("IDE" )) {
3000+ if (platformEmulator == null ) {
29963001 return DiskDef .DiskBus .IDE ;
3002+ } else if (platformEmulator .startsWith ("Other PV Virtio-SCSI" )) {
3003+ return DiskDef .DiskBus .SCSI ;
3004+ } else if (platformEmulator .startsWith ("Ubuntu" ) || platformEmulator .startsWith ("Fedora 13" ) || platformEmulator .startsWith ("Fedora 12" ) || platformEmulator .startsWith ("Fedora 11" ) ||
3005+ platformEmulator .startsWith ("Fedora 10" ) || platformEmulator .startsWith ("Fedora 9" ) || platformEmulator .startsWith ("CentOS 5.3" ) || platformEmulator .startsWith ("CentOS 5.4" ) ||
3006+ platformEmulator .startsWith ("CentOS 5.5" ) || platformEmulator .startsWith ("CentOS" ) || platformEmulator .startsWith ("Fedora" ) ||
3007+ platformEmulator .startsWith ("Red Hat Enterprise Linux 5.3" ) || platformEmulator .startsWith ("Red Hat Enterprise Linux 5.4" ) ||
3008+ platformEmulator .startsWith ("Red Hat Enterprise Linux 5.5" ) || platformEmulator .startsWith ("Red Hat Enterprise Linux 6" ) || platformEmulator .startsWith ("Debian GNU/Linux" ) ||
3009+ platformEmulator .startsWith ("FreeBSD 10" ) || platformEmulator .startsWith ("Oracle" ) || platformEmulator .startsWith ("Other PV" )) {
3010+ return DiskDef .DiskBus .VIRTIO ;
29973011 } else {
29983012 return DiskDef .DiskBus .IDE ;
29993013 }
3000- }
30013014
3015+ }
30023016 private void cleanupVMNetworks (final Connect conn , final List <InterfaceDef > nics ) {
30033017 if (nics != null ) {
30043018 for (final InterfaceDef nic : nics ) {
0 commit comments