]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
CP-1591: Synchronise VIF.MTU and PIF.MTU on plug
authorRob Hoes <rob.hoes@citrix.com>
Tue, 12 Oct 2010 09:34:47 +0000 (10:34 +0100)
committerRob Hoes <rob.hoes@citrix.com>
Tue, 12 Oct 2010 09:34:47 +0000 (10:34 +0100)
The VIF.MTU and PIF.MTU fields are now read-only, and will reflect the current state of the network. When you change the Network.MTU, VIFs and PIFs will have to be replugged to have their MTU changed by the networking subsystem. So when Network.MTU and PIF.MTU are not equal, this is a reminder to replug the PIF (same for VIFs).

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
ocaml/xapi/dbsync_slave.ml
ocaml/xapi/nm.ml
ocaml/xapi/vmops.ml
ocaml/xapi/xapi_globs.ml

index aa32d39c8b83a7ddb1bbd2b99249b8f81dbd4de5..1e3ddaad660a9ae9e28cca8f2ca7900c3a812e50 100644 (file)
@@ -420,7 +420,7 @@ let remove_all_leaked_vbds __context =
  * interface (defined by what is brought up before xapi starts) as attached too.
  * For example, this will prevent needless glitches in storage interfaces.
  *)
-let resynchronise_pif_currently_attached ~__context =
+let resynchronise_pif_params ~__context =
   let localhost = Helpers.get_localhost () in
   (* See which PIFs were brought up at start of day, according to the inventory file *)
   let pifs_brought_up =
@@ -443,7 +443,15 @@ let resynchronise_pif_currently_attached ~__context =
                               (Mtc.is_pif_attached_to_mtc_vms_and_should_not_be_offline ~__context ~self) in
        Db.PIF.set_currently_attached ~__context ~self ~value:mark_as_attached;
        Db.PIF.set_management ~__context ~self ~value:is_management_pif;
-       debug "Marking PIF device %s as %s" (Db.PIF.get_device ~__context ~self) (if mark_as_attached then "attached" else "offline")
+       debug "Marking PIF device %s as %s" (Db.PIF.get_device ~__context ~self) (if mark_as_attached then "attached" else "offline");
+       
+       (* sync MTU *)
+       try
+         let device = Db.PIF.get_device ~__context ~self in
+         let mtu = Int64.of_string (Netdev.get_mtu device) in
+         Db.PIF.set_MTU ~__context ~self ~value:mtu;
+       with _ ->
+         debug "could not update MTU field on PIF %s" (Db.PIF.get_uuid ~__context ~self)
     )
     (Db.Host.get_PIFs ~__context ~self:localhost)
 
@@ -529,9 +537,9 @@ let update_env __context sync_keys =
   update_physical_networks ~__context;
 *)
 
-  switched_sync Xapi_globs.sync_resynchronise_pif_currently_attached (fun () ->
-    debug "resynchronising PIF.currently_attached";
-    resynchronise_pif_currently_attached ~__context;
+  switched_sync Xapi_globs.sync_pif_params (fun () ->
+    debug "resynchronising PIF params";
+    resynchronise_pif_params ~__context;
   );
 
   switched_sync Xapi_globs.sync_patch_update_db (fun () ->
index cd7935ad969a0590b970f47413339ce5ee30924b..76f67a3e079bb43f988243459e10caddd0351d08 100644 (file)
@@ -72,6 +72,15 @@ let bring_pif_up ~__context ?(management_interface=false) (pif: API.ref_PIF) =
                   Xapi_mgmt_iface.rebind ()
                 end;
                 
+               (* sync MTU *)
+               (try
+                       let device = Db.PIF.get_device ~__context ~self:pif in
+                       let mtu = Int64.of_string (Netdev.get_mtu device) in
+                       Db.PIF.set_MTU ~__context ~self:pif ~value:mtu
+               with _ ->
+                       debug "could not update MTU field on PIF %s" uuid
+               );
+  
                Xapi_mgmt_iface.on_dom0_networking_change ~__context;
                
                update_inventory ~__context
index 8ad15f9bac156c14058b752f044f560fe4887e4d..15ba8e00ce181654160927321d2c12a9faa3339d 100644 (file)
@@ -82,8 +82,9 @@ let check_vm_parameters ~__context ~self ~snapshot =
 
 let add_vif ~__context ~xs vif_device = 
   if vif_device.Vm_config.bridge = "" then failwith "Don't know how to connect a VIF to this type of Network";
+  let vif_uuid = Db.VIF.get_uuid ~__context ~self:vif_device.Vm_config.vif_ref in
   let extra_private_keys = ["ref", Ref.string_of vif_device.Vm_config.vif_ref;
-                            "vif-uuid", Db.VIF.get_uuid ~__context ~self:vif_device.Vm_config.vif_ref;
+                            "vif-uuid", vif_uuid;
                             "network-uuid", Db.Network.get_uuid ~__context ~self:vif_device.Vm_config.network_ref] in
   Xapi_network.attach_internal ~__context ~self:vif_device.Vm_config.network_ref ();
   Xapi_udhcpd.maybe_add_lease ~__context vif_device.Vm_config.vif_ref;
@@ -97,7 +98,15 @@ let add_vif ~__context ~xs vif_device =
         vif_device.Vm_config.domid in
        ()
     );
-  Db.VIF.set_currently_attached ~__context ~self:vif_device.Vm_config.vif_ref ~value:true
+  Db.VIF.set_currently_attached ~__context ~self:vif_device.Vm_config.vif_ref ~value:true;
+  (* sync MTU *)
+  try
+    let device = "vif" ^ (string_of_int vif_device.Vm_config.domid) ^ "." ^ (string_of_int vif_device.Vm_config.devid) in
+    let mtu = Int64.of_string (Netdev.get_mtu device) in
+    Db.VIF.set_MTU ~__context ~self:vif_device.Vm_config.vif_ref ~value:mtu
+  with _ ->
+    debug "could not update MTU field on VIF %s" vif_uuid
+
 
 (* take a list of vif devices and attach them to the domid *)
 let create_vifs ~__context ~xs vifs =
index db96d478cb1fd5c623f83e8453a917d5e87a909f..5098393dd61d251880e053bd144023172dc69176 100644 (file)
@@ -342,7 +342,7 @@ let sync_create_domain_zero = "sync_create_domain_zero"
 let sync_crashdump_resynchronise = "sync_crashdump_resynchronise"
 let sync_update_vms = "sync_update_vms"
 let sync_remove_leaked_vbds = "sync_remove_leaked_vbds"
-let sync_resynchronise_pif_currently_attached = "sync_resynchronise_pif_currently_attached"
+let sync_pif_params = "sync_pif_params"
 let sync_patch_update_db = "sync_patch_update_db"
 let sync_pbd_reset = "sync_pbd_reset"
 let sync_bios_strings = "sync_bios_strings"