@@ -54,6 +54,20 @@ let fix_bonds ~__context () =
5454 in
5555 List. iter (fun bond -> Xapi_bond. fix_bond ~__context ~bond ) my_bonds
5656
57+ let get_my_physical_pifs_with_position ~__context =
58+ let me = ! Xapi_globs. localhost_ref in
59+ Db.PIF. get_records_where ~__context
60+ ~expr:
61+ (And
62+ ( Eq (Field " host" , Literal (Ref. string_of me))
63+ , Eq (Field " physical" , Literal " true" )
64+ )
65+ )
66+ |> List. filter_map (fun (pif_ref , pif_rec ) ->
67+ Xapi_pif_helpers. get_pif_position ~__context ~pif_rec
68+ |> Option. map (fun position -> (pif_ref, pif_rec, position))
69+ )
70+
5771(* * Copy Bonds from master *)
5872let copy_bonds_from_master ~__context () =
5973 (* if slave: then inherit network config (bonds and vlans) from master (if we don't already have them) *)
@@ -84,22 +98,8 @@ let copy_bonds_from_master ~__context () =
8498 )
8599 )
86100 in
87- let my_phy_pifs =
88- Db.PIF. get_records_where ~__context
89- ~expr:
90- (And
91- ( Eq (Field " host" , Literal (Ref. string_of me))
92- , Eq (Field " physical" , Literal " true" )
93- )
94- )
95- in
96- let my_phy_pifs_with_position =
97- List. filter_map
98- (fun (pif_ref , pif_rec ) ->
99- Xapi_pif_helpers. get_pif_position ~__context ~pif_rec
100- |> Option. map (fun position -> (pif_ref, pif_rec, position))
101- )
102- my_phy_pifs
101+ let my_physical_pifs_with_position =
102+ get_my_physical_pifs_with_position ~__context
103103 in
104104 (* Consider Bonds *)
105105 debug " Resynchronising bonds" ;
@@ -156,7 +156,7 @@ let copy_bonds_from_master ~__context () =
156156 let my_slave_pifs_with_position =
157157 List. filter
158158 (fun (_ , _ , position ) -> List. mem position slave_positions)
159- my_phy_pifs_with_position
159+ my_physical_pifs_with_position
160160 in
161161 let my_slave_pif_refs =
162162 List. map (fun (pif_ref , _ , _ ) -> pif_ref) my_slave_pifs_with_position
@@ -280,6 +280,7 @@ let copy_tunnels_from_master ~__context () =
280280let copy_network_sriovs_from_master ~__context () =
281281 let me = ! Xapi_globs. localhost_ref in
282282 let master = Helpers. get_master ~__context in
283+ let ( let& ) o f = Option. iter f o in
283284 let master_sriov_pifs =
284285 Db.PIF. get_records_where ~__context
285286 ~expr:
@@ -298,14 +299,8 @@ let copy_network_sriovs_from_master ~__context () =
298299 )
299300 )
300301 in
301- let my_physical_pifs =
302- Db.PIF. get_records_where ~__context
303- ~expr:
304- (And
305- ( Eq (Field " host" , Literal (Ref. string_of me))
306- , Eq (Field " physical" , Literal " true" )
307- )
308- )
302+ let my_physical_pifs_with_position =
303+ get_my_physical_pifs_with_position ~__context
309304 in
310305 debug " Resynchronising network-sriovs" ;
311306 let maybe_create_sriov_for_me (_ , master_pif_rec ) =
@@ -316,20 +311,34 @@ let copy_network_sriovs_from_master ~__context () =
316311 my_sriov_pifs
317312 in
318313 if existing_pif = [] then
319- let device = master_pif_rec.API. pIF_device in
314+ let & master_sriov_physical_pif =
315+ match
316+ Xapi_pif_helpers. get_pif_topo ~__context ~pif_rec: master_pif_rec
317+ with
318+ | Network_sriov_logical _ :: Physical physical_pif :: _ ->
319+ Some physical_pif
320+ | _ ->
321+ None
322+ in
323+ let & position =
324+ Xapi_pif_helpers. get_pif_position ~__context
325+ ~pif_rec: master_sriov_physical_pif
326+ in
320327 let pifs =
321328 List. filter
322- (fun (_ , pif_rec ) -> pif_rec. API. pIF_device = device )
323- my_physical_pifs
329+ (fun (_ , _ , pos ) -> pos = position )
330+ my_physical_pifs_with_position
324331 in
325332 match pifs with
326333 | [] ->
327334 info
328335 " Cannot sync network sriov because cannot find PIF whose device \
329- name is %s "
330- device
331- | (pif_ref , pif_rec ) :: _ -> (
336+ position is %d "
337+ position
338+ | (pif_ref , pif_rec , _ ) :: _ -> (
332339 try
340+ debug " Syncing network sriov for PIF %s position %d"
341+ pif_rec.API. pIF_uuid position ;
333342 Xapi_network_sriov. create ~__context ~pif: pif_ref
334343 ~network: sriov_network
335344 |> ignore
0 commit comments