@@ -338,7 +338,7 @@ type operation =
338
338
| VM_suspend of (Vm .id * data )
339
339
| VM_resume of (Vm .id * data )
340
340
| VM_restore_vifs of Vm .id
341
- | VM_restore_devices of (Vm .id * bool )
341
+ | VM_restore_devices of (Vm .id * bool * bool )
342
342
| VM_migrate of vm_migrate_op
343
343
| VM_receive_memory of vm_receive_op
344
344
| VBD_hotplug of Vbd .id
@@ -1763,7 +1763,7 @@ let rec atomics_of_operation = function
1763
1763
serial " VIF.activate_and_plug" ~id
1764
1764
[VIF_set_active (vif.Vif. id, true ); VIF_plug vif.Vif. id]
1765
1765
)
1766
- | VM_restore_devices (id , restore_vifs ) ->
1766
+ | VM_restore_devices (id , restore_vifs , migration ) ->
1767
1767
let vbds_rw, vbds_ro = VBD_DB. vbds id |> vbd_plug_sets in
1768
1768
let vgpus = VGPU_DB. vgpus id in
1769
1769
let pcis = PCI_DB. pcis id |> pci_plug_order in
@@ -1777,10 +1777,23 @@ let rec atomics_of_operation = function
1777
1777
[VBD_set_active (vbd.Vbd. id, true ); vbd_plug vbd.Vbd. id]
1778
1778
)
1779
1779
in
1780
+ let activate_vbds typ vbds =
1781
+ let name_multi = Printf. sprintf " VBDs.activate %s" typ in
1782
+ parallel name_multi ~id
1783
+ (List. map (fun vbd -> VBD_activate vbd.Vbd. id) vbds)
1784
+ in
1785
+ let prep_vbds =
1786
+ if ! xenopsd_vbd_plug_unplug_legacy || not migration then
1787
+ plug_vbds
1788
+ else
1789
+ (* If plug is split into activate and attach, when migrating we don't
1790
+ need to attach here as we attached outside of the VM downtime *)
1791
+ activate_vbds
1792
+ in
1780
1793
[
1781
1794
(* rw vbds must be plugged before ro vbds, see vbd_plug_sets *)
1782
- plug_vbds " RW" vbds_rw
1783
- ; plug_vbds " RO" vbds_ro
1795
+ prep_vbds " RW" vbds_rw
1796
+ ; prep_vbds " RO" vbds_ro
1784
1797
; (if restore_vifs then atomics_of_operation (VM_restore_vifs id) else [] )
1785
1798
; (* Nvidia SRIOV PCI devices have been already been plugged *)
1786
1799
parallel_map " VGPUs.activate" ~id vgpus (fun vgpu ->
@@ -1897,7 +1910,7 @@ let rec atomics_of_operation = function
1897
1910
]
1898
1911
; vgpu_start_operations
1899
1912
; [VM_restore (id, data, vgpu_data)]
1900
- ; atomics_of_operation (VM_restore_devices (id, true ))
1913
+ ; atomics_of_operation (VM_restore_devices (id, true , false ))
1901
1914
; [
1902
1915
(* At this point the domain is considered survivable. *)
1903
1916
VM_set_domain_action_request (id, None )
@@ -2573,7 +2586,7 @@ and trigger_cleanup_after_failure op t =
2573
2586
| VM_shutdown (id, _)
2574
2587
| VM_suspend (id, _)
2575
2588
| VM_restore_vifs id
2576
- | VM_restore_devices (id, _)
2589
+ | VM_restore_devices (id, _, _ )
2577
2590
| VM_resume (id , _ ) ->
2578
2591
immediate_operation dbg id (VM_check_state id)
2579
2592
| VM_receive_memory {vmr_id = id ; vmr_final_id = final_id ; _} ->
@@ -2696,9 +2709,9 @@ and perform_exn ?result (op : operation) (t : Xenops_task.task_handle) : unit =
2696
2709
| VM_restore_vifs id ->
2697
2710
debug " VM_restore_vifs %s" id ;
2698
2711
perform_atomics (atomics_of_operation op) t
2699
- | VM_restore_devices (id , restore_vifs ) ->
2712
+ | VM_restore_devices (id , restore_vifs , migration ) ->
2700
2713
(* XXX: this is delayed due to the 'attach'/'activate' behaviour *)
2701
- debug " VM_restore_devices %s %b" id restore_vifs ;
2714
+ debug " VM_restore_devices %s %b %b " id restore_vifs migration ;
2702
2715
perform_atomics (atomics_of_operation op) t
2703
2716
| VM_resume (id , _data ) ->
2704
2717
debug " VM.resume %s" id ;
@@ -3022,11 +3035,27 @@ and perform_exn ?result (op : operation) (t : Xenops_task.task_handle) : unit =
3022
3035
( try
3023
3036
let no_sharept = VGPU_DB. vgpus id |> List. exists is_no_sharept in
3024
3037
debug " VM %s no_sharept=%b (%s)" id no_sharept __LOC__ ;
3038
+ let early_attach =
3039
+ if ! xenopsd_vbd_plug_unplug_legacy then
3040
+ []
3041
+ else
3042
+ (* If plug is split into activate and attach, we can attach
3043
+ early so that it is outside of the VM downtime *)
3044
+ parallel_map " VBDs.set_active_and_attach" ~id (VBD_DB. vbds id)
3045
+ (fun vbd ->
3046
+ serial " VBD.set_active_and_attach" ~id
3047
+ [
3048
+ VBD_set_active (vbd.Vbd. id, true )
3049
+ ; VBD_attach vbd.Vbd. id
3050
+ ]
3051
+ )
3052
+ in
3025
3053
perform_atomics
3026
3054
([VM_create (id, Some memory_limit, Some final_id, no_sharept)]
3027
- @ (* Perform as many operations as possible on the destination
3028
- domain before pausing the original domain *)
3029
- atomics_of_operation (VM_restore_vifs id)
3055
+ (* Perform as many operations as possible on the destination
3056
+ domain before pausing the original domain *)
3057
+ @ atomics_of_operation (VM_restore_vifs id)
3058
+ @ early_attach
3030
3059
)
3031
3060
t ;
3032
3061
Handshake. send s Handshake. Success
@@ -3142,7 +3171,7 @@ and perform_exn ?result (op : operation) (t : Xenops_task.task_handle) : unit =
3142
3171
) ;
3143
3172
debug " VM.receive_memory: restoring remaining devices and unpausing" ;
3144
3173
perform_atomics
3145
- (atomics_of_operation (VM_restore_devices (final_id, false ))
3174
+ (atomics_of_operation (VM_restore_devices (final_id, false , true ))
3146
3175
@ [
3147
3176
VM_unpause final_id
3148
3177
; VM_set_domain_action_request (final_id, None )
0 commit comments