From nobody Sun Feb 8 22:42:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164390599249683.57672783752707; Thu, 3 Feb 2022 08:33:12 -0800 (PST) Received: from localhost ([::1]:48460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFf2l-0002Mt-Na for importer@patchew.org; Thu, 03 Feb 2022 11:33:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0K-0007yj-09 for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:30:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54834) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0E-00007G-UD for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:30:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-_DeE4YXAMJ6yq4i2bARnCg-1; Thu, 03 Feb 2022 11:30:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5694839A42; Thu, 3 Feb 2022 16:30:29 +0000 (UTC) Received: from localhost (unknown [10.39.193.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F77284D24; Thu, 3 Feb 2022 16:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643905834; 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=4WNSXZb0CfazjaLqKJNvpi+xiMFdTNSe4k139keRfjo=; b=d+rTifpiDQqPmZmIugqXZTW1zqgrJ6S3p98bKCLEMyVes+vUXVXEDbGYDenaPHIkKsJNXo rZPrfpC3G0vMo2b9n6HQ92zw1HSx1L5uisKJ8fm5itDi94d2IlmnFCZJcTMnz9R2P1X+lt Q3gQPYZl1bOkLasmDIOB+SI2mzboNug= X-MC-Unique: _DeE4YXAMJ6yq4i2bARnCg-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH 1/7] block/nbd: Delete reconnect delay timer when done Date: Thu, 3 Feb 2022 17:30:18 +0100 Message-Id: <20220203163024.38913-2-hreitz@redhat.com> In-Reply-To: <20220203163024.38913-1-hreitz@redhat.com> References: <20220203163024.38913-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.086, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Eric Blake , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1643905993798100001 Content-Type: text/plain; charset="utf-8" We start the reconnect delay timer to cancel the reconnection attempt after a while. Once nbd_co_do_establish_connection() has returned, this attempt is over, and we no longer need the timer. Delete it before returning from nbd_reconnect_attempt(), so that it does not persist beyond the I/O request that was paused for reconnecting; we do not want it to fire in a drained section, because all sort of things can happen in such a section (e.g. the AioContext might be changed, and we do not want the timer to fire in the wrong context; or the BDS might even be deleted, and so the timer CB would access already-freed data). Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/nbd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index 63dbfa807d..16cd7fef77 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -381,6 +381,13 @@ static coroutine_fn void nbd_reconnect_attempt(BDRVNBD= State *s) } =20 nbd_co_do_establish_connection(s->bs, NULL); + + /* + * The reconnect attempt is done (maybe successfully, maybe not), so + * we no longer need this timer. Delete it so it will not outlive + * this I/O request (so draining removes all timers). + */ + reconnect_delay_timer_del(s); } =20 static coroutine_fn int nbd_receive_replies(BDRVNBDState *s, uint64_t hand= le) --=20 2.34.1 From nobody Sun Feb 8 22:42:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1643906078580401.04060978715404; Thu, 3 Feb 2022 08:34:38 -0800 (PST) Received: from localhost ([::1]:49364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFf49-0002yh-D5 for importer@patchew.org; Thu, 03 Feb 2022 11:34:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0k-0008CG-T3 for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30651) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0O-00008j-DX for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:06 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-wHZF_RN4MimY6l_NypGAqg-1; Thu, 03 Feb 2022 11:30:33 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2FC8E1923E21; Thu, 3 Feb 2022 16:30:32 +0000 (UTC) Received: from localhost (unknown [10.39.193.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA25F7E2FC; Thu, 3 Feb 2022 16:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643905841; 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=L/yALtGnRAFItyx6a9duy3eIiskc8Dxn6TJKEaTcPto=; b=WmVOZNOjDKDrTqxXbcTTO7WnnIFjnOHpf84DfPigD5BYTuzkgmlt/UUVokxMM9yIGdRGaK TaE8dKMoSn1pJph+v5iGu+frkRq/1tNaB524IPMiDHwXPH7syFSjCbXLk77zC/id6swmiX AF3IZ+fMaubqoeB1dPoh+jMuA1YiDkc= X-MC-Unique: wHZF_RN4MimY6l_NypGAqg-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH 2/7] block/nbd: Delete open timer when done Date: Thu, 3 Feb 2022 17:30:19 +0100 Message-Id: <20220203163024.38913-3-hreitz@redhat.com> In-Reply-To: <20220203163024.38913-1-hreitz@redhat.com> References: <20220203163024.38913-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.086, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Eric Blake , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1643906081230100003 Content-Type: text/plain; charset="utf-8" We start the open timer to cancel the connection attempt after a while. Once nbd_do_establish_connection() has returned, the attempt is over, and we no longer need the timer. Delete it before returning from nbd_open(), so that it does not persist for longer. It has no use after nbd_open(), and just like the reconnect delay timer, it might well be dangerous if it were to fire afterwards. Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/nbd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index 16cd7fef77..5ff8a57314 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1885,11 +1885,19 @@ static int nbd_open(BlockDriverState *bs, QDict *op= tions, int flags, goto fail; } =20 + /* + * The connect attempt is done, so we no longer need this timer. + * Delete it, because we do not want it to be around when this node + * is drained or closed. + */ + open_timer_del(s); + nbd_client_connection_enable_retry(s->conn); =20 return 0; =20 fail: + open_timer_del(s); nbd_clear_bdrvstate(bs); return ret; } --=20 2.34.1 From nobody Sun Feb 8 22:42:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1643906371352484.16918685865494; Thu, 3 Feb 2022 08:39:31 -0800 (PST) Received: from localhost ([::1]:57430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFf8s-00009x-JJ for importer@patchew.org; Thu, 03 Feb 2022 11:39:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0l-0008BP-4E for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:38677) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0K-00008J-Ef for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:05 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-423-9smOV8FaPumylX4fGLlpEQ-1; Thu, 03 Feb 2022 11:30:35 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82275101F001; Thu, 3 Feb 2022 16:30:34 +0000 (UTC) Received: from localhost (unknown [10.39.193.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 065BA7D733; Thu, 3 Feb 2022 16:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643905839; 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=ymvILgsBS/Vo7cWDrqWHnVe7ZzeJkUnlP0qB/HfqmAo=; b=Lw9N60OdMk0tPMvd9rfA6+6ltV0FcdAgthl14vNahmAWiiG//BUYB2d/eUFhQ2dwQY8+/X kxDFZTIUWK0TE8wfnxI18+CeYVJcavI5SuMsMjZyFYw62zJ/NSBY4zU2cVL2e2HzHfDYaZ YriNKW6kJpO0LmzTfWyz7BKOy9SSUGY= X-MC-Unique: 9smOV8FaPumylX4fGLlpEQ-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH 3/7] block/nbd: Assert there are no timers when closed Date: Thu, 3 Feb 2022 17:30:20 +0100 Message-Id: <20220203163024.38913-4-hreitz@redhat.com> In-Reply-To: <20220203163024.38913-1-hreitz@redhat.com> References: <20220203163024.38913-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.086, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Eric Blake , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1643906373526100001 Content-Type: text/plain; charset="utf-8" Our two timers must not remain armed beyond nbd_clear_bdrvstate(), or they will access freed data when they fire. This patch is separate from the patches that actually fix the issue (HEAD^^ and HEAD^) so that you can run the associated regression iotest (281) on a configuration that reproducibly exposes the bug. Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/nbd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index 5ff8a57314..dc6c3f3bbc 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -110,6 +110,10 @@ static void nbd_clear_bdrvstate(BlockDriverState *bs) =20 yank_unregister_instance(BLOCKDEV_YANK_INSTANCE(bs->node_name)); =20 + /* Must not leave timers behind that would access freed data */ + assert(!s->reconnect_delay_timer); + assert(!s->open_timer); + object_unref(OBJECT(s->tlscreds)); qapi_free_SocketAddress(s->saddr); s->saddr =3D NULL; --=20 2.34.1 From nobody Sun Feb 8 22:42:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1643906006804801.4107695057855; Thu, 3 Feb 2022 08:33:26 -0800 (PST) Received: from localhost ([::1]:48912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFf2z-0002g1-Tb for importer@patchew.org; Thu, 03 Feb 2022 11:33:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0c-00084v-1v for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:30:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57613) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0L-00008Q-HJ for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:30:56 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-481-P9umPPGGN-OlFxK9ZZne-A-1; Thu, 03 Feb 2022 11:30:37 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5FE81923E2D; Thu, 3 Feb 2022 16:30:36 +0000 (UTC) Received: from localhost (unknown [10.39.193.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53013838F4; Thu, 3 Feb 2022 16:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643905840; 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=2RSulqQVW0FxtExJ4AU+SeV2rsAMrAzO29tdEplsmxs=; b=MhIM4Q0cCUcznM4GO5xybpFjqlvICxlY9t1CD4srrc2ctA9CosOZI0nNwNfhnsYGuKvIoe x2GCtq5cZNhOQmW5zyieeaJH5ZeoVZw0cmZXyIU6MQAaaiexqSlVPqV/JhNStw0P2qOqos 5XS06FaW5RYpzS4wikcrw9eIafR0fVg= X-MC-Unique: P9umPPGGN-OlFxK9ZZne-A-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH 4/7] iotests.py: Add QemuStorageDaemon class Date: Thu, 3 Feb 2022 17:30:21 +0100 Message-Id: <20220203163024.38913-5-hreitz@redhat.com> In-Reply-To: <20220203163024.38913-1-hreitz@redhat.com> References: <20220203163024.38913-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.086, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Eric Blake , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1643906009479100001 Content-Type: text/plain; charset="utf-8" This is a rather simple class that allows creating a QSD instance running in the background and stopping it when no longer needed. The __del__ handler is a safety net for when something goes so wrong in a test that e.g. the tearDown() method is not called (e.g. setUp() launches the QSD, but then launching a VM fails). We do not want the QSD to continue running after the test has failed, so __del__() will take care to kill it. Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/iotests.py | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 8cdb381f2a..c75e402b87 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -73,6 +73,8 @@ qemu_prog =3D os.environ.get('QEMU_PROG', 'qemu') qemu_opts =3D os.environ.get('QEMU_OPTIONS', '').strip().split(' ') =20 +qsd_prog =3D os.environ.get('QSD_PROG', 'qemu-storage-daemon') + gdb_qemu_env =3D os.environ.get('GDB_OPTIONS') qemu_gdb =3D [] if gdb_qemu_env: @@ -345,6 +347,46 @@ def cmd(self, cmd): return self._read_output() =20 =20 +class QemuStorageDaemon: + def __init__(self, *args: str, instance_id: Optional[str] =3D None): + if not instance_id: + instance_id =3D 'a' + + self.pidfile =3D os.path.join(test_dir, f'qsd-{instance_id}-pid') + all_args =3D [qsd_prog] + list(args) + ['--pidfile', self.pidfile] + + # Cannot use with here, we want the subprocess to stay around + # pylint: disable=3Dconsider-using-with + self._p =3D subprocess.Popen(all_args) + while not os.path.exists(self.pidfile): + if self._p.poll() is not None: + cmd =3D ' '.join(all_args) + raise RuntimeError( + 'qemu-storage-daemon terminated with exit code ' + + f'{self._p.returncode}: {cmd}') + + time.sleep(0.01) + + with open(self.pidfile, encoding=3D'utf-8') as f: + self._pid =3D int(f.read().strip()) + + assert self._pid =3D=3D self._p.pid + + def stop(self, kill_signal=3D15): + self._p.send_signal(kill_signal) + self._p.wait() + self._p =3D None + + try: + os.remove(self.pidfile) + except OSError: + pass + + def __del__(self): + if self._p is not None: + self.stop(kill_signal=3D9) + + def qemu_nbd(*args): '''Run qemu-nbd in daemon mode and return the parent's exit code''' return subprocess.call(qemu_nbd_args + ['--fork'] + list(args)) --=20 2.34.1 From nobody Sun Feb 8 22:42:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1643906654484189.8226111920468; Thu, 3 Feb 2022 08:44:14 -0800 (PST) Received: from localhost ([::1]:37742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFfDR-000697-Rk for importer@patchew.org; Thu, 03 Feb 2022 11:44:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf10-0008Pd-2g for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29111) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0Q-00008z-FC for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:21 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-414-wsj_pwmPMrG3uIUcPjFnrw-1; Thu, 03 Feb 2022 11:30:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 852ED101F00A; Thu, 3 Feb 2022 16:30:39 +0000 (UTC) Received: from localhost (unknown [10.39.193.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A99F7E2FC; Thu, 3 Feb 2022 16:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643905843; 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=/s0Ok7H8vya+yuwTOYVHiZP76M6XFpS+F7WqzfTKSIE=; b=iWQyEhREwRYhJ74HQj29UFuMe3E5PT1/xvz3+o9ZQryanKo81JmCAiiOnCwJfH0Jn8iNLL XwPG2GTTzOLOk2/YGK/KGq4Cyrf+O2X2xuh3T23yRR2JZXyVjiBGYY52oXe9jTj/30AKNH Ftzbe6hqEpqjiAzpoFmz95nu12/9J+g= X-MC-Unique: wsj_pwmPMrG3uIUcPjFnrw-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH 5/7] iotests/281: Test lingering timers Date: Thu, 3 Feb 2022 17:30:22 +0100 Message-Id: <20220203163024.38913-6-hreitz@redhat.com> In-Reply-To: <20220203163024.38913-1-hreitz@redhat.com> References: <20220203163024.38913-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.086, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 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: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Eric Blake , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1643906656122100001 Content-Type: text/plain; charset="utf-8" Prior to "block/nbd: Delete reconnect delay timer when done" and "block/nbd: Delete open timer when done", both of those timers would remain scheduled even after successfully (re-)connecting to the server, and they would not even be deleted when the BDS is deleted. This test constructs exactly this situation: (1) Configure an @open-timeout, so the open timer is armed, and (2) Configure a @reconnect-delay and trigger a reconnect situation (which succeeds immediately), so the reconnect delay timer is armed. Then we immediately delete the BDS, and sleep for longer than the @open-timeout and @reconnect-delay. Prior to said patches, this caused one (or both) of the timer CBs to access already-freed data. Accessing freed data may or may not crash, so this test can produce false successes, but I do not know how to show the problem in a better or more reliable way. If you run this test on "block/nbd: Assert there are no timers when closed" and without the fix patches mentioned above, you should reliably see an assertion failure. (But all other tests that use the reconnect delay timer (264 and 277) will fail in that configuration, too; as will nbd-reconnect-on-open, which uses the open timer.) Remove this test from the quick group because of the two second sleep this patch introduces. (I decided to put this test case into 281, because the main bug this series addresses is in the interaction of the NBD block driver and I/O threads, which is precisely the scope of 281. The test case for that other bug will also be put into the test class added here. Also, excuse the test class's name, I couldn't come up with anything better. The "yield" part will make sense two patches from now.) Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/281 | 79 +++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/281.out | 4 +- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/tests/qemu-iotests/281 b/tests/qemu-iotests/281 index 318e333939..4fb3cd30dd 100755 --- a/tests/qemu-iotests/281 +++ b/tests/qemu-iotests/281 @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# group: rw quick +# group: rw # # Test cases for blockdev + IOThread interactions # @@ -20,8 +20,9 @@ # =20 import os +import time import iotests -from iotests import qemu_img +from iotests import qemu_img, QemuStorageDaemon =20 image_len =3D 64 * 1024 * 1024 =20 @@ -243,6 +244,80 @@ class TestBlockdevBackupAbort(iotests.QMPTestCase): # Hangs on failure, we expect this error. self.assert_qmp(result, 'error/class', 'GenericError') =20 +# Test for RHBZ#2033626 +class TestYieldingAndTimers(iotests.QMPTestCase): + sock =3D os.path.join(iotests.sock_dir, 'nbd.sock') + qsd =3D None + + def setUp(self): + self.create_nbd_export() + + # Simple VM with an NBD block device connected to the NBD export + # provided by the QSD + self.vm =3D iotests.VM() + self.vm.add_blockdev('nbd,node-name=3Dnbd,server.type=3Dunix,' + + f'server.path=3D{self.sock},export=3Dexp,' + + 'reconnect-delay=3D1,open-timeout=3D1') + + self.vm.launch() + + def tearDown(self): + self.stop_nbd_export() + self.vm.shutdown() + + def test_timers_with_blockdev_del(self): + # The NBD BDS will have had an active open timer, because setUp() = gave + # a positive value for @open-timeout. It should be gone once the = BDS + # has been opened. + # (But there used to be a bug where it remained active, which will + # become important below.) + + # Stop and restart the NBD server, and do some I/O on the client to + # trigger a reconnect and start the reconnect delay timer + self.stop_nbd_export() + self.create_nbd_export() + + result =3D self.vm.qmp('human-monitor-command', + command_line=3D'qemu-io nbd "write 0 512"') + self.assert_qmp(result, 'return', '') + + # Reconnect is done, so the reconnect delay timer should be gone. + # (This is similar to how the open timer should be gone after open, + # and similarly there used to be a bug where it was not gone.) + + # Delete the BDS to see whether both timers are gone. If they are= not, + # they will remain active, fire later, and then access freed data. + # (Or, with "block/nbd: Assert there are no timers when closed" + # applied, the assertions added in that patch will fail.) + result =3D self.vm.qmp('blockdev-del', node_name=3D'nbd') + self.assert_qmp(result, 'return', {}) + + # Give the timers some time to fire (both have a timeout of 1 s). + # (Sleeping in an iotest may ring some alarm bells, but note that = if + # the timing is off here, the test will just always pass. If we k= ill + # the VM too early, then we just kill the timers before they can f= ire, + # thus not see the error, and so the test will pass.) + time.sleep(2) + + def create_nbd_export(self): + assert self.qsd is None + + # Simple NBD export of a null-co BDS + self.qsd =3D QemuStorageDaemon( + '--blockdev', + 'null-co,node-name=3Dnull,read-zeroes=3Dtrue', + + '--nbd-server', + f'addr.type=3Dunix,addr.path=3D{self.sock}', + + '--export', + 'nbd,id=3Dexp,node-name=3Dnull,name=3Dexp,writable=3Dtrue' + ) + + def stop_nbd_export(self): + self.qsd.stop() + self.qsd =3D None + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2'], supported_protocols=3D['file'], diff --git a/tests/qemu-iotests/281.out b/tests/qemu-iotests/281.out index 89968f35d7..914e3737bd 100644 --- a/tests/qemu-iotests/281.out +++ b/tests/qemu-iotests/281.out @@ -1,5 +1,5 @@ -.... +..... ---------------------------------------------------------------------- -Ran 4 tests +Ran 5 tests =20 OK --=20 2.34.1 From nobody Sun Feb 8 22:42:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1643906455041359.89698259111526; Thu, 3 Feb 2022 08:40:55 -0800 (PST) Received: from localhost ([::1]:59416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFfAD-0001Z3-Uf for importer@patchew.org; Thu, 03 Feb 2022 11:40:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0t-0008IC-JV for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0R-00009Q-Ad for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:08 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-625-wJvwSbYyPd2k8pBW3B_aKg-1; Thu, 03 Feb 2022 11:30:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 206E1101F000; Thu, 3 Feb 2022 16:30:42 +0000 (UTC) Received: from localhost (unknown [10.39.193.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC1C77E5AF; Thu, 3 Feb 2022 16:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643905846; 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=ItNFeJ8ufoX3uuGQfNmnmxJlZPzBBwzibiijcWJPrUE=; b=boAPzyK7qrm+Od7B8zl2ck66l5QUp8lswkC/N9lYCBef0UqNf8NgVfIurAlwvrVUREr9aI ODi2gvxCZMJuRhJuvtUwnKCtuI1e2gB8/dFt9Un973yw7yMFHg5TK10zSNd5TYw+MPoQyd urNsNCXcCFvt8BslTw1ZCsM4Tr9vVi4= X-MC-Unique: wJvwSbYyPd2k8pBW3B_aKg-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH 6/7] block/nbd: Move s->ioc on AioContext change Date: Thu, 3 Feb 2022 17:30:23 +0100 Message-Id: <20220203163024.38913-7-hreitz@redhat.com> In-Reply-To: <20220203163024.38913-1-hreitz@redhat.com> References: <20220203163024.38913-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.086, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Eric Blake , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1643906456789100001 Content-Type: text/plain; charset="utf-8" s->ioc must always be attached to the NBD node's AioContext. If that context changes, s->ioc must be attached to the new context. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D2033626 Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/nbd.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index dc6c3f3bbc..5853d85d60 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -2055,6 +2055,42 @@ static void nbd_cancel_in_flight(BlockDriverState *b= s) nbd_co_establish_connection_cancel(s->conn); } =20 +static void nbd_attach_aio_context(BlockDriverState *bs, + AioContext *new_context) +{ + BDRVNBDState *s =3D bs->opaque; + + /* The open_timer is used only during nbd_open() */ + assert(!s->open_timer); + + /* + * The reconnect_delay_timer is scheduled in I/O paths when the + * connection is lost, to cancel the reconnection attempt after a + * given time. Once this attempt is done (successfully or not), + * nbd_reconnect_attempt() ensures the timer is deleted before the + * respective I/O request is resumed. + * Since the AioContext can only be changed when a node is drained, + * the reconnect_delay_timer cannot be active here. + */ + assert(!s->reconnect_delay_timer); + + if (s->ioc) { + qio_channel_attach_aio_context(s->ioc, new_context); + } +} + +static void nbd_detach_aio_context(BlockDriverState *bs) +{ + BDRVNBDState *s =3D bs->opaque; + + assert(!s->open_timer); + assert(!s->reconnect_delay_timer); + + if (s->ioc) { + qio_channel_detach_aio_context(s->ioc); + } +} + static BlockDriver bdrv_nbd =3D { .format_name =3D "nbd", .protocol_name =3D "nbd", @@ -2078,6 +2114,9 @@ static BlockDriver bdrv_nbd =3D { .bdrv_dirname =3D nbd_dirname, .strong_runtime_opts =3D nbd_strong_runtime_opts, .bdrv_cancel_in_flight =3D nbd_cancel_in_flight, + + .bdrv_attach_aio_context =3D nbd_attach_aio_context, + .bdrv_detach_aio_context =3D nbd_detach_aio_context, }; =20 static BlockDriver bdrv_nbd_tcp =3D { @@ -2103,6 +2142,9 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_dirname =3D nbd_dirname, .strong_runtime_opts =3D nbd_strong_runtime_opts, .bdrv_cancel_in_flight =3D nbd_cancel_in_flight, + + .bdrv_attach_aio_context =3D nbd_attach_aio_context, + .bdrv_detach_aio_context =3D nbd_detach_aio_context, }; =20 static BlockDriver bdrv_nbd_unix =3D { @@ -2128,6 +2170,9 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_dirname =3D nbd_dirname, .strong_runtime_opts =3D nbd_strong_runtime_opts, .bdrv_cancel_in_flight =3D nbd_cancel_in_flight, + + .bdrv_attach_aio_context =3D nbd_attach_aio_context, + .bdrv_detach_aio_context =3D nbd_detach_aio_context, }; =20 static void bdrv_nbd_init(void) --=20 2.34.1 From nobody Sun Feb 8 22:42:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164390638808635.818435008575875; Thu, 3 Feb 2022 08:39:48 -0800 (PST) Received: from localhost ([::1]:58416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFf98-0000r8-MM for importer@patchew.org; Thu, 03 Feb 2022 11:39:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf15-00007h-5Y for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFf0X-00009a-A0 for qemu-devel@nongnu.org; Thu, 03 Feb 2022 11:31:26 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-355-jCD6w5UbM3u5boE-MdcAbg-1; Thu, 03 Feb 2022 11:30:46 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 025193482D; Thu, 3 Feb 2022 16:30:45 +0000 (UTC) Received: from localhost (unknown [10.39.193.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7CCAB838F5; Thu, 3 Feb 2022 16:30:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643905849; 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=0KJjLSudaoqHjfF16i06/5H+Wzv5hFo5o+OBIEnkpck=; b=JwYLpyT83rqS0InruyA5dvDpmIDkW82mGK8edBPV/8u1+IH1sbh6G1XdFlqwlBdMNSWqKf kIDhZzqLUPcmF9tKxw9uCdmuAiMzn5xPi012JXZfwoIvPrt7UwZcNynoO3gxXZySeDgTTl j05ZLBirqc5jdqUaYAIa7pESoskDZkY= X-MC-Unique: jCD6w5UbM3u5boE-MdcAbg-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PATCH 7/7] iotests/281: Let NBD connection yield in iothread Date: Thu, 3 Feb 2022 17:30:24 +0100 Message-Id: <20220203163024.38913-8-hreitz@redhat.com> In-Reply-To: <20220203163024.38913-1-hreitz@redhat.com> References: <20220203163024.38913-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.086, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Eric Blake , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1643906389426100001 Content-Type: text/plain; charset="utf-8" Put an NBD block device into an I/O thread, and then read data from it, hoping that the NBD connection will yield during that read. When it does, the coroutine must be reentered in the block device's I/O thread, which will only happen if the NBD block driver attaches the connection's QIOChannel to the new AioContext. It did not do that after 4ddb5d2fde ("block/nbd: drop connection_co") and prior to "block/nbd: Move s->ioc on AioContext change", which would cause an assertion failure. To improve our chances of yielding, the NBD server is throttled to reading 64 kB/s, and the NBD client reads 128 kB, so it should yield at some point. Signed-off-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/281 | 28 +++++++++++++++++++++++++--- tests/qemu-iotests/281.out | 4 ++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/281 b/tests/qemu-iotests/281 index 4fb3cd30dd..5e1339bd75 100755 --- a/tests/qemu-iotests/281 +++ b/tests/qemu-iotests/281 @@ -253,8 +253,9 @@ class TestYieldingAndTimers(iotests.QMPTestCase): self.create_nbd_export() =20 # Simple VM with an NBD block device connected to the NBD export - # provided by the QSD + # provided by the QSD, and an (initially unused) iothread self.vm =3D iotests.VM() + self.vm.add_object('iothread,id=3Diothr') self.vm.add_blockdev('nbd,node-name=3Dnbd,server.type=3Dunix,' + f'server.path=3D{self.sock},export=3Dexp,' + 'reconnect-delay=3D1,open-timeout=3D1') @@ -299,19 +300,40 @@ class TestYieldingAndTimers(iotests.QMPTestCase): # thus not see the error, and so the test will pass.) time.sleep(2) =20 + def test_yield_in_iothread(self): + # Move the NBD node to the I/O thread; the NBD block driver should + # attach the connection's QIOChannel to that thread's AioContext, = too + result =3D self.vm.qmp('x-blockdev-set-iothread', + node_name=3D'nbd', iothread=3D'iothr') + self.assert_qmp(result, 'return', {}) + + # Do some I/O that will be throttled by the QSD, so that the netwo= rk + # connection hopefully will yield here. When it is resumed, it mu= st + # then be resumed in the I/O thread's AioContext. + result =3D self.vm.qmp('human-monitor-command', + command_line=3D'qemu-io nbd "read 0 128K"') + self.assert_qmp(result, 'return', '') + def create_nbd_export(self): assert self.qsd is None =20 - # Simple NBD export of a null-co BDS + # Export a throttled null-co BDS: Reads are throttled (max 64 kB/s= ), + # writes are not. self.qsd =3D QemuStorageDaemon( + '--object', + 'throttle-group,id=3Dthrgr,x-bps-read=3D65536,x-bps-read-max= =3D65536', + '--blockdev', 'null-co,node-name=3Dnull,read-zeroes=3Dtrue', =20 + '--blockdev', + 'throttle,node-name=3Dthr,file=3Dnull,throttle-group=3Dthrgr', + '--nbd-server', f'addr.type=3Dunix,addr.path=3D{self.sock}', =20 '--export', - 'nbd,id=3Dexp,node-name=3Dnull,name=3Dexp,writable=3Dtrue' + 'nbd,id=3Dexp,node-name=3Dthr,name=3Dexp,writable=3Dtrue' ) =20 def stop_nbd_export(self): diff --git a/tests/qemu-iotests/281.out b/tests/qemu-iotests/281.out index 914e3737bd..3f8a935a08 100644 --- a/tests/qemu-iotests/281.out +++ b/tests/qemu-iotests/281.out @@ -1,5 +1,5 @@ -..... +...... ---------------------------------------------------------------------- -Ran 5 tests +Ran 6 tests =20 OK --=20 2.34.1