All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hanna Czenczek <hreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, Hanna Czenczek <hreitz@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>, John Snow <jsnow@redhat.com>,
	"Denis V . Lunev" <den@openvz.org>,
	Eric Blake <eblake@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH 5/9] block/accounting: Add BB field to latency checker
Date: Mon, 31 Aug 2026 15:52:01 +0200	[thread overview]
Message-ID: <20260831135206.126184-6-hreitz@redhat.com> (raw)
In-Reply-To: <20260831135206.126184-1-hreitz@redhat.com>

The BlockBackend reference is required to be able to generate the QOM
path as part of emitted events.

A weak reference is enough because BlockAcctStats is tied directly to
one BlockBackend, and will be deleted via block_acct_cleanup() before
the BlockBackend is truly deleted.

Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
---
 include/block/accounting.h | 3 ++-
 block/accounting.c         | 7 ++++++-
 block/block-backend.c      | 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/block/accounting.h b/include/block/accounting.h
index 9386440ec89..025536239e6 100644
--- a/include/block/accounting.h
+++ b/include/block/accounting.h
@@ -81,6 +81,7 @@ typedef struct BlockLatencyHistogram {
 
 struct BlockAcctStats {
     QemuMutex lock;
+    BlockBackend *blk;
     uint64_t nr_bytes[BLOCK_MAX_IOTYPE];
     uint64_t nr_ops[BLOCK_MAX_IOTYPE];
     uint64_t invalid_ops[BLOCK_MAX_IOTYPE];
@@ -101,7 +102,7 @@ typedef struct BlockAcctCookie {
     enum BlockAcctType type;
 } BlockAcctCookie;
 
-void block_acct_init(BlockAcctStats *stats);
+void block_acct_init(BlockBackend *blk, BlockAcctStats *stats);
 bool block_acct_setup(BlockAcctStats *stats, enum OnOffAuto account_invalid,
                       enum OnOffAuto account_failed, uint32_t *stats_intervals,
                       uint32_t num_stats_intervals, Error **errp);
diff --git a/block/accounting.c b/block/accounting.c
index 66e5001403f..a74551d41f2 100644
--- a/block/accounting.c
+++ b/block/accounting.c
@@ -33,7 +33,7 @@
 static QEMUClockType clock_type = QEMU_CLOCK_REALTIME;
 static const int qtest_latency_ns = NANOSECONDS_PER_SECOND / 1000;
 
-void block_acct_init(BlockAcctStats *stats)
+void block_acct_init(BlockBackend *blk, BlockAcctStats *stats)
 {
     qemu_mutex_init(&stats->lock);
     if (qtest_enabled()) {
@@ -41,6 +41,11 @@ void block_acct_init(BlockAcctStats *stats)
     }
     stats->account_invalid = true;
     stats->account_failed = true;
+    /*
+     * No need to blk_ref() because block_acct_cleanup() is called exactly when
+     * the BB is deleted.
+     */
+    stats->blk = blk;
 }
 
 static bool bool_from_onoffauto(OnOffAuto val, bool def)
diff --git a/block/block-backend.c b/block/block-backend.c
index 164bda846f4..ca091a8bf5d 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -369,7 +369,7 @@ BlockBackend *blk_new(AioContext *ctx, uint64_t perm, uint64_t shared_perm)
     blk->on_read_error = BLOCKDEV_ON_ERROR_REPORT;
     blk->on_write_error = BLOCKDEV_ON_ERROR_ENOSPC;
 
-    block_acct_init(&blk->stats);
+    block_acct_init(blk, &blk->stats);
 
     qemu_mutex_init(&blk->queued_requests_lock);
     qemu_co_queue_init(&blk->queued_requests);
-- 
2.55.0



  parent reply	other threads:[~2026-08-31 13:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 13:51 [PATCH 0/9] block: BLOCK_IO_DELAY event Hanna Czenczek
2026-08-31 13:51 ` [PATCH 1/9] block/accounting: Add offset to BlockAcctCookie Hanna Czenczek
2026-09-07 10:05   ` Jesper Wendel Devantier
2026-08-31 13:51 ` [PATCH 2/9] qapi/block: Add IoAccountingOperation enum Hanna Czenczek
2026-09-03 14:32   ` Markus Armbruster
2026-08-31 13:51 ` [PATCH 3/9] qapi/block: Add BLOCK_IO_DELAY event Hanna Czenczek
2026-09-03 14:36   ` Markus Armbruster
2026-08-31 13:52 ` [PATCH 4/9] block-backend: Public blk_get_attached_dev_path() Hanna Czenczek
2026-08-31 13:52 ` Hanna Czenczek [this message]
2026-08-31 13:52 ` [PATCH 6/9] block/accounting: Emit BLOCK_IO_DELAY event Hanna Czenczek
2026-09-03 14:23   ` Stefan Hajnoczi
2026-08-31 13:52 ` [PATCH 7/9] block: Add delay-alert-ms property Hanna Czenczek
2026-09-03 14:30   ` Stefan Hajnoczi
2026-08-31 13:52 ` [PATCH 8/9] block/accounting: Move latency_ns override down Hanna Czenczek
2026-09-03 15:08   ` Stefan Hajnoczi
2026-08-31 13:52 ` [PATCH 9/9] iotests: Add delay-alert test Hanna Czenczek
2026-09-03 15:16   ` Stefan Hajnoczi
2026-09-03 14:08 ` [PATCH 0/9] block: BLOCK_IO_DELAY event Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260831135206.126184-6-hreitz@redhat.com \
    --to=hreitz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.