From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2cfs-000877-Nj for qemu-devel@nongnu.org; Thu, 03 Jul 2014 04:47:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X2cfj-00013o-Lq for qemu-devel@nongnu.org; Thu, 03 Jul 2014 04:47:24 -0400 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]:39924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2cfj-00013d-Ex for qemu-devel@nongnu.org; Thu, 03 Jul 2014 04:47:15 -0400 Received: by mail-wg0-f52.google.com with SMTP id b13so356086wgh.23 for ; Thu, 03 Jul 2014 01:47:14 -0700 (PDT) Date: Thu, 3 Jul 2014 10:47:02 +0200 From: Stefan Hajnoczi Message-ID: <20140703084702.GA28032@stefanha-thinkpad.redhat.com> References: <1404122146-24279-1-git-send-email-marc.mari.barcelo@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline In-Reply-To: <1404122146-24279-1-git-send-email-marc.mari.barcelo@gmail.com> Subject: Re: [Qemu-devel] [PATCH v3] tests: Functions bus_foreach and device_find from libqos virtio API List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marc =?iso-8859-1?Q?Mar=ED?= Cc: Paolo Bonzini , qemu-devel@nongnu.org, Stefan Hajnoczi --17pEHd4RhPHOinZp Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 30, 2014 at 11:55:46AM +0200, Marc Mar=ED wrote: > +static void qvirtio_pci_foreach_callback( > + QPCIDevice *dev, int devfn, void *data) > +{ > + QVirtioPCIForeachData *d =3D data; > + QVirtioPCIDevice *vpcidev =3D qpcidevice_to_qvirtiodevice(dev); > + > + if (vpcidev->vdev.device_type =3D=3D d->device_type) { > + d->func(&vpcidev->vdev, d->user_data); > + } We should think about memory management here. Who will free vpcidev? In the case where device_type matches, ->func() should be responsible for the virtio device it receives. In the case where device_type does not match, we must free vpcidev. > +} > + > +static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data) > +{ > + QVirtioPCIDevice *vpcidev =3D data; > + vpcidev->pdev =3D ((QVirtioPCIDevice *)d)->pdev; > + vpcidev->vdev.device_type =3D ((QVirtioPCIDevice *)d)->vdev.device= _type; > +} This function may need to g_free(d) once you've settled on a memory management rules for virtio-pci.c. > +typedef struct QVirtioPCIForeachData { > + void (*func)(QVirtioDevice *d, void *data); > + uint16_t device_type; > + void *user_data; > +} QVirtioPCIForeachData; This is only used within virtio-pci.c. It should be declared there too since it doesn't need to be public. > diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h > new file mode 100644 > index 0000000..52f6b5b > --- /dev/null > +++ b/tests/libqos/virtio.h > @@ -0,0 +1,28 @@ > +/* > + * libqos virtio definitions > + * > + * Copyright (c) 2014 Marc Mar=ED > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. > + * See the COPYING file in the top-level directory. > + */ > + > +#ifndef LIBQOS_VIRTIO_H > +#define LIBQOS_VIRTIO_H > + > +#define QVIRTQUEUE_MAX_SIZE 1024 Unused, please drop. > +#define QVIRTIO_VENDOR_ID 0x1AF4 > + > +#define QVIRTIO_NET_DEVICE_ID 0x1 > +#define QVIRTIO_BLK_DEVICE_ID 0x2 > + > +typedef struct QVirtioDevice QVirtioDevice; > +typedef struct QVirtQueue QVirtQueue; > +typedef struct QVRing QVRing; QVirtQueue and QVRing are unused. Please drop them. > +static void pci_basic(void) > +{ > + QVirtioPCIDevice *dev; > + QPCIBus *bus; > + > + bus =3D test_start(); > + > + dev =3D qvirtio_pci_device_find(bus, QVIRTIO_BLK_DEVICE_ID); > + g_assert_cmphex(dev->vdev.device_type, =3D=3D, QVIRTIO_BLK_DEVICE_ID= ); > + g_assert_cmphex(dev->pdev->devfn, =3D=3D, ((PCI_SLOT << 3) | PCI_FN)= ); Should dev be freed once we are done with it? --17pEHd4RhPHOinZp Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJTtRiGAAoJEJykq7OBq3PIxFoIAL9dnATkC93hCNbL9R11YmtY saDFvM1QZLwtmI1jVTZC3aXgTiErHLvHBJ+t+PymPeIKqFXzydi9wBiu9r/0prwO wYvxztY04QLYLp6riTKAS7fYdhD/KImTuTDuRR28kWH82/avqaKlipApKs/yNCvF JH/0L4p+/kZRiseQ8wKlnCiXhE5JYaA46SAH304QWkRwl2N5seP8YInycUptp8+y KGhKoIeLA/i1MNXQHFPC4jz1kVDIOBXRCK9iuBn9Cm5u6GsOuuUioaul4oXOLnR2 KSjg2qbGKQVfiUT/C3UdOp1YW4Dwv30jZsRGyPHTkX3WPzMV9w4oFN3CumtjTqo= =NVA6 -----END PGP SIGNATURE----- --17pEHd4RhPHOinZp--