From nobody Sun Nov 9 22:32:27 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 1551981747971250.93677755629017; Thu, 7 Mar 2019 10:02:27 -0800 (PST) Received: from localhost ([127.0.0.1]:56537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xLc-0004A0-Lg for importer@patchew.org; Thu, 07 Mar 2019 13:02:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqz-0003Qx-M0 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-0008G0-N8 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:45 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:37440) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqt-0008BD-Pq for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:41 -0500 Received: by mail-wr1-x443.google.com with SMTP id w6so18400069wrs.4 for ; Thu, 07 Mar 2019 09:30:37 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:36 -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=ult0mEF+2e0zw3ErazF5kyITFBELMbqUeWoO+zunlEg=; b=HevWtwEc0kBf+D7vBkeHWZDoiv4dp62qeeBGUUGDnct8SkVqXtYRdzZYc7wEuqF3Gp G3/X15BTx1EHYmJ0tGZHgGN+pROXtCuTUndRxOSPEnkObuqgS+GZeAHG/d4K1eJHjqdE /QMew4CR0ci0JMQtiuoV3AokYAa0MnBI18ZH+N/N22t4oENOxRmKAuN6HtKZ7BZa3q9q 0K629xX2SYynxCBY5V4sr8dp6300uiNKEqpCzU0yAwBJDnaVy2rC1IshKjvAY1GXFR2L lRe0c7s+4CuDDvxmJxQDjntaa4lCBNwyjOQlUJZFUhOeW48a6bWhOw+tZ0RFZ/kUE97a 5z7Q== 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=ult0mEF+2e0zw3ErazF5kyITFBELMbqUeWoO+zunlEg=; b=DaQvY0zjkbnPtZwaMaM7/jfKdPRjcDfack0s96dxNsl0AkUqNp3hqDPM+y7TDr8v// BY9D7HXJ2/NSZcNxY/FPYOe8F+2SO6BddCTtpSPB33j68g15OAzZ/rYJwBVz4MeymRHq ahIZnj+W7wjYiX6SyCm0hRrctF6zOckWGOPxQ6WsuSemE3dQgIMhOx+HMnfsi858Mveu wzBvMMY6corag+tJTMx5yFuSwL8eQt8Tbmg+HGGzvg/hDMu3fXlTlLPum2IK3tgQDD68 ilfidzSmaJ6pOnt96m1dKUmtEFEb5N6jCdpWBqwM2IEOTV33yLwTSEjigqJ8NjgypR8t qmbQ== X-Gm-Message-State: APjAAAXJefjQzIAGv5Sq+1/+aO2mqdG5NGUP6bCSQv/zRiFhx3C+b7nr RMsMwzTEnIs1WFXN8XqMMu/9IqZA X-Google-Smtp-Source: APXvYqxzmfmbegrkD2oQMfQkte9wLh9W6LqVz4SFe+KJIhHRIpDLNo9wJgvJGR9nd2T6NjVnKCwZuA== X-Received: by 2002:a5d:5042:: with SMTP id h2mr7727504wrt.12.1551979836843; Thu, 07 Mar 2019 09:30:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:35 +0100 Message-Id: <1551979804-6060-29-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::443 Subject: [Qemu-devel] [PULL 28/57] tests/libqos: virtio-9p 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-9p-pci and virtio-9p-device. Both nodes produce virtio-9p, but virtio-9p-pci receives a pci-bus and overrides virtio-pci QOSGraphObject and its functions, while virtio-9p-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-9p.c | 173 +++++++++++++++++++++++++++++++++++++++++++= ++++ tests/libqos/virtio-9p.h | 42 ++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 tests/libqos/virtio-9p.c create mode 100644 tests/libqos/virtio-9p.h diff --git a/tests/Makefile.include b/tests/Makefile.include index d0cd6d2..cb8f0c5 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -748,6 +748,7 @@ qos-test-obj-y +=3D $(libqos-pc-obj-y) $(libqos-spapr-o= bj-y) 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-serial.o =20 # Machines diff --git a/tests/libqos/virtio-9p.c b/tests/libqos/virtio-9p.c new file mode 100644 index 0000000..a378b56 --- /dev/null +++ b/tests/libqos/virtio-9p.c @@ -0,0 +1,173 @@ +/* + * 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 "standard-headers/linux/virtio_ids.h" +#include "libqos/virtio-9p.h" +#include "libqos/qgraph.h" + +static QGuestAllocator *alloc; + +static void virtio_9p_cleanup(QVirtio9P *interface) +{ + qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc); +} + +static void virtio_9p_setup(QVirtio9P *interface) +{ + interface->vq =3D qvirtqueue_setup(interface->vdev, alloc, 0); + qvirtio_set_driver_ok(interface->vdev); +} + +/* virtio-9p-device */ +static void virtio_9p_device_destructor(QOSGraphObject *obj) +{ + QVirtio9PDevice *v_9p =3D (QVirtio9PDevice *) obj; + QVirtio9P *v9p =3D &v_9p->v9p; + + virtio_9p_cleanup(v9p); +} + +static void virtio_9p_device_start_hw(QOSGraphObject *obj) +{ + QVirtio9PDevice *v_9p =3D (QVirtio9PDevice *) obj; + QVirtio9P *v9p =3D &v_9p->v9p; + + virtio_9p_setup(v9p); +} + +static void *virtio_9p_get_driver(QVirtio9P *v_9p, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-9p")) { + return v_9p; + } + if (!g_strcmp0(interface, "virtio")) { + return v_9p->vdev; + } + + fprintf(stderr, "%s not present in virtio-9p-device\n", interface); + g_assert_not_reached(); +} + +static void *virtio_9p_device_get_driver(void *object, const char *interfa= ce) +{ + QVirtio9PDevice *v_9p =3D object; + return virtio_9p_get_driver(&v_9p->v9p, interface); +} + +static void *virtio_9p_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtio9PDevice *virtio_device =3D g_new0(QVirtio9PDevice, 1); + QVirtio9P *interface =3D &virtio_device->v9p; + + interface->vdev =3D virtio_dev; + alloc =3D t_alloc; + + virtio_device->obj.destructor =3D virtio_9p_device_destructor; + virtio_device->obj.get_driver =3D virtio_9p_device_get_driver; + virtio_device->obj.start_hw =3D virtio_9p_device_start_hw; + + return &virtio_device->obj; +} + +/* virtio-9p-pci */ +static void virtio_9p_pci_destructor(QOSGraphObject *obj) +{ + QVirtio9PPCI *v9_pci =3D (QVirtio9PPCI *) obj; + QVirtio9P *interface =3D &v9_pci->v9p; + QOSGraphObject *pci_vobj =3D &v9_pci->pci_vdev.obj; + + virtio_9p_cleanup(interface); + qvirtio_pci_destructor(pci_vobj); +} + +static void virtio_9p_pci_start_hw(QOSGraphObject *obj) +{ + QVirtio9PPCI *v9_pci =3D (QVirtio9PPCI *) obj; + QVirtio9P *interface =3D &v9_pci->v9p; + QOSGraphObject *pci_vobj =3D &v9_pci->pci_vdev.obj; + + qvirtio_pci_start_hw(pci_vobj); + virtio_9p_setup(interface); +} + +static void *virtio_9p_pci_get_driver(void *object, const char *interface) +{ + QVirtio9PPCI *v_9p =3D object; + if (!g_strcmp0(interface, "pci-device")) { + return v_9p->pci_vdev.pdev; + } + return virtio_9p_get_driver(&v_9p->v9p, interface); +} + +static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVirtio9PPCI *v9_pci =3D g_new0(QVirtio9PPCI, 1); + QVirtio9P *interface =3D &v9_pci->v9p; + QOSGraphObject *obj =3D &v9_pci->pci_vdev.obj; + + virtio_pci_init(&v9_pci->pci_vdev, pci_bus, addr); + interface->vdev =3D &v9_pci->pci_vdev.vdev; + alloc =3D t_alloc; + + g_assert_cmphex(interface->vdev->device_type, =3D=3D, VIRTIO_ID_9P); + + obj->destructor =3D virtio_9p_pci_destructor; + obj->start_hw =3D virtio_9p_pci_start_hw; + obj->get_driver =3D virtio_9p_pci_get_driver; + + return obj; +} + +static void virtio_9p_register_nodes(void) +{ + const char *str_simple =3D "fsdev=3Dfsdev0,mount_tag=3D" MOUNT_TAG; + const char *str_addr =3D "fsdev=3Dfsdev0,addr=3D04.0,mount_tag=3D" MOU= NT_TAG; + + QPCIAddress addr =3D { + .devfn =3D QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts =3D { + .before_cmd_line =3D "-fsdev synth,id=3Dfsdev0", + }; + + /* virtio-9p-device */ + opts.extra_device_opts =3D str_simple, + qos_node_create_driver("virtio-9p-device", virtio_9p_device_create); + qos_node_consumes("virtio-9p-device", "virtio-bus", &opts); + qos_node_produces("virtio-9p-device", "virtio"); + qos_node_produces("virtio-9p-device", "virtio-9p"); + + /* virtio-9p-pci */ + opts.extra_device_opts =3D str_addr; + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-9p-pci", virtio_9p_pci_create); + qos_node_consumes("virtio-9p-pci", "pci-bus", &opts); + qos_node_produces("virtio-9p-pci", "pci-device"); + qos_node_produces("virtio-9p-pci", "virtio"); + qos_node_produces("virtio-9p-pci", "virtio-9p"); + +} + +libqos_init(virtio_9p_register_nodes); diff --git a/tests/libqos/virtio-9p.h b/tests/libqos/virtio-9p.h new file mode 100644 index 0000000..dba2277 --- /dev/null +++ b/tests/libqos/virtio-9p.h @@ -0,0 +1,42 @@ +/* + * 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 QVirtio9P QVirtio9P; +typedef struct QVirtio9PPCI QVirtio9PPCI; +typedef struct QVirtio9PDevice QVirtio9PDevice; + +#define MOUNT_TAG "qtest" + +struct QVirtio9P { + QVirtioDevice *vdev; + QVirtQueue *vq; +}; + +struct QVirtio9PPCI { + QVirtioPCIDevice pci_vdev; + QVirtio9P v9p; +}; + +struct QVirtio9PDevice { + QOSGraphObject obj; + QVirtio9P v9p; +}; --=20 1.8.3.1