Patchwork [09/44] net: introduce qemu_new_net_client()

login
register
mail settings
Submitter Mark McLoughlin
Date Nov. 26, 2009, 6:06 p.m.
Message ID <1259258807.7522.6.camel@blaa>
Download mbox | patch
Permalink /patch/39580/
State New
Headers show

Comments

Mark McLoughlin - Nov. 26, 2009, 6:06 p.m.
On Wed, 2009-11-25 at 20:36 +0000, Blue Swirl wrote:
> On Wed, Nov 25, 2009 at 6:49 PM, Mark McLoughlin <markmc@redhat.com> wrote:
> > A replacement for qemu_new_vlan_client(), using NetClientInfo to
> > replace most arguments.
> 
> > +VLANClientState *qemu_new_net_client(NetClientInfo *info,
> > +                                     VLANState *vlan,
> > +                                     VLANClientState *peer,
> > +                                     const char *model,
> > +                                     const char *name)
> >  {
> 
> Could you change this to use const NetClientInfo *info instead? Then
> the device structures could be const as well.

Good idea.

I've added the patch below to http://repo.or.cz/w/qemu/markmc.git

Thanks,
Mark.

From: Mark McLoughlin <markmc@redhat.com>
Subject: [PATCH] net: constify NetClientInfo

Reported-by: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/dp8393x.c        |    2 +-
 hw/e1000.c          |    2 +-
 hw/eepro100.c       |    2 +-
 hw/etraxfs_eth.c    |    2 +-
 hw/lan9118.c        |    2 +-
 hw/lance.c          |    2 +-
 hw/mcf_fec.c        |    2 +-
 hw/mipsnet.c        |    2 +-
 hw/musicpal.c       |    2 +-
 hw/ne2000-isa.c     |    2 +-
 hw/ne2000.c         |    2 +-
 hw/pcnet.c          |    4 ++--
 hw/pcnet.h          |    2 +-
 hw/rtl8139.c        |    2 +-
 hw/smc91c111.c      |    2 +-
 hw/stellaris_enet.c |    2 +-
 hw/usb-net.c        |    2 +-
 hw/virtio-net.c     |    2 +-
 hw/xen_nic.c        |    2 +-
 hw/xilinx_ethlite.c |    2 +-
 net.c               |    4 ++--
 net.h               |    6 +++---
 net/dump.c          |    2 +-
 net/slirp.c         |    2 +-
 net/socket.c        |    4 ++--
 net/tap-win32.c     |    2 +-
 net/tap.c           |    2 +-
 net/vde.c           |    2 +-
 28 files changed, 33 insertions(+), 33 deletions(-)

Patch

diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index e65e4d1..b4b2e62 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -873,7 +873,7 @@  static void nic_cleanup(VLANClientState *nc)
     qemu_free(s);
 }
 
-static NetClientInfo net_dp83932_info = {
+static const NetClientInfo net_dp83932_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = nic_can_receive,
diff --git a/hw/e1000.c b/hw/e1000.c
index 683fdcc..2ca4c07 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1067,7 +1067,7 @@  static void e1000_reset(void *opaque)
     memset(&d->tx, 0, sizeof d->tx);
 }
 
-static NetClientInfo net_e1000_info = {
+static const NetClientInfo net_e1000_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = e1000_can_receive,
diff --git a/hw/eepro100.c b/hw/eepro100.c
index eb16a51..f6816f7 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1797,7 +1797,7 @@  static int pci_nic_uninit(PCIDevice *pci_dev)
     return 0;
 }
 
-static NetClientInfo net_eepro100_info = {
+static const NetClientInfo net_eepro100_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = nic_can_receive,
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index dedd107..6398c0c 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -565,7 +565,7 @@  static void eth_cleanup(VLANClientState *nc)
         qemu_free(eth);
 }
 
