From nobody Tue Nov 4 22:00:42 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 1533567335591651.6766850277133; Mon, 6 Aug 2018 07:55:35 -0700 (PDT) Received: from localhost ([::1]:34456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgv0-00066A-B0 for importer@patchew.org; Mon, 06 Aug 2018 10:55:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgbE-0005AT-2X for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmgbA-0000zG-Tl for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:08 -0400 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:39562) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmgbA-0000z0-Iv for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:04 -0400 Received: by mail-ed1-x541.google.com with SMTP id h4-v6so5253526edi.6 for ; Mon, 06 Aug 2018 07:35:04 -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.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 07:35:02 -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=mmPdT2x581ZtEsxPuby6AveaYcDLM0ZH11GZlBLML7c=; b=T6VJOdbHHwh1GEmwh/prCT5rX5Yj62NoAwBeLIwbEiBqHd9MabdgMWcRWmrvQuuCKU FPQ6eHbGmTDUX9HauAhMZnrS1mnkus1XAbqx5a1OBIHw9JTADYrnsdjLa6RUhkNe56KF CHPDJErqyJiPBwt/ZF8JP6Mn24zQcG/IvhTnm/lMuphzggAOzX6xmL3YJpSdma9f+/BX Tbiw/E3mP/SjxskTb0sh38GIbf/nddZotH+yKE7Vb32+IbVFJJDtxdCi91MO0TpnRLl8 yQNizVuy+9JonzRXY/8gz7pXY5AvviYQWXTA/Ynj18zc4RMhPiJ+nDmN0Qu5eAqKbkkh m8SQ== 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=mmPdT2x581ZtEsxPuby6AveaYcDLM0ZH11GZlBLML7c=; b=Atwk2HYDlPt5/1wBRcU4BRIRQ6xzYgVgD+B7Vn9BDQ+CU283U2Lef2fWixwbqHuqJS PethrOwZxlqK/pZIrD25GACybqG1T9X5c+dK6yIAZDnnxdiCXaSTbHcWVfikm1stp6H0 68Ri23AyHhGaSjUDD3XasRBUBSveE/ut2Ot516cSAQVGimgz4Jq6Zb5Sab5+bhwrPIY+ cmx6llFhH/2MucOGMp3JBjFfnSNKlrdo7Rr0XySLOjRkonHJ37q+UydL+dvc9p2pLKmp CRuiBcO7BDBSjquQfyjCgCDJU6ImH1DMzK+VXIz1mx7f4geZBlfQR0Iuq0V1Bv6UE6cK VwQQ== X-Gm-Message-State: AOUpUlGYllglWIBKP9l+NrJ/UAPoTRXnD/ABRYg6X8LPLlciZiZe83iV W9dlNa48Lz6m/JXf6JRNBs43oTq3 X-Google-Smtp-Source: AAOMgpdkUTSYPAzPt2Dg6pr42WeDGb3AjdTtdQ+bQS0TIILqk3WGZfGIsTNk6asAGi00rstRYDqzoA== X-Received: by 2002:a50:8b88:: with SMTP id m8-v6mr18787835edm.165.1533566103516; Mon, 06 Aug 2018 07:35:03 -0700 (PDT) From: Emanuele Giuseppe Esposito To: Paolo Bonzini Date: Mon, 6 Aug 2018 16:34:00 +0200 Message-Id: <20180806143412.27722-23-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::541 Subject: [Qemu-devel] [PATCH v2 22/34] test/qgraph: 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: 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-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 --- tests/Makefile.include | 1 + tests/libqos/virtio-9p.c | 164 +++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-9p.h | 42 ++++++++++ 3 files changed, 207 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 f258a7778e..e4385555e3 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -770,6 +770,7 @@ libqgraph-machines-obj-y +=3D tests/libqos/ppc64_pserie= s-machine.o 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 =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-9p.c b/tests/libqos/virtio-9p.c new file mode 100644 index 0000000000..88437d58af --- /dev/null +++ b/tests/libqos/virtio-9p.c @@ -0,0 +1,164 @@ +/* + * 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); +} + +/* virtio-9p-device */ +static void virtio_9p_device_destroy(QOSGraphObject *obj) +{ + QVirtio9PDevice *v_9p =3D (QVirtio9PDevice *) obj; + QVirtio9P *interface =3D &v_9p->v9p; + virtio_9p_cleanup(interface); + + g_free(v_9p); +} + +static void virtio_9p_device_start_hw(QOSGraphObject *obj) +{ + QVirtio9PDevice *v_9p =3D (QVirtio9PDevice *) obj; + QVirtio9P *interface =3D &v_9p->v9p; + + virtio_9p_setup(interface); +} + +static void *virtio_9p_device_get_driver(void *object, const char *interfa= ce) +{ + QVirtio9PDevice *v_9p =3D object; + if (!g_strcmp0(interface, "virtio-9p")) { + return &v_9p->v9p; + } + + printf("%s not present in virtio-9p-device\n", interface); + abort(); +} + +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_destroy; + 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_destroy(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_destroy(pci_vobj); + g_free(v9_pci); +} + +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 *v9p =3D object; + if (!g_strcmp0(interface, "virtio-9p")) { + return &v9p->v9p; + } + + printf("%s not present in virtio-9p-pci\n", interface); + abort(); +} + +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_destroy; + obj->start_hw =3D virtio_9p_pci_start_hw; + obj->get_driver =3D virtio_9p_pci_get_driver; + + return obj; +} + +static void virtio_9p(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", &opts); + 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", "virtio-9p"); + +} + +libqos_init(virtio_9p); diff --git a/tests/libqos/virtio-9p.h b/tests/libqos/virtio-9p.h new file mode 100644 index 0000000000..dba22772b5 --- /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 2.17.1