[ovs-dev] [PATCH 1 of 2] vswitch: do not access XenAPI from VIF hotplug script

Ian Campbell ian.campbell at citrix.com
Thu Feb 25 08:15:12 PST 2010


XenAPI accesses must go through the pool master which introduces a
scalability issue.  All but one of the required values are already
present in xenstore for this reason

The only exception is the network UUID for an internal network. Rather
than working around the lack of callout to interface-reconfigure for
these networks simply pass the network uuid when creating calling out
to create the bridge.

Signed-off-by: Ian Campbell <ian.campbell at citrix.com>

diff -r e0625d328ff8 -r cc11e72f2ec0 ocaml/netdev/netdev.ml
--- a/ocaml/netdev/netdev.ml	Thu Feb 25 16:07:59 2010 +0000
+++ b/ocaml/netdev/netdev.ml	Thu Feb 25 16:07:59 2010 +0000
@@ -18,7 +18,7 @@
 
 type network_ops = { 
   kind: kind;
-  add: string -> unit;
+  add: string -> ?uuid:string -> unit;
   del: string -> unit;
   list: unit -> string list;
 
@@ -98,7 +98,7 @@
 external _add : Unix.file_descr -> string -> unit = "stub_bridge_add"
 external _del : Unix.file_descr -> string -> unit = "stub_bridge_del"
 
-let add name =
+let add name ?uuid = 
 	Internal.with_fd (fun fd -> _add fd name)
 
 let del name =
@@ -223,7 +223,11 @@
     | "" -> []
     | s -> Stringext.String.split '\n' s
 
-let add name = ignore(vsctl ["add-br" ; name])
+let add name ?uuid = 
+  let extra = match uuid with
+    | Some uuid' -> ["--"; "br-set-external-id"; name; "xs-network-uuids"; uuid']
+    | None -> ["--"; "foo"] in
+  ignore(vsctl (["add-br" ; name] @ extra))
 let del name = ignore(vsctl ["del-br" ; name])
 let list () = vsctl [ "list-br" ]
 
diff -r e0625d328ff8 -r cc11e72f2ec0 ocaml/netdev/netdev.mli
--- a/ocaml/netdev/netdev.mli	Thu Feb 25 16:07:59 2010 +0000
+++ b/ocaml/netdev/netdev.mli	Thu Feb 25 16:07:59 2010 +0000
@@ -21,7 +21,7 @@
 (** Possible operations on each network backend type. *)
 type network_ops = {
   kind : kind;                              (** The type of network backend. *)
-  add : string -> unit;                     (** Add a bridge. *)
+  add : string -> ?uuid:string -> unit;     (** Add a bridge. *)
   del : string -> unit;                     (** Remove a bridge. *)
   list : unit -> string list;               (** List all bridges. *)
   exists : string -> bool;                  (** Query the existance of a bridge. *)
diff -r e0625d328ff8 -r cc11e72f2ec0 ocaml/xapi/xapi_network.ml
--- a/ocaml/xapi/xapi_network.ml	Thu Feb 25 16:07:59 2010 +0000
+++ b/ocaml/xapi/xapi_network.ml	Thu Feb 25 16:07:59 2010 +0000
@@ -24,10 +24,10 @@
 let get_allowed_messages ~__context ~self = []
 *)
 
-let create_internal_bridge ~bridge =
-  debug "Creating internal bridge %s" bridge;
+let create_internal_bridge ~bridge ~uuid =
+  debug "Creating internal bridge %s (uuid:%s)" bridge uuid;
   let current = Netdev.network.Netdev.list () in
-  if not(List.mem bridge current) then Netdev.network.Netdev.add bridge;
+  if not(List.mem bridge current) then Netdev.network.Netdev.add bridge ?uuid:(Some uuid);
   if not(Netdev.Link.is_up bridge) then Netdev.Link.up bridge
 
 let attach_internal ?(management_interface=false) ~__context ~self () =
@@ -36,10 +36,11 @@
     Xapi_network_attach_helpers.assert_can_attach_network_on_host ~__context ~self ~host ~overide_management_if_check:management_interface in
 
   let bridge = Db.Network.get_bridge ~__context ~self in
+  let uuid = Db.Network.get_uuid ~__context ~self in
 
   (* Ensure internal bridge exists and is up. external bridges will be
      brought up by call to interface-reconfigure. *)
-  if List.length(local_pifs) = 0 then create_internal_bridge ~bridge;
+  if List.length(local_pifs) = 0 then create_internal_bridge ~bridge ~uuid;
 
   (* Check if we're a guest-installer network: *)
   let other_config = Db.Network.get_other_config ~__context ~self in
diff -r e0625d328ff8 -r cc11e72f2ec0 scripts/vif
--- a/scripts/vif	Thu Feb 25 16:07:59 2010 +0000
+++ b/scripts/vif	Thu Feb 25 16:07:59 2010 +0000
@@ -66,6 +66,43 @@
     fi
 }
 
+set_vif_external_id()
+{
+    local key=$1
+    local value=$2
+
+    logger -t scripts-vif "vif${DOMID}.${DEVID} external-ids:\"${key}\"=\"${value}\""
+
+    echo "-- set interface vif${DOMID}.${DEVID} external-ids:\"${key}\"=\"${value}\""
+}
+
+handle_vswitch_vif_details()
+{
+    local vif_details=
+    local net_uuid=$(xenstore-read "${PRIVATE}/network-uuid" 2>/dev/null)
+    if [ -n "${net_uuid}" ] ; then
+	set_vif_external_id "xs-network-uuid" "${net_uuid}"
+    fi
+
+    local address=$(xenstore-read "/local/domain/$DOMID/device/vif/$DEVID/mac" 2>/dev/null)
+    if [ -n "${address}" ] ; then
+	set_vif_external_id "xs-vif-mac" "${address}"
+    fi
+
+    local vif_uuid=$(xenstore-read "${PRIVATE}/vif-uuid" 2>/dev/null)
+    if [ -n "${vif_uuid}" ] ; then
+	set_vif_external_id "xs-vif-uuid" "${vif_uuid}"
+    fi
+
+    local vm=$(xenstore-read "/local/domain/$DOMID/vm" 2>/dev/null)
+    if [ $? -eq 0 -a -n "${vm}" ] ; then
+	local vm_uuid=$(xenstore-read "$vm/uuid" 2>/dev/null)
+    fi
+    if [ -n "${vm_uuid}" ] ; then
+	set_vif_external_id "xs-vm-uuid" "${vm_uuid}"
+    fi
+}
+
 add_to_bridge()
 {
     local address=$(xenstore-read "${PRIVATE}/bridge-MAC")
@@ -92,12 +129,11 @@
 	    ${BRCTL} addif "${bridge}" "${dev}"                 || logger -t scripts-vif "Failed to brctl addif ${bridge} ${dev}"
 	    ;;
 	vswitch)
-		local vif_details=$($dump_vif_details $DOMID $DEVID)
-		if [ $? -ne 0 -o -z "${vif_details}" ]; then
-			logger -t scripts-vif "Failed to retrieve vif details for vswitch"
-		fi
+	    if [ "$TYPE" = "vif" ] ; then
+		local vif_details=$(handle_vswitch_vif_details)
+	    fi
 
-		$vsctl add-port $bridge $dev $vif_details
+	    $vsctl add-port $bridge $dev $vif_details
 	    ;;
     esac
 	    
@@ -111,7 +147,7 @@
 	    # Nothing to do
 	    ;;
 	vswitch)
-        $vsctl del-port $bridge $dev
+	    $vsctl del-port $bridge $dev
 	    ;;
     esac
 }




More information about the dev mailing list