]> xenbits.xen.org Git - xenclient/toolstack.git/commitdiff
Enable switching of a nic's bridge
authorJon Ludlam <Jonathan.Ludlam@eu.citrix.com>
Wed, 26 Aug 2009 10:55:09 +0000 (11:55 +0100)
committerJon Ludlam <Jonathan.Ludlam@eu.citrix.com>
Wed, 26 Aug 2009 10:55:09 +0000 (11:55 +0100)
xenops/device.ml
xenops/device.mli
xenvm/tasks.ml
xenvm/vmact.ml
xenvm/vmstate.ml
xenvm/xenvm.ml

index a925373586bc5c9dce7e2344ba433d748fb883c9..ce6dbdb1df3fbe789ac2c2575635c91bb73a50ed 100644 (file)
@@ -631,15 +631,18 @@ let check_mac mac =
         with _ ->
                raise (Invalid_Mac mac)
 
+let get_backend_dev ~xs (x: device) =
+        try
+               let path = Hotplug.get_hotplug_path x in
+               xs.Xs.read (path ^ "/vif")
+       with Xb.Noent ->
+               raise (Hotplug_script_expecting_field (x, "vif"))
+
 (** Plug in the backend of a guest's VIF in dom0. Note that a guest may disconnect and
     then reconnect their network interface: we have to re-run this code every time we
     see a hotplug online event. *)
 let plug ~xs ~netty ~mac ?(mtu=0) ?rate ?protocol (x: device) =
-       let backend_dev = try
-               let path = Hotplug.get_hotplug_path x in
-               xs.Xs.read (path ^ "/vif")
-       with Xb.Noent ->
-               raise (Hotplug_script_expecting_field (x, "vif")) in
+       let backend_dev = get_backend_dev xs x in
 
        if mtu > 0 then
                Netdev.set_mtu backend_dev mtu;
index e9d868496a6c4cc26ab95fef51b6efb6039e1752..8b3b03fe428deb3021c850028fcbb82529ca7918 100644 (file)
@@ -82,7 +82,7 @@ end
 module Vif :
 sig
        exception Invalid_Mac of string
-
+       val get_backend_dev : xs:Xs.xsh -> device -> string
        val add : xs:Xs.xsh -> devid:int -> netty:Netman.netty
               -> mac:string -> ?mtu:int -> ?rate:(int64 * int64) option
               -> ?protocol:protocol -> ?backend_domid:Xc.domid -> Xc.domid
index 4f4701f68a577eb0ef1acfd0698fa048f3261f35..1373404a17b741bcbb00a4e9b5333d502e2e86e4 100644 (file)
@@ -44,6 +44,7 @@ type action =
         | CDEject
         | CDInsertFile
         | CDInsertReal
+        | NicBridgeSwitch
        | ReadConfig
        | Help
 
@@ -110,6 +111,9 @@ let actions_table = [
                                                      "physpath", R, ArgString ]);
        (CDInsertReal,mk_desc_args "cd-insert-real" [ "virtpath", R, ArgString;
                                                       "physpath", R, ArgString ]);
+       (NicBridgeSwitch,mk_desc_args "nic-bridge-switch" [ "id", R, ArgInt;
+                                                           "bridge", R, ArgString ]);
+
                    
 
        (ReadConfig, mk_desc_args_nb "read-config" [ "path", O, ArgString ]);
index eb09d883c6b190ee2b429d6e9ebea8c1233cda7d..feee559e471729343181b96fc204c450504515ba 100644 (file)
@@ -127,12 +127,31 @@ let add_nic_to_vm ~xs state nic =
        let (_: Device_common.device) =
                Device.Vif.add ~xs ~devid:nic.nic_id ~netty ~mac:nic.nic_mac
                               ~protocol:(devproto_of_state state) state.vm_domid in
+        state.vm_nics <- {ns_id=nic.nic_id; ns_bridge=nic.nic_bridge}::state.vm_nics;
        ()
 
 let get_nics cfg =
        (* then sort the nics by ascending order *)
        List.sort (fun nic1 nic2 -> if nic1.nic_id > nic2.nic_id then 1 else -1) cfg.nics
 
+let device_of_vif domid id =
+        let backend = { Device_common.domid = 0; 
+                  kind = Device_common.Vif;
+                  devid = id } in
+        Device_common.device_of_backend backend domid
+
+let nic_bridge_switch ~xs state id bridge =
+        let id = Int64.to_int id in
+        let ns = List.find (fun ns -> ns.ns_id = id) state.vm_nics in
+        let cur_netty = Netman.Bridge ns.ns_bridge in
+        let new_netty = Netman.Bridge bridge in
+        let device = device_of_vif state.vm_domid id in
+        let backend_dev = Device.Vif.get_backend_dev xs device in
+        Netman.offline backend_dev cur_netty;
+        Netman.online backend_dev new_netty;
+        state.vm_nics <- List.map (fun ns -> if ns.ns_id=id then {ns with ns_bridge=bridge} else ns) state.vm_nics;
+        Xenvmlib.Ok
+
 let get_pcis cfg =
        let ids = ref [] in
        List.iter (fun (id, dev) ->
index 2e771c3a78f253a71fd1c7b207196722872eaa03..753d53800ccd9e3f2fa4168b1a8389d2c9b1fe95 100644 (file)
@@ -47,6 +47,11 @@ type monitor_state = {
        mutable monitor_dbus_quit: bool;
 }
 
+type nic_state = {
+        ns_id : int;
+        mutable ns_bridge: string;
+}
+
 type vm_state = {
        vm_uuid: string;
        vm_monitors: monitor_state;
@@ -59,6 +64,7 @@ type vm_state = {
        mutable vm_vnc_port: int;
        mutable vm_lifestate: vmlifestate;
        mutable vm_tap2_disks: (Vmconfig.config_disk * string) list;
+        mutable vm_nics: nic_state list;
        mutable vm_on_suspend_action: Vmconfig.action;
        mutable vm_cfg: Vmconfig.config;
        mutable vm_next_cfg: Vmconfig.config option;
@@ -85,6 +91,7 @@ let state_init uuid config_path cfg =
                vm_lifestate = VmShutdown;
                vm_vnc_port = (-1);
                vm_tap2_disks = [];
+                vm_nics = [];
                vm_on_suspend_action = ActionSuspend;
                vm_cfg = cfg;
                vm_next_cfg = None;
index a154bbae64d92e0efeedcde080cc561bb71c4140..9cb620ffdfd43604837348b34e56ed3fbb7e3780 100644 (file)
@@ -501,6 +501,10 @@ let do_task state (task, args) =
                 let virtpath = Tasks.args_get_string args "virtpath" in
                 let physpath = Tasks.args_get_string args "physpath" in
                 with_xcs (fun xc xs -> Vmact.cd_insert_file xs state virtpath physpath)
+        | Tasks.NicBridgeSwitch ->
+                let id = Tasks.args_get_int args "id" in
+                let bridge = Tasks.args_get_string args "bridge" in
+                with_xcs (fun xc xs -> Vmact.nic_bridge_switch xs state id bridge)
        | Tasks.ReadConfig ->
                let path =
                        try Some (Tasks.args_get_string args "path")