From nobody Tue Nov 4 22:01:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533566810073864.9955555814095; Mon, 6 Aug 2018 07:46:50 -0700 (PDT) Received: from localhost ([::1]:34414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgmW-0006bp-MW for importer@patchew.org; Mon, 06 Aug 2018 10:46:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgbE-0005BC-Pd for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmgbD-0000zh-CS for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:08 -0400 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]:33044) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmgbD-0000zb-1j for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:07 -0400 Received: by mail-ed1-x542.google.com with SMTP id x5-v6so5274715edr.0 for ; Mon, 06 Aug 2018 07:35:06 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.126]) by smtp.gmail.com with ESMTPSA id x13-v6sm14615157edx.17.2018.08.06.07.35.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 07:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A5lRqzEPsxqpIPiQK5fWfwAAZneUxuauMegR0KdnnGY=; b=cAqKZGLXxx7VfjI2g7BaQvGfH/EcXRk54oqKTnDJRAOwj0YY11aLQsgZmgeAd8ewFE 7dylyMgkWk7zWtsq0BBvfPYyO9pUktYWcPbaUbzco+JnofHO6Edk5P0m4Q8xusqBwGQo hS0qNK8cvyJcBnBal2dGFOjWp/eY5Qj3Qw1B79QSa9/9/ingrS3W/DJ4p3KctXBTAPJ4 m48gV1h/nz7NYEO3Gj6DZronj0hSFRHKyjal6GQrwp//PkxFy/ABvmyCqJK4Oii1/2id /0od50d1RgTgSl9jtDjYh81Lnywo9NefZ2a67M94hHGon7f2n24KoV2c1lpGh1DMcxZ3 q3Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A5lRqzEPsxqpIPiQK5fWfwAAZneUxuauMegR0KdnnGY=; b=X0n28Gh0U/kU3dEYBNHIFFITY5urD/4Yu5OPuMEK2csEFlWHCGR7zoB4NNupR0r7ZV qhmzmLhgPxTDCX/BTWcjXtiE81YzOWR2RTn27dbKIIv+5nQizawEviaxIr6mKo5korKX DXBJHx3Kpo99KPBSzweRPY16Mk/vSI5oRsx4ZbE4vpfkReP/X2/73NgIC3bpnAuPs0bu DZwfJrzfcnzAtC+JHp8ubWHkczWazQ2gBmEVKHExDAtaYdjqw19aSfH6QQUTW2TGsmLh sFZln3+2B3io65Lx4/W8KZiPsAZVkw8xbn5ESHYiTRfFYhH4J074ZXcYZZzclIEMMOrR XoWA== X-Gm-Message-State: AOUpUlH0UDtTwZtptzbYfORvH+uTQdWPdq+q7dZ69NHAm5TSNKMRYukC LnUlTcTAffjxRHpds8Rdh5w= X-Google-Smtp-Source: AAOMgpfrUB7QKNMoWxBuwoIfR28tHHK0b29XRcGaA1JWK3vEI9Goi1T7rC9oo269HqJPMVlSMUAaMg== X-Received: by 2002:a50:c251:: with SMTP id t17-v6mr18489876edf.108.1533566106015; Mon, 06 Aug 2018 07:35:06 -0700 (PDT) From: Emanuele Giuseppe Esposito To: Paolo Bonzini Date: Mon, 6 Aug 2018 16:34:02 +0200 Message-Id: <20180806143412.27722-25-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180806143412.27722-1-e.emanuelegiuseppe@gmail.com> References: <20180806143412.27722-1-e.emanuelegiuseppe@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::542 Subject: [Qemu-devel] [PATCH v2 24/34] test/qgraph: virtio-balloon driver and interface nodes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Stefan Hajnoczi , Emanuele Giuseppe Esposito , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add qgraph nodes for virtio-balloon-pci and virtio-balloon-device. Both nodes produce virtio-balloon, but virtio-balloon-pci receives a pci-bus and uses virtio-pci QOSGraphObject and functions, while virtio-balloon-device receives a virtio and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito --- tests/Makefile.include | 1 + tests/libqos/virtio-balloon.c | 111 ++++++++++++++++++++++++++++++++++ tests/libqos/virtio-balloon.h | 39 ++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 tests/libqos/virtio-balloon.c create mode 100644 tests/libqos/virtio-balloon.h diff --git a/tests/Makefile.include b/tests/Makefile.include index f367e9e321..a3d425918f 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -770,6 +770,7 @@ libqgraph-machines-obj-y +=3D tests/libqos/virt-machine= .o =20 libqgraph-virtio-obj-y =3D tests/libqos/virtio-serial.o libqgraph-virtio-obj-y +=3D tests/libqos/virtio-9p.o +libqgraph-virtio-obj-y +=3D tests/libqos/virtio-balloon.o =20 libqgraph-pci-obj-y =3D $(libqos-virtio-obj-y) libqgraph-pci-obj-y +=3D $(libqgraph-machines-obj-y) diff --git a/tests/libqos/virtio-balloon.c b/tests/libqos/virtio-balloon.c new file mode 100644 index 0000000000..e97a9038fc --- /dev/null +++ b/tests/libqos/virtio-balloon.c @@ -0,0 +1,111 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-balloon.h" + +/* virtio-balloon-device */ +static void qvirtio_balloon_device_destroy(QOSGraphObject *obj) +{ + QVirtioBalloonDevice *v_balloon =3D (QVirtioBalloonDevice *) obj; + + g_free(v_balloon); +} + +static void *qvirtio_balloon_device_get_driver(void *object, + const char *interface) +{ + QVirtioBalloonDevice *v_balloon =3D object; + if (!g_strcmp0(interface, "virtio-balloon")) { + return &v_balloon->balloon; + } + + printf("%s not present in virtio-balloon-device\n", interface); + abort(); +} + +static void *virtio_balloon_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioBalloonDevice *virtio_bdevice =3D g_new0(QVirtioBalloonDevice, = 1); + QVirtioBalloon *interface =3D &virtio_bdevice->balloon; + + interface->vdev =3D virtio_dev; + + virtio_bdevice->obj.destructor =3D qvirtio_balloon_device_destroy; + virtio_bdevice->obj.get_driver =3D qvirtio_balloon_device_get_driver; + + return &virtio_bdevice->obj; +} + +/* virtio-balloon-pci */ +static void *qvirtio_balloon_pci_get_driver(void *object, + const char *interface) +{ + QVirtioBalloonPCI *v_balloon =3D object; + if (!g_strcmp0(interface, "virtio-balloon")) { + return &v_balloon->balloon; + } + + printf("%s not present in virtio-balloon-pci\n", interface); + abort(); +} + +static void *virtio_balloon_pci_create(void *pci_bus, QGuestAllocator *t_a= lloc, + void *addr) +{ + QVirtioBalloonPCI *virtio_bpci =3D g_new0(QVirtioBalloonPCI, 1); + QVirtioBalloon *interface =3D &virtio_bpci->balloon; + QOSGraphObject *obj =3D &virtio_bpci->pci_vdev.obj; + + + virtio_pci_init(&virtio_bpci->pci_vdev, pci_bus, addr); + interface->vdev =3D &virtio_bpci->pci_vdev.vdev; + + obj->get_driver =3D qvirtio_balloon_pci_get_driver; + + return obj; +} + +static void virtio_balloon(void) +{ + QPCIAddress addr =3D { + .devfn =3D QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "addr=3D04.0", + }; + + /* virtio-balloon-device */ + qos_node_create_driver("virtio-balloon-device", + virtio_balloon_device_create); + qos_node_consumes("virtio-balloon-device", "virtio", NULL); + qos_node_produces("virtio-balloon-device", "virtio-balloon"); + + /* virtio-balloon-pci */ + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-balloon-pci", virtio_balloon_pci_create= ); + qos_node_consumes("virtio-balloon-pci", "pci-bus", &opts); + qos_node_produces("virtio-balloon-pci", "virtio-balloon"); +} + +libqos_init(virtio_balloon); diff --git a/tests/libqos/virtio-balloon.h b/tests/libqos/virtio-balloon.h new file mode 100644 index 0000000000..e8066c42bb --- /dev/null +++ b/tests/libqos/virtio-balloon.h @@ -0,0 +1,39 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "libqos/qgraph.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" + +typedef struct QVirtioBalloon QVirtioBalloon; +typedef struct QVirtioBalloonPCI QVirtioBalloonPCI; +typedef struct QVirtioBalloonDevice QVirtioBalloonDevice; + +struct QVirtioBalloon { + QVirtioDevice *vdev; +}; + +struct QVirtioBalloonPCI { + QVirtioPCIDevice pci_vdev; + QVirtioBalloon balloon; +}; + +struct QVirtioBalloonDevice { + QOSGraphObject obj; + QVirtioBalloon balloon; +}; --=20 2.17.1