From nobody Tue Feb 10 02:45:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1598258528; cv=none; d=zohomail.com; s=zohoarc; b=XqZUASigsAkdTsjEdEvHuoOX57Z12S7bFwyFkP3ff/dl1dqDRyErHvj/4CjuFzwkGcvs8tdDMls9s07J+nUiheXMHLtA3aBL090RJmkdKH6ElXAA1Fr5Tvogfh+JNb8juARZJleNYDf1sNt3oRRq5dKdcOVp8BHlUN4U/iwp7/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598258528; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=0YiyaXGCteV6eAUx85YKD/nISwnScCEnn+mIKN9OdOg=; b=KyuAHQveyouf5PFJn/ykotK3oB6Ln6hbjpwCKz7RCvpUh+bYNPyRdTyS1KTzfeqEpwZHcJcNi5wj5KdaGlgPqkuPyhDL9m0esOUjjNapOj9cgqx9VEjpVtDXWhUkVKp9io88DWOZzPpjiEVFYJON/q41TU5pyFbKTU8p6w6ml1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598258528267771.873293935154; Mon, 24 Aug 2020 01:42:08 -0700 (PDT) Received: from localhost ([::1]:39722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kA83K-0003i0-Vv for importer@patchew.org; Mon, 24 Aug 2020 04:42:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA822-0001yM-EJ; Mon, 24 Aug 2020 04:40:46 -0400 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:47016) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kA81z-0004xO-QM; Mon, 24 Aug 2020 04:40:46 -0400 Received: from myt5-23f0be3aa648.qloud-c.yandex.net (myt5-23f0be3aa648.qloud-c.yandex.net [IPv6:2a02:6b8:c12:3e29:0:640:23f0:be3a]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 7E3282E1570; Mon, 24 Aug 2020 11:40:41 +0300 (MSK) Received: from myt4-18a966dbd9be.qloud-c.yandex.net (myt4-18a966dbd9be.qloud-c.yandex.net [2a02:6b8:c00:12ad:0:640:18a9:66db]) by myt5-23f0be3aa648.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id ib5cfUIOd2-edvKr8VR; Mon, 24 Aug 2020 11:40:41 +0300 Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b080:6622::1:7]) by myt4-18a966dbd9be.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id B7dErHoRhW-edl4uxhb; Mon, 24 Aug 2020 11:40:39 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1598258441; bh=0YiyaXGCteV6eAUx85YKD/nISwnScCEnn+mIKN9OdOg=; h=In-Reply-To:In-Reply-To:Message-Id:References:References:Date: Subject:To:From:Cc; b=gAkG9F0mMYtx/M65u4erPOnj00hG07Ppskht6qy2OlJ5w+mqHuL5e+1IWvRp8o39P Ar0muTvkpvatFCop80rhCKKpXARfbjnxvz4ZoytDgCASX31M3dajJUEDIEb31Mh1IG IH07Zi5VUWHgkXSxfoU8fnbgJrt/utxrn3dHNF80= Authentication-Results: myt5-23f0be3aa648.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Subject: [PATCH v2 5/7] tests/qtest/vhost-user-test: add support for the vhost-user-blk device Date: Mon, 24 Aug 2020 11:39:30 +0300 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=5.45.199.163; envelope-from=dimastep@yandex-team.ru; helo=forwardcorp1j.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/24 04:40:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, lvivier@redhat.com, thuth@redhat.com, qemu-block@nongnu.org, mst@redhat.com, jasowang@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, fengli@smartx.com, yc-core@yandex-team.ru, pbonzini@redhat.com, raphael.norwitz@nutanix.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" Add vhost_user_ops structure for the vhost-user-blk device class. Add the test_reconnect and test_migrate tests for this device. Signed-off-by: Dima Stepanov --- tests/qtest/vhost-user-test.c | 140 ++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 138 insertions(+), 2 deletions(-) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 3df5322..9b6e202 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -24,6 +24,7 @@ #include "libqos/libqos.h" #include "libqos/pci-pc.h" #include "libqos/virtio-pci.h" +#include "libqos/virtio-blk.h" =20 #include "libqos/malloc-pc.h" #include "hw/virtio/virtio-net.h" @@ -31,6 +32,7 @@ #include "standard-headers/linux/vhost_types.h" #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_net.h" +#include "standard-headers/linux/virtio_blk.h" =20 #ifdef CONFIG_LINUX #include @@ -43,6 +45,7 @@ " -numa node,memdev=3Dmem" #define QEMU_CMD_CHR " -chardev socket,id=3D%s,path=3D%s%s" #define QEMU_CMD_NETDEV " -netdev vhost-user,id=3Dhs0,chardev=3D%s,vhostfo= rce" +#define QEMU_CMD_BLKCHR " -chardev socket,id=3Dchdev0,path=3D%s%s" =20 #define HUGETLBFS_MAGIC 0x958458f6 =20 @@ -55,6 +58,7 @@ #define VHOST_USER_PROTOCOL_F_MQ 0 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6 +#define VHOST_USER_PROTOCOL_F_CONFIG 9 =20 #define VHOST_LOG_PAGE 0x1000 =20 @@ -78,6 +82,8 @@ typedef enum VhostUserRequest { VHOST_USER_SET_PROTOCOL_FEATURES =3D 16, VHOST_USER_GET_QUEUE_NUM =3D 17, VHOST_USER_SET_VRING_ENABLE =3D 18, + VHOST_USER_GET_CONFIG =3D 24, + VHOST_USER_SET_CONFIG =3D 25, VHOST_USER_MAX } VhostUserRequest; =20 @@ -99,6 +105,14 @@ typedef struct VhostUserLog { uint64_t mmap_offset; } VhostUserLog; =20 +#define VHOST_USER_MAX_CONFIG_SIZE 256 +typedef struct VhostUserConfig { + uint32_t offset; + uint32_t size; + uint32_t flags; + uint8_t region[VHOST_USER_MAX_CONFIG_SIZE]; +} VhostUserConfig; + typedef struct VhostUserMsg { VhostUserRequest request; =20 @@ -114,6 +128,7 @@ typedef struct VhostUserMsg { struct vhost_vring_addr addr; VhostUserMemory memory; VhostUserLog log; + VhostUserConfig config; } payload; } QEMU_PACKED VhostUserMsg; =20 @@ -137,6 +152,7 @@ enum { =20 enum { VHOST_USER_NET, + VHOST_USER_BLK, }; =20 typedef struct TestServer { @@ -166,12 +182,15 @@ struct vhost_user_ops { int type; void (*append_opts)(TestServer *s, GString *cmd_line, const char *chr_opts); + void (*driver_init)(void *obj, QGuestAllocator *alloc); =20 /* VHOST-USER commands. */ void (*set_features)(TestServer *s, CharBackend *chr, VhostUserMsg *msg); void (*get_protocol_features)(TestServer *s, CharBackend *chr, VhostUserMsg *msg); + void (*get_config)(TestServer *s, CharBackend *chr, + VhostUserMsg *msg); }; =20 static const char *init_hugepagefs(void); @@ -194,6 +213,14 @@ static void append_vhost_net_opts(TestServer *s, GStri= ng *cmd_line, chr_opts, s->chr_name); } =20 +static void append_vhost_blk_opts(TestServer *s, GString *cmd_line, + const char *chr_opts) +{ + g_string_append_printf(cmd_line, QEMU_CMD_BLKCHR, + s->socket_path, + chr_opts); +} + static void append_mem_opts(TestServer *server, GString *cmd_line, int size, enum test_memfd memfd) { @@ -425,6 +452,12 @@ static void chr_read(void *opaque, const uint8_t *buf,= int size) qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); break; =20 + case VHOST_USER_GET_CONFIG: + if (s->vu_ops->get_config) { + s->vu_ops->get_config(s, chr, &msg); + } + break; + default: break; } @@ -727,6 +760,9 @@ static void test_migrate(void *obj, void *arg, QGuestAl= locator *alloc) guint8 *log; guint64 size; =20 + if (s->vu_ops->driver_init) { + s->vu_ops->driver_init(obj, alloc); + } if (!wait_for_fds(s)) { return; } @@ -796,6 +832,24 @@ static void test_migrate(void *obj, void *arg, QGuestA= llocator *alloc) g_string_free(dest_cmdline, true); } =20 +static void vu_blk_driver_init(void *obj, QGuestAllocator *alloc) +{ + QVirtioBlk *blk_if; + QVirtioDevice *dev; + QVirtQueue *vq; + uint64_t features; + + blk_if =3D obj; + dev =3D blk_if->vdev; + features =3D qvirtio_get_features(dev); + qvirtio_set_features(dev, features); + + vq =3D qvirtqueue_setup(dev, alloc, 0); + g_assert(vq); + + qvirtio_set_driver_ok(dev); +} + static void wait_for_rings_started(TestServer *s, size_t count) { gint64 end_time; @@ -857,12 +911,22 @@ static void test_reconnect(void *obj, void *arg, QGue= stAllocator *alloc) { TestServer *s =3D arg; GSource *src; + int nq; =20 + if (s->vu_ops->driver_init) { + s->vu_ops->driver_init(obj, alloc); + } if (!wait_for_fds(s)) { return; } =20 - wait_for_rings_started(s, 2); + if (s->vu_ops->type =3D=3D VHOST_USER_NET) { + /* tx and rx queues */ + nq =3D 2; + } else if (s->vu_ops->type =3D=3D VHOST_USER_BLK) { + nq =3D 1; + } + wait_for_rings_started(s, nq); =20 /* reconnect */ s->fds_num =3D 0; @@ -872,7 +936,7 @@ static void test_reconnect(void *obj, void *arg, QGuest= Allocator *alloc) g_source_attach(src, s->context); g_source_unref(src); g_assert(wait_for_fds(s)); - wait_for_rings_started(s, 2); + wait_for_rings_started(s, nq); } =20 static void *vhost_user_test_setup_connect_fail(GString *cmd_line, void *a= rg) @@ -960,6 +1024,56 @@ static void vu_net_get_protocol_features(TestServer *= s, CharBackend *chr, qemu_chr_fe_write_all(chr, (uint8_t *)msg, VHOST_USER_HDR_SIZE + msg->= size); } =20 +static void vu_blk_set_features(TestServer *s, CharBackend *chr, + VhostUserMsg *msg) +{ + if (s->test_flags =3D=3D TEST_FLAGS_DISCONNECT) { + qemu_chr_fe_disconnect(chr); + s->test_flags =3D TEST_FLAGS_BAD; + } +} + +static void vu_blk_get_protocol_features(TestServer *s, + CharBackend *chr, VhostUserMsg *msg) +{ + /* send back features to qemu */ + msg->flags |=3D VHOST_USER_REPLY_MASK; + msg->size =3D sizeof(m.payload.u64); + msg->payload.u64 =3D 1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD; + msg->payload.u64 |=3D 1 << VHOST_USER_PROTOCOL_F_CONFIG; + if (s->queues > 1) { + msg->payload.u64 |=3D 1 << VHOST_USER_PROTOCOL_F_MQ; + } + qemu_chr_fe_write_all(chr, (uint8_t *)msg, VHOST_USER_HDR_SIZE + msg->= size); +} + +static void vu_blk_get_config(TestServer *s, CharBackend *chr, + VhostUserMsg *msg) +{ + VhostUserConfig *config; + struct virtio_blk_config *blk_config; + + config =3D &msg->payload.config; + memset(config, 0, sizeof(*config)); + config->size =3D sizeof(*blk_config); + + blk_config =3D (struct virtio_blk_config *)&config->region; + /* + * Represent 128Mb test disk, with no real backend, just + * to test vhost-user functionality. + */ + blk_config->capacity =3D 262144; + blk_config->size_max =3D 0x20000; + blk_config->seg_max =3D 0x7e; + blk_config->blk_size =3D 512; + blk_config->min_io_size =3D 0x1; + blk_config->num_queues =3D 0x1; + + msg->size =3D sizeof(*config) - sizeof(config->region) + config->size; + msg->flags |=3D VHOST_USER_REPLY_MASK; + qemu_chr_fe_write_all(chr, (uint8_t *)msg, VHOST_USER_HDR_SIZE + msg->= size); +} + /* Each VHOST-USER device should have its ops structure defined. */ static struct vhost_user_ops g_vu_net_ops =3D { .type =3D VHOST_USER_NET, @@ -970,6 +1084,17 @@ static struct vhost_user_ops g_vu_net_ops =3D { .get_protocol_features =3D vu_net_get_protocol_features, }; =20 +static struct vhost_user_ops g_vu_blk_ops =3D { + .type =3D VHOST_USER_BLK, + + .append_opts =3D append_vhost_blk_opts, + .driver_init =3D vu_blk_driver_init, + + .set_features =3D vu_blk_set_features, + .get_protocol_features =3D vu_blk_get_protocol_features, + .get_config =3D vu_blk_get_config, +}; + static void register_vhost_user_test(void) { QOSGraphTestOptions opts =3D { @@ -1015,5 +1140,16 @@ static void register_vhost_user_test(void) qos_add_test("vhost-user/multiqueue", "virtio-net", test_multiqueue, &opts); + opts.edge.extra_device_opts =3D NULL; + + /* vhost-user-blk tests */ + opts.arg =3D &g_vu_blk_ops; + opts.before =3D vhost_user_test_setup_reconnect; + qos_add_test("reconnect", "vhost-user-blk", + test_reconnect, &opts); + + opts.before =3D vhost_user_test_setup_memfd; + qos_add_test("migrate", "vhost-user-blk", + test_migrate, &opts); } libqos_init(register_vhost_user_test); --=20 2.7.4