mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-11 16:00:50 -07:00
qdev: Catch attempt to attach more than one device to a netdev
Guest device and host netdev are peers, i.e. it's a 1:1 relation.
However, we fail to enforce that:
$ qemu -nodefaults --nographic -netdev user,id=net0 -device e1000,netdev=net0 -device virtio-net-pci,netdev=net0 -monitor stdio
QEMU 0.12.50 monitor - type 'help' for more information
(qemu) info network
Devices not on any VLAN:
net0: net=10.0.2.0, restricted=n peer=virtio-net-pci.0
e1000.0: model=e1000,macaddr=52:54:00:12:34:56 peer=net0
virtio-net-pci.0: model=virtio-net-pci,macaddr=52:54:00:12:34:57 peer=net0
It's all downhill from there.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
6bf38816df
commit
27f3f8a362
2 changed files with 8 additions and 0 deletions
|
|
@ -341,6 +341,9 @@ static int parse_netdev(DeviceState *dev, Property *prop, const char *str)
|
||||||
*ptr = qemu_find_netdev(str);
|
*ptr = qemu_find_netdev(str);
|
||||||
if (*ptr == NULL)
|
if (*ptr == NULL)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
if ((*ptr)->peer) {
|
||||||
|
return -EEXIST;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -557,6 +560,10 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
|
||||||
ret = prop->info->parse(dev, prop, value);
|
ret = prop->info->parse(dev, prop, value);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
|
case -EEXIST:
|
||||||
|
fprintf(stderr, "property \"%s.%s\": \"%s\" is already in use\n",
|
||||||
|
dev->info->name, name, value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
case -EINVAL:
|
case -EINVAL:
|
||||||
fprintf(stderr, "property \"%s.%s\": failed to parse \"%s\"\n",
|
fprintf(stderr, "property \"%s.%s\": failed to parse \"%s\"\n",
|
||||||
|
|
|
||||||
1
net.c
1
net.c
|
|
@ -246,6 +246,7 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info,
|
||||||
QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next);
|
QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next);
|
||||||
} else {
|
} else {
|
||||||
if (peer) {
|
if (peer) {
|
||||||
|
assert(!peer->peer);
|
||||||
vc->peer = peer;
|
vc->peer = peer;
|
||||||
peer->peer = vc;
|
peer->peer = vc;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue