diff mbox

[PATCHv2,7/8] Change pci bus get_dev_path callback to print only slot and func

Message ID 1288525209-3303-8-git-send-email-gleb@redhat.com
State New
Headers show

Commit Message

Gleb Natapov Oct. 31, 2010, 11:40 a.m. UTC
Domain should be determined form parent bus and bus number is configured
by guest and should not be used in qemu internally.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 hw/pci.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

Comments

Michael S. Tsirkin Nov. 8, 2010, 5:17 p.m. UTC | #1
On Sun, Oct 31, 2010 at 01:40:08PM +0200, Gleb Natapov wrote:
> Domain should be determined form parent bus and bus number is configured
> by guest and should not be used in qemu internally.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> ---
>  hw/pci.c |   11 ++++++-----
>  1 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index 92aaa85..1c5706f 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -2138,12 +2138,13 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
>  static char *pcibus_get_dev_path(DeviceState *dev)
>  {
>      PCIDevice *d = (PCIDevice *)dev;
> -    char path[16];
> -
> -    snprintf(path, sizeof(path), "%04x:%02x:%02x.%x",
> -             pci_find_domain(d->bus), d->config[PCI_SECONDARY_BUS],
> -             PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
> +    char path[50];
> +    int off;
>  
> +    off = snprintf(path, sizeof(path), "%s@%x", qdev_driver_name(dev),
> +             PCI_SLOT(d->devfn));
> +    if (PCI_FUNC(d->devfn))
> +        snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
>      return strdup(path);
>  }

Can we change separators to be : and . instead of @ and , please?
This will make it compatible with existing code and generally
what users expect.
Michael S. Tsirkin Nov. 8, 2010, 5:26 p.m. UTC | #2
On Sun, Oct 31, 2010 at 01:40:08PM +0200, Gleb Natapov wrote:
> Domain should be determined form parent bus and bus number is configured
> by guest and should not be used in qemu internally.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> ---
>  hw/pci.c |   11 ++++++-----
>  1 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index 92aaa85..1c5706f 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -2138,12 +2138,13 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
>  static char *pcibus_get_dev_path(DeviceState *dev)
>  {
>      PCIDevice *d = (PCIDevice *)dev;
> -    char path[16];
> -
> -    snprintf(path, sizeof(path), "%04x:%02x:%02x.%x",
> -             pci_find_domain(d->bus), d->config[PCI_SECONDARY_BUS],
> -             PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
> +    char path[50];
> +    int off;
>  
> +    off = snprintf(path, sizeof(path), "%s@%x", qdev_driver_name(dev),
> +             PCI_SLOT(d->devfn));
> +    if (PCI_FUNC(d->devfn))
> +        snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
>      return strdup(path);
>  }

If we want to be backwards compatible at least for a single domain,
we need to call PCI root in that case "0000:00". Can this work?
I think that keeping a single way to address devices is good.
Gleb Natapov Nov. 8, 2010, 5:29 p.m. UTC | #3
On Mon, Nov 08, 2010 at 07:17:37PM +0200, Michael S. Tsirkin wrote:
> On Sun, Oct 31, 2010 at 01:40:08PM +0200, Gleb Natapov wrote:
> > Domain should be determined form parent bus and bus number is configured
> > by guest and should not be used in qemu internally.
> > 
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > ---
> >  hw/pci.c |   11 ++++++-----
> >  1 files changed, 6 insertions(+), 5 deletions(-)
> > 
> > diff --git a/hw/pci.c b/hw/pci.c
> > index 92aaa85..1c5706f 100644
> > --- a/hw/pci.c
> > +++ b/hw/pci.c
> > @@ -2138,12 +2138,13 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
> >  static char *pcibus_get_dev_path(DeviceState *dev)
> >  {
> >      PCIDevice *d = (PCIDevice *)dev;
> > -    char path[16];
> > -
> > -    snprintf(path, sizeof(path), "%04x:%02x:%02x.%x",
> > -             pci_find_domain(d->bus), d->config[PCI_SECONDARY_BUS],
> > -             PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
> > +    char path[50];
> > +    int off;
> >  
> > +    off = snprintf(path, sizeof(path), "%s@%x", qdev_driver_name(dev),
> > +             PCI_SLOT(d->devfn));
> > +    if (PCI_FUNC(d->devfn))
> > +        snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
> >      return strdup(path);
> >  }
> 
> Can we change separators to be : and . instead of @ and , please?
No. I am implementing well defined Open Firmware device path. Lets stop
reinventing things wrongly please?

> This will make it compatible with existing code and generally
> what users expect.
> 
It will drop domain and bus number part anyway.

--
			Gleb.
Michael S. Tsirkin Nov. 8, 2010, 6:12 p.m. UTC | #4
On Mon, Nov 08, 2010 at 07:29:50PM +0200, Gleb Natapov wrote:
> On Mon, Nov 08, 2010 at 07:17:37PM +0200, Michael S. Tsirkin wrote:
> > On Sun, Oct 31, 2010 at 01:40:08PM +0200, Gleb Natapov wrote:
> > > Domain should be determined form parent bus and bus number is configured
> > > by guest and should not be used in qemu internally.
> > > 
> > > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > > ---
> > >  hw/pci.c |   11 ++++++-----
> > >  1 files changed, 6 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/hw/pci.c b/hw/pci.c
> > > index 92aaa85..1c5706f 100644
> > > --- a/hw/pci.c
> > > +++ b/hw/pci.c
> > > @@ -2138,12 +2138,13 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
> > >  static char *pcibus_get_dev_path(DeviceState *dev)
> > >  {
> > >      PCIDevice *d = (PCIDevice *)dev;
> > > -    char path[16];
> > > -
> > > -    snprintf(path, sizeof(path), "%04x:%02x:%02x.%x",
> > > -             pci_find_domain(d->bus), d->config[PCI_SECONDARY_BUS],
> > > -             PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
> > > +    char path[50];
> > > +    int off;
> > >  
> > > +    off = snprintf(path, sizeof(path), "%s@%x", qdev_driver_name(dev),
> > > +             PCI_SLOT(d->devfn));
> > > +    if (PCI_FUNC(d->devfn))
> > > +        snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
> > >      return strdup(path);
> > >  }
> > 
> > Can we change separators to be : and . instead of @ and , please?
> No. I am implementing well defined Open Firmware device path. Lets stop
> reinventing things wrongly please?
> 
> > This will make it compatible with existing code and generally
> > what users expect.
> > 
> It will drop domain and bus number part anyway.

Yes but most users at the moment have domain and bus 0 only.
So even simply adding 0000:00 prefix will work.

> --
> 			Gleb.
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Gleb Natapov Nov. 8, 2010, 6:22 p.m. UTC | #5
On Mon, Nov 08, 2010 at 08:12:55PM +0200, Michael S. Tsirkin wrote:
> On Mon, Nov 08, 2010 at 07:29:50PM +0200, Gleb Natapov wrote:
> > On Mon, Nov 08, 2010 at 07:17:37PM +0200, Michael S. Tsirkin wrote:
> > > On Sun, Oct 31, 2010 at 01:40:08PM +0200, Gleb Natapov wrote:
> > > > Domain should be determined form parent bus and bus number is configured
> > > > by guest and should not be used in qemu internally.
> > > > 
> > > > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > > > ---
> > > >  hw/pci.c |   11 ++++++-----
> > > >  1 files changed, 6 insertions(+), 5 deletions(-)
> > > > 
> > > > diff --git a/hw/pci.c b/hw/pci.c
> > > > index 92aaa85..1c5706f 100644
> > > > --- a/hw/pci.c
> > > > +++ b/hw/pci.c
> > > > @@ -2138,12 +2138,13 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
> > > >  static char *pcibus_get_dev_path(DeviceState *dev)
> > > >  {
> > > >      PCIDevice *d = (PCIDevice *)dev;
> > > > -    char path[16];
> > > > -
> > > > -    snprintf(path, sizeof(path), "%04x:%02x:%02x.%x",
> > > > -             pci_find_domain(d->bus), d->config[PCI_SECONDARY_BUS],
> > > > -             PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
> > > > +    char path[50];
> > > > +    int off;
> > > >  
> > > > +    off = snprintf(path, sizeof(path), "%s@%x", qdev_driver_name(dev),
> > > > +             PCI_SLOT(d->devfn));
> > > > +    if (PCI_FUNC(d->devfn))
> > > > +        snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
> > > >      return strdup(path);
> > > >  }
> > > 
> > > Can we change separators to be : and . instead of @ and , please?
> > No. I am implementing well defined Open Firmware device path. Lets stop
> > reinventing things wrongly please?
> > 
> > > This will make it compatible with existing code and generally
> > > what users expect.
> > > 
> > It will drop domain and bus number part anyway.
> 
> Yes but most users at the moment have domain and bus 0 only.
> So even simply adding 0000:00 prefix will work.
> 
Are we trying to build device path or do bunch of hacks? We already have
hack now. Why change anything at all? PPC Macs  (G500) had 3 pci buses.

--
			Gleb.
Michael S. Tsirkin Nov. 8, 2010, 9 p.m. UTC | #6
On Mon, Nov 08, 2010 at 07:29:50PM +0200, Gleb Natapov wrote:
> > This will make it compatible with existing code and generally
> > what users expect.
> > 
> It will drop domain and bus number part anyway.

Yes but the proposal was to add 0000:00: in front to
make it have the expected format for most users.
Gleb Natapov Nov. 8, 2010, 9:12 p.m. UTC | #7
On Mon, Nov 08, 2010 at 11:00:17PM +0200, Michael S. Tsirkin wrote:
> On Mon, Nov 08, 2010 at 07:29:50PM +0200, Gleb Natapov wrote:
> > > This will make it compatible with existing code and generally
> > > what users expect.
> > > 
> > It will drop domain and bus number part anyway.
> 
> Yes but the proposal was to add 0000:00: in front to
> make it have the expected format for most users.
> 
I am not interesting in hacks. I do not know who are those most users 
you are talking about and why they expect 0000:00: in front of
something. Anyway, as I said, I moved to use another callback so you can
do whatever you want with get_dev_path.

--
			Gleb.
diff mbox

Patch

diff --git a/hw/pci.c b/hw/pci.c
index 92aaa85..1c5706f 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -2138,12 +2138,13 @@  static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent)
 static char *pcibus_get_dev_path(DeviceState *dev)
 {
     PCIDevice *d = (PCIDevice *)dev;
-    char path[16];
-
-    snprintf(path, sizeof(path), "%04x:%02x:%02x.%x",
-             pci_find_domain(d->bus), d->config[PCI_SECONDARY_BUS],
-             PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
+    char path[50];
+    int off;
 
+    off = snprintf(path, sizeof(path), "%s@%x", qdev_driver_name(dev),
+             PCI_SLOT(d->devfn));
+    if (PCI_FUNC(d->devfn))
+        snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
     return strdup(path);
 }