aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/virtio
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2008-05-30 16:09:42 -0400
committerRusty Russell <rusty@rustcorp.com.au>2008-05-30 01:09:42 -0400
commitb769f579081943f14e0ff03b7b0bd3a11cf14625 (patch)
tree026d89b6d937af43af4a692bcf547e032f0c58cc /drivers/virtio
parent5610bd1524332fe7d651eb56cc780e32763a2ac3 (diff)
virtio: set device index in common code.
Anthony Liguori points out that three different transports use the virtio code, but each one keeps its own counter to set the virtio_device's index field. In theory (though not in current practice) this means that names could be duplicated, and that risk grows as more transports are created. So we move the selection of the unique virtio_device.index into the common code in virtio.c, which has the side-benefit of removing duplicate code. The only complexity is that lguest and S/390 use the index to uniquely identify the device in case of catastrophic failure before register_virtio_device() is called: now we use the offset within the descriptor page as a unique identifier for the printks. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Carsten Otte <cotte@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Chris Lalancette <clalance@redhat.com> Cc: Anthony Liguori <anthony@codemonkey.ws>
Diffstat (limited to 'drivers/virtio')
-rw-r--r--drivers/virtio/virtio.c6
-rw-r--r--drivers/virtio/virtio_pci.c6
2 files changed, 6 insertions, 6 deletions
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 59918dfc3cb7..0f3c2bb7bf35 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -2,6 +2,9 @@
2#include <linux/spinlock.h> 2#include <linux/spinlock.h>
3#include <linux/virtio_config.h> 3#include <linux/virtio_config.h>
4 4
5/* Unique numbering for virtio devices. */
6static unsigned int dev_index;
7
5static ssize_t device_show(struct device *_d, 8static ssize_t device_show(struct device *_d,
6 struct device_attribute *attr, char *buf) 9 struct device_attribute *attr, char *buf)
7{ 10{
@@ -166,6 +169,9 @@ int register_virtio_device(struct virtio_device *dev)
166 int err; 169 int err;
167 170
168 dev->dev.bus = &virtio_bus; 171 dev->dev.bus = &virtio_bus;
172
173 /* Assign a unique device index and hence name. */
174 dev->index = dev_index++;
169 sprintf(dev->dev.bus_id, "virtio%u", dev->index); 175 sprintf(dev->dev.bus_id, "virtio%u", dev->index);
170 176
171 /* We always start by resetting the device, in case a previous 177 /* We always start by resetting the device, in case a previous
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 2913c2f309f0..eae7236310e4 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -78,9 +78,6 @@ static struct device virtio_pci_root = {
78 .bus_id = "virtio-pci", 78 .bus_id = "virtio-pci",
79}; 79};
80 80
81/* Unique numbering for devices under the kvm root */
82static unsigned int dev_index;
83
84/* Convert a generic virtio device to our structure */ 81/* Convert a generic virtio device to our structure */
85static struct virtio_pci_device *to_vp_device(struct virtio_device *vdev) 82static struct virtio_pci_device *to_vp_device(struct virtio_device *vdev)
86{ 83{
@@ -325,9 +322,6 @@ static int __devinit virtio_pci_probe(struct pci_dev *pci_dev,
325 if (vp_dev == NULL) 322 if (vp_dev == NULL)
326 return -ENOMEM; 323 return -ENOMEM;
327 324
328 vp_dev->vdev.index = dev_index;
329 dev_index++;
330
331 vp_dev->vdev.dev.parent = &virtio_pci_root; 325 vp_dev->vdev.dev.parent = &virtio_pci_root;
332 vp_dev->vdev.config = &virtio_pci_config_ops; 326 vp_dev->vdev.config = &virtio_pci_config_ops;
333 vp_dev->pci_dev = pci_dev; 327 vp_dev->pci_dev = pci_dev;