From 44ac64fe97114b3c18c6bf6ed8f3d1fc7e2f6fd3 Mon Sep 17 00:00:00 2001 From: Rob Hoes Date: Tue, 12 Oct 2010 10:34:47 +0100 Subject: [PATCH] CP-1591: Synchronise VIF.MTU and PIF.MTU on plug 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 --- ocaml/xapi/dbsync_slave.ml | 18 +++++++++++++----- ocaml/xapi/nm.ml | 9 +++++++++ ocaml/xapi/vmops.ml | 13 +++++++++++-- ocaml/xapi/xapi_globs.ml | 2 +- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/ocaml/xapi/dbsync_slave.ml b/ocaml/xapi/dbsync_slave.ml index aa32d39c..1e3ddaad 100644 --- a/ocaml/xapi/dbsync_slave.ml +++ b/ocaml/xapi/dbsync_slave.ml @@ -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 () -> diff --git a/ocaml/xapi/nm.ml b/ocaml/xapi/nm.ml index cd7935ad..76f67a3e 100644 --- a/ocaml/xapi/nm.ml +++ b/ocaml/xapi/nm.ml @@ -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 diff --git a/ocaml/xapi/vmops.ml b/ocaml/xapi/vmops.ml index 8ad15f9b..15ba8e00 100644 --- a/ocaml/xapi/vmops.ml +++ b/ocaml/xapi/vmops.ml @@ -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 = diff --git a/ocaml/xapi/xapi_globs.ml b/ocaml/xapi/xapi_globs.ml index db96d478..5098393d 100644 --- a/ocaml/xapi/xapi_globs.ml +++ b/ocaml/xapi/xapi_globs.ml @@ -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" -- 2.39.5