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 153415652003092.53574007984389; Mon, 13 Aug 2018 03:35:20 -0700 (PDT) Received: from localhost ([::1]:38641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpABy-0008Uw-T7 for importer@patchew.org; Mon, 13 Aug 2018 06:35:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp9tf-0007ys-FR for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp9td-00038U-Db for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:23 -0400 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]:36080) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fp9td-00037Z-3e; Mon, 13 Aug 2018 06:16:21 -0400 Received: by mail-ed1-x544.google.com with SMTP id k15-v6so7957971edr.3; Mon, 13 Aug 2018 03:16:21 -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.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Aug 2018 03:16:19 -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=dzlzmYUlt0ZbKbfosOcyCLx3SLPKsxWGbpJWbKkVHrM=; b=Kt727KqhMNtYZiu6njWSP6kfwWFfO7jt+CdNv4DNL9p2ZLIJdNb3gkAT/0/EFzKVhl 3kLxQJjxVHV2ZB1TAtCslfxuOipHqdFRBDBAXHADi3V7ViELIEbLq8667uj+Y4bRaXf1 tpmOsF9+7uGPu83G/ayoXrupoxBukObFXKxuSfTWfnx/bVWZgxjt/GOfbm6/VyRoTfeZ 0K2vglSEu/nwY7KAP6nmFctoNTxypTbOXmq0vdSIuUZyuRsIy4Ob6cpTG5jumrhS7uJN xuYHAvdEICy5zcIkNmZPHxKpRYV92w9PAEYCQApUiNEGRR7Ut9vWW59poiMUYX72fA0B ZiHQ== 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=dzlzmYUlt0ZbKbfosOcyCLx3SLPKsxWGbpJWbKkVHrM=; b=O1+o4y8SJosQvBCkUMbY75e4qIoN3w1yI0Eqw0bmqp9yb4/r77hAm3bVf8dSLR+bX2 f+VtjpDNx3PP8psXsESSjl/djFN1Wli6aXXVZoTM32hh75JZG7aR4oe7k513WETCio/d SCYwuNCEs/1JHqzacBpDloLnDq/7nJChO7lybGg5i1v2uLDibswi58cmx+tMNY/zgfEm 9YzRIY7x+B3RznXBkv4bXEGsRp7klj8/LCPFJfuSlUGSxXiDOsjhlriPXz4+9/gzoGmB FDuAPUjqBTQmIKNytfSsXqCZbXEFW4Mf2PX0Ujhjom9kcH5lZ2ema+nLk6wImj1lrV0i ID0g== X-Gm-Message-State: AOUpUlHemDObWi8dqZ/wOggwDPY5L4T6MBn6nAVmT0httAuKQOfQrpeC mvKK5Bt6odKVkf9IBl9lh6nhl1dK2Jw= X-Google-Smtp-Source: AA+uWPx6fXDQMh9fwsOImu5Zn28LCVUvcEXaRT86w9DSvZnLYFUCVWNJVaEIOhbid+nym1fX65jG0Q== X-Received: by 2002:a50:a93c:: with SMTP id l57-v6mr20774398edc.229.1534155379781; Mon, 13 Aug 2018 03:16:19 -0700 (PDT) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:14:51 +0200 Message-Id: <20180813101453.10200-32-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::544 Subject: [Qemu-devel] [PATCH 31/33] tests/qgraph: virtio-scsi 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-scsi-pci and virtio-scsi-device. Both nodes produce virtio-scsi, but virtio-scsi-pci receives a pci-bus and uses virtio-pci QOSGraphObject and its functions, while virtio-scsi-device receives a virtio and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito --- tests/Makefile.include | 1 + tests/libqos/virtio-scsi.c | 117 +++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-scsi.h | 39 +++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 tests/libqos/virtio-scsi.c create mode 100644 tests/libqos/virtio-scsi.h diff --git a/tests/Makefile.include b/tests/Makefile.include index 7a2b67c1ec..a839763505 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -768,6 +768,7 @@ libqgraph-virtio-obj-y +=3D tests/libqos/virtio-balloon= .o libqgraph-virtio-obj-y +=3D tests/libqos/virtio-rng.o libqgraph-virtio-obj-y +=3D tests/libqos/virtio-blk.o libqgraph-virtio-obj-y +=3D tests/libqos/virtio-net.o +libqgraph-virtio-obj-y +=3D tests/libqos/virtio-scsi.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-scsi.c b/tests/libqos/virtio-scsi.c new file mode 100644 index 0000000000..8f13c0bfaf --- /dev/null +++ b/tests/libqos/virtio-scsi.c @@ -0,0 +1,117 @@ +/* + * 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/qgraph.h" +#include "libqos/virtio-scsi.h" + +/* virtio-scsi-device */ +static void qvirtio_scsi_device_destructor(QOSGraphObject *obj) +{ + QVirtioSCSIDevice *v_scsi =3D (QVirtioSCSIDevice *) obj; + + g_free(v_scsi); +} + +static void *qvirtio_scsi_device_get_driver(void *object, + const char *interface) +{ + QVirtioSCSIDevice *v_scsi =3D object; + if (!g_strcmp0(interface, "virtio-scsi")) { + return &v_scsi->scsi; + } + + fprintf(stderr, "%s not present in virtio-scsi-device\n", interface); + g_assert_not_reached(); +} + +static void *virtio_scsi_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioSCSIDevice *virtio_bdevice =3D g_new0(QVirtioSCSIDevice, 1); + QVirtioSCSI *interface =3D &virtio_bdevice->scsi; + + interface->vdev =3D virtio_dev; + + virtio_bdevice->obj.destructor =3D qvirtio_scsi_device_destructor; + virtio_bdevice->obj.get_driver =3D qvirtio_scsi_device_get_driver; + + return &virtio_bdevice->obj; +} + +/* virtio-scsi-pci */ +static void *qvirtio_scsi_pci_get_driver(void *object, + const char *interface) +{ + QVirtioSCSIPCI *v_scsi =3D object; + if (!g_strcmp0(interface, "virtio-scsi")) { + return &v_scsi->scsi; + } + + fprintf(stderr, "%s not present in virtio-scsi-pci\n", interface); + g_assert_not_reached(); +} + +static void *virtio_scsi_pci_create(void *pci_bus, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioSCSIPCI *virtio_spci =3D g_new0(QVirtioSCSIPCI, 1); + QVirtioSCSI *interface =3D &virtio_spci->scsi; + QOSGraphObject *obj =3D &virtio_spci->pci_vdev.obj; + + virtio_pci_init(&virtio_spci->pci_vdev, pci_bus, addr); + interface->vdev =3D &virtio_spci->pci_vdev.vdev; + + g_assert_cmphex(interface->vdev->device_type, =3D=3D, VIRTIO_ID_SCSI); + + obj->get_driver =3D qvirtio_scsi_pci_get_driver; + + return obj; +} + +static void virtio_scsi_register_nodes(void) +{ + QPCIAddress addr =3D { + .devfn =3D QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts =3D { + .before_cmd_line =3D "-drive id=3Ddrv0,if=3Dnone,file=3Dnull-co://= ,format=3Draw", + .after_cmd_line =3D "-device scsi-hd,bus=3Dvs0.0,drive=3Ddrv0", + }; + + /* virtio-scsi-device */ + opts.extra_device_opts =3D "id=3Dvs0"; + qos_node_create_driver("virtio-scsi-device", + virtio_scsi_device_create); + qos_node_consumes("virtio-scsi-device", "virtio", &opts); + qos_node_produces("virtio-scsi-device", "virtio-scsi"); + + /* virtio-scsi-pci */ + opts.extra_device_opts =3D "id=3Dvs0,addr=3D04.0"; + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-scsi-pci", virtio_scsi_pci_create); + qos_node_consumes("virtio-scsi-pci", "pci-bus", &opts); + qos_node_produces("virtio-scsi-pci", "virtio-scsi"); +} + +libqos_init(virtio_scsi_register_nodes); diff --git a/tests/libqos/virtio-scsi.h b/tests/libqos/virtio-scsi.h new file mode 100644 index 0000000000..17a47beddc --- /dev/null +++ b/tests/libqos/virtio-scsi.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 QVirtioSCSI QVirtioSCSI; +typedef struct QVirtioSCSIPCI QVirtioSCSIPCI; +typedef struct QVirtioSCSIDevice QVirtioSCSIDevice; + +struct QVirtioSCSI { + QVirtioDevice *vdev; +}; + +struct QVirtioSCSIPCI { + QVirtioPCIDevice pci_vdev; + QVirtioSCSI scsi; +}; + +struct QVirtioSCSIDevice { + QOSGraphObject obj; + QVirtioSCSI scsi; +}; --=20 2.17.1