Ian Campbell
2012-Jul-20 13:51 UTC
[PATCH] libxl: fix vif.ifname when used with stub device model
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1342792265 -3600 # Node ID 79cfa1892a5d55f2c137da6d4f2d5f261b47db26 # Parent 9cdc74869620ed5e9b4f379d83963755f4c45e01 libxl: fix vif.ifname when used with stub device model. Currently the same libxl_device_nic is used to create both the HVM domain and its stub domain''s NICs. This means that if a vifname is provided both the HVM domains PV NIC and the stub domains PV NIC will get the same name and the DM''s NIC will fail to be attached. Instead launder the libxl_device_nic to add the TAP_DEVICE_SUFFIX ("-emu"). This is a bit of a misnomer, since the device is actually PV, but it is used to "back" the emulated device in the stub domain and this naming scheme is consistent with the non-stub case and is known to work e.g. with our hotplug scripts. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 9cdc74869620 -r 79cfa1892a5d tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Fri Jul 20 12:03:49 2012 +0100 +++ b/tools/libxl/libxl_dm.c Fri Jul 20 14:51:05 2012 +0100 @@ -616,6 +616,24 @@ static char ** libxl__build_device_model } } +static void libxl__dm_nics_from_hvm_guest_config(libxl__gc *gc, + libxl_domain_config * const guest_config, + libxl_domain_config *dm_config) +{ + int i, nr = guest_config->num_nics; + + GCNEW_ARRAY(dm_config->nics, nr); + + for (i=0; i<nr; i++) { + dm_config->nics[i] = guest_config->nics[i]; + if (dm_config->nics[i].ifname) + dm_config->nics[i].ifname = GCSPRINTF("%s" TAP_DEVICE_SUFFIX, + dm_config->nics[i].ifname); + } + + dm_config->num_nics = nr; +} + static int libxl__vfb_and_vkb_from_hvm_guest_config(libxl__gc *gc, const libxl_domain_config *guest_config, libxl_device_vfb *vfb, @@ -764,8 +782,7 @@ void libxl__spawn_stub_dm(libxl__egc *eg dm_config->disks = guest_config->disks; dm_config->num_disks = guest_config->num_disks; - dm_config->nics = guest_config->nics; - dm_config->num_nics = guest_config->num_nics; + libxl__dm_nics_from_hvm_guest_config(gc, guest_config, dm_config); dm_config->c_info.run_hotplug_scripts guest_config->c_info.run_hotplug_scripts;
Ian Jackson
2012-Jul-20 14:06 UTC
Re: [PATCH] libxl: fix vif.ifname when used with stub device model
Ian Campbell writes ("[PATCH] libxl: fix vif.ifname when used with stub device model"):> libxl: fix vif.ifname when used with stub device model. > > Currently the same libxl_device_nic is used to create both the HVM domain and > its stub domain''s NICs. This means that if a vifname is provided both the HVM > domains PV NIC and the stub domains PV NIC will get the same name and the > DM''s NIC will fail to be attached. > > Instead launder the libxl_device_nic to add the TAP_DEVICE_SUFFIX ("-emu"). > This is a bit of a misnomer, since the device is actually PV, but it is used to > "back" the emulated device in the stub domain and this naming scheme is > consistent with the non-stub case and is known to work e.g. with our hotplug > scripts.Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> as far as it goes. However I think this is related to Roger''s: [PATCH v9 12/17] libxl: set correct nic type depending on the guest Shouldn''t the type field for the nics to be given to the stub dm be forced to VIF ? Ian.
Ian Campbell
2012-Jul-20 14:17 UTC
Re: [PATCH] libxl: fix vif.ifname when used with stub device model
On Fri, 2012-07-20 at 15:06 +0100, Ian Jackson wrote:> Ian Campbell writes ("[PATCH] libxl: fix vif.ifname when used with stub device model"): > > libxl: fix vif.ifname when used with stub device model. > > > > Currently the same libxl_device_nic is used to create both the HVM domain and > > its stub domain''s NICs. This means that if a vifname is provided both the HVM > > domains PV NIC and the stub domains PV NIC will get the same name and the > > DM''s NIC will fail to be attached. > > > > Instead launder the libxl_device_nic to add the TAP_DEVICE_SUFFIX ("-emu"). > > This is a bit of a misnomer, since the device is actually PV, but it is used to > > "back" the emulated device in the stub domain and this naming scheme is > > consistent with the non-stub case and is known to work e.g. with our hotplug > > scripts. > > Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> > > as far as it goes. > > However I think this is related to Roger''s: > [PATCH v9 12/17] libxl: set correct nic type depending on the guest > > Shouldn''t the type field for the nics to be given to the stub dm be > forced to VIF ?I should imagine so, although it''s somewhat orthogonal other than both involve frobbing the DM''s NIC config. I presume that in practice PV guests can''t have an EMU path and therefore the two NIC types collapse into the same thing, although there''s no harm being explicit I suppose.
Ian Campbell
2012-Jul-20 15:08 UTC
Re: [PATCH] libxl: fix vif.ifname when used with stub device model
On Fri, 2012-07-20 at 15:17 +0100, Ian Campbell wrote:> I presume that in practice PV guests can''t have an EMU path and > therefore the two NIC types collapse into the same thing,This happens in libxl__device_nic_setdefaults BTW. Ian.
Ian Campbell
2012-Jul-24 09:30 UTC
Re: [PATCH] libxl: fix vif.ifname when used with stub device model
On Fri, 2012-07-20 at 15:06 +0100, Ian Jackson wrote:> Ian Campbell writes ("[PATCH] libxl: fix vif.ifname when used with stub device model"): > > libxl: fix vif.ifname when used with stub device model. > > > > Currently the same libxl_device_nic is used to create both the HVM domain and > > its stub domain''s NICs. This means that if a vifname is provided both the HVM > > domains PV NIC and the stub domains PV NIC will get the same name and the > > DM''s NIC will fail to be attached. > > > > Instead launder the libxl_device_nic to add the TAP_DEVICE_SUFFIX ("-emu"). > > This is a bit of a misnomer, since the device is actually PV, but it is used to > > "back" the emulated device in the stub domain and this naming scheme is > > consistent with the non-stub case and is known to work e.g. with our hotplug > > scripts. > > Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>Applied, thanks.