From 41904cc217f0b0eae65e22eb1c60a62ae59a82d6 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Fri, 5 Aug 2022 12:17:48 +0800 Subject: [PATCH] fix(region): use virtio replace ide on diskattach If disk driver not assign, default use previous disk driver. Bus windows server can't recognize hot attached 'ide' disk, use 'virtio' replace 'ide' driver on diskattach. Signed-off-by: wanyaoqi --- pkg/apis/compute/disk_const.go | 8 ++++++++ pkg/compute/models/guests.go | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/apis/compute/disk_const.go b/pkg/apis/compute/disk_const.go index 506dd25217..0b92c53405 100644 --- a/pkg/apis/compute/disk_const.go +++ b/pkg/apis/compute/disk_const.go @@ -65,3 +65,11 @@ const ( ) const DISK_META_EXISTING_PATH = "disk_existing_path" + +const ( + DISK_DRIVER_VIRTIO = "virtio" + DISK_DRIVER_SCSI = "scsi" + DISK_DRIVER_PVSCSI = "pvscsi" + DISK_DRIVER_IDE = "ide" + DISK_DRIVER_SATA = "sata" +) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 6edfd1f233..529f4cfa97 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -3376,7 +3376,12 @@ func (self *SGuest) attach2Disk(ctx context.Context, disk *SDisk, userCred mccli // depends the last disk of this guest existingDisks, _ := self.GetGuestDisks() if len(existingDisks) > 0 { - driver = existingDisks[len(existingDisks)-1].Driver + prevDisk := existingDisks[len(existingDisks)-1] + if prevDisk.Driver == api.DISK_DRIVER_IDE { + driver = api.DISK_DRIVER_VIRTIO + } else { + driver = prevDisk.Driver + } } else { osProf := self.GetOSProfile() driver = osProf.DiskDriver