Skip to content

Commit 77284fd

Browse files
committed
fixup! CP-44103: Ordering network devices - ordering logic
Signed-off-by: Ming Lu <[email protected]>
1 parent 79254e5 commit 77284fd

File tree

2 files changed

+32
-40
lines changed

2 files changed

+32
-40
lines changed

ocaml/networkd/lib/network_device_order.ml

+31-37
Original file line numberDiff line numberDiff line change
@@ -487,40 +487,34 @@ let generate_order ~(currents : Dev.t list) ~(rules : Rule.t list)
487487
OrderedDev.assert_no_duplicate_mac new_order ;
488488
new_order
489489

490-
let generate ?(force = false) interface_order =
491-
match interface_order with
492-
| None ->
493-
None
494-
| Some last_order ->
495-
let rules, last_order =
496-
match (last_order, force) with
497-
| [], _ | _ :: _, true ->
498-
(Rule.rules_of_file ~path:initial_rules_file_path, [])
499-
| (_ :: _ as last_order), false ->
500-
([], last_order)
501-
in
502-
let currents = Dev.get_all () in
503-
currents
504-
|> List.iter (fun x ->
505-
debug "%s current: %s" __FUNCTION__ (Dev.to_string x)
506-
) ;
507-
let new_order = generate_order ~currents ~rules ~last_order in
508-
new_order
509-
|> List.iter (fun x ->
510-
debug "%s new order: %s" __FUNCTION__ (OrderedDev.to_string x)
511-
) ;
512-
513-
(* Find the NICs whose name changes *)
514-
let changes =
515-
let m = OrderedDev.map_by_position last_order in
516-
List.fold_left
517-
(fun acc {position; name= curr; _} ->
518-
match IntMap.find_opt position m with
519-
| Some {name= last; _} when last <> curr ->
520-
(last, curr) :: acc
521-
| _ ->
522-
acc
523-
)
524-
[] new_order
525-
in
526-
Some (new_order, changes)
490+
let generate ?(force = false) last_order =
491+
let rules, last_order =
492+
match (last_order, force) with
493+
| [], _ | _ :: _, true ->
494+
(Rule.rules_of_file ~path:initial_rules_file_path, [])
495+
| (_ :: _ as last_order), false ->
496+
([], last_order)
497+
in
498+
let currents = Dev.get_all () in
499+
currents
500+
|> List.iter (fun x -> debug "%s current: %s" __FUNCTION__ (Dev.to_string x)) ;
501+
let new_order = generate_order ~currents ~rules ~last_order in
502+
new_order
503+
|> List.iter (fun x ->
504+
debug "%s new order: %s" __FUNCTION__ (OrderedDev.to_string x)
505+
) ;
506+
507+
(* Find the NICs whose name changes *)
508+
let changes =
509+
let m = OrderedDev.map_by_position last_order in
510+
List.fold_left
511+
(fun acc {position; name= curr; _} ->
512+
match IntMap.find_opt position m with
513+
| Some {name= last; _} when last <> curr ->
514+
(last, curr) :: acc
515+
| _ ->
516+
acc
517+
)
518+
[] new_order
519+
in
520+
(new_order, changes)

ocaml/networkd/lib/network_device_order.mli

+1-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ module OrderedDev : sig
7777
end
7878

7979
val generate :
80-
?force:bool
81-
-> OrderedDev.t list option
82-
-> (OrderedDev.t list * (string * string) list) option
80+
?force:bool -> OrderedDev.t list -> OrderedDev.t list * (string * string) list
8381
(** [generate force ()] is to generate order, return the order and a list for device name changes (old_name, new_name).
8482
When the [force] is [true], use the initial rules only. By default it is [false]. *)
8583

0 commit comments

Comments
 (0)