Skip to content

Commit

Permalink
Merge pull request #2688 from sharady/CA-201728
Browse files Browse the repository at this point in the history
CA-201728: VLAN.create must fail if VLAN is in use by FCoE
  • Loading branch information
robhoes authored Jul 22, 2016
2 parents 3d4d9dd + 574b075 commit ee1bff5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions ocaml/idl/api_errors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ let pif_is_physical = "PIF_IS_PHYSICAL"
let pif_is_vlan = "PIF_IS_VLAN"
let pif_vlan_exists = "PIF_VLAN_EXISTS"
let pif_vlan_still_exists = "PIF_VLAN_STILL_EXISTS"
let vlan_in_use = "VLAN_IN_USE"
let pif_device_not_found = "PIF_DEVICE_NOT_FOUND"
let pif_already_bonded = "PIF_ALREADY_BONDED"
let pif_cannot_bond_cross_host = "PIF_CANNOT_BOND_CROSS_HOST"
Expand Down
2 changes: 2 additions & 0 deletions ocaml/idl/datamodel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ let _ =
~doc:"You tried to create a PIF, but it already exists." ();
error Api_errors.pif_vlan_still_exists [ "PIF" ]
~doc:"Operation cannot proceed while a VLAN exists on this interface." ();
error Api_errors.vlan_in_use ["device"; "vlan"]
~doc:"Operation cannot be performed because this VLAN is already in use. Please check your network configuration." ();
error Api_errors.pif_already_bonded [ "PIF" ]
~doc:"This operation cannot be performed because the pif is bonded." ();
error Api_errors.pif_cannot_bond_cross_host []
Expand Down
2 changes: 2 additions & 0 deletions ocaml/xapi/network.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ let transform_networkd_exn pif f =
| Not_implemented ->
let e = "networkd function not implemented" in
reraise Api_errors.pif_configuration_error [Ref.string_of pif; e]
| Vlan_in_use (device, vlan) ->
reraise Api_errors.vlan_in_use [device; string_of_int vlan]
| e ->
error "Caught %s while trying to plug a PIF" (ExnHelper.string_of_exn e);
reraise Api_errors.pif_configuration_error [Ref.string_of pif; ""]
Expand Down
1 change: 1 addition & 0 deletions ocaml/xapi/network.mli
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module Net :
params:(string * string) list -> unit
val is_connected : string -> name:Network_interface.iface -> bool
val is_physical : string -> name:Network_interface.iface -> bool
val has_vlan : string -> name:Network_interface.iface -> vlan:int -> bool
val bring_up : string -> name:Network_interface.iface -> unit
val bring_down : string -> name:Network_interface.iface -> unit
val is_persistent :
Expand Down
5 changes: 5 additions & 0 deletions ocaml/xapi/xapi_vlan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ let create ~__context ~tagged_PIF ~tag ~network =
if Db.PIF.get_tunnel_access_PIF_of ~__context ~self:tagged_PIF <> [] then
raise (Api_errors.Server_error (Api_errors.is_tunnel_access_pif, [Ref.string_of tagged_PIF]));

(* Check the VLAN is not in use by the kernel *)
let open Network in
if Net.Interface.has_vlan (Context.string_of_task __context) ~name:device ~vlan:(Int64.to_int tag) then
raise (Api_errors.Server_error (Api_errors.vlan_in_use, [device; Int64.to_string tag]));

let vlan, untagged_PIF = create_internal ~__context ~host ~tagged_PIF ~tag ~network ~device in
Xapi_pif.plug ~__context ~self:untagged_PIF;
vlan
Expand Down

0 comments on commit ee1bff5

Please sign in to comment.