Skip to contentSkip to conversation

libxl: fix vif.ifname when used with stub device model

PATCH In review Ian Campbell 2 participants 5 messages Jul 20, 2012 – Jul 24, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: fix vif.ifname when used with stub device model

# HG changeset patch
# User Ian Campbell <[email protected]> # 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.

tools/libxl/libxl_dm.c +19 -2
diff -r 9cdc74869620 -r 79cfa1892a5d tools/libxl/libxl_dm.c
@@ -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;
Acked-by on v1 1/1
#1 lore raw

Ian Campbell writes ("[PATCH] libxl: fix vif.ifname when used with stub device model"):

Quoted 7 lines

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.

Quoted 5 lines

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.

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.

#2 lore raw
Quoted 16 lines · Ian Jackson

Ian Campbell writes ("[PATCH] libxl: fix vif.ifname when used with stub device model"):

Quoted 7 lines

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.

Quoted 5 lines

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.

Quoted 7 lines

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.

#3 lore raw
Quoted 2 lines · Ian Campbell

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.

author Applied
#4 lore raw
In reply to Ian Jackson
Quoted 8 lines · Ian Jackson

Ian Campbell writes ("[PATCH] libxl: fix vif.ifname when used with stub device model"):

Quoted 7 lines

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.

Quoted 7 lines
Quoted 5 lines

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.

Applied, thanks.