提交 a68d6726 编写于 作者: P Peter Krempa

qemu: Record the default NIC model in the domain XML

This patch implements the devices post parse callback and uses it to fill
the default qemu network card model into the XML if none is specified.

Libvirt assumes that the network card model for qemu is the "rtl8139".
Record this in the XML using the new callback to avoid user
confusion.
上级 ad0d10b2
......@@ -554,7 +554,7 @@ virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver)
virDomainXMLOptionPtr
virQEMUDriverCreateXMLConf(void)
{
return virDomainXMLOptionNew(NULL,
return virDomainXMLOptionNew(&virQEMUDriverDomainDefParserConfig,
&virQEMUDriverPrivateDataCallbacks,
&virQEMUDriverDomainXMLNamespace);
}
......
......@@ -662,6 +662,31 @@ virDomainXMLNamespace virQEMUDriverDomainXMLNamespace = {
};
static int
qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
virDomainDefPtr def ATTRIBUTE_UNUSED,
virCapsPtr caps ATTRIBUTE_UNUSED,
void *opaque ATTRIBUTE_UNUSED)
{
if (dev->type == VIR_DOMAIN_DEVICE_NET &&
dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV) {
if (!dev->data.net->model &&
!(dev->data.net->model = strdup("rtl8139")))
goto no_memory;
}
return 0;
no_memory:
virReportOOMError();
return -1;
}
virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = {
.devicesPostParseCallback = qemuDomainDeviceDefPostParse,
};
static void
qemuDomainObjSaveJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
{
......
......@@ -342,5 +342,6 @@ void qemuDomainCleanupRun(virQEMUDriverPtr driver,
extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks;
extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace;
extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig;
#endif /* __QEMU_DOMAIN_H__ */
......@@ -44,6 +44,7 @@
<interface type='network'>
<mac address='52:54:00:24:a5:9f'/>
<source network='default'/>
<model type='rtl8139'/>
<bandwidth>
<inbound average='1000' peak='4000' burst='1024'/>
<outbound average='128' peak='256' burst='32768'/>
......
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\
macaddr=52:54:00:8c:b9:05,vlan=0 -net socket,connect=192.168.0.1:5558,vlan=0 \
-serial none -parallel none
macaddr=52:54:00:8c:b9:05,vlan=0,model=rtl8139 -net socket,\
connect=192.168.0.1:5558,vlan=0 -serial none -parallel none
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\
macaddr=00:11:22:33:44:55,vlan=0 -net tap,ifname=nic02,script=/etc/qemu-ifup,\
vlan=0 -serial none -parallel none
macaddr=00:11:22:33:44:55,vlan=0,model=rtl8139 -net tap,ifname=nic02,\
script=/etc/qemu-ifup,vlan=0 -serial none -parallel none
......@@ -25,6 +25,7 @@
<mac address='00:11:22:33:44:55'/>
<script path='/etc/qemu-ifup'/>
<target dev='nic02'/>
<model type='rtl8139'/>
</interface>
<memballoon model='virtio'/>
</devices>
......
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\
macaddr=00:11:22:33:44:55,vlan=0,name=net0 -net tap,script=/etc/qemu-ifup,\
vlan=0,name=hostnet0 -net nic,macaddr=00:11:22:33:44:56,vlan=1,model=e1000,\
name=net1 -net tap,script=/etc/qemu-ifup,vlan=1,name=hostnet1 -serial none \
-parallel none
macaddr=00:11:22:33:44:55,vlan=0,model=rtl8139,name=net0 -net tap,\
script=/etc/qemu-ifup,vlan=0,name=hostnet0 -net nic,macaddr=00:11:22:33:44:56,\
vlan=1,model=e1000,name=net1 -net tap,script=/etc/qemu-ifup,vlan=1,name=hostnet1 \
-serial none -parallel none
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\
macaddr=00:11:22:33:44:55,vlan=0 -net tap,script=/etc/qemu-ifup,vlan=0 -serial \
none -parallel none
macaddr=00:11:22:33:44:55,vlan=0,model=rtl8139 -net tap,script=/etc/qemu-ifup,\
vlan=0 -serial none -parallel none
......@@ -24,6 +24,7 @@
<interface type='ethernet'>
<mac address='00:11:22:33:44:55'/>
<script path='/etc/qemu-ifup'/>
<model type='rtl8139'/>
</interface>
<memballoon model='virtio'/>
</devices>
......
......@@ -32,6 +32,7 @@
<virtualport type='802.1Qbg'>
<parameters managerid='11' typeid='1193047' typeidversion='2' instanceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/>
</virtualport>
<model type='rtl8139'/>
</interface>
<memballoon model='virtio'/>
</devices>
......
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\
macaddr=52:54:00:8c:b9:05,vlan=0 -net socket,mcast=192.0.0.1:5558,vlan=0 \
-serial none -parallel none
macaddr=52:54:00:8c:b9:05,vlan=0,model=rtl8139 -net socket,mcast=192.0.0.1:5558,\
vlan=0 -serial none -parallel none
......@@ -32,6 +32,7 @@
<virtualport type='openvswitch'>
<parameters interfaceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f' profileid='bob'/>
</virtualport>
<model type='rtl8139'/>
</interface>
<memballoon model='virtio'/>
</devices>
......
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\
macaddr=52:54:00:8c:b9:05,vlan=0 -net socket,listen=192.168.0.1:5558,vlan=0 \
-serial none -parallel none
macaddr=52:54:00:8c:b9:05,vlan=0,model=rtl8139 -net socket,\
listen=192.168.0.1:5558,vlan=0 -serial none -parallel none
LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
-no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\
macaddr=00:11:22:33:44:55,vlan=0 -net user,vlan=0 -serial none -parallel none
macaddr=00:11:22:33:44:55,vlan=0,model=rtl8139 -net user,vlan=0 -serial none \
-parallel none
......@@ -23,6 +23,7 @@
<controller type='ide' index='0'/>
<interface type='user'>
<mac address='00:11:22:33:44:55'/>
<model type='rtl8139'/>
</interface>
<memballoon model='virtio'/>
</devices>
......
......@@ -38,6 +38,7 @@
<virtualport>
<parameters instanceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f' interfaceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/>
</virtualport>
<model type='rtl8139'/>
</interface>
<interface type='network'>
<mac address='22:11:22:33:44:55'/>
......@@ -45,6 +46,7 @@
<virtualport type='802.1Qbh'>
<parameters profileid='testhis99'/>
</virtualport>
<model type='rtl8139'/>
</interface>
<memballoon model='virtio'/>
</devices>
......
......@@ -62,6 +62,7 @@
<interface type='ethernet'>
<mac address='52:54:00:71:70:89'/>
<script path='/etc/qemu-ifup'/>
<model type='rtl8139'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</interface>
<serial type='pty'>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册