From nobody Wed Apr 16 12:49:19 2025 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=1603468412; cv=none; d=zohomail.com; s=zohoarc; b=c8ADKCXyprk8rDz2MsGmSD68mzkW5TtSM/H76uhvHJ+cFD3qlbWw2bDkmlp0yW5LeiXsSzOjvTpoVSQ2MdJROeKcBCCCpFW/nWDHAmm2nFEjwQ7EqTNxapi0xZepXsovwYtRKml8AjhwNCHuqleXzBbvtqOVYh4QLdaTCk3NhmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603468412; 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=zsCaudaCAP8PkpNHWaEzotujmMeJdOjxs146kNuomrY=; b=VYkwRWjxDRGQGKzHrjRSNYSOFJ+qPWw3oBAE5tZ4AViwuFbwwWFMCXlY2E9iR//CqW1tq5BOnVWzIXpFwAPTDQn2nmgCLeUixNYoLziBqEPiGEy9SWML3Jur3YqwFmm2GqjjXoCrBErd1ZuG8y3fanSdl/MbrK9WNGTyGy3Zfd4= 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 160346841202156.70913625973208; Fri, 23 Oct 2020 08:53:32 -0700 (PDT) Received: from localhost ([::1]:37650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVzNi-00054X-Ug for importer@patchew.org; Fri, 23 Oct 2020 11:53:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVyva-0007t2-1w for qemu-devel@nongnu.org; Fri, 23 Oct 2020 11:24:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kVyvS-000118-Lw for qemu-devel@nongnu.org; Fri, 23 Oct 2020 11:24: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-308-jD6lRgjFMHWFj3byhk82Lg-1; Fri, 23 Oct 2020 11:24:13 -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 11E67CE66E; Fri, 23 Oct 2020 15:23:45 +0000 (UTC) Received: from localhost (ovpn-114-178.ams2.redhat.com [10.36.114.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2D5019646; Fri, 23 Oct 2020 15:23:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603466657; 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=zsCaudaCAP8PkpNHWaEzotujmMeJdOjxs146kNuomrY=; b=eWnsoWejaPD6NVce8PVSFZARkZMzs2fY6BM8kB4ogh650QrifB9snKwzV+yzP4TEC+GAAW ySxMh1kFtYqVncq0fbrz/xVjntnty8EAqUlaJQgjpbYv6HC4eUzw5AdU0jC8u2aL5izA05 UjsNTCfTv6w74SpX2/gz0dq86KC9w58= X-MC-Unique: jD6lRgjFMHWFj3byhk82Lg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL v3 22/28] block/export: add iothread and fixed-iothread options Date: Fri, 23 Oct 2020 16:21:41 +0100 Message-Id: <20201023152147.1016281-23-stefanha@redhat.com> In-Reply-To: <20201023152147.1016281-1-stefanha@redhat.com> References: <20201023152147.1016281-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/23 02:46:25 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" 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 a24fadcfb5..c3478c6c97 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