replace duplicated code.
PATCH 1/1 replace duplicated code.
pci_register_simple() does exactly the same of great part of the code in pci nic initialization. Replace it.
--- hw/pci.c | 12 ++++-------- hw/qdev.c | 1 + 2 files changed, 5 insertions(+), 8 deletions(-)
hw/pci.c +4 -8
@@ -818,20 +818,16 @@ static const char * const pci_nic_names[] = {PCIDevice *pci_nic_init (PCIBus *bus,NICInfo *nd,int devfn,const char *default_model) { -DeviceState *dev;int i;qemu_check_nic_model_list (nd, pci_nic_models, default_model);for (i =0 ; pci_nic_models[i]; i++) {if (strcmp (nd->model, pci_nic_models[i]) ==0 ) { - dev =qdev_create (&bus->qbus, pci_nic_names[i]); -qdev_set_prop_int (dev,"devfn" , devfn); -qdev_set_prop_ptr (dev,"name" , (void *)pci_nic_names[i]); -qdev_set_netdev (dev, nd); -qdev_init (dev); - nd->private = dev; -return (PCIDevice *)dev; +PCIDevice *d; + d =pci_create_simple (bus, devfn, pci_nic_names[i]); +qdev_set_netdev ((DeviceState *)d, nd); +return d; } }
hw/qdev.c +1 -0
@@ -164,6 +164,7 @@ void qdev_set_netdev(DeviceState *dev, NICInfo *nd) {assert (!dev->nd); dev->nd = nd; + nd->private = dev; }
Signature · 1 line
1.6.2.2
Quoted 17 lines · Glauber Costa
pci_register_simple()does exactly the same of great part of the code in pci nic initialization. Replace it.Signed-off-by Glauber Costa <[email protected]>--- hw/pci.c | 12 ++++-------- hw/qdev.c | 1 + 2 files changed, 5 insertions(+), 8 deletions(-)hw/pci.c +0
-0@@ -818,20 +818,16 @@ static const char * const pci_nic_names[] = {PCIDevice *pci_nic_init (PCIBus *bus,NICInfo *nd,int devfn,const char *default_model) {
hw/pci.c static const char * const pci_nic_names[] = { · line 830
Quoted 10 lines
hw/pci.c +0
-4-DeviceState *dev;int i;qemu_check_nic_model_list (nd, pci_nic_models, default_model);for (i =0 ; pci_nic_models[i]; i++) {if (strcmp (nd->model, pci_nic_models[i]) ==0 ) { - dev =qdev_create (&bus->qbus, pci_nic_names[i]); -qdev_set_prop_int (dev,"devfn" , devfn); -qdev_set_prop_ptr (dev,"name" , (void *)pci_nic_names[i]);
So, this patch depends on your "allow for name property" patch - resend as a series, maybe with this one first?
hw/pci.c static const char * const pci_nic_names[] = { · line 829
Quoted 7 lines
hw/pci.c +3
-4-qdev_set_netdev (dev, nd); -qdev_init (dev); - nd->private = dev; -return (PCIDevice *)dev; +PCIDevice *d; + d =pci_create_simple (bus, devfn, pci_nic_names[i]); +qdev_set_netdev ((DeviceState *)d, nd);
I'd prefer &d->qdev here for type safety.
Cheers,
Mark.
hw/pci.c static const char * const pci_nic_names[] = {
Quoted 8 lines
hw/pci.c +2
-5- dev =qdev_create (&bus->qbus, pci_nic_names[i]); -qdev_set_prop_int (dev,"devfn" , devfn); -qdev_set_prop_ptr (dev,"name" , (void *)pci_nic_names[i]); -qdev_set_netdev (dev, nd); -qdev_init (dev); + d =pci_create_simple (bus, devfn, pci_nic_names[i]); +qdev_set_netdev ((DeviceState *)d, nd);
You have changed the ordering of the qdev_set_netdev and qdev_init calls. I don't think this is correct, the init callback will not see the nicinfo then.
cheers,
Gerd
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines
hw/pci.c +0
-5- dev =qdev_create (&bus->qbus, pci_nic_names[i]); -qdev_set_prop_int (dev,"devfn" , devfn); -qdev_set_prop_ptr (dev,"name" , (void *)pci_nic_names[i]); -qdev_set_netdev (dev, nd); -qdev_init (dev);
Quoted 6 lines
hw/pci.c static const char * const pci_nic_names[] = { · line 829
Quoted 2 lines
hw/pci.c +2
-0+ d =pci_create_simple (bus, devfn, pci_nic_names[i]); +qdev_set_netdev ((DeviceState *)d, nd);You have changed the ordering of the
qdev_set_netdevandqdev_initcalls. I don't think this is correct, the init callback will not see the nicinfo then.
I see.
How would you feel about changing the nd field of qdev for a void * one, call it private, or whatever?
then we could have a generic qdev_set_private(dev, p), that does it for everybody. I must say I kinda dislike that specific dependency on nd for net devices. Ideally, all devices should be treated as the same.
Quoted 11 lines · Glauber Costa
Quoted 3 lines
You have changed the ordering of the
qdev_set_netdevandqdev_initcalls. I don't think this is correct, the init callback will not see the nicinfo then.I see.
How would you feel about changing the nd field of qdev for a void * one, call it private, or whatever?
then we could have a generic
qdev_set_private(dev, p), that does it for everybody. I must say I kinda dislike that specific dependency on nd for net devices. Ideally, all devices should be treated as the same.
What problem you are trying to solve?
Unless there is something urgent to fix I'd leave it as is for now.
We need some sane way to link guest config (hopefully done by config file soon) to host config. Link nic to vlan in that case, but disks and chardevs share the same issue. I consider DeviceState->nd being temporary and expect will go away once we figured that out. It is a bigger undertaking though ...
cheers,
Gerd