From nobody Mon Feb 9 05:41:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633460296; cv=none; d=zohomail.com; s=zohoarc; b=Dd2gbNqXQnzTHFL8Bw5+T7xRB7/QgHft3jhWZ/PNrzJRrJMOE8k31n1+0bKInsX3XHjdgmCDQGJRnBkUAdyEp5qej83tXRbGcJWcttJj09PZWhNaDALVFzqCLxY3z/Z5CbWdns8Q4MJA55DIYnHN69mXEHZQrHKI7P09awnalq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633460296; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=+W7Y6rnsDDZf/ETt0uqjFCnv3qWeNLJXTQ9FgIMtpVs=; b=DGP87QoH7Uz52Bj+P1muULL321akEUNciBIYr6RH8PE/PCjC5NWFvp1dfX3FMD7E8bSaIMKQUbEzXpYKB11Ju20I/8nHbPDmGsoDiFQl8ijSQKkFxIVKHvW2gOgvFmA10eey+7PykjSLiyQt0GW+clf8X/OjBYVFwjsNI6sx0d0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633460296791660.7409945129582; Tue, 5 Oct 2021 11:58:16 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-135-QMsCF81bPFqFrx8FP6gfjA-1; Tue, 05 Oct 2021 14:58:14 -0400 Received: by mail-wr1-f72.google.com with SMTP id k2-20020adff5c2000000b00160b12639a5so78661wrp.3 for ; Tue, 05 Oct 2021 11:58:14 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (118.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.118]) by smtp.gmail.com with ESMTPSA id e14sm8762358wrw.33.2021.10.05.11.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 11:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633460295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+W7Y6rnsDDZf/ETt0uqjFCnv3qWeNLJXTQ9FgIMtpVs=; b=LuWTkjx8hm+188Y2/v/zZjjdsO1fkVRxbcfXzCsOx/pO87Q/WgnV0loOdyUs6FfCt8DGLt U5X2aV6hWBBPv/V+xsdpGAkjgXS4N1W/ZJImtYS6WYz276j+ORlOygWKDRbAVSV+uhkR2u +/oeBRgtY6YvK5Q04gUQ0R5iwbwGRY4= X-MC-Unique: QMsCF81bPFqFrx8FP6gfjA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+W7Y6rnsDDZf/ETt0uqjFCnv3qWeNLJXTQ9FgIMtpVs=; b=ikLN5wppxqEkqwH42oSPohPA1IhQQ5w2xpTj3TlLdCIweAz1tvJVm0IMf0uB/nal2D +e8ubyrG42aFhkTOIlTXC81s2gRV3awwv0JoGW2LF+5eZnZSHpnkv2e5Qv/EUAvCa+gw OiEKPlaz2Ah6hEvLCmge2kk3fchADG7Jx5KPN3DvVvRwhrG+JuL0v3O89bXXaGyaGXKE 2PKGbapOa7F+AiuEMYEUGzX2BiIcswobGQpuLehEk/BLO5I01jOO9Feo1OSqYWo+ZytE LF0Lf44HrlDcdBhfq74Rm+ZGaZ5+jsyCmtI0exIxcyAjgZaQ8dSYpJ8ilBT3OdblZx6u cmYw== X-Gm-Message-State: AOAM533Yc/y2oLwRnWw5PjgdK0LqjHB4KZIDI8ij/NA87hOrVk2WwRpF tVHuHuxHX19f0Zs51ymkyM4jUDlPegNyWq+cxLvCHCExfHwEq5JvD1kWM4eoUfZzMiaYNQH7plD IIDM5BucKaTuDow== X-Received: by 2002:a7b:c954:: with SMTP id i20mr5325420wml.126.1633460293610; Tue, 05 Oct 2021 11:58:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwidVFBmid0TDIDnJBkgBPtHJbHDrccdTXyE39Dq8J28z1hKYZoZJx3yeUgSE41KAWAMMDktg== X-Received: by 2002:a7b:c954:: with SMTP id i20mr5325359wml.126.1633460293104; Tue, 05 Oct 2021 11:58:13 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Stefan Hajnoczi , "Michael S. Tsirkin" , Fam Zheng , Hanna Reitz , Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH 1/4] block/aio: Add automatically released aio_context variants Date: Tue, 5 Oct 2021 20:58:04 +0200 Message-Id: <20211005185807.4134557-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211005185807.4134557-1-philmd@redhat.com> References: <20211005185807.4134557-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633460298895100003 Similarly to commit 5626f8c6d46 ("rcu: Add automatically released rcu_read_lock variants"): AIO_CONTEXT_ACQUIRE_GUARD() acquires the aio context and then uses glib's g_auto infrastructure (and thus whatever the compiler's hooks are) to release it on all exits of the block. WITH_AIO_CONTEXT_ACQUIRE_GUARD() is similar but is used as a wrapper for the lock, i.e.: WITH_AIO_CONTEXT_ACQUIRE_GUARD() { stuff with context acquired } Inspired-by: Dr. David Alan Gilbert Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/block/aio.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/block/aio.h b/include/block/aio.h index 47fbe9d81f2..4fa5a5c2720 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -294,6 +294,30 @@ void aio_context_acquire(AioContext *ctx); /* Relinquish ownership of the AioContext. */ void aio_context_release(AioContext *ctx); =20 +static inline AioContext *aio_context_auto_acquire(AioContext *ctx) +{ + aio_context_acquire(ctx); + return ctx; +} + +static inline void aio_context_auto_release(AioContext *ctx) +{ + aio_context_release(ctx); +} + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(AioContext, aio_context_auto_release) + +#define WITH_AIO_CONTEXT_ACQUIRE_GUARD(ctx) \ + WITH_AIO_CONTEXT_ACQUIRE_GUARD_(glue(_aio_context_auto, __COUNTER__), = ctx) + +#define WITH_AIO_CONTEXT_ACQUIRE_GUARD_(var, ctx) \ + for (g_autoptr(AioContext) var =3D aio_context_auto_acquire(ctx); \ + (var); aio_context_auto_release(var), (var) =3D NULL) + +#define AIO_CONTEXT_ACQUIRE_GUARD(ctx) \ + g_autoptr(AioContext) _aio_context_auto __attribute__((unused)) \ + =3D aio_context_auto_acquire(ctx) + /** * aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that= will * run only once and as soon as possible. --=20 2.31.1