]> xenbits.xensource.com Git - xen.git/commitdiff
libxl/xend: name tap devices vifX.Y-emu
authorIan Campbell <ian.campbell@citrix.com>
Wed, 25 Apr 2012 11:55:57 +0000 (12:55 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 25 Apr 2012 11:55:57 +0000 (12:55 +0100)
This prevents the udev scripts from operating on other tap devices (e.g.
openvpn etc)

Correct the documentation for the "vifname" option which suggested it applied
to HVM tap devices only, which is not the case.

Reported by Michael Young.

Also fix the use of vifname with emulated devices. This is slightly complex.
The current hotplug scripts rely on being able to parse the "tapX.Y" (now
"vifX.Y-emu") name in order to locate the xenstore backend dir relating to the
corresponding vif. This is because we cannot inject our own environment vars
into the tap hotplug events. However this means that if the tap is initially
named with a user specified name (which will not match the expected scheme) we
fail to do anything useful with the device. So now we create the initial tap
device with the standard "vifX.Y-emu" name and the hotplug script will handle
the rename to the desired name. This is also how PV vif devices work -- they
are always created by netback with the name vifX.Y and renamed in the script.

Lastly also move libxl__device_* to a better place in the header, otherwise the
comment about evgen stuff isn't next to the associated functions (noticed jsut
because I was going to add nic_devname near to the setdefault functions)

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
docs/misc/xl-network-configuration.markdown
tools/hotplug/Linux/vif-common.sh
tools/hotplug/Linux/xen-backend.rules
tools/libxl/libxl.c
tools/libxl/libxl_dm.c
tools/libxl/libxl_internal.h
tools/python/xen/xend/image.py

index e2a5bc60c53f7f20a8f2dcc4377fd07c90c4a2e3..b36d6c89c96b47181f6742183740a10f2742b754 100644 (file)
@@ -93,11 +93,14 @@ are:
 
 ### vifname
 
-This keyword is valid for HVM guest devices with `type=ioemu` only.
+Specifies the backend device name for the virtual device.
+
+If the domain is an HVM domain then the associated emulated (tap)
+device will have a "-emu" suffice added.
 
-Specifies the backend device name for an emulated device. The default
-is `tapDOMID.DEVID` where `DOMID` is the guest domain ID and `DEVID`
-is the device number.
+The default name for the virtual device is `vifDOMID.DEVID` where
+`DOMID` is the guest domain ID and `DEVID` is the device
+number. Likewise the default tap name is `vifDOMID.DEVID-emu`.
 
 ### script
 
index c9c5d41da0cc864c975852b70858ae3cf8ef91c8..fff22bbf9d82c0d37321e50fecd3a4680350957d 100644 (file)
@@ -85,12 +85,23 @@ elif [ "$type_if" = tap ]; then
     : ${INTERFACE:?}
 
     # Get xenbus_path from device name.
-    # The name is built like that: "tap${domid}.${devid}".
-    dev_=${dev#tap}
+    # The name is built like that: "vif${domid}.${devid}-emu".
+    dev_=${dev#vif}
+    dev_=${dev_%-emu}
     domid=${dev_%.*}
     devid=${dev_#*.}
 
     XENBUS_PATH="/local/domain/0/backend/vif/$domid/$devid"
+    vifname=$(xenstore_read_default "$XENBUS_PATH/vifname" "")
+    if [ "$vifname" ]
+    then
+        vifname="${vifname}-emu"
+        if [ "$command" == "add" ] && ! ip link show "$vifname" >&/dev/null
+        then
+            do_or_die ip link set "$dev" name "$vifname"
+        fi
+        dev="$vifname"
+    fi
 fi
 
 ip=${ip:-}
index 40f2658eb2090dae946678e8b41a89ca8e2a3b07..405387f1a91d3e1ef792eac4e65428d3b253f789 100644 (file)
@@ -13,4 +13,4 @@ KERNEL=="blktap-control", NAME="xen/blktap-2/control", MODE="0600"
 KERNEL=="gntdev", NAME="xen/%k", MODE="0600"
 KERNEL=="pci_iomul", NAME="xen/%k", MODE="0600"
 KERNEL=="tapdev[a-z]*", NAME="xen/blktap-2/tapdev%m", MODE="0600"
-SUBSYSTEM=="net", KERNEL=="tap*", ACTION=="add", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} type_if=tap"
+SUBSYSTEM=="net", KERNEL=="vif*-emu", ACTION=="add", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} type_if=tap"
index 14791d6e81944cdf95538ecd310eb7f8defe5c74..c420e19b690efb73353db475592881b5fe722cd2 100644 (file)
@@ -2087,6 +2087,21 @@ int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
     return 0;
 }
 
