From nobody Tue Apr 15 21:45:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1570710309; cv=none; d=zoho.com; s=zohoarc; b=QKy6uv9Q6njwPeWASD51SDb/JOLlFiOTFo+FXLh6G7PyGGgL/O42ABkO7NKUENQYo602U3O4ooPxWQO8WHzbWS+VDtpp2KmAnAVRNmeyRGCUwei+KVzyS4XsIPTgaC0QaUsaLbByqBTigL2UD8SdVbJ1qRs2AkuoxY6LSdi8frg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570710309; h=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=GkH6ErTklJbqcFNvwQTZ6lADPmuIj21rUexgyxZTD8g=; b=RFCldKhoiDBm/xZ/J8N/QvguxQkAB8oCZu5+rhPc0TSAVJ3B7KNZ6n9jMkBe4WuZwVz20egJTvrZvB66ZZq2GpGZQMpCoALL84U3J5EnOkOwQIy4z06z0slfRjQrf7X1VzAaq6pOrqvjJEuI4j8KwKrd2UypnMoKwbRCSbMz5GI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1570710309036701.777473039953; Thu, 10 Oct 2019 05:25:09 -0700 (PDT) Received: from localhost ([::1]:37166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIXVD-0003zC-64 for importer@patchew.org; Thu, 10 Oct 2019 08:25:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51998) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIWrF-0006pW-I6 for qemu-devel@nongnu.org; Thu, 10 Oct 2019 07:43:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIWrE-0008IC-CZ for qemu-devel@nongnu.org; Thu, 10 Oct 2019 07:43:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20545) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIWrB-0008GR-UA; Thu, 10 Oct 2019 07:43: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 mx1.redhat.com (Postfix) with ESMTPS id 2A85A20E9; Thu, 10 Oct 2019 11:43:45 +0000 (UTC) Received: from localhost (unknown [10.36.118.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4D9C5DA2C; Thu, 10 Oct 2019 11:43:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 19/36] block: add empty account cookie type Date: Thu, 10 Oct 2019 13:42:43 +0200 Message-Id: <20191010114300.7746-20-mreitz@redhat.com> In-Reply-To: <20191010114300.7746-1-mreitz@redhat.com> References: <20191010114300.7746-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Thu, 10 Oct 2019 11:43:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 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 , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Anton Nefedov Each block_acct_done/failed call is designed to correspond to a previous block_acct_start call, which initializes the stats cookie. However sometimes it is not the case, e.g. some error paths might report the same cookie twice because it is hard to accurately track if the cookie was reported yet or not. This patch cleans the cookie after report. (Note: block_acct_failed/done without a previous block_acct_start at all should be avoided. Uninitialized cookie might hold a garbage value and there is still "< BLOCK_MAX_IOTYPE" assertion for that) It will be particularly useful in ide code where it's hard to keep track whether the request done its accounting or not: in the following patch of the series, trim requests will do the accounting separately. Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy Message-id: 20190923121737.83281-4-anton.nefedov@virtuozzo.com Signed-off-by: Max Reitz --- include/block/accounting.h | 1 + block/accounting.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/block/accounting.h b/include/block/accounting.h index ba8b04d572..878b4c3581 100644 --- a/include/block/accounting.h +++ b/include/block/accounting.h @@ -33,6 +33,7 @@ typedef struct BlockAcctTimedStats BlockAcctTimedStats; typedef struct BlockAcctStats BlockAcctStats; =20 enum BlockAcctType { + BLOCK_ACCT_NONE =3D 0, BLOCK_ACCT_READ, BLOCK_ACCT_WRITE, BLOCK_ACCT_FLUSH, diff --git a/block/accounting.c b/block/accounting.c index 70a3d9a426..8d41c8a83a 100644 --- a/block/accounting.c +++ b/block/accounting.c @@ -195,6 +195,10 @@ static void block_account_one_io(BlockAcctStats *stats= , BlockAcctCookie *cookie, =20 assert(cookie->type < BLOCK_MAX_IOTYPE); =20 + if (cookie->type =3D=3D BLOCK_ACCT_NONE) { + return; + } + qemu_mutex_lock(&stats->lock); =20 if (failed) { @@ -217,6 +221,8 @@ static void block_account_one_io(BlockAcctStats *stats,= BlockAcctCookie *cookie, } =20 qemu_mutex_unlock(&stats->lock); + + cookie->type =3D BLOCK_ACCT_NONE; } =20 void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie) --=20 2.21.0