From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoUll-0002ei-Jb for qemu-devel@nongnu.org; Thu, 05 Dec 2013 03:58:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoUlg-0000ZD-0L for qemu-devel@nongnu.org; Thu, 05 Dec 2013 03:58:49 -0500 Received: from mail-ee0-x229.google.com ([2a00:1450:4013:c00::229]:59376) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoUlf-0000YR-Me for qemu-devel@nongnu.org; Thu, 05 Dec 2013 03:58:43 -0500 Received: by mail-ee0-f41.google.com with SMTP id t10so3057432eei.14 for ; Thu, 05 Dec 2013 00:58:42 -0800 (PST) Sender: Paolo Bonzini Message-ID: <52A04040.1040301@redhat.com> Date: Thu, 05 Dec 2013 09:58:40 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1386188688-6480-1-git-send-email-agraf@suse.de> In-Reply-To: <1386188688-6480-1-git-send-email-agraf@suse.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qdev: Keep global allocation counter per bus List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: QEMU Developers , Anthony Liguori , Markus Armbruster Il 04/12/2013 21:24, Alexander Graf ha scritto: > When we have 2 separate qdev devices that both create a qbus of the > same type without specifying a bus name or device name, we end up > with two buses of the same name, such as ide.0 on the Mac machines: > > dev: macio-ide, id "" > bus: ide.0 > type IDE > dev: macio-ide, id "" > bus: ide.0 > type IDE > > If we now spawn a device that connects to a ide.0 the last created > bus gets the device, with the first created bus inaccessible to the > command line. > > After some discussion on IRC we concluded that the best quick fix way > forward for this is to make automated bus-class type based allocation > count a global counter. That's what this patch implements. With this > we instead get > > dev: macio-ide, id "" > bus: ide.1 > type IDE > dev: macio-ide, id "" > bus: ide.0 > type IDE > > on the example mentioned above. > > CC: Paolo Bonzini > CC: Markus Armbruster > CC: Anthony Liguori > Signed-off-by: Alexander Graf > --- > hw/core/qdev.c | 20 +++++++++++++------- > include/hw/qdev-core.h | 2 ++ > 2 files changed, 15 insertions(+), 7 deletions(-) > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index e374a93..959130c 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -409,27 +409,33 @@ DeviceState *qdev_find_recursive(BusState *bus, const char *id) > static void qbus_realize(BusState *bus, DeviceState *parent, const char *name) > { > const char *typename = object_get_typename(OBJECT(bus)); > + BusClass *bc; > char *buf; > - int i,len; > + int i, len, bus_id; > > bus->parent = parent; > > if (name) { > bus->name = g_strdup(name); > } else if (bus->parent && bus->parent->id) { > - /* parent device has id -> use it for bus name */ > + /* parent device has id -> use it plus parent-bus-id for bus name */ > + bus_id = bus->parent->num_child_bus; > + > len = strlen(bus->parent->id) + 16; > buf = g_malloc(len); > - snprintf(buf, len, "%s.%d", bus->parent->id, bus->parent->num_child_bus); > + snprintf(buf, len, "%s.%d", bus->parent->id, bus_id); > bus->name = buf; > } else { > - /* no id -> use lowercase bus type for bus name */ > + /* no id -> use lowercase bus type plus global bus-id for bus name */ > + bc = BUS_GET_CLASS(bus); > + bus_id = bc->automatic_ids++; > + > len = strlen(typename) + 16; > buf = g_malloc(len); > - len = snprintf(buf, len, "%s.%d", typename, > - bus->parent ? bus->parent->num_child_bus : 0); > - for (i = 0; i < len; i++) > + len = snprintf(buf, len, "%s.%d", typename, bus_id); > + for (i = 0; i < len; i++) { > buf[i] = qemu_tolower(buf[i]); > + } > bus->name = buf; > } > > diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h > index f2043a6..09f8527 100644 > --- a/include/hw/qdev-core.h > +++ b/include/hw/qdev-core.h > @@ -161,6 +161,8 @@ struct BusClass { > int (*reset)(BusState *bus); > /* maximum devices allowed on the bus, 0: no limit. */ > int max_dev; > + /* number of automatically allocated bus ids (e.g. ide.0) */ > + int automatic_ids; > }; > > typedef struct BusChild { > Reviewed-by: Paolo Bonzini