Skip to content

Commit d95662a

Browse files
committed
Fixup: add print to show potential mismatch in networkd
For the situation if a db pif device's position is not in the position list but can get mac for networkd. There is a mismatch between networkd sort function and dev filesys method. Signed-off-by: Changlei Li <[email protected]>
1 parent e1126c1 commit d95662a

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

ocaml/xapi/xapi_pif.ml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,43 @@ let refresh_internal ~__context ~interface_tables ~self =
105105
else
106106
pif.API.pIF_network
107107
in
108+
let find_name_by_position position original_name =
109+
match
110+
List.find_map
111+
(fun (name, pos) -> if pos = position then Some name else None)
112+
interface_tables.device_to_position_table
113+
with
114+
| Some name ->
115+
if name <> original_name then
116+
info "PIF: device name changed from %s to %s" original_name name ;
117+
name
118+
| None -> (
119+
(* This clause should be unlike to happen, if enter this, check the if
120+
we can get mac from networkd. If yes there may be a bug *)
121+
warn "PIF %s: no device found for position %d" original_name position ;
122+
try
123+
let mac = Net.Interface.get_mac dbg original_name in
124+
error
125+
"PIF %s: no device found for position %d, but get MAC address %s , \
126+
there may be a bug in networkd sorting."
127+
original_name position mac ;
128+
original_name
129+
with _ -> original_name
130+
)
131+
in
108132
let bridge = Db.Network.get_bridge ~__context ~self:network in
109133
(* Pif device name maybe change. Look up device_to_position table to get the
110134
new device name. *)
111135
let pif_device_name =
112-
Option.bind (n_of_xenbrn_opt bridge) (fun position ->
113-
List.find_map
114-
(fun (name, pos) -> if pos = position then Some name else None)
115-
interface_tables.device_to_position_table
116-
)
117-
|> Option.value ~default:pif.API.pIF_device
136+
if pif.API.pIF_physical then (
137+
match n_of_xenbrn_opt bridge with
138+
| Some position ->
139+
find_name_by_position position pif.API.pIF_device
140+
| None ->
141+
info "PIF %s: no position found for this device" pif.API.pIF_device ;
142+
pif.API.pIF_device
143+
) else
144+
pif.API.pIF_device
118145
in
119146
(* Update the specified PIF field in the database, if
120147
* and only if a corresponding value can be read from

0 commit comments

Comments
 (0)