diff --git a/ocaml/xapi/xapi_vbd_helpers.ml b/ocaml/xapi/xapi_vbd_helpers.ml index 3d1a9fa4580..0ed6dc96106 100644 --- a/ocaml/xapi/xapi_vbd_helpers.ml +++ b/ocaml/xapi/xapi_vbd_helpers.ml @@ -116,6 +116,17 @@ let valid_operations ~expensive_sharing_checks ~__context record _ref' : table = let bad_ops' = if power_state = `Paused then bad_ops else `pause :: `unpause :: bad_ops in set_errors Api_errors.vm_bad_power_state [ Ref.string_of vm; expected; actual ] bad_ops'); + (* VBD plug/unplug must fail for current_operations + * like [clean_shutdown; hard_shutdown; suspend; pause] on VM *) + let vm_current_ops = Db.VM.get_current_operations ~__context ~self:vm in + List.iter (fun (task,op) -> + if List.mem op [ `clean_shutdown; `hard_shutdown; `suspend; `pause ] then begin + let current_op_str = "Current operation on VM:" ^ (Ref.string_of vm) ^ " is " + ^ (Record_util.vm_operation_to_string op) in + set_errors Api_errors.operation_not_allowed [ current_op_str ] [ `plug; `unplug ] + end + ) vm_current_ops; + (* HVM guests only support plug/unplug IF they have PV drivers *) (* They can only eject/insert CDs not plug/unplug *) let vm_gm = Db.VM.get_guest_metrics ~__context ~self:vm in diff --git a/ocaml/xapi/xapi_vif_helpers.ml b/ocaml/xapi/xapi_vif_helpers.ml index d08e7fa8da4..cbaaa77ad88 100644 --- a/ocaml/xapi/xapi_vif_helpers.ml +++ b/ocaml/xapi/xapi_vif_helpers.ml @@ -65,6 +65,17 @@ let valid_operations ~__context record _ref' : table = let expected = Record_util.power_to_string `Running in set_errors Api_errors.vm_bad_power_state [ Ref.string_of vm; expected; actual ] [ `plug; `unplug ]); + (* VIF plug/unplug must fail for current_operations + * like [clean_shutdown; hard_shutdown; suspend; pause] on VM *) + let vm_current_ops = Db.VM.get_current_operations ~__context ~self:vm in + List.iter (fun (task,op) -> + if List.mem op [ `clean_shutdown; `hard_shutdown; `suspend; `pause ] then begin + let current_op_str = "Current operation on VM:" ^ (Ref.string_of vm) ^ " is " + ^ (Record_util.vm_operation_to_string op) in + set_errors Api_errors.operation_not_allowed [ current_op_str ] [ `plug; `unplug ] + end + ) vm_current_ops; + (* HVM guests only support plug/unplug IF they have PV drivers *) let vm_gm = Db.VM.get_guest_metrics ~__context ~self:vm in let vm_gmr = try Some (Db.VM_guest_metrics.get_record_internal ~__context ~self:vm_gm) with _ -> None in