From nobody Sat Apr 11 18:38:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1775833610; cv=none; d=zohomail.com; s=zohoarc; b=FuzvbfFbygTB1Dp0f6o320L66hT1bNq65fWhkWu3maZuPRH+x5Ng/eCFFH+e62H4xYrM5VesJvrQz2VS6Ix1nyMpOn9dZUxmTyuaKjP1Tkk3SbP1z0YVZ80OY5b5HMq/fu6LYod4ibXGXsaZ3tM79BqjVQLcZwXbML9opvIQr48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775833610; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6M/hoXWqBMvPhrdOYgRm4aU7iBbj+zMMvv5Gl5LllJg=; b=EymO5tSqFtAwi/vz20IiHYVc4pwCZ7EUNbbZ4yCKKnOSiJEyBgY8dV+ulCmm8nNOlUpv60hPBwL2sIucO12ItyWYx3wNGiv+m41F0ZYWSTRGRuchvkylDR4LvKE8aF8WDLdpsCfPVk5cbYe7+bbXxuCBrSNJU0nw9RB67Vu4YRM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775833610151304.59498666814125; Fri, 10 Apr 2026 08:06:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBDQL-0006pF-EQ; Fri, 10 Apr 2026 11:05:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBDQK-0006l6-0w for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:32 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wBDQH-0002LW-O2 for qemu-devel@nongnu.org; Fri, 10 Apr 2026 11:05:31 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-35d90833cacso1542931a91.2 for ; Fri, 10 Apr 2026 08:05:29 -0700 (PDT) Received: from ZBMac-LWN10QXKQ0.taila0cd24.ts.net ([104.168.88.121]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35e4131cfacsm3565785a91.10.2026.04.10.08.05.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Apr 2026 08:05:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775833528; x=1776438328; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6M/hoXWqBMvPhrdOYgRm4aU7iBbj+zMMvv5Gl5LllJg=; b=Livk5s4iJrbYf9+e4iZU96kPP0FKJVmXw1n5roxOrimeuMn7p5b0irMjci7BP+rs5b JzkRSC8Tis91gWmWHEi4W6Js3FXSYgtwySMIRbin9VPVc7kXNeeZNCycyPjufEvcqG0e sdCoSLAtfbwtB9VquJ0TJ0jPQ+qoAxtT+oVs83cOeUsETu5veDM7wD0A1mL1s15g3B8s 3g0RkEqURNJyLshI0skHEkP+2Bg++E5KKJe9V8yRAn595jAJZibmcIeXYCR+Lrie63xJ 8Rntfd2yT6wrmzt8UHl59Onv/eMr6m9XuUehjPercT/0Wz1RsifGzL9XlWkF6EvTWP25 9NyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775833528; x=1776438328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6M/hoXWqBMvPhrdOYgRm4aU7iBbj+zMMvv5Gl5LllJg=; b=NeSh3xm3f8NwznlBZzMHzlIyn2tu0YjCM+qdkMAXppHWelkhGB2ASrP3J2y8zZoqK/ H7LFD8wPEgK7p6BBTg06BJdRVWmP3IB1pMjsNPBzmZa1iP0K00jZtuL4H8Yu4QLRmD13 O1A9N6Ag010qtlyma3EZs3fnOKUfEHsnj/czMCt6iH4Tgm3oWDRfIUD3O9stFyK4r87F twa6mBW8PmmlAdNnJvSfS2HVxcVUAIym+3VIHxEWOckyftKEdLmJbTmCHKvcZ7IjuSmL Jf2zbwMPLl3Q+L2vX2q2eEfmcALf6AND2oVUB8PQ5Rf2jBOUDhLFpbPmWI/XrVSjy2q8 Ma5Q== X-Gm-Message-State: AOJu0YyNeJyjMzNv3iMxVPRuFdEs/x72BaoElfbFFwWFRNEj3rnmNl6g CaCTT2xMUGdVMM+e7sI9QjxvK/DN5+48Yp9LI7BG1QvNwFUW9TPc1m9E3TiV5yWE X-Gm-Gg: AeBDiev9o5iHqNN3Cdyx21Jt+3qhGyLLihu/vw0EjxkPUuw6KnC3VSMgF7EXguTt911 CBcG34Xu3FZGQMJPzscSufPqSukh/bIdMyHbAlec/sPUuSXyJ1LvHBcfzau8uz2S2+QEAAKIfM/ SFDpN8g4OCsaNLeDuDqxZ1SQVOw7/xH+ZfDm2n727RRwtd06vo/gPJTf+mQtn71mzRdq26f9MkL XIPhvFZEMl9zk5Xustx4RsRG9SB4546b10jYdPkUUV2vpzLUY26B+Vu/dtsnQclAUxrkeEq5WKb gZhGlNMh7ubi5EJDuWBDhD8uqkyubWB+xadLTWfA4VW3IcuhkrUvJ/UK3+2vENHtndgF/Bh5XY5 Cf3dKSxSei1PyrPWTtQ3Ii4hT60wbnHbi2IMKqMT3SfBIGlGivbJrWn8zFCQ2u72iJf7b+Bo15Q FZtFVKk8De94Y2ytGEc/0Df/XKO6Hn8l4pNdRUV+JARzD5jjCeUmAr X-Received: by 2002:a17:90b:3c48:b0:35b:e690:c5ad with SMTP id 98e67ed59e1d1-35e42849e8cmr3830790a91.25.1775833527394; Fri, 10 Apr 2026 08:05:27 -0700 (PDT) From: Zhang Chen To: qemu-devel , "Dr . David Alan Gilbert" , Eric Blake , Markus Armbruster , "Michael S . Tsirkin" , Stefan Hajnoczi Cc: Zhang Chen Subject: [PATCH V6 05/14] block/export: track IOThread reference in BlockExport Date: Fri, 10 Apr 2026 23:04:48 +0800 Message-ID: <20260410150457.85190-6-zhangckid@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260410150457.85190-1-zhangckid@gmail.com> References: <20260410150457.85190-1-zhangckid@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=zhangckid@gmail.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1775833611554158500 Content-Type: text/plain; charset="utf-8" Users currently lack visibility into which block exports are utilizing specific IOThreads. This patch integrates IOThread referencing into the BlockExport lifecycle. - Add iothreads array and holder_name to BlockExport struct. - Use iothread_ref_and_get_aio_context during export creation. - Implement proper cleanup in blk_exp_add fail path and blk_exp_delete_bh. - Support both single and multi-iothread export configurations. This ensures IOThread 'holders' status correctly reflects active block exports for better debugging and resource tracking. Signed-off-by: Zhang Chen --- block/export/export.c | 44 +++++++++++++++++++++++++++++++++--------- include/block/export.h | 6 ++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/block/export/export.c b/block/export/export.c index b733f269f3..636633c324 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -15,7 +15,6 @@ =20 #include "block/block.h" #include "system/block-backend.h" -#include "system/iothread.h" #include "block/export.h" #include "block/fuse.h" #include "block/nbd.h" @@ -85,6 +84,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Erro= r **errp) AioContext *ctx; AioContext **multithread_ctxs =3D NULL; size_t multithread_count =3D 0; + g_autofree IOThread **local_iothreads =3D NULL; + const char *holder_name =3D NULL; uint64_t perm; int ret; =20 @@ -139,7 +140,11 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) goto fail; } =20 - new_ctx =3D iothread_get_aio_context(iothread); + holder_name =3D bdrv_get_node_name(bs); + new_ctx =3D iothread_ref_and_get_aio_context(iothread, holder_name= ); + multithread_count =3D 1; + local_iothreads =3D g_new0(IOThread *, 1); + local_iothreads[0] =3D iothread; =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; @@ -163,8 +168,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, E= rror **errp) return NULL; } =20 + local_iothreads =3D g_new0(IOThread *, multithread_count); multithread_ctxs =3D g_new(AioContext *, multithread_count); i =3D 0; + holder_name =3D bdrv_get_node_name(bs); for (strList *e =3D iothread_list; e; e =3D e->next) { IOThread *iothread =3D iothread_by_id(e->value); =20 @@ -172,7 +179,9 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) error_setg(errp, "iothread \"%s\" not found", e->value); goto fail; } - multithread_ctxs[i++] =3D iothread_get_aio_context(iothread); + local_iothreads[i] =3D iothread; + multithread_ctxs[i++] =3D iothread_ref_and_get_aio_context(iot= hread, + holder_n= ame); } assert(i =3D=3D multithread_count); } @@ -225,12 +234,15 @@ BlockExport *blk_exp_add(BlockExportOptions *export, = Error **errp) assert(drv->instance_size >=3D sizeof(BlockExport)); exp =3D g_malloc0(drv->instance_size); *exp =3D (BlockExport) { - .drv =3D drv, - .refcount =3D 1, - .user_owned =3D true, - .id =3D g_strdup(export->id), - .ctx =3D ctx, - .blk =3D blk, + .drv =3D drv, + .refcount =3D 1, + .user_owned =3D true, + .id =3D g_strdup(export->id), + .ctx =3D ctx, + .blk =3D blk, + .iothreads =3D g_steal_pointer(&local_iothreads), + .iothread_count =3D multithread_count, + .iothread_holder_name =3D g_strdup(holder_name), }; =20 ret =3D drv->create(exp, export, multithread_ctxs, multithread_count, = errp); @@ -253,6 +265,13 @@ fail: g_free(exp->id); g_free(exp); } + if (local_iothreads) { + for (size_t j =3D 0; j < multithread_count; j++) { + if (local_iothreads[j]) { + iothread_put_aio_context(local_iothreads[j], holder_name); + } + } + } g_free(multithread_ctxs); return NULL; } @@ -269,6 +288,13 @@ static void blk_exp_delete_bh(void *opaque) BlockExport *exp =3D opaque; =20 assert(exp->refcount =3D=3D 0); + if (exp->iothreads) { + for (size_t i =3D 0; i < exp->iothread_count; i++) { + iothread_put_aio_context(exp->iothreads[i], + exp->iothread_holder_name); + } + g_free(exp->iothreads); + } QLIST_REMOVE(exp, next); exp->drv->delete(exp); blk_set_dev_ops(exp->blk, NULL, NULL); diff --git a/include/block/export.h b/include/block/export.h index ca45da928c..2bb98aae31 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -16,6 +16,7 @@ =20 #include "qapi/qapi-types-block-export.h" #include "qemu/queue.h" +#include "system/iothread.h" =20 typedef struct BlockExport BlockExport; =20 @@ -89,6 +90,11 @@ struct BlockExport { =20 /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; + + /* The iothreads list for block_exports */ + IOThread **iothreads; + size_t iothread_count; + char *iothread_holder_name; }; =20 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); --=20 2.49.0