From patchwork Thu Apr 20 11:37:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 13218579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1921BC77B76 for ; Thu, 20 Apr 2023 11:38:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.524142.814848 (Exim 4.92) (envelope-from ) id 1ppScg-0004tf-D3; Thu, 20 Apr 2023 11:38:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 524142.814848; Thu, 20 Apr 2023 11:38:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppScg-0004tP-93; Thu, 20 Apr 2023 11:38:46 +0000 Received: by outflank-mailman (input) for mailman id 524142; Thu, 20 Apr 2023 11:38:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppSce-0001nK-BX for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:38:44 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e64fda60-df6f-11ed-8611-37d641c3527e; Thu, 20 Apr 2023 13:38:42 +0200 (CEST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-zMSb4NMHMQGsHyfUy_KGfA-1; Thu, 20 Apr 2023 07:38:40 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 59959886063; Thu, 20 Apr 2023 11:38:39 +0000 (UTC) Received: from localhost (unknown [10.39.193.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95E6F492C3E; Thu, 20 Apr 2023 11:38:38 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e64fda60-df6f-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681990721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TBoAHwSzsacA9uVcaYGhwuzX40gWj9dN8dhM1t9uyLM=; b=IOM8cZKyFfKXM8lt2kn57jDDH/ibCphamlDD/EO4eSbo/Gx5FtLV5ylddDsXEV+Yc/ImAl fQWgpzKa5KfZUBxC6IrggOH3MXlCE8EBjorDgbxErDZjKx0rkKXkBcpDzH0q5oYXlZy3QG gEMHbEfbYtk9NVxh490V9j2w1aWyYhs= X-MC-Unique: zMSb4NMHMQGsHyfUy_KGfA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Peter Lieven , Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Xie Yongji , Juan Quintela , qemu-block@nongnu.org, Eduardo Habkost , Richard Henderson , David Woodhouse , Stefan Weil , Fam Zheng , Julia Suvorova , Ronnie Sahlberg , xen-devel@lists.xenproject.org, Hanna Reitz , "Dr. David Alan Gilbert" , eesposit@redhat.com, Kevin Wolf , Marcel Apfelbaum , Stefano Stabellini , Paul Durrant , Aarushi Mehta , "Michael S. Tsirkin" , Anthony Perard , "Richard W.M. Jones" , Coiby Xu , Stefano Garzarella Subject: [PATCH v3 10/20] block: drain from main loop thread in bdrv_co_yield_to_drain() Date: Thu, 20 Apr 2023 07:37:22 -0400 Message-Id: <20230420113732.336620-11-stefanha@redhat.com> In-Reply-To: <20230420113732.336620-1-stefanha@redhat.com> References: <20230420113732.336620-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 For simplicity, always run BlockDevOps .drained_begin/end/poll() callbacks in the main loop thread. This makes it easier to implement the callbacks and avoids extra locks. Move the function pointer declarations from the I/O Code section to the Global State section in block-backend-common.h. Signed-off-by: Stefan Hajnoczi --- include/sysemu/block-backend-common.h | 25 +++++++++++++------------ block/io.c | 3 ++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/sysemu/block-backend-common.h b/include/sysemu/block-backend-common.h index 2391679c56..780cea7305 100644 --- a/include/sysemu/block-backend-common.h +++ b/include/sysemu/block-backend-common.h @@ -59,6 +59,19 @@ typedef struct BlockDevOps { */ bool (*is_medium_locked)(void *opaque); + /* + * Runs when the backend receives a drain request. + */ + void (*drained_begin)(void *opaque); + /* + * Runs when the backend's last drain request ends. + */ + void (*drained_end)(void *opaque); + /* + * Is the device still busy? + */ + bool (*drained_poll)(void *opaque); + /* * I/O API functions. These functions are thread-safe. * @@ -76,18 +89,6 @@ typedef struct BlockDevOps { * Runs when the size changed (e.g. monitor command block_resize) */ void (*resize_cb)(void *opaque); - /* - * Runs when the backend receives a drain request. - */ - void (*drained_begin)(void *opaque); - /* - * Runs when the backend's last drain request ends. - */ - void (*drained_end)(void *opaque); - /* - * Is the device still busy? - */ - bool (*drained_poll)(void *opaque); } BlockDevOps; /* diff --git a/block/io.c b/block/io.c index db438c7657..6285d67546 100644 --- a/block/io.c +++ b/block/io.c @@ -331,7 +331,8 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, if (ctx != co_ctx) { aio_context_release(ctx); } - replay_bh_schedule_oneshot_event(ctx, bdrv_co_drain_bh_cb, &data); + replay_bh_schedule_oneshot_event(qemu_get_aio_context(), + bdrv_co_drain_bh_cb, &data); qemu_coroutine_yield(); /* If we are resumed from some other event (such as an aio completion or a