From nobody Sun Nov 9 22:27:04 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 1551983167999889.2815119242717; Thu, 7 Mar 2019 10:26:07 -0800 (PST) Received: from localhost ([127.0.0.1]:56914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xiR-0007ER-H8 for importer@patchew.org; Thu, 07 Mar 2019 13:25:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr8-0003bq-Sc for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr7-0008PY-Jk for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:54 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:40180) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr7-0008Or-99 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:53 -0500 Received: by mail-wm1-x342.google.com with SMTP id g20so9984426wmh.5 for ; Thu, 07 Mar 2019 09:30:53 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:51 -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=hw2KDZVvMRBZcF9iEF1OCPR1qLYZdoVWF9GY0F8TsQA=; b=M3YXa/0bbkvGiV7P+CaiAcLsCRL2d84rgBIe9PxAhWMR7P6qUwdjcquf6F0OEYYXlr foe645Xqf2/z4jU79NCWE7x/tOKaWrimX8FcJzqAfqYWYMJtwxH22xk2mAi5qh1VVK8V PnsstKlhImYWZ4DTWplDKDD97DW6x1cxzm92KoqXknpK2xX7P1ToKgOLlCn+0U3Iwbvd jIjz1WoSbzZ49C8bq8mPoAjGRSyvumQUyTTUHGcrkvk8aRVm/tHrlLbIAkCSl/uR5YQv xf8/OHIV30W5Pa00Na6/d7Q1hu930IJdkqmFJghjvaTDPsdBt3wV3kTksVFNSlUAj6Ey sTuQ== 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=hw2KDZVvMRBZcF9iEF1OCPR1qLYZdoVWF9GY0F8TsQA=; b=GX/t3aygdhO+msqkpHWiL3q9tX4QI/IlDmJJurJx5BhofhA0TlqJS85vkjLeSRLpRS Y+D26XYKo/tHwO+UtChO1ouubum/u3jf8oO/uedieAcKMbGUvhHEhIaLhnMbUeoGRyRi c5ibgY4n0rXgY2VYHsHT+dlbBbVMmDHNBl1cdxflm1uMcKb1Xx6cHK7HUI1Zqe6SnrvO lDVlxjFfIM4nKRrAtAFQvoYmeFvoHGB6LuyoFrkBSY0OPbDcdpCf2ND7tCf0yt1/9oUf 6e7xAgJp7Q2yRR66H2cl0juy7OswRoD6NDD3afwONRFJx+QQQG7w4VoluCIpCaJw6jVB nLxg== X-Gm-Message-State: APjAAAWjXXTon4o4UtW+V69871cx9MJG8HUaiRm+zGTXM8R6Gbw36u4V 3mnTicbTbiq0XPi30JYEBXOeMf1l X-Google-Smtp-Source: APXvYqz+ai+fnVSLQLW+KDK/pgsqnnJbGFIGaUxaLORGkAnwAu5Du7Krqe9jmmLbAAbOZJPn2iqnEw== X-Received: by 2002:a1c:ce46:: with SMTP id e67mr6701081wmg.40.1551979851970; Thu, 07 Mar 2019 09:30:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:48 +0100 Message-Id: <1551979804-6060-42-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::342 Subject: [Qemu-devel] [PULL 41/57] tests/libqos: 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: 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-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 Signed-off-by: Paolo Bonzini --- 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 a0b42c9..48b7cf0 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -743,6 +743,7 @@ qos-test-obj-y +=3D tests/libqos/virtio-balloon.o qos-test-obj-y +=3D tests/libqos/virtio-blk.o qos-test-obj-y +=3D tests/libqos/virtio-net.o qos-test-obj-y +=3D tests/libqos/virtio-rng.o +qos-test-obj-y +=3D tests/libqos/virtio-scsi.o qos-test-obj-y +=3D tests/libqos/virtio-serial.o =20 # Machines diff --git a/tests/libqos/virtio-scsi.c b/tests/libqos/virtio-scsi.c new file mode 100644 index 0000000..482684d --- /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_get_driver(QVirtioSCSI *v_scsi, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-scsi")) { + return v_scsi; + } + if (!g_strcmp0(interface, "virtio")) { + return v_scsi->vdev; + } + + fprintf(stderr, "%s not present in virtio-scsi-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_scsi_device_get_driver(void *object, + const char *interface) +{ + QVirtioSCSIDevice *v_scsi =3D object; + return qvirtio_scsi_get_driver(&v_scsi->scsi, interface); +} + +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.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, "pci-device")) { + return v_scsi->pci_vdev.pdev; + } + return qvirtio_scsi_get_driver(&v_scsi->scsi, interface); +} + +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-bus", &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", "pci-device"); + 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 0000000..17a47be --- /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 1.8.3.1