From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762644391; cv=none; d=zohomail.com; s=zohoarc; b=lsl5gwLi5MbnLyU2tkjFdB6VhCCZ6kqd+XxpNoi518ZCvD1hSVZ/2FcdyFBJUycYbCPCfVkUUkN0YK+Vs2tREry57GgkyHXo9lUzaFA1qFPsvNEVsduFPJQ3qjfomndqQb+958aJYqmLcCZwfcvA5lihZmYDzjMuueokVFMhhwc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762644391; h=Content-Type: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=3zpGiwoNkw9y4Du5TKeywYa7YTBc7fS3KNYRCSB4bHk=; b=mEL8vlmAdex8D0WeivxRA762Il/wIpBeAhLxa+O2VG0RssqrTrvHz2SEnkRdPH8Zrz40nQEMtKimqCKvqeFGOd2QCHgc38ALMiOsupxngXseiU4HKiPj/JjqLN9YdTJuLHCbtxHWMZjw44kC+DA/sygu0MjGlRcbrBVxmYwi/jE= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762644391150223.0089993655165; Sat, 8 Nov 2025 15:26:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0F-0005Ye-FO; Sat, 08 Nov 2025 18:05:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs03-0005ND-HY for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs01-0001dQ-8k for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:39 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-L3PxsogMMt-0pdoTMhuO4Q-1; Sat, 08 Nov 2025 18:05:32 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1697F1800451; Sat, 8 Nov 2025 23:05:31 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EFF2819560A7; Sat, 8 Nov 2025 23:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643135; 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=3zpGiwoNkw9y4Du5TKeywYa7YTBc7fS3KNYRCSB4bHk=; b=BDuDrW1A4kJNMPMXd5cuVlbi7KvaWrKkCxkVjA4QM8T/AO2hgFI1EM7C1iF3G0pMnjT1ee wd2FrCcUFAlcfEdl0YQu3XeWGyOWZeRsQZaWfl2ejTdRHh6t4Hlrb+Hjrs7V8/x1D+rLK3 j65iVJ4O/hWUsFz36GHiTTNRThgqquk= X-MC-Unique: L3PxsogMMt-0pdoTMhuO4Q-1 X-Mimecast-MFC-AGG-ID: L3PxsogMMt-0pdoTMhuO4Q_1762643131 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com Subject: [PATCH v2 01/12] iotests: Drop execute permissions on vvfat.out Date: Sat, 8 Nov 2025 16:59:22 -0600 Message-ID: <20251108230525.3169174-15-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @redhat.com) X-ZM-MESSAGEID: 1762644393206158500 Content-Type: text/plain; charset="utf-8" Output files are not executables. Noticed while preparing another iotest addition. Fixes: c8f60bfb43 ("iotests: Add `vvfat` tests", v9.1.0) Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: split this change to separate patch --- tests/qemu-iotests/tests/vvfat.out | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 =3D> 100644 tests/qemu-iotests/tests/vvfat.out diff --git a/tests/qemu-iotests/tests/vvfat.out b/tests/qemu-iotests/tests/= vvfat.out old mode 100755 new mode 100644 --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762644605; cv=none; d=zohomail.com; s=zohoarc; b=HaYXpdGMemO69bRTeeg/e65hyZjNPHkUps6JGHLG3MAoqM6ZrVKf+41FBNJjKdhnWpah5NnzNc7Bd/KkHfGuizUmPIl9vYqJzALJDl5lGhBzN88g/wOCEtcIF00AxT3AQ0IWmk1TCKzNGvhtlnWcKabOBnukKP43fejfsoL7veI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762644605; h=Content-Type: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=8RbXOGFHGqgI1H/gtUzVCIZikkCvOAXL9Avnt8QXKdQ=; b=J82ob6WzkHGRV8qQrtf5fq4TjxFfJn7ksSbDTVGYYP0/m3Adm9DDXOtkuxKQXhCt+j37WReMqbWyvw7nl2OU3PH+0KTKaqqJyRpADbEhsvbwuLn9wJXVLOXN5Br5NldqH6CwlaeuzP//cPfVYamPjqErUKVxV3/EK1uStC0lj84= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762644605711342.322099509355; Sat, 8 Nov 2025 15:30:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0F-0005YU-BB; Sat, 08 Nov 2025 18:05:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs03-0005NU-Ua for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs01-0001dd-UK for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:39 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-9Ntg46mJOyKBI6iExW6_JQ-1; Sat, 08 Nov 2025 18:05:35 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8685B195605A; Sat, 8 Nov 2025 23:05:34 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5B36519560A7; Sat, 8 Nov 2025 23:05:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643136; 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=8RbXOGFHGqgI1H/gtUzVCIZikkCvOAXL9Avnt8QXKdQ=; b=OMrN/rNdHlTNiWjbAkETGV6E3aW4y6Cy0hUMOFJXUsa7Sw4x0I+Apk4b3XWODbOFTB4LE5 fUMsJOippaFGkbwMkHrKgjG8e/hDPJK1alCBCkplrBM7Y5GKkpV6SuUGHTc2W0D2lMypFw Z4UNpCdS0HMKgbixj3pwvhg2gkOqSMk= X-MC-Unique: 9Ntg46mJOyKBI6iExW6_JQ-1 X-Mimecast-MFC-AGG-ID: 9Ntg46mJOyKBI6iExW6_JQ_1762643134 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com Subject: [PATCH v2 02/12] qio: Add trace points to net_listener Date: Sat, 8 Nov 2025 16:59:23 -0600 Message-ID: <20251108230525.3169174-16-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762644608235158500 Content-Type: text/plain; charset="utf-8" Upcoming patches will adjust how net_listener watches for new client connections; adding trace points now makes it easier to debug that the changes work as intended. For example, adding --trace=3D'qio_net_listener*' to the qemu-storage-daemon command line before --nbd-server will track when the server first starts listening for clients. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: Make tracepoints unconditional, rename to match later refactoring patch, document io_func in unwatch --- io/net-listener.c | 10 ++++++++++ io/trace-events | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/io/net-listener.c b/io/net-listener.c index 47405965a66..007acbd5b18 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -23,6 +23,7 @@ #include "io/dns-resolver.h" #include "qapi/error.h" #include "qemu/module.h" +#include "trace.h" QIONetListener *qio_net_listener_new(void) { @@ -50,6 +51,7 @@ static gboolean qio_net_listener_channel_func(QIOChannel = *ioc, return TRUE; } + trace_qio_net_listener_callback(listener, listener->io_func); if (listener->io_func) { listener->io_func(listener, sioc, listener->io_data); } @@ -123,6 +125,7 @@ void qio_net_listener_add(QIONetListener *listener, object_ref(OBJECT(sioc)); listener->connected =3D true; + trace_qio_net_listener_watch(listener, listener->io_func, "add"); if (listener->io_func !=3D NULL) { object_ref(OBJECT(listener)); listener->io_source[listener->nsioc] =3D qio_channel_add_watch_sou= rce( @@ -143,6 +146,8 @@ void qio_net_listener_set_client_func_full(QIONetListen= er *listener, { size_t i; + trace_qio_net_listener_unwatch(listener, listener->io_func, + "set_client_func"); if (listener->io_notify) { listener->io_notify(listener->io_data); } @@ -158,6 +163,8 @@ void qio_net_listener_set_client_func_full(QIONetListen= er *listener, } } + trace_qio_net_listener_watch(listener, listener->io_func, + "set_client_func"); if (listener->io_func !=3D NULL) { for (i =3D 0; i < listener->nsioc; i++) { object_ref(OBJECT(listener)); @@ -218,6 +225,7 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetLi= stener *listener) }; size_t i; + trace_qio_net_listener_unwatch(listener, listener->io_func, "wait_clie= nt"); for (i =3D 0; i < listener->nsioc; i++) { if (listener->io_source[i]) { g_source_destroy(listener->io_source[i]); @@ -247,6 +255,7 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetLi= stener *listener) g_main_loop_unref(loop); g_main_context_unref(ctxt); + trace_qio_net_listener_watch(listener, listener->io_func, "wait_client= "); if (listener->io_func !=3D NULL) { for (i =3D 0; i < listener->nsioc; i++) { object_ref(OBJECT(listener)); @@ -268,6 +277,7 @@ void qio_net_listener_disconnect(QIONetListener *listen= er) return; } + trace_qio_net_listener_unwatch(listener, listener->io_func, "disconnec= t"); for (i =3D 0; i < listener->nsioc; i++) { if (listener->io_source[i]) { g_source_destroy(listener->io_source[i]); diff --git a/io/trace-events b/io/trace-events index dc3a63ba1fb..10976eca5fe 100644 --- a/io/trace-events +++ b/io/trace-events @@ -72,3 +72,8 @@ qio_channel_command_new_pid(void *ioc, int writefd, int r= eadfd, int pid) "Comman qio_channel_command_new_spawn(void *ioc, const char *binary, int flags) "C= ommand new spawn ioc=3D%p binary=3D%s flags=3D%d" qio_channel_command_abort(void *ioc, int pid) "Command abort ioc=3D%p pid= =3D%d" qio_channel_command_wait(void *ioc, int pid, int ret, int status) "Command= abort ioc=3D%p pid=3D%d ret=3D%d status=3D%d" + +# net-listener.c +qio_net_listener_watch(void *listener, void *func, const char *extra) "Net= listener=3D%p watch enabled func=3D%p by %s" +qio_net_listener_unwatch(void *listener, void *func, const char *extra) "N= et listener=3D%p watch disabled func=3D%p by %s" +qio_net_listener_callback(void *listener, void *func) "Net listener=3D%p c= allback forwarding to func=3D%p" --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762644604; cv=none; d=zohomail.com; s=zohoarc; b=D2l5ZzPy5DV5Aa4O03B9op9xuysuMIop1ase84qQr+dENPQ4twsAvhCkW2OMgtsBAPwK8+ZFb1nYHdM9AU3nya/aINR8+8tR7lHkVsbdZiWBDELoZqa+a8YGLB1fPNd7JqfUg0eCqpYAWdSTydm1vqeRWLZ+qguv3w1TedbFkB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762644604; h=Content-Type: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=udpGvb6GsLzY8Nzx5SVU1xxaApckb0eWOKbbFMkxDfw=; b=F0miKecYcpyiwS7EwdnOHlY9geEs8UYmy6ijGBiG1OLar2x3H/+15nMFFyIElwjzRqILJzPvGROkmYc/SuugkBlFCJRJbeknYD5dik/JAZsoctvzQaQzujS2pe42V5u3KA6fB/jqp718TLorua+n9VaJgmIBZkNLzS7jU9T1tuw= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762644604893270.12157764495976; Sat, 8 Nov 2025 15:30:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0H-0005bT-Ac; Sat, 08 Nov 2025 18:05:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs07-0005Ox-LM for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs06-0001fT-4s for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:43 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-x1Lfxzr8Oi6Jm7BI3CxTQQ-1; Sat, 08 Nov 2025 18:05:37 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4BD7A1800451; Sat, 8 Nov 2025 23:05:36 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E422619560A7; Sat, 8 Nov 2025 23:05:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643141; 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=udpGvb6GsLzY8Nzx5SVU1xxaApckb0eWOKbbFMkxDfw=; b=S4Rz407wGY78MsDJiwJ3ICcvktUvSnXWiScOuzJXP3wAt5NQKqDkJ7KIDCQ9t0iufK9ndq CIz6nkorbHYvVUNeT/kId2gkOpg4SZU9vSv1240cmtVnTd8JYKnL3RgqvMPA6vvn8g0Mde kuyKpyL2G2DYXU9XxYoXd7hhJHYvvKg= X-MC-Unique: x1Lfxzr8Oi6Jm7BI3CxTQQ-1 X-Mimecast-MFC-AGG-ID: x1Lfxzr8Oi6Jm7BI3CxTQQ_1762643136 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com, qemu-stable@nongnu.org Subject: [PATCH v2 03/12] qio: Unwatch before notify in QIONetListener Date: Sat, 8 Nov 2025 16:59:24 -0600 Message-ID: <20251108230525.3169174-17-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @redhat.com) X-ZM-MESSAGEID: 1762644608169158500 Content-Type: text/plain; charset="utf-8" When changing the callback registered with QIONetListener, the code was calling notify on the old opaque data prior to actually removing the old GSource objects still pointing to that data. Similarly, during finalize, it called notify before tearing down the various GSource objects tied to the data. In practice, a grep of the QEMU code base found that every existing client of QIONetListener passes in a NULL notifier (the opaque data, if non-NULL, outlives the NetListener and so does not need cleanup when the NetListener is torn down), so this patch has no impact. And even if a caller had passed in a reference-counted object with a notifier of object_unref but kept its own reference on the data, then the early notify would merely reduce a refcount from (say) 2 to 1, but not free the object. However, it is a latent bug waiting to bite any future caller that passes in data where the notifier actually frees the object, because the GSource could then trigger a use-after-free if it loses the race on a last-minute client connection resulting in the data being passed to one final use of the async callback. Better is to delay the notify call until after all GSource that have been given a copy of the opaque data are torn down. CC: qemu-stable@nongnu.org Fixes: 530473924d "io: introduce a network socket listener API", v2.12.0 Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: new patch, split out from 4/8 to leave that one as just pure refactoring, and call attention to this being a latent bug fix --- io/net-listener.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/io/net-listener.c b/io/net-listener.c index 007acbd5b18..d71b65270e0 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -148,13 +148,6 @@ void qio_net_listener_set_client_func_full(QIONetListe= ner *listener, trace_qio_net_listener_unwatch(listener, listener->io_func, "set_client_func"); - if (listener->io_notify) { - listener->io_notify(listener->io_data); - } - listener->io_func =3D func; - listener->io_data =3D data; - listener->io_notify =3D notify; - for (i =3D 0; i < listener->nsioc; i++) { if (listener->io_source[i]) { g_source_destroy(listener->io_source[i]); @@ -163,6 +156,13 @@ void qio_net_listener_set_client_func_full(QIONetListe= ner *listener, } } + if (listener->io_notify) { + listener->io_notify(listener->io_data); + } + listener->io_func =3D func; + listener->io_data =3D data; + listener->io_notify =3D notify; + trace_qio_net_listener_watch(listener, listener->io_func, "set_client_func"); if (listener->io_func !=3D NULL) { @@ -300,10 +300,10 @@ static void qio_net_listener_finalize(Object *obj) QIONetListener *listener =3D QIO_NET_LISTENER(obj); size_t i; + qio_net_listener_disconnect(listener); if (listener->io_notify) { listener->io_notify(listener->io_data); } - qio_net_listener_disconnect(listener); for (i =3D 0; i < listener->nsioc; i++) { object_unref(OBJECT(listener->sioc[i])); --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762643570; cv=none; d=zohomail.com; s=zohoarc; b=cGlZuoDITktXJANwGZH2VirjtZ6+cYNAXK2LEl6PZ64f3DPX7F7jgTksyNLy28fprM2PfCIjWIyRCi/allV4vAUjT4nZsFfnCmw+i05FhWRIXbqEBUKItqndOyhc1lyvEHbratNweTo+LdhRd2Al20rF0Jr6drJRzd4iuT+gqIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762643570; h=Content-Type: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=xpXc3S2Q3NrPCkGXSUoupnhbTvu0TcNTPyx71+k/Gxw=; b=j+D9W4xVmAfayPS9qZY1ZVOK7nZYsrhCRuKdDC7ggKWe17pytO/Plxi2h5o/z4KIx0o4djQfRce64gq55Rc7nsqEFPSD8jO/Qd+BAuw6XpkKUQL9fC0ZbrBFlktRt0FvJZ/AOdEhwwB5tr1pcW5KdTAD+yzjrRy9rWG/gjh5N0U= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762643570823223.2626723418149; Sat, 8 Nov 2025 15:12:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0I-0005cd-8b; Sat, 08 Nov 2025 18:05:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs07-0005Ov-Iy for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs05-0001fG-JJ for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:43 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-FOCQtf0HPKKJ8mPuSzrzeQ-1; Sat, 08 Nov 2025 18:05:39 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 17385195605F; Sat, 8 Nov 2025 23:05:38 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CCF2419560A7; Sat, 8 Nov 2025 23:05:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643140; 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=xpXc3S2Q3NrPCkGXSUoupnhbTvu0TcNTPyx71+k/Gxw=; b=grL3H4VdfvZocareeZJQeXy3kBr058YEmB1PWr+ouiKBNeGm1SS2a01dPTCyho2oGygYhe cugEnGOiyTXbjCRL1BBZH7MNmVrkCMDjb3MKjdn+gWpqekutzk73JyEQs7IUjeKT9o3NmJ uy1jzg7a/FaopKWUM1HHlTYZHIdYPDQ= X-MC-Unique: FOCQtf0HPKKJ8mPuSzrzeQ-1 X-Mimecast-MFC-AGG-ID: FOCQtf0HPKKJ8mPuSzrzeQ_1762643138 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com, qemu-stable@nongnu.org Subject: [PATCH v2 04/12] qio: Remember context of qio_net_listener_set_client_func_full Date: Sat, 8 Nov 2025 16:59:25 -0600 Message-ID: <20251108230525.3169174-18-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762643573227158500 Content-Type: text/plain; charset="utf-8" io/net-listener.c has two modes of use: asynchronous (the user calls qio_net_listener_set_client_func to wake up the callback via the global GMainContext, or qio_net_listener_set_client_func_full to wake up the callback via the caller's own alternative GMainContext), and synchronous (the user calls qio_net_listener_wait_client which creates its own GMainContext and waits for the first client connection before returning, with no need for a user's callback). But commit 938c8b79 has a latent logic flaw: when qio_net_listener_wait_client finishes on its temporary context, it reverts all of the siocs back to the global GMainContext rather than the potentially non-NULL context they might have been originally registered with. Similarly, if the user creates a net-listener, adds initial addresses, registers an async callback with a non-default context (which ties to all siocs for the initial addresses), then adds more addresses with qio_net_listener_add, the siocs for later addresses are blindly placed in the global context, rather than sharing the context of the earlier ones. In practice, I don't think this has caused issues. As pointed out by the original commit, all async callers prior to that commit were already okay with the NULL default context; and the typical usage pattern is to first add ALL the addresses the listener will pay attention to before ever setting the async callback. Likewise, if a file uses only qio_net_listener_set_client_func instead of qio_net_listener_set_client_func_full, then it is never using a custom context, so later assignments of async callbacks will still be to the same global context as earlier ones. Meanwhile, any callers that want to do the sync operation to grab the first client are unlikely to register an async callback; altogether bypassing the question of whether later assignments of a GSource are being tied to a different context over time. I do note that chardev/char-socket.c is the only file that calls both qio_net_listener_wait_client (sync for a single client in tcp_chr_accept_server_sync), and qio_net_listener_set_client_func_full (several places, all with chr->gcontext, but sometimes with a NULL callback function during teardown). But as far as I can tell, the two uses are mutually exclusive, based on the is_waitconnect parameter to qmp_chardev_open_socket_server. That said, it is more robust to remember when an async callback function is tied to a non-default context, and have both the sync wait and any late address additions honor that same context. That way, the code will be robust even if a later user performs a sync wait for a specific client in the middle of servicing a longer-lived QIONetListener that has an async callback for all other clients. CC: qemu-stable@nongnu.org Fixes: 938c8b79 ("qio: store gsources for net listeners", v2.12.0) Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: move earlier in series, trace context --- include/io/net-listener.h | 1 + io/net-listener.c | 25 ++++++++++++++++--------- io/trace-events | 6 +++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/io/net-listener.h b/include/io/net-listener.h index ab9f291ed62..42fbfab5467 100644 --- a/include/io/net-listener.h +++ b/include/io/net-listener.h @@ -50,6 +50,7 @@ struct QIONetListener { QIOChannelSocket **sioc; GSource **io_source; size_t nsioc; + GMainContext *context; bool connected; diff --git a/io/net-listener.c b/io/net-listener.c index d71b65270e0..0f16b78fbbd 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -51,7 +51,8 @@ static gboolean qio_net_listener_channel_func(QIOChannel = *ioc, return TRUE; } - trace_qio_net_listener_callback(listener, listener->io_func); + trace_qio_net_listener_callback(listener, listener->io_func, + listener->context); if (listener->io_func) { listener->io_func(listener, sioc, listener->io_data); } @@ -125,13 +126,14 @@ void qio_net_listener_add(QIONetListener *listener, object_ref(OBJECT(sioc)); listener->connected =3D true; - trace_qio_net_listener_watch(listener, listener->io_func, "add"); + trace_qio_net_listener_watch(listener, listener->io_func, + listener->context, "add"); if (listener->io_func !=3D NULL) { object_ref(OBJECT(listener)); listener->io_source[listener->nsioc] =3D qio_channel_add_watch_sou= rce( QIO_CHANNEL(listener->sioc[listener->nsioc]), G_IO_IN, qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref, NULL); + listener, (GDestroyNotify)object_unref, listener->context); } listener->nsioc++; @@ -147,7 +149,8 @@ void qio_net_listener_set_client_func_full(QIONetListen= er *listener, size_t i; trace_qio_net_listener_unwatch(listener, listener->io_func, - "set_client_func"); + listener->context, "set_client_func"); + for (i =3D 0; i < listener->nsioc; i++) { if (listener->io_source[i]) { g_source_destroy(listener->io_source[i]); @@ -162,9 +165,10 @@ void qio_net_listener_set_client_func_full(QIONetListe= ner *listener, listener->io_func =3D func; listener->io_data =3D data; listener->io_notify =3D notify; + listener->context =3D context; trace_qio_net_listener_watch(listener, listener->io_func, - "set_client_func"); + listener->context, "set_client_func"); if (listener->io_func !=3D NULL) { for (i =3D 0; i < listener->nsioc; i++) { object_ref(OBJECT(listener)); @@ -225,7 +229,8 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetLi= stener *listener) }; size_t i; - trace_qio_net_listener_unwatch(listener, listener->io_func, "wait_clie= nt"); + trace_qio_net_listener_unwatch(listener, listener->io_func, + listener->context, "wait_client"); for (i =3D 0; i < listener->nsioc; i++) { if (listener->io_source[i]) { g_source_destroy(listener->io_source[i]); @@ -255,14 +260,15 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONet= Listener *listener) g_main_loop_unref(loop); g_main_context_unref(ctxt); - trace_qio_net_listener_watch(listener, listener->io_func, "wait_client= "); + trace_qio_net_listener_watch(listener, listener->io_func, + listener->context, "wait_client"); if (listener->io_func !=3D NULL) { for (i =3D 0; i < listener->nsioc; i++) { object_ref(OBJECT(listener)); listener->io_source[i] =3D qio_channel_add_watch_source( QIO_CHANNEL(listener->sioc[i]), G_IO_IN, qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref, NULL); + listener, (GDestroyNotify)object_unref, listener->context); } } @@ -277,7 +283,8 @@ void qio_net_listener_disconnect(QIONetListener *listen= er) return; } - trace_qio_net_listener_unwatch(listener, listener->io_func, "disconnec= t"); + trace_qio_net_listener_unwatch(listener, listener->io_func, + listener->context, "disconnect"); for (i =3D 0; i < listener->nsioc; i++) { if (listener->io_source[i]) { g_source_destroy(listener->io_source[i]); diff --git a/io/trace-events b/io/trace-events index 10976eca5fe..0cb77d579b6 100644 --- a/io/trace-events +++ b/io/trace-events @@ -74,6 +74,6 @@ qio_channel_command_abort(void *ioc, int pid) "Command ab= ort ioc=3D%p pid=3D%d" qio_channel_command_wait(void *ioc, int pid, int ret, int status) "Command= abort ioc=3D%p pid=3D%d ret=3D%d status=3D%d" # net-listener.c -qio_net_listener_watch(void *listener, void *func, const char *extra) "Net= listener=3D%p watch enabled func=3D%p by %s" -qio_net_listener_unwatch(void *listener, void *func, const char *extra) "N= et listener=3D%p watch disabled func=3D%p by %s" -qio_net_listener_callback(void *listener, void *func) "Net listener=3D%p c= allback forwarding to func=3D%p" +qio_net_listener_watch(void *listener, void *func, void *ctx, const char *= extra) "Net listener=3D%p watch enabled func=3D%p ctx=3D%p by %s" +qio_net_listener_unwatch(void *listener, void *func, void *ctx, const char= *extra) "Net listener=3D%p watch disabled func=3D%p ctx=3D%p by %s" +qio_net_listener_callback(void *listener, void *func, void *ctx) "Net list= ener=3D%p callback forwarding to func=3D%p ctx=3D%p" --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762644468; cv=none; d=zohomail.com; s=zohoarc; b=GcWCxIxaVoejQB/4Ek7bOclYnQCZ0P+VuLcDdzRNcUqOEJGQaSoFkYxEAwH9EGkMXMH58JllSLoJD55e1DtJxFZGs111ays9Q+5uwzwJyQocSIKYDYK9V1GKruLjsk30Vqi5TulxotMPFhq1H+UAHrrUDYYIxybJeZVaRZeFnFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762644468; h=Content-Type: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=GCGpzqyaIpdEcTcu0H10/jQddJp9T6PwX6q8xDmr93s=; b=Cad2+lT4NDW7JczRl4E81r8FD4bXfnPW4QiodT2UxOmQX/BHRi3ugyWSiOjREAAtcmMgyIVxGcRz85haf+FNGBSn73swELYM2FaLjLkXSgECpSOmHpIDXtDJ3gKJZgvwzrI1K4WFyFoXFN7Ox39h58qYmk172UV+MHG/RXDrNNY= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762644468696586.9275995915422; Sat, 8 Nov 2025 15:27:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0H-0005bb-CF; Sat, 08 Nov 2025 18:05:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs07-0005Oy-St for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs06-0001fX-DE for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:43 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-141-FBuagGNNPziLgqmGhX4vCg-1; Sat, 08 Nov 2025 18:05:40 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8D084195605A; Sat, 8 Nov 2025 23:05:39 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 79FD319560A7; Sat, 8 Nov 2025 23:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643141; 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=GCGpzqyaIpdEcTcu0H10/jQddJp9T6PwX6q8xDmr93s=; b=CfpKqeQv7uJAT2R6zTppRWVYwuT3lUh14I/uinsUZe57cgT81Lzo6vwRaxTRY7gvVM1SaT cTn8I3bCuUuQ/LtYteahuckSYGCX2HcLELOPNyp2lF0COs9YQLyLPoKofNhwOf0ICCtEvC bzNUDVsWtJ8rq9tMFv9TByns8Xv6vNE= X-MC-Unique: FBuagGNNPziLgqmGhX4vCg-1 X-Mimecast-MFC-AGG-ID: FBuagGNNPziLgqmGhX4vCg_1762643139 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com Subject: [PATCH v2 05/12] qio: Minor optimization when callback function is unchanged Date: Sat, 8 Nov 2025 16:59:26 -0600 Message-ID: <20251108230525.3169174-19-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762644470303158500 Content-Type: text/plain; charset="utf-8" In qemu-nbd and other NBD server setups where parallel clients are supported, it is common that the caller will re-register the same callback function as long as it has not reached its limit on simultaneous clients. In that case, there is no need to tear down and reinstall GSource watches in the GMainContext. In practice, all callers currently pass NULL for notify, and no caller ever changes context across calls (for async uses, either the caller consistently uses qio_net_listener_set_client_func_full with the same context, or the caller consistently uses only qio_net_listener_set_client_func which always uses the global context); but the time spent checking these two fields in addition to the more important func and data is still less than the savings of not churning through extra GSource manipulations when the result will be unchanged. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: move later in series, also ensure notify and context are the same --- io/net-listener.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/io/net-listener.c b/io/net-listener.c index 0f16b78fbbd..a9da8e4e069 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -148,6 +148,11 @@ void qio_net_listener_set_client_func_full(QIONetListe= ner *listener, { size_t i; + if (listener->io_func =3D=3D func && listener->io_data =3D=3D data && + listener->io_notify =3D=3D notify && listener->context =3D=3D cont= ext) { + return; + } + trace_qio_net_listener_unwatch(listener, listener->io_func, listener->context, "set_client_func"); --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762643738; cv=none; d=zohomail.com; s=zohoarc; b=NmMNZWQjHmNZ69YTFqlCC/CEikOooUjchg+fiPEYWmIsZTExBeSQGtjoEk6t6CEQ2cHUQd6Azw4et2gWZyEPhAtdp9BREr98d3+m+SxaaG/MtHMSmCE5Tz6AmvCLQ35Nzc9PJgmdhpfcqTbnk090AT6d9sUJ46sIr/jruWJColQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762643738; h=Content-Type: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=yO3pUiCIfNOPPL+f28s/uQabQqNRwayP/PJkeGgpLX0=; b=bIXtPLXQDQHibNeYb27f5P3q8owW1/+nQAOdsg3/H+6S0Kl4w1ZP0CSGY0JEAnHDbsbERb39qdnIs3YbfrmiSQLeh30bVZNd1yYqObvdmWhA6/FYWMztJkUuI2SMOC/xl1HdpOI+ebER/jix7OSttl5r0XwtbEWfrAG0l0EnvVE= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762643738874805.8017960096495; Sat, 8 Nov 2025 15:15:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0L-0005gV-8u; Sat, 08 Nov 2025 18:05:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0A-0005TT-N5 for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs08-0001gL-Nj for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:46 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-cxYgnvlrMhCVahOc9_FtjA-1; Sat, 08 Nov 2025 18:05:41 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0F12F1800250; Sat, 8 Nov 2025 23:05:41 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F149219560A7; Sat, 8 Nov 2025 23:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643143; 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=yO3pUiCIfNOPPL+f28s/uQabQqNRwayP/PJkeGgpLX0=; b=XjWvVrpYUcrpXI3r05bgN5HgwJzrSPuD6Hd46wdN33Vmi6fenOA2vuqmld7ahC6EuPagbC boOesGeHJim8CCU58Hi4JPwpoZHtvboAswpkxolMMIzs4KRiKzs9R3ASxPBmfNasAx6uol k11gzud5mwiyYC9h2rvx58aA88Edvgc= X-MC-Unique: cxYgnvlrMhCVahOc9_FtjA-1 X-Mimecast-MFC-AGG-ID: cxYgnvlrMhCVahOc9_FtjA_1762643141 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com Subject: [PATCH v2 06/12] qio: Factor out helpers qio_net_listener_[un]watch Date: Sat, 8 Nov 2025 16:59:27 -0600 Message-ID: <20251108230525.3169174-20-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762643740576158500 Content-Type: text/plain; charset="utf-8" The code had three similar repetitions of an iteration over one or all of nsiocs to set up a GSource, and likewise for teardown. Since an upcoming patch wants to tweak whether GSource or AioContext is used, its better to consolidate that into one helper function for fewer places to edit later. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: rebase to changes on the tracepoints earlier in series --- io/net-listener.c | 108 ++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 61 deletions(-) diff --git a/io/net-listener.c b/io/net-listener.c index a9da8e4e069..ad097175eba 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -107,6 +107,47 @@ int qio_net_listener_open_sync(QIONetListener *listene= r, } } +/* + * i =3D=3D 0 to set watch on entire array, non-zero to only set watch on + * recent additions when earlier entries are already watched. + */ +static void +qio_net_listener_watch(QIONetListener *listener, size_t i, const char *cal= ler) +{ + if (!listener->io_func) { + return; + } + + trace_qio_net_listener_watch(listener, listener->io_func, + listener->context, caller); + for ( ; i < listener->nsioc; i++) { + object_ref(OBJECT(listener)); + listener->io_source[i] =3D qio_channel_add_watch_source( + QIO_CHANNEL(listener->sioc[i]), G_IO_IN, + qio_net_listener_channel_func, + listener, (GDestroyNotify)object_unref, listener->context); + } +} + +static void +qio_net_listener_unwatch(QIONetListener *listener, const char *caller) +{ + size_t i; + + if (!listener->io_func) { + return; + } + + trace_qio_net_listener_unwatch(listener, listener->io_func, + listener->context, caller); + for (i =3D 0; i < listener->nsioc; i++) { + if (listener->io_source[i]) { + g_source_destroy(listener->io_source[i]); + g_source_unref(listener->io_source[i]); + listener->io_source[i] =3D NULL; + } + } +} void qio_net_listener_add(QIONetListener *listener, QIOChannelSocket *sioc) @@ -126,17 +167,8 @@ void qio_net_listener_add(QIONetListener *listener, object_ref(OBJECT(sioc)); listener->connected =3D true; - trace_qio_net_listener_watch(listener, listener->io_func, - listener->context, "add"); - if (listener->io_func !=3D NULL) { - object_ref(OBJECT(listener)); - listener->io_source[listener->nsioc] =3D qio_channel_add_watch_sou= rce( - QIO_CHANNEL(listener->sioc[listener->nsioc]), G_IO_IN, - qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref, listener->context); - } - listener->nsioc++; + qio_net_listener_watch(listener, listener->nsioc - 1, "add"); } @@ -146,24 +178,12 @@ void qio_net_listener_set_client_func_full(QIONetList= ener *listener, GDestroyNotify notify, GMainContext *context) { - size_t i; - if (listener->io_func =3D=3D func && listener->io_data =3D=3D data && listener->io_notify =3D=3D notify && listener->context =3D=3D cont= ext) { return; } - trace_qio_net_listener_unwatch(listener, listener->io_func, - listener->context, "set_client_func"); - - for (i =3D 0; i < listener->nsioc; i++) { - if (listener->io_source[i]) { - g_source_destroy(listener->io_source[i]); - g_source_unref(listener->io_source[i]); - listener->io_source[i] =3D NULL; - } - } - + qio_net_listener_unwatch(listener, "set_client_func"); if (listener->io_notify) { listener->io_notify(listener->io_data); } @@ -172,17 +192,7 @@ void qio_net_listener_set_client_func_full(QIONetListe= ner *listener, listener->io_notify =3D notify; listener->context =3D context; - trace_qio_net_listener_watch(listener, listener->io_func, - listener->context, "set_client_func"); - if (listener->io_func !=3D NULL) { - for (i =3D 0; i < listener->nsioc; i++) { - object_ref(OBJECT(listener)); - listener->io_source[i] =3D qio_channel_add_watch_source( - QIO_CHANNEL(listener->sioc[i]), G_IO_IN, - qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref, context); - } - } + qio_net_listener_watch(listener, 0, "set_client_func"); } void qio_net_listener_set_client_func(QIONetListener *listener, @@ -234,15 +244,7 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetL= istener *listener) }; size_t i; - trace_qio_net_listener_unwatch(listener, listener->io_func, - listener->context, "wait_client"); - for (i =3D 0; i < listener->nsioc; i++) { - if (listener->io_source[i]) { - g_source_destroy(listener->io_source[i]); - g_source_unref(listener->io_source[i]); - listener->io_source[i] =3D NULL; - } - } + qio_net_listener_unwatch(listener, "wait_client"); sources =3D g_new0(GSource *, listener->nsioc); for (i =3D 0; i < listener->nsioc; i++) { @@ -265,17 +267,7 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetL= istener *listener) g_main_loop_unref(loop); g_main_context_unref(ctxt); - trace_qio_net_listener_watch(listener, listener->io_func, - listener->context, "wait_client"); - if (listener->io_func !=3D NULL) { - for (i =3D 0; i < listener->nsioc; i++) { - object_ref(OBJECT(listener)); - listener->io_source[i] =3D qio_channel_add_watch_source( - QIO_CHANNEL(listener->sioc[i]), G_IO_IN, - qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref, listener->context); - } - } + qio_net_listener_watch(listener, 0, "wait_client"); return data.sioc; } @@ -288,14 +280,8 @@ void qio_net_listener_disconnect(QIONetListener *liste= ner) return; } - trace_qio_net_listener_unwatch(listener, listener->io_func, - listener->context, "disconnect"); + qio_net_listener_unwatch(listener, "disconnect"); for (i =3D 0; i < listener->nsioc; i++) { - if (listener->io_source[i]) { - g_source_destroy(listener->io_source[i]); - g_source_unref(listener->io_source[i]); - listener->io_source[i] =3D NULL; - } qio_channel_close(QIO_CHANNEL(listener->sioc[i]), NULL); } listener->connected =3D false; --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762643890; cv=none; d=zohomail.com; s=zohoarc; b=GrgmuOaoNdTQbbB9vrQsGogntgtidGIq1QzscUeJlkIoL5iXyGRyCdiCslhwLlVF2xjyoJyH2jopSnRmAkhzfHkehtrPZ0L+iuURNzlPXUwF1+1mmg+K+I6F77X0KQbvR8xTjoTH/wE1OyK85G/OcxHOZxFP/9uSYd3wtVLEgIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762643890; h=Content-Type: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=CqLFRgmxOI5A5wkzNI8p51JwiRBx4RST27KTIV11lCY=; b=YLBoGkD/+h6CMaIx8Bta+PTYQzII88L6su9+bvEJg6MThxDdJsQ8Yhh5+GsR/6gTNsJrHu4+nkPySssASXmaDCUkW07m7YCVcksFj3xioFpQ0a4B31r1ydeZRs6fXeDdKNMSq2v6X/lqOQn9c4sy8AtHxSXwTegTziXdU4jVkEM= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762643890041359.6070713464642; Sat, 8 Nov 2025 15:18:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0N-0005lB-HJ; Sat, 08 Nov 2025 18:05:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0D-0005Wq-Eg for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0B-0001hi-8e for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:49 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-ANB4UOUAO9SBK8A4eSBZWw-1; Sat, 08 Nov 2025 18:05:43 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 871361956080; Sat, 8 Nov 2025 23:05:42 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7495D19560B6; Sat, 8 Nov 2025 23:05:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643146; 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=CqLFRgmxOI5A5wkzNI8p51JwiRBx4RST27KTIV11lCY=; b=VUzYxrcqnG9f0uGF4z28XYov5c/jctHOJI7R9MAPF+ZX+iyu+51v6tcHdhrfS/+gifDuaK E9bTd5a+MNMcfn2nJY0g1W/eNwyDUMLtyO9tQZEWgt2hSaWO0C9TKkZFtO1ETdmvZNIZu3 1U6hevyTa5jLPhREeQBotXq+rIrh9OA= X-MC-Unique: ANB4UOUAO9SBK8A4eSBZWw-1 X-Mimecast-MFC-AGG-ID: ANB4UOUAO9SBK8A4eSBZWw_1762643142 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com Subject: [PATCH v2 07/12] qio: Hoist ref of listener outside loop Date: Sat, 8 Nov 2025 16:59:28 -0600 Message-ID: <20251108230525.3169174-21-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @redhat.com) X-ZM-MESSAGEID: 1762643892503158500 Content-Type: text/plain; charset="utf-8" The point of QIONetListener is to allow a server to listen to more than one socket address at a time, and respond to clients in a first-come-first-serve order across any of those addresses. While some servers (like NBD) really do want to serve multiple simultaneous clients, others only care about the first client to connect, and will immediately deregister the callback, possibly by dropping their reference to the QIONetListener. The existing code ensures that the reference count on the listener will not drop to zero while there are any pending GSource (since each GSource will not call the notify of object_unref() until it is no longer servicing a callback); however, it is also possible to guarantee the same setup by merely holding an overall reference to the listener as long as there is at least one GSource, as well as also holding a local reference around any callback function that has not yet run to completion. Hoisting the reference like this will make it easier for an upcoming patch to still ensure the listener cannot be prematurely finalized during the user's callback, even when using AioContext (where we have not plumbed in support for a notify function) rather than GSource. Signed-off-by: Eric Blake --- v2: also grab reference around callback execution --- io/net-listener.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/io/net-listener.c b/io/net-listener.c index ad097175eba..dd3522c9b3c 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -54,7 +54,9 @@ static gboolean qio_net_listener_channel_func(QIOChannel = *ioc, trace_qio_net_listener_callback(listener, listener->io_func, listener->context); if (listener->io_func) { + object_ref(OBJECT(listener)); listener->io_func(listener, sioc, listener->io_data); + object_unref(OBJECT(listener)); } object_unref(OBJECT(sioc)); @@ -120,12 +122,14 @@ qio_net_listener_watch(QIONetListener *listener, size= _t i, const char *caller) trace_qio_net_listener_watch(listener, listener->io_func, listener->context, caller); - for ( ; i < listener->nsioc; i++) { + if (i =3D=3D 0) { object_ref(OBJECT(listener)); + } + for ( ; i < listener->nsioc; i++) { listener->io_source[i] =3D qio_channel_add_watch_source( QIO_CHANNEL(listener->sioc[i]), G_IO_IN, qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref, listener->context); + listener, NULL, listener->context); } } @@ -147,6 +151,7 @@ qio_net_listener_unwatch(QIONetListener *listener, cons= t char *caller) listener->io_source[i] =3D NULL; } } + object_unref(OBJECT(listener)); } void qio_net_listener_add(QIONetListener *listener, --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762644223; cv=none; d=zohomail.com; s=zohoarc; b=aJ86vgIj3sD1EYRG4SGDAYKOGkKq8TIlpJTbpx2amwbq6Xx5TUaZFYz2chmEYktv2IhK/xKMhnLw6T6xMPj6FBTwRcW7raG+2kCIrLAercT95n69RNNfoVyZywfNQ+3dUjtsUwQ5JDhVUDk97M4kMxxYARPv+fDq3J+U3I24Huc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762644223; h=Content-Type: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=ZHzTbysZfVgRgo3/EkmfM0mHlmWhy7F45zwi7JUWfOE=; b=mlGSKarWmCYDmRxSBKXmG8HASQBTwR+tCiu3Lm6qmbe1Q0VsyI4f+X5C4loYfXrUnkWCEIhshFjtBhoMdGmjARY/Oqlr7xF6ro+Q5iFnXM2k5hbjXHYy+C4MGeFH7ZRjdyfPLoNrtTVTWj2f1NZhlKPMXdEBPtjYyGIBS12Lx94= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762644223896639.3856258173768; Sat, 8 Nov 2025 15:23:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0O-0005mX-7B; Sat, 08 Nov 2025 18:06:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0I-0005d8-JA for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0E-0001iu-R0 for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:54 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-353-bruxVELwNCyymlMIwNMqMA-1; Sat, 08 Nov 2025 18:05:46 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5DE9919560A3; Sat, 8 Nov 2025 23:05:45 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F22B619560A7; Sat, 8 Nov 2025 23:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643149; 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=ZHzTbysZfVgRgo3/EkmfM0mHlmWhy7F45zwi7JUWfOE=; b=RdifAo7AbObJpOOvJdZF/KCjE7H6cifJLgB4KdTkq1LJlQT00Dz5ubSWY2H6DqtpB4P4Qg bw5Cazy3H1JfUrJfPojfbUdM6ijxuzRZkMcmouXEGrQ54BvG9Y4LcGY+GgA+z3hwO/C50z yiYTew5YETwZIji8+6l8a334EPl8Qbg= X-MC-Unique: bruxVELwNCyymlMIwNMqMA-1 X-Mimecast-MFC-AGG-ID: bruxVELwNCyymlMIwNMqMA_1762643145 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Peter Xu , Fabiano Rosas Subject: [PATCH v2 08/12] qio: Provide accessor around QIONetListener->sioc Date: Sat, 8 Nov 2025 16:59:29 -0600 Message-ID: <20251108230525.3169174-22-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @redhat.com) X-ZM-MESSAGEID: 1762644225073158500 Content-Type: text/plain; charset="utf-8" An upcoming patch needs to pass more than just sioc as the opaque pointer to an AioContext; but since our AioContext code in general (and its QIO Channel wrapper code) lacks a notify callback present with GSource, we do not have the trivial option of just g_malloc'ing a small struct to hold all that data coupled with a notify of g_free. Instead, the data pointer must outlive the registered handler; in fact, having the data pointer have the same lifetime as QIONetListener is adequate. But the cleanest way to stick such a helper struct in QIONetListener will be to rearrange internal struct members. And that in turn means that all existing code that currently directly accesses listener->nsioc and listener->sioc[] should instead go through accessor functions, to be immune to the upcoming struct layout changes. So this patch adds accessor methods qio_net_listener_nsioc() and qio_net_listener_sioc(), and puts them to use. Signed-off-by: Eric Blake --- v2: new patch --- include/io/net-listener.h | 24 ++++++++++++++++++++++++ chardev/char-socket.c | 3 ++- io/net-listener.c | 12 ++++++++++++ migration/socket.c | 5 +++-- ui/vnc.c | 36 +++++++++++++++++++++++------------- 5 files changed, 64 insertions(+), 16 deletions(-) diff --git a/include/io/net-listener.h b/include/io/net-listener.h index 42fbfab5467..2605d6aae1e 100644 --- a/include/io/net-listener.h +++ b/include/io/net-listener.h @@ -184,4 +184,28 @@ void qio_net_listener_disconnect(QIONetListener *liste= ner); */ bool qio_net_listener_is_connected(QIONetListener *listener); + +/** + * qio_net_listener_nsioc: + * @listener: the network listener object + * + * Determine the number of listener channels currently owned by the + * given listener. + * + * Returns: number of channels, or 0 if not listening + */ +size_t qio_net_listener_nsioc(QIONetListener *listener); + + +/** + * qio_net_listener_sioc: + * @listener: the network listener object + * @n: index of the sioc to grab + * + * Accessor for the nth sioc owned by the listener. + * + * Returns: the requested listener, or #NULL if not in bounds + */ +QIOChannelSocket *qio_net_listener_sioc(QIONetListener *listener, size_t n= ); + #endif /* QIO_NET_LISTENER_H */ diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 62852e3caf5..022ae47d726 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -1255,7 +1255,8 @@ static int qmp_chardev_open_socket_server(Chardev *ch= r, } qapi_free_SocketAddress(s->addr); - s->addr =3D socket_local_address(s->listener->sioc[0]->fd, errp); + s->addr =3D socket_local_address(qio_net_listener_sioc(s->listener, 0)= ->fd, + errp); skip_listen: update_disconnected_filename(s); diff --git a/io/net-listener.c b/io/net-listener.c index dd3522c9b3c..83c977ecca2 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -298,6 +298,18 @@ bool qio_net_listener_is_connected(QIONetListener *lis= tener) return listener->connected; } +size_t qio_net_listener_nsioc(QIONetListener *listener) +{ + return listener->nsioc; +} + +QIOChannelSocket *qio_net_listener_sioc(QIONetListener *listener, size_t n) +{ + if (n > listener->nsioc) { + return NULL; + } + return listener->sioc[n]; +} static void qio_net_listener_finalize(Object *obj) { QIONetListener *listener =3D QIO_NET_LISTENER(obj); diff --git a/migration/socket.c b/migration/socket.c index 5ec65b8c039..297de3ee156 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -170,9 +170,10 @@ void socket_start_incoming_migration(SocketAddress *sa= ddr, NULL, NULL, g_main_context_get_thread_defaul= t()); - for (i =3D 0; i < listener->nsioc; i++) { + for (i =3D 0; i < qio_net_listener_nsioc(listener); i++) { SocketAddress *address =3D - qio_channel_socket_get_local_address(listener->sioc[i], errp); + qio_channel_socket_get_local_address( + qio_net_listener_sioc(listener, i), errp); if (!address) { return; } diff --git a/ui/vnc.c b/ui/vnc.c index 50016ff7ab4..b5b6f5cd06f 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -235,12 +235,12 @@ static VncServerInfo *vnc_server_info_get(VncDisplay = *vd) VncServerInfo *info; Error *err =3D NULL; - if (!vd->listener || !vd->listener->nsioc) { + if (!vd->listener || !qio_net_listener_nsioc(vd->listener)) { return NULL; } info =3D g_malloc0(sizeof(*info)); - vnc_init_basic_info_from_server_addr(vd->listener->sioc[0], + vnc_init_basic_info_from_server_addr(qio_net_listener_sioc(vd->listene= r, 0), qapi_VncServerInfo_base(info), &e= rr); info->auth =3D g_strdup(vnc_auth_name(vd)); if (err) { @@ -377,7 +377,7 @@ VncInfo *qmp_query_vnc(Error **errp) VncDisplay *vd =3D vnc_display_find(NULL); SocketAddress *addr =3D NULL; - if (vd =3D=3D NULL || !vd->listener || !vd->listener->nsioc) { + if (vd =3D=3D NULL || !vd->listener || !qio_net_listener_nsioc(vd->lis= tener)) { info->enabled =3D false; } else { info->enabled =3D true; @@ -386,8 +386,8 @@ VncInfo *qmp_query_vnc(Error **errp) info->has_clients =3D true; info->clients =3D qmp_query_client_list(vd); - addr =3D qio_channel_socket_get_local_address(vd->listener->sioc[0= ], - errp); + addr =3D qio_channel_socket_get_local_address( + qio_net_listener_sioc(vd->listener, 0), errp); if (!addr) { goto out_error; } @@ -549,6 +549,8 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp) size_t i; QTAILQ_FOREACH(vd, &vnc_displays, next) { + size_t nsioc =3D 0; + info =3D g_new0(VncInfo2, 1); info->id =3D g_strdup(vd->id); info->clients =3D qmp_query_client_list(vd); @@ -559,14 +561,21 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp) "device", &error_abort)); info->display =3D g_strdup(dev->id); } - for (i =3D 0; vd->listener !=3D NULL && i < vd->listener->nsioc; i= ++) { - info->server =3D qmp_query_server_entry( - vd->listener->sioc[i], false, vd->auth, vd->subauth, - info->server); + if (vd->listener !=3D NULL) { + nsioc =3D qio_net_listener_nsioc(vd->listener); } - for (i =3D 0; vd->wslistener !=3D NULL && i < vd->wslistener->nsio= c; i++) { + for (i =3D 0; i < nsioc; i++) { info->server =3D qmp_query_server_entry( - vd->wslistener->sioc[i], true, vd->ws_auth, + qio_net_listener_sioc(vd->listener, i), false, vd->auth, + vd->subauth, info->server); + } + nsioc =3D 0; + if (vd->wslistener) { + nsioc =3D qio_net_listener_nsioc(vd->wslistener); + } + for (i =3D 0; i < nsioc; i++) { + info->server =3D qmp_query_server_entry( + qio_net_listener_sioc(vd->wslistener, i), true, vd->ws_aut= h, vd->ws_subauth, info->server); } @@ -3550,11 +3559,12 @@ static void vnc_display_print_local_addr(VncDisplay= *vd) { SocketAddress *addr; - if (!vd->listener || !vd->listener->nsioc) { + if (!vd->listener || !qio_net_listener_nsioc(vd->listener)) { return; } - addr =3D qio_channel_socket_get_local_address(vd->listener->sioc[0], N= ULL); + addr =3D qio_channel_socket_get_local_address( + qio_net_listener_sioc(vd->listener, 0), NULL); if (!addr) { return; } --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762643254; cv=none; d=zohomail.com; s=zohoarc; b=kKyd2G+89lcqZUCVFqsj5ZVxLlu/gLyJhuIyGfqUtDLMVTzOqW2j0zmGGKeeK9dT232GkPz7dH7/TTraYr4Mye6eZ7zmQu4uear//VcARjfh3029EDpm9jmeSeB+VUqaEAwi3VIvpkBZeGeXITelvMVYc9OEWKQcrxLrKV9/2m4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762643254; h=Content-Type: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=tYCfZAH2P4JWJ/fPjO7E2/nMVRBEkEBOTpeY5IMD+Kk=; b=ajg6VHNUh7+qA4zU+Lhkj40G3Kz9uwA4nzeKKqqaD20j/DLzqI1xufB5Tqg8qB9Pm54stFQ6Hpc5/JRcMvNvDERGDJOxJTitS4QIrQXCU/aes6wf7ByNy4qA4zuaAyYZMBhbHoGIVk+nw3lzy7HiUY73fUk4NSoGi3ApGzdYgo0= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762643254482751.7717923848719; Sat, 8 Nov 2025 15:07:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0P-0005nD-Eh; Sat, 08 Nov 2025 18:06:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0I-0005dE-L5 for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0F-0001jr-PG for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:54 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-LCp15DMhNISCGmbZrNUSCA-1; Sat, 08 Nov 2025 18:05:47 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E19D5195608F; Sat, 8 Nov 2025 23:05:46 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6A6819560B0; Sat, 8 Nov 2025 23:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643151; 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=tYCfZAH2P4JWJ/fPjO7E2/nMVRBEkEBOTpeY5IMD+Kk=; b=CIhL2u5r21EgWV75F8tZ5MoVAIkie35rS0PDolm8uxdiCF/LtLn0X0yR9UGaSGIlpaVqh5 UodyLH+suXym4ThfIhxyjE7x7CXk1BXIs9LXN9x+4AC4iHBmy0W2EK7bF3/3oJfGl3Gq6z ssPgMqmeuKYk83Mk1BTlE1ema/esdXE= X-MC-Unique: LCp15DMhNISCGmbZrNUSCA-1 X-Mimecast-MFC-AGG-ID: LCp15DMhNISCGmbZrNUSCA_1762643147 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com Subject: [PATCH v2 09/12] qio: Prepare NetListener to use AioContext Date: Sat, 8 Nov 2025 16:59:30 -0600 Message-ID: <20251108230525.3169174-23-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @redhat.com) X-ZM-MESSAGEID: 1762643257732158500 Content-Type: text/plain; charset="utf-8" For ease of review, this patch adds an AioContext pointer to the QIONetListener struct, the code to trace it, and refactors listener->io_source to instead be an array of utility structs; but the aio_context pointer is always NULL until the next patch adds an API to set it. There should be no semantic change in this patch. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: new patch, replacing the earlier "qio: Let listening sockets remember their owning QIONetListener" --- include/io/net-listener.h | 6 ++- io/net-listener.c | 102 ++++++++++++++++++++++++++------------ io/trace-events | 6 +-- 3 files changed, 76 insertions(+), 38 deletions(-) diff --git a/include/io/net-listener.h b/include/io/net-listener.h index 2605d6aae1e..7188721cb34 100644 --- a/include/io/net-listener.h +++ b/include/io/net-listener.h @@ -28,6 +28,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(QIONetListener, QIO_NET_LISTENER) +typedef struct QIONetListenerSource QIONetListenerSource; typedef void (*QIONetListenerClientFunc)(QIONetListener *listener, QIOChannelSocket *sioc, @@ -47,10 +48,11 @@ struct QIONetListener { Object parent; char *name; - QIOChannelSocket **sioc; - GSource **io_source; + QIONetListenerSource **source; size_t nsioc; + /* At most one of context or aio_context will be set */ GMainContext *context; + AioContext *aio_context; bool connected; diff --git a/io/net-listener.c b/io/net-listener.c index 83c977ecca2..ebc61f81ed6 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -23,8 +23,15 @@ #include "io/dns-resolver.h" #include "qapi/error.h" #include "qemu/module.h" +#include "qemu/main-loop.h" #include "trace.h" +struct QIONetListenerSource { + QIOChannelSocket *sioc; + GSource *io_source; + QIONetListener *listener; +}; + QIONetListener *qio_net_listener_new(void) { return QIO_NET_LISTENER(object_new(TYPE_QIO_NET_LISTENER)); @@ -52,7 +59,7 @@ static gboolean qio_net_listener_channel_func(QIOChannel = *ioc, } trace_qio_net_listener_callback(listener, listener->io_func, - listener->context); + listener->context, listener->aio_conte= xt); if (listener->io_func) { object_ref(OBJECT(listener)); listener->io_func(listener, sioc, listener->io_data); @@ -121,15 +128,25 @@ qio_net_listener_watch(QIONetListener *listener, size= _t i, const char *caller) } trace_qio_net_listener_watch(listener, listener->io_func, - listener->context, caller); + listener->context, listener->aio_context, + caller); if (i =3D=3D 0) { object_ref(OBJECT(listener)); } for ( ; i < listener->nsioc; i++) { - listener->io_source[i] =3D qio_channel_add_watch_source( - QIO_CHANNEL(listener->sioc[i]), G_IO_IN, - qio_net_listener_channel_func, - listener, NULL, listener->context); + if (!listener->aio_context) { + /* + * The user passed a GMainContext with the async callback; + * they plan on running the default or their own g_main_loop. + */ + listener->source[i]->io_source =3D qio_channel_add_watch_sourc= e( + QIO_CHANNEL(listener->source[i]->sioc), G_IO_IN, + qio_net_listener_channel_func, + listener, NULL, listener->context); + } else { + /* The user passed an AioContext. Not supported yet. */ + g_assert_not_reached(); + } } } @@ -143,12 +160,17 @@ qio_net_listener_unwatch(QIONetListener *listener, co= nst char *caller) } trace_qio_net_listener_unwatch(listener, listener->io_func, - listener->context, caller); + listener->context, listener->aio_contex= t, + caller); for (i =3D 0; i < listener->nsioc; i++) { - if (listener->io_source[i]) { - g_source_destroy(listener->io_source[i]); - g_source_unref(listener->io_source[i]); - listener->io_source[i] =3D NULL; + if (!listener->aio_context) { + if (listener->source[i]->io_source) { + g_source_destroy(listener->source[i]->io_source); + g_source_unref(listener->source[i]->io_source); + listener->source[i]->io_source =3D NULL; + } + } else { + g_assert_not_reached(); } } object_unref(OBJECT(listener)); @@ -161,13 +183,12 @@ void qio_net_listener_add(QIONetListener *listener, qio_channel_set_name(QIO_CHANNEL(sioc), listener->name); } - listener->sioc =3D g_renew(QIOChannelSocket *, listener->sioc, - listener->nsioc + 1); - listener->io_source =3D g_renew(typeof(listener->io_source[0]), - listener->io_source, - listener->nsioc + 1); - listener->sioc[listener->nsioc] =3D sioc; - listener->io_source[listener->nsioc] =3D NULL; + listener->source =3D g_renew(typeof(listener->source[0]), + listener->source, + listener->nsioc + 1); + listener->source[listener->nsioc] =3D g_new0(QIONetListenerSource, 1); + listener->source[listener->nsioc]->sioc =3D sioc; + listener->source[listener->nsioc]->listener =3D listener; object_ref(OBJECT(sioc)); listener->connected =3D true; @@ -177,14 +198,17 @@ void qio_net_listener_add(QIONetListener *listener, } -void qio_net_listener_set_client_func_full(QIONetListener *listener, - QIONetListenerClientFunc func, - gpointer data, - GDestroyNotify notify, - GMainContext *context) +static void +qio_net_listener_set_client_func_internal(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify, + GMainContext *context, + AioContext *aio_context) { if (listener->io_func =3D=3D func && listener->io_data =3D=3D data && - listener->io_notify =3D=3D notify && listener->context =3D=3D cont= ext) { + listener->io_notify =3D=3D notify && listener->context =3D=3D cont= ext && + listener->aio_context =3D=3D aio_context) { return; } @@ -196,17 +220,28 @@ void qio_net_listener_set_client_func_full(QIONetList= ener *listener, listener->io_data =3D data; listener->io_notify =3D notify; listener->context =3D context; + listener->aio_context =3D aio_context; qio_net_listener_watch(listener, 0, "set_client_func"); } +void qio_net_listener_set_client_func_full(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify, + GMainContext *context) +{ + qio_net_listener_set_client_func_internal(listener, func, data, + notify, context, NULL); +} + void qio_net_listener_set_client_func(QIONetListener *listener, QIONetListenerClientFunc func, gpointer data, GDestroyNotify notify) { - qio_net_listener_set_client_func_full(listener, func, data, - notify, NULL); + qio_net_listener_set_client_func_internal(listener, func, data, + notify, NULL, NULL); } struct QIONetListenerClientWaitData { @@ -253,8 +288,8 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetLi= stener *listener) sources =3D g_new0(GSource *, listener->nsioc); for (i =3D 0; i < listener->nsioc; i++) { - sources[i] =3D qio_channel_create_watch(QIO_CHANNEL(listener->sioc= [i]), - G_IO_IN); + sources[i] =3D qio_channel_create_watch( + QIO_CHANNEL(listener->source[i]->sioc), G_IO_IN); g_source_set_callback(sources[i], (GSourceFunc)qio_net_listener_wait_client_fu= nc, @@ -287,7 +322,7 @@ void qio_net_listener_disconnect(QIONetListener *listen= er) qio_net_listener_unwatch(listener, "disconnect"); for (i =3D 0; i < listener->nsioc; i++) { - qio_channel_close(QIO_CHANNEL(listener->sioc[i]), NULL); + qio_channel_close(QIO_CHANNEL(listener->source[i]->sioc), NULL); } listener->connected =3D false; } @@ -308,8 +343,9 @@ QIOChannelSocket *qio_net_listener_sioc(QIONetListener = *listener, size_t n) if (n > listener->nsioc) { return NULL; } - return listener->sioc[n]; + return listener->source[n]->sioc; } + static void qio_net_listener_finalize(Object *obj) { QIONetListener *listener =3D QIO_NET_LISTENER(obj); @@ -321,10 +357,10 @@ static void qio_net_listener_finalize(Object *obj) } for (i =3D 0; i < listener->nsioc; i++) { - object_unref(OBJECT(listener->sioc[i])); + object_unref(OBJECT(listener->source[i]->sioc)); + g_free(listener->source[i]); } - g_free(listener->io_source); - g_free(listener->sioc); + g_free(listener->source); g_free(listener->name); } diff --git a/io/trace-events b/io/trace-events index 0cb77d579b6..ec91453335a 100644 --- a/io/trace-events +++ b/io/trace-events @@ -74,6 +74,6 @@ qio_channel_command_abort(void *ioc, int pid) "Command ab= ort ioc=3D%p pid=3D%d" qio_channel_command_wait(void *ioc, int pid, int ret, int status) "Command= abort ioc=3D%p pid=3D%d ret=3D%d status=3D%d" # net-listener.c -qio_net_listener_watch(void *listener, void *func, void *ctx, const char *= extra) "Net listener=3D%p watch enabled func=3D%p ctx=3D%p by %s" -qio_net_listener_unwatch(void *listener, void *func, void *ctx, const char= *extra) "Net listener=3D%p watch disabled func=3D%p ctx=3D%p by %s" -qio_net_listener_callback(void *listener, void *func, void *ctx) "Net list= ener=3D%p callback forwarding to func=3D%p ctx=3D%p" +qio_net_listener_watch(void *listener, void *func, void *gctx, void *actx,= const char *extra) "Net listener=3D%p watch enabled func=3D%p ctx=3D%p/%p = by %s" +qio_net_listener_unwatch(void *listener, void *func, void *gctx, void *act= x, const char *extra) "Net listener=3D%p watch disabled func=3D%p ctx=3D%p/= %p by %s" +qio_net_listener_callback(void *listener, void *func, void *gctx, void *ac= tx) "Net listener=3D%p callback forwarding to func=3D%p ctx=3D%p/%p" --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762644199; cv=none; d=zohomail.com; s=zohoarc; b=B/IA8O68Q5tuXFHVpYB0v+owvEkDSdLCWQ5VnaVHHQRgjWwtRbwsQ1V0iMVkZxchK1XD2NL0eNqLef+PuYGzuvN72k07eJRVpprnkOuAOY4z2TTdXkxT3NuUhbvr4gPGFjMwd7YgfLwVQc3W9Nc6AyahDSYUAcJvERI0Ajr9G+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762644199; h=Content-Type: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=MYwiU7nYP0+sR8jZh/WC9zAz8Ea5t7r6LXo4wsBhCwI=; b=H2229wuxaowxWzt9nb2K/zsRyU34Lri0k7sMjHVHtSSmZepOA4prIZviNzJRoapbxO1AlPR7aPIWinkz6oV6DP+Uz0PqP6VjPQKPlahq/r2sd6f848ntRxCRwAA6vj5qnDvK1l13c9/wr/Qg9/kyo7p91vE+fKI4F3zLbaXvCug= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762644199018850.4438721316607; Sat, 8 Nov 2025 15:23:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0O-0005mj-Ls; Sat, 08 Nov 2025 18:06:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0I-0005dG-Lo for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0F-0001je-DC for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:54 -0500 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-600-U1fST1ySNdGB_2Ig-kOhlA-1; Sat, 08 Nov 2025 18:05:49 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 61B14180047F; Sat, 8 Nov 2025 23:05:48 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4FC0519560A7; Sat, 8 Nov 2025 23:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643150; 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=MYwiU7nYP0+sR8jZh/WC9zAz8Ea5t7r6LXo4wsBhCwI=; b=TvhA4CEWxA0tVM+m74JGTJAMzuF4/UTwxlhpVdu577eULZR+6A55T95d9Fzo7f+wrHFaG0 opDXTC8uJQHNnMzuKqx8HTFDaiQLPVFjxrmZYm6JI2CRl+9IcCBJy41DC696DER3LE4lKW tF0nhafwEgScxynjswwITFc5eiY+AZM= X-MC-Unique: U1fST1ySNdGB_2Ig-kOhlA-1 X-Mimecast-MFC-AGG-ID: U1fST1ySNdGB_2Ig-kOhlA_1762643148 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com Subject: [PATCH v2 10/12] qio: Add QIONetListener API for using AioContext Date: Sat, 8 Nov 2025 16:59:31 -0600 Message-ID: <20251108230525.3169174-24-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762644200994158500 Content-Type: text/plain; charset="utf-8" The user "John Doe" reported a deadlock when attempting to use qemu-storage-daemon to serve both a base file over NBD, and a qcow2 file with that NBD export as its backing file, from the same process, even though it worked just fine when there were two q-s-d processes. The bulk of the NBD server code properly uses coroutines to make progress in an event-driven manner, but the code for spawning a new coroutine at the point when listen(2) detects a new client was hard-coded to use the global GMainContext; in other words, the callback that triggers nbd_client_new to let the server start the negotiation sequence with the client requires the main loop to be making progress. However, the code for bdrv_open of a qcow2 image with an NBD backing file uses an AIO_WAIT_WHILE nested event loop to ensure that the entire qcow2 backing chain is either fully loaded or rejected, without any side effects from the main loop causing unwanted changes to the disk being loaded (in short, an AioContext represents the set of actions that are known to be safe while handling block layer I/O, while excluding any other pending actions in the global main loop with potentially larger risk of unwanted side effects). This creates a classic case of deadlock: the server can't progress to the point of accept(2)ing the client to write to the NBD socket because the main loop is being starved until the AIO_WAIT_WHILE completes the bdrv_open, but the AIO_WAIT_WHILE can't progress because it is blocked on the client coroutine stuck in a read() of the expected magic number from the server side of the socket. This patch adds a new API to allow clients to opt in to listening via an AioContext rather than a GMainContext. This will allow NBD to fix the deadlock by performing all actions during bdrv_open in the main loop AioContext. An upcoming patch will then add a unit test (kept separate to make it easier to rearrange the series to demonstrate the deadlock without this patch). Fixes: https://gitlab.com/qemu-project/qemu/-/issues/3169 Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: Retitle and add new API rather than changing semantics of existing qio_net_listener_set_client_func; use qio accessor rather than direct access to the sioc fd and a lower-level aio call --- include/io/net-listener.h | 16 ++++++++++++++++ io/net-listener.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/include/io/net-listener.h b/include/io/net-listener.h index 7188721cb34..e93efd5d96a 100644 --- a/include/io/net-listener.h +++ b/include/io/net-listener.h @@ -151,6 +151,22 @@ void qio_net_listener_set_client_func(QIONetListener *= listener, gpointer data, GDestroyNotify notify); +/** + * qio_net_listener_set_client_aio_func: + * @listener: the network listener object + * @func: the callback function + * @data: opaque data to pass to @func + * @context: AioContext that @func will be bound to; if #NULL, this will + * will use qemu_get_aio_context(). + * + * Similar to qio_net_listener_set_client_func_full(), except that the pol= ling + * will be done by an AioContext rather than a GMainContext. + */ +void qio_net_listener_set_client_aio_func(QIONetListener *listener, + QIONetListenerClientFunc func, + void *data, + AioContext *context); + /** * qio_net_listener_wait_client: * @listener: the network listener object diff --git a/io/net-listener.c b/io/net-listener.c index ebc61f81ed6..53f2e7091d7 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -72,6 +72,17 @@ static gboolean qio_net_listener_channel_func(QIOChannel= *ioc, } +static void qio_net_listener_aio_func(void *opaque) +{ + QIONetListenerSource *data =3D opaque; + + assert(data->io_source =3D=3D NULL); + assert(data->listener->aio_context !=3D NULL); + qio_net_listener_channel_func(QIO_CHANNEL(data->sioc), G_IO_IN, + data->listener); +} + + int qio_net_listener_open_sync(QIONetListener *listener, SocketAddress *addr, int num, @@ -144,8 +155,12 @@ qio_net_listener_watch(QIONetListener *listener, size_= t i, const char *caller) qio_net_listener_channel_func, listener, NULL, listener->context); } else { - /* The user passed an AioContext. Not supported yet. */ - g_assert_not_reached(); + /* The user passed an AioContext. */ + assert(listener->context =3D=3D NULL); + qio_channel_set_aio_fd_handler( + QIO_CHANNEL(listener->source[i]->sioc), + listener->aio_context, qio_net_listener_aio_func, + NULL, NULL, listener->source[i]); } } } @@ -170,7 +185,10 @@ qio_net_listener_unwatch(QIONetListener *listener, con= st char *caller) listener->source[i]->io_source =3D NULL; } } else { - g_assert_not_reached(); + assert(listener->context =3D=3D NULL); + qio_channel_set_aio_fd_handler( + QIO_CHANNEL(listener->source[i]->sioc), + NULL, NULL, NULL, NULL, NULL); } } object_unref(OBJECT(listener)); @@ -244,6 +262,18 @@ void qio_net_listener_set_client_func(QIONetListener *= listener, notify, NULL, NULL); } +void qio_net_listener_set_client_aio_func(QIONetListener *listener, + QIONetListenerClientFunc func, + void *data, + AioContext *context) +{ + if (!context) { + context =3D qemu_get_aio_context(); + } + qio_net_listener_set_client_func_internal(listener, func, data, + NULL, NULL, context); +} + struct QIONetListenerClientWaitData { QIOChannelSocket *sioc; GMainLoop *loop; --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762643495; cv=none; d=zohomail.com; s=zohoarc; b=FLbIn/CgJYZdY8vkYbf9D0kv3uOo6ISLtXeR5lqG1AR0UodFFekp9yBe/jjyQ9XTnZc8+viN+U2fyjFOykiY/6uKuUcMi/S+PWwkZjGm7OqKvac/cjrMjSw0wH4gbxjqqDJ+V7G8KCR0QlL3EY8+YHDW42nEGTqNr0wpZf7mImg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762643495; h=Content-Type: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=GHCV5Y1+bFiRE1Z7GpY7cBjjW6e37+tKAMyqV7hErAM=; b=TQpg/1Snx/0qDfuoQ9Du1AyMpu7QpBvEM0ZwencwFEQZaOnqw91O5JiWJZiUI3lE6SDoyJUpQjXk0aq2W+UHpweAyVCOoAsQ2CztT4N903UJbeZX0szLGc+gyuZ/VK86ewho0HtDttKAqQKUkbwiQuzryXfGV4FuSi68ropAs+I= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762643495783375.1841465678424; Sat, 8 Nov 2025 15:11:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs1b-0006U9-Mk; Sat, 08 Nov 2025 18:07:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0L-0005gn-7p for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0J-0001l9-FS for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:56 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-IFyqvJe4N4ePL5glwEnHKw-1; Sat, 08 Nov 2025 18:05:51 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9E00C195608E; Sat, 8 Nov 2025 23:05:50 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C666819560A7; Sat, 8 Nov 2025 23:05:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643154; 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=GHCV5Y1+bFiRE1Z7GpY7cBjjW6e37+tKAMyqV7hErAM=; b=WoHhSrl/E9ticjMHiph1HJIw0Tj80cOf0ehQJI1L6Geo7C4reS3aZvWvNqoS6EiqaGz2WY lAksAh8RaWXnvwDB9zz+CgEnqWyHDW7sPvYtynNDICzaNK1lPmDwsOOkaDVLo6aXAABIt4 4+rS4RToVPh/nsbLm5mlgK+dFerzJ4M= X-MC-Unique: IFyqvJe4N4ePL5glwEnHKw-1 X-Mimecast-MFC-AGG-ID: IFyqvJe4N4ePL5glwEnHKw_1762643151 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com, Vladimir Sementsov-Ogievskiy , Hanna Reitz Subject: [PATCH v2 11/12] nbd: Avoid deadlock in client connecting to same-process server Date: Sat, 8 Nov 2025 16:59:32 -0600 Message-ID: <20251108230525.3169174-25-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762643498485158500 Content-Type: text/plain; charset="utf-8" See the previous patch for a longer description of the deadlock. Now that QIONetListener supports waiting for clients in the main loop AioContext, NBD can use that to ensure that the server can make progress even when a client is intentionally starving the GMainContext from any activity not tied to an AioContext. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/3169 Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: new patch --- blockdev-nbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 1e3e634b87d..696474aea93 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -94,10 +94,10 @@ static void nbd_update_server_watch(NBDServerData *s) { if (s->listener) { if (!s->max_connections || s->connections < s->max_connections) { - qio_net_listener_set_client_func(s->listener, nbd_accept, NULL, + qio_net_listener_set_client_aio_func(s->listener, nbd_accept, = NULL, NULL); } else { - qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL= ); + qio_net_listener_set_client_aio_func(s->listener, NULL, NULL, = NULL); } } } --=20 2.51.1 From nobody Sun Nov 16 00:57:37 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762644111; cv=none; d=zohomail.com; s=zohoarc; b=LjZuvS7ViYY4sHM6eQMcNaKbzaeUS4+71h+yOu27ejwU4gmihE7yWqLucHyXiPcOo5G1HFFmOkfGQTagbw+wYGoLQnuf7fBCNH+0D0E02dicKAEM+gXU46z6+kiwlGlbkIhopsaci5x2Cx8gqRcyw1/DixcHxlEix3r6wF2953E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762644111; h=Content-Type: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=t1Hn5JAxT2XDEA1uwbAx5QKtwFdVZRbThx8XoBKz/Ts=; b=CuSTAM/UGS3wn9kpv1oYkv2J1rvD/ZQzxQK9GXmjWeBUvHCo1h+PahaeRtYhBm5MnAL34MsT1HoaxhyLpDfm9ZZ5a/B/l+gmo/MSVPPghlYOPT4eyTXud10AfaSUrDmyXFQ8vnt6OLvSPBjdVDJISQdcIS0Z2Plb0gc6oB2GktM= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762644111648675.5692383686596; Sat, 8 Nov 2025 15:21:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vHs0e-0005sQ-Ng; Sat, 08 Nov 2025 18:06:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0O-0005mP-2a for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:06:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vHs0L-0001m5-Ue for qemu-devel@nongnu.org; Sat, 08 Nov 2025 18:05:59 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-15-QOOqL-A2P8eKSfC-QRnBnQ-1; Sat, 08 Nov 2025 18:05:53 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 93B411956096; Sat, 8 Nov 2025 23:05:52 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.2]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E660519560A7; Sat, 8 Nov 2025 23:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762643157; 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=t1Hn5JAxT2XDEA1uwbAx5QKtwFdVZRbThx8XoBKz/Ts=; b=IkJWhBhbM0+9drYFyOVa3p0Kkzw4lcNOhkPf8AXDvMOIhptrdcplaHmu25QcH7+B6fXdwR UF4upPyXX1iEQvLSvnoBKW66UZ847pXdZhyd+MeyhWF8v2hfT/4MI20u6hAYMtVAsoq9I1 Ji6RNAQT9NtuXAVJNvPYoqkJjcTtFpk= X-MC-Unique: QOOqL-A2P8eKSfC-QRnBnQ-1 X-Mimecast-MFC-AGG-ID: QOOqL-A2P8eKSfC-QRnBnQ_1762643152 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, berrange@redhat.com, kwolf@redhat.com, Vladimir Sementsov-Ogievskiy , Hanna Reitz Subject: [PATCH v2 12/12] iotests: Add coverage of recent NBD qio deadlock fix Date: Sat, 8 Nov 2025 16:59:33 -0600 Message-ID: <20251108230525.3169174-26-eblake@redhat.com> In-Reply-To: <20251108230525.3169174-14-eblake@redhat.com> References: <20251108230525.3169174-14-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @redhat.com) X-ZM-MESSAGEID: 1762644113934158500 Content-Type: text/plain; charset="utf-8" Test that all images in a qcow2 chain using an NBD backing file can be served by the same process. Prior to the recent QIONetListener fixes, this test would demonstrate deadlock. The test borrows heavily from the original formula by "John Doe" in the gitlab bug, but uses a Unix socket rather than TCP to avoid port contention, and uses a full-blown QEMU rather than qemu-storage-daemon since both programs were impacted. The test starts out with the even simpler task of directly adding an NBD client without qcow2 chain ('client'), which also provokes the deadlock; but commenting out the 'Adding explicit NBD client' section will still show deadlock when reaching the 'Adding wrapper image...'. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/3169 Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Vladimir Sementsov-Ogievskiy --- v2: split out vvfat changes, add an explicit client in addition to the implicit one through qcow2 --- tests/qemu-iotests/tests/nbd-in-qcow2-chain | 94 +++++++++++++++++++ .../qemu-iotests/tests/nbd-in-qcow2-chain.out | 75 +++++++++++++++ 2 files changed, 169 insertions(+) create mode 100755 tests/qemu-iotests/tests/nbd-in-qcow2-chain create mode 100644 tests/qemu-iotests/tests/nbd-in-qcow2-chain.out diff --git a/tests/qemu-iotests/tests/nbd-in-qcow2-chain b/tests/qemu-iotes= ts/tests/nbd-in-qcow2-chain new file mode 100755 index 00000000000..455ddfa86fe --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-in-qcow2-chain @@ -0,0 +1,94 @@ +#!/usr/bin/env bash +# group: rw quick +# +# Test of opening both server and client NBD in a qcow2 backing chain +# +# Copyright (C) Red Hat, Inc. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +# creator +owner=3Deblake@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_qemu + _cleanup_test_img + rm -f "$SOCK_DIR/nbd" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +cd .. +. ./common.rc +. ./common.filter +. ./common.qemu +. ./common.nbd + +_supported_fmt qcow2 # Hardcoded to qcow2 command line and QMP below +_supported_proto file + +size=3D100M + +echo +echo "=3D=3D=3D Preparing base image =3D=3D=3D" + +TEST_IMG=3D"$TEST_IMG.base" _make_test_img $size + +echo +echo "=3D=3D=3D Starting QEMU and exposing base image =3D=3D=3D" + +_launch_qemu -machine q35 +h1=3D$QEMU_HANDLE +_send_qemu_cmd $QEMU_HANDLE '{"execute": "qmp_capabilities"}' 'return' +_send_qemu_cmd $QEMU_HANDLE '{"execute": "blockdev-add", + "arguments": {"node-name":"base", "driver":"qcow2", + "file":{"driver":"file", "filename":"'"$TEST_IMG.base"'"}}}' 'return' +_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start", + "arguments": {"addr":{"type":"unix", + "data":{"path":"'"$SOCK_DIR/nbd"'"}}}}' 'return' +_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", + "arguments": {"device":"base","name":"base"}}' 'return' + +echo +echo "=3D=3D=3D Adding explicit NBD client =3D=3D=3D" + +_send_qemu_cmd $QEMU_HANDLE '{"execute": "blockdev-add", + "arguments": {"node-name":"client", "driver":"nbd", + "read-only":true, "export":"base", + "server":{"type":"unix", "path":"'"$SOCK_DIR/nbd"'"}}}' 'return' +_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", + "arguments": {"device":"client","name":"client"}}' 'return' + +echo +echo "=3D=3D=3D Creating wrapper image =3D=3D=3D" + +_make_test_img -F raw -b "nbd+unix:///base?socket=3D$SOCK_DIR/nbd" $size + +echo +echo "=3D=3D=3D Adding wrapper image with implicit client from qcow2 file = =3D=3D=3D" + +_send_qemu_cmd $QEMU_HANDLE '{"execute": "blockdev-add", + "arguments": {"node-name":"wrap", "driver":"qcow2", + "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' 'return' +_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", + "arguments": {"device":"wrap","name":"wrap"}}' 'return' + +echo +echo "=3D=3D=3D Checking NBD server =3D=3D=3D" + +$QEMU_NBD --list -k $SOCK_DIR/nbd + +echo +echo "=3D=3D=3D Cleaning up =3D=3D=3D" + +_send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' '' + +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/tests/nbd-in-qcow2-chain.out b/tests/qemu-i= otests/tests/nbd-in-qcow2-chain.out new file mode 100644 index 00000000000..b65cdaa4f25 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-in-qcow2-chain.out @@ -0,0 +1,75 @@ +QA output created by nbd-in-qcow2-chain + +=3D=3D=3D Preparing base image =3D=3D=3D +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D104857600 + +=3D=3D=3D Starting QEMU and exposing base image =3D=3D=3D +{"execute": "qmp_capabilities"} +{"return": {}} +{"execute": "blockdev-add", + "arguments": {"node-name":"base", "driver":"IMGFMT", + "file":{"driver":"file", "filename":"TEST_DIR/t.IMGFMT.base"}}} +{"return": {}} +{"execute":"nbd-server-start", + "arguments": {"addr":{"type":"unix", + "data":{"path":"SOCK_DIR/nbd"}}}} +{"return": {}} +{"execute":"nbd-server-add", + "arguments": {"device":"base","name":"base"}} +{"return": {}} + +=3D=3D=3D Adding explicit NBD client =3D=3D=3D +{"execute": "blockdev-add", + "arguments": {"node-name":"client", "driver":"nbd", + "read-only":true, "export":"base", + "server":{"type":"unix", "path":"SOCK_DIR/nbd"}}} +{"return": {}} +{"execute":"nbd-server-add", + "arguments": {"device":"client","name":"client"}} +{"return": {}} + +=3D=3D=3D Creating wrapper image =3D=3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D104857600 backing_file= =3Dnbd+unix:///base?socket=3DSOCK_DIR/nbd backing_fmt=3Draw + +=3D=3D=3D Adding wrapper image with implicit client from qcow2 file =3D=3D= =3D +{"execute": "blockdev-add", + "arguments": {"node-name":"wrap", "driver":"IMGFMT", + "file":{"driver":"file", "filename":"TEST_DIR/t.IMGFMT"}}} +{"return": {}} +{"execute":"nbd-server-add", + "arguments": {"device":"wrap","name":"wrap"}} +{"return": {}} + +=3D=3D=3D Checking NBD server =3D=3D=3D +exports available: 3 + export: 'base' + size: 104857600 + flags: 0x158f ( readonly flush fua df multi cache block-status-payload ) + min block: 1 + opt block: 4096 + max block: 33554432 + transaction size: 64-bit + available meta contexts: 1 + base:allocation + export: 'client' + size: 104857600 + flags: 0x158f ( readonly flush fua df multi cache block-status-payload ) + min block: 1 + opt block: 4096 + max block: 33554432 + transaction size: 64-bit + available meta contexts: 1 + base:allocation + export: 'wrap' + size: 104857600 + flags: 0x158f ( readonly flush fua df multi cache block-status-payload ) + min block: 1 + opt block: 4096 + max block: 33554432 + transaction size: 64-bit + available meta contexts: 1 + base:allocation + +=3D=3D=3D Cleaning up =3D=3D=3D +{"execute":"quit"} +*** done --=20 2.51.1