From nobody Mon Feb 9 07:06:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502215384320253.19763678600884; Tue, 8 Aug 2017 11:03:04 -0700 (PDT) Received: from localhost ([::1]:43935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df8qN-0004ct-6U for importer@patchew.org; Tue, 08 Aug 2017 14:03:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df8lf-0001Ez-Ry for qemu-devel@nongnu.org; Tue, 08 Aug 2017 13:58:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1df8le-0002dq-Lw for qemu-devel@nongnu.org; Tue, 08 Aug 2017 13:58:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1df8lZ-0002b6-Ma; Tue, 08 Aug 2017 13:58:05 -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 mx1.redhat.com (Postfix) with ESMTPS id 95DFF61488; Tue, 8 Aug 2017 17:58:04 +0000 (UTC) Received: from probe.redhat.com (ovpn-123-63.rdu2.redhat.com [10.10.123.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id C93B07093A; Tue, 8 Aug 2017 17:57:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 95DFF61488 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jsnow@redhat.com From: John Snow To: qemu-block@nongnu.org Date: Tue, 8 Aug 2017 13:57:10 -0400 Message-Id: <20170808175711.12203-4-jsnow@redhat.com> In-Reply-To: <20170808175711.12203-1-jsnow@redhat.com> References: <20170808175711.12203-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 08 Aug 2017 17:58:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/4] block-backend: shift in-flight counter to BB from BDS X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, John Snow , pjp@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Kevin Wolf This allows us to detect errors in cache flushing (ENOMEDIUM) without choking on a null dereference because we assume that blk_bs(bb) is always defined. Signed-off-by: Kevin Wolf Signed-off-by: John Snow --- block.c | 2 +- block/block-backend.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index ce9cce7..834b836 100644 --- a/block.c +++ b/block.c @@ -4476,7 +4476,7 @@ out: =20 AioContext *bdrv_get_aio_context(BlockDriverState *bs) { - return bs->aio_context; + return bs ? bs->aio_context : qemu_get_aio_context(); } =20 void bdrv_coroutine_enter(BlockDriverState *bs, Coroutine *co) diff --git a/block/block-backend.c b/block/block-backend.c index 968438c..efd7e92 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -68,6 +68,9 @@ struct BlockBackend { NotifierList remove_bs_notifiers, insert_bs_notifiers; =20 int quiesce_counter; + + /* Number of in-flight requests. Accessed with atomic ops. */ + unsigned int in_flight; }; =20 typedef struct BlockBackendAIOCB { @@ -1109,6 +1112,16 @@ int blk_make_zero(BlockBackend *blk, BdrvRequestFlag= s flags) return bdrv_make_zero(blk->root, flags); } =20 +static void blk_inc_in_flight(BlockBackend *blk) +{ + atomic_inc(&blk->in_flight); +} + +static void blk_dec_in_flight(BlockBackend *blk) +{ + atomic_dec(&blk->in_flight); +} + static void error_callback_bh(void *opaque) { struct BlockBackendAIOCB *acb =3D opaque; @@ -1147,7 +1160,7 @@ static const AIOCBInfo blk_aio_em_aiocb_info =3D { static void blk_aio_complete(BlkAioEmAIOCB *acb) { if (acb->has_returned) { - bdrv_dec_in_flight(acb->common.bs); + blk_dec_in_flight(acb->rwco.blk); acb->common.cb(acb->common.opaque, acb->rwco.ret); qemu_aio_unref(acb); } @@ -1168,7 +1181,7 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, in= t64_t offset, int bytes, BlkAioEmAIOCB *acb; Coroutine *co; =20 - bdrv_inc_in_flight(blk_bs(blk)); + blk_inc_in_flight(blk); acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); acb->rwco =3D (BlkRwCo) { .blk =3D blk, @@ -1405,14 +1418,28 @@ int blk_flush(BlockBackend *blk) =20 void blk_drain(BlockBackend *blk) { - if (blk_bs(blk)) { - bdrv_drain(blk_bs(blk)); + AioContext *ctx =3D blk_get_aio_context(blk); + + while (atomic_read(&blk->in_flight)) { + aio_context_acquire(ctx); + aio_poll(ctx, false); + aio_context_release(ctx); + + if (blk_bs(blk)) { + bdrv_drain(blk_bs(blk)); + } } } =20 void blk_drain_all(void) { - bdrv_drain_all(); + BlockBackend *blk =3D NULL; + + bdrv_drain_all_begin(); + while ((blk =3D blk_all_next(blk)) !=3D NULL) { + blk_drain(blk); + } + bdrv_drain_all_end(); } =20 void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, @@ -1453,10 +1480,11 @@ static void send_qmp_error_event(BlockBackend *blk, bool is_read, int error) { IoOperationType optype; + BlockDriverState *bs =3D blk_bs(blk); =20 optype =3D is_read ? IO_OPERATION_TYPE_READ : IO_OPERATION_TYPE_WRITE; qapi_event_send_block_io_error(blk_name(blk), - bdrv_get_node_name(blk_bs(blk)), optype, + bs ? bdrv_get_node_name(bs) : "", optyp= e, action, blk_iostatus_is_enabled(blk), error =3D=3D ENOSPC, strerror(error), &error_abort); --=20 2.9.4