+const char *libxl__device_nic_devname(libxl__gc *gc,
+                                      uint32_t domid,
+                                      uint32_t devid,
+                                      libxl_nic_type type)
+{
+    switch (type) {
+    case LIBXL_NIC_TYPE_VIF:
+        return GCSPRINTF("vif%u.%d", domid, devid);
+    case LIBXL_NIC_TYPE_IOEMU:
+        return GCSPRINTF("vif%u.%d" TAP_DEVICE_SUFFIX, domid, devid);
+    default:
+        abort();
+    }
+}
+
 /******************************************************************************/
 int libxl__device_console_add(libxl__gc *gc, uint32_t domid,
                               libxl__device_console *console,
index 48c7ed52dca24883866a8350bba1e3c6d1bd4a61..ec967f784a9782600cb97b38a5f64b05f9b135e3 100644 (file)
@@ -209,12 +209,9 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc,
             if (vifs[i].nictype == LIBXL_NIC_TYPE_IOEMU) {
                 char *smac = libxl__sprintf(gc,
                                    LIBXL_MAC_FMT, LIBXL_MAC_BYTES(vifs[i].mac));
-                char *ifname;
-                if (!vifs[i].ifname)
-                    ifname = libxl__sprintf(gc,
-                                            "tap%d.%d", domid, vifs[i].devid);
-                else
-                    ifname = vifs[i].ifname;
+                const char *ifname = libxl__device_nic_devname(gc,
+                                                domid, vifs[i].devid,
+                                                LIBXL_NIC_TYPE_IOEMU);
                 flexarray_vappend(dm_args,
                                   "-net",
                                   GCSPRINTF(
@@ -456,13 +453,9 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
             if (vifs[i].nictype == LIBXL_NIC_TYPE_IOEMU) {
                 char *smac = libxl__sprintf(gc,
                                 LIBXL_MAC_FMT, LIBXL_MAC_BYTES(vifs[i].mac));
-                char *ifname;
-                if (!vifs[i].ifname) {
-                    ifname = libxl__sprintf(gc, "tap%d.%d",
-                                            guest_domid, vifs[i].devid);
-                } else {
-                    ifname = vifs[i].ifname;
-                }
+                const char *ifname = libxl__device_nic_devname(gc,
+                                                guest_domid, vifs[i].devid,
+                                                LIBXL_NIC_TYPE_IOEMU);
                 flexarray_append(dm_args, "-device");
                 flexarray_append(dm_args,
                    libxl__sprintf(gc, "%s,id=nic%d,netdev=net%d,mac=%s",
index 34ea15ca862d95ab6fb7db3640cb8b01ec18d7d0..c047253f219dcdba0f1105b5b7f52caca4684ecb 100644 (file)
@@ -83,6 +83,7 @@
 #define STUBDOM_CONSOLE_RESTORE 2
 #define STUBDOM_CONSOLE_SERIAL 3
 #define STUBDOM_SPECIAL_CONSOLES 3
+#define TAP_DEVICE_SUFFIX "-emu"
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
@@ -196,17 +197,6 @@ _hidden libxl__ev_xswatch *libxl__watch_slot_contents(libxl__gc *gc,
  * version of the _evdisable_FOO function; the internal one is
  * used during cleanup.
  */
-_hidden int libxl__domain_create_info_setdefault(libxl__gc *gc,
-                                        libxl_domain_create_info *c_info);
-_hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
-                                        libxl_domain_build_info *b_info);
-_hidden int libxl__device_disk_setdefault(libxl__gc *gc,
-                                          libxl_device_disk *disk);
-_hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic);
-_hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb);
-_hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb);
-_hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
-
 struct libxl__evgen_domain_death {
     uint32_t domid;
     unsigned shutdown_reported:1, death_reported:1;
@@ -705,6 +695,21 @@ _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
  *     All libxl API functions are expected to have arranged for this
  *     to be called before using any values within these structures.
  */
+_hidden int libxl__domain_create_info_setdefault(libxl__gc *gc,
+                                        libxl_domain_create_info *c_info);
+_hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
+                                        libxl_domain_build_info *b_info);
+_hidden int libxl__device_disk_setdefault(libxl__gc *gc,
+                                          libxl_device_disk *disk);
+_hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic);
+_hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb);
+_hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb);
+_hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
+
+_hidden const char *libxl__device_nic_devname(libxl__gc *gc,
+                                              uint32_t domid,
+                                              uint32_t devid,
+                                              libxl_nic_type type);
 
 /* Arranges that dev will be removed from its guest.  When
  * this is done, the ao will be completed.  An error
index f3768b4612103b63b97d1533dd7282ed078655f6..e08417282dca92f15059e9cc041fb1e9eff7af31 100644 (file)
@@ -917,11 +917,7 @@ class HVMImageHandler(ImageHandler):
             ret.append("-net")
             ret.append("nic,vlan=%d,macaddr=%s,model=%s" %
                        (nics, mac, model))
-            vifname = devinfo.get('vifname')
-            if vifname:
-                vifname = "tap-" + vifname
-            else:
-                vifname = "tap%d.%d" % (self.vm.getDomid(), nics-1)
+            vifname = "vif%d.%d-emu" % (self.vm.getDomid(), nics-1)
             ret.append("-net")
             ret.append("tap,vlan=%d,ifname=%s,bridge=%s" %
                        (nics, vifname, bridge))