* [Qemu-devel] [PATCH 1/7] net: remove NICInfo::vc
2009-11-12 20:28 [Qemu-devel] [RFC PATCH 0/7] Fix qemu_announce_self() properly Mark McLoughlin
@ 2009-11-12 20:28 ` Mark McLoughlin
2009-11-12 20:28 ` [Qemu-devel] [PATCH 2/7] qdev: add "net-client" property Mark McLoughlin
` (5 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Mark McLoughlin @ 2009-11-12 20:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Mark McLoughlin, kraxel, quintela
Since 1cc33683, this field is not set for most devices, so just
remove it and its remaining few uses.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
hw/dp8393x.c | 10 +++++-----
hw/etraxfs_eth.c | 10 +++++-----
hw/mcf_fec.c | 10 +++++-----
hw/mipsnet.c | 10 +++++-----
hw/usb-net.c | 14 +++++++-------
net.h | 1 -
6 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index ae8b16e..5143cc8 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -889,11 +889,11 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s);
s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */
- s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- nic_can_receive, nic_receive, NULL, NULL,
- nic_cleanup, s);
+ s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+ nd->vlan, nd->netdev,
+ nd->model, nd->name,
+ nic_can_receive, nic_receive, NULL, NULL,
+ nic_cleanup, s);
qemu_format_nic_info_str(s->vc, nd->macaddr);
qemu_register_reset(nic_reset, s);
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index ffe7082..2cc2332 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -590,11 +590,11 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr)
eth->ethregs = cpu_register_io_memory(eth_read, eth_write, eth);
cpu_register_physical_memory (base, 0x5c, eth->ethregs);
- eth->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- eth_can_receive, eth_receive,
- NULL, NULL, eth_cleanup, eth);
+ eth->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+ nd->vlan, nd->netdev,
+ nd->model, nd->name,
+ eth_can_receive, eth_receive,
+ NULL, NULL, eth_cleanup, eth);
eth->vc->opaque = eth;
eth->vc->link_status_changed = eth_set_link;
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 9f0d0f4..8242c8a 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -462,11 +462,11 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
mcf_fec_writefn, s);
cpu_register_physical_memory(base, 0x400, s->mmio_index);
- s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- mcf_fec_can_receive, mcf_fec_receive,
- NULL, NULL, mcf_fec_cleanup, s);
+ s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+ nd->vlan, nd->netdev,
+ nd->model, nd->name,
+ mcf_fec_can_receive, mcf_fec_receive,
+ NULL, NULL, mcf_fec_cleanup, s);
memcpy(s->macaddr, nd->macaddr, 6);
qemu_format_nic_info_str(s->vc, s->macaddr);
}
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 65e1d59..67160a4 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -263,11 +263,11 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
s->io_base = base;
s->irq = irq;
if (nd) {
- s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- mipsnet_can_receive, mipsnet_receive,
- NULL, NULL, mipsnet_cleanup, s);
+ s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+ nd->vlan, nd->netdev,
+ nd->model, nd->name,
+ mipsnet_can_receive, mipsnet_receive,
+ NULL, NULL, mipsnet_cleanup, s);
} else {
s->vc = NULL;
}
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 9c6549c..7b8cc7a 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1460,13 +1460,13 @@ USBDevice *usb_net_init(NICInfo *nd)
memcpy(s->mac, nd->macaddr, 6);
- s->vc = nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- usbnet_can_receive,
- usbnet_receive,
- NULL, NULL,
- usbnet_cleanup, s);
+ s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+ nd->vlan, nd->netdev,
+ nd->model, nd->name,
+ usbnet_can_receive,
+ usbnet_receive,
+ NULL, NULL,
+ usbnet_cleanup, s);
qemu_format_nic_info_str(s->vc, s->mac);
diff --git a/net.h b/net.h
index 4ffce91..aa4b78a 100644
--- a/net.h
+++ b/net.h
@@ -124,7 +124,6 @@ struct NICInfo {
char *devaddr;
VLANState *vlan;
VLANClientState *netdev;
- VLANClientState *vc;
void *private;
int used;
int bootable;
--
1.6.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 2/7] qdev: add "net-client" property
2009-11-12 20:28 [Qemu-devel] [RFC PATCH 0/7] Fix qemu_announce_self() properly Mark McLoughlin
2009-11-12 20:28 ` [Qemu-devel] [PATCH 1/7] net: remove NICInfo::vc Mark McLoughlin
@ 2009-11-12 20:28 ` Mark McLoughlin
2009-11-16 9:03 ` [Qemu-devel] " Gerd Hoffmann
2009-11-12 20:28 ` [Qemu-devel] [PATCH 3/7] net: create the VLANClientState for NICs early Mark McLoughlin
` (4 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Mark McLoughlin @ 2009-11-12 20:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Mark McLoughlin, kraxel, quintela
Rather than having each NIC create it's own client, let's create the
client early and pass it down to the NIC.
One advantage is that we can add parameters which only the client
knows about, without having the NIC know anything about it - e.g. NICs
shouldn't know about netdev vs. vlan.
Another advantage is that we can easily get the client associated with
a qdev.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
hw/qdev-properties.c | 25 +++++++++++++++++++++++++
hw/qdev.h | 5 +++++
net.h | 8 +++++---
3 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index bda6699..8ce0de7 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -279,6 +279,26 @@ PropertyInfo qdev_prop_chr = {
.print = print_chr,
};
+/* --- network client object --- */
+
+static int print_net_client(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+ VLANClientState **ptr = qdev_get_prop_ptr(dev, prop);
+
+ if (*ptr && (*ptr)->name) {
+ return snprintf(dest, len, "%s", (*ptr)->name);
+ } else {
+ return snprintf(dest, len, "<null>");
+ }
+}
+
+PropertyInfo qdev_prop_net_client = {
+ .name = "net-client",
+ .type = PROP_TYPE_NET_CLIENT,
+ .size = sizeof(VLANClientState*),
+ .print = print_net_client,
+};
+
/* --- netdev device --- */
static int parse_netdev(DeviceState *dev, Property *prop, const char *str)
@@ -558,6 +578,11 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu
qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
}
+void qdev_prop_set_net_client(DeviceState *dev, const char *name, VLANClientState *value)
+{
+ qdev_prop_set(dev, name, &value, PROP_TYPE_NET_CLIENT);
+}
+
void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
{
qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
diff --git a/hw/qdev.h b/hw/qdev.h
index 41642ee..3e1510f 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -79,6 +79,7 @@ enum PropertyType {
PROP_TYPE_DRIVE,
PROP_TYPE_CHR,
PROP_TYPE_STRING,
+ PROP_TYPE_NET_CLIENT,
PROP_TYPE_NETDEV,
PROP_TYPE_VLAN,
PROP_TYPE_PTR,
@@ -194,6 +195,7 @@ extern PropertyInfo qdev_prop_chr;
extern PropertyInfo qdev_prop_ptr;
extern PropertyInfo qdev_prop_macaddr;
extern PropertyInfo qdev_prop_drive;
+extern PropertyInfo qdev_prop_net_client;
extern PropertyInfo qdev_prop_netdev;
extern PropertyInfo qdev_prop_vlan;
extern PropertyInfo qdev_prop_pci_devfn;
@@ -235,6 +237,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
#define DEFINE_PROP_STRING(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
+#define DEFINE_PROP_NET_CLIENT(_n, _s, _f) \
+ DEFINE_PROP(_n, _s, _f, qdev_prop_net_client, VLANClientState *)
#define DEFINE_PROP_NETDEV(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
#define DEFINE_PROP_VLAN(_n, _s, _f) \
@@ -258,6 +262,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
+void qdev_prop_set_net_client(DeviceState *dev, const char *name, VLANClientState *value);
void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
diff --git a/net.h b/net.h
index aa4b78a..d7235bb 100644
--- a/net.h
+++ b/net.h
@@ -14,15 +14,17 @@ struct MACAddr {
/* qdev nic properties */
typedef struct NICConf {
+ VLANClientState *client;
MACAddr macaddr;
VLANState *vlan;
VLANClientState *peer;
} NICConf;
#define DEFINE_NIC_PROPERTIES(_state, _conf) \
- DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
- DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \
- DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
+ DEFINE_PROP_NET_CLIENT("net-client", _state, _conf.client), \
+ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
+ DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \
+ DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
/* VLANs support */
--
1.6.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] Re: [PATCH 2/7] qdev: add "net-client" property
2009-11-12 20:28 ` [Qemu-devel] [PATCH 2/7] qdev: add "net-client" property Mark McLoughlin
@ 2009-11-16 9:03 ` Gerd Hoffmann
0 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2009-11-16 9:03 UTC (permalink / raw)
To: Mark McLoughlin; +Cc: qemu-devel, quintela
On 11/12/09 21:28, Mark McLoughlin wrote:
> Rather than having each NIC create it's own client, let's create the
> client early and pass it down to the NIC.
'-device $nic,net-client=$name' doesn't work ...
> One advantage is that we can add parameters which only the client
> knows about, without having the NIC know anything about it - e.g. NICs
> shouldn't know about netdev vs. vlan.
What this is needed for?
> Another advantage is that we can easily get the client associated with
> a qdev.
Looks like this is the *real* reason ...
cheers,
Gerd
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 3/7] net: create the VLANClientState for NICs early
2009-11-12 20:28 [Qemu-devel] [RFC PATCH 0/7] Fix qemu_announce_self() properly Mark McLoughlin
2009-11-12 20:28 ` [Qemu-devel] [PATCH 1/7] net: remove NICInfo::vc Mark McLoughlin
2009-11-12 20:28 ` [Qemu-devel] [PATCH 2/7] qdev: add "net-client" property Mark McLoughlin
@ 2009-11-12 20:28 ` Mark McLoughlin
2009-11-16 9:26 ` [Qemu-devel] " Gerd Hoffmann
2009-11-12 20:28 ` [Qemu-devel] [PATCH 4/7] net: kill off NICInfo/NICConf::vlan/netdev Mark McLoughlin
` (3 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Mark McLoughlin @ 2009-11-12 20:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Mark McLoughlin, kraxel, quintela
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
hw/dp8393x.c | 10 +++++-----
hw/e1000.c | 10 +++++-----
hw/eepro100.c | 10 +++++-----
hw/etraxfs_eth.c | 11 +++++------
hw/mcf_fec.c | 10 +++++-----
hw/mipsnet.c | 15 ++++++---------
hw/musicpal.c | 10 +++++-----
hw/ne2000-isa.c | 10 ++++++----
hw/ne2000.c | 11 +++++++----
hw/pcnet.c | 10 +++++-----
hw/qdev.c | 3 +++
hw/rtl8139.c | 11 ++++++-----
hw/smc91c111.c | 11 ++++++-----
hw/stellaris_enet.c | 12 ++++++------
hw/usb-net.c | 12 +++++-------
hw/virtio-net.c | 11 ++++++-----
hw/xilinx_ethlite.c | 10 +++++-----
net.c | 5 +++++
net.h | 1 +
19 files changed, 97 insertions(+), 86 deletions(-)
diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index 5143cc8..7145ad5 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -889,11 +889,11 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s);
s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- nic_can_receive, nic_receive, NULL, NULL,
- nic_cleanup, s);
+ s->vc = nd->vc;
+ s->vc->opaque = s;
+ s->vc->receive = nic_receive;
+ s->vc->can_receive = nic_can_receive;
+ s->vc->cleanup = nic_cleanup;
qemu_format_nic_info_str(s->vc, nd->macaddr);
qemu_register_reset(nic_reset, s);
diff --git a/hw/e1000.c b/hw/e1000.c
index 00f6a57..d9c9f79 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1107,11 +1107,11 @@ static int pci_e1000_init(PCIDevice *pci_dev)
checksum = (uint16_t) EEPROM_SUM - checksum;
d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
- d->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- d->conf.vlan, d->conf.peer,
- d->dev.qdev.info->name, d->dev.qdev.id,
- e1000_can_receive, e1000_receive, NULL,
- NULL, e1000_cleanup, d);
+ d->vc = d->conf.client;
+ d->vc->opaque = d;
+ d->vc->can_receive = e1000_can_receive;
+ d->vc->receive = e1000_receive;
+ d->vc->cleanup = e1000_cleanup;
d->vc->link_status_changed = e1000_set_link_status;
qemu_format_nic_info_str(d->vc, macaddr);
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 8734907..2608f31 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1829,11 +1829,11 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)
nic_reset(s);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- s->conf.vlan, s->conf.peer,
- pci_dev->qdev.info->name, pci_dev->qdev.id,
- nic_can_receive, nic_receive, NULL, NULL,
- nic_cleanup, s);
+ s->vc = s->conf.client;
+ s->vc->opaque = s;
+ s->vc->can_receive = nic_can_receive;
+ s->vc->receive = nic_receive;
+ s->vc->cleanup = nic_cleanup;
qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
TRACE(OTHER, logout("%s\n", s->vc->info_str));
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index 2cc2332..f958d62 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -590,12 +590,11 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr)
eth->ethregs = cpu_register_io_memory(eth_read, eth_write, eth);
cpu_register_physical_memory (base, 0x5c, eth->ethregs);
- eth->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- eth_can_receive, eth_receive,
- NULL, NULL, eth_cleanup, eth);
- eth->vc->opaque = eth;
+ eth->vc = nd->vc;
+ eth->vc->opaque = eth;
+ eth->vc->receive = eth_receive;
+ eth->vc->can_receive = eth_can_receive;
+ eth->vc->cleanup = eth_cleanup;
eth->vc->link_status_changed = eth_set_link;
return dma;
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 8242c8a..d1e57c8 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -462,11 +462,11 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
mcf_fec_writefn, s);
cpu_register_physical_memory(base, 0x400, s->mmio_index);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- mcf_fec_can_receive, mcf_fec_receive,
- NULL, NULL, mcf_fec_cleanup, s);
+ s->vc = nd->vc;
+ s->vc->opaque = s;
+ s->vc->receive = mcf_fec_receive;
+ s->vc->can_receive = mcf_fec_can_receive;
+ s->vc->cleanup = mcf_fec_cleanup;
memcpy(s->macaddr, nd->macaddr, 6);
qemu_format_nic_info_str(s->vc, s->macaddr);
}
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 67160a4..c630890 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -262,15 +262,12 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
s->io_base = base;
s->irq = irq;
- if (nd) {
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- mipsnet_can_receive, mipsnet_receive,
- NULL, NULL, mipsnet_cleanup, s);
- } else {
- s->vc = NULL;
- }
+
+ s->vc = nd->vc;
+ s->vc->opaque = s;
+ s->vc->receive = mipsnet_receive;
+ s->vc->can_receive = mipsnet_can_receive;
+ s->vc->cleanup = mipsnet_cleanup;
qemu_format_nic_info_str(s->vc, nd->macaddr);
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 0d21f17..a32eed6 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -377,11 +377,11 @@ static int mv88w8618_eth_init(SysBusDevice *dev)
mv88w8618_eth_state *s = FROM_SYSBUS(mv88w8618_eth_state, dev);
sysbus_init_irq(dev, &s->irq);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- s->conf.vlan, s->conf.peer,
- dev->qdev.info->name, dev->qdev.id,
- eth_can_receive, eth_receive, NULL,
- NULL, eth_cleanup, s);
+ s->vc = s->conf.client;
+ s->vc->opaque = s;
+ s->vc->receive = eth_receive;
+ s->vc->can_receive = eth_can_receive;
+ s->vc->cleanup = eth_cleanup;
s->mmio_index = cpu_register_io_memory(mv88w8618_eth_readfn,
mv88w8618_eth_writefn, s);
sysbus_init_mmio(dev, MP_ETH_SIZE, s->mmio_index);
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 729e8e2..6ea80c2 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -63,10 +63,12 @@ static int isa_ne2000_initfn(ISADevice *dev)
qemu_macaddr_default_if_unset(&s->c.macaddr);
ne2000_reset(s);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, s->c.vlan, s->c.peer,
- dev->qdev.info->name, dev->qdev.id,
- ne2000_can_receive, ne2000_receive, NULL,
- NULL, isa_ne2000_cleanup, s);
+ s->vc = s->c.client;
+ s->vc->opaque = s;
+ s->vc->receive = ne2000_receive;
+ s->vc->can_receive = ne2000_can_receive;
+ s->vc->cleanup = isa_ne2000_cleanup;
+
qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
vmstate_register(-1, &vmstate_ne2000, s);
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 63efc3a..19f52ad 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -725,10 +725,13 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
qemu_macaddr_default_if_unset(&s->c.macaddr);
ne2000_reset(s);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, s->c.vlan, s->c.peer,
- pci_dev->qdev.info->name, pci_dev->qdev.id,
- ne2000_can_receive, ne2000_receive, NULL,
- NULL, ne2000_cleanup, s);
+
+ s->vc = s->c.client;
+ s->vc->opaque = s;
+ s->vc->receive = ne2000_receive;
+ s->vc->can_receive = ne2000_can_receive;
+ s->vc->cleanup = ne2000_cleanup;
+
qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
if (!pci_dev->qdev.hotplugged) {
diff --git a/hw/pcnet.c b/hw/pcnet.c
index ee3db09..18da141 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1897,11 +1897,11 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s,
s->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s);
qemu_macaddr_default_if_unset(&s->conf.macaddr);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- s->conf.vlan, s->conf.peer,
- dev->info->name, dev->id,
- pcnet_can_receive, pcnet_receive, NULL, NULL,
- cleanup, s);
+ s->vc = s->conf.client;
+ s->vc->opaque = s;
+ s->vc->receive = pcnet_receive;
+ s->vc->can_receive = pcnet_can_receive;
+ s->vc->cleanup = cleanup;
qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
return 0;
}
diff --git a/hw/qdev.c b/hw/qdev.c
index d19d531..757b285 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -366,6 +366,9 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin)
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
{
qdev_prop_set_macaddr(dev, "mac", nd->macaddr);
+ if (nd->vc) {
+ qdev_prop_set_net_client(dev, "net-client", nd->vc);
+ }
if (nd->vlan)
qdev_prop_set_vlan(dev, "vlan", nd->vlan);
if (nd->netdev)
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index c166db0..f2c8adb 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3332,11 +3332,12 @@ static int pci_rtl8139_init(PCIDevice *dev)
qemu_macaddr_default_if_unset(&s->conf.macaddr);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- s->conf.vlan, s->conf.peer,
- dev->qdev.info->name, dev->qdev.id,
- rtl8139_can_receive, rtl8139_receive, NULL,
- NULL, rtl8139_cleanup, s);
+ s->vc = s->conf.client;
+ s->vc->opaque = s;
+ s->vc->receive = rtl8139_receive;
+ s->vc->can_receive = rtl8139_can_receive;
+ s->vc->cleanup = rtl8139_cleanup;
+
qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
s->cplus_txbuffer = NULL;
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index b7398c9..410393c 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -711,11 +711,12 @@ static int smc91c111_init1(SysBusDevice *dev)
smc91c111_reset(s);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- s->conf.vlan, s->conf.peer,
- dev->qdev.info->name, dev->qdev.id,
- smc91c111_can_receive, smc91c111_receive, NULL,
- NULL, smc91c111_cleanup, s);
+ s->vc = s->conf.client;
+ s->vc->opaque = s;
+ s->vc->receive = smc91c111_receive;
+ s->vc->can_receive = smc91c111_can_receive;
+ s->vc->cleanup = smc91c111_cleanup;
+
qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
/* ??? Save/restore. */
return 0;
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index 2252f1a..432c4ed 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -406,12 +406,12 @@ static int stellaris_enet_init(SysBusDevice *dev)
sysbus_init_irq(dev, &s->irq);
qemu_macaddr_default_if_unset(&s->conf.macaddr);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- s->conf.vlan, s->conf.peer,
- dev->qdev.info->name, dev->qdev.id,
- stellaris_enet_can_receive,
- stellaris_enet_receive, NULL, NULL,
- stellaris_enet_cleanup, s);
+ s->vc = s->conf.client;
+ s->vc->opaque = s;
+ s->vc->receive = stellaris_enet_receive;
+ s->vc->can_receive = stellaris_enet_can_receive;
+ s->vc->cleanup = stellaris_enet_cleanup;
+
qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
stellaris_enet_reset(s);
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 7b8cc7a..2d8e79f 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1460,13 +1460,11 @@ USBDevice *usb_net_init(NICInfo *nd)
memcpy(s->mac, nd->macaddr, 6);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
- nd->model, nd->name,
- usbnet_can_receive,
- usbnet_receive,
- NULL, NULL,
- usbnet_cleanup, s);
+ s->vc = nd->vc;
+ s->vc->opaque = s;
+ s->vc->receive = usbnet_receive;
+ s->vc->can_receive = usbnet_can_receive;
+ s->vc->cleanup = usbnet_cleanup;
qemu_format_nic_info_str(s->vc, s->mac);
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 2f147e5..94f8616 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -839,11 +839,12 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf)
qemu_macaddr_default_if_unset(&conf->macaddr);
memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
n->status = VIRTIO_NET_S_LINK_UP;
- n->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, conf->vlan, conf->peer,
- dev->info->name, dev->id,
- virtio_net_can_receive,
- virtio_net_receive, NULL, NULL,
- virtio_net_cleanup, n);
+
+ n->vc = conf->client;
+ n->vc->opaque = n;
+ n->vc->can_receive = virtio_net_can_receive;
+ n->vc->receive = virtio_net_receive;
+ n->vc->cleanup = virtio_net_cleanup;
n->vc->link_status_changed = virtio_net_set_link_status;
qemu_format_nic_info_str(n->vc, conf->macaddr.a);
diff --git a/hw/xilinx_ethlite.c b/hw/xilinx_ethlite.c
index b7129d5..af3978d 100644
--- a/hw/xilinx_ethlite.c
+++ b/hw/xilinx_ethlite.c
@@ -220,11 +220,11 @@ static int xilinx_ethlite_init(SysBusDevice *dev)
sysbus_init_mmio(dev, R_MAX * 4, regs);
qemu_macaddr_default_if_unset(&s->conf.macaddr);
- s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- s->conf.vlan, s->conf.peer,
- dev->qdev.info->name, dev->qdev.id,
- eth_can_rx, eth_rx, NULL,
- NULL, eth_cleanup, s);
+ s->vc = s->conf.client;
+ s->vc->opaque = s;
+ s->vc->receive = eth_rx;
+ s->vc->can_receive = eth_can_rx;
+ s->vc->cleanup = eth_cleanup;
qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
return 0;
}
diff --git a/net.c b/net.c
index 9ea66e3..e90084d 100644
--- a/net.c
+++ b/net.c
@@ -2107,6 +2107,11 @@ static int net_init_nic(QemuOpts *opts,
return -1;
}
+ nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
+ nd->vlan, nd->netdev,
+ nd->model, nd->name,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL);
nd->used = 1;
if (vlan) {
nd->vlan->nb_guest_devs++;
diff --git a/net.h b/net.h
index d7235bb..83e50ab 100644
--- a/net.h
+++ b/net.h
@@ -126,6 +126,7 @@ struct NICInfo {
char *devaddr;
VLANState *vlan;
VLANClientState *netdev;
+ VLANClientState *vc;
void *private;
int used;
int bootable;
--
1.6.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] Re: [PATCH 3/7] net: create the VLANClientState for NICs early
2009-11-12 20:28 ` [Qemu-devel] [PATCH 3/7] net: create the VLANClientState for NICs early Mark McLoughlin
@ 2009-11-16 9:26 ` Gerd Hoffmann
0 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2009-11-16 9:26 UTC (permalink / raw)
To: Mark McLoughlin; +Cc: qemu-devel, quintela
Hi,
> diff --git a/hw/e1000.c b/hw/e1000.c
> index 00f6a57..d9c9f79 100644
> --- a/hw/e1000.c
> +++ b/hw/e1000.c
> @@ -1107,11 +1107,11 @@ static int pci_e1000_init(PCIDevice *pci_dev)
> checksum = (uint16_t) EEPROM_SUM - checksum;
> d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
>
> - d->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
> - d->conf.vlan, d->conf.peer,
> - d->dev.qdev.info->name, d->dev.qdev.id,
> - e1000_can_receive, e1000_receive, NULL,
> - NULL, e1000_cleanup, d);
> + d->vc = d->conf.client;
> + d->vc->opaque = d;
> + d->vc->can_receive = e1000_can_receive;
> + d->vc->receive = e1000_receive;
> + d->vc->cleanup = e1000_cleanup;
> d->vc->link_status_changed = e1000_set_link_status;
>
> qemu_format_nic_info_str(d->vc, macaddr);
... and now -device $nic,args is completely broken.
There are netdev, vlan and net-client properties but none of them will work.
If you want to have net.c prepare vlanclientstate (there might be good
reasons for it), then it must be properly:
* Create a named vlanclientstate.
* Have drivers lookup the vlanclientstate by name. Pretty much like
the netdev peer lookup works today, only with the difference that
it is used directly instead of being passed as peer on vlanclient
creation.
i.e. something like
-netdev client,id=foo,<moreargs>
-device e1000,client=foo,mac=11:22:33:44:55:66
It is probably a good idea to zap the vlan and netdev properties then,
so we don't have tons of different ways to setup a nic. Fortunaly we
had no release with the vlan+netdev properties yet, so this shouldn't be
a backward compatibility issue IMHO.
Also take care that the creation and destruction is symmetric. If net.c
creates the vlanclient it should also net.c's job to clean it up, i.e.
all the qemu_del_vlan_client() calls in the nic drivers should go away,
otherwise hotplug will have some unpleasant surprises for you.
cheers,
Gerd
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 4/7] net: kill off NICInfo/NICConf::vlan/netdev
2009-11-12 20:28 [Qemu-devel] [RFC PATCH 0/7] Fix qemu_announce_self() properly Mark McLoughlin
` (2 preceding siblings ...)
2009-11-12 20:28 ` [Qemu-devel] [PATCH 3/7] net: create the VLANClientState for NICs early Mark McLoughlin
@ 2009-11-12 20:28 ` Mark McLoughlin
2009-11-12 20:29 ` [Qemu-devel] [PATCH 5/7] qdev: add qdev_foreach() Mark McLoughlin
` (2 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Mark McLoughlin @ 2009-11-12 20:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Mark McLoughlin, kraxel, quintela
No valid users left except the announce_self() code which currently
crashes when used with -netdev.
Note the assertion in the xen code. Need to figure out how to support
the -netdev arg with xen.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
hw/integratorcp.c | 3 +-
hw/mcf5208.c | 3 +-
hw/mips_mipssim.c | 3 +-
hw/mips_r4k.c | 3 +-
hw/qdev-properties.c | 75 --------------------------------------------------
hw/qdev.c | 4 --
hw/qdev.h | 10 ------
hw/syborg.c | 2 +-
hw/xen_devconfig.c | 9 +++--
net.c | 20 ++++++------
net.h | 8 +----
savevm.c | 4 ++
12 files changed, 29 insertions(+), 115 deletions(-)
diff --git a/hw/integratorcp.c b/hw/integratorcp.c
index bee8298..9ce141d 100644
--- a/hw/integratorcp.c
+++ b/hw/integratorcp.c
@@ -497,8 +497,9 @@ static void integratorcp_init(ram_addr_t ram_size,
sysbus_create_simple("pl050_keyboard", 0x18000000, pic[3]);
sysbus_create_simple("pl050_mouse", 0x19000000, pic[4]);
sysbus_create_varargs("pl181", 0x1c000000, pic[23], pic[24], NULL);
- if (nd_table[0].vlan)
+ if (nd_table[0].used) {
smc91c111_init(&nd_table[0], 0xc8000000, pic[27]);
+ }
sysbus_create_simple("pl110", 0xc0000000, pic[22]);
diff --git a/hw/mcf5208.c b/hw/mcf5208.c
index 5598611..a939cb0 100644
--- a/hw/mcf5208.c
+++ b/hw/mcf5208.c
@@ -239,8 +239,9 @@ static void mcf5208evb_init(ram_addr_t ram_size,
fprintf(stderr, "Too many NICs\n");
exit(1);
}
- if (nd_table[0].vlan)
+ if (nd_table[0].used) {
mcf_fec_init(&nd_table[0], 0xfc030000, pic + 36);
+ }
/* 0xfc000000 SCM. */
/* 0xfc004000 XBS. */
diff --git a/hw/mips_mipssim.c b/hw/mips_mipssim.c
index 9aed40e..5cdfe00 100644
--- a/hw/mips_mipssim.c
+++ b/hw/mips_mipssim.c
@@ -187,9 +187,10 @@ mips_mipssim_init (ram_addr_t ram_size,
if (serial_hds[0])
serial_init(0x3f8, env->irq[4], 115200, serial_hds[0]);
- if (nd_table[0].vlan)
+ if (nd_table[0].used) {
/* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */
mipsnet_init(0x4200, env->irq[2], &nd_table[0]);
+ }
}
static QEMUMachine mips_mipssim_machine = {
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index d525c63..442eda3 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -265,8 +265,9 @@ void mips_r4k_init (ram_addr_t ram_size,
isa_vga_init();
- if (nd_table[0].vlan)
+ if (nd_table[0].used) {
isa_ne2000_init(0x300, 9, &nd_table[0]);
+ }
if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
fprintf(stderr, "qemu: too many IDE bus\n");
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 8ce0de7..fe40813 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -299,71 +299,6 @@ PropertyInfo qdev_prop_net_client = {
.print = print_net_client,
};
-/* --- netdev device --- */
-
-static int parse_netdev(DeviceState *dev, Property *prop, const char *str)
-{
- VLANClientState **ptr = qdev_get_prop_ptr(dev, prop);
-
- *ptr = qemu_find_netdev(str);
- if (*ptr == NULL)
- return -1;
- return 0;
-}
-
-static int print_netdev(DeviceState *dev, Property *prop, char *dest, size_t len)
-{
- VLANClientState **ptr = qdev_get_prop_ptr(dev, prop);
-
- if (*ptr && (*ptr)->name) {
- return snprintf(dest, len, "%s", (*ptr)->name);
- } else {
- return snprintf(dest, len, "<null>");
- }
-}
-
-PropertyInfo qdev_prop_netdev = {
- .name = "netdev",
- .type = PROP_TYPE_NETDEV,
- .size = sizeof(VLANClientState*),
- .parse = parse_netdev,
- .print = print_netdev,
-};
-
-/* --- vlan --- */
-
-static int parse_vlan(DeviceState *dev, Property *prop, const char *str)
-{
- VLANState **ptr = qdev_get_prop_ptr(dev, prop);
- int id;
-
- if (sscanf(str, "%d", &id) != 1)
- return -1;
- *ptr = qemu_find_vlan(id, 1);
- if (*ptr == NULL)
- return -1;
- return 0;
-}
-
-static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len)
-{
- VLANState **ptr = qdev_get_prop_ptr(dev, prop);
-
- if (*ptr) {
- return snprintf(dest, len, "%d", (*ptr)->id);
- } else {
- return snprintf(dest, len, "<null>");
- }
-}
-
-PropertyInfo qdev_prop_vlan = {
- .name = "vlan",
- .type = PROP_TYPE_VLAN,
- .size = sizeof(VLANClientState*),
- .parse = parse_vlan,
- .print = print_vlan,
-};
-
/* --- pointer --- */
static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
@@ -583,16 +518,6 @@ void qdev_prop_set_net_client(DeviceState *dev, const char *name, VLANClientStat
qdev_prop_set(dev, name, &value, PROP_TYPE_NET_CLIENT);
}
-void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
-{
- qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
-}
-
-void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
-{
- qdev_prop_set(dev, name, &value, PROP_TYPE_VLAN);
-}
-
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
{
qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
diff --git a/hw/qdev.c b/hw/qdev.c
index 757b285..b8ab449 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -369,10 +369,6 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
if (nd->vc) {
qdev_prop_set_net_client(dev, "net-client", nd->vc);
}
- if (nd->vlan)
- qdev_prop_set_vlan(dev, "vlan", nd->vlan);
- if (nd->netdev)
- qdev_prop_set_netdev(dev, "netdev", nd->netdev);
if (nd->nvectors != NIC_NVECTORS_UNSPECIFIED &&
qdev_prop_exists(dev, "vectors")) {
qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
diff --git a/hw/qdev.h b/hw/qdev.h
index 3e1510f..26e372c 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -80,8 +80,6 @@ enum PropertyType {
PROP_TYPE_CHR,
PROP_TYPE_STRING,
PROP_TYPE_NET_CLIENT,
- PROP_TYPE_NETDEV,
- PROP_TYPE_VLAN,
PROP_TYPE_PTR,
};
@@ -196,8 +194,6 @@ extern PropertyInfo qdev_prop_ptr;
extern PropertyInfo qdev_prop_macaddr;
extern PropertyInfo qdev_prop_drive;
extern PropertyInfo qdev_prop_net_client;
-extern PropertyInfo qdev_prop_netdev;
-extern PropertyInfo qdev_prop_vlan;
extern PropertyInfo qdev_prop_pci_devfn;
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
@@ -239,10 +235,6 @@ extern PropertyInfo qdev_prop_pci_devfn;
DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
#define DEFINE_PROP_NET_CLIENT(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_net_client, VLANClientState *)
-#define DEFINE_PROP_NETDEV(_n, _s, _f) \
- DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
-#define DEFINE_PROP_VLAN(_n, _s, _f) \
- DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
#define DEFINE_PROP_MACADDR(_n, _s, _f) \
@@ -263,8 +255,6 @@ void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
void qdev_prop_set_net_client(DeviceState *dev, const char *name, VLANClientState *value);
-void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
-void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
/* FIXME: Remove opaque pointer properties. */
diff --git a/hw/syborg.c b/hw/syborg.c
index 2d08cb2..e6a888c 100644
--- a/hw/syborg.c
+++ b/hw/syborg.c
@@ -77,7 +77,7 @@ static void syborg_init(ram_addr_t ram_size,
sysbus_create_simple("syborg,serial", 0xC0008000, pic[7]);
sysbus_create_simple("syborg,serial", 0xC0009000, pic[8]);
- if (nd_table[0].vlan || nd_table[0].netdev) {
+ if (nd_table[0].used) {
DeviceState *dev;
SysBusDevice *s;
diff --git a/hw/xen_devconfig.c b/hw/xen_devconfig.c
index ea8f8c4..7bda4d0 100644
--- a/hw/xen_devconfig.c
+++ b/hw/xen_devconfig.c
@@ -126,15 +126,16 @@ int xen_config_dev_nic(NICInfo *nic)
snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
nic->macaddr[0], nic->macaddr[1], nic->macaddr[2],
nic->macaddr[3], nic->macaddr[4], nic->macaddr[5]);
- xen_be_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", nic->vlan->id, mac);
- xen_config_dev_dirs("vif", "qnic", nic->vlan->id, fe, be, sizeof(fe));
+ assert(nic->vc && nic->vc->vlan);
+ xen_be_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", nic->vc->vlan->id, mac);
+ xen_config_dev_dirs("vif", "qnic", nic->vc->vlan->id, fe, be, sizeof(fe));
/* frontend */
- xenstore_write_int(fe, "handle", nic->vlan->id);
+ xenstore_write_int(fe, "handle", nic->vc->vlan->id);
xenstore_write_str(fe, "mac", mac);
/* backend */
- xenstore_write_int(be, "handle", nic->vlan->id);
+ xenstore_write_int(be, "handle", nic->vc->vlan->id);
xenstore_write_str(be, "mac", mac);
/* common stuff */
diff --git a/net.c b/net.c
index e90084d..44416b3 100644
--- a/net.c
+++ b/net.c
@@ -2055,7 +2055,8 @@ static int net_init_nic(QemuOpts *opts,
{
int idx;
NICInfo *nd;
- const char *netdev;
+ const char *netdev_str;
+ VLANClientState *netdev = NULL;
idx = nic_get_free_idx();
if (idx == -1 || nb_nics >= MAX_NICS) {
@@ -2067,15 +2068,14 @@ static int net_init_nic(QemuOpts *opts,
memset(nd, 0, sizeof(*nd));
- if ((netdev = qemu_opt_get(opts, "netdev"))) {
- nd->netdev = qemu_find_netdev(netdev);
- if (!nd->netdev) {
- qemu_error("netdev '%s' not found\n", netdev);
+ if ((netdev_str = qemu_opt_get(opts, "netdev"))) {
+ netdev = qemu_find_netdev(netdev_str);
+ if (!netdev) {
+ qemu_error("netdev '%s' not found\n", netdev_str);
return -1;
}
} else {
assert(vlan);
- nd->vlan = vlan;
}
if (name) {
nd->name = qemu_strdup(name);
@@ -2108,13 +2108,13 @@ static int net_init_nic(QemuOpts *opts,
}
nd->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
- nd->vlan, nd->netdev,
+ vlan, netdev,
nd->model, nd->name,
NULL, NULL, NULL,
NULL, NULL, NULL);
nd->used = 1;
if (vlan) {
- nd->vlan->nb_guest_devs++;
+ vlan->nb_guest_devs++;
}
nb_nics++;
@@ -2651,8 +2651,8 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
void net_client_uninit(NICInfo *nd)
{
- if (nd->vlan) {
- nd->vlan->nb_guest_devs--;
+ if (nd->vc && nd->vc->vlan) {
+ nd->vc->vlan->nb_guest_devs--;
}
nb_nics--;
diff --git a/net.h b/net.h
index 83e50ab..53d643b 100644
--- a/net.h
+++ b/net.h
@@ -16,15 +16,11 @@ struct MACAddr {
typedef struct NICConf {
VLANClientState *client;
MACAddr macaddr;
- VLANState *vlan;
- VLANClientState *peer;
} NICConf;
#define DEFINE_NIC_PROPERTIES(_state, _conf) \
DEFINE_PROP_NET_CLIENT("net-client", _state, _conf.client), \
- DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
- DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \
- DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
+ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr)
/* VLANs support */
@@ -124,8 +120,6 @@ struct NICInfo {
char *model;
char *name;
char *devaddr;
- VLANState *vlan;
- VLANClientState *netdev;
VLANClientState *vc;
void *private;
int used;
diff --git a/savevm.c b/savevm.c
index 74f2c66..039740c 100644
--- a/savevm.c
+++ b/savevm.c
@@ -126,8 +126,10 @@ static int announce_self_create(uint8_t *buf,
static void qemu_announce_self_once(void *opaque)
{
int i, len;
+#ifdef FIXME
VLANState *vlan;
VLANClientState *vc;
+#endif
uint8_t buf[60];
static int count = SELF_ANNOUNCE_ROUNDS;
QEMUTimer *timer = *(QEMUTimer **)opaque;
@@ -136,10 +138,12 @@ static void qemu_announce_self_once(void *opaque)
if (!nd_table[i].used)
continue;
len = announce_self_create(buf, nd_table[i].macaddr);
+#ifdef FIXME
vlan = nd_table[i].vlan;
QTAILQ_FOREACH(vc, &vlan->clients, next) {
qemu_send_packet_raw(vc, buf, len);
}
+#endif
}
if (--count) {
/* delay 50ms, 150ms, 250ms, ... */
--
1.6.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 5/7] qdev: add qdev_foreach()
2009-11-12 20:28 [Qemu-devel] [RFC PATCH 0/7] Fix qemu_announce_self() properly Mark McLoughlin
` (3 preceding siblings ...)
2009-11-12 20:28 ` [Qemu-devel] [PATCH 4/7] net: kill off NICInfo/NICConf::vlan/netdev Mark McLoughlin
@ 2009-11-12 20:29 ` Mark McLoughlin
2009-11-16 9:28 ` [Qemu-devel] " Gerd Hoffmann
2009-11-12 20:29 ` [Qemu-devel] [PATCH 6/7] qdev: add qdev_prop_get_{macaddr, net_client}() Mark McLoughlin
2009-11-12 20:29 ` [Qemu-devel] [PATCH 7/7] net: fix qemu_announce_self() Mark McLoughlin
6 siblings, 1 reply; 15+ messages in thread
From: Mark McLoughlin @ 2009-11-12 20:29 UTC (permalink / raw)
To: qemu-devel; +Cc: Mark McLoughlin, kraxel, quintela
No doubt this is the worst idea ever, but the requirement is simple -
some way to iterate all NICs in the system.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
hw/qdev.c | 20 ++++++++++++++++++++
hw/qdev.h | 3 +++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index b8ab449..d6e3184 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -401,6 +401,26 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name)
return NULL;
}
+static void qdev_foreach_recursive(BusState *bus, qdev_foreach_func func, void *opaque)
+{
+ DeviceState *dev;
+
+ QLIST_FOREACH(dev, &bus->children, sibling) {
+ BusState *child;
+
+ func(dev, opaque);
+
+ QLIST_FOREACH(child, &dev->child_bus, sibling) {
+ qdev_foreach_recursive(child, func, opaque);
+ }
+ }
+}
+
+void qdev_foreach(qdev_foreach_func func, void *opaque)
+{
+ qdev_foreach_recursive(main_system_bus, func, opaque);
+}
+
static BusState *qbus_find_recursive(BusState *bus, const char *name,
const BusInfo *info)
{
diff --git a/hw/qdev.h b/hw/qdev.h
index 26e372c..712ae3b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -153,6 +153,9 @@ CharDriverState *qdev_init_chardev(DeviceState *dev);
BusState *qdev_get_parent_bus(DeviceState *dev);
+typedef void (*qdev_foreach_func)(DeviceState *dev, void *opaque);
+void qdev_foreach(qdev_foreach_func func, void *opaque);
+
/* Convert from a base type to a parent type, with compile time checking. */
#ifdef __GNUC__
#define DO_UPCAST(type, field, dev) ( __extension__ ( { \
--
1.6.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] Re: [PATCH 5/7] qdev: add qdev_foreach()
2009-11-12 20:29 ` [Qemu-devel] [PATCH 5/7] qdev: add qdev_foreach() Mark McLoughlin
@ 2009-11-16 9:28 ` Gerd Hoffmann
2009-11-20 14:20 ` Mark McLoughlin
0 siblings, 1 reply; 15+ messages in thread
From: Gerd Hoffmann @ 2009-11-16 9:28 UTC (permalink / raw)
To: Mark McLoughlin; +Cc: qemu-devel, quintela
On 11/12/09 21:29, Mark McLoughlin wrote:
> No doubt this is the worst idea ever, but the requirement is simple -
> some way to iterate all NICs in the system.
Doesn't have net.c a list of all vlanclientstates it could use instead?
cheers,
Gerd
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Qemu-devel] Re: [PATCH 5/7] qdev: add qdev_foreach()
2009-11-16 9:28 ` [Qemu-devel] " Gerd Hoffmann
@ 2009-11-20 14:20 ` Mark McLoughlin
2009-11-23 9:55 ` Gerd Hoffmann
0 siblings, 1 reply; 15+ messages in thread
From: Mark McLoughlin @ 2009-11-20 14:20 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-devel, quintela
Hi Gerd,
Thanks for looking, you're absolutely right that this approach just
isn't right with e.g. -device
On Mon, 2009-11-16 at 10:28 +0100, Gerd Hoffmann wrote:
> On 11/12/09 21:29, Mark McLoughlin wrote:
> > No doubt this is the worst idea ever, but the requirement is simple -
> > some way to iterate all NICs in the system.
>
> Doesn't have net.c a list of all vlanclientstates it could use instead?
It does, but there's currently no way of getting at each NIC's MAC
address.
I've pushed a series of patches to the fix-announce-self-rfc.v2 branch
on my tree:
http://repo.or.cz/w/qemu/markmc.git
The idea is to have a NICState struct:
struct NICState {
VLANClientState nc;
MACAddr *macaddr;
void *opaque;
};
and similar structs for each net backend.
This way we can have a qemu_foreach_nic() which iterates over each
client, checks whether it's a NIC and upcast to NICState.
Still a WIP, but how does that sound?
Thanks,
Mark.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 6/7] qdev: add qdev_prop_get_{macaddr, net_client}()
2009-11-12 20:28 [Qemu-devel] [RFC PATCH 0/7] Fix qemu_announce_self() properly Mark McLoughlin
` (4 preceding siblings ...)
2009-11-12 20:29 ` [Qemu-devel] [PATCH 5/7] qdev: add qdev_foreach() Mark McLoughlin
@ 2009-11-12 20:29 ` Mark McLoughlin
2009-11-12 20:29 ` [Qemu-devel] [PATCH 7/7] net: fix qemu_announce_self() Mark McLoughlin
6 siblings, 0 replies; 15+ messages in thread
From: Mark McLoughlin @ 2009-11-12 20:29 UTC (permalink / raw)
To: qemu-devel; +Cc: Mark McLoughlin, kraxel, quintela
Probably the second worst idea in the world, ever.
While iterating over all NICs in the system, we need to be
able to query their 'net-client' and 'macaddr' properties.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
hw/qdev-properties.c | 31 ++++++++++++++++++++++++++++---
hw/qdev.h | 3 +++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index fe40813..11ae6ad 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -458,10 +458,10 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
return prop->info->parse(dev, prop, value);
}
-void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
+static void *qdev_prop_get(DeviceState *dev, const char *name,
+ enum PropertyType type, Property **prop_ret)
{
Property *prop;
- void *dst;
prop = qdev_prop_find(dev, name);
if (!prop) {
@@ -474,7 +474,20 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
__FUNCTION__, dev->info->name, name);
abort();
}
- dst = qdev_get_prop_ptr(dev, prop);
+
+ if (prop_ret) {
+ *prop_ret = prop;
+ }
+
+ return qdev_get_prop_ptr(dev, prop);
+}
+
+void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type)
+{
+ Property *prop;
+ void *dst;
+
+ dst = qdev_prop_get(dev, name, type, &prop);
memcpy(dst, src, prop->info->size);
}
@@ -518,11 +531,23 @@ void qdev_prop_set_net_client(DeviceState *dev, const char *name, VLANClientStat
qdev_prop_set(dev, name, &value, PROP_TYPE_NET_CLIENT);
}
+VLANClientState *qdev_prop_get_net_client(DeviceState *dev, const char *name)
+{
+ VLANClientState **clientp = qdev_prop_get(dev, name, PROP_TYPE_NET_CLIENT, NULL);
+ return *clientp;
+}
+
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
{
qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
}
+uint8_t *qdev_prop_get_macaddr(DeviceState *dev, const char *name)
+{
+ uint8_t *mac = qdev_prop_get(dev, name, PROP_TYPE_MACADDR, NULL);
+ return mac;
+}
+
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
{
qdev_prop_set(dev, name, &value, PROP_TYPE_PTR);
diff --git a/hw/qdev.h b/hw/qdev.h
index 712ae3b..41b2f07 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -267,6 +267,9 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props);
void qdev_prop_register_compat(CompatProperty *props);
void qdev_prop_set_compat(DeviceState *dev);
+VLANClientState *qdev_prop_get_net_client(DeviceState *dev, const char *name);
+uint8_t *qdev_prop_get_macaddr(DeviceState *dev, const char *name);
+
/* This is a nasty hack to allow passing a NULL bus to qdev_create. */
extern struct BusInfo system_bus_info;
--
1.6.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 7/7] net: fix qemu_announce_self()
2009-11-12 20:28 [Qemu-devel] [RFC PATCH 0/7] Fix qemu_announce_self() properly Mark McLoughlin
` (5 preceding siblings ...)
2009-11-12 20:29 ` [Qemu-devel] [PATCH 6/7] qdev: add qdev_prop_get_{macaddr, net_client}() Mark McLoughlin
@ 2009-11-12 20:29 ` Mark McLoughlin
2009-11-13 7:41 ` Mark McLoughlin
2009-11-13 8:14 ` Markus Armbruster
6 siblings, 2 replies; 15+ messages in thread
From: Mark McLoughlin @ 2009-11-12 20:29 UTC (permalink / raw)
To: qemu-devel; +Cc: Mark McLoughlin, kraxel, quintela
Now that we have a sane way of iterating over NICs.
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
savevm.c | 43 ++++++++++++++++++++++++++-----------------
1 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/savevm.c b/savevm.c
index 039740c..3736588 100644
--- a/savevm.c
+++ b/savevm.c
@@ -75,6 +75,7 @@
#include "qemu-common.h"
#include "hw/hw.h"
+#include "hw/qdev.h"
#include "net.h"
#include "monitor.h"
#include "sysemu.h"
@@ -123,28 +124,36 @@ static int announce_self_create(uint8_t *buf,
return 60; /* len (FCS will be added by hardware) */
}
-static void qemu_announce_self_once(void *opaque)
+static void qemu_announce_self_iter(DeviceState *dev, void *opaque)
{
- int i, len;
-#ifdef FIXME
- VLANState *vlan;
- VLANClientState *vc;
-#endif
+ VLANClientState *client;
+ uint8_t *mac;
uint8_t buf[60];
+ int len;
+
+ if (!qdev_prop_exists(dev, "net-client")) {
+ return;
+ }
+
+ client = qdev_prop_get_net_client(dev, "net-client");
+ mac = qdev_prop_get_macaddr(dev, "mac");
+
+ printf("qemu_announce_self_iter() mac = %p\n", mac);
+
+ len = announce_self_create(buf, mac);
+
+ printf("sending packet from %s\n", client->name);
+
+ qemu_send_packet_raw(client, buf, len);
+}
+
+static void qemu_announce_self_once(void *opaque)
+{
static int count = SELF_ANNOUNCE_ROUNDS;
QEMUTimer *timer = *(QEMUTimer **)opaque;
- for (i = 0; i < MAX_NICS; i++) {
- if (!nd_table[i].used)
- continue;
- len = announce_self_create(buf, nd_table[i].macaddr);
-#ifdef FIXME
- vlan = nd_table[i].vlan;
- QTAILQ_FOREACH(vc, &vlan->clients, next) {
- qemu_send_packet_raw(vc, buf, len);
- }
-#endif
- }
+ qdev_foreach(qemu_announce_self_iter, NULL);
+
if (--count) {
/* delay 50ms, 150ms, 250ms, ... */
qemu_mod_timer(timer, qemu_get_clock(rt_clock) +
--
1.6.2.5
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 7/7] net: fix qemu_announce_self()
2009-11-12 20:29 ` [Qemu-devel] [PATCH 7/7] net: fix qemu_announce_self() Mark McLoughlin
@ 2009-11-13 7:41 ` Mark McLoughlin
2009-11-13 8:14 ` Markus Armbruster
1 sibling, 0 replies; 15+ messages in thread
From: Mark McLoughlin @ 2009-11-13 7:41 UTC (permalink / raw)
To: qemu-devel; +Cc: kraxel, quintela
On Thu, 2009-11-12 at 20:29 +0000, Mark McLoughlin wrote:
...
> + printf("qemu_announce_self_iter() mac = %p\n", mac);
> +
> + len = announce_self_create(buf, mac);
> +
> + printf("sending packet from %s\n", client->name);
Ooops, some debugging leftovers. removed in my tree.
Cheers,
Mark.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 7/7] net: fix qemu_announce_self()
2009-11-12 20:29 ` [Qemu-devel] [PATCH 7/7] net: fix qemu_announce_self() Mark McLoughlin
2009-11-13 7:41 ` Mark McLoughlin
@ 2009-11-13 8:14 ` Markus Armbruster
1 sibling, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2009-11-13 8:14 UTC (permalink / raw)
To: Mark McLoughlin; +Cc: quintela, qemu-devel, kraxel
Mark McLoughlin <markmc@redhat.com> writes:
> Now that we have a sane way of iterating over NICs.
>
> Signed-off-by: Mark McLoughlin <markmc@redhat.com>
> ---
> savevm.c | 43 ++++++++++++++++++++++++++-----------------
> 1 files changed, 26 insertions(+), 17 deletions(-)
>
> diff --git a/savevm.c b/savevm.c
> index 039740c..3736588 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -75,6 +75,7 @@
>
> #include "qemu-common.h"
> #include "hw/hw.h"
> +#include "hw/qdev.h"
> #include "net.h"
> #include "monitor.h"
> #include "sysemu.h"
> @@ -123,28 +124,36 @@ static int announce_self_create(uint8_t *buf,
> return 60; /* len (FCS will be added by hardware) */
> }
>
> -static void qemu_announce_self_once(void *opaque)
> +static void qemu_announce_self_iter(DeviceState *dev, void *opaque)
> {
> - int i, len;
> -#ifdef FIXME
> - VLANState *vlan;
> - VLANClientState *vc;
> -#endif
> + VLANClientState *client;
> + uint8_t *mac;
> uint8_t buf[60];
> + int len;
> +
> + if (!qdev_prop_exists(dev, "net-client")) {
> + return;
> + }
This is an ad-hoc "is this a NIC" test. It assumes all NICs have a
"net-client" property (trivial), and that no other kind of device ever
has a "net-client" property (reasonable). But, as we accumulate more of
this type of tests, we'll accumulate more of these assumptions, and
having them spread over the code could be confusing. What about
collecting the "is this a DEVICE_KIND" tests in one place?
For the record, I still believe that identifying device kind by testing
presence of properties is suboptimal[*], but we got more important fish
to fry.
> +
> + client = qdev_prop_get_net_client(dev, "net-client");
> + mac = qdev_prop_get_macaddr(dev, "mac");
> +
> + printf("qemu_announce_self_iter() mac = %p\n", mac);
> +
> + len = announce_self_create(buf, mac);
> +
> + printf("sending packet from %s\n", client->name);
> +
> + qemu_send_packet_raw(client, buf, len);
> +}
[...]
[*] There's no way to test "is this a watchdog" by testing presence of
properties. Ability to identify watchdog devices would let us kill
watchdog_list.
^ permalink raw reply [flat|nested] 15+ messages in thread