@@ -33,6 +33,11 @@ type nameKindKey struct {
3333 name string
3434}
3535
36+ type kvvmiDiskInfo struct {
37+ d virtv1.Disk
38+ vs virtv1.VolumeStatus
39+ }
40+
3641// getBlockDeviceStatusRefs returns block device refs to populate .status.blockDeviceRefs of the virtual machine.
3742// If kvvm is present, this method will reflect all volumes with prefixes (vi,vd, or cvi) into the slice of `BlockDeviceStatusRef`.
3843// Block devices from the virtual machine specification will be added to the resulting slice if they have not been included in the previous step.
@@ -74,11 +79,20 @@ func (h *BlockDeviceHandler) getBlockDeviceStatusRefs(ctx context.Context, s sta
7479 return nil , err
7580 }
7681
77- var kvvmiVolumeStatusByName map [string ]virtv1. VolumeStatus
82+ var kvvmiDiskInfoByName map [string ]kvvmiDiskInfo
7883 if kvvmi != nil {
79- kvvmiVolumeStatusByName = make (map [string ]virtv1. VolumeStatus )
84+ kvvmiDiskInfoByName = make (map [string ]kvvmiDiskInfo , len ( kvvmi . Status . VolumeStatus ) )
8085 for _ , vs := range kvvmi .Status .VolumeStatus {
81- kvvmiVolumeStatusByName [vs .Name ] = vs
86+ di := kvvmiDiskInfo {
87+ vs : vs ,
88+ }
89+ for _ , d := range kvvmi .Spec .Domain .Devices .Disks {
90+ if d .Name == vs .Name {
91+ di .d = d
92+ break
93+ }
94+ }
95+ kvvmiDiskInfoByName [vs .Name ] = di
8296 }
8397 }
8498
@@ -96,13 +110,17 @@ func (h *BlockDeviceHandler) getBlockDeviceStatusRefs(ctx context.Context, s sta
96110 key := nameKindKey {kind : kind , name : bdName }
97111
98112 ref := h .getBlockDeviceStatusRef (kind , bdName )
99- _ , ref .Attached = h .getBlockDeviceTarget (volume , kvvmiVolumeStatusByName )
113+ _ , ref .Attached = h .getBlockDeviceTarget (volume , kvvmiDiskInfoByName )
100114 ref .Size , err = h .getBlockDeviceRefSize (ctx , ref , s )
101115 if err != nil {
102116 return nil , err
103117 }
118+ bootOrder := h .getBlockDeviceBootOrder (volume , kvvmiDiskInfoByName )
119+ if bootOrder != nil {
120+ ref .BootOrder = bootOrder
121+ }
104122
105- ref .Hotplugged = h .isHotplugged (volume , kvvmiVolumeStatusByName )
123+ ref .Hotplugged = h .isHotplugged (volume , kvvmiDiskInfoByName )
106124 if ref .Hotplugged {
107125 _ , isSpecDevice := specDevices [key ]
108126 if ! isSpecDevice {
@@ -188,15 +206,15 @@ func (h *BlockDeviceHandler) getBlockDeviceRefSize(ctx context.Context, ref v1al
188206 return "" , nil
189207}
190208
191- func (h * BlockDeviceHandler ) getBlockDeviceTarget (volume virtv1.Volume , kvvmiVolumeStatusByName map [string ]virtv1. VolumeStatus ) (string , bool ) {
192- vs , ok := kvvmiVolumeStatusByName [volume .Name ]
193- return vs .Target , ok
209+ func (h * BlockDeviceHandler ) getBlockDeviceTarget (volume virtv1.Volume , kvvmiDiskInfoByName map [string ]kvvmiDiskInfo ) (string , bool ) {
210+ di , ok := kvvmiDiskInfoByName [volume .Name ]
211+ return di . vs .Target , ok
194212}
195213
196- func (h * BlockDeviceHandler ) isHotplugged (volume virtv1.Volume , kvvmiVolumeStatusByName map [string ]virtv1. VolumeStatus ) bool {
214+ func (h * BlockDeviceHandler ) isHotplugged (volume virtv1.Volume , kvvmiDiskInfoByName map [string ]kvvmiDiskInfo ) bool {
197215 switch {
198216 // 1. If kvvmi has volume status with hotplugVolume reference then it's 100% hot-plugged volume.
199- case kvvmiVolumeStatusByName [volume .Name ].HotplugVolume != nil :
217+ case kvvmiDiskInfoByName [volume .Name ]. vs .HotplugVolume != nil :
200218 return true
201219
202220 // 2. If kvvm has volume with hot-pluggable pvc reference then it's 100% hot-plugged volume.
@@ -236,3 +254,11 @@ func (h *BlockDeviceHandler) getBlockDeviceAttachmentName(ctx context.Context, k
236254
237255 return vmbdas [0 ].Name , nil
238256}
257+
258+ func (h * BlockDeviceHandler ) getBlockDeviceBootOrder (volume virtv1.Volume , kvvmiDiskInfoByName map [string ]kvvmiDiskInfo ) * uint {
259+ di , ok := kvvmiDiskInfoByName [volume .Name ]
260+ if ok {
261+ return di .d .BootOrder
262+ }
263+ return nil
264+ }
0 commit comments