Skip to content

Commit 098c548

Browse files
committed
Merge pull request xapi-project#2539 from sharady/CA-187691
CA-187691: VBD plug must fail under certain VM Lifecycle operations
2 parents cf58e3e + 8f8acab commit 098c548

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-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

ocaml/xapi/xapi_vif_helpers.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ let valid_operations ~__context record _ref' : table =
6565
let expected = Record_util.power_to_string `Running in
6666
set_errors Api_errors.vm_bad_power_state [ Ref.string_of vm; expected; actual ] [ `plug; `unplug ]);
6767

68+
(* VIF plug/unplug must fail for current_operations
69+
* like [clean_shutdown; hard_shutdown; suspend; pause] on VM *)
70+
let vm_current_ops = Db.VM.get_current_operations ~__context ~self:vm in
71+
List.iter (fun (task,op) ->
72+
if List.mem op [ `clean_shutdown; `hard_shutdown; `suspend; `pause ] then begin
73+
let current_op_str = "Current operation on VM:" ^ (Ref.string_of vm) ^ " is "
74+
^ (Record_util.vm_operation_to_string op) in
75+
set_errors Api_errors.operation_not_allowed [ current_op_str ] [ `plug; `unplug ]
76+
end
77+
) vm_current_ops;
78+
6879
(* HVM guests only support plug/unplug IF they have PV drivers *)
6980
let vm_gm = Db.VM.get_guest_metrics ~__context ~self:vm in
7081
let vm_gmr = try Some (Db.VM_guest_metrics.get_record_internal ~__context ~self:vm_gm) with _ -> None in

0 commit comments

Comments
 (0)