Skip to content

xapi_xenops: Avoid a race during suspend #6454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions ocaml/xapi/xapi_xenops.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2049,18 +2049,10 @@ let update_vm ~__context id =
) ;
debug "xenopsd event: Updating VM %s power_state <- %s" id
(Record_util.vm_power_state_to_string power_state) ;
(* This will mark VBDs, VIFs as detached and clear resident_on
if the VM has permanently shutdown. current-operations
should not be reset as there maybe a checkpoint is ongoing*)
Xapi_vm_lifecycle.force_state_reset_keep_current_operations
~__context ~self ~value:power_state ;
if power_state = `Running then create_guest_metrics_if_needed () ;
if power_state = `Suspended || power_state = `Halted then (
Xapi_network.detach_for_vm ~__context ~host:localhost ~vm:self ;
Storage_access.reset ~__context ~vm:self
) ;
if power_state = `Halted then
Xenopsd_metadata.delete ~__context id ;

(* NOTE: Pull xenopsd metadata as soon as possible so that
nothing comes inbetween the power state change and the
Xenopsd_metadata.pull and overwrites it. *)
( if power_state = `Suspended then
let md = Xenopsd_metadata.pull ~__context id in
match md.Metadata.domains with
Expand All @@ -2071,8 +2063,22 @@ let update_vm ~__context id =
debug "VM %s last_booted_record set to %s"
(Ref.string_of self) x
) ;
if power_state = `Halted then

(* This will mark VBDs, VIFs as detached and clear resident_on
if the VM has permanently shutdown. current-operations
should not be reset as there maybe a checkpoint is ongoing*)
Xapi_vm_lifecycle.force_state_reset_keep_current_operations
~__context ~self ~value:power_state ;
if power_state = `Running then
create_guest_metrics_if_needed () ;
if power_state = `Suspended || power_state = `Halted then (
Xapi_network.detach_for_vm ~__context ~host:localhost ~vm:self ;
Storage_access.reset ~__context ~vm:self
) ;
if power_state = `Halted then (
Xenopsd_metadata.delete ~__context id ;
!trigger_xenapi_reregister ()
)
with e ->
error "Caught %s: while updating VM %s power_state"
(Printexc.to_string e) id
Expand Down
Loading