Skip to content

Commit 043b62f

Browse files
committed
CA-187691: VBD plug/unplug must fail under certain VM Lifecycle operations
VBD plug/unplug must fail gracefully when VM undergoing operations like clean_shutdown, hard_shutdown, pause and suspend. Signed-off-by: Sharad Yadav <[email protected]>
1 parent 856147c commit 043b62f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ocaml/xapi/xapi_vbd_helpers.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ let valid_operations ~expensive_sharing_checks ~__context record _ref' : table =
116116
let bad_ops' = if power_state = `Paused then bad_ops else `pause :: `unpause :: bad_ops in
117117
set_errors Api_errors.vm_bad_power_state [ Ref.string_of vm; expected; actual ] bad_ops');
118118

119+
(* VBD plug/unplug must fail for current_operations
120+
* like [clean_shutdown; hard_shutdown; suspend; pause] on VM *)
121+
let vm_current_ops = Db.VM.get_current_operations ~__context ~self:vm in
122+
List.iter (fun (task,op) ->
123+
if List.mem op [ `clean_shutdown; `hard_shutdown; `suspend; `pause ] then begin
124+
let current_op_str = "Current operation on VM:" ^ (Ref.string_of vm) ^ " is "
125+
^ (Record_util.vm_operation_to_string op) in
126+
set_errors Api_errors.operation_not_allowed [ current_op_str ] [ `plug; `unplug ]
127+
end
128+
) vm_current_ops;
129+
119130
(* HVM guests only support plug/unplug IF they have PV drivers *)
120131
(* They can only eject/insert CDs not plug/unplug *)
121132
let vm_gm = Db.VM.get_guest_metrics ~__context ~self:vm in

0 commit comments

Comments
 (0)