From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366163; cv=none; d=zohomail.com; s=zohoarc; b=U0v3hA1Vs7tAMeHlgeldk4TRkEI/VdLtDbWmAJjKduEmJp+GDs/k14Ot4C6+hAVqqNJUHeBpA/zSa5+IeYxRrnv5UKzlXo0S/FzmkGS3wouDIGJxoqUgHBkB1+CxF0iAvC+NshrSZu4L+XVtxmO+YJTt0glTpSvUCH3/hrlA4Vo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366163; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EO2GP8/cUhOZvA5Y5IO2yeAygcpIdE7qOLHBQuf4HNw=; b=IjXrmhwysJbXjmopuqgrd/tY5HqcJzEMET6h2MiMuhVQPhUzKSFrOyl4frBW6ZcoIpg5QCjuN7LnoHAE1HYHvJtnhwKiqDg6uGU/QNuK5k+fUe2bCQSqTLJyyMtoW8JJSHpPk+dFZ5lrSRF7fcN+C3trhuD+ACnSNAza2aq38ps= 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 1603366163044124.77238256031819; Thu, 22 Oct 2020 04:29:23 -0700 (PDT) Received: from localhost ([::1]:52308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYmX-0005Fy-NY for importer@patchew.org; Thu, 22 Oct 2020 07:29:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYkv-0003Z4-Fl for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:27:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYks-0004y9-NU for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:27:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-530-MEn4SQB7OGOjA4n4SEvnaA-1; Thu, 22 Oct 2020 07:27:35 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE27A186DD29; Thu, 22 Oct 2020 11:27:33 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 188E819C4F; Thu, 22 Oct 2020 11:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366057; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EO2GP8/cUhOZvA5Y5IO2yeAygcpIdE7qOLHBQuf4HNw=; b=WAtPR6Jwvfx3wgu2y6SHbJaSuGxFZgIL4zZa0ki4wmuiC544UJr1N1D0JWzxZgaHwY4GPR 8tsL8buHUx18nGDcpgn6zgqqChuGnPFMWSz7MKFfYN83p/thIARDHSmgZU3d4kGufih1Df 3KJhB0awzxr2DDF0cLvRPwfKGK6k/pw= X-MC-Unique: MEn4SQB7OGOjA4n4SEvnaA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 01/28] block/nvme: Add driver statistics for access alignment and hw errors Date: Thu, 22 Oct 2020 12:26:59 +0100 Message-Id: <20201022112726.736757-2-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 Keep statistics of some hardware errors, and number of aligned/unaligned I/O accesses. QMP example booting a full RHEL 8.3 aarch64 guest: { "execute": "query-blockstats" } { "return": [ { "device": "", "node-name": "drive0", "stats": { "flush_total_time_ns": 6026948, "wr_highest_offset": 3383991230464, "wr_total_time_ns": 807450995, "failed_wr_operations": 0, "failed_rd_operations": 0, "wr_merged": 3, "wr_bytes": 50133504, "failed_unmap_operations": 0, "failed_flush_operations": 0, "account_invalid": false, "rd_total_time_ns": 1846979900, "flush_operations": 130, "wr_operations": 659, "rd_merged": 1192, "rd_bytes": 218244096, "account_failed": false, "idle_time_ns": 2678641497, "rd_operations": 7406, }, "driver-specific": { "driver": "nvme", "completion-errors": 0, "unaligned-accesses": 2959, "aligned-accesses": 4477 }, "qdev": "/machine/peripheral-anon/device[0]/virtio-backend" } ] } Suggested-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Markus Armbruster Message-id: 20201001162939.1567915-1-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- qapi/block-core.json | 24 +++++++++++++++++++++++- block/nvme.c | 27 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index ee5ebef7f2..e00fc27b5e 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -947,6 +947,27 @@ 'discard-nb-failed': 'uint64', 'discard-bytes-ok': 'uint64' } } =20 +## +# @BlockStatsSpecificNvme: +# +# NVMe driver statistics +# +# @completion-errors: The number of completion errors. +# +# @aligned-accesses: The number of aligned accesses performed by +# the driver. +# +# @unaligned-accesses: The number of unaligned accesses performed by +# the driver. +# +# Since: 5.2 +## +{ 'struct': 'BlockStatsSpecificNvme', + 'data': { + 'completion-errors': 'uint64', + 'aligned-accesses': 'uint64', + 'unaligned-accesses': 'uint64' } } + ## # @BlockStatsSpecific: # @@ -959,7 +980,8 @@ 'discriminator': 'driver', 'data': { 'file': 'BlockStatsSpecificFile', - 'host_device': 'BlockStatsSpecificFile' } } + 'host_device': 'BlockStatsSpecificFile', + 'nvme': 'BlockStatsSpecificNvme' } } =20 ## # @BlockStats: diff --git a/block/nvme.c b/block/nvme.c index b48f6f2588..739a0a700c 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -128,6 +128,12 @@ struct BDRVNVMeState { =20 /* PCI address (required for nvme_refresh_filename()) */ char *device; + + struct { + uint64_t completion_errors; + uint64_t aligned_accesses; + uint64_t unaligned_accesses; + } stats; }; =20 #define NVME_BLOCK_OPT_DEVICE "device" @@ -384,6 +390,9 @@ static bool nvme_process_completion(NVMeQueuePair *q) break; } ret =3D nvme_translate_error(c); + if (ret) { + s->stats.completion_errors++; + } q->cq.head =3D (q->cq.head + 1) % NVME_QUEUE_SIZE; if (!q->cq.head) { q->cq_phase =3D !q->cq_phase; @@ -1155,8 +1164,10 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_= t offset, uint64_t bytes, assert(QEMU_IS_ALIGNED(bytes, s->page_size)); assert(bytes <=3D s->max_transfer); if (nvme_qiov_aligned(bs, qiov)) { + s->stats.aligned_accesses++; return nvme_co_prw_aligned(bs, offset, bytes, qiov, is_write, flag= s); } + s->stats.unaligned_accesses++; trace_nvme_prw_buffered(s, offset, bytes, qiov->niov, is_write); buf =3D qemu_try_memalign(s->page_size, bytes); =20 @@ -1452,6 +1463,21 @@ static void nvme_unregister_buf(BlockDriverState *bs= , void *host) qemu_vfio_dma_unmap(s->vfio, host); } =20 +static BlockStatsSpecific *nvme_get_specific_stats(BlockDriverState *bs) +{ + BlockStatsSpecific *stats =3D g_new(BlockStatsSpecific, 1); + BDRVNVMeState *s =3D bs->opaque; + + stats->driver =3D BLOCKDEV_DRIVER_NVME; + stats->u.nvme =3D (BlockStatsSpecificNvme) { + .completion_errors =3D s->stats.completion_errors, + .aligned_accesses =3D s->stats.aligned_accesses, + .unaligned_accesses =3D s->stats.unaligned_accesses, + }; + + return stats; +} + static const char *const nvme_strong_runtime_opts[] =3D { NVME_BLOCK_OPT_DEVICE, NVME_BLOCK_OPT_NAMESPACE, @@ -1485,6 +1511,7 @@ static BlockDriver bdrv_nvme =3D { .bdrv_refresh_filename =3D nvme_refresh_filename, .bdrv_refresh_limits =3D nvme_refresh_limits, .strong_runtime_opts =3D nvme_strong_runtime_opts, + .bdrv_get_specific_stats =3D nvme_get_specific_stats, =20 .bdrv_detach_aio_context =3D nvme_detach_aio_context, .bdrv_attach_aio_context =3D nvme_attach_aio_context, --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366188; cv=none; d=zohomail.com; s=zohoarc; b=ir0ADlGltz5wG044ptNGQYEB/czNA5GQ/cCxl1ywf2Y1Yhma3zvyAEYNMZWYbTnLLmhhtpwgM1Z1Yp8JR6n5sVcblNX9lKLNxPZ1mDg8r54OG5Jskowi3gZQym02Vh48NpXr5qXuUrWTAtj1rTC6/88ZAu7P2FTlGvLnk3NuSYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366188; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Kscl1ioJ6SN53vbiV6YpCJG6a5j4Q2stnV8phu6EEJ4=; b=QwlSMiIoTDHuuLm51LlHsCc36eL5oIErgY8es6/iLbkiX2gWX3Q+3CHDK6PO9m0PyRqLVxY77Ou5CEooYxOfLqZzZMb6+bRbF8j2WvRgM/GASZ8O2X+yH4a2FZthZnRZzN/8FWKlYoXe17CoD2v5CzbvKg984xrcDHbeRVy4NtI= 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 1603366188451155.840129985693; Thu, 22 Oct 2020 04:29:48 -0700 (PDT) Received: from localhost ([::1]:53318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYmx-0005hq-C3 for importer@patchew.org; Thu, 22 Oct 2020 07:29:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYl6-0003rA-PI for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:27:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYl2-0004zf-K1 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:27:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-330-NIBWCHkAMk2pXnNKTmP0hQ-1; Thu, 22 Oct 2020 07:27:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 036AD1009E28; Thu, 22 Oct 2020 11:27:44 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A9CD10013D0; Thu, 22 Oct 2020 11:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kscl1ioJ6SN53vbiV6YpCJG6a5j4Q2stnV8phu6EEJ4=; b=EdnBIFrPP5IuO/w0qMrYgScI41fk+dvCWP5eNocSMvIjYXQogDaWHYXa3tZG+b4mWhOfqa HB7rbTZOmDDckaaa8zzYvLA/B3OA8DKhwY3LDzMIxzOOpPKRyGh9Fj89WMH0is6PIkWcQV nsVC12mvR4S4+1qX75SavWzRxcHQZuo= X-MC-Unique: NIBWCHkAMk2pXnNKTmP0hQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 02/28] libvhost-user: Allow vu_message_read to be replaced Date: Thu, 22 Oct 2020 12:27:00 +0100 Message-Id: <20201022112726.736757-3-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Coiby Xu Allow vu_message_read to be replaced by one which will make use of the QIOChannel functions. Thus reading vhost-user message won't stall the guest. For slave channel, we still use the default vu_message_read. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Coiby Xu Reviewed-by: Stefan Hajnoczi Message-id: 20200918080912.321299-2-coiby.xu@gmail.com Signed-off-by: Stefan Hajnoczi --- contrib/libvhost-user/libvhost-user.h | 21 +++++++++++++++++++++ contrib/libvhost-user/libvhost-user-glib.c | 2 +- contrib/libvhost-user/libvhost-user.c | 14 +++++++------- tests/vhost-user-bridge.c | 2 ++ tools/virtiofsd/fuse_virtio.c | 4 ++-- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/= libvhost-user.h index 287ac5fec7..3bbeae8587 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -36,6 +36,8 @@ */ #define VHOST_USER_MAX_RAM_SLOTS 32 =20 +#define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) + typedef enum VhostSetConfigType { VHOST_SET_CONFIG_TYPE_MASTER =3D 0, VHOST_SET_CONFIG_TYPE_MIGRATION =3D 1, @@ -221,6 +223,7 @@ typedef uint64_t (*vu_get_features_cb) (VuDev *dev); typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features); typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg, int *do_reply); +typedef bool (*vu_read_msg_cb) (VuDev *dev, int sock, VhostUserMsg *vmsg); typedef void (*vu_queue_set_started_cb) (VuDev *dev, int qidx, bool starte= d); typedef bool (*vu_queue_is_processed_in_order_cb) (VuDev *dev, int qidx); typedef int (*vu_get_config_cb) (VuDev *dev, uint8_t *config, uint32_t len= ); @@ -389,6 +392,23 @@ struct VuDev { bool broken; uint16_t max_queues; =20 + /* @read_msg: custom method to read vhost-user message + * + * Read data from vhost_user socket fd and fill up + * the passed VhostUserMsg *vmsg struct. + * + * If reading fails, it should close the received set of file + * descriptors as socket message's auxiliary data. + * + * For the details, please refer to vu_message_read in libvhost-user.c + * which will be used by default if not custom method is provided when + * calling vu_init + * + * Returns: true if vhost-user message successfully received, + * otherwise return false. + * + */ + vu_read_msg_cb read_msg; /* @set_watch: add or update the given fd to the watch set, * call cb when condition is met */ vu_set_watch_cb set_watch; @@ -432,6 +452,7 @@ bool vu_init(VuDev *dev, uint16_t max_queues, int socket, vu_panic_cb panic, + vu_read_msg_cb read_msg, vu_set_watch_cb set_watch, vu_remove_watch_cb remove_watch, const VuDevIface *iface); diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/contrib/libvhost-= user/libvhost-user-glib.c index 53f1ca4cdd..0df2ec9271 100644 --- a/contrib/libvhost-user/libvhost-user-glib.c +++ b/contrib/libvhost-user/libvhost-user-glib.c @@ -147,7 +147,7 @@ vug_init(VugDev *dev, uint16_t max_queues, int socket, g_assert(dev); g_assert(iface); =20 - if (!vu_init(&dev->parent, max_queues, socket, panic, set_watch, + if (!vu_init(&dev->parent, max_queues, socket, panic, NULL, set_watch, remove_watch, iface)) { return false; } diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index 9f1285b8a1..09bdff18f3 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -68,8 +68,6 @@ /* The version of inflight buffer */ #define INFLIGHT_VERSION 1 =20 -#define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) - /* The version of the protocol we support */ #define VHOST_USER_VERSION 1 #define LIBVHOST_USER_DEBUG 0 @@ -268,7 +266,7 @@ have_userfault(void) } =20 static bool -vu_message_read(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) +vu_message_read_default(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) { char control[CMSG_SPACE(VHOST_MEMORY_BASELINE_NREGIONS * sizeof(int))]= =3D {}; struct iovec iov =3D { @@ -416,7 +414,7 @@ vu_process_message_reply(VuDev *dev, const VhostUserMsg= *vmsg) goto out; } =20 - if (!vu_message_read(dev, dev->slave_fd, &msg_reply)) { + if (!vu_message_read_default(dev, dev->slave_fd, &msg_reply)) { goto out; } =20 @@ -907,7 +905,7 @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg= *vmsg) /* Wait for QEMU to confirm that it's registered the handler for the * faults. */ - if (!vu_message_read(dev, dev->sock, vmsg) || + if (!dev->read_msg(dev, dev->sock, vmsg) || vmsg->size !=3D sizeof(vmsg->payload.u64) || vmsg->payload.u64 !=3D 0) { vu_panic(dev, "failed to receive valid ack for postcopy set-mem-ta= ble"); @@ -1869,7 +1867,7 @@ vu_dispatch(VuDev *dev) int reply_requested; bool need_reply, success =3D false; =20 - if (!vu_message_read(dev, dev->sock, &vmsg)) { + if (!dev->read_msg(dev, dev->sock, &vmsg)) { goto end; } =20 @@ -1967,6 +1965,7 @@ vu_init(VuDev *dev, uint16_t max_queues, int socket, vu_panic_cb panic, + vu_read_msg_cb read_msg, vu_set_watch_cb set_watch, vu_remove_watch_cb remove_watch, const VuDevIface *iface) @@ -1984,6 +1983,7 @@ vu_init(VuDev *dev, =20 dev->sock =3D socket; dev->panic =3D panic; + dev->read_msg =3D read_msg ? read_msg : vu_message_read_default; dev->set_watch =3D set_watch; dev->remove_watch =3D remove_watch; dev->iface =3D iface; @@ -2349,7 +2349,7 @@ static void _vu_queue_notify(VuDev *dev, VuVirtq *vq,= bool sync) =20 vu_message_write(dev, dev->slave_fd, &vmsg); if (ack) { - vu_message_read(dev, dev->slave_fd, &vmsg); + vu_message_read_default(dev, dev->slave_fd, &vmsg); } return; } diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c index 6c3d490611..bd43607a4d 100644 --- a/tests/vhost-user-bridge.c +++ b/tests/vhost-user-bridge.c @@ -520,6 +520,7 @@ vubr_accept_cb(int sock, void *ctx) VHOST_USER_BRIDGE_MAX_QUEUES, conn_fd, vubr_panic, + NULL, vubr_set_watch, vubr_remove_watch, &vuiface)) { @@ -573,6 +574,7 @@ vubr_new(const char *path, bool client) VHOST_USER_BRIDGE_MAX_QUEUES, dev->sock, vubr_panic, + NULL, vubr_set_watch, vubr_remove_watch, &vuiface)) { diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index 89f537f79b..324936948d 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -1013,8 +1013,8 @@ int virtio_session_mount(struct fuse_session *se) se->vu_socketfd =3D data_sock; se->virtio_dev->se =3D se; pthread_rwlock_init(&se->virtio_dev->vu_dispatch_rwlock, NULL); - vu_init(&se->virtio_dev->dev, 2, se->vu_socketfd, fv_panic, fv_set_wat= ch, - fv_remove_watch, &fv_iface); + vu_init(&se->virtio_dev->dev, 2, se->vu_socketfd, fv_panic, NULL, + fv_set_watch, fv_remove_watch, &fv_iface); =20 return 0; } --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366377; cv=none; d=zohomail.com; s=zohoarc; b=fccIynnGgjQnF0tudZ29SPx5u2bSOh0Y38MSMkKQFOCQawgAey7IK7qlV9iqx6jDhpLrzX9Mifi957Q1+BgZzkabzJlEvNUmAR8UgHC84JPEzM//xs63z19R2UXOOnRSrSoxh52un2JasUpsvByqlWlAnEGXvtngP4UcGxBFlv8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366377; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4EZdYt16YWuJFdVFl2nWGZ6CRGtlctxL0AjPsJnvegM=; b=Vp/SEQ17YMDcKQ8fb48KtCzuhbX/YE7obIk5hn/0CmyEG0fH+z4C8gY6qfoCb3LUAFbV7yXGOkDdOg34wj40DsxDYzKELlrBiNxpB6KLkk9vJSDGYvnb9WmBJ3F+x9tlVQ1MAQYfFbFvtqdG3u4hleIvQPsuAaThmWcKKCDrQNc= 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 1603366377546267.20000998209775; Thu, 22 Oct 2020 04:32:57 -0700 (PDT) Received: from localhost ([::1]:34264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYq0-0001G0-DF for importer@patchew.org; Thu, 22 Oct 2020 07:32:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYlA-0003wi-NU for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:27:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31023) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYl9-00050Q-B7 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:27:56 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-1vUfS6dkPO-LaE49Hl6_ZQ-1; Thu, 22 Oct 2020 07:27:49 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7A671084D78; Thu, 22 Oct 2020 11:27:48 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7691919C4F; Thu, 22 Oct 2020 11:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4EZdYt16YWuJFdVFl2nWGZ6CRGtlctxL0AjPsJnvegM=; b=NnzdAXgOtKeSYYyeU2eG1RQ57MditJijYmSGSyhugEUt8ivhokfciBJ0KjGxZCbixnGBWB Dk4XZ/R8KyfTzRaqFiuY/kHhE22xgTN1Ac69c9mVUkwsOFRSQLebFxPCj3vyjOBlX9FqmP IypQJtUX8/BFSo9ggIj/7dsFEZyBCxk= X-MC-Unique: 1vUfS6dkPO-LaE49Hl6_ZQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 03/28] libvhost-user: remove watch for kick_fd when de-initialize vu-dev Date: Thu, 22 Oct 2020 12:27:01 +0100 Message-Id: <20201022112726.736757-4-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Coiby Xu When the client is running in gdb and quit command is run in gdb, QEMU will still dispatch the event which will cause segment fault in the callback function. Signed-off-by: Coiby Xu Reviewed-by: Stefan Hajnoczi Reviewed-by: Marc-Andr=C3=A9 Lureau Message-id: 20200918080912.321299-3-coiby.xu@gmail.com Signed-off-by: Stefan Hajnoczi --- contrib/libvhost-user/libvhost-user.c | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index 09bdff18f3..bfec8a881a 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -1918,6 +1918,7 @@ vu_deinit(VuDev *dev) } =20 if (vq->kick_fd !=3D -1) { + dev->remove_watch(dev, vq->kick_fd); close(vq->kick_fd); vq->kick_fd =3D -1; } --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366362; cv=none; d=zohomail.com; s=zohoarc; b=G18NlJFT6iyfPQO+kXVDnFWFoB9cy8GBcwy+NDKRytTvAo9pVEeAOf21cP7uOvY4zslesWE7AKpACzvPtNEqVjLfSXke3x0K5BqViX4kAWhB6Cpb4yy0PAGVKMdFY1Qfz3EUpz2/Lnk6a4D/0D9XJCVGJvzOD/RxzVivbLMVuBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366362; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dFpMASVSNF4gnj4wpvZPZnPDmOAhSVnZ+tVY7OKNgmc=; b=M4MVaqZL0kbjw6wiDWyezVTppT/3yYYq4H96AnKOjJ3itvPFnuiI4vtV/a79g9rxVxdVPgX50oL0TCHFDouwPYB8G+qPhh9XC4NVDcVCI8h1GlBdlDwZYaVNiM+xCKq2VhMiAOkCQXTZ/f7FeycwwdsqOaTXehIu/spLaDbVdA0= 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 1603366362113569.916062076731; Thu, 22 Oct 2020 04:32:42 -0700 (PDT) Received: from localhost ([::1]:60866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYpk-0000ZS-KZ for importer@patchew.org; Thu, 22 Oct 2020 07:32:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYlN-00042Z-EJ for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32220) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYlH-00050z-0l for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:07 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-eaBDNC3nNXiokZq11uKR1w-1; Thu, 22 Oct 2020 07:27:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CC3921009E23; Thu, 22 Oct 2020 11:27:57 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E62D75C1C7; Thu, 22 Oct 2020 11:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dFpMASVSNF4gnj4wpvZPZnPDmOAhSVnZ+tVY7OKNgmc=; b=BK0VjHBbxQk59JxtlsxJKICSBabmahl2BORNwYOJj9wDpHVgUoZmhnuedW1Mpm1rzlv9oj oYlUjonoqjm03xO1YIEz5I75JspVp0iMCEkRRCpgNiondu3lmi8z7j7GOM2L1GIRD3A1mP tjMFiMbCEmgn+4abSEJSNIQ8uMIrn4A= X-MC-Unique: eaBDNC3nNXiokZq11uKR1w-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 04/28] util/vhost-user-server: generic vhost user server Date: Thu, 22 Oct 2020 12:27:02 +0100 Message-Id: <20201022112726.736757-5-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Coiby Xu Sharing QEMU devices via vhost-user protocol. Only one vhost-user client can connect to the server one time. Suggested-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Signed-off-by: Coiby Xu Reviewed-by: Stefan Hajnoczi Reviewed-by: Marc-Andr=C3=A9 Lureau Message-id: 20200918080912.321299-4-coiby.xu@gmail.com [Fixed size_t %lu -> %zu format string compiler error. --Stefan] Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.h | 65 ++++++ util/vhost-user-server.c | 428 +++++++++++++++++++++++++++++++++++++++ util/meson.build | 1 + 3 files changed, 494 insertions(+) create mode 100644 util/vhost-user-server.h create mode 100644 util/vhost-user-server.c diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h new file mode 100644 index 0000000000..5232f96718 --- /dev/null +++ b/util/vhost-user-server.h @@ -0,0 +1,65 @@ +/* + * Sharing QEMU devices via vhost-user protocol + * + * Copyright (c) Coiby Xu . + * Copyright (c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef VHOST_USER_SERVER_H +#define VHOST_USER_SERVER_H + +#include "contrib/libvhost-user/libvhost-user.h" +#include "io/channel-socket.h" +#include "io/channel-file.h" +#include "io/net-listener.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "standard-headers/linux/virtio_blk.h" + +typedef struct VuFdWatch { + VuDev *vu_dev; + int fd; /*kick fd*/ + void *pvt; + vu_watch_cb cb; + bool processing; + QTAILQ_ENTRY(VuFdWatch) next; +} VuFdWatch; + +typedef struct VuServer VuServer; +typedef void DevicePanicNotifierFn(VuServer *server); + +struct VuServer { + QIONetListener *listener; + AioContext *ctx; + DevicePanicNotifierFn *device_panic_notifier; + int max_queues; + const VuDevIface *vu_iface; + VuDev vu_dev; + QIOChannel *ioc; /* The I/O channel with the client */ + QIOChannelSocket *sioc; /* The underlying data channel with the client= */ + /* IOChannel for fd provided via VHOST_USER_SET_SLAVE_REQ_FD */ + QIOChannel *ioc_slave; + QIOChannelSocket *sioc_slave; + Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ + QTAILQ_HEAD(, VuFdWatch) vu_fd_watches; + /* restart coroutine co_trip if AIOContext is changed */ + bool aio_context_changed; + bool processing_msg; +}; + +bool vhost_user_server_start(VuServer *server, + SocketAddress *unix_socket, + AioContext *ctx, + uint16_t max_queues, + DevicePanicNotifierFn *device_panic_notifier, + const VuDevIface *vu_iface, + Error **errp); + +void vhost_user_server_stop(VuServer *server); + +void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx); + +#endif /* VHOST_USER_SERVER_H */ diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c new file mode 100644 index 0000000000..b189944856 --- /dev/null +++ b/util/vhost-user-server.c @@ -0,0 +1,428 @@ +/* + * Sharing QEMU devices via vhost-user protocol + * + * Copyright (c) Coiby Xu . + * Copyright (c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "vhost-user-server.h" + +static void vmsg_close_fds(VhostUserMsg *vmsg) +{ + int i; + for (i =3D 0; i < vmsg->fd_num; i++) { + close(vmsg->fds[i]); + } +} + +static void vmsg_unblock_fds(VhostUserMsg *vmsg) +{ + int i; + for (i =3D 0; i < vmsg->fd_num; i++) { + qemu_set_nonblock(vmsg->fds[i]); + } +} + +static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, + gpointer opaque); + +static void close_client(VuServer *server) +{ + /* + * Before closing the client + * + * 1. Let vu_client_trip stop processing new vhost-user msg + * + * 2. remove kick_handler + * + * 3. wait for the kick handler to be finished + * + * 4. wait for the current vhost-user msg to be finished processing + */ + + QIOChannelSocket *sioc =3D server->sioc; + /* When this is set vu_client_trip will stop new processing vhost-user= message */ + server->sioc =3D NULL; + + VuFdWatch *vu_fd_watch, *next; + QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { + aio_set_fd_handler(server->ioc->ctx, vu_fd_watch->fd, true, NULL, + NULL, NULL, NULL); + } + + while (!QTAILQ_EMPTY(&server->vu_fd_watches)) { + QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, nex= t) { + if (!vu_fd_watch->processing) { + QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); + g_free(vu_fd_watch); + } + } + } + + while (server->processing_msg) { + if (server->ioc->read_coroutine) { + server->ioc->read_coroutine =3D NULL; + qio_channel_set_aio_fd_handler(server->ioc, server->ioc->ctx, = NULL, + NULL, server->ioc); + server->processing_msg =3D false; + } + } + + vu_deinit(&server->vu_dev); + object_unref(OBJECT(sioc)); + object_unref(OBJECT(server->ioc)); +} + +static void panic_cb(VuDev *vu_dev, const char *buf) +{ + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + + /* avoid while loop in close_client */ + server->processing_msg =3D false; + + if (buf) { + error_report("vu_panic: %s", buf); + } + + if (server->sioc) { + close_client(server); + } + + if (server->device_panic_notifier) { + server->device_panic_notifier(server); + } + + /* + * Set the callback function for network listener so another + * vhost-user client can connect to this server + */ + qio_net_listener_set_client_func(server->listener, + vu_accept, + server, + NULL); +} + +static bool coroutine_fn +vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg) +{ + struct iovec iov =3D { + .iov_base =3D (char *)vmsg, + .iov_len =3D VHOST_USER_HDR_SIZE, + }; + int rc, read_bytes =3D 0; + Error *local_err =3D NULL; + /* + * Store fds/nfds returned from qio_channel_readv_full into + * temporary variables. + * + * VhostUserMsg is a packed structure, gcc will complain about passing + * pointer to a packed structure member if we pass &VhostUserMsg.fd_num + * and &VhostUserMsg.fds directly when calling qio_channel_readv_full, + * thus two temporary variables nfds and fds are used here. + */ + size_t nfds =3D 0, nfds_t =3D 0; + const size_t max_fds =3D G_N_ELEMENTS(vmsg->fds); + int *fds_t =3D NULL; + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + QIOChannel *ioc =3D server->ioc; + + if (!ioc) { + error_report_err(local_err); + goto fail; + } + + assert(qemu_in_coroutine()); + do { + /* + * qio_channel_readv_full may have short reads, keeping calling it + * until getting VHOST_USER_HDR_SIZE or 0 bytes in total + */ + rc =3D qio_channel_readv_full(ioc, &iov, 1, &fds_t, &nfds_t, &loca= l_err); + if (rc < 0) { + if (rc =3D=3D QIO_CHANNEL_ERR_BLOCK) { + qio_channel_yield(ioc, G_IO_IN); + continue; + } else { + error_report_err(local_err); + return false; + } + } + read_bytes +=3D rc; + if (nfds_t > 0) { + if (nfds + nfds_t > max_fds) { + error_report("A maximum of %zu fds are allowed, " + "however got %zu fds now", + max_fds, nfds + nfds_t); + goto fail; + } + memcpy(vmsg->fds + nfds, fds_t, + nfds_t *sizeof(vmsg->fds[0])); + nfds +=3D nfds_t; + g_free(fds_t); + } + if (read_bytes =3D=3D VHOST_USER_HDR_SIZE || rc =3D=3D 0) { + break; + } + iov.iov_base =3D (char *)vmsg + read_bytes; + iov.iov_len =3D VHOST_USER_HDR_SIZE - read_bytes; + } while (true); + + vmsg->fd_num =3D nfds; + /* qio_channel_readv_full will make socket fds blocking, unblock them = */ + vmsg_unblock_fds(vmsg); + if (vmsg->size > sizeof(vmsg->payload)) { + error_report("Error: too big message request: %d, " + "size: vmsg->size: %u, " + "while sizeof(vmsg->payload) =3D %zu", + vmsg->request, vmsg->size, sizeof(vmsg->payload)); + goto fail; + } + + struct iovec iov_payload =3D { + .iov_base =3D (char *)&vmsg->payload, + .iov_len =3D vmsg->size, + }; + if (vmsg->size) { + rc =3D qio_channel_readv_all_eof(ioc, &iov_payload, 1, &local_err); + if (rc =3D=3D -1) { + error_report_err(local_err); + goto fail; + } + } + + return true; + +fail: + vmsg_close_fds(vmsg); + + return false; +} + + +static void vu_client_start(VuServer *server); +static coroutine_fn void vu_client_trip(void *opaque) +{ + VuServer *server =3D opaque; + + while (!server->aio_context_changed && server->sioc) { + server->processing_msg =3D true; + vu_dispatch(&server->vu_dev); + server->processing_msg =3D false; + } + + if (server->aio_context_changed && server->sioc) { + server->aio_context_changed =3D false; + vu_client_start(server); + } +} + +static void vu_client_start(VuServer *server) +{ + server->co_trip =3D qemu_coroutine_create(vu_client_trip, server); + aio_co_enter(server->ctx, server->co_trip); +} + +/* + * a wrapper for vu_kick_cb + * + * since aio_dispatch can only pass one user data pointer to the + * callback function, pack VuDev and pvt into a struct. Then unpack it + * and pass them to vu_kick_cb + */ +static void kick_handler(void *opaque) +{ + VuFdWatch *vu_fd_watch =3D opaque; + vu_fd_watch->processing =3D true; + vu_fd_watch->cb(vu_fd_watch->vu_dev, 0, vu_fd_watch->pvt); + vu_fd_watch->processing =3D false; +} + + +static VuFdWatch *find_vu_fd_watch(VuServer *server, int fd) +{ + + VuFdWatch *vu_fd_watch, *next; + QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { + if (vu_fd_watch->fd =3D=3D fd) { + return vu_fd_watch; + } + } + return NULL; +} + +static void +set_watch(VuDev *vu_dev, int fd, int vu_evt, + vu_watch_cb cb, void *pvt) +{ + + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + g_assert(vu_dev); + g_assert(fd >=3D 0); + g_assert(cb); + + VuFdWatch *vu_fd_watch =3D find_vu_fd_watch(server, fd); + + if (!vu_fd_watch) { + VuFdWatch *vu_fd_watch =3D g_new0(VuFdWatch, 1); + + QTAILQ_INSERT_TAIL(&server->vu_fd_watches, vu_fd_watch, next); + + vu_fd_watch->fd =3D fd; + vu_fd_watch->cb =3D cb; + qemu_set_nonblock(fd); + aio_set_fd_handler(server->ioc->ctx, fd, true, kick_handler, + NULL, NULL, vu_fd_watch); + vu_fd_watch->vu_dev =3D vu_dev; + vu_fd_watch->pvt =3D pvt; + } +} + + +static void remove_watch(VuDev *vu_dev, int fd) +{ + VuServer *server; + g_assert(vu_dev); + g_assert(fd >=3D 0); + + server =3D container_of(vu_dev, VuServer, vu_dev); + + VuFdWatch *vu_fd_watch =3D find_vu_fd_watch(server, fd); + + if (!vu_fd_watch) { + return; + } + aio_set_fd_handler(server->ioc->ctx, fd, true, NULL, NULL, NULL, NULL); + + QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); + g_free(vu_fd_watch); +} + + +static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, + gpointer opaque) +{ + VuServer *server =3D opaque; + + if (server->sioc) { + warn_report("Only one vhost-user client is allowed to " + "connect the server one time"); + return; + } + + if (!vu_init(&server->vu_dev, server->max_queues, sioc->fd, panic_cb, + vu_message_read, set_watch, remove_watch, server->vu_ifac= e)) { + error_report("Failed to initialize libvhost-user"); + return; + } + + /* + * Unset the callback function for network listener to make another + * vhost-user client keeping waiting until this client disconnects + */ + qio_net_listener_set_client_func(server->listener, + NULL, + NULL, + NULL); + server->sioc =3D sioc; + /* + * Increase the object reference, so sioc will not freed by + * qio_net_listener_channel_func which will call object_unref(OBJECT(s= ioc)) + */ + object_ref(OBJECT(server->sioc)); + qio_channel_set_name(QIO_CHANNEL(sioc), "vhost-user client"); + server->ioc =3D QIO_CHANNEL(sioc); + object_ref(OBJECT(server->ioc)); + qio_channel_attach_aio_context(server->ioc, server->ctx); + qio_channel_set_blocking(QIO_CHANNEL(server->sioc), false, NULL); + vu_client_start(server); +} + + +void vhost_user_server_stop(VuServer *server) +{ + if (server->sioc) { + close_client(server); + } + + if (server->listener) { + qio_net_listener_disconnect(server->listener); + object_unref(OBJECT(server->listener)); + } + +} + +void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx) +{ + VuFdWatch *vu_fd_watch, *next; + void *opaque =3D NULL; + IOHandler *io_read =3D NULL; + bool attach; + + server->ctx =3D ctx ? ctx : qemu_get_aio_context(); + + if (!server->sioc) { + /* not yet serving any client*/ + return; + } + + if (ctx) { + qio_channel_attach_aio_context(server->ioc, ctx); + server->aio_context_changed =3D true; + io_read =3D kick_handler; + attach =3D true; + } else { + qio_channel_detach_aio_context(server->ioc); + /* server->ioc->ctx keeps the old AioConext */ + ctx =3D server->ioc->ctx; + attach =3D false; + } + + QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { + if (vu_fd_watch->cb) { + opaque =3D attach ? vu_fd_watch : NULL; + aio_set_fd_handler(ctx, vu_fd_watch->fd, true, + io_read, NULL, NULL, + opaque); + } + } +} + + +bool vhost_user_server_start(VuServer *server, + SocketAddress *socket_addr, + AioContext *ctx, + uint16_t max_queues, + DevicePanicNotifierFn *device_panic_notifier, + const VuDevIface *vu_iface, + Error **errp) +{ + QIONetListener *listener =3D qio_net_listener_new(); + if (qio_net_listener_open_sync(listener, socket_addr, 1, + errp) < 0) { + object_unref(OBJECT(listener)); + return false; + } + + /* zero out unspecified fileds */ + *server =3D (VuServer) { + .listener =3D listener, + .vu_iface =3D vu_iface, + .max_queues =3D max_queues, + .ctx =3D ctx, + .device_panic_notifier =3D device_panic_notifier, + }; + + qio_net_listener_set_name(server->listener, "vhost-user-backend-listen= er"); + + qio_net_listener_set_client_func(server->listener, + vu_accept, + server, + NULL); + + QTAILQ_INIT(&server->vu_fd_watches); + return true; +} diff --git a/util/meson.build b/util/meson.build index e6b207a99e..3921981ccf 100644 --- a/util/meson.build +++ b/util/meson.build @@ -66,6 +66,7 @@ if have_block util_ss.add(files('main-loop.c')) util_ss.add(files('nvdimm-utils.c')) util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-cor= outine-io.c')) + util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) util_ss.add(files('qemu-coroutine-sleep.c')) util_ss.add(files('qemu-co-shared-resource.c')) util_ss.add(files('thread-pool.c', 'qemu-timer.c')) --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366225; cv=none; d=zohomail.com; s=zohoarc; b=nXOQl9p5qbxaD2B7BbN5XxdSEZ0RQIanF5Ht736SoyOQz+EQ2MAxU6BpaiNeIbR8Hyfw5ncGWBJfPKeoIrk2x5urHI+x/ED4iJKu2D0BhgS+HbjXgA5CeO13Z2fIMeNmyFGerBVgZAcEqbL1qBUCMTkNOLSWLtafivLdl9CUR1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366225; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r/vM8uz2r0r9gdL4b3AEy4UiXb/2h/7H59pl5AF6Y+g=; b=F7sd99cbctdeub5nAqMBc6ZE+/0d22JGInHxV4y6Cd5Ynrkg2I3QyVIgJYT+mxQStqd0bB35CQYTXPxmcFsYgaYYzkuw7X/oBL5B46L+UYuqVwC/JonZF+xU2upYeeyUShVCtlOQim2CekyX8hpvV2SZGqads4f1k9bbLsQvGu0= 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 1603366225131149.863152715723; Thu, 22 Oct 2020 04:30:25 -0700 (PDT) Received: from localhost ([::1]:54094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYnX-00063k-U2 for importer@patchew.org; Thu, 22 Oct 2020 07:30:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYlU-00049a-W5 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYlP-00052k-Hd for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:15 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-l9_99nTnNoSqOTWS_u0f8Q-1; Thu, 22 Oct 2020 07:28:08 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 27CA31084D65; Thu, 22 Oct 2020 11:28:07 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F84C1002388; Thu, 22 Oct 2020 11:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r/vM8uz2r0r9gdL4b3AEy4UiXb/2h/7H59pl5AF6Y+g=; b=PHHPGBz8blcs1aMirV9etZKZyl0HXyo/lWDwIwU6dGWce+ABFdRcvivkMe9bVoUUaiu3IP ttFYA4nogXGlHcIBiDdfiDEL/R565UCJ4SQS8upz5yQoKIeu7juhD0wHPM3nqWPNJx7OXk D20icqoUVum0IJm9Nr9yKEhmUaG7rtU= X-MC-Unique: l9_99nTnNoSqOTWS_u0f8Q-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 05/28] block: move logical block size check function to a common utility function Date: Thu, 22 Oct 2020 12:27:03 +0100 Message-Id: <20201022112726.736757-6-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Coiby Xu Move the constants from hw/core/qdev-properties.c to util/block-helpers.h so that knowledge of the min/max values is Signed-off-by: Stefan Hajnoczi Signed-off-by: Coiby Xu Reviewed-by: Stefan Hajnoczi Reviewed-by: Marc-Andr=C3=A9 Lureau Acked-by: Eduardo Habkost Message-id: 20200918080912.321299-5-coiby.xu@gmail.com Signed-off-by: Stefan Hajnoczi --- util/block-helpers.h | 19 +++++++++++++ hw/core/qdev-properties-system.c | 31 ++++----------------- util/block-helpers.c | 46 ++++++++++++++++++++++++++++++++ util/meson.build | 1 + 4 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 util/block-helpers.h create mode 100644 util/block-helpers.c diff --git a/util/block-helpers.h b/util/block-helpers.h new file mode 100644 index 0000000000..b53295a529 --- /dev/null +++ b/util/block-helpers.h @@ -0,0 +1,19 @@ +#ifndef BLOCK_HELPERS_H +#define BLOCK_HELPERS_H + +#include "qemu/units.h" + +/* lower limit is sector size */ +#define MIN_BLOCK_SIZE INT64_C(512) +#define MIN_BLOCK_SIZE_STR "512 B" +/* + * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses,= and + * matches qcow2 cluster size limit + */ +#define MAX_BLOCK_SIZE (2 * MiB) +#define MAX_BLOCK_SIZE_STR "2 MiB" + +void check_block_size(const char *id, const char *name, int64_t value, + Error **errp); + +#endif /* BLOCK_HELPERS_H */ diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 49bdd12581..b81a4e8d14 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -30,6 +30,7 @@ #include "sysemu/blockdev.h" #include "net/net.h" #include "hw/pci/pci.h" +#include "util/block-helpers.h" =20 static bool check_prop_still_unset(DeviceState *dev, const char *name, const void *old_val, const char *new_va= l, @@ -576,16 +577,6 @@ const PropertyInfo qdev_prop_losttickpolicy =3D { =20 /* --- blocksize --- */ =20 -/* lower limit is sector size */ -#define MIN_BLOCK_SIZE 512 -#define MIN_BLOCK_SIZE_STR "512 B" -/* - * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses,= and - * matches qcow2 cluster size limit - */ -#define MAX_BLOCK_SIZE (2 * MiB) -#define MAX_BLOCK_SIZE_STR "2 MiB" - static void set_blocksize(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { @@ -593,6 +584,7 @@ static void set_blocksize(Object *obj, Visitor *v, cons= t char *name, Property *prop =3D opaque; uint32_t *ptr =3D qdev_get_prop_ptr(dev, prop); uint64_t value; + Error *local_err =3D NULL; =20 if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); @@ -602,24 +594,11 @@ static void set_blocksize(Object *obj, Visitor *v, co= nst char *name, if (!visit_type_size(v, name, &value, errp)) { return; } - /* value of 0 means "unset" */ - if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { - error_setg(errp, - "Property %s.%s doesn't take value %" PRIu64 - " (minimum: " MIN_BLOCK_SIZE_STR - ", maximum: " MAX_BLOCK_SIZE_STR ")", - dev->id ? : "", name, value); + check_block_size(dev->id ? : "", name, value, &local_err); + if (local_err) { + error_propagate(errp, local_err); return; } - - /* We rely on power-of-2 blocksizes for bitmasks */ - if ((value & (value - 1)) !=3D 0) { - error_setg(errp, - "Property %s.%s doesn't take value '%" PRId64 "', " - "it's not a power of 2", dev->id ?: "", name, (int64_t)v= alue); - return; - } - *ptr =3D value; } =20 diff --git a/util/block-helpers.c b/util/block-helpers.c new file mode 100644 index 0000000000..c4851432f5 --- /dev/null +++ b/util/block-helpers.c @@ -0,0 +1,46 @@ +/* + * Block utility functions + * + * Copyright IBM, Corp. 2011 + * Copyright (c) 2020 Coiby Xu + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qmp/qerror.h" +#include "block-helpers.h" + +/** + * check_block_size: + * @id: The unique ID of the object + * @name: The name of the property being validated + * @value: The block size in bytes + * @errp: A pointer to an area to store an error + * + * This function checks that the block size meets the following conditions: + * 1. At least MIN_BLOCK_SIZE + * 2. No larger than MAX_BLOCK_SIZE + * 3. A power of 2 + */ +void check_block_size(const char *id, const char *name, int64_t value, + Error **errp) +{ + /* value of 0 means "unset" */ + if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, + id, name, value, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE); + return; + } + + /* We rely on power-of-2 blocksizes for bitmasks */ + if ((value & (value - 1)) !=3D 0) { + error_setg(errp, + "Property %s.%s doesn't take value '%" PRId64 + "', it's not a power of 2", + id, name, value); + return; + } +} diff --git a/util/meson.build b/util/meson.build index 3921981ccf..2296e81b34 100644 --- a/util/meson.build +++ b/util/meson.build @@ -67,6 +67,7 @@ if have_block util_ss.add(files('nvdimm-utils.c')) util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-cor= outine-io.c')) util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) + util_ss.add(files('block-helpers.c')) util_ss.add(files('qemu-coroutine-sleep.c')) util_ss.add(files('qemu-co-shared-resource.c')) util_ss.add(files('thread-pool.c', 'qemu-timer.c')) --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366524; cv=none; d=zohomail.com; s=zohoarc; b=mjJzYGEIXh+NNVbjsAMlf6UeJalI2vrWQUHegbcKN1YuyL4OsV8X5cXw74dZMXPV7RYwTYSi6Rk1bnOwrbwTLHqscJ4YrWBAG8rzxZuYENh6l6sh2aSb7aFXuFXDb5JtItXJGELGkPIJQy/lW6TPMHDz+UxwMwLqZWQZwpxZH54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366524; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O642ir5IEq3mZdjtd2xy4Gsz9ZRz0c2Uqrt3a+vhkLg=; b=X3sA49BDyBpHO5atgT4UZR5gYVaJjO3bsRYhMJOwVmZPBwhli1eOXxprxqiCgb+4FDmizmn9YAyDgBLcRIEpSt/f7MRBkx0tFkdvxt9gA+MuVVZO44DUw+gpAvzygciyd+O8g8Kzzrqa4/v0YDRLzvKyuAbMeKH2j4B6hBbXVtw= 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 160336652458961.04627343011089; Thu, 22 Oct 2020 04:35:24 -0700 (PDT) Received: from localhost ([::1]:42904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYsN-0004kd-DR for importer@patchew.org; Thu, 22 Oct 2020 07:35:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYlb-0004EW-Cb for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59291) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYlY-00053I-2o for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-4MxgbuHaPTSvaWfRyj3bew-1; Thu, 22 Oct 2020 07:28:16 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88D9E107ACF5; Thu, 22 Oct 2020 11:28:15 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F57919C4F; Thu, 22 Oct 2020 11:28:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O642ir5IEq3mZdjtd2xy4Gsz9ZRz0c2Uqrt3a+vhkLg=; b=Nc0PCO5fWywHZVwYsTD4k4g19t0wkEVGUjP5v0qnpTnqpinPtOBcSrqm4y8gy0bjNhXPOQ GNsez0nFe6S+qJPP+F0rIke2Ft9hOSNXzaX9BxDo/vlEvsEngzOaNtTyhxrBvQ6hnolxAx prPy69e4Z7bxi5G+TsouorsNyOAQUgQ= X-MC-Unique: 4MxgbuHaPTSvaWfRyj3bew-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 06/28] block/export: vhost-user block device backend server Date: Thu, 22 Oct 2020 12:27:04 +0100 Message-Id: <20201022112726.736757-7-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Coiby Xu By making use of libvhost-user, block device drive can be shared to the connected vhost-user client. Only one client can connect to the server one time. Since vhost-user-server needs a block drive to be created first, delay the creation of this object. Suggested-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Signed-off-by: Coiby Xu Reviewed-by: Stefan Hajnoczi Reviewed-by: Marc-Andr=C3=A9 Lureau Message-id: 20200918080912.321299-6-coiby.xu@gmail.com [Shorten "vhost_user_blk_server" string to "vhost_user_blk" to avoid the following compiler warning: ../block/export/vhost-user-blk-server.c:178:50: error: =E2=80=98%s=E2=80=99= directive output truncated writing 21 bytes into a region of size 20 [-Wer= ror=3Dformat-truncation=3D] and fix "Invalid size %ld ..." ssize_t format string arguments for 32-bit hosts. --Stefan] Signed-off-by: Stefan Hajnoczi --- block/export/vhost-user-blk-server.h | 36 ++ block/export/vhost-user-blk-server.c | 661 +++++++++++++++++++++++++++ softmmu/vl.c | 4 + block/meson.build | 1 + 4 files changed, 702 insertions(+) create mode 100644 block/export/vhost-user-blk-server.h create mode 100644 block/export/vhost-user-blk-server.c diff --git a/block/export/vhost-user-blk-server.h b/block/export/vhost-user= -blk-server.h new file mode 100644 index 0000000000..f06f37c4c8 --- /dev/null +++ b/block/export/vhost-user-blk-server.h @@ -0,0 +1,36 @@ +/* + * Sharing QEMU block devices via vhost-user protocal + * + * Copyright (c) Coiby Xu . + * Copyright (c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef VHOST_USER_BLK_SERVER_H +#define VHOST_USER_BLK_SERVER_H +#include "util/vhost-user-server.h" + +typedef struct VuBlockDev VuBlockDev; +#define TYPE_VHOST_USER_BLK_SERVER "vhost-user-blk-server" +#define VHOST_USER_BLK_SERVER(obj) \ + OBJECT_CHECK(VuBlockDev, obj, TYPE_VHOST_USER_BLK_SERVER) + +/* vhost user block device */ +struct VuBlockDev { + Object parent_obj; + char *node_name; + SocketAddress *addr; + AioContext *ctx; + VuServer vu_server; + bool running; + uint32_t blk_size; + BlockBackend *backend; + QIOChannelSocket *sioc; + QTAILQ_ENTRY(VuBlockDev) next; + struct virtio_blk_config blkcfg; + bool writable; +}; + +#endif /* VHOST_USER_BLK_SERVER_H */ diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c new file mode 100644 index 0000000000..2ba1613cc9 --- /dev/null +++ b/block/export/vhost-user-blk-server.c @@ -0,0 +1,661 @@ +/* + * Sharing QEMU block devices via vhost-user protocal + * + * Parts of the code based on nbd/server.c. + * + * Copyright (c) Coiby Xu . + * Copyright (c) 2020 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "block/block.h" +#include "vhost-user-blk-server.h" +#include "qapi/error.h" +#include "qom/object_interfaces.h" +#include "sysemu/block-backend.h" +#include "util/block-helpers.h" + +enum { + VHOST_USER_BLK_MAX_QUEUES =3D 1, +}; +struct virtio_blk_inhdr { + unsigned char status; +}; + +typedef struct VuBlockReq { + VuVirtqElement *elem; + int64_t sector_num; + size_t size; + struct virtio_blk_inhdr *in; + struct virtio_blk_outhdr out; + VuServer *server; + struct VuVirtq *vq; +} VuBlockReq; + +static void vu_block_req_complete(VuBlockReq *req) +{ + VuDev *vu_dev =3D &req->server->vu_dev; + + /* IO size with 1 extra status byte */ + vu_queue_push(vu_dev, req->vq, req->elem, req->size + 1); + vu_queue_notify(vu_dev, req->vq); + + if (req->elem) { + free(req->elem); + } + + g_free(req); +} + +static VuBlockDev *get_vu_block_device_by_server(VuServer *server) +{ + return container_of(server, VuBlockDev, vu_server); +} + +static int coroutine_fn +vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov, + uint32_t iovcnt, uint32_t type) +{ + struct virtio_blk_discard_write_zeroes desc; + ssize_t size =3D iov_to_buf(iov, iovcnt, 0, &desc, sizeof(desc)); + if (unlikely(size !=3D sizeof(desc))) { + error_report("Invalid size %zd, expect %zu", size, sizeof(desc)); + return -EINVAL; + } + + VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(req->server); + uint64_t range[2] =3D { le64_to_cpu(desc.sector) << 9, + le32_to_cpu(desc.num_sectors) << 9 }; + if (type =3D=3D VIRTIO_BLK_T_DISCARD) { + if (blk_co_pdiscard(vdev_blk->backend, range[0], range[1]) =3D=3D = 0) { + return 0; + } + } else if (type =3D=3D VIRTIO_BLK_T_WRITE_ZEROES) { + if (blk_co_pwrite_zeroes(vdev_blk->backend, + range[0], range[1], 0) =3D=3D 0) { + return 0; + } + } + + return -EINVAL; +} + +static void coroutine_fn vu_block_flush(VuBlockReq *req) +{ + VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(req->server); + BlockBackend *backend =3D vdev_blk->backend; + blk_co_flush(backend); +} + +struct req_data { + VuServer *server; + VuVirtq *vq; + VuVirtqElement *elem; +}; + +static void coroutine_fn vu_block_virtio_process_req(void *opaque) +{ + struct req_data *data =3D opaque; + VuServer *server =3D data->server; + VuVirtq *vq =3D data->vq; + VuVirtqElement *elem =3D data->elem; + uint32_t type; + VuBlockReq *req; + + VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); + BlockBackend *backend =3D vdev_blk->backend; + + struct iovec *in_iov =3D elem->in_sg; + struct iovec *out_iov =3D elem->out_sg; + unsigned in_num =3D elem->in_num; + unsigned out_num =3D elem->out_num; + /* refer to hw/block/virtio_blk.c */ + if (elem->out_num < 1 || elem->in_num < 1) { + error_report("virtio-blk request missing headers"); + free(elem); + return; + } + + req =3D g_new0(VuBlockReq, 1); + req->server =3D server; + req->vq =3D vq; + req->elem =3D elem; + + if (unlikely(iov_to_buf(out_iov, out_num, 0, &req->out, + sizeof(req->out)) !=3D sizeof(req->out))) { + error_report("virtio-blk request outhdr too short"); + goto err; + } + + iov_discard_front(&out_iov, &out_num, sizeof(req->out)); + + if (in_iov[in_num - 1].iov_len < sizeof(struct virtio_blk_inhdr)) { + error_report("virtio-blk request inhdr too short"); + goto err; + } + + /* We always touch the last byte, so just see how big in_iov is. */ + req->in =3D (void *)in_iov[in_num - 1].iov_base + + in_iov[in_num - 1].iov_len + - sizeof(struct virtio_blk_inhdr); + iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr)); + + type =3D le32_to_cpu(req->out.type); + switch (type & ~VIRTIO_BLK_T_BARRIER) { + case VIRTIO_BLK_T_IN: + case VIRTIO_BLK_T_OUT: { + ssize_t ret =3D 0; + bool is_write =3D type & VIRTIO_BLK_T_OUT; + req->sector_num =3D le64_to_cpu(req->out.sector); + + int64_t offset =3D req->sector_num * vdev_blk->blk_size; + QEMUIOVector qiov; + if (is_write) { + qemu_iovec_init_external(&qiov, out_iov, out_num); + ret =3D blk_co_pwritev(backend, offset, qiov.size, + &qiov, 0); + } else { + qemu_iovec_init_external(&qiov, in_iov, in_num); + ret =3D blk_co_preadv(backend, offset, qiov.size, + &qiov, 0); + } + if (ret >=3D 0) { + req->in->status =3D VIRTIO_BLK_S_OK; + } else { + req->in->status =3D VIRTIO_BLK_S_IOERR; + } + break; + } + case VIRTIO_BLK_T_FLUSH: + vu_block_flush(req); + req->in->status =3D VIRTIO_BLK_S_OK; + break; + case VIRTIO_BLK_T_GET_ID: { + size_t size =3D MIN(iov_size(&elem->in_sg[0], in_num), + VIRTIO_BLK_ID_BYTES); + snprintf(elem->in_sg[0].iov_base, size, "%s", "vhost_user_blk"); + req->in->status =3D VIRTIO_BLK_S_OK; + req->size =3D elem->in_sg[0].iov_len; + break; + } + case VIRTIO_BLK_T_DISCARD: + case VIRTIO_BLK_T_WRITE_ZEROES: { + int rc; + rc =3D vu_block_discard_write_zeroes(req, &elem->out_sg[1], + out_num, type); + if (rc =3D=3D 0) { + req->in->status =3D VIRTIO_BLK_S_OK; + } else { + req->in->status =3D VIRTIO_BLK_S_IOERR; + } + break; + } + default: + req->in->status =3D VIRTIO_BLK_S_UNSUPP; + break; + } + + vu_block_req_complete(req); + return; + +err: + free(elem); + g_free(req); + return; +} + +static void vu_block_process_vq(VuDev *vu_dev, int idx) +{ + VuServer *server; + VuVirtq *vq; + struct req_data *req_data; + + server =3D container_of(vu_dev, VuServer, vu_dev); + assert(server); + + vq =3D vu_get_queue(vu_dev, idx); + assert(vq); + VuVirtqElement *elem; + while (1) { + elem =3D vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + + sizeof(VuBlockReq)); + if (elem) { + req_data =3D g_new0(struct req_data, 1); + req_data->server =3D server; + req_data->vq =3D vq; + req_data->elem =3D elem; + Coroutine *co =3D qemu_coroutine_create(vu_block_virtio_proces= s_req, + req_data); + aio_co_enter(server->ioc->ctx, co); + } else { + break; + } + } +} + +static void vu_block_queue_set_started(VuDev *vu_dev, int idx, bool starte= d) +{ + VuVirtq *vq; + + assert(vu_dev); + + vq =3D vu_get_queue(vu_dev, idx); + vu_set_queue_handler(vu_dev, vq, started ? vu_block_process_vq : NULL); +} + +static uint64_t vu_block_get_features(VuDev *dev) +{ + uint64_t features; + VuServer *server =3D container_of(dev, VuServer, vu_dev); + VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); + features =3D 1ull << VIRTIO_BLK_F_SIZE_MAX | + 1ull << VIRTIO_BLK_F_SEG_MAX | + 1ull << VIRTIO_BLK_F_TOPOLOGY | + 1ull << VIRTIO_BLK_F_BLK_SIZE | + 1ull << VIRTIO_BLK_F_FLUSH | + 1ull << VIRTIO_BLK_F_DISCARD | + 1ull << VIRTIO_BLK_F_WRITE_ZEROES | + 1ull << VIRTIO_BLK_F_CONFIG_WCE | + 1ull << VIRTIO_F_VERSION_1 | + 1ull << VIRTIO_RING_F_INDIRECT_DESC | + 1ull << VIRTIO_RING_F_EVENT_IDX | + 1ull << VHOST_USER_F_PROTOCOL_FEATURES; + + if (!vdev_blk->writable) { + features |=3D 1ull << VIRTIO_BLK_F_RO; + } + + return features; +} + +static uint64_t vu_block_get_protocol_features(VuDev *dev) +{ + return 1ull << VHOST_USER_PROTOCOL_F_CONFIG | + 1ull << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD; +} + +static int +vu_block_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) +{ + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); + memcpy(config, &vdev_blk->blkcfg, len); + + return 0; +} + +static int +vu_block_set_config(VuDev *vu_dev, const uint8_t *data, + uint32_t offset, uint32_t size, uint32_t flags) +{ + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); + uint8_t wce; + + /* don't support live migration */ + if (flags !=3D VHOST_SET_CONFIG_TYPE_MASTER) { + return -EINVAL; + } + + if (offset !=3D offsetof(struct virtio_blk_config, wce) || + size !=3D 1) { + return -EINVAL; + } + + wce =3D *data; + vdev_blk->blkcfg.wce =3D wce; + blk_set_enable_write_cache(vdev_blk->backend, wce); + return 0; +} + +/* + * When the client disconnects, it sends a VHOST_USER_NONE request + * and vu_process_message will simple call exit which cause the VM + * to exit abruptly. + * To avoid this issue, process VHOST_USER_NONE request ahead + * of vu_process_message. + * + */ +static int vu_block_process_msg(VuDev *dev, VhostUserMsg *vmsg, int *do_re= ply) +{ + if (vmsg->request =3D=3D VHOST_USER_NONE) { + dev->panic(dev, "disconnect"); + return true; + } + return false; +} + +static const VuDevIface vu_block_iface =3D { + .get_features =3D vu_block_get_features, + .queue_set_started =3D vu_block_queue_set_started, + .get_protocol_features =3D vu_block_get_protocol_features, + .get_config =3D vu_block_get_config, + .set_config =3D vu_block_set_config, + .process_msg =3D vu_block_process_msg, +}; + +static void blk_aio_attached(AioContext *ctx, void *opaque) +{ + VuBlockDev *vub_dev =3D opaque; + aio_context_acquire(ctx); + vhost_user_server_set_aio_context(&vub_dev->vu_server, ctx); + aio_context_release(ctx); +} + +static void blk_aio_detach(void *opaque) +{ + VuBlockDev *vub_dev =3D opaque; + AioContext *ctx =3D vub_dev->vu_server.ctx; + aio_context_acquire(ctx); + vhost_user_server_set_aio_context(&vub_dev->vu_server, NULL); + aio_context_release(ctx); +} + +static void +vu_block_initialize_config(BlockDriverState *bs, + struct virtio_blk_config *config, uint32_t blk_= size) +{ + config->capacity =3D bdrv_getlength(bs) >> BDRV_SECTOR_BITS; + config->blk_size =3D blk_size; + config->size_max =3D 0; + config->seg_max =3D 128 - 2; + config->min_io_size =3D 1; + config->opt_io_size =3D 1; + config->num_queues =3D VHOST_USER_BLK_MAX_QUEUES; + config->max_discard_sectors =3D 32768; + config->max_discard_seg =3D 1; + config->discard_sector_alignment =3D config->blk_size >> 9; + config->max_write_zeroes_sectors =3D 32768; + config->max_write_zeroes_seg =3D 1; +} + +static VuBlockDev *vu_block_init(VuBlockDev *vu_block_device, Error **errp) +{ + + BlockBackend *blk; + Error *local_error =3D NULL; + const char *node_name =3D vu_block_device->node_name; + bool writable =3D vu_block_device->writable; + uint64_t perm =3D BLK_PERM_CONSISTENT_READ; + int ret; + + AioContext *ctx; + + BlockDriverState *bs =3D bdrv_lookup_bs(node_name, node_name, &local_e= rror); + + if (!bs) { + error_propagate(errp, local_error); + return NULL; + } + + if (bdrv_is_read_only(bs)) { + writable =3D false; + } + + if (writable) { + perm |=3D BLK_PERM_WRITE; + } + + ctx =3D bdrv_get_aio_context(bs); + aio_context_acquire(ctx); + bdrv_invalidate_cache(bs, NULL); + aio_context_release(ctx); + + /* + * Don't allow resize while the vhost user server is running, + * otherwise we don't care what happens with the node. + */ + blk =3D blk_new(bdrv_get_aio_context(bs), perm, + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | + BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD); + ret =3D blk_insert_bs(blk, bs, errp); + + if (ret < 0) { + goto fail; + } + + blk_set_enable_write_cache(blk, false); + + blk_set_allow_aio_context_change(blk, true); + + vu_block_device->blkcfg.wce =3D 0; + vu_block_device->backend =3D blk; + if (!vu_block_device->blk_size) { + vu_block_device->blk_size =3D BDRV_SECTOR_SIZE; + } + vu_block_device->blkcfg.blk_size =3D vu_block_device->blk_size; + blk_set_guest_block_size(blk, vu_block_device->blk_size); + vu_block_initialize_config(bs, &vu_block_device->blkcfg, + vu_block_device->blk_size); + return vu_block_device; + +fail: + blk_unref(blk); + return NULL; +} + +static void vu_block_deinit(VuBlockDev *vu_block_device) +{ + if (vu_block_device->backend) { + blk_remove_aio_context_notifier(vu_block_device->backend, blk_aio_= attached, + blk_aio_detach, vu_block_device); + } + + blk_unref(vu_block_device->backend); +} + +static void vhost_user_blk_server_stop(VuBlockDev *vu_block_device) +{ + vhost_user_server_stop(&vu_block_device->vu_server); + vu_block_deinit(vu_block_device); +} + +static void vhost_user_blk_server_start(VuBlockDev *vu_block_device, + Error **errp) +{ + AioContext *ctx; + SocketAddress *addr =3D vu_block_device->addr; + + if (!vu_block_init(vu_block_device, errp)) { + return; + } + + ctx =3D bdrv_get_aio_context(blk_bs(vu_block_device->backend)); + + if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, + VHOST_USER_BLK_MAX_QUEUES, + NULL, &vu_block_iface, + errp)) { + goto error; + } + + blk_add_aio_context_notifier(vu_block_device->backend, blk_aio_attache= d, + blk_aio_detach, vu_block_device); + vu_block_device->running =3D true; + return; + + error: + vu_block_deinit(vu_block_device); +} + +static bool vu_prop_modifiable(VuBlockDev *vus, Error **errp) +{ + if (vus->running) { + error_setg(errp, "The property can't be modified " + "while the server is running"); + return false; + } + return true; +} + +static void vu_set_node_name(Object *obj, const char *value, Error **errp) +{ + VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); + + if (!vu_prop_modifiable(vus, errp)) { + return; + } + + if (vus->node_name) { + g_free(vus->node_name); + } + + vus->node_name =3D g_strdup(value); +} + +static char *vu_get_node_name(Object *obj, Error **errp) +{ + VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); + return g_strdup(vus->node_name); +} + +static void free_socket_addr(SocketAddress *addr) +{ + g_free(addr->u.q_unix.path); + g_free(addr); +} + +static void vu_set_unix_socket(Object *obj, const char *value, + Error **errp) +{ + VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); + + if (!vu_prop_modifiable(vus, errp)) { + return; + } + + if (vus->addr) { + free_socket_addr(vus->addr); + } + + SocketAddress *addr =3D g_new0(SocketAddress, 1); + addr->type =3D SOCKET_ADDRESS_TYPE_UNIX; + addr->u.q_unix.path =3D g_strdup(value); + vus->addr =3D addr; +} + +static char *vu_get_unix_socket(Object *obj, Error **errp) +{ + VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); + return g_strdup(vus->addr->u.q_unix.path); +} + +static bool vu_get_block_writable(Object *obj, Error **errp) +{ + VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); + return vus->writable; +} + +static void vu_set_block_writable(Object *obj, bool value, Error **errp) +{ + VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); + + if (!vu_prop_modifiable(vus, errp)) { + return; + } + + vus->writable =3D value; +} + +static void vu_get_blk_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); + uint32_t value =3D vus->blk_size; + + visit_type_uint32(v, name, &value, errp); +} + +static void vu_set_blk_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); + + Error *local_err =3D NULL; + uint32_t value; + + if (!vu_prop_modifiable(vus, errp)) { + return; + } + + visit_type_uint32(v, name, &value, &local_err); + if (local_err) { + goto out; + } + + check_block_size(object_get_typename(obj), name, value, &local_err); + if (local_err) { + goto out; + } + + vus->blk_size =3D value; + +out: + error_propagate(errp, local_err); +} + +static void vhost_user_blk_server_instance_finalize(Object *obj) +{ + VuBlockDev *vub =3D VHOST_USER_BLK_SERVER(obj); + + vhost_user_blk_server_stop(vub); + + /* + * Unlike object_property_add_str, object_class_property_add_str + * doesn't have a release method. Thus manual memory freeing is + * needed. + */ + free_socket_addr(vub->addr); + g_free(vub->node_name); +} + +static void vhost_user_blk_server_complete(UserCreatable *obj, Error **err= p) +{ + VuBlockDev *vub =3D VHOST_USER_BLK_SERVER(obj); + + vhost_user_blk_server_start(vub, errp); +} + +static void vhost_user_blk_server_class_init(ObjectClass *klass, + void *class_data) +{ + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(klass); + ucc->complete =3D vhost_user_blk_server_complete; + + object_class_property_add_bool(klass, "writable", + vu_get_block_writable, + vu_set_block_writable); + + object_class_property_add_str(klass, "node-name", + vu_get_node_name, + vu_set_node_name); + + object_class_property_add_str(klass, "unix-socket", + vu_get_unix_socket, + vu_set_unix_socket); + + object_class_property_add(klass, "logical-block-size", "uint32", + vu_get_blk_size, vu_set_blk_size, + NULL, NULL); +} + +static const TypeInfo vhost_user_blk_server_info =3D { + .name =3D TYPE_VHOST_USER_BLK_SERVER, + .parent =3D TYPE_OBJECT, + .instance_size =3D sizeof(VuBlockDev), + .instance_finalize =3D vhost_user_blk_server_instance_finalize, + .class_init =3D vhost_user_blk_server_class_init, + .interfaces =3D (InterfaceInfo[]) { + {TYPE_USER_CREATABLE}, + {} + }, +}; + +static void vhost_user_blk_server_register_types(void) +{ + type_register_static(&vhost_user_blk_server_info); +} + +type_init(vhost_user_blk_server_register_types) diff --git a/softmmu/vl.c b/softmmu/vl.c index cb476aa70b..05cbfc5764 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2540,6 +2540,10 @@ static bool object_create_initial(const char *type, = QemuOpts *opts) } #endif =20 + /* Reason: vhost-user-blk-server property "node-name" */ + if (g_str_equal(type, "vhost-user-blk-server")) { + return false; + } /* * Reason: filter-* property "netdev" etc. */ diff --git a/block/meson.build b/block/meson.build index 78e8b25232..6e6c1dc479 100644 --- a/block/meson.build +++ b/block/meson.build @@ -60,6 +60,7 @@ block_ss.add(when: 'CONFIG_WIN32', if_true: files('file-w= in32.c', 'win32-aio.c') block_ss.add(when: 'CONFIG_POSIX', if_true: [files('file-posix.c'), coref,= iokit]) block_ss.add(when: 'CONFIG_LIBISCSI', if_true: files('iscsi-opts.c')) block_ss.add(when: 'CONFIG_LINUX', if_true: files('nvme.c')) +block_ss.add(when: 'CONFIG_LINUX', if_true: files('export/vhost-user-blk-s= erver.c', '../contrib/libvhost-user/libvhost-user.c')) block_ss.add(when: 'CONFIG_REPLICATION', if_true: files('replication.c')) block_ss.add(when: 'CONFIG_SHEEPDOG', if_true: files('sheepdog.c')) block_ss.add(when: ['CONFIG_LINUX_AIO', libaio], if_true: files('linux-aio= .c')) --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366499; cv=none; d=zohomail.com; s=zohoarc; b=St5FgidCfHcjPqkM5vu/9kjQk/6z92TIub3wZwOXSrq5Y5Y6W0PoqXmN+aCyfKpAjMOl841QGvSjBzBIBqVMVZztz4rLKCqsOzObwaRxHnEajy1ob+w42B/IOmuMRPStGeo92PkUEXoifRaxUMaoKYVypHwGljwJRGWkwemtDI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366499; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Sxsa46ohfJOw5uoy3nKPXxKds2WWM/hMeA6idAANNNo=; b=Il4bIRhBzOdTrPVkC3VrrXtBLrSb4DQj+0yOA+T4Xt+mvi93wB//7AbeiSWiRsPJiXti0CZam5prv0zmsMX1/40VZssGuej1333jNFzwbH8GhIWpvmUuG+2jUmSyNrNbkRcc3v++lqJxrOfeo7RaAORKWYeiWG1//LI1sTmQp+U= 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 1603366499165190.91910353882668; Thu, 22 Oct 2020 04:34:59 -0700 (PDT) Received: from localhost ([::1]:41902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYrx-0004M8-Uu for importer@patchew.org; Thu, 22 Oct 2020 07:34:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYlb-0004Fq-QN for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35317) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYlZ-00053S-Ib for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-420-NBqNx28qOTC_4ZkEseFNXQ-1; Thu, 22 Oct 2020 07:28:18 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 696591009E21; Thu, 22 Oct 2020 11:28:17 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id E412A19C4F; Thu, 22 Oct 2020 11:28:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sxsa46ohfJOw5uoy3nKPXxKds2WWM/hMeA6idAANNNo=; b=dorKBVTzQ9z1pnKauQcALNVbAMRliz5xd2Wyq/RidwrQlv9RUlfqGD3oDQqww3Ykhlx5w6 TF3PGTdpUyrOLU8z3ApMWl5cM9rBLT0Hy2QyWT3bd3/zbORIh4Aqc3v6uIcl2lh3aGNzDW /vP8iLpxLF5pTaKlzAp8ClABfB9ZLuo= X-MC-Unique: NBqNx28qOTC_4ZkEseFNXQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 07/28] MAINTAINERS: Add vhost-user block device backend server maintainer Date: Thu, 22 Oct 2020 12:27:05 +0100 Message-Id: <20201022112726.736757-8-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Max Reitz , Stefano Garzarella Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Coiby Xu Suggested-by: Stefano Garzarella Signed-off-by: Coiby Xu Reviewed-by: Stefan Hajnoczi Reviewed-by: Marc-Andr=C3=A9 Lureau Message-id: 20200918080912.321299-8-coiby.xu@gmail.com [Removed reference to vhost-user-blk-test.c, it will be sent in a separate pull request. --Stefan] Signed-off-by: Stefan Hajnoczi --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index a7f0acf866..39fd488bd0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3062,6 +3062,13 @@ L: qemu-block@nongnu.org S: Supported F: tests/image-fuzzer/ =20 +Vhost-user block device backend server +M: Coiby Xu +S: Maintained +F: block/export/vhost-user-blk-server.c +F: util/vhost-user-server.c +F: tests/qtest/libqos/vhost-user-blk.c + Replication M: Wen Congyang M: Xie Changlong --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366683; cv=none; d=zohomail.com; s=zohoarc; b=hUTxWC2p6vPO6N1Q89bPIxlg5b0Jm0xCzdVJ46UsvKH5eu0Ii7VppEOISHpSWXoPelVhndXny9JcmajYNpbnPuWnzxpd12oF3icPzsZGhJZX+nXbcopvcECZNyjQ9nyGXJ7CK/NcKCndOULW2w3I0hC99rjHviZ7B1Vr+1Trqto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366683; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gdbjx4jC6RspLuWlx++Rq0O/3VtjqAWAahM++epM/XA=; b=HI2u+gbxDGh6iBmkoH8aE8LmvvKg16Li2DcbJ2rxK5TFamGnWIK6ilB5ZHigJ20L1Pqu28/lPU/BhpsoCflc+uCdwE5dEebe1Pb5jLaS0Z6PwfY5wi0k5zSDfRs8hNy9BS/Q8Un98P/RQMNIDA+w040en19G9g+Q9k2hpCNEVIM= 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 1603366683723998.271134889074; Thu, 22 Oct 2020 04:38:03 -0700 (PDT) Received: from localhost ([::1]:51392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYuw-0008GQ-Jf for importer@patchew.org; Thu, 22 Oct 2020 07:38:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYlg-0004PW-L1 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31479) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYlf-000544-1K for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-260-lfBU8mVgPg698_aZBXqjfA-1; Thu, 22 Oct 2020 07:28:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 543FF1009E2B; Thu, 22 Oct 2020 11:28:22 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE6495D9D5; Thu, 22 Oct 2020 11:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gdbjx4jC6RspLuWlx++Rq0O/3VtjqAWAahM++epM/XA=; b=AvwOGDXCODhLf/LZMDWHmEfADnqC8gt/gP/piYqQV/p8q+baV67oJsVLi0SaT8Oce1LDLa tO7kZq4NaUI/cyIxWGA41+n3jXzNsjy00HzB8ACRHDCc4nSWuahITvipscgdnmGMEDb6Uk oAiMUdUDiEfkWc+5Ix9t8gCjsX7vscA= X-MC-Unique: lfBU8mVgPg698_aZBXqjfA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 08/28] util/vhost-user-server: s/fileds/fields/ typo fix Date: Thu, 22 Oct 2020 12:27:06 +0100 Message-Id: <20201022112726.736757-9-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-3-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index b189944856..9bd33e0fdb 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -407,7 +407,7 @@ bool vhost_user_server_start(VuServer *server, return false; } =20 - /* zero out unspecified fileds */ + /* zero out unspecified fields */ *server =3D (VuServer) { .listener =3D listener, .vu_iface =3D vu_iface, --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366838; cv=none; d=zohomail.com; s=zohoarc; b=R5/N9RzL9orLkKfqQTdDpHT1WkZ7R3IlOI/uRHjPX+p/e7k8zQB45KJVKbJgGqVkDinsgRN4ANBko/U4ZIzy8eoS07ErlixkiKasiu8yERRG3mrvnS85KGmrbtYc7ZTN6xJ4JeDEkMlFm9URdfV8Y5CzfktdgJlftKOImHVmbVM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366838; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cZ50qLLD6k1ryEay4NPbvsMG0Teqrn3RbrK7K8ZngAE=; b=f2P+1/jz5wDHNnMJIY/+XmsmAk2rMXJzsqPcm1rMaI0ovYN0zipSWYK+YPwSwf+KhiWS7tXnMX1acZx6EV6ttHWslYUnGGPjJmCXosuKC+g+62fLghYtcXsJkax4L5mRJnk0Ih7M1lK/sxsOAtuJv09wv3S0QSL7cc9AFyscu30= 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 1603366838540557.5703817043584; Thu, 22 Oct 2020 04:40:38 -0700 (PDT) Received: from localhost ([::1]:59750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYxR-0003K2-Ct for importer@patchew.org; Thu, 22 Oct 2020 07:40:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYlp-0004n2-HC for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYlo-00054f-0T for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-464-EqwBJLuhPgermCNVfHYnTA-1; Thu, 22 Oct 2020 07:28:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7E9C64091; Thu, 22 Oct 2020 11:28:29 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 735B95C1C7; Thu, 22 Oct 2020 11:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cZ50qLLD6k1ryEay4NPbvsMG0Teqrn3RbrK7K8ZngAE=; b=IWn+HrqQi/29sTW4en/9aIgti6pNGgvyUgYPGHU00qHE9F/Ve26JYGIXMh5ZR0kNmtHt/h sjxDvpB7n74A/dF1UK817lwUD+UPzrB/PEd220DlTr1OF7RineheSQP0pi2K/yEA0XQorU KcmFgwOHHcY0DFp7RJbt9yzw2P8kOy8= X-MC-Unique: EqwBJLuhPgermCNVfHYnTA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 09/28] util/vhost-user-server: drop unnecessary QOM cast Date: Thu, 22 Oct 2020 12:27:07 +0100 Message-Id: <20201022112726.736757-10-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We already have access to the value with the correct type (ioc and sioc are the same QIOChannel). Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-4-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 9bd33e0fdb..443ab7448c 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -337,7 +337,7 @@ static void vu_accept(QIONetListener *listener, QIOChan= nelSocket *sioc, server->ioc =3D QIO_CHANNEL(sioc); object_ref(OBJECT(server->ioc)); qio_channel_attach_aio_context(server->ioc, server->ctx); - qio_channel_set_blocking(QIO_CHANNEL(server->sioc), false, NULL); + qio_channel_set_blocking(server->ioc, false, NULL); vu_client_start(server); } =20 --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366395; cv=none; d=zohomail.com; s=zohoarc; b=bNtsxwLGwzZRnIEegyVxRZXZ19//eU2QkU2Pn/stb+r3B/kvwPjwnvpyZOpOBIcmyU+MAWacQ3n+4e/5z9DOufEV64thxOWMm50fx3Qr59zybN54NMsFBasN/cgWcuyuQPfVVe0PHb20nRr83VIQXJJsjk0bHkqLud3q7U56620= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366395; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fDviE/SJ6uF9ldAP6G/NhtSKe90wMCeVNvasQ/wFgFo=; b=UljXcwIQrEXyciWEGDGmNZloGE5FVdFYgnHCEAi2ePQj3YtUwxH4i+3uVmsJzfV8OpfWN8u2ppj4HhEx3WZAlYYVBppHqPmwZ0U9fKmIphXGzeEc+3vnsIJqQ3dCXDcfsX6UBv0BxMGhNU6dQFpTL8IocQJct9iKL61Dtv3lEYg= 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 1603366395924391.3577325709508; Thu, 22 Oct 2020 04:33:15 -0700 (PDT) Received: from localhost ([::1]:35784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYqI-0001rR-TG for importer@patchew.org; Thu, 22 Oct 2020 07:33:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYls-0004tf-2I for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYlq-00054v-CQ for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-287-9iCS9Sj5NgmOb6EO0JAxNg-1; Thu, 22 Oct 2020 07:28:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 507DA1882FA8; Thu, 22 Oct 2020 11:28:34 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08CE060BFA; Thu, 22 Oct 2020 11:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fDviE/SJ6uF9ldAP6G/NhtSKe90wMCeVNvasQ/wFgFo=; b=ahsnqOvyAmcx+Dv+H91xBr4QCw5kFNH23XlDUGFH/5BHk6zmmAjhieoblR+APPIiqIB2ZU S4mN0WqlFCZgsINl64XfpSpUjvA0r+yhLrQBOkD/ImMPrsVlsCXL38g8i+EGDp4vW7c6zx Mjb/MlAOW1VVH3G5I2eFpIU+C6KjWIA= X-MC-Unique: 9iCS9Sj5NgmOb6EO0JAxNg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 10/28] util/vhost-user-server: drop unnecessary watch deletion Date: Thu, 22 Oct 2020 12:27:08 +0100 Message-Id: <20201022112726.736757-11-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Explicitly deleting watches is not necessary since libvhost-user calls remove_watch() during vu_deinit(). Add an assertion to check this though. Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-5-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 443ab7448c..6efe2279fd 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -48,21 +48,6 @@ static void close_client(VuServer *server) /* When this is set vu_client_trip will stop new processing vhost-user= message */ server->sioc =3D NULL; =20 - VuFdWatch *vu_fd_watch, *next; - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { - aio_set_fd_handler(server->ioc->ctx, vu_fd_watch->fd, true, NULL, - NULL, NULL, NULL); - } - - while (!QTAILQ_EMPTY(&server->vu_fd_watches)) { - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, nex= t) { - if (!vu_fd_watch->processing) { - QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); - g_free(vu_fd_watch); - } - } - } - while (server->processing_msg) { if (server->ioc->read_coroutine) { server->ioc->read_coroutine =3D NULL; @@ -73,6 +58,10 @@ static void close_client(VuServer *server) } =20 vu_deinit(&server->vu_dev); + + /* vu_deinit() should have called remove_watch() */ + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); + object_unref(OBJECT(sioc)); object_unref(OBJECT(server->ioc)); } --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366417; cv=none; d=zohomail.com; s=zohoarc; b=bmF66pi9M9OQk7CLVnjNj/d9nw6qFX9u1ff2SnOl0aQGc6O4LNVrBw24s/Vlg9V9cbbvt63Zs7CCHxqy6lNtCIp/Eh/mPiG93wwr8/M69ULlNXE4owIPyQWRG1XrbHpEAvVOdtVa0pPH3A9VsQg8rC1IUbrfU0p3FQVgUXjHikU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366417; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pDPK/gDxvSqd+AKC4ACRi9LgzC2OcfLuz1FIto+Zozc=; b=AMi5h4aNI8DsCJv4WV1YHAgu9ksaC05ihCIkFhn4f4sE4/rVTVv+OBDiRb1GV/pKniffnDPqzFrVBSf5rApR5KaPBqP8MwAv6t7P45KzQIPfqvJdljNrXNNaJpY7NSmj92SBA0yubf7oCKEFXbJ4a5S4plJjv259GnajwRd46m8= 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 16033664171601005.0419677812997; Thu, 22 Oct 2020 04:33:37 -0700 (PDT) Received: from localhost ([::1]:36814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYqd-0002GW-Us for importer@patchew.org; Thu, 22 Oct 2020 07:33:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYly-00059Y-P8 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46141) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYlx-00055V-1D for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-475-TXtnzSfIMNul0suezRU_iw-1; Thu, 22 Oct 2020 07:28:40 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7F2E835B76; Thu, 22 Oct 2020 11:28:38 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88A6C19C78; Thu, 22 Oct 2020 11:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pDPK/gDxvSqd+AKC4ACRi9LgzC2OcfLuz1FIto+Zozc=; b=HBJuS+/yTFELrIETBgvJuvOHKER7usZfj3q4O85Qk+7sX8pErsvzlsD+AB7BvdzHZV9OnC wEQj3ZxrPtBH/siGaC2y4rQBcl0PPlKyG0xtU1h2o9u8v0DbgYxTXpbyHApQaLU16ostm3 tvC1IZ8g0e6yfxqIHpjDO9P3ph/+T4w= X-MC-Unique: TXtnzSfIMNul0suezRU_iw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 11/28] block/export: consolidate request structs into VuBlockReq Date: Thu, 22 Oct 2020 12:27:09 +0100 Message-Id: <20201022112726.736757-12-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Only one struct is needed per request. Drop req_data and the separate VuBlockReq instance. Instead let vu_queue_pop() allocate everything at once. This fixes the req_data memory leak in vu_block_virtio_process_req(). Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-6-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- block/export/vhost-user-blk-server.c | 68 +++++++++------------------- 1 file changed, 21 insertions(+), 47 deletions(-) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index 2ba1613cc9..d227b468d8 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -25,7 +25,7 @@ struct virtio_blk_inhdr { }; =20 typedef struct VuBlockReq { - VuVirtqElement *elem; + VuVirtqElement elem; int64_t sector_num; size_t size; struct virtio_blk_inhdr *in; @@ -39,14 +39,10 @@ static void vu_block_req_complete(VuBlockReq *req) VuDev *vu_dev =3D &req->server->vu_dev; =20 /* IO size with 1 extra status byte */ - vu_queue_push(vu_dev, req->vq, req->elem, req->size + 1); + vu_queue_push(vu_dev, req->vq, &req->elem, req->size + 1); vu_queue_notify(vu_dev, req->vq); =20 - if (req->elem) { - free(req->elem); - } - - g_free(req); + free(req); } =20 static VuBlockDev *get_vu_block_device_by_server(VuServer *server) @@ -89,20 +85,12 @@ static void coroutine_fn vu_block_flush(VuBlockReq *req) blk_co_flush(backend); } =20 -struct req_data { - VuServer *server; - VuVirtq *vq; - VuVirtqElement *elem; -}; - static void coroutine_fn vu_block_virtio_process_req(void *opaque) { - struct req_data *data =3D opaque; - VuServer *server =3D data->server; - VuVirtq *vq =3D data->vq; - VuVirtqElement *elem =3D data->elem; + VuBlockReq *req =3D opaque; + VuServer *server =3D req->server; + VuVirtqElement *elem =3D &req->elem; uint32_t type; - VuBlockReq *req; =20 VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); BlockBackend *backend =3D vdev_blk->backend; @@ -111,18 +99,13 @@ static void coroutine_fn vu_block_virtio_process_req(v= oid *opaque) struct iovec *out_iov =3D elem->out_sg; unsigned in_num =3D elem->in_num; unsigned out_num =3D elem->out_num; + /* refer to hw/block/virtio_blk.c */ if (elem->out_num < 1 || elem->in_num < 1) { error_report("virtio-blk request missing headers"); - free(elem); - return; + goto err; } =20 - req =3D g_new0(VuBlockReq, 1); - req->server =3D server; - req->vq =3D vq; - req->elem =3D elem; - if (unlikely(iov_to_buf(out_iov, out_num, 0, &req->out, sizeof(req->out)) !=3D sizeof(req->out))) { error_report("virtio-blk request outhdr too short"); @@ -202,36 +185,27 @@ static void coroutine_fn vu_block_virtio_process_req(= void *opaque) =20 err: free(elem); - g_free(req); - return; } =20 static void vu_block_process_vq(VuDev *vu_dev, int idx) { - VuServer *server; - VuVirtq *vq; - struct req_data *req_data; + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + VuVirtq *vq =3D vu_get_queue(vu_dev, idx); =20 - server =3D container_of(vu_dev, VuServer, vu_dev); - assert(server); - - vq =3D vu_get_queue(vu_dev, idx); - assert(vq); - VuVirtqElement *elem; while (1) { - elem =3D vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + - sizeof(VuBlockReq)); - if (elem) { - req_data =3D g_new0(struct req_data, 1); - req_data->server =3D server; - req_data->vq =3D vq; - req_data->elem =3D elem; - Coroutine *co =3D qemu_coroutine_create(vu_block_virtio_proces= s_req, - req_data); - aio_co_enter(server->ioc->ctx, co); - } else { + VuBlockReq *req; + + req =3D vu_queue_pop(vu_dev, vq, sizeof(VuBlockReq)); + if (!req) { break; } + + req->server =3D server; + req->vq =3D vq; + + Coroutine *co =3D + qemu_coroutine_create(vu_block_virtio_process_req, req); + qemu_coroutine_enter(co); } } =20 --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603367087; cv=none; d=zohomail.com; s=zohoarc; b=KuNOBalIJSKHvTmUy537DHqFKd5uZZXmsfZyHAtKpdHfsshMgWggJs+uNZBFvpQCwUYdHXVAvVWacvO+djhVbFivzEBp2J3yZq8phlgFfpGlKEFousMSTf1G7onQQXkt/Obf7iuDH4Dm2OVIlone/OiGGDikyrWVSH7xi+yIR0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603367087; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qMFZnj3WKL2Y2KPQIX3botLUm8jWqyo4+G2IcDvsub0=; b=VUPjpbsLzJTMrBgHHbVdeDR+q0xMkk4SIVOo0VB4VZWw99spZ5ZyvwK6SU3PlZt5JqXHpQqxIMoYPdsRgkzPG3g87wGT6E3LT11WrIapoVdTPKIgHpO8nJKY2KTCIVCGJe8HiyRpcqmaL4Enb9cwi11FiLbButLvyidK54J2Vik= 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 1603367087905876.7956503233981; Thu, 22 Oct 2020 04:44:47 -0700 (PDT) Received: from localhost ([::1]:41308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZ1S-0007UW-MV for importer@patchew.org; Thu, 22 Oct 2020 07:44:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYm2-0005Ib-3l for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56111) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYm0-00055t-C6 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-mMSKDRgSNTOgAGtldZThGQ-1; Thu, 22 Oct 2020 07:28:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D44FE835B91; Thu, 22 Oct 2020 11:28:43 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 473AE5D9F7; Thu, 22 Oct 2020 11:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366127; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qMFZnj3WKL2Y2KPQIX3botLUm8jWqyo4+G2IcDvsub0=; b=Bcx4U3N9uVkzm6P1hLDoH8Axde7mD2kqX88IbT1yfDWhTgIjm9hQ1GWpXXNAoZMxihcbFx DtU24vckDq+bR6aezxUl591/GE4t38mQcyaOHc5auD/8fArcIgGhYfNfUgy+mRe7UOHlDn bZbwGdNXtpjcODr5eKyRTH9fmWAFeIc= X-MC-Unique: mMSKDRgSNTOgAGtldZThGQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 12/28] util/vhost-user-server: drop unused DevicePanicNotifier Date: Thu, 22 Oct 2020 12:27:10 +0100 Message-Id: <20201022112726.736757-13-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The device panic notifier callback is not used. Drop it. Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-7-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.h | 3 --- block/export/vhost-user-blk-server.c | 3 +-- util/vhost-user-server.c | 6 ------ 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h index 5232f96718..92177fc911 100644 --- a/util/vhost-user-server.h +++ b/util/vhost-user-server.h @@ -29,12 +29,10 @@ typedef struct VuFdWatch { } VuFdWatch; =20 typedef struct VuServer VuServer; -typedef void DevicePanicNotifierFn(VuServer *server); =20 struct VuServer { QIONetListener *listener; AioContext *ctx; - DevicePanicNotifierFn *device_panic_notifier; int max_queues; const VuDevIface *vu_iface; VuDev vu_dev; @@ -54,7 +52,6 @@ bool vhost_user_server_start(VuServer *server, SocketAddress *unix_socket, AioContext *ctx, uint16_t max_queues, - DevicePanicNotifierFn *device_panic_notifier, const VuDevIface *vu_iface, Error **errp); =20 diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index d227b468d8..c8fa4ecba9 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -439,8 +439,7 @@ static void vhost_user_blk_server_start(VuBlockDev *vu_= block_device, ctx =3D bdrv_get_aio_context(blk_bs(vu_block_device->backend)); =20 if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, - VHOST_USER_BLK_MAX_QUEUES, - NULL, &vu_block_iface, + VHOST_USER_BLK_MAX_QUEUES, &vu_block_ifac= e, errp)) { goto error; } diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 6efe2279fd..73a1667b54 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -81,10 +81,6 @@ static void panic_cb(VuDev *vu_dev, const char *buf) close_client(server); } =20 - if (server->device_panic_notifier) { - server->device_panic_notifier(server); - } - /* * Set the callback function for network listener so another * vhost-user client can connect to this server @@ -385,7 +381,6 @@ bool vhost_user_server_start(VuServer *server, SocketAddress *socket_addr, AioContext *ctx, uint16_t max_queues, - DevicePanicNotifierFn *device_panic_notifier, const VuDevIface *vu_iface, Error **errp) { @@ -402,7 +397,6 @@ bool vhost_user_server_start(VuServer *server, .vu_iface =3D vu_iface, .max_queues =3D max_queues, .ctx =3D ctx, - .device_panic_notifier =3D device_panic_notifier, }; =20 qio_net_listener_set_name(server->listener, "vhost-user-backend-listen= er"); --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366549; cv=none; d=zohomail.com; s=zohoarc; b=Kb6o4ug7yOINJVn1fNIs/FvTfSy7+EQPt2tz8Yp7+c7IQYrW8/QZr5a2NKHCWqrXN4NLJ1sPY9a/k1dEPC9JdrPkChCe4TrQNQ7H9c6BO6+Sq76V62letb9H9xY3mMiccLbmoVF7pjmpTb6LRGkMvl0sFHz1/HX0qSrTRmnrXQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366549; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oTHycSRmLA65HL97g9avNjqsTxBZTSW/qVBAreWcHcU=; b=hlfQuCIF3UsdY10NRvw/+HtK7XdiNE/0PHtu/PPCvZh5hV14HFFOOPabh7qtRQbo/KK/tW6xDBy8xS/o6nGrpH8VXEETBvmPBTsnoE1WYW3O5QB0BlL33VU3fLHXywA0tBQUKNSK8zene+mJSBf8g+GWRcvxA6VihODHXi/VwqI= 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 1603366549716878.5153792879556; Thu, 22 Oct 2020 04:35:49 -0700 (PDT) Received: from localhost ([::1]:44862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYsm-0005Yj-IQ for importer@patchew.org; Thu, 22 Oct 2020 07:35:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYm3-0005NV-Ub for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23072) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYm1-00055z-94 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-254-65L-OqsOOwGgFKrugCov0A-1; Thu, 22 Oct 2020 07:28:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 660D164091; Thu, 22 Oct 2020 11:28:45 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0647D5D9F7; Thu, 22 Oct 2020 11:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oTHycSRmLA65HL97g9avNjqsTxBZTSW/qVBAreWcHcU=; b=IDA7A/SxG5Up0I/3j5rAoq1FKifsOFdlDCHK7u1G49KFWiFU3XQVDoAkAYTwg77M/KsoZy IEIPa2jaQzKvlVQL5kwtXJI3KiDw586p4veHJXauURV7YcR2eOizA+uvu7+rrqeA6g+iSL Q8E1RCJajnrS70afhmhIJv/LenynRmE= X-MC-Unique: 65L-OqsOOwGgFKrugCov0A-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 13/28] util/vhost-user-server: fix memory leak in vu_message_read() Date: Thu, 22 Oct 2020 12:27:11 +0100 Message-Id: <20201022112726.736757-14-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" fds[] is leaked when qio_channel_readv_full() fails. Use vmsg->fds[] instead of keeping a local fds[] array. Then we can reuse goto fail to clean up fds. vmsg->fd_num must be zeroed before the loop to make this safe. Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-8-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 50 ++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 73a1667b54..a7b7a9897f 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -100,21 +100,11 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUser= Msg *vmsg) }; int rc, read_bytes =3D 0; Error *local_err =3D NULL; - /* - * Store fds/nfds returned from qio_channel_readv_full into - * temporary variables. - * - * VhostUserMsg is a packed structure, gcc will complain about passing - * pointer to a packed structure member if we pass &VhostUserMsg.fd_num - * and &VhostUserMsg.fds directly when calling qio_channel_readv_full, - * thus two temporary variables nfds and fds are used here. - */ - size_t nfds =3D 0, nfds_t =3D 0; const size_t max_fds =3D G_N_ELEMENTS(vmsg->fds); - int *fds_t =3D NULL; VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); QIOChannel *ioc =3D server->ioc; =20 + vmsg->fd_num =3D 0; if (!ioc) { error_report_err(local_err); goto fail; @@ -122,41 +112,47 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUser= Msg *vmsg) =20 assert(qemu_in_coroutine()); do { + size_t nfds =3D 0; + int *fds =3D NULL; + /* * qio_channel_readv_full may have short reads, keeping calling it * until getting VHOST_USER_HDR_SIZE or 0 bytes in total */ - rc =3D qio_channel_readv_full(ioc, &iov, 1, &fds_t, &nfds_t, &loca= l_err); + rc =3D qio_channel_readv_full(ioc, &iov, 1, &fds, &nfds, &local_er= r); if (rc < 0) { if (rc =3D=3D QIO_CHANNEL_ERR_BLOCK) { + assert(local_err =3D=3D NULL); qio_channel_yield(ioc, G_IO_IN); continue; } else { error_report_err(local_err); - return false; + goto fail; } } - read_bytes +=3D rc; - if (nfds_t > 0) { - if (nfds + nfds_t > max_fds) { + + if (nfds > 0) { + if (vmsg->fd_num + nfds > max_fds) { error_report("A maximum of %zu fds are allowed, " "however got %zu fds now", - max_fds, nfds + nfds_t); + max_fds, vmsg->fd_num + nfds); + g_free(fds); goto fail; } - memcpy(vmsg->fds + nfds, fds_t, - nfds_t *sizeof(vmsg->fds[0])); - nfds +=3D nfds_t; - g_free(fds_t); + memcpy(vmsg->fds + vmsg->fd_num, fds, nfds * sizeof(vmsg->fds[= 0])); + vmsg->fd_num +=3D nfds; + g_free(fds); } - if (read_bytes =3D=3D VHOST_USER_HDR_SIZE || rc =3D=3D 0) { - break; + + if (rc =3D=3D 0) { /* socket closed */ + goto fail; } - iov.iov_base =3D (char *)vmsg + read_bytes; - iov.iov_len =3D VHOST_USER_HDR_SIZE - read_bytes; - } while (true); =20 - vmsg->fd_num =3D nfds; + iov.iov_base +=3D rc; + iov.iov_len -=3D rc; + read_bytes +=3D rc; + } while (read_bytes !=3D VHOST_USER_HDR_SIZE); + /* qio_channel_readv_full will make socket fds blocking, unblock them = */ vmsg_unblock_fds(vmsg); if (vmsg->size > sizeof(vmsg->payload)) { --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603367281; cv=none; d=zohomail.com; s=zohoarc; b=k2WbPwrZBQ5sxEy+z6BAWCQvqqKx2d3ubI6VuelA89u9HGL2VQUyW88jAtyec+b0lJKsQhF7jCRVx8wlOLQzTTEAozSc/C5OEhjjanrzvEN78lrU4hFGWKWM6tLmhTvv8e/tFjml9FJdhReWarNgAcRKtWBHSmUsfgLR41MrI88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603367281; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0Ysu0k6E3/S/MI8iUGDc9MJPGsA6fQ6O6sEzKj/Di4A=; b=QwJ4rH3/72hb60BZto1MVqc5sZ4TN4y13pBPlkunU1kK10+92FyMimABAsCVZKNBpzzV990H4oqIGmuma2berLT2TqvJSz0Js+QOWaBWkxBEUjCWTv1wvO80oSptRNZdLPUn4rVt3l2ybrNKPAvqqwbCSHkZePNxfPgZXuOY9eU= 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 1603367281402430.569847706524; Thu, 22 Oct 2020 04:48:01 -0700 (PDT) Received: from localhost ([::1]:49800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZ4a-0002iL-5D for importer@patchew.org; Thu, 22 Oct 2020 07:48:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYm4-0005QM-TO for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37241) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYm3-00056G-7J for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:28:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-573-JCCiFs6nNYSrpSzpJs43Ww-1; Thu, 22 Oct 2020 07:28:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 48E241009E22; Thu, 22 Oct 2020 11:28:47 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92B445D9F7; Thu, 22 Oct 2020 11:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0Ysu0k6E3/S/MI8iUGDc9MJPGsA6fQ6O6sEzKj/Di4A=; b=LJ6CrcRh9HASLbG4lQx6W4tkPTPbN4Z71exlGq6lhNY1i/yHXcN+DU4jqX68QGwpWtaLnT O5ywQ0ymUddMRDCu6hfLCjxCUrliwSR3YJAaJh0zlldHREv+Hyg63Gejsi3lJBAu6Xy2wm HTbZYDcWF+9DQYArkaslRk+j2j20ano= X-MC-Unique: JCCiFs6nNYSrpSzpJs43Ww-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 14/28] util/vhost-user-server: check EOF when reading payload Date: Thu, 22 Oct 2020 12:27:12 +0100 Message-Id: <20201022112726.736757-15-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Unexpected EOF is an error that must be reported. Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-9-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index a7b7a9897f..981908fef0 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -169,8 +169,10 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserM= sg *vmsg) }; if (vmsg->size) { rc =3D qio_channel_readv_all_eof(ioc, &iov_payload, 1, &local_err); - if (rc =3D=3D -1) { - error_report_err(local_err); + if (rc !=3D 1) { + if (local_err) { + error_report_err(local_err); + } goto fail; } } --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366575; cv=none; d=zohomail.com; s=zohoarc; b=Ylk8o8norroAkIs02Y4FxaQXRi1yaSwoaoSUoLZ072xkbQ0I3L1i4eXQagqJ2eI6jLPPUT+XsHhzY6mHMUXm1tozfGs+H7lVZwBMPn7YSodGRdB0syxndOzAWMJnQR7IigabBjLWdY8bsVc/VDk1dfJua3ARaBiiMBZZNQdtaiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366575; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+vxy5x5xecSmCI+F9Uy3S/1WYLg4+56Aq97tns2zofI=; b=Zgx6ux1Bm07HsDFWeC2e8lhKHDKcHJuxpupq+9/uyBiQrooUL/hbfLbwzMCWwCYoKzSac5scQTzKgdE5CY7mBRVhp3MM4q7h8a3yZvAQ8JmIyZ87sleLbYsPRTgRvnG+6Z9EAwC2JFg+R+/dR30etyHJD9iv84kXaJtjVonHb/8= 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 1603366575787377.22719059195754; Thu, 22 Oct 2020 04:36:15 -0700 (PDT) Received: from localhost ([::1]:46580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYtC-0006KI-HZ for importer@patchew.org; Thu, 22 Oct 2020 07:36:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmN-0005p4-Lc for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23359) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmJ-00057I-2o for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:11 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-375-MuMzkl43Npa1GOIcAEt12w-1; Thu, 22 Oct 2020 07:28:57 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47F85804B72; Thu, 22 Oct 2020 11:28:56 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 115E86115F; Thu, 22 Oct 2020 11:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+vxy5x5xecSmCI+F9Uy3S/1WYLg4+56Aq97tns2zofI=; b=G0bmX+OU9kN77jthjYxz4+ENfzUccvmcHEXH59uNxOvFQJxjqNE26uJhqg2gJXtGGm6S3q C7JPqrZ87UivvrPjtIzQZvLB2xLzIz9dPvnd/jeaZ/ueO5AXa/zCWFT4csw4eemD0X4hxE YioTrjLhbhQmBjz+yl7RvO1R6fZfSPc= X-MC-Unique: MuMzkl43Npa1GOIcAEt12w-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 15/28] util/vhost-user-server: rework vu_client_trip() coroutine lifecycle Date: Thu, 22 Oct 2020 12:27:13 +0100 Message-Id: <20201022112726.736757-16-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The vu_client_trip() coroutine is leaked during AioContext switching. It is also unsafe to destroy the vu_dev in panic_cb() since its callers still access it in some cases. Rework the lifecycle to solve these safety issues. Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-10-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- util/vhost-user-server.h | 29 ++-- block/export/vhost-user-blk-server.c | 9 +- util/vhost-user-server.c | 245 +++++++++++++++------------ 3 files changed, 155 insertions(+), 128 deletions(-) diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h index 92177fc911..0da4c2cc4c 100644 --- a/util/vhost-user-server.h +++ b/util/vhost-user-server.h @@ -19,34 +19,36 @@ #include "qapi/error.h" #include "standard-headers/linux/virtio_blk.h" =20 +/* A kick fd that we monitor on behalf of libvhost-user */ typedef struct VuFdWatch { VuDev *vu_dev; int fd; /*kick fd*/ void *pvt; vu_watch_cb cb; - bool processing; QTAILQ_ENTRY(VuFdWatch) next; } VuFdWatch; =20 -typedef struct VuServer VuServer; - -struct VuServer { +/** + * VuServer: + * A vhost-user server instance with user-defined VuDevIface callbacks. + * Vhost-user device backends can be implemented using VuServer. VuDevIface + * callbacks and virtqueue kicks run in the given AioContext. + */ +typedef struct { QIONetListener *listener; + QEMUBH *restart_listener_bh; AioContext *ctx; int max_queues; const VuDevIface *vu_iface; + + /* Protected by ctx lock */ VuDev vu_dev; QIOChannel *ioc; /* The I/O channel with the client */ QIOChannelSocket *sioc; /* The underlying data channel with the client= */ - /* IOChannel for fd provided via VHOST_USER_SET_SLAVE_REQ_FD */ - QIOChannel *ioc_slave; - QIOChannelSocket *sioc_slave; - Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ QTAILQ_HEAD(, VuFdWatch) vu_fd_watches; - /* restart coroutine co_trip if AIOContext is changed */ - bool aio_context_changed; - bool processing_msg; -}; + + Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ +} VuServer; =20 bool vhost_user_server_start(VuServer *server, SocketAddress *unix_socket, @@ -57,6 +59,7 @@ bool vhost_user_server_start(VuServer *server, =20 void vhost_user_server_stop(VuServer *server); =20 -void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx); +void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ct= x); +void vhost_user_server_detach_aio_context(VuServer *server); =20 #endif /* VHOST_USER_SERVER_H */ diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index c8fa4ecba9..4d35232bf3 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -313,18 +313,13 @@ static const VuDevIface vu_block_iface =3D { static void blk_aio_attached(AioContext *ctx, void *opaque) { VuBlockDev *vub_dev =3D opaque; - aio_context_acquire(ctx); - vhost_user_server_set_aio_context(&vub_dev->vu_server, ctx); - aio_context_release(ctx); + vhost_user_server_attach_aio_context(&vub_dev->vu_server, ctx); } =20 static void blk_aio_detach(void *opaque) { VuBlockDev *vub_dev =3D opaque; - AioContext *ctx =3D vub_dev->vu_server.ctx; - aio_context_acquire(ctx); - vhost_user_server_set_aio_context(&vub_dev->vu_server, NULL); - aio_context_release(ctx); + vhost_user_server_detach_aio_context(&vub_dev->vu_server); } =20 static void diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 981908fef0..c448800e58 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -9,8 +9,50 @@ */ #include "qemu/osdep.h" #include "qemu/main-loop.h" +#include "block/aio-wait.h" #include "vhost-user-server.h" =20 +/* + * Theory of operation: + * + * VuServer is started and stopped by vhost_user_server_start() and + * vhost_user_server_stop() from the main loop thread. Starting the server + * opens a vhost-user UNIX domain socket and listens for incoming connecti= ons. + * Only one connection is allowed at a time. + * + * The connection is handled by the vu_client_trip() coroutine in the + * VuServer->ctx AioContext. The coroutine consists of a vu_dispatch() loop + * where libvhost-user calls vu_message_read() to receive the next vhost-u= ser + * protocol messages over the UNIX domain socket. + * + * When virtqueues are set up libvhost-user calls set_watch() to monitor k= ick + * fds. These fds are also handled in the VuServer->ctx AioContext. + * + * Both vu_client_trip() and kick fd monitoring can be stopped by shutting= down + * the socket connection. Shutting down the socket connection causes + * vu_message_read() to fail since no more data can be received from the s= ocket. + * After vu_dispatch() fails, vu_client_trip() calls vu_deinit() to stop + * libvhost-user before terminating the coroutine. vu_deinit() calls + * remove_watch() to stop monitoring kick fds and this stops virtqueue + * processing. + * + * When vu_client_trip() has finished cleaning up it schedules a BH in the= main + * loop thread to accept the next client connection. + * + * When libvhost-user detects an error it calls panic_cb() and sets the + * dev->broken flag. Both vu_client_trip() and kick fd processing stop when + * the dev->broken flag is set. + * + * It is possible to switch AioContexts using + * vhost_user_server_detach_aio_context() and + * vhost_user_server_attach_aio_context(). They stop monitoring fds in the= old + * AioContext and resume monitoring in the new AioContext. The vu_client_t= rip() + * coroutine remains in a yielded state during the switch. This is made + * possible by QIOChannel's support for spurious coroutine re-entry in + * qio_channel_yield(). The coroutine will restart I/O when re-entered fro= m the + * new AioContext. + */ + static void vmsg_close_fds(VhostUserMsg *vmsg) { int i; @@ -27,68 +69,9 @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) } } =20 -static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, - gpointer opaque); - -static void close_client(VuServer *server) -{ - /* - * Before closing the client - * - * 1. Let vu_client_trip stop processing new vhost-user msg - * - * 2. remove kick_handler - * - * 3. wait for the kick handler to be finished - * - * 4. wait for the current vhost-user msg to be finished processing - */ - - QIOChannelSocket *sioc =3D server->sioc; - /* When this is set vu_client_trip will stop new processing vhost-user= message */ - server->sioc =3D NULL; - - while (server->processing_msg) { - if (server->ioc->read_coroutine) { - server->ioc->read_coroutine =3D NULL; - qio_channel_set_aio_fd_handler(server->ioc, server->ioc->ctx, = NULL, - NULL, server->ioc); - server->processing_msg =3D false; - } - } - - vu_deinit(&server->vu_dev); - - /* vu_deinit() should have called remove_watch() */ - assert(QTAILQ_EMPTY(&server->vu_fd_watches)); - - object_unref(OBJECT(sioc)); - object_unref(OBJECT(server->ioc)); -} - static void panic_cb(VuDev *vu_dev, const char *buf) { - VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); - - /* avoid while loop in close_client */ - server->processing_msg =3D false; - - if (buf) { - error_report("vu_panic: %s", buf); - } - - if (server->sioc) { - close_client(server); - } - - /* - * Set the callback function for network listener so another - * vhost-user client can connect to this server - */ - qio_net_listener_set_client_func(server->listener, - vu_accept, - server, - NULL); + error_report("vu_panic: %s", buf); } =20 static bool coroutine_fn @@ -185,28 +168,31 @@ fail: return false; } =20 - -static void vu_client_start(VuServer *server); static coroutine_fn void vu_client_trip(void *opaque) { VuServer *server =3D opaque; + VuDev *vu_dev =3D &server->vu_dev; =20 - while (!server->aio_context_changed && server->sioc) { - server->processing_msg =3D true; - vu_dispatch(&server->vu_dev); - server->processing_msg =3D false; + while (!vu_dev->broken && vu_dispatch(vu_dev)) { + /* Keep running */ } =20 - if (server->aio_context_changed && server->sioc) { - server->aio_context_changed =3D false; - vu_client_start(server); - } -} + vu_deinit(vu_dev); + + /* vu_deinit() should have called remove_watch() */ + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); + + object_unref(OBJECT(server->sioc)); + server->sioc =3D NULL; =20 -static void vu_client_start(VuServer *server) -{ - server->co_trip =3D qemu_coroutine_create(vu_client_trip, server); - aio_co_enter(server->ctx, server->co_trip); + object_unref(OBJECT(server->ioc)); + server->ioc =3D NULL; + + server->co_trip =3D NULL; + if (server->restart_listener_bh) { + qemu_bh_schedule(server->restart_listener_bh); + } + aio_wait_kick(); } =20 /* @@ -219,12 +205,18 @@ static void vu_client_start(VuServer *server) static void kick_handler(void *opaque) { VuFdWatch *vu_fd_watch =3D opaque; - vu_fd_watch->processing =3D true; - vu_fd_watch->cb(vu_fd_watch->vu_dev, 0, vu_fd_watch->pvt); - vu_fd_watch->processing =3D false; + VuDev *vu_dev =3D vu_fd_watch->vu_dev; + + vu_fd_watch->cb(vu_dev, 0, vu_fd_watch->pvt); + + /* Stop vu_client_trip() if an error occurred in vu_fd_watch->cb() */ + if (vu_dev->broken) { + VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); + + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + } } =20 - static VuFdWatch *find_vu_fd_watch(VuServer *server, int fd) { =20 @@ -319,62 +311,95 @@ static void vu_accept(QIONetListener *listener, QIOCh= annelSocket *sioc, qio_channel_set_name(QIO_CHANNEL(sioc), "vhost-user client"); server->ioc =3D QIO_CHANNEL(sioc); object_ref(OBJECT(server->ioc)); - qio_channel_attach_aio_context(server->ioc, server->ctx); + + /* TODO vu_message_write() spins if non-blocking! */ qio_channel_set_blocking(server->ioc, false, NULL); - vu_client_start(server); + + server->co_trip =3D qemu_coroutine_create(vu_client_trip, server); + + aio_context_acquire(server->ctx); + vhost_user_server_attach_aio_context(server, server->ctx); + aio_context_release(server->ctx); } =20 - void vhost_user_server_stop(VuServer *server) { + aio_context_acquire(server->ctx); + + qemu_bh_delete(server->restart_listener_bh); + server->restart_listener_bh =3D NULL; + if (server->sioc) { - close_client(server); + VuFdWatch *vu_fd_watch; + + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, + NULL, NULL, NULL, vu_fd_watch); + } + + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + + AIO_WAIT_WHILE(server->ctx, server->co_trip); } =20 + aio_context_release(server->ctx); + if (server->listener) { qio_net_listener_disconnect(server->listener); object_unref(OBJECT(server->listener)); } +} + +/* + * Allow the next client to connect to the server. Called from a BH in the= main + * loop. + */ +static void restart_listener_bh(void *opaque) +{ + VuServer *server =3D opaque; =20 + qio_net_listener_set_client_func(server->listener, vu_accept, server, + NULL); } =20 -void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx) +/* Called with ctx acquired */ +void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ct= x) { - VuFdWatch *vu_fd_watch, *next; - void *opaque =3D NULL; - IOHandler *io_read =3D NULL; - bool attach; + VuFdWatch *vu_fd_watch; =20 - server->ctx =3D ctx ? ctx : qemu_get_aio_context(); + server->ctx =3D ctx; =20 if (!server->sioc) { - /* not yet serving any client*/ return; } =20 - if (ctx) { - qio_channel_attach_aio_context(server->ioc, ctx); - server->aio_context_changed =3D true; - io_read =3D kick_handler; - attach =3D true; - } else { + qio_channel_attach_aio_context(server->ioc, ctx); + + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { + aio_set_fd_handler(ctx, vu_fd_watch->fd, true, kick_handler, NULL, + NULL, vu_fd_watch); + } + + aio_co_schedule(ctx, server->co_trip); +} + +/* Called with server->ctx acquired */ +void vhost_user_server_detach_aio_context(VuServer *server) +{ + if (server->sioc) { + VuFdWatch *vu_fd_watch; + + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, + NULL, NULL, NULL, vu_fd_watch); + } + qio_channel_detach_aio_context(server->ioc); - /* server->ioc->ctx keeps the old AioConext */ - ctx =3D server->ioc->ctx; - attach =3D false; } =20 - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { - if (vu_fd_watch->cb) { - opaque =3D attach ? vu_fd_watch : NULL; - aio_set_fd_handler(ctx, vu_fd_watch->fd, true, - io_read, NULL, NULL, - opaque); - } - } + server->ctx =3D NULL; } =20 - bool vhost_user_server_start(VuServer *server, SocketAddress *socket_addr, AioContext *ctx, @@ -382,6 +407,7 @@ bool vhost_user_server_start(VuServer *server, const VuDevIface *vu_iface, Error **errp) { + QEMUBH *bh; QIONetListener *listener =3D qio_net_listener_new(); if (qio_net_listener_open_sync(listener, socket_addr, 1, errp) < 0) { @@ -389,9 +415,12 @@ bool vhost_user_server_start(VuServer *server, return false; } =20 + bh =3D qemu_bh_new(restart_listener_bh, server); + /* zero out unspecified fields */ *server =3D (VuServer) { .listener =3D listener, + .restart_listener_bh =3D bh, .vu_iface =3D vu_iface, .max_queues =3D max_queues, .ctx =3D ctx, --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366725; cv=none; d=zohomail.com; s=zohoarc; b=aFpv/yP2mdj+TmRSoFMPIy6fmEjv9H1KVA0zon8QrkqPRO4AKwADBvz2C0mlXHtjBVqwRXLXm7+z/n5kq4hF23H7rbYVkjKJNfLuxS4qPrksg9tHvqczv3U9cDoj1bn6Tu2a2qm+V/3+d4cF7EoiRTeFaSpM1zVWu3etBaNUrL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366725; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=i9BqQWbn6bBTqDvWG1EPwIseH5oZZ8P+u+lBuBOOTsM=; b=Z8AepUMaf6Wk/uLZB9Z8nvb/qpNC+0VIK3WBitChTmtO+VeGu1lmFQtOT+2XeYN5LvFiA5w36BpK+TEzzMN3ufLP5uop7GZCjhNMqtjNHacqnKlkPd7YWOBQboevsWq9Eoewu7EkDlPvCGY3syTSH95QEGBaaw0uo0etJ2CM2jo= 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 1603366725881196.17642050371205; Thu, 22 Oct 2020 04:38:45 -0700 (PDT) Received: from localhost ([::1]:55112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYvc-0001OR-Lo for importer@patchew.org; Thu, 22 Oct 2020 07:38:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmP-0005pb-Ks for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25039) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmK-00057T-Sd for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-119-JAAizruJPPatdnAElp74GQ-1; Thu, 22 Oct 2020 07:29:05 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 989F81019631; Thu, 22 Oct 2020 11:29:03 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id B433A1002397; Thu, 22 Oct 2020 11:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i9BqQWbn6bBTqDvWG1EPwIseH5oZZ8P+u+lBuBOOTsM=; b=acIK/xoLgdOj84Gk3fa4Ftl1y9gikGlhLoqPU3sIop8fS/sKETZYwM0Q0M96aQVK0c0i9M ZB0T9mV6PktBfZVnj5zYZGnvC5sWgwSJHxvtmSuQSLUCmuwEtJov7/zoNok8jOW1jLuHDO VcbtNYFUjlLitTkps15XLWsLak7w6jE= X-MC-Unique: JAAizruJPPatdnAElp74GQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 16/28] block/export: report flush errors Date: Thu, 22 Oct 2020 12:27:14 +0100 Message-Id: <20201022112726.736757-17-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Propagate the flush return value since errors are possible. Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-11-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- block/export/vhost-user-blk-server.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index 4d35232bf3..faefcfcaea 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -78,11 +78,11 @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct i= ovec *iov, return -EINVAL; } =20 -static void coroutine_fn vu_block_flush(VuBlockReq *req) +static int coroutine_fn vu_block_flush(VuBlockReq *req) { VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(req->server); BlockBackend *backend =3D vdev_blk->backend; - blk_co_flush(backend); + return blk_co_flush(backend); } =20 static void coroutine_fn vu_block_virtio_process_req(void *opaque) @@ -152,8 +152,11 @@ static void coroutine_fn vu_block_virtio_process_req(v= oid *opaque) break; } case VIRTIO_BLK_T_FLUSH: - vu_block_flush(req); - req->in->status =3D VIRTIO_BLK_S_OK; + if (vu_block_flush(req) =3D=3D 0) { + req->in->status =3D VIRTIO_BLK_S_OK; + } else { + req->in->status =3D VIRTIO_BLK_S_IOERR; + } break; case VIRTIO_BLK_T_GET_ID: { size_t size =3D MIN(iov_size(&elem->in_sg[0], in_num), --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603367486; cv=none; d=zohomail.com; s=zohoarc; b=HjFf/Z4NmbSz18andVHt2VfYaPKJ8EEWdGPUWX/LOou66z/qCP83kSrDFhH5+5l+3zfBOzdJt5W2ra6IKOCyk9CcZrtj3npqSkLzTFOqRzoTVl3vVPLRf3WqkBy5bEhehkt7LxYvhlo3S89f+DscRsUHWxA6JppHgBmylmyQ5AE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603367486; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ibHT/TSnMM6KTiECl4UXf3LGTVp7eVvYfL7olpM4XwA=; b=GuCBa0Cbgs7YiqgvVjYJz+FHf8oOsV47wF9WkQkgHiscXEXzckIRKiSK3t80QQhEym6K60S4Vp0bMVK+3y4fcGiZBOVc7RIlZsfAnr2a6s8dkNvLyrCCDbhKYKJpvBbbUb5mwA9rTfX9WJlv3MagQ/nUFEW/jMA0ZRcGKWs1Q0U= 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 1603367486847365.10173980080447; Thu, 22 Oct 2020 04:51:26 -0700 (PDT) Received: from localhost ([::1]:59910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZ7t-0006zE-Jq for importer@patchew.org; Thu, 22 Oct 2020 07:51:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmV-0005wj-Dc for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38575) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmS-00059H-H4 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-408-fqR1OMVuMNagUAwyYvYflg-1; Thu, 22 Oct 2020 07:29:11 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 13A4B10866C5; Thu, 22 Oct 2020 11:29:10 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46B7D5C22B; Thu, 22 Oct 2020 11:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ibHT/TSnMM6KTiECl4UXf3LGTVp7eVvYfL7olpM4XwA=; b=g1QWlbp7bz6k9IiCsk/yK5ioDcOgEgbLc/f5kr7W/nYb4C0Sd88oi3on6DhgKY51s5sYvN 2QHLfNX2q27wFeR24sl2tSIZMd9ivx2pnqVBlF0bxvWbVNuSuYrv6XtLXgSbVNm7Aw075a jMDPhgHVNNzGpWs8+eXmFydkDJZQztA= X-MC-Unique: fqR1OMVuMNagUAwyYvYflg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 17/28] block/export: convert vhost-user-blk server to block export API Date: Thu, 22 Oct 2020 12:27:15 +0100 Message-Id: <20201022112726.736757-18-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use the new QAPI block exports API instead of defining our own QOM objects. This is a large change because the lifecycle of VuBlockDev needs to follow BlockExportDriver. QOM properties are replaced by QAPI options objects. VuBlockDev is renamed VuBlkExport and contains a BlockExport field. Several fields can be dropped since BlockExport already has equivalents. The file names and meson build integration will be adjusted in a future patch. libvhost-user should probably be built as a static library that is linked into QEMU instead of as a .c file that results in duplicate compilation. The new command-line syntax is: $ qemu-storage-daemon \ --blockdev file,node-name=3Ddrive0,filename=3Dtest.img \ --export vhost-user-blk,node-name=3Ddrive0,id=3Dexport0,unix-socket= =3D/tmp/vhost-user-blk.sock Note that unix-socket is optional because we may wish to accept chardevs too in the future. Markus noted that supported address families are not explicit in the QAPI schema. It is unlikely that support for more address families will be added since file descriptor passing is required and few address families support it. If a new address family needs to be added, then the QAPI 'features' syntax can be used to advertize them. Signed-off-by: Stefan Hajnoczi Acked-by: Markus Armbruster Message-id: 20200924151549.913737-12-stefanha@redhat.com [Skip test on big-endian host architectures because this device doesn't support them yet (as already mentioned in a code comment). --Stefan] Signed-off-by: Stefan Hajnoczi --- qapi/block-export.json | 21 +- block/export/vhost-user-blk-server.h | 23 +- block/export/export.c | 6 + block/export/vhost-user-blk-server.c | 452 +++++++-------------------- util/vhost-user-server.c | 10 +- block/export/meson.build | 1 + block/meson.build | 1 - 7 files changed, 156 insertions(+), 358 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 65804834d9..a793e34af9 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -84,6 +84,21 @@ 'data': { '*name': 'str', '*description': 'str', '*bitmap': 'str' } } =20 +## +# @BlockExportOptionsVhostUserBlk: +# +# A vhost-user-blk block export. +# +# @addr: The vhost-user socket on which to listen. Both 'unix' and 'fd' +# SocketAddress types are supported. Passed fds must be UNIX domain +# sockets. +# @logical-block-size: Logical block size in bytes. Defaults to 512 bytes. +# +# Since: 5.2 +## +{ 'struct': 'BlockExportOptionsVhostUserBlk', + 'data': { 'addr': 'SocketAddress', '*logical-block-size': 'size' } } + ## # @NbdServerAddOptions: # @@ -180,11 +195,12 @@ # An enumeration of block export types # # @nbd: NBD export +# @vhost-user-blk: vhost-user-blk export (since 5.2) # # Since: 4.2 ## { 'enum': 'BlockExportType', - 'data': [ 'nbd' ] } + 'data': [ 'nbd', 'vhost-user-blk' ] } =20 ## # @BlockExportOptions: @@ -213,7 +229,8 @@ '*writethrough': 'bool' }, 'discriminator': 'type', 'data': { - 'nbd': 'BlockExportOptionsNbd' + 'nbd': 'BlockExportOptionsNbd', + 'vhost-user-blk': 'BlockExportOptionsVhostUserBlk' } } =20 ## diff --git a/block/export/vhost-user-blk-server.h b/block/export/vhost-user= -blk-server.h index f06f37c4c8..fcf46fc8a5 100644 --- a/block/export/vhost-user-blk-server.h +++ b/block/export/vhost-user-blk-server.h @@ -10,27 +10,10 @@ =20 #ifndef VHOST_USER_BLK_SERVER_H #define VHOST_USER_BLK_SERVER_H -#include "util/vhost-user-server.h" =20 -typedef struct VuBlockDev VuBlockDev; -#define TYPE_VHOST_USER_BLK_SERVER "vhost-user-blk-server" -#define VHOST_USER_BLK_SERVER(obj) \ - OBJECT_CHECK(VuBlockDev, obj, TYPE_VHOST_USER_BLK_SERVER) +#include "block/export.h" =20 -/* vhost user block device */ -struct VuBlockDev { - Object parent_obj; - char *node_name; - SocketAddress *addr; - AioContext *ctx; - VuServer vu_server; - bool running; - uint32_t blk_size; - BlockBackend *backend; - QIOChannelSocket *sioc; - QTAILQ_ENTRY(VuBlockDev) next; - struct virtio_blk_config blkcfg; - bool writable; -}; +/* For block/export/export.c */ +extern const BlockExportDriver blk_exp_vhost_user_blk; =20 #endif /* VHOST_USER_BLK_SERVER_H */ diff --git a/block/export/export.c b/block/export/export.c index f2c00d13bf..bd7cac241f 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -17,6 +17,9 @@ #include "sysemu/block-backend.h" #include "block/export.h" #include "block/nbd.h" +#if CONFIG_LINUX +#include "block/export/vhost-user-blk-server.h" +#endif #include "qapi/error.h" #include "qapi/qapi-commands-block-export.h" #include "qapi/qapi-events-block-export.h" @@ -24,6 +27,9 @@ =20 static const BlockExportDriver *blk_exp_drivers[] =3D { &blk_exp_nbd, +#if CONFIG_LINUX + &blk_exp_vhost_user_blk, +#endif }; =20 /* Only accessed from the main thread */ diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index faefcfcaea..3e5bd6caee 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -11,6 +11,9 @@ */ #include "qemu/osdep.h" #include "block/block.h" +#include "contrib/libvhost-user/libvhost-user.h" +#include "standard-headers/linux/virtio_blk.h" +#include "util/vhost-user-server.h" #include "vhost-user-blk-server.h" #include "qapi/error.h" #include "qom/object_interfaces.h" @@ -24,7 +27,7 @@ struct virtio_blk_inhdr { unsigned char status; }; =20 -typedef struct VuBlockReq { +typedef struct VuBlkReq { VuVirtqElement elem; int64_t sector_num; size_t size; @@ -32,9 +35,19 @@ typedef struct VuBlockReq { struct virtio_blk_outhdr out; VuServer *server; struct VuVirtq *vq; -} VuBlockReq; +} VuBlkReq; =20 -static void vu_block_req_complete(VuBlockReq *req) +/* vhost user block device */ +typedef struct { + BlockExport export; + VuServer vu_server; + uint32_t blk_size; + QIOChannelSocket *sioc; + struct virtio_blk_config blkcfg; + bool writable; +} VuBlkExport; + +static void vu_blk_req_complete(VuBlkReq *req) { VuDev *vu_dev =3D &req->server->vu_dev; =20 @@ -45,14 +58,9 @@ static void vu_block_req_complete(VuBlockReq *req) free(req); } =20 -static VuBlockDev *get_vu_block_device_by_server(VuServer *server) -{ - return container_of(server, VuBlockDev, vu_server); -} - static int coroutine_fn -vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov, - uint32_t iovcnt, uint32_t type) +vu_blk_discard_write_zeroes(BlockBackend *blk, struct iovec *iov, + uint32_t iovcnt, uint32_t type) { struct virtio_blk_discard_write_zeroes desc; ssize_t size =3D iov_to_buf(iov, iovcnt, 0, &desc, sizeof(desc)); @@ -61,16 +69,14 @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct i= ovec *iov, return -EINVAL; } =20 - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(req->server); uint64_t range[2] =3D { le64_to_cpu(desc.sector) << 9, le32_to_cpu(desc.num_sectors) << 9 }; if (type =3D=3D VIRTIO_BLK_T_DISCARD) { - if (blk_co_pdiscard(vdev_blk->backend, range[0], range[1]) =3D=3D = 0) { + if (blk_co_pdiscard(blk, range[0], range[1]) =3D=3D 0) { return 0; } } else if (type =3D=3D VIRTIO_BLK_T_WRITE_ZEROES) { - if (blk_co_pwrite_zeroes(vdev_blk->backend, - range[0], range[1], 0) =3D=3D 0) { + if (blk_co_pwrite_zeroes(blk, range[0], range[1], 0) =3D=3D 0) { return 0; } } @@ -78,22 +84,15 @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct i= ovec *iov, return -EINVAL; } =20 -static int coroutine_fn vu_block_flush(VuBlockReq *req) +static void coroutine_fn vu_blk_virtio_process_req(void *opaque) { - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(req->server); - BlockBackend *backend =3D vdev_blk->backend; - return blk_co_flush(backend); -} - -static void coroutine_fn vu_block_virtio_process_req(void *opaque) -{ - VuBlockReq *req =3D opaque; + VuBlkReq *req =3D opaque; VuServer *server =3D req->server; VuVirtqElement *elem =3D &req->elem; uint32_t type; =20 - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); - BlockBackend *backend =3D vdev_blk->backend; + VuBlkExport *vexp =3D container_of(server, VuBlkExport, vu_server); + BlockBackend *blk =3D vexp->export.blk; =20 struct iovec *in_iov =3D elem->in_sg; struct iovec *out_iov =3D elem->out_sg; @@ -133,16 +132,19 @@ static void coroutine_fn vu_block_virtio_process_req(= void *opaque) bool is_write =3D type & VIRTIO_BLK_T_OUT; req->sector_num =3D le64_to_cpu(req->out.sector); =20 - int64_t offset =3D req->sector_num * vdev_blk->blk_size; + if (is_write && !vexp->writable) { + req->in->status =3D VIRTIO_BLK_S_IOERR; + break; + } + + int64_t offset =3D req->sector_num * vexp->blk_size; QEMUIOVector qiov; if (is_write) { qemu_iovec_init_external(&qiov, out_iov, out_num); - ret =3D blk_co_pwritev(backend, offset, qiov.size, - &qiov, 0); + ret =3D blk_co_pwritev(blk, offset, qiov.size, &qiov, 0); } else { qemu_iovec_init_external(&qiov, in_iov, in_num); - ret =3D blk_co_preadv(backend, offset, qiov.size, - &qiov, 0); + ret =3D blk_co_preadv(blk, offset, qiov.size, &qiov, 0); } if (ret >=3D 0) { req->in->status =3D VIRTIO_BLK_S_OK; @@ -152,7 +154,7 @@ static void coroutine_fn vu_block_virtio_process_req(vo= id *opaque) break; } case VIRTIO_BLK_T_FLUSH: - if (vu_block_flush(req) =3D=3D 0) { + if (blk_co_flush(blk) =3D=3D 0) { req->in->status =3D VIRTIO_BLK_S_OK; } else { req->in->status =3D VIRTIO_BLK_S_IOERR; @@ -169,8 +171,13 @@ static void coroutine_fn vu_block_virtio_process_req(v= oid *opaque) case VIRTIO_BLK_T_DISCARD: case VIRTIO_BLK_T_WRITE_ZEROES: { int rc; - rc =3D vu_block_discard_write_zeroes(req, &elem->out_sg[1], - out_num, type); + + if (!vexp->writable) { + req->in->status =3D VIRTIO_BLK_S_IOERR; + break; + } + + rc =3D vu_blk_discard_write_zeroes(blk, &elem->out_sg[1], out_num,= type); if (rc =3D=3D 0) { req->in->status =3D VIRTIO_BLK_S_OK; } else { @@ -183,22 +190,22 @@ static void coroutine_fn vu_block_virtio_process_req(= void *opaque) break; } =20 - vu_block_req_complete(req); + vu_blk_req_complete(req); return; =20 err: - free(elem); + free(req); } =20 -static void vu_block_process_vq(VuDev *vu_dev, int idx) +static void vu_blk_process_vq(VuDev *vu_dev, int idx) { VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); VuVirtq *vq =3D vu_get_queue(vu_dev, idx); =20 while (1) { - VuBlockReq *req; + VuBlkReq *req; =20 - req =3D vu_queue_pop(vu_dev, vq, sizeof(VuBlockReq)); + req =3D vu_queue_pop(vu_dev, vq, sizeof(VuBlkReq)); if (!req) { break; } @@ -207,26 +214,26 @@ static void vu_block_process_vq(VuDev *vu_dev, int id= x) req->vq =3D vq; =20 Coroutine *co =3D - qemu_coroutine_create(vu_block_virtio_process_req, req); + qemu_coroutine_create(vu_blk_virtio_process_req, req); qemu_coroutine_enter(co); } } =20 -static void vu_block_queue_set_started(VuDev *vu_dev, int idx, bool starte= d) +static void vu_blk_queue_set_started(VuDev *vu_dev, int idx, bool started) { VuVirtq *vq; =20 assert(vu_dev); =20 vq =3D vu_get_queue(vu_dev, idx); - vu_set_queue_handler(vu_dev, vq, started ? vu_block_process_vq : NULL); + vu_set_queue_handler(vu_dev, vq, started ? vu_blk_process_vq : NULL); } =20 -static uint64_t vu_block_get_features(VuDev *dev) +static uint64_t vu_blk_get_features(VuDev *dev) { uint64_t features; VuServer *server =3D container_of(dev, VuServer, vu_dev); - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); + VuBlkExport *vexp =3D container_of(server, VuBlkExport, vu_server); features =3D 1ull << VIRTIO_BLK_F_SIZE_MAX | 1ull << VIRTIO_BLK_F_SEG_MAX | 1ull << VIRTIO_BLK_F_TOPOLOGY | @@ -240,35 +247,35 @@ static uint64_t vu_block_get_features(VuDev *dev) 1ull << VIRTIO_RING_F_EVENT_IDX | 1ull << VHOST_USER_F_PROTOCOL_FEATURES; =20 - if (!vdev_blk->writable) { + if (!vexp->writable) { features |=3D 1ull << VIRTIO_BLK_F_RO; } =20 return features; } =20 -static uint64_t vu_block_get_protocol_features(VuDev *dev) +static uint64_t vu_blk_get_protocol_features(VuDev *dev) { return 1ull << VHOST_USER_PROTOCOL_F_CONFIG | 1ull << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD; } =20 static int -vu_block_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) +vu_blk_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) { + /* TODO blkcfg must be little-endian for VIRTIO 1.0 */ VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); - memcpy(config, &vdev_blk->blkcfg, len); - + VuBlkExport *vexp =3D container_of(server, VuBlkExport, vu_server); + memcpy(config, &vexp->blkcfg, len); return 0; } =20 static int -vu_block_set_config(VuDev *vu_dev, const uint8_t *data, +vu_blk_set_config(VuDev *vu_dev, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags) { VuServer *server =3D container_of(vu_dev, VuServer, vu_dev); - VuBlockDev *vdev_blk =3D get_vu_block_device_by_server(server); + VuBlkExport *vexp =3D container_of(server, VuBlkExport, vu_server); uint8_t wce; =20 /* don't support live migration */ @@ -282,8 +289,8 @@ vu_block_set_config(VuDev *vu_dev, const uint8_t *data, } =20 wce =3D *data; - vdev_blk->blkcfg.wce =3D wce; - blk_set_enable_write_cache(vdev_blk->backend, wce); + vexp->blkcfg.wce =3D wce; + blk_set_enable_write_cache(vexp->export.blk, wce); return 0; } =20 @@ -295,7 +302,7 @@ vu_block_set_config(VuDev *vu_dev, const uint8_t *data, * of vu_process_message. * */ -static int vu_block_process_msg(VuDev *dev, VhostUserMsg *vmsg, int *do_re= ply) +static int vu_blk_process_msg(VuDev *dev, VhostUserMsg *vmsg, int *do_repl= y) { if (vmsg->request =3D=3D VHOST_USER_NONE) { dev->panic(dev, "disconnect"); @@ -304,29 +311,29 @@ static int vu_block_process_msg(VuDev *dev, VhostUser= Msg *vmsg, int *do_reply) return false; } =20 -static const VuDevIface vu_block_iface =3D { - .get_features =3D vu_block_get_features, - .queue_set_started =3D vu_block_queue_set_started, - .get_protocol_features =3D vu_block_get_protocol_features, - .get_config =3D vu_block_get_config, - .set_config =3D vu_block_set_config, - .process_msg =3D vu_block_process_msg, +static const VuDevIface vu_blk_iface =3D { + .get_features =3D vu_blk_get_features, + .queue_set_started =3D vu_blk_queue_set_started, + .get_protocol_features =3D vu_blk_get_protocol_features, + .get_config =3D vu_blk_get_config, + .set_config =3D vu_blk_set_config, + .process_msg =3D vu_blk_process_msg, }; =20 static void blk_aio_attached(AioContext *ctx, void *opaque) { - VuBlockDev *vub_dev =3D opaque; - vhost_user_server_attach_aio_context(&vub_dev->vu_server, ctx); + VuBlkExport *vexp =3D opaque; + vhost_user_server_attach_aio_context(&vexp->vu_server, ctx); } =20 static void blk_aio_detach(void *opaque) { - VuBlockDev *vub_dev =3D opaque; - vhost_user_server_detach_aio_context(&vub_dev->vu_server); + VuBlkExport *vexp =3D opaque; + vhost_user_server_detach_aio_context(&vexp->vu_server); } =20 static void -vu_block_initialize_config(BlockDriverState *bs, +vu_blk_initialize_config(BlockDriverState *bs, struct virtio_blk_config *config, uint32_t blk_= size) { config->capacity =3D bdrv_getlength(bs) >> BDRV_SECTOR_BITS; @@ -343,290 +350,67 @@ vu_block_initialize_config(BlockDriverState *bs, config->max_write_zeroes_seg =3D 1; } =20 -static VuBlockDev *vu_block_init(VuBlockDev *vu_block_device, Error **errp) +static void vu_blk_exp_request_shutdown(BlockExport *exp) { + VuBlkExport *vexp =3D container_of(exp, VuBlkExport, export); =20 - BlockBackend *blk; - Error *local_error =3D NULL; - const char *node_name =3D vu_block_device->node_name; - bool writable =3D vu_block_device->writable; - uint64_t perm =3D BLK_PERM_CONSISTENT_READ; - int ret; - - AioContext *ctx; - - BlockDriverState *bs =3D bdrv_lookup_bs(node_name, node_name, &local_e= rror); - - if (!bs) { - error_propagate(errp, local_error); - return NULL; - } - - if (bdrv_is_read_only(bs)) { - writable =3D false; - } - - if (writable) { - perm |=3D BLK_PERM_WRITE; - } - - ctx =3D bdrv_get_aio_context(bs); - aio_context_acquire(ctx); - bdrv_invalidate_cache(bs, NULL); - aio_context_release(ctx); - - /* - * Don't allow resize while the vhost user server is running, - * otherwise we don't care what happens with the node. - */ - blk =3D blk_new(bdrv_get_aio_context(bs), perm, - BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | - BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD); - ret =3D blk_insert_bs(blk, bs, errp); - - if (ret < 0) { - goto fail; - } - - blk_set_enable_write_cache(blk, false); - - blk_set_allow_aio_context_change(blk, true); - - vu_block_device->blkcfg.wce =3D 0; - vu_block_device->backend =3D blk; - if (!vu_block_device->blk_size) { - vu_block_device->blk_size =3D BDRV_SECTOR_SIZE; - } - vu_block_device->blkcfg.blk_size =3D vu_block_device->blk_size; - blk_set_guest_block_size(blk, vu_block_device->blk_size); - vu_block_initialize_config(bs, &vu_block_device->blkcfg, - vu_block_device->blk_size); - return vu_block_device; - -fail: - blk_unref(blk); - return NULL; -} - -static void vu_block_deinit(VuBlockDev *vu_block_device) -{ - if (vu_block_device->backend) { - blk_remove_aio_context_notifier(vu_block_device->backend, blk_aio_= attached, - blk_aio_detach, vu_block_device); - } - - blk_unref(vu_block_device->backend); -} - -static void vhost_user_blk_server_stop(VuBlockDev *vu_block_device) -{ - vhost_user_server_stop(&vu_block_device->vu_server); - vu_block_deinit(vu_block_device); -} - -static void vhost_user_blk_server_start(VuBlockDev *vu_block_device, - Error **errp) -{ - AioContext *ctx; - SocketAddress *addr =3D vu_block_device->addr; - - if (!vu_block_init(vu_block_device, errp)) { - return; - } - - ctx =3D bdrv_get_aio_context(blk_bs(vu_block_device->backend)); - - if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, - VHOST_USER_BLK_MAX_QUEUES, &vu_block_ifac= e, - errp)) { - goto error; - } - - blk_add_aio_context_notifier(vu_block_device->backend, blk_aio_attache= d, - blk_aio_detach, vu_block_device); - vu_block_device->running =3D true; - return; - - error: - vu_block_deinit(vu_block_device); -} - -static bool vu_prop_modifiable(VuBlockDev *vus, Error **errp) -{ - if (vus->running) { - error_setg(errp, "The property can't be modified " - "while the server is running"); - return false; - } - return true; -} - -static void vu_set_node_name(Object *obj, const char *value, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - - if (!vu_prop_modifiable(vus, errp)) { - return; - } - - if (vus->node_name) { - g_free(vus->node_name); - } - - vus->node_name =3D g_strdup(value); -} - -static char *vu_get_node_name(Object *obj, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - return g_strdup(vus->node_name); -} - -static void free_socket_addr(SocketAddress *addr) -{ - g_free(addr->u.q_unix.path); - g_free(addr); -} - -static void vu_set_unix_socket(Object *obj, const char *value, - Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - - if (!vu_prop_modifiable(vus, errp)) { - return; - } - - if (vus->addr) { - free_socket_addr(vus->addr); - } - - SocketAddress *addr =3D g_new0(SocketAddress, 1); - addr->type =3D SOCKET_ADDRESS_TYPE_UNIX; - addr->u.q_unix.path =3D g_strdup(value); - vus->addr =3D addr; + vhost_user_server_stop(&vexp->vu_server); } =20 -static char *vu_get_unix_socket(Object *obj, Error **errp) +static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, + Error **errp) { - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - return g_strdup(vus->addr->u.q_unix.path); -} - -static bool vu_get_block_writable(Object *obj, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - return vus->writable; -} - -static void vu_set_block_writable(Object *obj, bool value, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - - if (!vu_prop_modifiable(vus, errp)) { - return; - } - - vus->writable =3D value; -} - -static void vu_get_blk_size(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - uint32_t value =3D vus->blk_size; - - visit_type_uint32(v, name, &value, errp); -} - -static void vu_set_blk_size(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - VuBlockDev *vus =3D VHOST_USER_BLK_SERVER(obj); - + VuBlkExport *vexp =3D container_of(exp, VuBlkExport, export); + BlockExportOptionsVhostUserBlk *vu_opts =3D &opts->u.vhost_user_blk; Error *local_err =3D NULL; - uint32_t value; + uint64_t logical_block_size; =20 - if (!vu_prop_modifiable(vus, errp)) { - return; - } + vexp->writable =3D opts->writable; + vexp->blkcfg.wce =3D 0; =20 - visit_type_uint32(v, name, &value, &local_err); - if (local_err) { - goto out; + if (vu_opts->has_logical_block_size) { + logical_block_size =3D vu_opts->logical_block_size; + } else { + logical_block_size =3D BDRV_SECTOR_SIZE; } - - check_block_size(object_get_typename(obj), name, value, &local_err); + check_block_size(exp->id, "logical-block-size", logical_block_size, + &local_err); if (local_err) { - goto out; + error_propagate(errp, local_err); + return -EINVAL; + } + vexp->blk_size =3D logical_block_size; + blk_set_guest_block_size(exp->blk, logical_block_size); + vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, + logical_block_size); + + blk_set_allow_aio_context_change(exp->blk, true); + blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detac= h, + vexp); + + if (!vhost_user_server_start(&vexp->vu_server, vu_opts->addr, exp->ctx, + VHOST_USER_BLK_MAX_QUEUES, &vu_blk_iface, + errp)) { + blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, + blk_aio_detach, vexp); + return -EADDRNOTAVAIL; } =20 - vus->blk_size =3D value; - -out: - error_propagate(errp, local_err); -} - -static void vhost_user_blk_server_instance_finalize(Object *obj) -{ - VuBlockDev *vub =3D VHOST_USER_BLK_SERVER(obj); - - vhost_user_blk_server_stop(vub); - - /* - * Unlike object_property_add_str, object_class_property_add_str - * doesn't have a release method. Thus manual memory freeing is - * needed. - */ - free_socket_addr(vub->addr); - g_free(vub->node_name); -} - -static void vhost_user_blk_server_complete(UserCreatable *obj, Error **err= p) -{ - VuBlockDev *vub =3D VHOST_USER_BLK_SERVER(obj); - - vhost_user_blk_server_start(vub, errp); + return 0; } =20 -static void vhost_user_blk_server_class_init(ObjectClass *klass, - void *class_data) +static void vu_blk_exp_delete(BlockExport *exp) { - UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(klass); - ucc->complete =3D vhost_user_blk_server_complete; - - object_class_property_add_bool(klass, "writable", - vu_get_block_writable, - vu_set_block_writable); - - object_class_property_add_str(klass, "node-name", - vu_get_node_name, - vu_set_node_name); - - object_class_property_add_str(klass, "unix-socket", - vu_get_unix_socket, - vu_set_unix_socket); + VuBlkExport *vexp =3D container_of(exp, VuBlkExport, export); =20 - object_class_property_add(klass, "logical-block-size", "uint32", - vu_get_blk_size, vu_set_blk_size, - NULL, NULL); + blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_de= tach, + vexp); } =20 -static const TypeInfo vhost_user_blk_server_info =3D { - .name =3D TYPE_VHOST_USER_BLK_SERVER, - .parent =3D TYPE_OBJECT, - .instance_size =3D sizeof(VuBlockDev), - .instance_finalize =3D vhost_user_blk_server_instance_finalize, - .class_init =3D vhost_user_blk_server_class_init, - .interfaces =3D (InterfaceInfo[]) { - {TYPE_USER_CREATABLE}, - {} - }, +const BlockExportDriver blk_exp_vhost_user_blk =3D { + .type =3D BLOCK_EXPORT_TYPE_VHOST_USER_BLK, + .instance_size =3D sizeof(VuBlkExport), + .create =3D vu_blk_exp_create, + .delete =3D vu_blk_exp_delete, + .request_shutdown =3D vu_blk_exp_request_shutdown, }; - -static void vhost_user_blk_server_register_types(void) -{ - type_register_static(&vhost_user_blk_server_info); -} - -type_init(vhost_user_blk_server_register_types) diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index c448800e58..516999b38a 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -408,7 +408,15 @@ bool vhost_user_server_start(VuServer *server, Error **errp) { QEMUBH *bh; - QIONetListener *listener =3D qio_net_listener_new(); + QIONetListener *listener; + + if (socket_addr->type !=3D SOCKET_ADDRESS_TYPE_UNIX && + socket_addr->type !=3D SOCKET_ADDRESS_TYPE_FD) { + error_setg(errp, "Only socket address types 'unix' and 'fd' are su= pported"); + return false; + } + + listener =3D qio_net_listener_new(); if (qio_net_listener_open_sync(listener, socket_addr, 1, errp) < 0) { object_unref(OBJECT(listener)); diff --git a/block/export/meson.build b/block/export/meson.build index 558ef35d38..ef3a9576f7 100644 --- a/block/export/meson.build +++ b/block/export/meson.build @@ -1 +1,2 @@ block_ss.add(files('export.c')) +block_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-server.c= ', '../../contrib/libvhost-user/libvhost-user.c')) diff --git a/block/meson.build b/block/meson.build index 6e6c1dc479..78e8b25232 100644 --- a/block/meson.build +++ b/block/meson.build @@ -60,7 +60,6 @@ block_ss.add(when: 'CONFIG_WIN32', if_true: files('file-w= in32.c', 'win32-aio.c') block_ss.add(when: 'CONFIG_POSIX', if_true: [files('file-posix.c'), coref,= iokit]) block_ss.add(when: 'CONFIG_LIBISCSI', if_true: files('iscsi-opts.c')) block_ss.add(when: 'CONFIG_LINUX', if_true: files('nvme.c')) -block_ss.add(when: 'CONFIG_LINUX', if_true: files('export/vhost-user-blk-s= erver.c', '../contrib/libvhost-user/libvhost-user.c')) block_ss.add(when: 'CONFIG_REPLICATION', if_true: files('replication.c')) block_ss.add(when: 'CONFIG_SHEEPDOG', if_true: files('sheepdog.c')) block_ss.add(when: ['CONFIG_LINUX_AIO', libaio], if_true: files('linux-aio= .c')) --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366946; cv=none; d=zohomail.com; s=zohoarc; b=l6Akb0aKyejgweqHHz5LSbD3bKLMiilE/moM6E+qz0lWFHZ6PJiTxYJ07s5rupOx3U+96Lql5N/tExmu56ViZyrmCprJyHrG3nlBX+Y8Nwpq3y8ewirY6SZrOD2KoInKxwxHKlfll5Dd1qpZj/ctnKJ2hwUHG6Z34dVIgco0WhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366946; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CMNwoCnigUPcB3dN719WwGHMtn3wt9B/0xh5QicFSB8=; b=Og7FSUpQ2Q/yT1bQ/K2hbTkZ8CmqWd2jKRMaMUspcKl2gM+C6Tz42uY6q8RVEiArmW6UFw1KSuSj+ZPHqz4dnDjGCNeBhnkOVidn1VvyOghQ7sUw5mw6pFLlEHHQM3Z5SJDwE61V0wC3DedQjn9EYnFvRVYp8PKy3o5Fza9l7Ao= 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 1603366946560679.0899551913144; Thu, 22 Oct 2020 04:42:26 -0700 (PDT) Received: from localhost ([::1]:35292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYzB-0004zV-Cx for importer@patchew.org; Thu, 22 Oct 2020 07:42:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmX-00063L-R2 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38535) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmW-00059f-0k for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-235-6SA4LxTcNB-v25Yxy1iuiQ-1; Thu, 22 Oct 2020 07:29:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F35FA106B813; Thu, 22 Oct 2020 11:29:15 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DBCD5B4B8; Thu, 22 Oct 2020 11:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CMNwoCnigUPcB3dN719WwGHMtn3wt9B/0xh5QicFSB8=; b=HtyoP8WW3huNO2ByXZruFgze28Am5XeNpDgefXMhA67wgdn5YM6ndMEDoZs4PDASxgejJg LB1+QrbBxfFk3aJ3KjUsxVW2AKgSkubWOkaiei6FBl35PaL9b59BYYmjA2twM98RjiVtYR UIwOiR7Z7QXnXdKWBpFtJJk7+O7YTt0= X-MC-Unique: 6SA4LxTcNB-v25Yxy1iuiQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 18/28] util/vhost-user-server: move header to include/ Date: Thu, 22 Oct 2020 12:27:16 +0100 Message-Id: <20201022112726.736757-19-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Headers used by other subsystems are located in include/. Also add the vhost-user-server and vhost-user-blk-server headers to MAINTAINERS. Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-13-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- MAINTAINERS | 4 +++- {util =3D> include/qemu}/vhost-user-server.h | 0 block/export/vhost-user-blk-server.c | 2 +- util/vhost-user-server.c | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) rename {util =3D> include/qemu}/vhost-user-server.h (100%) diff --git a/MAINTAINERS b/MAINTAINERS index 39fd488bd0..461dae4989 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3066,8 +3066,10 @@ Vhost-user block device backend server M: Coiby Xu S: Maintained F: block/export/vhost-user-blk-server.c -F: util/vhost-user-server.c +F: block/export/vhost-user-blk-server.h +F: include/qemu/vhost-user-server.h F: tests/qtest/libqos/vhost-user-blk.c +F: util/vhost-user-server.c =20 Replication M: Wen Congyang diff --git a/util/vhost-user-server.h b/include/qemu/vhost-user-server.h similarity index 100% rename from util/vhost-user-server.h rename to include/qemu/vhost-user-server.h diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index 3e5bd6caee..f7021cbd7b 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -13,7 +13,7 @@ #include "block/block.h" #include "contrib/libvhost-user/libvhost-user.h" #include "standard-headers/linux/virtio_blk.h" -#include "util/vhost-user-server.h" +#include "qemu/vhost-user-server.h" #include "vhost-user-blk-server.h" #include "qapi/error.h" #include "qom/object_interfaces.h" diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 516999b38a..783d847a6d 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -9,8 +9,8 @@ */ #include "qemu/osdep.h" #include "qemu/main-loop.h" +#include "qemu/vhost-user-server.h" #include "block/aio-wait.h" -#include "vhost-user-server.h" =20 /* * Theory of operation: --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603367135; cv=none; d=zohomail.com; s=zohoarc; b=W5Ycg5FGYHWwaZ/YoiUj0UesTcBkt0x3vunqGOYanll5WK5UUfiAwu82EUAmvqV+h8ANVVHxIYtQmBm+deJbiz0CkmfgFTDhohw//fQJndx18IMRej2Su5gGVuQ8IqHXp+R8a5LuIH2Da9XQv/RVlXUVfyhxrzmUKkn/BJUpgUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603367135; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QwQd8wORDao0+3QpVdU00Rbe1vhC/LwYTHjYaJ28YWs=; b=TJ5auQZAJKqzJeLzW1b2fAwnDaKN82EDfSPwYZis6Qo/GC9LyxR16Gt9+M43GVTQ4a1tLCpVKH3qUQ/vd+cI44k6baSRItW6FYmA+JFrpZEjUy5+3QVJiHXttRSmQeOxE9MNxTjiO5xZNmBj+LgSqJs8P/J8JMAmumKEOYsWIyI= 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 1603367135139375.37286078074055; Thu, 22 Oct 2020 04:45:35 -0700 (PDT) Received: from localhost ([::1]:43852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZ2D-00005R-Pn for importer@patchew.org; Thu, 22 Oct 2020 07:45:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmb-0006Cm-I9 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27901) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmY-00059x-K3 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-376-BWo2g1G6PZ-kHiM3IT_58Q-1; Thu, 22 Oct 2020 07:29:19 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42CECAD749; Thu, 22 Oct 2020 11:29:18 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCD7510013D7; Thu, 22 Oct 2020 11:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QwQd8wORDao0+3QpVdU00Rbe1vhC/LwYTHjYaJ28YWs=; b=S16Gsqb23xE0XQ8Y8ymmo9Bf9K0ysEW/pQ/5wRacawQGP4AH8YrGuvRsPo8CnuWWGWt9us IlBh6/abd+wq1QqTz1fJcxyYECbzuDVKZ6dVLv7sMp0NsfsrLKcDv1zz/Bwi3laaf7dxeD gTLc/d3w/IMVGIdQBGc/vVnNd88OhIQ= X-MC-Unique: BWo2g1G6PZ-kHiM3IT_58Q-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 19/28] util/vhost-user-server: use static library in meson.build Date: Thu, 22 Oct 2020 12:27:17 +0100 Message-Id: <20201022112726.736757-20-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Don't compile contrib/libvhost-user/libvhost-user.c again. Instead build the static library once and then reuse it throughout QEMU. Also switch from CONFIG_LINUX to CONFIG_VHOST_USER, which is what the vhost-user tools (vhost-user-gpu, etc) do. Signed-off-by: Stefan Hajnoczi Message-id: 20200924151549.913737-14-stefanha@redhat.com [Added CONFIG_LINUX again because libvhost-user doesn't build on macOS. --Stefan] Signed-off-by: Stefan Hajnoczi --- block/export/export.c | 8 ++++---- block/export/meson.build | 2 +- contrib/libvhost-user/meson.build | 1 + meson.build | 6 +++++- util/meson.build | 4 +++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index bd7cac241f..550897e236 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -17,17 +17,17 @@ #include "sysemu/block-backend.h" #include "block/export.h" #include "block/nbd.h" -#if CONFIG_LINUX -#include "block/export/vhost-user-blk-server.h" -#endif #include "qapi/error.h" #include "qapi/qapi-commands-block-export.h" #include "qapi/qapi-events-block-export.h" #include "qemu/id.h" +#ifdef CONFIG_VHOST_USER +#include "vhost-user-blk-server.h" +#endif =20 static const BlockExportDriver *blk_exp_drivers[] =3D { &blk_exp_nbd, -#if CONFIG_LINUX +#ifdef CONFIG_VHOST_USER &blk_exp_vhost_user_blk, #endif }; diff --git a/block/export/meson.build b/block/export/meson.build index ef3a9576f7..fffe6b09e8 100644 --- a/block/export/meson.build +++ b/block/export/meson.build @@ -1,2 +1,2 @@ block_ss.add(files('export.c')) -block_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-server.c= ', '../../contrib/libvhost-user/libvhost-user.c')) +block_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: files('= vhost-user-blk-server.c')) diff --git a/contrib/libvhost-user/meson.build b/contrib/libvhost-user/meso= n.build index e68dd1a581..a261e7665f 100644 --- a/contrib/libvhost-user/meson.build +++ b/contrib/libvhost-user/meson.build @@ -1,3 +1,4 @@ libvhost_user =3D static_library('vhost-user', files('libvhost-user.c', 'libvhost-user-gli= b.c'), build_by_default: false) +vhost_user =3D declare_dependency(link_with: libvhost_user) diff --git a/meson.build b/meson.build index 7627a0ae46..2ec4f114ce 100644 --- a/meson.build +++ b/meson.build @@ -1398,6 +1398,11 @@ trace_events_subdirs +=3D [ 'util', ] =20 +vhost_user =3D not_found +if 'CONFIG_VHOST_USER' in config_host + subdir('contrib/libvhost-user') +endif + subdir('qapi') subdir('qobject') subdir('stubs') @@ -1830,7 +1835,6 @@ if have_tools install: true) =20 if 'CONFIG_VHOST_USER' in config_host - subdir('contrib/libvhost-user') subdir('contrib/vhost-user-blk') subdir('contrib/vhost-user-gpu') subdir('contrib/vhost-user-input') diff --git a/util/meson.build b/util/meson.build index 2296e81b34..c5159ad79d 100644 --- a/util/meson.build +++ b/util/meson.build @@ -66,7 +66,9 @@ if have_block util_ss.add(files('main-loop.c')) util_ss.add(files('nvdimm-utils.c')) util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-cor= outine-io.c')) - util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) + util_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: [ + files('vhost-user-server.c'), vhost_user + ]) util_ss.add(files('block-helpers.c')) util_ss.add(files('qemu-coroutine-sleep.c')) util_ss.add(files('qemu-co-shared-resource.c')) --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603367384; cv=none; d=zohomail.com; s=zohoarc; b=OmOiiqyT5QsRVdjaiG5fRH52wPj2AyXqj9Xe22hWg9vlMqoT4BI0PQZBynjFePJooqnCHw6W+tSv/YCH0V+/1yc4liqJZq7nSeSFUFr1y9HUpE9kaP27UXbY3U9Y3ayliWdi39U4G0HG4RNIUEnz0OZLOilT9+uTNU91TSGlMvw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603367384; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ogDc78Da3pGyWDfyJyhV89iS65RlQAvah2kWaoor87s=; b=RTUGEgt4JhHWa9SdmbHrqtStfVODsl1u8zrxLjaqVIwJadYGPNmf+Pf6wvcAi0+0bc6xUmdLWh2w6s/QarkILBntuMLDelGHpVLHYr9I73DPlyrbsfAU52iRj9cVLAizb9D0EkNj4vPI5uct4h9kdJmoV+xrkwC2/pCHpJGZLsk= 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 1603367384420470.351008945432; Thu, 22 Oct 2020 04:49:44 -0700 (PDT) Received: from localhost ([::1]:53056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZ6F-00047f-99 for importer@patchew.org; Thu, 22 Oct 2020 07:49:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmj-0006Md-3G for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmh-0005Ax-DQ for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-vnrzL1k7NXawBdGvwXnzAA-1; Thu, 22 Oct 2020 07:29:24 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 509A7AD741; Thu, 22 Oct 2020 11:29:23 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6D3819C4F; Thu, 22 Oct 2020 11:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ogDc78Da3pGyWDfyJyhV89iS65RlQAvah2kWaoor87s=; b=itMzGb8q2W2UwaopiFV6KZ0AlVKbOrkngxtki86E5J+VPJwG1gEottRq7g4Q7o4+mEvm8A 7/2ST/IeHspt58EMxdiNHn3wZ0YUmehaOTW6swnczjWsb/1+AaD8HwBJ6YBZfChojyjook Q/Oz9hU969MudhSQLEYW5A5g859yQjg= X-MC-Unique: vnrzL1k7NXawBdGvwXnzAA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 20/28] qemu-storage-daemon: avoid compiling blockdev_ss twice Date: Thu, 22 Oct 2020 12:27:18 +0100 Message-Id: <20201022112726.736757-21-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Introduce libblkdev.fa to avoid recompiling blockdev_ss twice. Suggested-by: Paolo Bonzini Reviewed-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi Message-id: 20200929125516.186715-3-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- meson.build | 12 ++++++++++-- storage-daemon/meson.build | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 2ec4f114ce..880683407f 100644 --- a/meson.build +++ b/meson.build @@ -1464,7 +1464,6 @@ blockdev_ss.add(files( # os-win32.c does not blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c')) softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')]) -softmmu_ss.add_all(blockdev_ss) =20 common_ss.add(files('cpus-common.c')) =20 @@ -1596,6 +1595,15 @@ block =3D declare_dependency(link_whole: [libblock], link_args: '@block.syms', dependencies: [crypto, io]) =20 +blockdev_ss =3D blockdev_ss.apply(config_host, strict: false) +libblockdev =3D static_library('blockdev', blockdev_ss.sources() + genh, + dependencies: blockdev_ss.dependencies(), + name_suffix: 'fa', + build_by_default: false) + +blockdev =3D declare_dependency(link_whole: [libblockdev], + dependencies: [block]) + qmp_ss =3D qmp_ss.apply(config_host, strict: false) libqmp =3D static_library('qmp', qmp_ss.sources() + genh, dependencies: qmp_ss.dependencies(), @@ -1628,7 +1636,7 @@ foreach m : block_mods + softmmu_mods install_dir: config_host['qemu_moddir']) endforeach =20 -softmmu_ss.add(authz, block, chardev, crypto, io, qmp) +softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp) common_ss.add(qom, qemuutil) =20 common_ss.add_all(when: 'CONFIG_SOFTMMU', if_true: [softmmu_ss]) diff --git a/storage-daemon/meson.build b/storage-daemon/meson.build index 0409acc3f5..c5adce81c3 100644 --- a/storage-daemon/meson.build +++ b/storage-daemon/meson.build @@ -1,7 +1,6 @@ qsd_ss =3D ss.source_set() qsd_ss.add(files('qemu-storage-daemon.c')) -qsd_ss.add(block, chardev, qmp, qom, qemuutil) -qsd_ss.add_all(blockdev_ss) +qsd_ss.add(blockdev, chardev, qmp, qom, qemuutil) =20 subdir('qapi') =20 --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603367699; cv=none; d=zohomail.com; s=zohoarc; b=Vt5Ndy9rRqewkywzszSwZRDZc2+TAt1FCOUK++uQ4kfrFk7Wc3v5MX6h91WyIXU2tTff+C5PxPZzPGcn/spAuTHcQKC8MI8whrN5nuDrTncNG6WHmQpIHQAjotHASXgQKRNBiystx1MfCAtIuMOIl2KK2Dmj6ps/Xg8d1eUnOww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603367699; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4L06fNv5aJG9QsRTTubOTAeBelEAva87357K9YMFpAU=; b=jvfVURZ3T2tSRdc0w9GnHMiMtW+lsDW0pJf8Gr7uxRUwIVah9SzqRYimLYAD3hOL3D5zwxYYoiC6K+q03Vpq9T1sKE6PT1zBZp/dxodmP21Om4zrI1/ooLP8/EMRreDwrZqZ5U9im+ezmF1vnhtzxctxGnCpJMcPXH9/D4kjmVA= 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 16033676999601013.7524500872956; Thu, 22 Oct 2020 04:54:59 -0700 (PDT) Received: from localhost ([::1]:40932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZBK-0002Ln-Km for importer@patchew.org; Thu, 22 Oct 2020 07:54:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmn-0006Qp-Dr for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21681) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmj-0005BF-99 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-278-cknAamc2MpKWl9QVVtar5w-1; Thu, 22 Oct 2020 07:29:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B6D0107ACF5; Thu, 22 Oct 2020 11:29:28 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAA9260C04; Thu, 22 Oct 2020 11:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4L06fNv5aJG9QsRTTubOTAeBelEAva87357K9YMFpAU=; b=SfYttsP2ohM6ZYkg+7tyw9tGkMd8u5NqisxUoD/uR7y630YYpPALqNflnw5BCX+8lYlEGg 9AKtd16KHtYQFM/jHFGFDL087F8KA4MG6xctWdB/t0iz3UzmwGle92grNBxrfnTwLZESlV yTR5UyU2Om4u394oz/dJO4RM2hsPbV0= X-MC-Unique: cknAamc2MpKWl9QVVtar5w-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 21/28] block: move block exports to libblockdev Date: Thu, 22 Oct 2020 12:27:19 +0100 Message-Id: <20201022112726.736757-22-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Block exports are used by softmmu, qemu-storage-daemon, and qemu-nbd. They are not used by other programs and are not otherwise needed in libblock. Undo the recent move of blockdev-nbd.c from blockdev_ss into block_ss. Since bdrv_close_all() (libblock) calls blk_exp_close_all() (libblockdev) a stub function is required.. Make qemu-nbd.c use signal handling utility functions instead of duplicating the code. This helps because os-posix.c is in libblockdev and it depends on a qemu_system_killed() symbol that qemu-nbd.c lacks. Once we use the signal handling utility functions we also end up providing the necessary symbol. Signed-off-by: Stefan Hajnoczi Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Message-id: 20200929125516.186715-4-stefanha@redhat.com [Fixed s/ndb/nbd/ typo in commit description as suggested by Eric Blake --Stefan] Signed-off-by: Stefan Hajnoczi --- qemu-nbd.c | 21 ++++++++------------- stubs/blk-exp-close-all.c | 7 +++++++ block/export/meson.build | 4 ++-- meson.build | 4 ++-- nbd/meson.build | 2 ++ stubs/meson.build | 1 + 6 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 stubs/blk-exp-close-all.c diff --git a/qemu-nbd.c b/qemu-nbd.c index bc644a0670..a0701cdf36 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -25,6 +25,7 @@ #include "qapi/error.h" #include "qemu/cutils.h" #include "sysemu/block-backend.h" +#include "sysemu/runstate.h" /* for qemu_system_killed() prototype */ #include "block/block_int.h" #include "block/nbd.h" #include "qemu/main-loop.h" @@ -155,7 +156,11 @@ QEMU_COPYRIGHT "\n" } =20 #ifdef CONFIG_POSIX -static void termsig_handler(int signum) +/* + * The client thread uses SIGTERM to interrupt the server. A signal + * handler ensures that "qemu-nbd -v -c" exits with a nice status code. + */ +void qemu_system_killed(int signum, pid_t pid) { qatomic_cmpxchg(&state, RUNNING, TERMINATE); qemu_notify_event(); @@ -582,18 +587,8 @@ int main(int argc, char **argv) BlockExportOptions *export_opts; =20 #ifdef CONFIG_POSIX - /* - * Exit gracefully on various signals, which includes SIGTERM used - * by 'qemu-nbd -v -c'. - */ - struct sigaction sa_sigterm; - memset(&sa_sigterm, 0, sizeof(sa_sigterm)); - sa_sigterm.sa_handler =3D termsig_handler; - sigaction(SIGTERM, &sa_sigterm, NULL); - sigaction(SIGINT, &sa_sigterm, NULL); - sigaction(SIGHUP, &sa_sigterm, NULL); - - signal(SIGPIPE, SIG_IGN); + os_setup_early_signal_handling(); + os_setup_signal_handling(); #endif =20 socket_init(); diff --git a/stubs/blk-exp-close-all.c b/stubs/blk-exp-close-all.c new file mode 100644 index 0000000000..1c71316763 --- /dev/null +++ b/stubs/blk-exp-close-all.c @@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "block/export.h" + +/* Only used in programs that support block exports (libblockdev.fa) */ +void blk_exp_close_all(void) +{ +} diff --git a/block/export/meson.build b/block/export/meson.build index fffe6b09e8..9fb4fbf81d 100644 --- a/block/export/meson.build +++ b/block/export/meson.build @@ -1,2 +1,2 @@ -block_ss.add(files('export.c')) -block_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: files('= vhost-user-blk-server.c')) +blockdev_ss.add(files('export.c')) +blockdev_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: file= s('vhost-user-blk-server.c')) diff --git a/meson.build b/meson.build index 880683407f..b349c9bda8 100644 --- a/meson.build +++ b/meson.build @@ -1443,7 +1443,6 @@ subdir('dump') =20 block_ss.add(files( 'block.c', - 'blockdev-nbd.c', 'blockjob.c', 'job.c', 'qemu-io-cmds.c', @@ -1456,6 +1455,7 @@ subdir('block') =20 blockdev_ss.add(files( 'blockdev.c', + 'blockdev-nbd.c', 'iothread.c', 'job-qmp.c', )) @@ -1832,7 +1832,7 @@ if have_tools qemu_io =3D executable('qemu-io', files('qemu-io.c'), dependencies: [block, qemuutil], install: true) qemu_nbd =3D executable('qemu-nbd', files('qemu-nbd.c'), - dependencies: [block, qemuutil], install: true) + dependencies: [blockdev, qemuutil], install: true) =20 subdir('storage-daemon') subdir('contrib/rdmacm-mux') diff --git a/nbd/meson.build b/nbd/meson.build index 0c00a776d3..2baaa36948 100644 --- a/nbd/meson.build +++ b/nbd/meson.build @@ -1,5 +1,7 @@ block_ss.add(files( 'client.c', 'common.c', +)) +blockdev_ss.add(files( 'server.c', )) diff --git a/stubs/meson.build b/stubs/meson.build index 67f2a8c069..7b733fadb7 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -1,6 +1,7 @@ stub_ss.add(files('arch_type.c')) stub_ss.add(files('bdrv-next-monitor-owned.c')) stub_ss.add(files('blk-commit-all.c')) +stub_ss.add(files('blk-exp-close-all.c')) stub_ss.add(files('blockdev-close-all-bdrv-states.c')) stub_ss.add(files('change-state-handler.c')) stub_ss.add(files('cmos.c')) --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603367831; cv=none; d=zohomail.com; s=zohoarc; b=PSFS2hSOouwpsJjlooro1sfXBxqhUI0iOnovtkHWKsgwz2hnG4fGKqj2SPgNuEbD+17J3fQoJXRSvXvXwgEbW0SjgKHzT2Iw1Hkr1KfeaptkSkIT9rdWWLPxEr8nMVIvIhAv7t7guShW+OqY5j/OSz1sBxW+u0JVgPayqcz/5ow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603367831; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ISLk/f/qup/bAzietY5lmdfvNvFxUIRufnIKhOcUOfM=; b=TEilq+ZYLsDnwHUYdAgGiPTAFLsI51NJ9n6uOt8RGcbKp7b3YxQ5tmxd3va4bZvE3fgTHf8+o8PN+B3m/YFWwhlgZwxHPcHqExoDYnESxwdqBLq1G+14mwml30TRA0o/jXLyorN5LCkYYYzu5fCv5b0MA0D6Ys03WJhSg82ir84= 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 1603367831726756.9577888021181; Thu, 22 Oct 2020 04:57:11 -0700 (PDT) Received: from localhost ([::1]:50082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZDS-0006C9-K2 for importer@patchew.org; Thu, 22 Oct 2020 07:57:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmv-0006Ty-29 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21297) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmp-0005Ba-1d for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-482-wgXrpmsOOWuW7oeUulwiug-1; Thu, 22 Oct 2020 07:29:34 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7241918C89D7; Thu, 22 Oct 2020 11:29:33 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0700210013D0; Thu, 22 Oct 2020 11:29:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366176; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ISLk/f/qup/bAzietY5lmdfvNvFxUIRufnIKhOcUOfM=; b=cBEpiBxBw/6N+FKARD1+D7mAOZBCfqKQ4ONje8v8QGFq5dVFcbvGW0GJZJy7zIDBkk5UfT SUfmZecezk2Z6qd8T7+897cb5xLzQnGlWnbN5ORRh64PZmYqavT5+lcYHZl3U50XRnThLt Bpx/CEN8VjEC/VKu/ndIPTAYhUsjt4w= X-MC-Unique: wgXrpmsOOWuW7oeUulwiug-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 22/28] block/export: add iothread and fixed-iothread options Date: Thu, 22 Oct 2020 12:27:20 +0100 Message-Id: <20201022112726.736757-23-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Make it possible to specify the iothread where the export will run. By default the block node can be moved to other AioContexts later and the export will follow. The fixed-iothread option forces strict behavior that prevents changing AioContext while the export is active. See the QAPI docs for details. Signed-off-by: Stefan Hajnoczi Message-id: 20200929125516.186715-5-stefanha@redhat.com [Fix stray '#' character in block-export.json and add missing "(since: 5.2)" as suggested by Eric Blake. --Stefan] Signed-off-by: Stefan Hajnoczi --- qapi/block-export.json | 11 ++++++++++ block/export/export.c | 31 +++++++++++++++++++++++++++- block/export/vhost-user-blk-server.c | 5 ++++- nbd/server.c | 2 -- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index a793e34af9..8a4ced817f 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -219,11 +219,22 @@ # export before completion is signalled. (since: 5.2; # default: false) # +# @iothread: The name of the iothread object where the export will run. The +# default is to use the thread currently associated with the +# block node. (since: 5.2) +# +# @fixed-iothread: True prevents the block node from being moved to another +# thread while the export is active. If true and @iothrea= d is +# given, export creation fails if the block node cannot be +# moved to the iothread. The default is false. (since: 5.= 2) +# # Since: 4.2 ## { 'union': 'BlockExportOptions', 'base': { 'type': 'BlockExportType', 'id': 'str', + '*fixed-iothread': 'bool', + '*iothread': 'str', 'node-name': 'str', '*writable': 'bool', '*writethrough': 'bool' }, diff --git a/block/export/export.c b/block/export/export.c index 550897e236..a5b6b02703 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -15,6 +15,7 @@ =20 #include "block/block.h" #include "sysemu/block-backend.h" +#include "sysemu/iothread.h" #include "block/export.h" #include "block/nbd.h" #include "qapi/error.h" @@ -63,10 +64,11 @@ static const BlockExportDriver *blk_exp_find_driver(Blo= ckExportType type) =20 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { + bool fixed_iothread =3D export->has_fixed_iothread && export->fixed_io= thread; const BlockExportDriver *drv; BlockExport *exp =3D NULL; BlockDriverState *bs; - BlockBackend *blk; + BlockBackend *blk =3D NULL; AioContext *ctx; uint64_t perm; int ret; @@ -102,6 +104,28 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) ctx =3D bdrv_get_aio_context(bs); aio_context_acquire(ctx); =20 + if (export->has_iothread) { + IOThread *iothread; + AioContext *new_ctx; + + iothread =3D iothread_by_id(export->iothread); + if (!iothread) { + error_setg(errp, "iothread \"%s\" not found", export->iothread= ); + goto fail; + } + + new_ctx =3D iothread_get_aio_context(iothread); + + ret =3D bdrv_try_set_aio_context(bs, new_ctx, errp); + if (ret =3D=3D 0) { + aio_context_release(ctx); + aio_context_acquire(new_ctx); + ctx =3D new_ctx; + } else if (fixed_iothread) { + goto fail; + } + } + /* * Block exports are used for non-shared storage migration. Make sure * that BDRV_O_INACTIVE is cleared and the image is ready for write @@ -116,6 +140,11 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) } =20 blk =3D blk_new(ctx, perm, BLK_PERM_ALL); + + if (!fixed_iothread) { + blk_set_allow_aio_context_change(blk, true); + } + ret =3D blk_insert_bs(blk, bs, errp); if (ret < 0) { goto fail; diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index f7021cbd7b..286eb5fb9a 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -323,13 +323,17 @@ static const VuDevIface vu_blk_iface =3D { static void blk_aio_attached(AioContext *ctx, void *opaque) { VuBlkExport *vexp =3D opaque; + + vexp->export.ctx =3D ctx; vhost_user_server_attach_aio_context(&vexp->vu_server, ctx); } =20 static void blk_aio_detach(void *opaque) { VuBlkExport *vexp =3D opaque; + vhost_user_server_detach_aio_context(&vexp->vu_server); + vexp->export.ctx =3D NULL; } =20 static void @@ -384,7 +388,6 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExp= ortOptions *opts, vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, logical_block_size); =20 - blk_set_allow_aio_context_change(exp->blk, true); blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detac= h, vexp); =20 diff --git a/nbd/server.c b/nbd/server.c index e75c825879..08b621f70a 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1517,8 +1517,6 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, return ret; } =20 - blk_set_allow_aio_context_change(blk, true); - QTAILQ_INIT(&exp->clients); exp->name =3D g_strdup(arg->name); exp->description =3D g_strdup(arg->description); --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603367502; cv=none; d=zohomail.com; s=zohoarc; b=la7Xd/w0nN1gTWeDABri1TJ277wagT0WwyO/YoCNCvDoChSwgM7TI4HcDGejtZmIrM/Tb8e/cKK5CiO1mTeL+WDcc9JVEhQWxsK8UBgotiY6bzFznJn0ohkMJRlwmTazxEKcOkPQVY1N/R/eJ6ewm4SU9fH16P4WZy0NQcghuSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603367502; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PDGU8gIk8Pi7rgM0O/1+uxeO4tyTqhwMmraME3uYtfY=; b=FhZUTUbq7+/Jow09btRqh/D5isc2my6yQDw6eXSuZ7l9IC9TICQlgiVkEAhhaa7x7J5MVlmjCQZnaHeg1W+CJvTFfRAQ/E36EK3GcJzuwzC70g0HVGbxIbCNbkoU4pEWMkjKPeZt/wTr/7mzzgoqkShawAxwNIO4zaapDP9vUlI= 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 1603367502911290.6508606573492; Thu, 22 Oct 2020 04:51:42 -0700 (PDT) Received: from localhost ([::1]:33190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZ89-0007bM-P7 for importer@patchew.org; Thu, 22 Oct 2020 07:51:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmv-0006Tv-1X for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25159) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmp-0005Bn-0g for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-493-RLZ2uVi9NuqCMYnPMKD10A-1; Thu, 22 Oct 2020 07:29:36 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 45BA1AD741; Thu, 22 Oct 2020 11:29:35 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD01110013D0; Thu, 22 Oct 2020 11:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366178; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PDGU8gIk8Pi7rgM0O/1+uxeO4tyTqhwMmraME3uYtfY=; b=DTyD6vlUdEKy274Z8IYDJJ9H5bJR2iUmn0VQRc0nnkZrWgpp8zuoKzPVP0KZKo8K8G4inK 8Nx6MKG/kDbGw7S+fPLgIF4FDcnz1F3chxeSx/tLeGEwGCV4DSv11HvvpTWm14+3HrWhWY cap5jTE9MhZpXkl0245i3SvPS73lkvU= X-MC-Unique: RLZ2uVi9NuqCMYnPMKD10A-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 23/28] block/export: add vhost-user-blk multi-queue support Date: Thu, 22 Oct 2020 12:27:21 +0100 Message-Id: <20201022112726.736757-24-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Allow the number of queues to be configured using --export vhost-user-blk,num-queues=3DN. This setting should match the QEMU --device vhost-user-blk-pci,num-queues=3DN setting but QEMU vhost-user-blk.c lowers its own value if the vhost-user-blk backend offers fewer queues than QEMU. The vhost-user-blk-server.c code is already capable of multi-queue. All virtqueue processing runs in the same AioContext. No new locking is needed. Add the num-queues=3DN option and set the VIRTIO_BLK_F_MQ feature bit. Note that the feature bit only announces the presence of the num_queues configuration space field. It does not promise that there is more than 1 virtqueue, so we can set it unconditionally. I tested multi-queue by running a random read fio test with numjobs=3D4 on an -smp 4 guest. After the benchmark finished the guest /proc/interrupts file showed activity on all 4 virtio-blk MSI-X. The /sys/block/vda/mq/ directory shows that Linux blk-mq has 4 queues configured. An automated test is included in the next commit. Signed-off-by: Stefan Hajnoczi Acked-by: Markus Armbruster Message-id: 20201001144604.559733-2-stefanha@redhat.com [Fixed accidental tab characters as suggested by Markus Armbruster --Stefan] Signed-off-by: Stefan Hajnoczi --- qapi/block-export.json | 10 +++++++--- block/export/vhost-user-blk-server.c | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 8a4ced817f..480c497690 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -93,11 +93,15 @@ # SocketAddress types are supported. Passed fds must be UNIX domain # sockets. # @logical-block-size: Logical block size in bytes. Defaults to 512 bytes. +# @num-queues: Number of request virtqueues. Must be greater than 0. Defau= lts +# to 1. # # Since: 5.2 ## { 'struct': 'BlockExportOptionsVhostUserBlk', - 'data': { 'addr': 'SocketAddress', '*logical-block-size': 'size' } } + 'data': { 'addr': 'SocketAddress', + '*logical-block-size': 'size', + '*num-queues': 'uint16'} } =20 ## # @NbdServerAddOptions: @@ -233,8 +237,8 @@ { 'union': 'BlockExportOptions', 'base': { 'type': 'BlockExportType', 'id': 'str', - '*fixed-iothread': 'bool', - '*iothread': 'str', + '*fixed-iothread': 'bool', + '*iothread': 'str', 'node-name': 'str', '*writable': 'bool', '*writethrough': 'bool' }, diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index 286eb5fb9a..41f4933d6e 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -21,7 +21,7 @@ #include "util/block-helpers.h" =20 enum { - VHOST_USER_BLK_MAX_QUEUES =3D 1, + VHOST_USER_BLK_NUM_QUEUES_DEFAULT =3D 1, }; struct virtio_blk_inhdr { unsigned char status; @@ -242,6 +242,7 @@ static uint64_t vu_blk_get_features(VuDev *dev) 1ull << VIRTIO_BLK_F_DISCARD | 1ull << VIRTIO_BLK_F_WRITE_ZEROES | 1ull << VIRTIO_BLK_F_CONFIG_WCE | + 1ull << VIRTIO_BLK_F_MQ | 1ull << VIRTIO_F_VERSION_1 | 1ull << VIRTIO_RING_F_INDIRECT_DESC | 1ull << VIRTIO_RING_F_EVENT_IDX | @@ -338,7 +339,9 @@ static void blk_aio_detach(void *opaque) =20 static void vu_blk_initialize_config(BlockDriverState *bs, - struct virtio_blk_config *config, uint32_t blk_= size) + struct virtio_blk_config *config, + uint32_t blk_size, + uint16_t num_queues) { config->capacity =3D bdrv_getlength(bs) >> BDRV_SECTOR_BITS; config->blk_size =3D blk_size; @@ -346,7 +349,7 @@ vu_blk_initialize_config(BlockDriverState *bs, config->seg_max =3D 128 - 2; config->min_io_size =3D 1; config->opt_io_size =3D 1; - config->num_queues =3D VHOST_USER_BLK_MAX_QUEUES; + config->num_queues =3D num_queues; config->max_discard_sectors =3D 32768; config->max_discard_seg =3D 1; config->discard_sector_alignment =3D config->blk_size >> 9; @@ -368,6 +371,7 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExp= ortOptions *opts, BlockExportOptionsVhostUserBlk *vu_opts =3D &opts->u.vhost_user_blk; Error *local_err =3D NULL; uint64_t logical_block_size; + uint16_t num_queues =3D VHOST_USER_BLK_NUM_QUEUES_DEFAULT; =20 vexp->writable =3D opts->writable; vexp->blkcfg.wce =3D 0; @@ -385,15 +389,23 @@ static int vu_blk_exp_create(BlockExport *exp, BlockE= xportOptions *opts, } vexp->blk_size =3D logical_block_size; blk_set_guest_block_size(exp->blk, logical_block_size); + + if (vu_opts->has_num_queues) { + num_queues =3D vu_opts->num_queues; + } + if (num_queues =3D=3D 0) { + error_setg(errp, "num-queues must be greater than 0"); + return -EINVAL; + } + vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, - logical_block_size); + logical_block_size, num_queues); =20 blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detac= h, vexp); =20 if (!vhost_user_server_start(&vexp->vu_server, vu_opts->addr, exp->ctx, - VHOST_USER_BLK_MAX_QUEUES, &vu_blk_iface, - errp)) { + num_queues, &vu_blk_iface, errp)) { blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, vexp); return -EADDRNOTAVAIL; --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366720; cv=none; d=zohomail.com; s=zohoarc; b=TZ9uApmirtzDQkFQhAfoF5A0jjlTP6A7xRRGZO7dUdo3VdyuqGS6SKmAyGkjMMm1oGLsNpxacHdW6y57Ix1nH9X+dXxFOXF1BQ3BoS3qbQxJdy4FoYwdqAblgBoRUCcNB09hdx60EW26SHX1dkMt964do2CBVAaypG9rm56ezB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366720; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MtvnK0f/LNuPJKfiDksYrxzItoNrs0JmX/tUwY70GkA=; b=Sw+vl8awVHaJhyg1YB/6SBJiFDFHAbIAHVDDEqeFOkXG3CudEW86Jw3NW1o1Zma4ulFn7qGyzlciDRC/8ki/KfIjBFGreUmXYGo9N4LHNRg5YTY4aNraCinl0vumCLT9keKq7glJ4yl2Y87HkP7nieqgazGOG2qDxop8y8AtkCA= 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 1603366720801218.45622783810848; Thu, 22 Oct 2020 04:38:40 -0700 (PDT) Received: from localhost ([::1]:54718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYvX-0001Em-J5 for importer@patchew.org; Thu, 22 Oct 2020 07:38:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYmy-0006W4-Ui for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYmv-0005CR-MU for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-205-7Zor1OpNNTujkYulcjhrHg-1; Thu, 22 Oct 2020 07:29:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 91A2E804B62; Thu, 22 Oct 2020 11:29:40 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id D45825C1C7; Thu, 22 Oct 2020 11:29:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MtvnK0f/LNuPJKfiDksYrxzItoNrs0JmX/tUwY70GkA=; b=Qom5dWQdN0VeLikvspiKzclt7GH42oxqurMmnPDXuVnvQFPBnXAc9SW2HteFlup/HPyVMD D7fOoTwiO4vtOb97++xKyssL6HEG4h+NaMh2x30+5QO+RGpIP64xXW2de/j6yKGxETaPsR PLD4E0FfbSk2OpBy8GuS5KmC3L2ujAk= X-MC-Unique: 7Zor1OpNNTujkYulcjhrHg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 24/28] block/io: fix bdrv_co_block_status_above Date: Thu, 22 Oct 2020 12:27:22 +0100 Message-Id: <20201022112726.736757-25-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Alberto Garcia , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy bdrv_co_block_status_above has several design problems with handling short backing files: 1. With want_zeros=3Dtrue, it may return ret with BDRV_BLOCK_ZERO but without BDRV_BLOCK_ALLOCATED flag, when actually short backing file which produces these after-EOF zeros is inside requested backing sequence. 2. With want_zero=3Dfalse, it may return pnum=3D0 prior to actual EOF, because of EOF of short backing file. Fix these things, making logic about short backing files clearer. With fixed bdrv_block_status_above we also have to improve is_zero in qcow2 code, otherwise iotest 154 will fail, because with this patch we stop to merge zeros of different types (produced by fully unallocated in the whole backing chain regions vs produced by short backing files). Note also, that this patch leaves for another day the general problem around block-status: misuse of BDRV_BLOCK_ALLOCATED as is-fs-allocated vs go-to-backing. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake Message-id: 20200924194003.22080-2-vsementsov@virtuozzo.com [Fix s/comes/come/ as suggested by Eric Blake --Stefan] Signed-off-by: Stefan Hajnoczi --- block/io.c | 68 ++++++++++++++++++++++++++++++++++++++++----------- block/qcow2.c | 16 ++++++++++-- 2 files changed, 68 insertions(+), 16 deletions(-) diff --git a/block/io.c b/block/io.c index 54f0968aee..a718d50ca2 100644 --- a/block/io.c +++ b/block/io.c @@ -2350,34 +2350,74 @@ bdrv_co_common_block_status_above(BlockDriverState = *bs, int64_t *map, BlockDriverState **file) { + int ret; BlockDriverState *p; - int ret =3D 0; - bool first =3D true; + int64_t eof =3D 0; =20 assert(bs !=3D base); - for (p =3D bs; p !=3D base; p =3D bdrv_filter_or_cow_bs(p)) { + + ret =3D bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, = file); + if (ret < 0 || *pnum =3D=3D 0 || ret & BDRV_BLOCK_ALLOCATED) { + return ret; + } + + if (ret & BDRV_BLOCK_EOF) { + eof =3D offset + *pnum; + } + + assert(*pnum <=3D bytes); + bytes =3D *pnum; + + for (p =3D bdrv_filter_or_cow_bs(bs); p !=3D base; + p =3D bdrv_filter_or_cow_bs(p)) + { ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, file); if (ret < 0) { - break; + return ret; } - if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { + if (*pnum =3D=3D 0) { /* - * Reading beyond the end of the file continues to read - * zeroes, but we can only widen the result to the - * unallocated length we learned from an earlier - * iteration. + * The top layer deferred to this layer, and because this laye= r is + * short, any zeroes that we synthesize beyond EOF behave as i= f they + * were allocated at this layer. + * + * We don't include BDRV_BLOCK_EOF into ret, as upper layer ma= y be + * larger. We'll add BDRV_BLOCK_EOF if needed at function end,= see + * below. */ + assert(ret & BDRV_BLOCK_EOF); *pnum =3D bytes; + if (file) { + *file =3D p; + } + ret =3D BDRV_BLOCK_ZERO | BDRV_BLOCK_ALLOCATED; + break; } - if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) { + if (ret & BDRV_BLOCK_ALLOCATED) { + /* + * We've found the node and the status, we must break. + * + * Drop BDRV_BLOCK_EOF, as it's not for upper layer, which may= be + * larger. We'll add BDRV_BLOCK_EOF if needed at function end,= see + * below. + */ + ret &=3D ~BDRV_BLOCK_EOF; break; } - /* [offset, pnum] unallocated on this layer, which could be only - * the first part of [offset, bytes]. */ - bytes =3D MIN(bytes, *pnum); - first =3D false; + + /* + * OK, [offset, offset + *pnum) region is unallocated on this laye= r, + * let's continue the diving. + */ + assert(*pnum <=3D bytes); + bytes =3D *pnum; + } + + if (offset + *pnum =3D=3D eof) { + ret |=3D BDRV_BLOCK_EOF; } + return ret; } =20 diff --git a/block/qcow2.c b/block/qcow2.c index b05512718c..b6cb4db8bb 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3860,8 +3860,20 @@ static bool is_zero(BlockDriverState *bs, int64_t of= fset, int64_t bytes) if (!bytes) { return true; } - res =3D bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NU= LL); - return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && nr =3D=3D bytes; + + /* + * bdrv_block_status_above doesn't merge different types of zeros, for + * example, zeros which come from the region which is unallocated in + * the whole backing chain, and zeros which come because of a short + * backing file. So, we need a loop. + */ + do { + res =3D bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL= , NULL); + offset +=3D nr; + bytes -=3D nr; + } while (res >=3D 0 && (res & BDRV_BLOCK_ZERO) && nr && bytes); + + return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && bytes =3D=3D 0; } =20 static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603368214; cv=none; d=zohomail.com; s=zohoarc; b=I0YIT70Efs7zjVW/t4MaGgsDrKVnFWitVdYd8CL+6JTc9J4opD1kAKmtlrwR7mGkcOkE1O8yuuigoB2oomKQgl/p/fjr7woQuZkIEtJbNiCFpdm1ksoEq/VvGg39DCuRZdyE2RjcrmWv9xGmSnYzs0tggTPHRn8HtY65Gl2IqJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603368214; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qFGmSQHsWrrOfWOH+/peX5MRwaUCO4cXU4Gw5k/UjVE=; b=U6euBLo9OdoWqBeinxEdj+V8NuoKCrqfla3o+cUyTIvFxjqxMD/0dpCDq+97Ts6mMi42dV5yK5YGWxbXOXwSl4xUKxCCymPaDDu8ne/Xv0lLqehoJfEueNcmq2+9UomWVxpkAPPZ1PcZx2SoO+Y1ZjSf3p4kWbTDEf8Q0USQ4ew= 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 1603368214510468.0357440953969; Thu, 22 Oct 2020 05:03:34 -0700 (PDT) Received: from localhost ([::1]:39316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZJc-00053I-Qy for importer@patchew.org; Thu, 22 Oct 2020 08:03:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYnE-0006gm-IE for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:30:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57214) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYn4-0005DW-K3 for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:30:01 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-46-rCPiPFv-OFiyoenwopvM2A-1; Thu, 22 Oct 2020 07:29:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0367F804B62; Thu, 22 Oct 2020 11:29:45 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id D16536EF69; Thu, 22 Oct 2020 11:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366190; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qFGmSQHsWrrOfWOH+/peX5MRwaUCO4cXU4Gw5k/UjVE=; b=F+IY6cHFo5VL7WnBuTuYSKwglTSH1XkxWk93jrJ4kOOVVjT4xgpZGH4wGjkisDJU5Zeou6 dQRoVW9AKOKkvyDvECCCBvXt72/+kchZI1Z/XHsNCV8R4jJlzIxhKNrRVBp2belL895Eyz GLRMV519xN1m80teiFUgjsIy+QFk+K0= X-MC-Unique: rCPiPFv-OFiyoenwopvM2A-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 25/28] block/io: bdrv_common_block_status_above: support include_base Date: Thu, 22 Oct 2020 12:27:23 +0100 Message-Id: <20201022112726.736757-26-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Alberto Garcia , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy In order to reuse bdrv_common_block_status_above in bdrv_is_allocated_above, let's support include_base parameter. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake Message-id: 20200924194003.22080-3-vsementsov@virtuozzo.com Signed-off-by: Stefan Hajnoczi --- block/coroutines.h | 2 ++ block/io.c | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index f69179f5ef..1cb3128b94 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -41,6 +41,7 @@ bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned i= nt bytes, int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, + bool include_base, bool want_zero, int64_t offset, int64_t bytes, @@ -50,6 +51,7 @@ bdrv_co_common_block_status_above(BlockDriverState *bs, int generated_co_wrapper bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, + bool include_base, bool want_zero, int64_t offset, int64_t bytes, diff --git a/block/io.c b/block/io.c index a718d50ca2..86f76d04bf 100644 --- a/block/io.c +++ b/block/io.c @@ -2343,6 +2343,7 @@ early_out: int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, + bool include_base, bool want_zero, int64_t offset, int64_t bytes, @@ -2354,10 +2355,11 @@ bdrv_co_common_block_status_above(BlockDriverState = *bs, BlockDriverState *p; int64_t eof =3D 0; =20 - assert(bs !=3D base); + assert(include_base || bs !=3D base); + assert(!include_base || base); /* Can't include NULL base */ =20 ret =3D bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, = file); - if (ret < 0 || *pnum =3D=3D 0 || ret & BDRV_BLOCK_ALLOCATED) { + if (ret < 0 || *pnum =3D=3D 0 || ret & BDRV_BLOCK_ALLOCATED || bs =3D= =3D base) { return ret; } =20 @@ -2368,7 +2370,7 @@ bdrv_co_common_block_status_above(BlockDriverState *b= s, assert(*pnum <=3D bytes); bytes =3D *pnum; =20 - for (p =3D bdrv_filter_or_cow_bs(bs); p !=3D base; + for (p =3D bdrv_filter_or_cow_bs(bs); include_base || p !=3D base; p =3D bdrv_filter_or_cow_bs(p)) { ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, @@ -2406,6 +2408,11 @@ bdrv_co_common_block_status_above(BlockDriverState *= bs, break; } =20 + if (p =3D=3D base) { + assert(include_base); + break; + } + /* * OK, [offset, offset + *pnum) region is unallocated on this laye= r, * let's continue the diving. @@ -2425,7 +2432,7 @@ int bdrv_block_status_above(BlockDriverState *bs, Blo= ckDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) { - return bdrv_common_block_status_above(bs, base, true, offset, bytes, + return bdrv_common_block_status_above(bs, base, false, true, offset, b= ytes, pnum, map, file); } =20 @@ -2442,9 +2449,9 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *= bs, int64_t offset, int ret; int64_t dummy; =20 - ret =3D bdrv_common_block_status_above(bs, bdrv_filter_or_cow_bs(bs), = false, - offset, bytes, pnum ? pnum : &dum= my, - NULL, NULL); + ret =3D bdrv_common_block_status_above(bs, bs, true, false, offset, + bytes, pnum ? pnum : &dummy, NULL, + NULL); if (ret < 0) { return ret; } --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603367983; cv=none; d=zohomail.com; s=zohoarc; b=Ek2WBEtAtkg5twDkjTWv0lvZWDP1BVaLz+g+DX8kXSXyO7r+ze+qn07MWBleDaFBUr3WhUM54gNg90x8YpQdpz3Uov/s0dOYmKhv7Kj25QLCaqSIzfWjJqoJ+YeWrBiuEZBSVhWt7XkqpB+WeSyDkifjzDy2Qm66xU28aWYv1+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603367983; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=u7bm674skGiXTOIOUgCjRtaAQ5TwmqJJ5o5uOKPqBfo=; b=b8uBdMEFt9I9KcyUd01NuUC2z7ulszA98dxjTX3mtQd8rEpugQunBGKAzzwQXTB6SXVpM/o0WQ8bNrxruusC+yvGNsSk11W5fZ7JN0AptDBM1rAaSxkflUUegErcPgyuVc3Ue7k4uVIQj3E1AReZNNFSJRJRr/4NAoqfXnnvvx4= 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 1603367983577346.9747259833184; Thu, 22 Oct 2020 04:59:43 -0700 (PDT) Received: from localhost ([::1]:59050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZFu-0001PL-JF for importer@patchew.org; Thu, 22 Oct 2020 07:59:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYn5-0006dT-3e for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYn1-0005DL-5R for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:29:54 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-0-dQUQdnNGmysXkYQFE8-Q-1; Thu, 22 Oct 2020 07:29:48 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFE87804B6C; Thu, 22 Oct 2020 11:29:46 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45B45100238E; Thu, 22 Oct 2020 11:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366190; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u7bm674skGiXTOIOUgCjRtaAQ5TwmqJJ5o5uOKPqBfo=; b=ASf7pdVtqJPRC6kt8uJcFtidwXzKTinKax/XjphazQ1Cz3xpzFQ4VUyL7hUu0xn5A7mfOo dwajnjspG/dgkxJnKyD/U3DFUfR3lnDtDeu115cvkCvh1QC7yk00Jg88HTLSpUkgmcR2zb dEUElgPC9yV+jZ08lPvQwxt3J7uzAxo= X-MC-Unique: 0-dQUQdnNGmysXkYQFE8-Q-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 26/28] block/io: bdrv_common_block_status_above: support bs == base Date: Thu, 22 Oct 2020 12:27:24 +0100 Message-Id: <20201022112726.736757-27-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Alberto Garcia , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We are going to reuse bdrv_common_block_status_above in bdrv_is_allocated_above. bdrv_is_allocated_above may be called with include_base =3D=3D false and still bs =3D=3D base (for ex. from img_rebase= ()). So, support this corner case. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Message-id: 20200924194003.22080-4-vsementsov@virtuozzo.com Signed-off-by: Stefan Hajnoczi --- block/io.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index 86f76d04bf..b616bc4ada 100644 --- a/block/io.c +++ b/block/io.c @@ -2355,9 +2355,13 @@ bdrv_co_common_block_status_above(BlockDriverState *= bs, BlockDriverState *p; int64_t eof =3D 0; =20 - assert(include_base || bs !=3D base); assert(!include_base || base); /* Can't include NULL base */ =20 + if (!include_base && bs =3D=3D base) { + *pnum =3D bytes; + return 0; + } + ret =3D bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, = file); if (ret < 0 || *pnum =3D=3D 0 || ret & BDRV_BLOCK_ALLOCATED || bs =3D= =3D base) { return ret; --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603366777; cv=none; d=zohomail.com; s=zohoarc; b=bYHjnRFQXJt21aLC0O7R8QkSqAJ/QxpLxDmPuZCYss7hWc9tXlNdrFvRQsIhgIm8tRYlQFuYUKGtnC9pHR5jk1dYUFCsIIVBTPu0NKKKRaA3rCorN9wGtmJ4pHko45MMtk00bFHa6Hm/xz8ldtRs80u0MaZqKWlSbV7fLgPPByc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603366777; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0082Lo4MDolrcETSjUoN1/VyBCJMMbq8vm2eo+Y/Rp4=; b=eK1HOhS8qbnApyTSYx/BaWFODdTMhVqsIOisgzvkXJboDLixCplG7JYI9DVHEHCceRPyOc0+Lhm8PivTS5oLwVxnCI+a+h4e/YgR1bvsMppqzEvMTgwoHCWj8Bo6T4COFjsKaS+WwZrszkemTZTCgKrdnu+TQuh/Lk/uB3fRIIo= 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 1603366777794478.8316757931109; Thu, 22 Oct 2020 04:39:37 -0700 (PDT) Received: from localhost ([::1]:55956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVYwS-0001jP-Lv for importer@patchew.org; Thu, 22 Oct 2020 07:39:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYnG-0006gs-AG for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:30:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYnE-0005EC-0m for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:30:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306-NM2AIGItMletc0tfMpadlw-1; Thu, 22 Oct 2020 07:29:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8335EAD741; Thu, 22 Oct 2020 11:29:51 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 016ED5D9D5; Thu, 22 Oct 2020 11:29:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0082Lo4MDolrcETSjUoN1/VyBCJMMbq8vm2eo+Y/Rp4=; b=dbeXB3wlOYEugJxHw2eq+rLX0AZYY+LBooLsMX9QdcBmgvCYdIy69V6goy3+1hEvLCXw0r wJPTGZFiGuMMH0e1D6X5eT6kQPKg2bsusYhPthSrTJSQAqP79xr/m+hr1gK9FbFzC13hSK HFDfxanJGX0/RN+8ztFhjvbhs+rmmaU= X-MC-Unique: NM2AIGItMletc0tfMpadlw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 27/28] block/io: fix bdrv_is_allocated_above Date: Thu, 22 Oct 2020 12:27:25 +0100 Message-Id: <20201022112726.736757-28-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 06:53:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Alberto Garcia , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy bdrv_is_allocated_above wrongly handles short backing files: it reports after-EOF space as UNALLOCATED which is wrong, as on read the data is generated on the level of short backing file (if all overlays have unallocated areas at that place). Reusing bdrv_common_block_status_above fixes the issue and unifies code path. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Message-id: 20200924194003.22080-5-vsementsov@virtuozzo.com [Fix s/has/have/ as suggested by Eric Blake. Fix s/area/areas/. --Stefan] Signed-off-by: Stefan Hajnoczi --- block/io.c | 43 +++++-------------------------------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/block/io.c b/block/io.c index b616bc4ada..02528b3823 100644 --- a/block/io.c +++ b/block/io.c @@ -2477,52 +2477,19 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState= *bs, int64_t offset, * at 'offset + *pnum' may return the same allocation status (in other * words, the result is not necessarily the maximum possible range); * but 'pnum' will only be 0 when end of file is reached. - * */ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, bool include_base, int64_t offset, int64_t bytes, int64_t *pnum) { - BlockDriverState *intermediate; - int ret; - int64_t n =3D bytes; - - assert(base || !include_base); - - intermediate =3D top; - while (include_base || intermediate !=3D base) { - int64_t pnum_inter; - int64_t size_inter; - - assert(intermediate); - ret =3D bdrv_is_allocated(intermediate, offset, bytes, &pnum_inter= ); - if (ret < 0) { - return ret; - } - if (ret) { - *pnum =3D pnum_inter; - return 1; - } - - size_inter =3D bdrv_getlength(intermediate); - if (size_inter < 0) { - return size_inter; - } - if (n > pnum_inter && - (intermediate =3D=3D top || offset + pnum_inter < size_inter))= { - n =3D pnum_inter; - } - - if (intermediate =3D=3D base) { - break; - } - - intermediate =3D bdrv_filter_or_cow_bs(intermediate); + int ret =3D bdrv_common_block_status_above(top, base, include_base, fa= lse, + offset, bytes, pnum, NULL, NU= LL); + if (ret < 0) { + return ret; } =20 - *pnum =3D n; - return 0; + return !!(ret & BDRV_BLOCK_ALLOCATED); } =20 int coroutine_fn --=20 2.26.2 From nobody Sun May 19 02:26:43 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603368453; cv=none; d=zohomail.com; s=zohoarc; b=GLVMF9ogmkp8HTzPsIabxVd3VBnLrdn9mR5PajJjWqAD1ehA1VEuo4UUFJXJt3CTvCUXzg3C/U9s63X8EmUtzdVUNJHwftrRdAIkNKnB5P19PVIgBKAMcs/5GlH+easvYH8G5oz0aw2h+L6XX7U6yOjsqkIGeh9Zk38lEGc2kA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603368453; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Itz/H77O8YQ99CGzsq9afhukogYzz/U6DlCXeUrgRFQ=; b=bZvlwoPSpCNc/6S19TT9qQZsJuUrFJDGFdn0QkfjGQPOxTOiRmiscbnuJpnH9ApOc/m505OtlUOGVwvjPVD9WHhba9yoq3DFZiT4mBrcN/nu6F/bdwHKgRAABllrpKXh/1r8ciq5JjoWVV9mlCa9YoGFjghpAh3mo10DDXFaYPo= 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 160336845355999.09424192767358; Thu, 22 Oct 2020 05:07:33 -0700 (PDT) Received: from localhost ([::1]:47990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVZNU-0000Ye-Dx for importer@patchew.org; Thu, 22 Oct 2020 08:07:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVYnK-0006iI-AL for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:30:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVYnE-0005FK-9j for qemu-devel@nongnu.org; Thu, 22 Oct 2020 07:30:09 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-385-w5VJ63psMaWWBzrKB8jnpw-1; Thu, 22 Oct 2020 07:29:57 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66362AD743; Thu, 22 Oct 2020 11:29:56 +0000 (UTC) Received: from localhost (ovpn-114-229.ams2.redhat.com [10.36.114.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B96A1002388; Thu, 22 Oct 2020 11:29:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603366202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Itz/H77O8YQ99CGzsq9afhukogYzz/U6DlCXeUrgRFQ=; b=F753wHuWgsSE9Xhwb1TQ3XpVojsJKZyzjgRhJVS1ihGfBrGvaonf+mo73rhxg2kgdKeIVq q3SYFdPqD6pcJlchWZBo7djlKn5PVZUZqrpPz7wCW5pyCQDwS+/7HiUhqN3i0opELyo3pE W3Z7MvVmM34Ssmczv1vOPn9ds7k5BDo= X-MC-Unique: w5VJ63psMaWWBzrKB8jnpw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v2 28/28] iotests: add commit top->base cases to 274 Date: Thu, 22 Oct 2020 12:27:26 +0100 Message-Id: <20201022112726.736757-29-stefanha@redhat.com> In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com> References: <20201022112726.736757-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 00:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , qemu-block@nongnu.org, "Dr. David Alan Gilbert" , Coiby Xu , Markus Armbruster , Alberto Garcia , Stefan Hajnoczi , Paolo Bonzini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy These cases are fixed by previous patches around block_status and is_allocated. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Message-id: 20200924194003.22080-6-vsementsov@virtuozzo.com Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/274 | 20 +++++++++++ tests/qemu-iotests/274.out | 68 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/tests/qemu-iotests/274 b/tests/qemu-iotests/274 index d4571c5465..76b1ba6a52 100755 --- a/tests/qemu-iotests/274 +++ b/tests/qemu-iotests/274 @@ -115,6 +115,26 @@ with iotests.FilePath('base') as base, \ iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, mid) iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff),= mid) =20 + iotests.log('=3D=3D=3D Testing qemu-img commit (top -> base) =3D=3D=3D= ') + + create_chain() + iotests.qemu_img_log('commit', '-b', base, top) + iotests.img_info_log(base) + iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, base) + iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff),= base) + + iotests.log('=3D=3D=3D Testing QMP active commit (top -> base) =3D=3D= =3D') + + create_chain() + with create_vm() as vm: + vm.launch() + vm.qmp_log('block-commit', device=3D'top', base_node=3D'base', + job_id=3D'job0', auto_dismiss=3DFalse) + vm.run_job('job0', wait=3D5) + + iotests.img_info_log(mid) + iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, base) + iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff),= base) =20 iotests.log('=3D=3D Resize tests =3D=3D') =20 diff --git a/tests/qemu-iotests/274.out b/tests/qemu-iotests/274.out index bf5abd4c10..cfe17a8659 100644 --- a/tests/qemu-iotests/274.out +++ b/tests/qemu-iotests/274.out @@ -135,6 +135,74 @@ read 1048576/1048576 bytes at offset 0 read 1048576/1048576 bytes at offset 1048576 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 +=3D=3D=3D Testing qemu-img commit (top -> base) =3D=3D=3D +Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 cluster_size=3D65536 extended_= l2=3Doff compression_type=3Dzlib size=3D2097152 lazy_refcounts=3Doff refcou= nt_bits=3D16 + +Formatting 'TEST_DIR/PID-mid', fmt=3Dqcow2 cluster_size=3D65536 extended_l= 2=3Doff compression_type=3Dzlib size=3D1048576 backing_file=3DTEST_DIR/PID-= base backing_fmt=3Dqcow2 lazy_refcounts=3Doff refcount_bits=3D16 + +Formatting 'TEST_DIR/PID-top', fmt=3Dqcow2 cluster_size=3D65536 extended_l= 2=3Doff compression_type=3Dzlib size=3D2097152 backing_file=3DTEST_DIR/PID-= mid backing_fmt=3Dqcow2 lazy_refcounts=3Doff refcount_bits=3D16 + +wrote 2097152/2097152 bytes at offset 0 +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +Image committed. + +image: TEST_IMG +file format: IMGFMT +virtual size: 2 MiB (2097152 bytes) +cluster_size: 65536 +Format specific information: + compat: 1.1 + compression type: zlib + lazy refcounts: false + refcount bits: 16 + corrupt: false + extended l2: false + +read 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +read 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D=3D Testing QMP active commit (top -> base) =3D=3D=3D +Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 cluster_size=3D65536 extended_= l2=3Doff compression_type=3Dzlib size=3D2097152 lazy_refcounts=3Doff refcou= nt_bits=3D16 + +Formatting 'TEST_DIR/PID-mid', fmt=3Dqcow2 cluster_size=3D65536 extended_l= 2=3Doff compression_type=3Dzlib size=3D1048576 backing_file=3DTEST_DIR/PID-= base backing_fmt=3Dqcow2 lazy_refcounts=3Doff refcount_bits=3D16 + +Formatting 'TEST_DIR/PID-top', fmt=3Dqcow2 cluster_size=3D65536 extended_l= 2=3Doff compression_type=3Dzlib size=3D2097152 backing_file=3DTEST_DIR/PID-= mid backing_fmt=3Dqcow2 lazy_refcounts=3Doff refcount_bits=3D16 + +wrote 2097152/2097152 bytes at offset 0 +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +{"execute": "block-commit", "arguments": {"auto-dismiss": false, "base-nod= e": "base", "device": "top", "job-id": "job0"}} +{"return": {}} +{"execute": "job-complete", "arguments": {"id": "job0"}} +{"return": {}} +{"data": {"device": "job0", "len": 1048576, "offset": 1048576, "speed": 0,= "type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds= ": "USECS", "seconds": "SECS"}} +{"data": {"device": "job0", "len": 1048576, "offset": 1048576, "speed": 0,= "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microsec= onds": "USECS", "seconds": "SECS"}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} +image: TEST_IMG +file format: IMGFMT +virtual size: 1 MiB (1048576 bytes) +cluster_size: 65536 +backing file: TEST_DIR/PID-base +backing file format: IMGFMT +Format specific information: + compat: 1.1 + compression type: zlib + lazy refcounts: false + refcount bits: 16 + corrupt: false + extended l2: false + +read 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +read 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + =3D=3D Resize tests =3D=3D =3D=3D=3D preallocation=3Doff =3D=3D=3D Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 cluster_size=3D65536 extended_= l2=3Doff compression_type=3Dzlib size=3D6442450944 lazy_refcounts=3Doff ref= count_bits=3D16 --=20 2.26.2