[PULL,19/36] block: add empty account cookie type
diff mbox series

Message ID 20191010114300.7746-20-mreitz@redhat.com
State New
Headers show
  • [PULL,01/36] qemu-iotests: ignore leaks on failure paths in 026
Related show

Commit Message

Max Reitz Oct. 10, 2019, 11:42 a.m. UTC
From: Anton Nefedov <anton.nefedov@virtuozzo.com>

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

Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20190923121737.83281-4-anton.nefedov@virtuozzo.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
 include/block/accounting.h | 1 +
 block/accounting.c         | 6 ++++++
 2 files changed, 7 insertions(+)

diff mbox series

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;
 enum BlockAcctType {
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,
     assert(cookie->type < BLOCK_MAX_IOTYPE);
+    if (cookie->type == BLOCK_ACCT_NONE) {
+        return;
+    }
     if (failed) {
@@ -217,6 +221,8 @@  static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie,
+    cookie->type = BLOCK_ACCT_NONE;
 void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie)