@@ -572,48 +572,43 @@ module Bridge = struct
572572 | Bridge -> Sysfs. get_all_bridges ()
573573 ) ()
574574
575- let destroy_existing_vlan_bridge name (parent , vlan ) =
576- begin match ! backend_kind with
577- | Openvswitch ->
578- let bridges =
579- let raw = Ovs. vsctl [" --bare" ; " -f" ; " table" ; " --" ; " --columns=name" ; " find" ; " port" ; " fake_bridge=true" ; " tag=" ^ (string_of_int vlan)] in
580- if raw <> " " then Astring.String. cuts ~empty: false ~sep: " \n " (String. trim raw) else []
581- in
582- let existing_bridges =
583- List. filter ( fun bridge ->
584- match Ovs. bridge_to_vlan bridge with
585- | Some (p , v ) -> p = parent && v = vlan
586- | None -> false
587- ) bridges in
588- List. iter (fun bridge ->
589- if bridge <> name then begin
590- debug " Destroying existing bridge %s" bridge;
591- remove_config bridge;
592- ignore (Ovs. destroy_bridge bridge)
593- end
594- ) existing_bridges
595- | Bridge ->
596- let ifaces = Sysfs. bridge_to_interfaces parent in
597- let existing_bridges =
598- match List. filter (fun (_ , tag , iface ) -> tag = vlan && List. mem iface ifaces) (Proc. get_vlans () ) with
599- | [] -> []
600- | (vlan_iface , _ , _ ) :: _ ->
601- List. filter (fun bridge ->
602- List. mem vlan_iface (Sysfs. bridge_to_interfaces bridge)
603- ) (Sysfs. get_all_bridges () )
604- in
605- List. iter (fun bridge ->
606- if bridge <> name then begin
607- debug " Destroying existing bridge %s" bridge;
608- Interface. bring_down " Destroying existing bridge" bridge;
609- remove_config bridge;
610- List. iter (fun dev ->
611- Brctl. destroy_port bridge dev;
612- ) (Sysfs. bridge_to_interfaces bridge);
613- ignore (Brctl. destroy_bridge bridge)
614- end
615- ) existing_bridges
616- end
575+ (* Destroy any existing OVS bridge that isn't the "wanted bridge" and has the
576+ * given VLAN on it. *)
577+ let destroy_existing_vlan_ovs_bridge wanted_bridge (parent , vlan ) =
578+ let vlan_bridges =
579+ let raw = Ovs. vsctl [" --bare" ; " -f" ; " table" ; " --" ; " --columns=name" ; " find" ; " port" ; " fake_bridge=true" ; " tag=" ^ (string_of_int vlan)] in
580+ if raw <> " " then Astring.String. cuts ~empty: false ~sep: " \n " (String. trim raw) else []
581+ in
582+ let existing_bridges =
583+ List. filter ( fun bridge ->
584+ match Ovs. bridge_to_vlan bridge with
585+ | Some (p , v ) -> p = parent && v = vlan
586+ | None -> false
587+ ) vlan_bridges in
588+ List. iter (fun bridge ->
589+ if bridge <> wanted_bridge then begin
590+ debug " Destroying existing bridge %s" bridge;
591+ remove_config bridge;
592+ ignore (Ovs. destroy_bridge bridge)
593+ end
594+ ) existing_bridges
595+
596+ (* Destroy any existing Linux bridge that isn't the "wanted bridge" and has the
597+ * given VLAN on it. *)
598+ let destroy_existing_vlan_linux_bridge dbg wanted_bridge vlan_device =
599+ List. iter (fun bridge ->
600+ if bridge <> wanted_bridge then
601+ let ifaces_on_bridge = Sysfs. bridge_to_interfaces bridge in
602+ if List. mem vlan_device ifaces_on_bridge then begin
603+ debug " Destroying existing bridge %s" bridge;
604+ Interface. bring_down dbg bridge;
605+ remove_config bridge;
606+ List. iter (fun dev ->
607+ Brctl. destroy_port bridge dev;
608+ ) ifaces_on_bridge;
609+ ignore (Brctl. destroy_bridge bridge)
610+ end
611+ ) (Sysfs. get_all_bridges () )
617612
618613 let create dbg vlan mac igmp_snooping other_config name =
619614 Debug. with_thread_associated dbg (fun () ->
@@ -624,7 +619,6 @@ module Bridge = struct
624619 | None -> " "
625620 | Some (parent , vlan ) -> Printf. sprintf " (VLAN %d on bridge %s)" vlan parent
626621 );
627- Xapi_stdext_monadic.Opt. iter (destroy_existing_vlan_bridge name) vlan;
628622 update_config name {(get_config name) with vlan; bridge_mac= mac; igmp_snooping; other_config};
629623 begin match ! backend_kind with
630624 | Openvswitch ->
@@ -668,6 +662,7 @@ module Bridge = struct
668662 None )
669663 in
670664 let old_igmp_snooping = Ovs. get_mcast_snooping_enable ~name in
665+ Xapi_stdext_monadic.Opt. iter (destroy_existing_vlan_ovs_bridge name) vlan;
671666 ignore (Ovs. create_bridge ?mac ~fail_mode ?external_id ?disable_in_band ?igmp_snooping
672667 vlan vlan_bug_workaround name);
673668 if igmp_snooping = Some true && not old_igmp_snooping then
@@ -696,6 +691,7 @@ module Bridge = struct
696691 parent_bridge_interface
697692 in
698693 let vlan_name = Ip. vlan_name parent_interface vlan in
694+ destroy_existing_vlan_linux_bridge dbg name vlan_name;
699695 (* Check if the VLAN is already in use by something else *)
700696 List. iter (fun (device , vlan' , parent' ) ->
701697 (* A device for the same VLAN (parent + tag), but with a different
0 commit comments