File xend-validate-nic-model.patch of Package xen

Do not invoke qemu with unsupported NIC model

Unlike xmdomain.cfg config format, libvirt does not distinguish between
'model' and 'type' in its vif XML, which is correct IMO since netfront
(pv NIC) is just another NIC model.  libvirt maps a model of type netfront
to 'type=netfront', and all other models to 'type=ioemu,model=user-val'.
For example

libvirt vif XML                 xmdomain.cfg
<model type='netfrond'/>        vif=[ 'type=netfrond' ]
<model type='user-val'/>        vif=[ 'type=ioemu,model=user-val' ]

In the latter case, qemu-dm is invoked with 

-net nic,vlan=1,macaddr=00:16:3e:3b:c6:0d,model=user-val,bridge=br0

which causes qemu-dm to exit with failure if user-val is not a
supported NIC model.  Since monitoring qemu-dm exit is asynchronous
wrt domain creation, it appears the domain was successfully created from
the client's (xm, libvirt, etc.) perspective when in fact it was not.

This patch simply checks that the specifed NIC model is supported by
qemu-dm, and raises a VmError if not.  qemu will report supported models
when invoked with '-net nic,model=?'.  It will also list supported models
when invoked with an unsupported one.

    Signed-off-by: Jim Fehlig <jfehlig@novell.com>


Index: xen-4.0.2-testing/tools/python/xen/xend/image.py
===================================================================
--- xen-4.0.2-testing.orig/tools/python/xen/xend/image.py
+++ xen-4.0.2-testing/tools/python/xen/xend/image.py
@@ -50,6 +50,9 @@ MAX_GUEST_CMDLINE = 1024
 sentinel_path_prefix = '/var/run/xend/dm-'
 sentinel_fifos_inuse = { }
 
+supported_nic_models = ['ne2k_pci', 'i82551', 'i82557b', 'i82559er',
+                        'rtl8139', 'e1000', 'pcnet', 'virtio']
+
 def cleanup_stale_sentinel_fifos():
     for path in glob.glob(sentinel_path_prefix + '*.fifo'):
         if path in sentinel_fifos_inuse: continue
@@ -925,6 +928,10 @@ class HVMImageHandler(ImageHandler):
                 raise VmError("MAC address not specified or generated.")
             bridge = devinfo.get('bridge', None)
             model = devinfo.get('model', 'rtl8139')
+            if model not in supported_nic_models:
+                raise VmError("Emulation of NIC model '%s' is not supported" %
+                              model)
+
             ret.append("-net")
             net = "nic,vlan=%d,macaddr=%s,model=%s" % (nics, mac, model)
             if bridge:
openSUSE Build Service is sponsored by