Skip to content

Commit df72218

Browse files
thomassarobhoes
authored andcommitted
CP-18658: xenopsd tells us PVS_proxy.currently_attached
Instead of setting PVS_proxy.currently_attached to true proactively after setting up the site, now we set it to the value sent by xenopsd as part of an update to the VIF state. In turn, xenopsd watches xenstore for a node which is created or deleted after the OVS rules for the PVS proxy have been set up or removed, respectively. Signed-off-by: Thomas Sanders <[email protected]>
1 parent e9a2a53 commit df72218

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

ocaml/xapi/pvs_proxy_control.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ let start_proxy ~__context vif proxy =
124124
let site = Db.PVS_proxy.get_site ~__context ~self:proxy in
125125
let sr, vdi = Xapi_pvs_cache.find_or_create_cache_vdi ~__context ~host ~site in
126126
update_site_on_localhost ~__context ~site ~vdi ~starting_proxies:[vif, proxy] ();
127-
Db.PVS_proxy.set_currently_attached ~__context ~self:proxy ~value:true;
128-
Db.PVS_proxy.set_cache_SR ~__context ~self:proxy ~value:sr
127+
Db.PVS_proxy.set_cache_SR ~__context ~self:proxy ~value:sr;
128+
true
129129
with e ->
130130
let reason =
131131
match e with
@@ -154,7 +154,8 @@ let start_proxy ~__context vif proxy =
154154
"PVS proxy not licensed"
155155
| _ -> Printf.sprintf "unknown error (%s)" (Printexc.to_string e)
156156
in
157-
warn "Unable to enable PVS proxy for VIF %s: %s. Continuing with proxy unattached." (Ref.string_of vif) reason
157+
warn "Unable to enable PVS proxy for VIF %s: %s. Continuing with proxy unattached." (Ref.string_of vif) reason;
158+
false
158159

159160
let stop_proxy ~__context vif proxy =
160161
if Db.PVS_proxy.get_currently_attached ~__context ~self:proxy then begin
@@ -163,7 +164,6 @@ let stop_proxy ~__context vif proxy =
163164
let sr = Db.PVS_proxy.get_cache_SR ~__context ~self:proxy in
164165
let vdi = Xapi_pvs_cache.find_cache_vdi ~__context ~sr in
165166
update_site_on_localhost ~__context ~site ~vdi ~stopping_proxies:[vif, proxy] ();
166-
Db.PVS_proxy.set_currently_attached ~__context ~self:proxy ~value:false;
167167
Db.PVS_proxy.set_cache_SR ~__context ~self:proxy ~value:Ref.null
168168
with e ->
169169
let reason =
@@ -183,9 +183,10 @@ let find_proxy_for_vif ~__context ~vif =
183183
| [] -> None
184184
| proxy :: _ -> Some proxy
185185

186+
(* Called on VM start *)
186187
let maybe_start_proxy_for_vif ~__context ~vif =
187188
Opt.iter
188-
(start_proxy ~__context vif)
189+
(fun p -> start_proxy ~__context vif p |> ignore)
189190
(find_proxy_for_vif ~__context ~vif)
190191

191192
let maybe_stop_proxy_for_vif ~__context ~vif =

ocaml/xapi/pvs_proxy_control.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
val proxy_port_name : string -> string
1616
val get_running_proxies : __context:Context.t -> site:API.ref_PVS_site -> API.ref_PVS_proxy list
1717

18-
val start_proxy : __context:Context.t -> API.ref_VIF -> API.ref_PVS_proxy -> unit
18+
val start_proxy : __context:Context.t -> API.ref_VIF -> API.ref_PVS_proxy -> bool
1919
val stop_proxy : __context:Context.t -> API.ref_VIF -> API.ref_PVS_proxy -> unit
2020

2121
val find_proxy_for_vif : __context:Context.t -> vif:API.ref_VIF -> API.ref_PVS_proxy option

ocaml/xapi/xapi_pvs_proxy.ml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ let create ~__context ~site ~vIF ~prepopulate =
3838
Db.PVS_proxy.create ~__context
3939
~ref:pvs_proxy ~uuid ~site ~vIF ~prepopulate ~currently_attached:false ~cache_SR:Ref.null;
4040
if Db.VIF.get_currently_attached ~__context ~self:vIF then begin
41-
Pvs_proxy_control.start_proxy ~__context vIF pvs_proxy;
42-
if Db.PVS_proxy.get_currently_attached ~__context ~self:pvs_proxy then
41+
if Pvs_proxy_control.start_proxy ~__context vIF pvs_proxy then
4342
try
43+
(* This will cause Pvs_proxy.currently_attached to become true. *)
4444
Xapi_xenops.vif_set_pvs_proxy ~__context ~self:vIF true
45-
with e ->
46-
let body = Printf.sprintf "Failed to setup PVS-proxy %s for VIF %s due to an internal error"
47-
uuid (Db.VIF.get_uuid ~__context ~self:vIF) in
48-
let (name, priority) = Api_messages.pvs_proxy_setup_failed in
49-
Helpers.call_api_functions ~__context (fun rpc session_id ->
50-
ignore(Client.Client.Message.create ~rpc ~session_id ~name ~priority ~cls:`PVS_proxy ~obj_uuid:uuid ~body));
51-
error "Unable to setup PVS proxy for vif %s: %s." (Ref.string_of vIF) (ExnHelper.string_of_exn e)
45+
with e -> (
46+
let body = Printf.sprintf "Failed to setup PVS-proxy %s for VIF %s due to an internal error"
47+
uuid (Db.VIF.get_uuid ~__context ~self:vIF) in
48+
let (name, priority) = Api_messages.pvs_proxy_setup_failed in
49+
Helpers.call_api_functions ~__context (fun rpc session_id ->
50+
ignore(Client.Client.Message.create ~rpc ~session_id ~name ~priority ~cls:`PVS_proxy ~obj_uuid:uuid ~body));
51+
error "Unable to setup PVS proxy for vif %s: %s." (Ref.string_of vIF) (ExnHelper.string_of_exn e)
52+
)
5253
end;
5354
pvs_proxy
5455

@@ -64,6 +65,6 @@ let set_prepopulate ~__context ~self ~value =
6465
Db.PVS_proxy.set_prepopulate ~__context ~self ~value;
6566
if Db.PVS_proxy.get_currently_attached ~__context ~self then begin
6667
let vif = Db.PVS_proxy.get_VIF ~__context ~self in
67-
Pvs_proxy_control.start_proxy ~__context vif self
68+
Pvs_proxy_control.start_proxy ~__context vif self |> ignore
6869
end
6970

ocaml/xapi/xapi_xenops.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,12 @@ let update_vif ~__context id =
16931693
Monitor_dbcalls_cache.clear_cache_for_pif ~pif_name
16941694
) pifs
16951695
end;
1696+
(match Pvs_proxy_control.find_proxy_for_vif ~__context ~vif with
1697+
| None -> ()
1698+
| Some proxy ->
1699+
debug "xenopsd event: Updating PVS_proxy for VIF %s.%s currently_attached <- %b" (fst id) (snd id) state.pvs_rules_active;
1700+
Db.PVS_proxy.set_currently_attached ~__context ~self:proxy ~value:state.pvs_rules_active
1701+
);
16961702
debug "xenopsd event: Updating VIF %s.%s currently_attached <- %b" (fst id) (snd id) (state.plugged || state.active);
16971703
Db.VIF.set_currently_attached ~__context ~self:vif ~value:(state.plugged || state.active)
16981704
) info;

0 commit comments

Comments
 (0)