From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0BIn-0008Rq-8Y for qemu-devel@nongnu.org; Thu, 26 Jun 2014 11:09:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0BIZ-0000SJ-V5 for qemu-devel@nongnu.org; Thu, 26 Jun 2014 11:09:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0BIZ-0000Ry-Ma for qemu-devel@nongnu.org; Thu, 26 Jun 2014 11:09:15 -0400 Message-ID: <53AC3798.50302@redhat.com> Date: Thu, 26 Jun 2014 17:09:12 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1403793280-4353-1-git-send-email-marc.mari.barcelo@gmail.com> In-Reply-To: <1403793280-4353-1-git-send-email-marc.mari.barcelo@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] Functions bus_foreach and device_find from libqos virtio API List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?TWFyYyBNYXLDrQ==?= , qemu-devel@nongnu.org Cc: Stefan Hajnoczi Il 26/06/2014 16:34, Marc Mar=C3=AD ha scritto: > +static void qvirtio_pci_foreach(uint16_t device_type, > + void (*func)(QVirtioDevice *d, void *data), void *data= ) > +{ > + QVirtioPCIForeachData d =3D { .func =3D func, > + .device_type =3D device_type, > + .user_data =3D data }; > + > + if (!bus) { > + bus =3D qpci_init_pc(); Why not pass this as an argument? .bus_foreach and .device_find need=20 not be part of QVirtioBus. > + } > + > + qpci_device_foreach(bus, QVIRTIO_VENDOR_ID, -1, > + qvirtio_pci_foreach_callback, &d); > +} > + > +static QVirtioDevice *qvirtio_pci_device_find(uint16_t device_type) (Also here, qvirtio_pci_device_find would just forward the bus to=20 qvirtio_pci_foreach). > + fprintf(stderr, "Device position: %x. Device type: %x\n", > + dev->pdev->devfn, dev->vdev.device= _type); You can change these to assertions, and get your first testcase too. :) You can set the address in the qtest_start argument (like "-device=20 virtio-blk-pci,...,addr=3D0x0a.0") so you know the expected value. Otherwise looks good! Paolo > +{ > + QVirtioPCIDevice *dev; > + > + dev =3D g_malloc0(sizeof(*dev)); > + qvirtio_pci_foreach(device_type, qvirtio_pci_assign_device, dev); > + > + return (QVirtioDevice *)dev; > +}