From nobody Wed Nov 5 10:47:35 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 1534156793653869.1987140739947; Mon, 13 Aug 2018 03:39:53 -0700 (PDT) Received: from localhost ([::1]:38693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpAGF-0004JR-7U for importer@patchew.org; Mon, 13 Aug 2018 06:39:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp9tP-0007nw-SG for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp9tO-0002pk-F8 for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:07 -0400 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]:40940) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fp9tO-0002pK-4H; Mon, 13 Aug 2018 06:16:06 -0400 Received: by mail-ed1-x542.google.com with SMTP id e19-v6so7946117edq.7; Mon, 13 Aug 2018 03:16:06 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.125]) by smtp.gmail.com with ESMTPSA id s27-v6sm11670006edb.73.2018.08.13.03.16.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Aug 2018 03:16:04 -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=cqHwdSBa45wOt7gFrX+aE02Ehq/8LyZi45CwU/FyL7Q=; b=Uf7/Sez7lccOPMgGM3EDwIHcu5wu87q19kTHSjZzr40rGHBeyT0zexkBpLeCv/1yYY dcfzEaVW6e4e/ThSNmOD99KzMY638tokwm56lfFD/v7eQ4rztRMBbvnvIKHK/a6MYPpY bx7TiQUd8ls7ieuZBKFbfqq+Xhaq+J9Z83HQpVt5jPiEqiGmqwHNXsZHwotr5np94d3X 4/FvRBrNP3ZhacmxX/GjjXd5xUAlqT1SA2WGj44vmIBcxlbHNkw6qI7YW8XUFHODhUgF zp2Eq16+HQoSXHSpO2l0bwYxAYckHeRvQPzJcf0Rn4IP/6/vR3vKz9DldV6sY1qPMnDd cfwg== 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=cqHwdSBa45wOt7gFrX+aE02Ehq/8LyZi45CwU/FyL7Q=; b=VBLqEYOBYPbZTL2ven2m/WhAUIeE6wUKZCiiEMurHHz9eopH2xWp27shg/iVADSkI0 cr4OTbQLipuYsm1x+wO9eqk9JQfSEAm9+nOm75QrxGFoEIt/oqRKIuuZTBz2RIan85uS yZx5ICHJHouLki1q+vX9gYrjb7kuDtHiz5PTne5lePHT8ho/UMuU9cxyEYfDRAFURB4Y nyGU4QcCR2Z+12vY6HfhGU51/RP0RQbDo9AJFbkKOQW61w6h7TDVZj5V7RKqMN2wayJn gdGG4hBZ6pkN8sxIxgeasHkr+sAj5uT0UDaL1wTmunNxkxf8sEOrMoeBT0KQAZOprs7z X0YA== X-Gm-Message-State: AOUpUlGDtxPIVqLRg56gF4olVaLizSoWISusWZia+WXvmgfGATbo2M4k 4OLCuzmpunXqvQy2GU+u4SRuqWQkco0= X-Google-Smtp-Source: AA+uWPxJwnQ5zhxKjmjl+nkSKaUMxng2L9t/g1XyrTfEBTuAoGPFtyS70cpcZcdI8qXAXlY1E1UjBQ== X-Received: by 2002:a50:9935:: with SMTP id k50-v6mr20722105edb.45.1534155364727; Mon, 13 Aug 2018 03:16:04 -0700 (PDT) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:14:43 +0200 Message-Id: <20180813101453.10200-24-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180813101453.10200-1-e.emanuelegiuseppe@gmail.com> References: <20180813101453.10200-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 23/33] tests/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 , Fam Zheng , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Amit Shah , Emanuele Giuseppe Esposito , Alexander Graf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Greg Kurz , qemu-ppc@nongnu.org, Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini , John Snow , David Gibson 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 495ff5ca9b..362d9ec4b2 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..98d2548ffe --- /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_destructor(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; + } + + fprintf(stderr, "%s not present in virtio-balloon-device\n", interface= ); + g_assert_not_reached(); +} + +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_destructor; + 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; + } + + fprintf(stderr, "%s not present in virtio-balloon-pci\n", interface); + g_assert_not_reached(); +} + +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_register_nodes(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_register_nodes); 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