From nobody Sun Nov 9 22:34:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551982429447587.1516904931123; Thu, 7 Mar 2019 10:13:49 -0800 (PST) Received: from localhost ([127.0.0.1]:56703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xWZ-0005Jf-3r for importer@patchew.org; Thu, 07 Mar 2019 13:13:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqz-0003Qz-MV for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqx-0008GF-PG for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:45 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:36297) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqv-0008D2-Qs for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:43 -0500 Received: by mail-wm1-x32d.google.com with SMTP id j125so10118580wmj.1 for ; Thu, 07 Mar 2019 09:30:40 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=AfDkS6wPBetCgGtPr5eF9mZqt6uxAqMyfxC05FkM4zw=; b=geZyCqmhe91jvpVOy+1LHq1sBjTA73Kl4IFQSNtXJ/efw/nUoMCvShx1QOnzdRui2R 0crZARwyQ0gKEdkJ/ZsRDR+hl6r4Y22Xl+4CIiWtqf5Ox1gXd9oz6J+Aw0QB6LRclTTc 3LWMdKOec3Sbgq10v03/rvk22Ixp6ymWLcf8F5MQoYH5xKhYU51Hh9+fSETF/0m3wiDM BR4YgU8qrCwPYFRXbHgaanFnwfz25rqf2Psso/uc9m5VDTTDgKXhuSPUyFbn/OiPSXii 0Nrsr/l2u6Q9c3MkNBwTNLV9lvY2erEDXUMs77P9TxmVILuqLqJbWgKyR20ixgCxSEEl 9/yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=AfDkS6wPBetCgGtPr5eF9mZqt6uxAqMyfxC05FkM4zw=; b=BDx6L2O04iKbrQcr5PKo/q8QA8zDlsIqZo5sy/ojdrKP3HrUehftsbPzCvK5lgFaGt uLTRs+agmtKj5i9xRZaJ5G58aJjlvJjje6f+/vDzgE/38zpoxSP5/DyB8GiwRpZBqMes ZD0B+Ajh3rxAsPFAIB7Dxp7n53mwn9QvplQy3IhYIVgNk4aL9nqmFcEPiDCgp+D1soOh N3+FMYe/OLV6TPqOMjV2vgZYjHRazXN+IlDybHFySMNZ8qwCD8E9405f4wyiTMMaVp/n VvsTvUZ2oc3D5TTqr1rD27eymFva5z4Ve/C+mSlQUuifJ+37G2jcqmeAG2yxWGeugrLG Wy3g== X-Gm-Message-State: APjAAAUlnzERCzSCZ44H21jrArGNYl1RsEO8uPczOxA43NGbgPF1CBVZ WEZs8U4KB1UUXdlm3TECCM5yY3B8 X-Google-Smtp-Source: APXvYqxswDdzwNi7dDq5cdnHF9RCZgpU+hBIEndgzHjuufiHCshtay7BfiIGa8RO3MyPaM9tBk2tDg== X-Received: by 2002:a7b:c94c:: with SMTP id i12mr6325939wml.2.1551979839159; Thu, 07 Mar 2019 09:30:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:37 +0100 Message-Id: <1551979804-6060-31-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32d Subject: [Qemu-devel] [PULL 30/57] tests/libqos: 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito 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 Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-balloon.c | 113 ++++++++++++++++++++++++++++++++++++++= ++++ tests/libqos/virtio-balloon.h | 39 +++++++++++++++ 3 files changed, 153 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 8feca79..53794cd 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -746,6 +746,7 @@ qos-test-obj-y +=3D tests/libqos/e1000e.o qos-test-obj-y +=3D tests/libqos/sdhci.o qos-test-obj-y +=3D $(libqos-virtio-obj-y) qos-test-obj-$(CONFIG_VIRTFS) +=3D tests/libqos/virtio-9p.o +qos-test-obj-y +=3D tests/libqos/virtio-balloon.o qos-test-obj-y +=3D tests/libqos/virtio-serial.o =20 # Machines diff --git a/tests/libqos/virtio-balloon.c b/tests/libqos/virtio-balloon.c new file mode 100644 index 0000000..7e6e9e9 --- /dev/null +++ b/tests/libqos/virtio-balloon.c @@ -0,0 +1,113 @@ +/* + * 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_get_driver(QVirtioBalloon *v_balloon, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-balloon")) { + return v_balloon; + } + if (!g_strcmp0(interface, "virtio")) { + return v_balloon->vdev; + } + + fprintf(stderr, "%s not present in virtio-balloon-device\n", interface= ); + g_assert_not_reached(); +} + +static void *qvirtio_balloon_device_get_driver(void *object, + const char *interface) +{ + QVirtioBalloonDevice *v_balloon =3D object; + return qvirtio_balloon_get_driver(&v_balloon->balloon, interface); +} + +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.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, "pci-device")) { + return v_balloon->pci_vdev.pdev; + } + return qvirtio_balloon_get_driver(&v_balloon->balloon, interface); +} + +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-bus", NULL); + qos_node_produces("virtio-balloon-device", "virtio"); + 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", "pci-device"); + qos_node_produces("virtio-balloon-pci", "virtio"); + 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 0000000..e8066c4 --- /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 1.8.3.1