-static NetClientInfo net_etraxfs_info = {
+static const NetClientInfo net_etraxfs_info = {
 	.type = NET_CLIENT_TYPE_NIC,
 	.size = sizeof(NICState),
 	.can_receive = eth_can_receive,
diff --git a/hw/lan9118.c b/hw/lan9118.c
index ba982d1..306a16a 100644
--- a/hw/lan9118.c
+++ b/hw/lan9118.c
@@ -1029,7 +1029,7 @@  static void lan9118_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_lan9118_info = {
+static const NetClientInfo net_lan9118_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = lan9118_can_receive,
diff --git a/hw/lance.c b/hw/lance.c
index 98033a4..cba111b 100644
--- a/hw/lance.c
+++ b/hw/lance.c
@@ -100,7 +100,7 @@  static void lance_cleanup(VLANClientState *nc)
     pcnet_common_cleanup(d);
 }
 
-static NetClientInfo net_lance_info = {
+static const NetClientInfo net_lance_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = pcnet_can_receive,
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 4e7fbed..ed7e0c8 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -450,7 +450,7 @@  static void mcf_fec_cleanup(VLANClientState *nc)
     qemu_free(s);
 }
 
-static NetClientInfo net_mcf_fec_info = {
+static const NetClientInfo net_mcf_fec_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = mcf_fec_can_receive,
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index a066f63..5396489 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -246,7 +246,7 @@  static void mipsnet_cleanup(VLANClientState *nc)
     qemu_free(s);
 }
 
-static NetClientInfo net_mipsnet_info = {
+static const NetClientInfo net_mipsnet_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = mipsnet_can_receive,
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 4a33e28..5128c06 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -372,7 +372,7 @@  static void eth_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_mv88w8618_info = {
+static const NetClientInfo net_mv88w8618_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = eth_can_receive,
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 0260f84..e1519a8 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -42,7 +42,7 @@  static void isa_ne2000_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_ne2000_isa_info = {
+static const NetClientInfo net_ne2000_isa_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = ne2000_can_receive,
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 0be189a..e7ef91a 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -705,7 +705,7 @@  static void ne2000_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_ne2000_info = {
+static const NetClientInfo net_ne2000_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = ne2000_can_receive,
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 195c825..42c3464 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1891,7 +1891,7 @@  void pcnet_common_cleanup(PCNetState *d)
     d->nic = NULL;
 }
 
-int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
+int pcnet_common_init(DeviceState *dev, PCNetState *s, const NetClientInfo *info)
 {
     s->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s);
 
@@ -1959,7 +1959,7 @@  static int pci_pcnet_uninit(PCIDevice *dev)
     return 0;
 }
 
-static NetClientInfo net_pci_pcnet_info = {
+static const NetClientInfo net_pci_pcnet_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = pcnet_can_receive,
diff --git a/hw/pcnet.h b/hw/pcnet.h
index efacc9f..1274f95 100644
--- a/hw/pcnet.h
+++ b/hw/pcnet.h
@@ -35,5 +35,5 @@  uint32_t pcnet_ioport_readw(void *opaque, uint32_t addr);
 int pcnet_can_receive(VLANClientState *nc);
 ssize_t pcnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size_);
 void pcnet_common_cleanup(PCNetState *d);
-int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info);
+int pcnet_common_init(DeviceState *dev, PCNetState *s, const NetClientInfo *info);
 extern const VMStateDescription vmstate_pcnet;
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 931cde9..7a73598 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3305,7 +3305,7 @@  static int pci_rtl8139_uninit(PCIDevice *dev)
     return 0;
 }
 
-static NetClientInfo net_rtl8139_info = {
+static const NetClientInfo net_rtl8139_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = rtl8139_can_receive,
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index c1a88c9..1ed841d 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -699,7 +699,7 @@  static void smc91c111_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_smc91c111_info = {
+static const NetClientInfo net_smc91c111_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = smc91c111_can_receive,
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index d1d755e..198c8bf 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -396,7 +396,7 @@  static void stellaris_enet_cleanup(VLANClientState *nc)
     qemu_free(s);
 }
 
-static NetClientInfo net_stellaris_enet_info = {
+static const NetClientInfo net_stellaris_enet_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = stellaris_enet_can_receive,
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 2556e05..d5c60f7 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1450,7 +1450,7 @@  static int usb_net_initfn(USBDevice *dev)
     return 0;
 }
 
-static NetClientInfo net_usbnet_info = {
+static const NetClientInfo net_usbnet_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = usbnet_can_receive,
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 2f201ff..b97151a 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -818,7 +818,7 @@  static void virtio_net_cleanup(VLANClientState *nc)
     n->nic = NULL;
 }
 
-static NetClientInfo net_virtio_info = {
+static const NetClientInfo net_virtio_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = virtio_net_can_receive,
diff --git a/hw/xen_nic.c b/hw/xen_nic.c
index 08055b8..bdc8134 100644
--- a/hw/xen_nic.c
+++ b/hw/xen_nic.c
@@ -290,7 +290,7 @@  static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t siz
 
 /* ------------------------------------------------------------- */
 
-static NetClientInfo net_xen_info = {
+static const NetClientInfo net_xen_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = net_rx_ok,
diff --git a/hw/xilinx_ethlite.c b/hw/xilinx_ethlite.c
index 37e33ec..87b393b 100644
--- a/hw/xilinx_ethlite.c
+++ b/hw/xilinx_ethlite.c
@@ -208,7 +208,7 @@  static void eth_cleanup(VLANClientState *nc)
     s->nic = NULL;
 }
 
-static NetClientInfo net_xilinx_ethlite_info = {
+static const NetClientInfo net_xilinx_ethlite_info = {
     .type = NET_CLIENT_TYPE_NIC,
     .size = sizeof(NICState),
     .can_receive = eth_can_rx,
diff --git a/net.c b/net.c
index 13bdbb2..5e3f2e8 100644
--- a/net.c
+++ b/net.c
@@ -217,7 +217,7 @@  static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
                                        int iovcnt,
                                        void *opaque);
 
-VLANClientState *qemu_new_net_client(NetClientInfo *info,
+VLANClientState *qemu_new_net_client(const NetClientInfo *info,
                                      VLANState *vlan,
                                      VLANClientState *peer,
                                      const char *model,
@@ -256,7 +256,7 @@  VLANClientState *qemu_new_net_client(NetClientInfo *info,
     return vc;
 }
 
-NICState *qemu_new_nic(NetClientInfo *info,
+NICState *qemu_new_nic(const NetClientInfo *info,
                        NICConf *conf,
                        const char *model,
                        const char *name,
diff --git a/net.h b/net.h
index d583d59..36a3448 100644
--- a/net.h
+++ b/net.h
@@ -54,7 +54,7 @@  typedef struct NetClientInfo {
 } NetClientInfo;
 
 struct VLANClientState {
-    NetClientInfo *info;
+    const NetClientInfo *info;
     int link_down;
     QTAILQ_ENTRY(VLANClientState) next;
     struct VLANState *vlan;
@@ -82,12 +82,12 @@  struct VLANState {
 
 VLANState *qemu_find_vlan(int id, int allocate);
 VLANClientState *qemu_find_netdev(const char *id);
-VLANClientState *qemu_new_net_client(NetClientInfo *info,
+VLANClientState *qemu_new_net_client(const NetClientInfo *info,
                                      VLANState *vlan,
                                      VLANClientState *peer,
                                      const char *model,
                                      const char *name);
-NICState *qemu_new_nic(NetClientInfo *info,
+NICState *qemu_new_nic(const NetClientInfo *info,
                        NICConf *conf,
                        const char *model,
                        const char *name,
diff --git a/net/dump.c b/net/dump.c
index 4ed3f5f..b8660d2 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -90,7 +90,7 @@  static void dump_cleanup(VLANClientState *nc)
     close(s->fd);
 }
 
-static NetClientInfo net_dump_info = {
+static const NetClientInfo net_dump_info = {
     .type = NET_CLIENT_TYPE_DUMP,
     .size = sizeof(DumpState),
     .receive = dump_receive,
diff --git a/net/slirp.c b/net/slirp.c
index 3f91c4b..fc53ab5 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -125,7 +125,7 @@  static void net_slirp_cleanup(VLANClientState *nc)
     QTAILQ_REMOVE(&slirp_stacks, s, entry);
 }
 
-static NetClientInfo net_slirp_info = {
+static const NetClientInfo net_slirp_info = {
     .type = NET_CLIENT_TYPE_SLIRP,
     .size = sizeof(SlirpState),
     .receive = net_slirp_receive,
diff --git a/net/socket.c b/net/socket.c
index 7331d87..931dff5 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -216,7 +216,7 @@  static void net_socket_cleanup(VLANClientState *nc)
     close(s->fd);
 }
 
-static NetClientInfo net_dgram_socket_info = {
+static const NetClientInfo net_dgram_socket_info = {
     .type = NET_CLIENT_TYPE_SOCKET,
     .size = sizeof(NetSocketState),
     .receive = net_socket_receive_dgram,
@@ -290,7 +290,7 @@  static void net_socket_connect(void *opaque)
     qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
 }
 
-static NetClientInfo net_socket_info = {
+static const NetClientInfo net_socket_info = {
     .type = NET_CLIENT_TYPE_SOCKET,
     .size = sizeof(NetSocketState),
     .receive = net_socket_receive,
diff --git a/net/tap-win32.c b/net/tap-win32.c
index ef63782..5734ada 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -666,7 +666,7 @@  static void tap_win32_send(void *opaque)
     }
 }
 
-static NetClientInfo net_tap_win32_info = {
+static const NetClientInfo net_tap_win32_info = {
     .type = NET_CLIENT_TYPE_TAP,
     .size = sizeof(TAPState),
     .receive = tap_receive,
diff --git a/net/tap.c b/net/tap.c
index 0d8b424..a4c25dd 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -264,7 +264,7 @@  static void tap_cleanup(VLANClientState *nc)
 
 /* fd support */
 
-static NetClientInfo net_tap_info = {
+static const NetClientInfo net_tap_info = {
     .type = NET_CLIENT_TYPE_TAP,
     .size = sizeof(TAPState),
     .receive = tap_receive,
diff --git a/net/vde.c b/net/vde.c
index 42b4633..8f834d6 100644
--- a/net/vde.c
+++ b/net/vde.c
@@ -69,7 +69,7 @@  static void vde_cleanup(VLANClientState *nc)
     vde_close(s->vde);
 }
 
-static NetClientInfo net_vde_info = {
+static const NetClientInfo net_vde_info = {
     .type = NET_CLIENT_TYPE_VDE,
     .size = sizeof(VDEState),
     .receive = vde_receive,