From mboxrd@z Thu Jan 1 00:00:00 1970 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCHv2 4/8] Store IDE bus id in IDEBus structure for easy access. Date: Wed, 03 Nov 2010 14:39:52 +0100 Message-ID: References: <1288525209-3303-1-git-send-email-gleb@redhat.com> <1288525209-3303-5-git-send-email-gleb@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: qemu-devel@nongnu.org, blauwirbel@gmail.com, alex.williamson@redhat.com, kvm@vger.kernel.org To: Gleb Natapov Return-path: Received: from mx1.redhat.com ([209.132.183.28]:32282 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752055Ab0KCNj6 (ORCPT ); Wed, 3 Nov 2010 09:39:58 -0400 In-Reply-To: <1288525209-3303-5-git-send-email-gleb@redhat.com> (Gleb Natapov's message of "Sun, 31 Oct 2010 13:40:05 +0200") Sender: kvm-owner@vger.kernel.org List-ID: Here's a generic answer to the question "which of the device's buses is this?" int qbus_index(BusState *bus) { BusState *b; int i, index; index = -1; i = 0; QLIST_FOREACH(b, &bus->parent->child_bus, sibling) { if (b == bus) { index = i; } i++; } assert(0 <= index && index < i); return i - 1 - index; } The bus created first has index 0. Note that the child_bus holds the children in reverse creation order, and we can't traverse it backwards. Same problem also visible with makes info qtree: dev: piix3-ide, id "" [...] bus: ide.1 type IDE bus: ide.0 type IDE From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=38070 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDdZH-0001Jr-1l for qemu-devel@nongnu.org; Wed, 03 Nov 2010 09:39:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDdZF-0007hk-UT for qemu-devel@nongnu.org; Wed, 03 Nov 2010 09:39:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28347) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDdZF-0007ha-NX for qemu-devel@nongnu.org; Wed, 03 Nov 2010 09:39:57 -0400 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCHv2 4/8] Store IDE bus id in IDEBus structure for easy access. References: <1288525209-3303-1-git-send-email-gleb@redhat.com> <1288525209-3303-5-git-send-email-gleb@redhat.com> Date: Wed, 03 Nov 2010 14:39:52 +0100 In-Reply-To: <1288525209-3303-5-git-send-email-gleb@redhat.com> (Gleb Natapov's message of "Sun, 31 Oct 2010 13:40:05 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gleb Natapov Cc: blauwirbel@gmail.com, alex.williamson@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org Here's a generic answer to the question "which of the device's buses is this?" int qbus_index(BusState *bus) { BusState *b; int i, index; index = -1; i = 0; QLIST_FOREACH(b, &bus->parent->child_bus, sibling) { if (b == bus) { index = i; } i++; } assert(0 <= index && index < i); return i - 1 - index; } The bus created first has index 0. Note that the child_bus holds the children in reverse creation order, and we can't traverse it backwards. Same problem also visible with makes info qtree: dev: piix3-ide, id "" [...] bus: ide.1 type IDE bus: ide.0 type IDE