From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787040; cv=none; d=zohomail.com; s=zohoarc; b=XUnGM8jjaO0ETKQuM5Wr1ArVZjIkE7N1CBHMLPExuVIaXYAaS9gyOCbULLoupqY3Gaj/nDDbBJUxopeswl3FSnI6i2YBYqBf1jqSxUR862vFT13HzNpNdLdqvmg0Zkxr3f0X0ulRGhp6bzogVXYUKRv3jLWryUhW2C/zPBwT2Mg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787040; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=02pJqpidZlyztGLDO4CVTQG7JLwu5zrLatcXjsrC0zQ=; b=mfaJw1vCFZlCpw/GmIYF/lpczu9e6j9MF/VLd7Yd/y16KQK2EqSnKoFZYMUe1vQGDIRLBsaXyFdBLOuaxn6d361G/bjNvavQKMhMBxJngzwDXYj1Y6brwBxJKuI8Dlqklq1r85USMv3bkrSOtwjGxvus/Mk3pIB3FDCK5qZb958= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787040207942.8733919015366; Wed, 30 Sep 2026 09:50:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxVm-0006ep-SZ; Wed, 30 Sep 2026 12:50:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVQ-0006Mn-Mu for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:09 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVO-0003V3-1Z for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:08 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49cd5462b69so31675755e9.1 for ; Wed, 30 Sep 2026 09:50:05 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787005; x=1791391805; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=02pJqpidZlyztGLDO4CVTQG7JLwu5zrLatcXjsrC0zQ=; b=dOA++NWcMhhSy46omblgXhP4XGLNAcfVoRDKvupiiJuU4DXTaYlVu9/zSdfBMWEw18 gJrIDvXPsvKqsA0+9jjuF0vtkgEwdLrLehOHnrCmrWLl69o7iXdwLKRR63caXVNFJOR5 8psEJ/FNQcRxmsj4myx+em+RDM2T/Ey0zuQHO/WCl2re6cf6tkqkjiXWdyP9l7QPuV9b YfS+hsx67P5W+SXZF0Y7sYoRD8RNZvGRlyXoiK8BQk0/Pjg8UWDTAUSVY1PmgnnaU7sK qNmL+LXE8IR5LPelgl0u2nZ8mM/b4sV6WqrRQTdVSG3Lw9IVjs2pWFSXIv0fQ9a7FGv3 mZPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787005; x=1791391805; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=02pJqpidZlyztGLDO4CVTQG7JLwu5zrLatcXjsrC0zQ=; b=pgskBuAPHvZa/sd4Pa9hwzdOXLGBV4IUNc9KouzlSX1fDfUbPkwLGH/Wei9oYExOXW +SkVEU0aPJBPLaHxhkALeOxWoQW8k0p/mpuwy92sZoAdv9L/h8NSaPNMkUknxpCc0QJf fL5Yfrj9l177TlHjz7Ty9U3BF98UC3UktNpjq83DsiBer0pghn5ahUf+3ih7fdngE4bm 1n4omG3j2eOT+gwRMAqUfECBsV/VqKrf/vvAAQD3PTRxH5NTQJoOabh+JD116oiX50wQ bvj8nBRl6JgSfN/eNNza95Cgh5GcKhz3lZQrnEKiliwfoVGFstlhbc1O6AM0NtIyzkIb 3m6A== X-Gm-Message-State: AFuF++n9Pg7XXzv9KhxQ/34ZGB1rvlt2dAhL23oFPKvo1aQkOBQZMdBt hdbMiptcZHVl0PU9hgR5GzAxI5LYTk+XY3KbySzdFuKtORMuVkKpPNSsYrYpv6nUH7pkMVqSXJU +Dg78 X-Gm-Gg: AYBFou3puGSaeEp0XaJpty/nBKmvaJlBk+nIvAoVPOqKYBewCo8B3K4cxgC+1HGrzU9 S1hvsLjY+tUxZt6q/GpsGI3cOgxNJ6nNiTFJ3Z28j1y5RJIp+64m0/+SolB+oEVSXR+CfxsKnKZ bR+NqrbKg9tgyN7/SISSS1t3nHixWyolCeTpoypSqeQ1U3lK6OFVO9AE74lG1+mRr1GXr6/FMK5 TDD+NBzAiIr968BE3zBsgA4DmhDlqB9RnJSUSnfkZbVePjBc6WyPOtDf/x53+zQqFA8ey4lZclP /KDZf6twk7/upM/zUt0oAA8wij2idrAGXmHwBdRDHrXP+nEuBrGTbxZUShkHnaINBNyLitZS+vr v3EK0lBSoiAoX4ZBKXX5u+IMIooFudrzGDzQMIDm74nZKUStEaMypLf5NMZtxpa0df7jsP34ceY UbeJRbrta1KPKQEz9LOdVFxBQWzW54EaSFkbWNenxdVDjLg0u6t3uiFucKEYn2dWRcPfk= X-Received: by 2002:a05:600c:8b88:b0:49f:ce78:356d with SMTP id 5b1f17b1804b1-4a01b12b389mr33017365e9.30.1790787004646; Wed, 30 Sep 2026 09:50:04 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, qemu-stable@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 01/13] block/file-posix: drop the XFS workaround for post-EOF fallocate Date: Wed, 30 Sep 2026 18:49:47 +0200 Message-ID: <20260930165000.303236-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787043161158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev 292d06b925b extended the tracked request of a post-EOF write zeroes to infinity and made it serialising, to work around an XFS bug where AIO writes past EOF were discarded by a concurrently extending fallocate(). The kernel bug was fixed by 249bd9087a52 ("xfs: properly serialise fallocate against AIO+DIO"), which moves inode_dio_wait() up under IOLOCK_EXCL so fallocate cannot run alongside in-flight AIO. That landed in v5.5, three days before the workaround was committed here, and predates every stable series still maintained. The workaround runs on every filesystem and on every write zeroes past EOF, which for the preallocate filter is every preallocation. It widens the request to the end of the address space and makes it serialising, so it excludes every other request above its offset, and it does that after bdrv_co_write_req_prepare() has honoured BDRV_REQ_NO_WAIT, so the flag no longer holds for the rest of the request. Drop it. The only series that never took the kernel fix is 4.19.y, which is end of life. Signed-off-by: Denis V. Lunev Cc: qemu-stable@nongnu.org CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev Reviewed-by: Andrey Drobyshev --- block/file-posix.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 9aad156aad..529e302041 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3658,40 +3658,6 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t o= ffset, int64_t bytes, RawPosixAIOData acb; ThreadPoolFunc *handler; =20 -#ifdef CONFIG_FALLOCATE - if (offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) { - BdrvTrackedRequest *req; - - /* - * This is a workaround for a bug in the Linux XFS driver, - * where writes submitted through the AIO interface will be - * discarded if they happen beyond a concurrently running - * fallocate() that increases the file length (i.e., both the - * write and the fallocate() happen beyond the EOF). - * - * To work around it, we extend the tracked request for this - * zero write until INT64_MAX (effectively infinity), and mark - * it as serializing. - * - * We have to enable this workaround for all filesystems and - * AIO modes (not just XFS with aio=3Dnative), because for - * remote filesystems we do not know the host configuration. - */ - - req =3D bdrv_co_get_self_request(bs); - assert(req); - assert(req->type =3D=3D BDRV_TRACKED_WRITE); - assert(req->offset <=3D offset); - assert(req->offset + req->bytes >=3D offset + bytes); - - req->bytes =3D BDRV_MAX_LENGTH - req->offset; - - bdrv_check_request(req->offset, req->bytes, &error_abort); - - bdrv_make_request_serialising(req, bs->bl.request_alignment); - } -#endif - acb =3D (RawPosixAIOData) { .bs =3D bs, .aio_fildes =3D s->fd, --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787101; cv=none; d=zohomail.com; s=zohoarc; b=IeHhc76hn2exsoROU6J5D+r/8qoohdF5BaSgKXEuzG6OKt3DXMN6/nQ18JPAxpbCrmGVFUpbk5EeEb7qQhB8y4oefOBQqzT4aNywBShdO1Zy5dBGL2cOJihbinGzOrjUmApBr9S7f4VT172UgxLyi7O+aLXv+bYStg7IIn//LTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787101; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4/ucdW8y7gbahjmT+R0rE/I3juMJxREJdmg4f8wpT3c=; b=O+iKFMEt+rbHaPv/UMu6g/ddLYsWclW6tRZGjCRrv5zXzWi+VR0vMwEq075Lkwg5ZOgbpyDX3romsotx/4Uv2AwiMu22epZAiIgKR7k6yt4CBXrm+upMfzM2uG1evqka5VOPZFOx+AZV7irAZSMrtnLqPzO9KwlP/fk/APtgGTg= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787101101962.9911658925273; Wed, 30 Sep 2026 09:51:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxVy-00076W-ID; Wed, 30 Sep 2026 12:50:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVS-0006OI-46 for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:12 -0400 Received: from mail-wr2-x0f.google.com ([2a00:1450:4864:30::f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVP-0003VH-PC for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:09 -0400 Received: by mail-wr2-x0f.google.com with SMTP id ffacd0b85a97d-48b042e00f7so409918f8f.0 for ; Wed, 30 Sep 2026 09:50:07 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787006; x=1791391806; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=4/ucdW8y7gbahjmT+R0rE/I3juMJxREJdmg4f8wpT3c=; b=OHzIEAm6pLQ/MOtZ0rCWQ17GFrZgvVnsZdgc566UjoWYtAswkcMkeOg0olqkuxfvqR TwZDQ8B0qnlhCaXGyvs9OtP8X8ARU+plehRSrGOlnJvuTibJzrmQXxtsDh3NcsfcD6ht 20FMrdrzPHAApSCSTF15TlzN0RnyIMuxeltcl5Ez1eyhZKm+vZ8hh9G1EpltbOZbPFWL r7zvx6LzJ1VC4I8cAZNcypYzHkabTi33yTfD1ebNj8ENIMZBaZMzGb572yTvXOn7Nfej v+I6p/aiXmoTPdPRJdxbJfo9498hTWSTwvRWAbD9vj021f1VBzq0usVUUfSG/QIbWf/X 99sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787006; x=1791391806; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=4/ucdW8y7gbahjmT+R0rE/I3juMJxREJdmg4f8wpT3c=; b=hkuR/pG88N1/YgIrEvXtsV63MZ/wa4tb1DZ4S025bFtkvFUUn23F6PE7x69+AFW89j Ms7li9Pzltih4k2DWTPj9T9NqOUSSaBm14+WE1uo51h6/5XxDIc+a8cyJlwKAS8r6+O1 FppLJ5gbS7sbGmJ2PL+HHyQ+Rl9BHbfUFQ0mkNiBQ1HtOJK/q/hi4gdZLpziHP3bLyr/ v7Zd+VV1ukbRJrPcrGUZ5oFdrFWScI7PMnII8o13N4H2u+I7GdgKnk1dn0e5Jgasw3Dx H175X0nqctB85zDhp12+m6/bukKZ7rdvESZvLztiEq20q9y3PSMYwblY6J1HtkwsYz97 zrlQ== X-Gm-Message-State: AFuF++l6rvL3c+ZJWK04mQFvA1HYkS4jqVauAsk2GC4ffGM2O/M+VMmS n+Za+SR17bzuHRQCDwU3Av/2T9qKtTpzbTK/bG/6E8UiJOzinmWMAWvOiFBTA3Kpds4BhGfwZN1 2deJK X-Gm-Gg: AYBFou0KeTHxUZcHzisPgWqsJLcUoycvh34GUswVMWpNicd8vtqJx3+9vF0v+X+Hw1A l8olMUk1i+QrcdbJEh/itYARhRxRqYh3OFbKplMwGMPtLm1nC0KBku6CnlXwcOQAQon0F5qK9uS Iqa7L1l5lNhYOkwe1c/jdtwIkIvf9KUS/+SMFqmELOeBe5fx5Pxo7qI7brSixteC3s6xcPBoyky tFZzXjk33XgdrO4k659YKKKULWpM1SL+5LxIEm7l5gxZLR4Ih+wgJy5qfQ8J2T+kxCWimE3Vac2 JLCIosZCeypcb34NUFPKbndEIbbkEgSL8j8x5K9LBi8UJanYDU9aVu6J7M5GfQqaruJNk+/R8JH Rj0vINqwEfut+lVhUEU9kTTHgGWOwu2jafPmeba3tbcNDuJZziEp1TveAaYNpv71v/6B9tevZLZ jsKfe+ADSfMcFNJh/2RxiAX77y6n/o1t46i75hZOWMdTdWTpookJhyGDmMjLjWRLNQQ10= X-Received: by 2002:a05:600c:3b21:b0:4a0:1a7f:2ab7 with SMTP id 5b1f17b1804b1-4a01afe1ecemr35372175e9.10.1790787006194; Wed, 30 Sep 2026 09:50:06 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, qemu-stable@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 02/13] block/preallocate: keep zero_start above written data Date: Wed, 30 Sep 2026 18:49:48 +0200 Message-ID: <20260930165000.303236-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::f; envelope-from=den@openvz.org; helo=mail-wr2-x0f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787102614158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev The filter records where the trailing preallocated zeroes begin, and skips a write zeroes request that starts at or above that point, because the range is zero already. A plain write below data_end returns before that bookkeeping, so a write into the zero region leaves the mark behind it. The guest then loses an acknowledged write zeroes over the range: it is skipped as already zero, and the plain write's data stays. Reachable from qcow2 when a cluster is allocated again after a discard and the allocating write zeroes straddles data_end. Move the mark past any write that reaches into the region it covers and leaves data there. want_merge_zero is what the function already uses to tell those apart when the write extends the file: a request that writes zeroes leaves the region zero and the mark where it is. Signed-off-by: Denis V. Lunev Cc: qemu-stable@nongnu.org CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev --- block/preallocate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/preallocate.c b/block/preallocate.c index d215bc5d6d..99bd6b1ae7 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -347,6 +347,10 @@ handle_write(BlockDriverState *bs, int64_t offset, int= 64_t bytes, } } =20 + if (!want_merge_zero && s->zero_start >=3D 0 && end > s->zero_start) { + s->zero_start =3D end; + } + if (end <=3D s->data_end) { return false; } --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787086; cv=none; d=zohomail.com; s=zohoarc; b=JA2I78xGQHf1GTfPxfPfD8bC6qbGoT0y8/wBgofU0Ura0WvgLx4pXoWE6FuIPkKFZV2ZMG/UOHy7yMbzMPgZAbiwSDFPDlVPK+K63z4QhYakPdM6wTA4SA7GMWF5GcAg/bWsDXEuwMmny14JZ4L2q+luVpnNGjOpZi2GNN7/lKk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787086; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=arxabVZu3G5gPytGTqP4ECM41QbAg7PaAj4k4dx1Ulc=; b=QEV1NXu9SLzmg3Se6YpZA41pw8hlk0/bXhlOEKgZ7oCM4qVPegSNXu7gJbN5cLHIj+YrXHCkNPbb6SwD7cwfDOQgGCsZKiuKyZJLCMgT0wYZuz/v+GoHRcFfCG2DFMvA4vCXqZKnsA8iHXUt8O2am+r1Y4nJId3G2RM/lVXdTxw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787086729919.6541931494279; Wed, 30 Sep 2026 09:51:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxW0-0007K1-LZ; Wed, 30 Sep 2026 12:50:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVW-0006QG-H3 for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:17 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVQ-0003Vf-WD for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:10 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49ffe817151so24343335e9.0 for ; Wed, 30 Sep 2026 09:50:08 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787007; x=1791391807; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=arxabVZu3G5gPytGTqP4ECM41QbAg7PaAj4k4dx1Ulc=; b=NjiJ+sgP3jwVuh9XemDVcRT7+gbUDoXtB1W1DjmH9GRQD00EYwt18rp2jakknBNUv7 FE97jtKPcDgGHgEfV76YEAxyk35vixBape2hhWzXBeiX7yKPytctBlZxl2RIQYLI7p9g 608sbF41cyt4XjizsGPmVTsNKy4sDz1MbY3Xneh72X/wQdsG8derG8F/aTr6FRu7swBO bgzsIawXRcZ1AlEtU4trmJlbBuUYBWMeH8wS0uzsuU7bD+ZiUrLbw2LfGli4FrlJ6bgz jsLiN+F3Agf4TvUoWkaH16205g46PDPyTuoCU33RQmFUAf9AB/e0ba7FVSm/WcjuCMB4 nddw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787007; x=1791391807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=arxabVZu3G5gPytGTqP4ECM41QbAg7PaAj4k4dx1Ulc=; b=P+vf9kij/LL57vx8nYGIRBTYtCJP9gggjqjZUT8DhzfPDWtW+D0OkOixNBYleCcaOo dzB/ckcnlHFYkmeGOwIvAeXWBmJ4lCvgvSy4LhAvav0LjZ6PGE1tlMtTHHBp9tPx8Uok l50o4PtOc1TecWZQ3ZW1NKuLuixu5Hnb5pullSdQykORkRENUw3LN/mpqv6lKod4yH3s YwPodNieAoQrC2o+LUVYTNROkNizaUjdl/IaSiWmwwSQ2Fzp9UOUZQUKFWvOaE0z5hVs D0qumFKS2qDXyxcpgtLj5i3HE7bdFyJDNg3Z/+zlN3snMBv0IOho6IsRfY1rDSiTeSL2 K4Pg== X-Gm-Message-State: AFuF++mJmW0Ur4TVxO9dag0OqXqUIGhJ5WfOcX0yL8NNS4RzoFuxmeFd teFXMoVTuhOal2PYXJkAqaXpoxVi2zynwV08N8LMavm0W6VBzNfXlr+VGKq5UurEtaIKbw4vdBt GcybJ X-Gm-Gg: AYBFou2OAxPjMGa0GbncyIsfNkcRQVBS9kzKMQ48D9csZ1HbI5qYH6JSABoFy8dL0im eu0co2VyScPAvTtohaHL6mr53OVZN5Bi0lWU/THxsnHd/y8iPLdrwXBjDW69Yxc8HWRWnd2qVlV LbzBRjPfAAfLpVWOEyATtKoFBJz6+UvXZ+yawGIXKcTE7+rtStcJ9meWLEUXKnUW6tSM8J1UFz0 AaKN5S1lOO1Sod5uni5g2d/VoELs1Qwr7vcVKoPO3bzEcrXG7Pq2EVdT9OjGFrPe8Z9LPzJZ+tW T01XNWx0osZCvSfd3XFenGsTywa8sLxBGyoIM2sQp4nfXLlzmDkW9SCDnV/RhfK3kdrdeK/dIpO /+Qf2+22CllKJhwThl2L0q5vOLVXGcfU5H3khHaq10Sg/8GVRg/Qcb71pOfIDVL2tj4sB+Xsqc3 tpZdEJOpRVOU8nFNeaKud99ECpOBfo8mBmNfsxpnxOsswQJ8nnpHQ7YfZtbV5fZMXDqAc= X-Received: by 2002:a05:600c:800e:b0:49f:ff6b:bc82 with SMTP id 5b1f17b1804b1-4a01b00d9a1mr34465385e9.20.1790787007487; Wed, 30 Sep 2026 09:50:07 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, qemu-stable@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 03/13] block/preallocate: collect the state assignments in one place Date: Wed, 30 Sep 2026 18:49:49 +0200 Message-ID: <20260930165000.303236-4-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=den@openvz.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787088487158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev The filter invalidates or re-establishes data_end, zero_start and file_end together in six places, each spelling out the same chained assignment. Put them in one function, so that a change to what the state consists of is one edit rather than six. No functional change. Signed-off-by: Denis V. Lunev Cc: qemu-stable@nongnu.org CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev Reviewed-by: Andrey Drobyshev --- block/preallocate.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/preallocate.c b/block/preallocate.c index 99bd6b1ae7..8cd98684f4 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -104,6 +104,11 @@ static QemuOptsList runtime_opts =3D { }, }; =20 +static void preallocate_set_state(BDRVPreallocateState *s, int64_t v) +{ + s->file_end =3D s->zero_start =3D s->data_end =3D v; +} + static bool preallocate_absorb_opts(PreallocateOpts *dest, QDict *options, BlockDriverState *child_bs, Error **er= rp) { @@ -149,7 +154,7 @@ static int preallocate_open(BlockDriverState *bs, QDict= *options, int flags, * s->data_end and friends should be initialized on permission update. * For this to work, mark them invalid. */ - s->file_end =3D s->zero_start =3D s->data_end =3D -EINVAL; + preallocate_set_state(s, -EINVAL); s->drop_resize_bh =3D qemu_bh_new(preallocate_drop_resize_bh, bs); =20 ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); @@ -480,12 +485,12 @@ preallocate_co_truncate(BlockDriverState *bs, int64_t= offset, =20 ret =3D bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, err= p); if (ret < 0) { - s->file_end =3D s->zero_start =3D s->data_end =3D ret; + preallocate_set_state(s, ret); return ret; } =20 if (has_prealloc_perms(bs)) { - s->file_end =3D s->zero_start =3D s->data_end =3D offset; + preallocate_set_state(s, offset); } return 0; } @@ -508,7 +513,7 @@ preallocate_co_getlength(BlockDriverState *bs) ret =3D bdrv_co_getlength(bs->file->bs); =20 if (has_prealloc_perms(bs)) { - s->file_end =3D s->zero_start =3D s->data_end =3D ret; + preallocate_set_state(s, ret); } =20 return ret; @@ -539,7 +544,7 @@ preallocate_drop_resize(BlockDriverState *bs, Error **e= rrp) * change the child, so mark all states invalid. We'll regain control = if a * parent requests write access again. */ - s->data_end =3D s->file_end =3D s->zero_start =3D -EINVAL; + preallocate_set_state(s, -EINVAL); =20 bdrv_child_refresh_perms(bs, bs->file, NULL); =20 @@ -566,8 +571,8 @@ preallocate_set_perm(BlockDriverState *bs, uint64_t per= m, uint64_t shared) if (can_write_resize(perm)) { qemu_bh_cancel(s->drop_resize_bh); if (s->data_end < 0) { - s->data_end =3D s->file_end =3D s->zero_start =3D - bs->file->bs->total_sectors * BDRV_SECTOR_SIZE; + preallocate_set_state(s, + bs->file->bs->total_sectors * BDRV_SECTOR_SIZE); } } else { qemu_bh_schedule(s->drop_resize_bh); --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787084; cv=none; d=zohomail.com; s=zohoarc; b=d5yo1Qzq+3MYKUSpEd/hf3CbncLMEs05jju+2UAijbMPEwpgqVHL725Up92d4yDQbDZQ3Oqxr0P1zikwpbE0EK8JA0rF/gWXBkgV+cF5ZZ1zyl1KU8N5rJ8edM6Tu4LlN4drE2kKcLthEu76vBl5yUd2b68iei+clWRhQnwe3CI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787084; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5ofn20N1FUg18TXR7Ved1Q66g4OfV1gHL7SrWzTzJ5Q=; b=WbjCee1s5dXSCZp/++K4MVRFu1vdsVOsz+/IevmuFlShaYNUa4dIIC+HgcREdUqIbzdzXbFo0W9AqkIEZCM+pE83LdTCNLZrSBmOeXVMfveYIPEaizeVsKEf/eeG0DjVXxYP+phq2FMt42aZzPzQ+O5+kyp1yZgCWDye6s/09vY= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179078708410239.39895047118898; Wed, 30 Sep 2026 09:51:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxW3-0007X5-1R; Wed, 30 Sep 2026 12:50:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVZ-0006SP-Oz for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:20 -0400 Received: from mail-wr2-x0e.google.com ([2a00:1450:4864:30::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVW-0003WL-8d for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:17 -0400 Received: by mail-wr2-x0e.google.com with SMTP id ffacd0b85a97d-48b017a3be3so801671f8f.2 for ; Wed, 30 Sep 2026 09:50:10 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787009; x=1791391809; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5ofn20N1FUg18TXR7Ved1Q66g4OfV1gHL7SrWzTzJ5Q=; b=icO7hAkq9X3E8p5LIjcUbItFq+dM6c9VDN9JA6EfQlw7arwerhIaZUqf9f6e1qgLKA jyLcxk1EgGfcWTaIR0iK+tzpUg7IrsFI+NlNtyxrNhdrJhztuY2FgSwUOViZHKS6y11M vIlOljOjXYveaDlLi6q5vrG/kKmlXO1qVCpF2ez9RFvD2Tzz4mj6nV9TLgaR6xiao6W2 gr/sO8yofv8X+5p0znNM3riWlJSvtvbYU6ipU2eBNjRYVk5L/y0IGsIIWvqcrLktMsBH sa2KArB6OLRDKYUWUVyx2iaBjIbs6niJZczadyu/ZPYhMEBUtYtF2rqeFR9HxN14GAOd biBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787009; x=1791391809; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5ofn20N1FUg18TXR7Ved1Q66g4OfV1gHL7SrWzTzJ5Q=; b=ooL86KBJN9TL+f1hphGTUMQY6N3+BnC1wJukm+fU59z+BwkjFMQ+YPf0w/A017xXDy jcZGoi9oRkzMEaqQ7RGNe31kRg/NHVU/j0+D+hOrIyE3lhyO3o66wRlCX+ZSYwAlLSyB dBxqnSNextnSaPSUYtqF5ZIuY2uIDtJOg0RWFDxroxugfFunrJ6uzTNaYX5ixDaO3Ac1 Gvp7L8pa34SRIyARKJ8pHwQJyuqwOUNHqLZfN86k+kXluVZnOOhAnKX2FgDuwsAPvmjd rrD4KpliwmnSOe8gDPQwf+zSnZQK/Iyycme0Ee0X2sh1Riob9DomKxB8YGJI/tDFhGkQ ZPMA== X-Gm-Message-State: AFuF++lF05eEvaVVqncuvPLT1ObniMqQ7XA3xTZt1Iyae09/1wq2Vw/x atcZXwAcfw1XWcLxT3N6f/XtaR25C9fKEkSycxq7yuejI2DfRCYgh+Rz4mSZq4uu5VQRzfBKK8q qkITI X-Gm-Gg: AYBFou2xLpWKLziGlDDr5eD/ohnm9pYW7NVVzQHG4haHqqkaDRGgKlfndZ5J4001jjS PKqg4mbHy60lbzy+9I08QvOZSc7Kp+6oX/bbQWD5n31T9dlmJ2MLDWb8datbnisNL4qicON5vNp e+TxpvB1UW/ESMicyn+N82OZCraCDIwxcl7QfH459LHcNP6rif4oppg/fb9D7cjiPT0eCeRPWsW qcaV+6WolUzFBv8cQ7mHqqxWlRgc4yCYx82mML2WYFWaY2Ym9esjNeRCg/8FzB0ovk2vByOEcPj 0Oi7pGbn/8AIW5jcIcjOIyQI/WHSFJRloqmaKcsrf/nLAlWYaX487g33LNEZawVCL1tOqD5/aGK 8PHzqMr4bxt/E1NLMkXdIFOoWrR6ybfZwuYJR/NkJdOW0E25vZI0kHwGklUnmKMUM5Oj139jeHQ ai/Bu31QgkG9Ppcjl5rvmIGQl1sCNNbuFfjzhdXHMyYA6+bw+9+MYpOPcVGo+MSY8lS5o= X-Received: by 2002:a05:600c:4714:b0:49f:fe88:e7d1 with SMTP id 5b1f17b1804b1-4a01affe8bdmr39096745e9.15.1790787009010; Wed, 30 Sep 2026 09:50:09 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, qemu-stable@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 04/13] block/preallocate: serialise the filter state Date: Wed, 30 Sep 2026 18:49:50 +0200 Message-ID: <20260930165000.303236-5-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::e; envelope-from=den@openvz.org; helo=mail-wr2-x0e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787086805158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev The filter keeps the file length it has seen, the length it has reserved and where the trailing zeroes start in plain fields, and updates them with a read, a compare and a store. That was indivisible while one node was driven by one AioContext. It is not any more: virtio-blk with iothread-vq-mapping drives one node from several. Two writers extending the file then both pass the compare, and the smaller end lands last: writer A, [1G, 1G+64k) writer B, [1G+64k, 1G+128k) -------------------------------- -------------------------------- reads data_end 1G, 1G+64k > 1G reads data_end 1G, 1G+128k > 1G stores data_end =3D 1G+128k stores data_end =3D 1G+64k Both writes are acknowledged, and data_end now sits below B's data. Nothing raises it again except a later write ending beyond it, and closing the image truncates the file to it, so B's data is cut off the end. The last pair of extending writes before a shutdown is exactly where this bites. Take a mutex across handle_write() and preallocate_co_getlength(). The remaining readers, apart from preallocate_co_truncate(), reach the state from global state code with the node drained, where no request is in flight. Holding it cannot deadlock. A writer waiting for it has not reached bs->file yet, so it owns nothing below the filter, and the only calls made under it go to the child. preallocate_co_truncate() is left out for that reason: growing the file waits for the requests in flight on the child, and once the next patch issues the preallocation without the mutex, one of those can be a preallocation that needs it back. Signed-off-by: Denis V. Lunev Cc: qemu-stable@nongnu.org CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev --- block/preallocate.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/block/preallocate.c b/block/preallocate.c index 8cd98684f4..442cdb0176 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -76,6 +76,8 @@ typedef struct BDRVPreallocateState { * BLK_PERM_WRITE permissions on file child. */ =20 + CoMutex lock; + /* Gives up the resize permission on children when parents don't need = it */ QEMUBH *drop_resize_bh; } BDRVPreallocateState; @@ -155,6 +157,7 @@ static int preallocate_open(BlockDriverState *bs, QDict= *options, int flags, * For this to work, mark them invalid. */ preallocate_set_state(s, -EINVAL); + qemu_co_mutex_init(&s->lock); s->drop_resize_bh =3D qemu_bh_new(preallocate_drop_resize_bh, bs); =20 ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); @@ -324,8 +327,8 @@ static bool GRAPH_RDLOCK has_prealloc_perms(BlockDriver= State *bs) * one bdrv_co_pwrite_zeroes() call. */ static bool coroutine_fn GRAPH_RDLOCK -handle_write(BlockDriverState *bs, int64_t offset, int64_t bytes, - bool want_merge_zero) +handle_write_locked(BlockDriverState *bs, int64_t offset, int64_t bytes, + bool want_merge_zero) { BDRVPreallocateState *s =3D bs->opaque; int64_t end =3D offset + bytes; @@ -404,6 +407,20 @@ handle_write(BlockDriverState *bs, int64_t offset, int= 64_t bytes, return want_merge_zero; } =20 +static bool coroutine_fn GRAPH_RDLOCK +handle_write(BlockDriverState *bs, int64_t offset, int64_t bytes, + bool want_merge_zero) +{ + BDRVPreallocateState *s =3D bs->opaque; + bool ret; + + qemu_co_mutex_lock(&s->lock); + ret =3D handle_write_locked(bs, offset, bytes, want_merge_zero); + qemu_co_mutex_unlock(&s->lock); + + return ret; +} + static int coroutine_fn GRAPH_RDLOCK preallocate_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags) @@ -506,8 +523,11 @@ preallocate_co_getlength(BlockDriverState *bs) int64_t ret; BDRVPreallocateState *s =3D bs->opaque; =20 + qemu_co_mutex_lock(&s->lock); if (s->data_end >=3D 0) { - return s->data_end; + ret =3D s->data_end; + qemu_co_mutex_unlock(&s->lock); + return ret; } =20 ret =3D bdrv_co_getlength(bs->file->bs); @@ -515,6 +535,7 @@ preallocate_co_getlength(BlockDriverState *bs) if (has_prealloc_perms(bs)) { preallocate_set_state(s, ret); } + qemu_co_mutex_unlock(&s->lock); =20 return ret; } --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787046; cv=none; d=zohomail.com; s=zohoarc; b=Cnb1ZZSLcL33pBKRbwIQPnJ91W7bB2ccslwkKKukEB9nhf9numZ+B4fWiZot8WH1gsyqwPBmJkIqWRUCohCqG1UpbKNboWUTRHbcpEKEZVLE7pKoBTkREiU+DpMJ3n5PePOIoHxD8J1PKUWl+yxi8GLgX7A5g05sP0DtsNaiYZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787046; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AjHnUyfHfzBiYJqLm+EofS6tYDgNmwYtxj0MnNrLJWY=; b=MFT0XQMVhuPKqZP32dNBzGEg10ikPmXp/BM7RCkptJFhoEZwS6LtvuJGELN4xohnVHyCB1prdgxdshLvCPGp5Hhnlh1M6UeLu0ZOigwmTaaUWiKKwejR9LGe90ZEqHcB79Sw6wenb1GddMsW7U2n/sExNf+I8NKaY+X0cKJhyP0= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787046700698.034305402907; Wed, 30 Sep 2026 09:50:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxVw-0006ww-Sd; Wed, 30 Sep 2026 12:50:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVb-0006We-I5 for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:20 -0400 Received: from mail-wr2-x0e.google.com ([2a00:1450:4864:30::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVW-0003Wy-9N for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:19 -0400 Received: by mail-wr2-x0e.google.com with SMTP id ffacd0b85a97d-48af9f88c95so612503f8f.0 for ; Wed, 30 Sep 2026 09:50:11 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787011; x=1791391811; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AjHnUyfHfzBiYJqLm+EofS6tYDgNmwYtxj0MnNrLJWY=; b=ITS71i+3uTuC9k8U1P7kwL1KKmUiRCkdlcLEOembaostH74BWknUANhfOIcOwpb+QP +UzqMEYhQap3KPXwpHGp+MCcjNL8FThPTbJNviCZHjT9o3hMybWfoEXAqfJUSnyMBbu5 dkJdGfhMqkFtQk/puS/Mx6lD2bneIBbZq5SReRG4iAn9D0YD8P0PyV5adY8WQtm+F5D+ 4mZ/GEGFwCUrm2D5ZzcOogpdu5ZYPTmfZNSAI+S3oV+SHIir4oy6bQz10QTObCYWGkgK q4JTBg8TuJorpssNCN0LK+irlBt/3NCHqR6VOe3z1v6EEBaLY8seAE2MmQu3sfcY/LjS sOiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787011; x=1791391811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=AjHnUyfHfzBiYJqLm+EofS6tYDgNmwYtxj0MnNrLJWY=; b=eW8O0tcZUyOHoZUgjyjtqZOFcLIU2wlS+DPkMo6j5XdLrlvVDOjb6+65lRnNayRVJe NVFA2BGqKOzImJ5b/trRXAZ7+t+WSQZTPuQcKp3BbYYmrNGA8tReRbATrRdVTAqii/C5 S3bWhe71fttYMg524lqMM8ebUq+CoLYatBSaLwukJYZui1F5ru4svCqnrjER2dXm1T2k acrdiGMgtEr/y6S3rVg3VlbMV21n+jYtYlbh103YNr5DbUHRRh1pwNiQ5w3N43QK/zRT khqOk7JszYpfU/+inu72bHmnMMmvuKm72flkcI5cFMirmSEPQmJuC64mRVW+gwaQK5jT f2mw== X-Gm-Message-State: AFuF++nZ8eBKVLB5UnHyPBNWkvlC6mBm9QetZTEuC3i/WqPwhT0iCZ9T dznyMoTiWI8COxy5DZOJIhUn/cuzodTekCnwtCTHi26l3FraMtpFX7R+wRk0Vl9iJlL9wA7vyDH Cm/rf X-Gm-Gg: AYBFou3Mh/A77Mk9aEtl7XdPaHHozvACrAwsO6DeY4GjmNredqqjVOSNAl2o30KfuZt jD1AwjEDc4U2CW+Ue7qQdqOQgedJQ9vOjP3ZTd8POUVvHdqyp5z4lQ9NepUwfUgT1vC+dVSOfYG wnUXfiFFCqkisBtLmav8e/B90s8i9Ows4neKaM/WPqlk2auoieohOlO6rVwhc5nhSqtmiX2PP6g d+wHdIsCWzlB4dADUg0byDXPNqBvLOjXBwG4DMUu5RhPd8M2cV96Dp4fHF53L65UMUrZy/GMSzo V8sXQfOzVBd+CjoENArkHjqQwwExlafQbVA0jH0w+dju07OhyHhj86SUR6SkDwfcmIo9NA89Ake p9gnrfweiwuhMLNYKWJzqgUbm6Mmn0Pe8YYaX+rZRtpJ7x2C8ikE/V6bh9bxPyZOM/IA2m1y4S4 PP21Q00v/5b9hr/QSf/SjLn/v4eyNxwmihDQ6CQY4PhPPh9YfNPOCrRQFELdPA6pZIKT3g X-Received: by 2002:a05:600c:a318:b0:49f:ffa2:1c72 with SMTP id 5b1f17b1804b1-4a01eb0b951mr3802335e9.11.1790787010874; Wed, 30 Sep 2026 09:50:10 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, qemu-stable@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 05/13] block/preallocate: hold back writes into a preallocation in flight Date: Wed, 30 Sep 2026 18:49:51 +0200 Message-ID: <20260930165000.303236-6-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::e; envelope-from=den@openvz.org; helo=mail-wr2-x0e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787048658158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev The previous patch holds the mutex across all of handle_write(), including the preallocating write zeroes. That is correct and far too coarse: the fallocate takes as long as it takes, and every writer that extends the file waits for it. Reserve the range instead of holding the lock over it. file_end moves to the end of the preallocated range before the request is issued, so a writer arriving while it is in flight works from a length that already covers the range being zeroed. That leaves it going straight into the range, and BDRV_REQ_SERIALISING cannot stop it. Serialisation orders a request against the ones in bs->tracked_requests, and the zeroing request is not there yet: the filter runs above bdrv_co_pwritev_part(), which is what tracks it. Whatever the filter lets through in that window is unordered by construction, so the filter has to hold it back itself. safe_end trails file_end, standing at the lowest start of a preallocation in flight and reaching file_end once none is left. A write above it waits on a queue and re-reads the state when the preallocations drain. A write zeroes merged into a preallocation starts it below file_end, so safe_end has to move down as well as up. Below safe_end nothing can be zeroed any more, so those writes do not queue, and below zero_start there is nothing to record either, so those take no mutex at all. The stores are qatomic_set() because that path reads them without it. Signed-off-by: Denis V. Lunev Cc: qemu-stable@nongnu.org CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev --- block/preallocate.c | 95 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/block/preallocate.c b/block/preallocate.c index 442cdb0176..128f1da014 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -32,6 +32,7 @@ #include "qemu/units.h" #include "block/block-io.h" #include "block/block_int.h" +#include "qemu/atomic.h" =20 =20 typedef struct PreallocateOpts { @@ -76,6 +77,21 @@ typedef struct BDRVPreallocateState { * BLK_PERM_WRITE permissions on file child. */ =20 + /* + * @file_end is reserved as soon as a preallocation is decided on, so + * that the next one starts above it. @safe_end is the lowest start of + * a preallocation in flight, or @file_end when there is none: nothing + * below it can still be zeroed, so a write ending below it does not + * queue. + */ + int64_t safe_end; + int prealloc_in_flight; + CoQueue prealloc_waiters; + + /* + * Nothing done while this is held may wait for a request that has alr= eady + * passed the filter: that request can need it back. + */ CoMutex lock; =20 /* Gives up the resize permission on children when parents don't need = it */ @@ -106,9 +122,17 @@ static QemuOptsList runtime_opts =3D { }, }; =20 +static void preallocate_set_file_end(BDRVPreallocateState *s, int64_t v) +{ + s->file_end =3D v; + qatomic_set(&s->safe_end, v); +} + static void preallocate_set_state(BDRVPreallocateState *s, int64_t v) { - s->file_end =3D s->zero_start =3D s->data_end =3D v; + preallocate_set_file_end(s, v); + qatomic_set(&s->data_end, v); + qatomic_set(&s->zero_start, v); } =20 static bool preallocate_absorb_opts(PreallocateOpts *dest, QDict *options, @@ -158,6 +182,7 @@ static int preallocate_open(BlockDriverState *bs, QDict= *options, int flags, */ preallocate_set_state(s, -EINVAL); qemu_co_mutex_init(&s->lock); + qemu_co_queue_init(&s->prealloc_waiters); s->drop_resize_bh =3D qemu_bh_new(preallocate_drop_resize_bh, bs); =20 ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); @@ -188,7 +213,7 @@ preallocate_truncate_to_real_size(BlockDriverState *bs,= Error **errp) int ret; =20 if (s->file_end < 0) { - s->file_end =3D bdrv_getlength(bs->file->bs); + preallocate_set_file_end(s, bdrv_getlength(bs->file->bs)); if (s->file_end < 0) { error_setg_errno(errp, -s->file_end, "Failed to get file lengt= h"); return s->file_end; @@ -200,10 +225,10 @@ preallocate_truncate_to_real_size(BlockDriverState *b= s, Error **errp) NULL); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to drop preallocation"); - s->file_end =3D ret; + preallocate_set_file_end(s, ret); return ret; } - s->file_end =3D s->data_end; + preallocate_set_file_end(s, s->data_end); } =20 return 0; @@ -345,18 +370,21 @@ handle_write_locked(BlockDriverState *bs, int64_t off= set, int64_t bytes, } =20 if (s->data_end < 0) { - s->data_end =3D bdrv_co_getlength(bs->file->bs); - if (s->data_end < 0) { + int64_t len =3D bdrv_co_getlength(bs->file->bs); + + if (len < 0) { + s->data_end =3D len; return false; } + qatomic_set(&s->data_end, len); =20 if (s->file_end < 0) { - s->file_end =3D s->data_end; + preallocate_set_file_end(s, len); } } =20 if (!want_merge_zero && s->zero_start >=3D 0 && end > s->zero_start) { - s->zero_start =3D end; + qatomic_set(&s->zero_start, end); } =20 if (end <=3D s->data_end) { @@ -365,13 +393,13 @@ handle_write_locked(BlockDriverState *bs, int64_t off= set, int64_t bytes, =20 /* We have valid s->data_end, and request writes beyond it. */ =20 - s->data_end =3D end; + qatomic_set(&s->data_end, end); if (s->zero_start < 0 || !want_merge_zero) { - s->zero_start =3D end; + qatomic_set(&s->zero_start, end); } =20 if (s->file_end < 0) { - s->file_end =3D bdrv_co_getlength(bs->file->bs); + preallocate_set_file_end(s, bdrv_co_getlength(bs->file->bs)); if (s->file_end < 0) { return false; } @@ -395,16 +423,27 @@ handle_write_locked(BlockDriverState *bs, int64_t off= set, int64_t bytes, =20 want_merge_zero =3D want_merge_zero && (prealloc_start <=3D offset); =20 + /* Reserve the range; safe_end keeps writers out of it until it is zer= o. */ + s->file_end =3D prealloc_end; + if (s->prealloc_in_flight++ =3D=3D 0 || prealloc_start < s->safe_end) { + qatomic_set(&s->safe_end, prealloc_start); + } + qemu_co_mutex_unlock(&s->lock); + ret =3D bdrv_co_pwrite_zeroes( bs->file, prealloc_start, prealloc_end - prealloc_start, BDRV_REQ_NO_FALLBACK | BDRV_REQ_SERIALISING | BDRV_REQ_NO_WAIT= ); + + qemu_co_mutex_lock(&s->lock); if (ret < 0) { s->file_end =3D ret; - return false; } + if (--s->prealloc_in_flight =3D=3D 0) { + qatomic_set(&s->safe_end, s->file_end); + } + qemu_co_queue_restart_all(&s->prealloc_waiters); =20 - s->file_end =3D prealloc_end; - return want_merge_zero; + return ret < 0 ? false : want_merge_zero; } =20 static bool coroutine_fn GRAPH_RDLOCK @@ -412,9 +451,22 @@ handle_write(BlockDriverState *bs, int64_t offset, int= 64_t bytes, bool want_merge_zero) { BDRVPreallocateState *s =3D bs->opaque; + int64_t zero_start =3D qatomic_read(&s->zero_start); + int64_t end =3D offset + bytes; bool ret; =20 + /* + * Below zero_start there is nothing to record: data_end covers it, and + * only a write zeroes that already covers it can preallocate over it. + */ + if (zero_start >=3D 0 && end <=3D zero_start) { + return false; + } + qemu_co_mutex_lock(&s->lock); + while (s->prealloc_in_flight && (s->safe_end < 0 || end > s->safe_end)= ) { + qemu_co_queue_wait(&s->prealloc_waiters, &s->lock); + } ret =3D handle_write_locked(bs, offset, bytes, want_merge_zero); qemu_co_mutex_unlock(&s->lock); =20 @@ -456,7 +508,7 @@ preallocate_co_truncate(BlockDriverState *bs, int64_t o= ffset, =20 if (s->data_end >=3D 0 && offset > s->data_end) { if (s->file_end < 0) { - s->file_end =3D bdrv_co_getlength(bs->file->bs); + preallocate_set_file_end(s, bdrv_co_getlength(bs->file->bs)); if (s->file_end < 0) { error_setg(errp, "failed to get file length"); return s->file_end; @@ -471,7 +523,7 @@ preallocate_co_truncate(BlockDriverState *bs, int64_t o= ffset, * Otherwise just proceed to preallocate missing part. */ if (offset <=3D s->file_end) { - s->data_end =3D offset; + qatomic_set(&s->data_end, offset); return 0; } } else { @@ -488,16 +540,16 @@ preallocate_co_truncate(BlockDriverState *bs, int64_t= offset, ret =3D bdrv_co_truncate(bs->file, s->data_end, true, PREALLOC_MODE_OFF, 0, errp); if (ret < 0) { - s->file_end =3D ret; + preallocate_set_file_end(s, ret); error_prepend(errp, "preallocate-filter: failed to dro= p " "write-zero preallocation: "); return ret; } - s->file_end =3D s->data_end; + preallocate_set_file_end(s, s->data_end); } } =20 - s->data_end =3D offset; + qatomic_set(&s->data_end, offset); } =20 ret =3D bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, err= p); @@ -522,6 +574,11 @@ preallocate_co_getlength(BlockDriverState *bs) { int64_t ret; BDRVPreallocateState *s =3D bs->opaque; + int64_t data_end =3D qatomic_read(&s->data_end); + + if (data_end >=3D 0) { + return data_end; + } =20 qemu_co_mutex_lock(&s->lock); if (s->data_end >=3D 0) { --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787041; cv=none; d=zohomail.com; s=zohoarc; b=mLxxLPeMjJzKVxVi6jkRFUJmeM4Pj5YCf+5nBQ+0ldUfYdoW1GJ9HOifSXvxCd2JVJHrf29mrWXArf1oGY2ZxM4V+93n0qeDSsugPn3Xxh6JRegD/twZxsa8+pHvIHXNXOlKEZ8tEvBlWo9uoJds+gQc9Qcp6TUqond/1EUjuz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787041; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tX/eoVXGT9GlXWnw9X/ctJ6/ZvMghMZLPGwlqfRGtlg=; b=TxyBmp+zPNkExmfPIdoKOBgoeu4dFy5w3uOf+ZqAJyiLjJEuQjp3UUXJiHFjb4eFDPPJxsiru/2lWMUrIuKbKOhRQdmWHw7YuJcVs+XRQsutKvswelhx2Xj9ONZ6aBrVUeBy7mYCGOOtaaauBxfJaDIXHOVAYWGcsCeAgC0Ezm0= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787041598243.67597904381216; Wed, 30 Sep 2026 09:50:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxVv-0006qV-3y; Wed, 30 Sep 2026 12:50:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVZ-0006SB-Ow for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:20 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVW-0003X7-8u for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:17 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-4a00713639cso26676975e9.1 for ; Wed, 30 Sep 2026 09:50:12 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787012; x=1791391812; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tX/eoVXGT9GlXWnw9X/ctJ6/ZvMghMZLPGwlqfRGtlg=; b=SZF4GLgNLHwI4ENfhTjycAgpjx814FynSa885ucm6f4pV0TWdhQzq8qc+PsFNYqPHw 5yOn/YoqUCq7p3pLQy31XVSgV/q36MNeezQJvlaUxvLPs7Zu6rJTSPpe5cTbBOlG5WKr TkkOs2iOqCmb6g3oL1VRtEThWe+3Q08g1uTe3nLhbXfwr5rHsHCTS3CPw7rmnmTM0KrZ 3GNiqzuTp6i8HeK9GmfQVSlBICR67pBwHm/G3WBuoVPYpY0HGpbKqu4bjJ/H95laEp+u znrQciEDbo7nQVw6Wqd/Tq173vzmdNNAK96B1kah1WLS3Mm6+xTbHxLURX0KAwh3x3FT WJ5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787012; x=1791391812; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=tX/eoVXGT9GlXWnw9X/ctJ6/ZvMghMZLPGwlqfRGtlg=; b=gKkuwqIOwGsAI4CZnr8Nfeb12vEn8o+07ZTqBGyM3dq5GlXQcvq7+fpM6VvW4ktI5q 9l27Dx2r7WUAlfj9KOhOcTkk/Zk/e4tQ7PMzLKz7aGqw5ZnqT3+AAUwkf74qNYB5wh/E rC2FECGB+aAxzxzi4NB8pFORvtUWOKyWULdUfdONmbSlclYfzy0gq87mylPtsv0sc6fb cyqjQ8doPFKV4cBqArcUkDRB8M+4M9Wjun+LiV3d+FOZ1j+vwZo8Rl02PYcn10iFlOgb lXMvBVd3KXy3sFIWRO4BeJkBrQc10kmV4gkRD/zpEVc2W3I56ytKdqBZ92lvNy0P4lxk CT7Q== X-Gm-Message-State: AFuF++mNV1OGZd6MXjqtsztLKvoeu2aRp1e+6dGPsIaKFTMsNSIU5YRE vTuDoIhg6T4CwStSIvAMTfKpExhcwyqpdAGxYNMH/IAQ2OTXyP3c0i0Ucj7biZ9GHQ6Hx1gXgDz EYmo6 X-Gm-Gg: AYBFou1pGRfZNaK9R+zlD+kMl85jVn3cmO0UUGkClFF1ipQN6qRAQIJvGFCJAenxyzU gNTkH2WiNyEfQObgSAD5US51oRkFNekTIw8gjch4zFnjArJPtUfuBrjFr9qWzHyHhVSDY81PTUh FnNNQUF/bRwkziVxj660IPOLOJVdApu10fjG4AFOpLv3bfEHfTD5ft0WmKXqBfQfVELK0mleMCr VOzOgOE5+frrs3Ou84zDA2l+cCzEj2EI/bE16UMTIkxDJhTCwxquxUjhQNmFWjxjkOk7qC4SKyC ocZumAsToo8AAMFFzytJPUAbe5KBPKzm1Q1kgccxDUjxfE+HvvnCqrahLEFCmfKuJCWtQIL+rox O17TMnsFU2MeEuIciTEXz8RTGt3x8nacq0PjiAFkJ8Jkc+brx7b+UYpH+wLcNARS5J46M9vvlrE RLRTW1naWTh3Rx31U5ockcLa49QL2AiyBkF/P3o7JQpwh0Of2o0tOLG0nLOIu++bYNAVg= X-Received: by 2002:a05:600c:8411:b0:49b:9202:6f80 with SMTP id 5b1f17b1804b1-4a01affe5camr36956455e9.6.1790787011935; Wed, 30 Sep 2026 09:50:11 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, Andrey Drobyshev , Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy Subject: [PATCH 06/13] iotests/298: add testcase for async writes with preallocation filter Date: Wed, 30 Sep 2026 18:49:52 +0200 Message-ID: <20260930165000.303236-7-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787043180158500 Content-Type: text/plain; charset="utf-8" From: Andrey Drobyshev The testcase creates a 64G image with 1M clusters, generates a list of 1M aligned offsets and feeds aio_write commands with those offsets to qemu-io run with '--aio native --nocache'. Then we check the data written at each of the offsets. Before this series this could result in a race within the preallocation filter which would zeroize some clusters after actually writing data to them. Note: the test does not fail every time as there's a race involved, but the failures are pretty consistent so it should be good enough for detecting the problem. Signed-off-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/298 | 49 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/298.out | 4 ++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/298 b/tests/qemu-iotests/298 index f2b94077f4..23e7789d09 100755 --- a/tests/qemu-iotests/298 +++ b/tests/qemu-iotests/298 @@ -20,8 +20,10 @@ =20 import os import iotests +import random =20 MiB =3D 1024 * 1024 +GiB =3D MiB * 1024 disk =3D os.path.join(iotests.test_dir, 'disk') overlay =3D os.path.join(iotests.test_dir, 'overlay') refdisk =3D os.path.join(iotests.test_dir, 'refdisk') @@ -176,6 +178,53 @@ class TestTruncate(iotests.QMPTestCase): self.do_test('off', '150M') =20 =20 +class TestPreallocAsyncWrites(iotests.QMPTestCase): + def setUp(self): + # Make sure we get reproducible write patterns on each run + random.seed(42) + iotests.qemu_img_create('-f', iotests.imgfmt, disk, '-o', + f'cluster_size=3D{MiB},lazy_refcounts=3Don= ', + str(64 * GiB)) + + def tearDown(self): + os.remove(disk) + + def test_prealloc_async_writes(self): + def gen_write_pattern(): + n =3D 0 + while True: + yield '-P 0xaa' if n else '-z' + n =3D 1 - n + + def gen_read_pattern(): + n =3D 0 + while True: + yield '-P 0xaa' if n else '-P 0x00' + n =3D 1 - n + + requests =3D 2048 # Number of write/read requests to feed to qemu-= io + total_clusters =3D 64 * 1024 # 64G / 1M + + wpgen =3D gen_write_pattern() + rpgen =3D gen_read_pattern() + + offsets =3D random.sample(range(0, total_clusters), requests) + aio_write_cmds =3D [f'aio_write {next(wpgen)} {off}M 1M' for off i= n offsets] + read_cmds =3D [f'read {next(rpgen)} {off}M 1M' for off in offsets] + + proc =3D iotests.QemuIoInteractive('--aio', 'native', '--nocache', + '--image-opts', drive_opts) + for cmd in aio_write_cmds: + proc.cmd(cmd) + proc.close() + + proc =3D iotests.QemuIoInteractive('-f', iotests.imgfmt, disk) + for cmd in read_cmds: + out =3D proc.cmd(cmd) + self.assertFalse('Pattern verification failed' in str(out)) + proc.close() + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2'], required_fmts=3D['preallocate= '], require_hmp=3DTrue) diff --git a/tests/qemu-iotests/298.out b/tests/qemu-iotests/298.out index fa16b5ccef..6323079e08 100644 --- a/tests/qemu-iotests/298.out +++ b/tests/qemu-iotests/298.out @@ -1,5 +1,5 @@ -............. +.............. ---------------------------------------------------------------------- -Ran 13 tests +Ran 14 tests =20 OK --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787082; cv=none; d=zohomail.com; s=zohoarc; b=kXWreu1MtbP0iUUrQRcQCAvhYEXlaTZSu3ck0tEGyHQg+famBMIYQTBC6yGTXFGr83cwCv+/Rfdx3karniq21rMox6FFf5/h7eNofgY5c3NxKaWT3enSSS6MnyXiLLqsJmQdwYYwIAaOVQHJ/M5hHNM1BolpcVf4Se+N973jST8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787082; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MDB6UCDP9ACMXLxVZ73TiOCWYZoH42ANfONkVN56IH0=; b=kRdTpEJ0itesdT/P6GOwLqq4M37kjtio0HYYOiMud6wOud3wwmQxwKtbRnx90tkZ0uucruzsO1I/fiGuBfbs7zEuJ+m8OSF+8Nnu1uG7Fego88h6b9W+0A4eOXKD5q8do3nFlBbuneRqP0LyNT0uPfhFnu2uajvZIhh3Fc3tJz8= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179078708291795.29954592256206; Wed, 30 Sep 2026 09:51:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxW7-0007pn-J4; Wed, 30 Sep 2026 12:50:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVc-0006Xh-HR for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:22 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVW-0003XI-Iu for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:19 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49b912d822dso41602195e9.2 for ; Wed, 30 Sep 2026 09:50:14 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787013; x=1791391813; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MDB6UCDP9ACMXLxVZ73TiOCWYZoH42ANfONkVN56IH0=; b=ccQfoTKAqlP3KPkhj75CCYF+kbLu79p6ro2ECmEKs1551skSN+aHRjec8WlOjJvJvn qHoLOYSNvbFc3W1/TW4TglwBttqtwYUoTPjnSEBxcd1oM3bKsdqXKtBoM0ZiUqS6Y1an 6xsDVsBTy8W1p1aLRc5dqpMZBuN9wFH1QfTTfye+rZeC6hwnJe+lZIM7HzgXu4lpuaTj 2sUnMHH8kt2ssk9uoxD+HiWUdBnPZ7uwEExoDV7Qqan6yYnanYigNBppb9EYTSPvaDHQ g3yo9LvQ78i9xkU8nFniRxuTj7egPlS6ps9reY3RfB6pFXwY6AYozFvYdRvUM+i6jMFL 57DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787013; x=1791391813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=MDB6UCDP9ACMXLxVZ73TiOCWYZoH42ANfONkVN56IH0=; b=0HrlNfyD2A+8xnxOQoSS1hLb33ZykAKLC9bN5yo2uFAx+3VhUwmLMYcU6ZRAJcn6Le NIupq2K1DUGOXTdZ09/UhWVmZ14NJftvk5FHYDPcGQBsAnE+lLQY0oesZGOy3elyswoZ P42VIDPJBQjaYXQthZ0GzzPdb9HkeZUdxTEgJYXz359gs2sYwuSvuqv1PSf2hsq98RUZ fD+uZXAm1mxsOFO89l9F+Kkf16rSOVVIb1WrOk+BKdkTk8LBBvDyU5uQjfdN3ZIDlAlj NKVttClxQ4U6mOjTKB319m7Pj6qk4frQLWyyZVydIgffcnTOKgafWigCyfDJ9vaaVXL/ wMEQ== X-Gm-Message-State: AFuF++ki0eLguhqRhKtiQ8taH68UCcazm9WhFFTuBe0afGyXifMsIbIL 4WX4GAaZ2r2ZKfDdHprpqK8HgdA3WpSkC+Bd/YQkP3oA685e0vhARmrBsllvWXFDWibO0KyiI/S tUi99 X-Gm-Gg: AYBFou3Kumvm0B/C7X5scpX7BVHnRJ8Sdm1mA3Ju24NJhCkSCVADNL58Xw41FTFkVcq Kymf1EJkxHvlWgbW9tJ0L1q8+ta1kk9rEgxmLp45ZaCmnwMnRQg+wK266F4qhOJyVhAm21+66rO eEvg717xjaZPdiuEuOpGU9JbMggCG3WY3wIdWfBCvMjF9KZRQVgqDTardHZHGXySq8321RNL9c2 AszRPcoCsk+mBoQB26CGLg9P8+x/Uq3dsYeSOQuLJoLGSp3XvWgYZh7MHAZuyVppdZz+Q//puMD Fv61qJyAeHrHY1FHLKZYjVdZ5/4g51/f5Ps6wA06rAgQux7ABus1cLITMv2ckQ2ygWQf3a1cfAG 7cz3jAkUAPGUBKAui6rTAyC3vpOt3OZj1I1sYFQI9yCcoH2bLv5mXbtPeJVfaFGazZu4C9BTKN3 2zKrOyD7mwlTiWAH9TCIPEyBVcPimm4m5WWh2O49DBrbrVKsbRw0tp4EY2DOVMzKGxomq0X11bk XFCug== X-Received: by 2002:a05:600c:8b88:b0:4a0:62d:4424 with SMTP id 5b1f17b1804b1-4a01addebd5mr31620675e9.8.1790787013015; Wed, 30 Sep 2026 09:50:13 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 07/13] tests/unit: prefix the iothread test helper Date: Wed, 30 Sep 2026 18:49:53 +0200 Message-ID: <20260930165000.303236-8-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787084716158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev tests/unit/iothread.c defines a struct IOThread and an iothread_get_aio_context() under the same names as the IOThread QOM object in iothread.c, so nothing that links the real object can use the helper. Prefix the helper and its type with test_ and Test. This is preparation for building the QOM object into the block layer. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev Reviewed-by: Eric Blake --- tests/unit/iothread.c | 28 +++++++++++++-------------- tests/unit/iothread.h | 8 ++++---- tests/unit/test-aio-multithread.c | 8 ++++---- tests/unit/test-bdrv-drain.c | 32 +++++++++++++++---------------- tests/unit/test-block-iothread.c | 28 +++++++++++++-------------- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/tests/unit/iothread.c b/tests/unit/iothread.c index a363bf8f70..ff05ae8b11 100644 --- a/tests/unit/iothread.c +++ b/tests/unit/iothread.c @@ -19,7 +19,7 @@ #include "qemu/rcu.h" #include "iothread.h" =20 -struct IOThread { +struct TestIOThread { AioContext *ctx; GMainContext *worker_context; GMainLoop *main_loop; @@ -30,20 +30,20 @@ struct IOThread { bool stopping; }; =20 -static void iothread_init_gcontext(IOThread *iothread) +static void test_iothread_init_gcontext(TestIOThread *iothread) { GSource *source; =20 iothread->worker_context =3D g_main_context_new(); - source =3D aio_get_g_source(iothread_get_aio_context(iothread)); + source =3D aio_get_g_source(test_iothread_get_aio_context(iothread)); g_source_attach(source, iothread->worker_context); g_source_unref(source); iothread->main_loop =3D g_main_loop_new(iothread->worker_context, TRUE= ); } =20 -static void *iothread_run(void *opaque) +static void *test_iothread_run(void *opaque) { - IOThread *iothread =3D opaque; + TestIOThread *iothread =3D opaque; =20 rcu_register_thread(); =20 @@ -56,7 +56,7 @@ static void *iothread_run(void *opaque) * of glib the g_source_ref()/unref() functions are not threadsafe * on sources without a context. */ - iothread_init_gcontext(iothread); + test_iothread_init_gcontext(iothread); =20 /* * g_main_context_push_thread_default() must be called before anything @@ -76,16 +76,16 @@ static void *iothread_run(void *opaque) return NULL; } =20 -static void iothread_stop_bh(void *opaque) +static void test_iothread_stop_bh(void *opaque) { - IOThread *iothread =3D opaque; + TestIOThread *iothread =3D opaque; =20 iothread->stopping =3D true; } =20 -void iothread_join(IOThread *iothread) +void test_iothread_join(TestIOThread *iothread) { - aio_bh_schedule_oneshot(iothread->ctx, iothread_stop_bh, iothread); + aio_bh_schedule_oneshot(iothread->ctx, test_iothread_stop_bh, iothread= ); qemu_thread_join(&iothread->thread); g_main_context_unref(iothread->worker_context); g_main_loop_unref(iothread->main_loop); @@ -95,13 +95,13 @@ void iothread_join(IOThread *iothread) g_free(iothread); } =20 -IOThread *iothread_new(void) +TestIOThread *test_iothread_new(void) { - IOThread *iothread =3D g_new0(IOThread, 1); + TestIOThread *iothread =3D g_new0(TestIOThread, 1); =20 qemu_mutex_init(&iothread->init_done_lock); qemu_cond_init(&iothread->init_done_cond); - qemu_thread_create(&iothread->thread, NULL, iothread_run, + qemu_thread_create(&iothread->thread, NULL, test_iothread_run, iothread, QEMU_THREAD_JOINABLE); =20 /* Wait for initialization to complete */ @@ -114,7 +114,7 @@ IOThread *iothread_new(void) return iothread; } =20 -AioContext *iothread_get_aio_context(IOThread *iothread) +AioContext *test_iothread_get_aio_context(TestIOThread *iothread) { return iothread->ctx; } diff --git a/tests/unit/iothread.h b/tests/unit/iothread.h index eb4d0c77f8..8475170eaa 100644 --- a/tests/unit/iothread.h +++ b/tests/unit/iothread.h @@ -16,10 +16,10 @@ #include "qemu/aio.h" #include "qemu/thread.h" =20 -typedef struct IOThread IOThread; +typedef struct TestIOThread TestIOThread; =20 -IOThread *iothread_new(void); -void iothread_join(IOThread *iothread); -AioContext *iothread_get_aio_context(IOThread *iothread); +TestIOThread *test_iothread_new(void); +void test_iothread_join(TestIOThread *iothread); +AioContext *test_iothread_get_aio_context(TestIOThread *iothread); =20 #endif diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multit= hread.c index 9179cdc6a3..d07376455b 100644 --- a/tests/unit/test-aio-multithread.c +++ b/tests/unit/test-aio-multithread.c @@ -21,7 +21,7 @@ =20 #define NUM_CONTEXTS 5 =20 -static IOThread *threads[NUM_CONTEXTS]; +static TestIOThread *threads[NUM_CONTEXTS]; static AioContext *ctx[NUM_CONTEXTS]; static __thread int id =3D -1; =20 @@ -68,8 +68,8 @@ static void create_aio_contexts(void) int i; =20 for (i =3D 0; i < NUM_CONTEXTS; i++) { - threads[i] =3D iothread_new(); - ctx[i] =3D iothread_get_aio_context(threads[i]); + threads[i] =3D test_iothread_new(); + ctx[i] =3D test_iothread_get_aio_context(threads[i]); } =20 qemu_event_init(&done_event, false); @@ -88,7 +88,7 @@ static void join_aio_contexts(void) aio_context_ref(ctx[i]); } for (i =3D 0; i < NUM_CONTEXTS; i++) { - iothread_join(threads[i]); + test_iothread_join(threads[i]); } for (i =3D 0; i < NUM_CONTEXTS; i++) { aio_context_unref(ctx[i]); diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 43b0ba8648..a852874f74 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -535,10 +535,10 @@ static void test_iothread_common(enum drain_type drai= n_type, int drain_thread) int aio_ret; struct test_iothread_data data; =20 - IOThread *a =3D iothread_new(); - IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + TestIOThread *a =3D test_iothread_new(); + TestIOThread *b =3D test_iothread_new(); + AioContext *ctx_a =3D test_iothread_get_aio_context(a); + AioContext *ctx_b =3D test_iothread_get_aio_context(b); =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 @@ -614,8 +614,8 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) blk_unref(blk); =20 out: - iothread_join(a); - iothread_join(b); + test_iothread_join(a); + test_iothread_join(b); } =20 static void test_iothread_drain_all(void) @@ -727,7 +727,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, BlockDriverState *src, *src_backing, *src_overlay, *target, *drain_bs; BlockJob *job; TestBlockJob *tjob; - IOThread *iothread =3D NULL; + TestIOThread *iothread =3D NULL; int ret =3D -1; =20 src =3D bdrv_new_open_driver(&bdrv_test, "source", BDRV_O_RDWR, @@ -761,8 +761,8 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, if (use_iothread) { AioContext *ctx; =20 - iothread =3D iothread_new(); - ctx =3D iothread_get_aio_context(iothread); + iothread =3D test_iothread_new(); + ctx =3D test_iothread_get_aio_context(iothread); blk_set_aio_context(blk_src, ctx, &error_abort); } =20 @@ -893,7 +893,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, bdrv_unref(target); =20 if (iothread) { - iothread_join(iothread); + test_iothread_join(iothread); } } =20 @@ -1396,10 +1396,10 @@ static void test_append_to_drained(void) static void test_set_aio_context(void) { BlockDriverState *bs; - IOThread *a =3D iothread_new(); - IOThread *b =3D iothread_new(); - AioContext *ctx_a =3D iothread_get_aio_context(a); - AioContext *ctx_b =3D iothread_get_aio_context(b); + TestIOThread *a =3D test_iothread_new(); + TestIOThread *b =3D test_iothread_new(); + AioContext *ctx_a =3D test_iothread_get_aio_context(a); + AioContext *ctx_b =3D test_iothread_get_aio_context(b); =20 bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, &error_abort); @@ -1410,8 +1410,8 @@ static void test_set_aio_context(void) bdrv_try_change_aio_context(bs, qemu_get_aio_context(), NULL, &error_a= bort); =20 bdrv_unref(bs); - iothread_join(a); - iothread_join(b); + test_iothread_join(a); + test_iothread_join(b); } =20 =20 diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 5273ff235a..5a150adfe8 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -465,8 +465,8 @@ const SyncOpTest sync_op_tests[] =3D { static void test_sync_op(const void *opaque) { const SyncOpTest *t =3D opaque; - IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + TestIOThread *iothread =3D test_iothread_new(); + AioContext *ctx =3D test_iothread_get_aio_context(iothread); BlockBackend *blk; BlockDriverState *bs; BdrvChild *c; @@ -548,8 +548,8 @@ BlockJobDriver test_job_driver =3D { =20 static void test_attach_blockjob(void) { - IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + TestIOThread *iothread =3D test_iothread_new(); + AioContext *ctx =3D test_iothread_get_aio_context(iothread); BlockBackend *blk; BlockDriverState *bs; TestBlockJob *tjob; @@ -611,8 +611,8 @@ static void test_attach_blockjob(void) */ static void test_propagate_basic(void) { - IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + TestIOThread *iothread =3D test_iothread_new(); + AioContext *ctx =3D test_iothread_get_aio_context(iothread); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_verify; @@ -675,8 +675,8 @@ static void test_propagate_basic(void) */ static void test_propagate_diamond(void) { - IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + TestIOThread *iothread =3D test_iothread_new(); + AioContext *ctx =3D test_iothread_get_aio_context(iothread); AioContext *main_ctx; BlockBackend *blk; BlockDriverState *bs_a, *bs_b, *bs_c, *bs_verify; @@ -740,8 +740,8 @@ static void test_propagate_diamond(void) =20 static void test_propagate_mirror(void) { - IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + TestIOThread *iothread =3D test_iothread_new(); + AioContext *ctx =3D test_iothread_get_aio_context(iothread); AioContext *main_ctx =3D qemu_get_aio_context(); BlockDriverState *src, *target, *filter; BlockBackend *blk; @@ -811,8 +811,8 @@ static void test_propagate_mirror(void) =20 static void test_attach_second_node(void) { - IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + TestIOThread *iothread =3D test_iothread_new(); + AioContext *ctx =3D test_iothread_get_aio_context(iothread); AioContext *main_ctx =3D qemu_get_aio_context(); BlockBackend *blk; BlockDriverState *bs, *filter; @@ -844,8 +844,8 @@ static void test_attach_second_node(void) =20 static void test_attach_preserve_blk_ctx(void) { - IOThread *iothread =3D iothread_new(); - AioContext *ctx =3D iothread_get_aio_context(iothread); + TestIOThread *iothread =3D test_iothread_new(); + AioContext *ctx =3D test_iothread_get_aio_context(iothread); BlockBackend *blk; BlockDriverState *bs; =20 --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787083; cv=none; d=zohomail.com; s=zohoarc; b=AOC2f+ra88oZWqtm7yIT+4dqEYHowf8kBuTAE/5fX5wbVuq7RI3KkUTGNTJ0h0wL8aM/+BVSbV6cQ65QEpFBQ0TPmo67XV7M+ub7basLohubAgVIwiikNmJIYOKU+aH+w0VRSMpFJ3gNtuuS0TDtDpcSbVNvTnSXRwcxkpJ2y6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787083; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7YZqbxUsWx8TcPnKOofK6gyVGdQ+2fV6RVy3rIunwZ0=; b=hdl9BIMhZoDiEQsls+EHHSMDOh195TQNA76BtzEpTLijczdPGokR5ruA9O9lZj3o8qAvaYt3aV/hC9OqffzoTBPSfKhveyaPtY5+AXQi3fsjeGO41BPkD5/O1tvdYegBQNet9YQVa4KaCkbjIzXc1Nbjqi+JchxjpUaom/h9XSs= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787083166653.0917133932101; Wed, 30 Sep 2026 09:51:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxVv-0006v5-Mm; Wed, 30 Sep 2026 12:50:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVd-0006ZX-4H for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:23 -0400 Received: from mail-wr2-x0f.google.com ([2a00:1450:4864:30::f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVZ-0003Xb-1s for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:20 -0400 Received: by mail-wr2-x0f.google.com with SMTP id ffacd0b85a97d-48b0591cf85so158743f8f.0 for ; Wed, 30 Sep 2026 09:50:15 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787014; x=1791391814; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7YZqbxUsWx8TcPnKOofK6gyVGdQ+2fV6RVy3rIunwZ0=; b=qrAG8Q50gCyv/cRPkXDQwxydkLKC5ccwfPMDDqgvmnCmNfDZv74d55SVjbUA2IV3Z9 2E6MjtJe26IjGjvNK0wn2aSJG1EDozIf/+kXiJv4CzUSbmz4fviZ1bBBF3H+/L6wxMV6 cjcqz8BOUzRLAo59ePv12tPwB/Nph8QS32tGMHK34KGc9e2m1yheeGx4RacKpTza7jjt LHf8RrAy+tF+tWgq8JO33Gh+ljTb9fY/jS8rtlu95jj6fcKyrp9BXtkytkPEpQvzg56/ 0KgnEuK780zT0wZvjf0b5vmdQQZybqoY9JfM71bs2CQOtjWsR8bFFOMfbm7i/IHRzurb 77nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787014; x=1791391814; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=7YZqbxUsWx8TcPnKOofK6gyVGdQ+2fV6RVy3rIunwZ0=; b=PH7NcejLVJoZfHHo3cCGTTx3klacxvyd7+Y05Gdt1gpLMYgDfzIf+D+YMTPXWFuyGu HVv3kAzEsaBeZRLbPztOky7DyXwK2+QqL/dkD6zoRlxMC3n17OP+26FjMGJB0Wd+7OVf Rqjb7UVX2mtp9zSco2IEsmBORLsx4D4nXnyd2uXStJW9/0CzUuv/cYZ5NOdSnYGuuYCd E6/EQ/Tbnc07BcjXmEOb0z2CmnOAqf2lsjvb9tiLCemFuDiF1Kbi0kZK+i2zq8ffhDCV 5zLo8Tqt9t/uO8kbkMD93EPxEkJgKxwfk7TK6vmGYhxRu3jCtvvVgiPQZh27OxGbDslz sFMA== X-Gm-Message-State: AFuF++mzOlxBqv9sHg44iDNPWut1AHf1uYbU8u4jAhc+zSeTuhjK4IG+ gePt2bh837ZxcIQv8PzRBTZDswxOz5aRRPfkFbskYJmOy4WDjr69Bn+7M6Gr+eqhZUBWwbuhaQ/ HdTXc X-Gm-Gg: AYBFou14Kbks9MC7hkObDhEUJhORzHmyN8oFFG8H3Kq7msDLgSKB00s0CcPLSt6pKZ3 5LjRRtQOMs369oOlC11KBjz4QxV6U9VAT2kQ3Va493FfPtdy2eHcuY3nLBb0p7D8yfcHGEx/YOd DQnMHsPmBeLcHaEKw+o1qbKSciAeBl2Dp1rf40NEb0ujfLvisJPNjf6JuFz9AM4yqHGPl7JfYcP mVYkWJOFMGaTeuwMpNUdnDQxr6ofLi2R5F8ZhZa9Lh84pa/eOEkFP2nsLZnYoGuf7s/A/DbJS6x cK7hZs5n7wiTC7b1PzDXx9iaC+A7cdec/Z7VIqgUVkUSdXx4cwv/0jffUKhyunkwEPZb5DwcFBe wIushnDQGLtJaiAOW/1nQ20xsB6tCeEAXYb0qGCqH6OQKVgWFNljVrDL/F/ICPG35X+ABDymClu d/6PqBz8A2Vvj0or0dwhVl1dhhyiWzE48bJ01o03W2VYbypROgzbR4Gc2DYBB+/dSXe+w= X-Received: by 2002:a05:600c:4e4b:b0:49f:fc13:18a5 with SMTP id 5b1f17b1804b1-4a01ea5719cmr6635085e9.6.1790787014116; Wed, 30 Sep 2026 09:50:14 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 08/13] qemu-io: accept --object iothread Date: Wed, 30 Sep 2026 18:49:54 +0200 Message-ID: <20260930165000.303236-9-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::f; envelope-from=den@openvz.org; helo=mail-wr2-x0f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787084566158502 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev qemu-io refused "--object iothread,id=3Dt0" with "invalid object type: iothread", because iothread.c was built into blockdev_ss, which qemu-io does not link. Move it to block_ss: it wraps an AioContext and has nothing to do with blockdev, and linking blockdev instead would drag in os-posix.c, whose qemu_system_killed() every program linking it has to define. Collect the --object arguments during option parsing and process them once qemu_init_main_loop() has run; nothing before that point uses an object. An iothread created earlier registers the timer lists of its AioContext with clocks that qemu_init_clocks() then resets, unlinking them silently: no failure, just timers that never fire. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev Reviewed-by: Eric Blake --- meson.build | 2 +- qemu-io.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index cfac634cf1..4c3f6518fd 100644 --- a/meson.build +++ b/meson.build @@ -3816,6 +3816,7 @@ if have_block block_ss.add(files( 'block.c', 'blockjob.c', + 'iothread.c', 'job.c', 'qemu-io-cmds.c', )) @@ -3830,7 +3831,6 @@ if have_block blockdev_ss.add(files( 'blockdev.c', 'blockdev-nbd.c', - 'iothread.c', 'job-qmp.c', )) =20 diff --git a/qemu-io.c b/qemu-io.c index 598d5b1c9c..2b684ccf55 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -532,6 +532,7 @@ int main(int argc, char **argv) QDict *opts =3D NULL; const char *format =3D NULL; bool force_share =3D false; + g_autoptr(GPtrArray) objects =3D g_ptr_array_new(); =20 #ifdef CONFIG_POSIX signal(SIGPIPE, SIG_IGN); @@ -607,7 +608,7 @@ int main(int argc, char **argv) force_share =3D true; break; case OPTION_OBJECT: - user_creatable_process_cmdline(optarg); + g_ptr_array_add(objects, optarg); break; case OPTION_IMAGE_OPTS: imageOpts =3D true; @@ -630,6 +631,11 @@ int main(int argc, char **argv) =20 qemu_init_main_loop(&error_fatal); =20 + /* An iothread object cannot be created before the main loop exists. */ + for (guint i =3D 0; i < objects->len; i++) { + user_creatable_process_cmdline(g_ptr_array_index(objects, i)); + } + if (!trace_init_backends()) { exit(1); } @@ -686,6 +692,7 @@ int main(int argc, char **argv) bdrv_drain_all(); =20 blk_unref(qemuio_blk); + user_creatable_cleanup(); g_free(readline_state); =20 if (ret < 0) { --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787084; cv=none; d=zohomail.com; s=zohoarc; b=mCfl3JhlRi7FXN//f3yzyyZ9FlHUsCOIPL1X3Xy0I4J8n9fy3JDR1xNJM/U+1/zxsCr8sFzYY1DGt77J9qm0Ndb4KH6tBowJ93y5MC81QRPpohaCoPvW+d31AmvLyEtnOlSvTHJdnViBHHKDcnEYdrqmSVmy7NwZV4UzGkALykQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787084; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ROdqnZ/nLMN3k6AxZtOjR0wy51FmT8iu0mjenz/VUAk=; b=nfXZZXBzufidoaLQIOiTt1HkpVLmV577VXom6wNY3qlZ+IQCx41Wsg89JVjvYzqBuDKqyasO0/1qEtd6iZTLUh6OZfKlhbhQ5Spg6OuGAKYkk2vdoQo106kP69TGZjTyJoXvqHD6FOwcDEn2VA9Uoi6/HpX3U+KZefrwExIDHFM= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787084077983.4155538342511; Wed, 30 Sep 2026 09:51:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxW8-0007xj-OR; Wed, 30 Sep 2026 12:50:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVd-0006Zd-BN for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:24 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVZ-0003Xs-1o for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:21 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49b912d3920so42046725e9.1 for ; Wed, 30 Sep 2026 09:50:16 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787015; x=1791391815; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ROdqnZ/nLMN3k6AxZtOjR0wy51FmT8iu0mjenz/VUAk=; b=f1FoLtbdcM5bjyPdAQ6PH4sZHClkMu/UMVtmfX4mrr3powxCc6WMbYbyhCmIiqLpN8 E7fs5DFuNXvAkCe8wdu6JyjRXZ3Z2+agt2W8lNXBVfD7yzpu6MDOEgxxRpbcyfDn+lqL vsqWGFmjD3cOBE5MFx5ry7pDwnPr0gw8HMfFJUPijVAUJ825CtPt3Gxg29mZBWD9od+c Qqm2LHsXpKqg4eke5/YJuP/cogX5WjPdmkLkT/KXAsWnhIfcykcUXITZsBuZS45kkhKz AndOoiPjxo6iFTvpQSWeNai3rrLla7cT3uB78TNPJz2IbLnPXoQq1yVBnZku8LaOR4Uu hp3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787015; x=1791391815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ROdqnZ/nLMN3k6AxZtOjR0wy51FmT8iu0mjenz/VUAk=; b=0EVnWRoKBXE+pOdhYIDjp2CpxnJog+KNDlOZM8SK/Gb5tdndMrdclIXqcxNrJSX7ZB a37ji0QAJw+xlNyInmLT8UbHR5JwAEiPiPGQxhMIXhZMaFEJZ6LuCqYyTQ8yKf87ETcZ qVXbDEKkKzBb9tBJXd3Wp5Fd1t4obbkOmWRR5LstN8jGU+zHBeBbhqhaq1W092XiVmD7 /YQiejxmss9G1E29kfdHF0QMMJFnnQuW8DPIPUVcV5XceaifFBip92u7c3hj4QOq0S6i sXu7yPGNZd9kf9gGku1xeuj5YfCWdZMmp+r86qn8Tvw2WsUYG9TRZdCNdb5yixnh4tTr E7cA== X-Gm-Message-State: AFuF++kBNDSQAIvNU5sRGnQkNcLYlEA2JXMP9cQ45AfIUyoZkjjSTBB4 2cJ2UHJfIPK6fCESNlwQRca5S6zQgoVz6e6acC7CX8l1+YJmQJ14jn5i3xHMWSBMNtmF2La5Se/ Mr9wI X-Gm-Gg: AYBFou2zxlRIa0NqMZJgSZbxAq+0ZHmmrUAzDqxBOFx3MwuNmmUWT5TvDKsVb8YZ4cv +oUYdgCYYJAt/1r06gRiKYTvrmXu/2A6ObFF3L34uEKvtjOhu7BHbGlCe2tAWzVGJmiwn/UlAoR iLvBy8npHVjxrhctS9HtfjrFuN3D5ubZlMoFvQzNq0rBdOWh63PrcPB6HqnBDjZreIc0cVLjevB 3CoaQuW3SkXePPNNlx6MAWaL61c8j48DjT9RWjaasFyWWYZB2V0BhOEaMJgEjA/yh6AlK78PS8i B6FezkXcprl2PCb2g1jdTWMTADaIGUKnmkrBHkxClR/sxCqAVhSl2VHJOOHkj+Gs1X1Zs4elye5 BPRe122RL94kxssGHJA/b0Q2bwGvUqqGUGmd1Ze+gZA+XSju9ZbKn90sKYVoBJK1p95OFzOJA/P Et6hsGXsY8nFktulgShukViG0kYAww2+Mn2F+a4wRWYEZoGOri/6lxxYyOaU5Ciu8UEmw= X-Received: by 2002:a05:600c:4e8f:b0:4a0:1eb0:1ab9 with SMTP id 5b1f17b1804b1-4a01eb01b1bmr4389885e9.16.1790787015513; Wed, 30 Sep 2026 09:50:15 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 09/13] qemu-io: add -t to run an aio request in a named iothread Date: Wed, 30 Sep 2026 18:49:55 +0200 Message-ID: <20260930165000.303236-10-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787084663158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev A multiqueue virtio-blk drives one node from several AioContexts at once, and nothing in the test tools could reproduce that shape: every qemu-io request ran in the main loop. Filters and drivers that cache state across a yield have therefore never been exercised the way production runs them. blk_aio_preadv() and friends enter the request coroutine in the caller's context, so submitting from a bottom half scheduled on an iothread is all it takes to put the request on that thread. The node itself stays where it is, which is what virtio-blk does with the queues it maps to iothreads other than the first. aio_read and aio_write promise their caller that the request has been submitted by the time they return, so wait for the bottom half to run before returning. That also makes a test deterministic: entering a coroutine from its own context runs it until it yields, so by the time the command returns the request has reached, or blocked at, whatever the test set up for it. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev Reviewed-by: Eric Blake --- qemu-io-cmds.c | 111 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 101 insertions(+), 10 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index aa795fd87a..ce5bb53f4e 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -22,6 +22,8 @@ #include "qemu/timer.h" #include "qemu/cutils.h" #include "qemu/memalign.h" +#include "system/iothread.h" +#include "qemu/aio-wait.h" =20 #define CMD_NOFILE_OK 0x01 =20 @@ -1367,8 +1369,84 @@ struct aio_ctx { int pattern; BdrvRequestFlags flags; struct timespec t1; + AioContext *aio_context; }; =20 +enum aio_submit_type { + AIO_SUBMIT_READ, + AIO_SUBMIT_WRITE, + AIO_SUBMIT_WRITE_ZEROES, +}; + +struct aio_submit { + struct aio_ctx *ctx; + enum aio_submit_type type; + int64_t bytes; + BlockCompletionFunc *cb; + bool submitted; +}; + +static AioContext *aio_context_by_iothread_id(const char *id) +{ + IOThread *iothread =3D iothread_by_id(id); + + if (!iothread) { + printf("iothread \"%s\" not found\n", id); + return NULL; + } + + return iothread_get_aio_context(iothread); +} + +static void aio_submit_bh(void *opaque) +{ + struct aio_submit *s =3D opaque; + struct aio_ctx *ctx =3D s->ctx; + + switch (s->type) { + case AIO_SUBMIT_READ: + blk_aio_preadv(ctx->blk, ctx->offset, &ctx->qiov, ctx->flags, + s->cb, ctx); + break; + case AIO_SUBMIT_WRITE: + blk_aio_pwritev(ctx->blk, ctx->offset, &ctx->qiov, ctx->flags, + s->cb, ctx); + break; + case AIO_SUBMIT_WRITE_ZEROES: + blk_aio_pwrite_zeroes(ctx->blk, ctx->offset, s->bytes, ctx->flags, + s->cb, ctx); + break; + default: + g_assert_not_reached(); + } + + qatomic_set(&s->submitted, true); + aio_wait_kick(); +} + +/* + * blk_aio_*() runs the request in the caller's AioContext, so submitting = from + * a bottom half is what puts it on another thread. + */ +static void aio_submit(struct aio_ctx *ctx, enum aio_submit_type type, + int64_t bytes, BlockCompletionFunc *cb) +{ + struct aio_submit s =3D { + .ctx =3D ctx, + .type =3D type, + .bytes =3D bytes, + .cb =3D cb, + }; + + if (!ctx->aio_context) { + aio_submit_bh(&s); + return; + } + + aio_bh_schedule_oneshot(ctx->aio_context, aio_submit_bh, &s); + AIO_WAIT_WHILE_UNLOCKED(NULL, !qatomic_read(&s.submitted)); +} + static void aio_write_done(void *opaque, int ret) { struct aio_ctx *ctx =3D opaque; @@ -1468,6 +1546,7 @@ static void aio_read_help(void) " -P, -- use a pattern to verify read data\n" " -q, -- quiet mode, do not show I/O statistics\n" " -r, -- register I/O buffer\n" +" -t, -- run the request in the named iothread\n" " -v, -- dump buffer to standard output\n" "\n"); } @@ -1479,7 +1558,7 @@ static const cmdinfo_t aio_read_cmd =3D { .cfunc =3D aio_read_f, .argmin =3D 2, .argmax =3D -1, - .args =3D "[-Ciqrv] [-P pattern] off len [len..]", + .args =3D "[-Ciqrv] [-P pattern] [-t iothread] off len [len..]", .oneline =3D "asynchronously reads a number of bytes", .help =3D aio_read_help, }; @@ -1490,7 +1569,7 @@ static int aio_read_f(BlockBackend *blk, int argc, ch= ar **argv, Error **errp) struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); =20 ctx->blk =3D blk; - while ((c =3D getopt(argc, argv, "CiP:qrv")) !=3D -1) { + while ((c =3D getopt(argc, argv, "CiP:qrt:v")) !=3D -1) { switch (c) { case 'C': ctx->Cflag =3D true; @@ -1514,6 +1593,13 @@ static int aio_read_f(BlockBackend *blk, int argc, c= har **argv, Error **errp) case 'r': ctx->flags |=3D BDRV_REQ_REGISTERED_BUF; break; + case 't': + ctx->aio_context =3D aio_context_by_iothread_id(optarg); + if (!ctx->aio_context) { + g_free(ctx); + return -EINVAL; + } + break; case 'v': ctx->vflag =3D true; break; @@ -1551,8 +1637,7 @@ static int aio_read_f(BlockBackend *blk, int argc, ch= ar **argv, Error **errp) clock_gettime(CLOCK_MONOTONIC, &ctx->t1); block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size, BLOCK_ACCT_READ); - blk_aio_preadv(blk, ctx->offset, &ctx->qiov, ctx->flags, aio_read_done, - ctx); + aio_submit(ctx, AIO_SUBMIT_READ, 0, aio_read_done); return 0; } =20 @@ -1579,6 +1664,7 @@ static void aio_write_help(void) " -P, -- use different pattern to fill file\n" " -q, -- quiet mode, do not show I/O statistics\n" " -r, -- register I/O buffer\n" +" -t, -- run the request in the named iothread\n" " -u, -- with -z, allow unmapping\n" " -z, -- write zeroes using blk_aio_pwrite_zeroes\n" "\n"); @@ -1592,7 +1678,7 @@ static const cmdinfo_t aio_write_cmd =3D { .perm =3D BLK_PERM_WRITE, .argmin =3D 2, .argmax =3D -1, - .args =3D "[-Cfiqruz] [-P pattern] off len [len..]", + .args =3D "[-Cfiqruz] [-P pattern] [-t iothread] off len [len..]= ", .oneline =3D "asynchronously writes a number of bytes", .help =3D aio_write_help, }; @@ -1604,7 +1690,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv, Error **errp) struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); =20 ctx->blk =3D blk; - while ((c =3D getopt(argc, argv, "CfiP:qruz")) !=3D -1) { + while ((c =3D getopt(argc, argv, "CfiP:qrt:uz")) !=3D -1) { switch (c) { case 'C': ctx->Cflag =3D true; @@ -1618,6 +1704,13 @@ static int aio_write_f(BlockBackend *blk, int argc, = char **argv, Error **errp) case 'r': ctx->flags |=3D BDRV_REQ_REGISTERED_BUF; break; + case 't': + ctx->aio_context =3D aio_context_by_iothread_id(optarg); + if (!ctx->aio_context) { + g_free(ctx); + return -EINVAL; + } + break; case 'u': ctx->flags |=3D BDRV_REQ_MAY_UNMAP; break; @@ -1692,8 +1785,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv, Error **errp) } =20 ctx->qiov.size =3D count; - blk_aio_pwrite_zeroes(blk, ctx->offset, count, ctx->flags, - aio_write_done, ctx); + aio_submit(ctx, AIO_SUBMIT_WRITE_ZEROES, count, aio_write_done); } else { nr_iov =3D argc - optind; ctx->buf =3D create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, @@ -1709,8 +1801,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv, Error **errp) block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size, BLOCK_ACCT_WRITE); =20 - blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, ctx->flags, - aio_write_done, ctx); + aio_submit(ctx, AIO_SUBMIT_WRITE, 0, aio_write_done); } =20 return 0; --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787088; cv=none; d=zohomail.com; s=zohoarc; b=AB4tM69DAyHWC02t4Ciogu3HG91+ZLIwJ4y0yBRCqPLl/WdUcE5Z6nYDNexX94i7eFEWCW8LyIqEVzyO/ry4MiAOWtX45Wqp31uYgnG/cfimHgZtHaG/+KlIfgJ0EGAwyrY2CZltj853ozehFTJyeda5Z2hEjqIjXOwaCNhZSbA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787088; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5US/vIcb1jdJXn35ECQsGQA2Ouaa1Ah+FNh4z4UiZkI=; b=L7zXiAvtBmqAtGPUNy1G4tNc5ogWKSM3vV4b8bV8sIPCXzdBcNChfxfzF+5JAGPIOwGPWcb61qW/7BTl0hLcZex7w807IX7QKCqlO1LSSoPxUf2XcDbK+qZMjTw7hxz9aaknWYNLKu/NE48r8+AnBKm8ZXnq9MbHlNJA666x5qU= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787088909814.9812498724281; Wed, 30 Sep 2026 09:51:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxWA-0008Ae-K8; Wed, 30 Sep 2026 12:50:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVm-0006iI-EL for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:30 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVk-0003YF-MC for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:30 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49ffe281cb1so28742805e9.1 for ; Wed, 30 Sep 2026 09:50:17 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787017; x=1791391817; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5US/vIcb1jdJXn35ECQsGQA2Ouaa1Ah+FNh4z4UiZkI=; b=IhLECNnPewpb5MuAV588HFWozZhvMtuzpZJVpk1HxDRveNQN5QDOIAVKBrbhbL/dcT T5xrYdchUT7EJZSx5ZCsBun4mbkl9bTI/3UCcu6LtO1i3+fOeAUyQuxV7vYTkkHy4AZO pE4cQRFwTxoJZ1Z+WO/g6pxlFRQ+AkiD9VXV+yDatzNZuMqaEsTuBeTMv8Vpa7cQxTio J2fUuIPAHzktGvAYn2veul5/yWZcwP0zMyip/qJsAoBVbU+ttuiIPwiXML0/lxdLQ5rP iq0kpymAr8Dd2HL8isp0RJTWqbwATwRmAG+jYPbFs8cDpEylAgC2bZLw/5VxvV8aYh9B uhcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787017; x=1791391817; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5US/vIcb1jdJXn35ECQsGQA2Ouaa1Ah+FNh4z4UiZkI=; b=izCMPJkU/okO8DlatBa94fhndgS8SRNaQl+q7vcucmn1oKzwmb2hJtdhwBGEnDp7XZ Qa/gUH9nnu5jlrQFoXVqivAyehQTorgcHmnyJRYN0wAJPsS5MTGEXx15aVDkyMx+Oe8C ClaQF2uKC9NoSAYojbFm0eUZgv9Lu/yKRLG+V0Gbwc80MejydxQvZG5oP0kinJH6wjRK d4lZlZe8Pp3TjkIN0hgWNbqJoUZghO+oHAX8NX+/3DkzInQjSl5XB8t5gAd/oYMwacQe YxBFLmLvNM4JAIqu+ktSRMul0BWAjztXj6e+0hsfjtsDQ78csUTrjgKK9IqMqaepDVQl 7M8g== X-Gm-Message-State: AFuF++mD5W6V/iU2IxyiCvsr87Z0PzUDyBiAgJhwdxY3QlGGiSRzZ5/P sVXlUmnz5l7tFJKPUPlrw4bsk0piqAeDEOvaaCMd/oxmNYW/BdZnqtPPRLGxbAJDT0GVW/xO7kB xsY0h X-Gm-Gg: AYBFou19OZxmg9TvSHlrgWfbeaew4Y4g003UIg6I/sJrmASKV4mT0UHSi3qUCJCnFxH jAPe/mw/wBS2l/vITYfq3xhCXl5NmYAh6hroOpBN83wyTfLXSRDzl2hpIWKrIW5rBSOiZThh4JP e/8Kh15QaDsXqur1wTQ7ikjsLRLaDqZIHDqwHQMJD00XBXfrSi061i4o9UvSNv+YQRjHw3ctTVb kxM9IS/KDjhkkV8VtGvCafhXiuLHeflYu7Ftv0yxx2j13bqzGm8oeRhunM50mTEfVUOBs6O0nJc y4WQRfw0oM8dYJRzLw5lXd/Ta1nASGqOYRLM+COMKPAdyPpfzwQTTSWLKZ2T3po1H6T9h6ogJ6s eDhAlcOK3Poo0bENe5poWf7o/Nro3zb3Eap5B150ewdBe8u9NBDGQeX2F7LrIfB/f26YsMjiJwZ Uguu6u7my0RUG6sbrZmKzxodnZ/QBxw3EMSvtCf2gEicBzP5WX7YyslribmQN1wlg9ph8= X-Received: by 2002:a05:600c:c162:b0:49f:bc43:9e96 with SMTP id 5b1f17b1804b1-4a01afe1dfamr36181175e9.8.1790787016651; Wed, 30 Sep 2026 09:50:16 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 10/13] qemu-io: add -g to write past the end of the image Date: Wed, 30 Sep 2026 18:49:56 +0200 Message-ID: <20260930165000.303236-11-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787090801158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev The preallocate filter only does anything for a write that lands beyond the end of its file, and that is what a format driver above it produces. qemu-io could not produce it at all: the backend rejects such a request with EIO, and the write path asserts without the resize permission, so the filter could only be reached by stacking a real format on top and letting it choose the offsets. Take the resize permission and allow writes beyond the end when -g is given, which leaves the tool free to address the filter directly. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev Reviewed-by: Eric Blake --- qemu-io.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index 2b684ccf55..87254b32ff 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -45,6 +45,7 @@ static bool quit_qemu_io; static int ncmdline; static char **cmdline; static bool imageOpts; +static bool write_beyond_eof; =20 static ReadLineState *readline_state; =20 @@ -114,6 +115,21 @@ static int openfile(char *name, int flags, bool writet= hrough, bool force_share, =20 blk_set_enable_write_cache(qemuio_blk, !writethrough); =20 + if (write_beyond_eof) { + uint64_t perm, shared; + + blk_set_allow_write_beyond_eof(qemuio_blk, true); + + blk_get_perm(qemuio_blk, &perm, &shared); + if (blk_set_perm(qemuio_blk, perm | BLK_PERM_RESIZE, shared, + &local_err) < 0) { + error_reportf_err(local_err, "can't take the resize permission= : "); + blk_unref(qemuio_blk); + qemuio_blk =3D NULL; + return 1; + } + } + return 0; } =20 @@ -129,6 +145,7 @@ static void open_help(void) " Opens a file for subsequent use by all of the other qemu-io commands.\n" " -r, -- open file read-only\n" " -s, -- use snapshot file\n" +" -g, -- let writes extend the image past its end\n" " -C, -- use copy-on-read\n" " -n, -- disable host cache, short for -t none\n" " -U, -- force shared permissions\n" @@ -149,7 +166,7 @@ static const cmdinfo_t open_cmd =3D { .argmin =3D 1, .argmax =3D -1, .flags =3D CMD_NOFILE_OK, - .args =3D "[-rsCnkU] [-t cache] [-d discard] [-o options] [path]= ", + .args =3D "[-grsCnkU] [-t cache] [-d discard] [-o options] [path= ]", .oneline =3D "open the file specified by path", .help =3D open_help, }; @@ -175,7 +192,7 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv, Error **errp) QDict *opts; bool force_share =3D false; =20 - while ((c =3D getopt(argc, argv, "snCro:ki:t:d:U")) !=3D -1) { + while ((c =3D getopt(argc, argv, "gsnCro:ki:t:d:U")) !=3D -1) { switch (c) { case 's': flags |=3D BDRV_O_SNAPSHOT; @@ -228,6 +245,9 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv, Error **errp) case 'U': force_share =3D true; break; + case 'g': + write_beyond_eof =3D true; + break; default: qemu_opts_reset(&empty_opts); qemuio_command_usage(&open_cmd); @@ -310,6 +330,8 @@ static void usage(const char *name) " specify tracing options\n" " see qemu-img(1) man page for full description\n" " -U, --force-share force shared permissions\n" +" -g, --grow let writes extend the image past its end,\n" +" as a format driver does to its file\n" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n" "\n" @@ -503,7 +525,7 @@ static QemuOptsList file_opts =3D { int main(int argc, char **argv) { int readonly =3D 0; - const char *sopt =3D "hVc:d:f:rsnCmki:t:T:U"; + const char *sopt =3D "hVc:d:f:grsnCmki:t:T:U"; const struct option lopt[] =3D { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, @@ -522,6 +544,7 @@ int main(int argc, char **argv) { "object", required_argument, NULL, OPTION_OBJECT }, { "image-opts", no_argument, NULL, OPTION_IMAGE_OPTS }, { "force-share", no_argument, 0, 'U'}, + { "grow", no_argument, NULL, 'g' }, { NULL, 0, NULL, 0 } }; int c; @@ -607,6 +630,9 @@ int main(int argc, char **argv) case 'U': force_share =3D true; break; + case 'g': + write_beyond_eof =3D true; + break; case OPTION_OBJECT: g_ptr_array_add(objects, optarg); break; --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787103; cv=none; d=zohomail.com; s=zohoarc; b=FwxYjCsBJwQUMnHQBgNgwiJJZ5uutx+1PgzAfd/ZB+D7EaJpk2u9L6XT4E3RC6VgrYAwa03bZmFi8jnb2IVJu66n+HMJl8fuPc3yE8rS0usdmbvAeOaSYeCyWpu399ejZMdlS3VP82gGDYJCWDs6bI9ILk9Nwocg48ikVxftE+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787103; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VbF2v5R4oT26b8Dj57rPb9AkdXwY59tdRR55Q6yPNA4=; b=XJxFPaK4Y7tQD9lpBJOmy5QwzJmlnLVbmrw62VUL86ywDmnALi3E4f+6laLlpAFIeaZJTjx7NexbK+DMbkYAamJq2v1QuE63x8VE8HfXmCeZvbqz49xqmHPNbKvV0sU68GdgyDgNMRTsoE4rzRfMkpxxSYwYS0uFIV145XXFdT0= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179078710275921.59180094327519; Wed, 30 Sep 2026 09:51:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxW6-0007oW-LC; Wed, 30 Sep 2026 12:50:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVh-0006eq-T7 for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:30 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVb-0003Yl-8n for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:25 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49d1fb0cf5eso51985435e9.3 for ; Wed, 30 Sep 2026 09:50:18 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787018; x=1791391818; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VbF2v5R4oT26b8Dj57rPb9AkdXwY59tdRR55Q6yPNA4=; b=QzWP+DmMMon/rmV4KjdgrgqRNBy0cVl69RQT/zrhNQioS7ZfdGA22XhzYOjABAfQr+ ccQ9DqAIxFpG5pcaJ6hZoPmh4S2Lxy2PjTiDNfXPDNhq/YKdzHZD2Ag4NRQ+jLDDzwwF MhMRAq9UqXpmd4bnPd8LVkMxdQz3IasMSZAFQDDLtogteysr7TlwKl+5F6z30sehYpOk b38Ga5cVUjotbSDkTQiAG2fuWoZisLgz39jU+9tHbZOlcxuJNYxkktAHdf23Ks+CCsqV hfDIQ19DAcOKpAFXHWdmfAM7AHtyGkQT7+StqTPANGTkN+moo+X4jBGknvcl2d+aEnl+ rgnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787018; x=1791391818; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VbF2v5R4oT26b8Dj57rPb9AkdXwY59tdRR55Q6yPNA4=; b=gCXmLm3qlmywsoep6ha+j6WrAkMeovzTz9RDZcHfuSe7UUXKBygx6TBNry6ubtHUGk faZQiVemhQ/+po2esMpYw5YTmZUsJulOXR/CrwtWkXKX1dRukGLOHAHxlLTnCJnYWqYv ok8VpOabl6w42GajBz+aUI8vCbBbolNrcPp3lRnGlCOe72gFxNYHHe3bzw13ztmM+v6W UsFq7etYA9kUFlT2GpqCGhhir3VZ3y4m9S9i+3O2mCOUo1F9+fkzTzlLvD+AXG6Ylvgz XDtNqwcq1NkDmbelleG7W7Mj9QsVwHVevy+D6kcSXgZNYPplow7IEsHAWjLso0lS4klU OJHw== X-Gm-Message-State: AFuF++kL70CFhnq2FIHWUytDIHws0JL9YNK/eSFtiOSfOZNe/x6EKc9N y1JMwNlhgOyKYI7X2HtETUMeNjp39N77Mz7Srm4Y+Ene7J59xS7gy139sdEqlV0KykdA2ap84wr FZ4lz X-Gm-Gg: AYBFou0K3i3v13oanj7RI3ImuD2tCexEC8uPeasxaK9DPRMPJtg0Wc9wdfWEYHv8+ri sQt2HD/+Cm8/u8Lxo9SiNyyqLc88TgkoOs/RI8iLQIt+uTmf8fKL0HvBMCZeqjzg9W8CEpNcbP4 vsWGE+vU8Iy8RBTtTztWS5cEBfojeAWliZoH9zGNTANA6dUGodlhQDa7MU4TU9CgLndBNwwv12+ Ncc+8vee2Y2eo5t2NhWpmlY0PGD1dWLbs8BbPsV3HSLuOlpmFDTag6nqjkm4Sv/YcnTEqM3ub76 +eI2xFxL9Fe9N4Gb/Nm74uyHMmeXIqqOzJLbDyddWswOzeIBLV90X+CZxsTC+TYFuoi96mA/+lt x0SZcbs8FJH75fTiL6Y2YSLpgjR7kNwx2aDbzZcQOKplT1ILTQYAnZeK3LOjMIa+0GUY4DqSwlR xRhdXw0o4h8Velat2KoGoXMuNgazGzgW3eU0JnZZJDgEcAcHtfsjb/A7wC+1jrOctt5joYc2pzs ElIQg== X-Received: by 2002:a05:600c:800e:b0:4a0:12d6:33b6 with SMTP id 5b1f17b1804b1-4a01afe84f4mr35941475e9.8.1790787017672; Wed, 30 Sep 2026 09:50:17 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 11/13] block/blkdebug: make a breakpoint work across AioContexts Date: Wed, 30 Sep 2026 18:49:57 +0200 Message-ID: <20260930165000.303236-12-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=den@openvz.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787104609158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev A request that stops at a breakpoint belongs to whichever AioContext issued it, and the monitor or qemu-io that resumes it runs somewhere else. Two things go wrong once those are not the same thread. resume_req_by_tag() woke the request with qemu_coroutine_enter(), which enters the coroutine on the caller's thread. That moves the request off its own thread for the rest of its life, and it aborts outright when it wins the race against the yield, because the request is published to the list before the coroutine gets there. wait_break polled the block backend's AioContext, where the event will never arrive, so it slept through the suspension it was waiting for. Wake the request in the context it came from and wait for it the way the rest of the block layer waits across contexts. Where the two contexts are the same the coroutine is still entered directly, so single-threaded behaviour, and the output tests depending on it, do not change. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev Reviewed-by: Eric Blake --- block/blkdebug.c | 3 ++- qemu-io-cmds.c | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 78cc03746f..1522015b34 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -813,6 +813,7 @@ static void suspend_request(BlockDriverState *bs, Blkde= bugRule *rule) =20 remove_rule(rule); QLIST_INSERT_HEAD(&s->suspended_reqs, r, next); + aio_wait_kick(); =20 if (!qtest_enabled()) { printf("blkdebug: Suspended request '%s'\n", r->tag); @@ -925,7 +926,7 @@ retry: g_free(r); =20 qemu_mutex_unlock(&s->lock); - qemu_coroutine_enter(co); + aio_co_wake(co); qemu_mutex_lock(&s->lock); =20 if (all) { diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index ce5bb53f4e..eed39ab93c 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2791,9 +2791,8 @@ static const cmdinfo_t resume_cmd =3D { =20 static int wait_break_f(BlockBackend *blk, int argc, char **argv, Error **= errp) { - while (!bdrv_debug_is_suspended(blk_bs(blk), argv[1])) { - aio_poll(blk_get_aio_context(blk), true); - } + AIO_WAIT_WHILE_UNLOCKED(NULL, + !bdrv_debug_is_suspended(blk_bs(blk), argv[1])= ); return 0; } =20 --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787083; cv=none; d=zohomail.com; s=zohoarc; b=Irxwx2hfjD+cKtvTfIo+M0/JlXSxkWc+PJiT88s2dQiu6/jjVdq/pXKolGXkbchK2dk1S67JVHg1nKXY8BJFTLa4fTHvAyTxf+dB3Bt4aevTrPyrDGrU+YkpM9OS0FE9fZURQjVLam8PethpB2e15BiyBrnyWfNiVYS0WR/GIQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787083; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Gc8btmcgaQ636BUxwTgKPD/UQOCA38WGrDAL/WuGLv8=; b=fP2KNghYtGzEM+vlwQDMoDl3brEDlzDQwhaePKRfhLMsRd3peSSu2pVsuDnSnvZnACfIa2AX4B/wHO69UxLWp3QwkwDfUoPYqBKSPCNB8ouQ1pdK25Q3R5T7HtHTd554o7UtekXvtPl+ngtlzUHpfTtAP3YE1S9As85m4Bq38sY= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787083455714.0952064680527; Wed, 30 Sep 2026 09:51:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxW9-00085L-J4; Wed, 30 Sep 2026 12:50:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVe-0006cm-SB for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:24 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVc-0003ZO-S2 for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:22 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49e7bcb94d3so42330665e9.2 for ; Wed, 30 Sep 2026 09:50:19 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787019; x=1791391819; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Gc8btmcgaQ636BUxwTgKPD/UQOCA38WGrDAL/WuGLv8=; b=GduSZsFSc0Iml+YLbmKDzKfl4LcDkRPp0Z236oqVyJqG7RfNl1vlywAtzifCGAlzrd Kv3JJruGzBSsCY/IprapVQiXd7mnjoSjDTaD++TDnBv7P40Zj8DOXYfpXRhfq09V9ySg iFsdNIcyiF120mf4EUedZYgBZflzzRD8yk1n9O5cF1j0m6sUgoPg3yr+yIdZ7J2/sfg/ MsCBdzPQDBslAfArI0ouwG7DdStSuJk8kClEzcElC4wmsoKr7LE4fEkM7OPxnLrjNj+Y SbkX7rN9cKveOKI2ty/PyUXdJJmbxIV4C/zJzApoB1RIz12k9uWMwohcjIlQnMV/WV6o jJZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787019; x=1791391819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Gc8btmcgaQ636BUxwTgKPD/UQOCA38WGrDAL/WuGLv8=; b=oa1xW5DcDw5yiu+IUN8gZ9SkRH5qYb+cQjor9lFUwqjPc/xQ9df/p7spJPqpAjJMAO wK3Tq7KLv2+4JxCq7zdRb02WyKE0IWBpuC7dxSjcqIAY8BeC4QsYJrQCuaE0SW74CdTY pV4KTx+NFfPhZ9j2VLJra0K/VxFrUgRe/GEOb07Tw4OAZA+yPqBuZC259UQ7vuH96giV hEuO6lhOO0ia8z+08fMfJ9Y5ubH2SwRxVTwWOtqkz1hkh1Pd9cYTj514koN8R2U+dd2g phrGxPBItBC9V6a+k1wbkE/ZQ8gA7c4hXsLE7lH/aARgPvIHhnl1aqP1V6nYBMixgqNg l7eQ== X-Gm-Message-State: AFuF++ma3G2H2otpSUcYR0Zs+4nxUGt+EuCXOc1hAi2+kBdCFZXT41XR ZTtmN34xLTknIGFYSqfWjhcVTYesvtQpeQDhOJO2wmESFu8FHu1iWC5P6V7dqgJcEoZ1jcBw0W+ ssrbj X-Gm-Gg: AYBFou1W6t3Mj8451Nw1iXbUz6A2Dr0v5JMXL7fcZIsD4TdF6NwSuLJ+CYA/FL7dFSp zmHBLT/Ao8AikF4LTPMLy4hJUvorlk4W4fwsgIe0YiVEwLw8gJvvIrhukot21Gd0YnJKQ7yV7IU 0D+eBhPkobHRLsh6Tm55g44gkO4zSo5Cgm24u43jWQwbBVHSIrE35+NLABySp9Twyl8w6FoNTvQ 7grzAadG4SwMTJp33nmY6/uHzb91nT4WdJTrVnv7L+rCLGq/T+RhLu6mlCVq10hpTDanaSFKFN1 6JxG+EVynp2Qy9D+cb8EzrYaW6y68K8AihQhj4N4QkYhceza1C2NeSXIV0RA0bYF159xj5P5fyM RIcdCD2L9gcpPFE5D4BIeWQPMWzIUaUEb2MW9rr1ClNHzqDij9Tv97os7+NCIRG0qJlR3/sivSK UnDks3bB0mgTy4qrVCZ6dVYtQ2EMbeRveo5vZSF4Y0wjLMF8HS9kCk+q1j70B+uF3hkJk= X-Received: by 2002:a05:600c:3b10:b0:4a0:c02:938c with SMTP id 5b1f17b1804b1-4a01b1290f0mr36983705e9.25.1790787018846; Wed, 30 Sep 2026 09:50:18 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev , Eric Blake , Markus Armbruster Subject: [PATCH 12/13] block: add blkdebug events for a write before it is tracked Date: Wed, 30 Sep 2026 18:49:58 +0200 Message-ID: <20260930165000.303236-13-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=den@openvz.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787084562158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev A breakpoint on pwritev or pwritev_zero stops a request that has already joined the list of tracked requests, so it is ordered against everything that arrives later. There was no way to hold a request in the window before that, which is where a filter has published its state but the block layer does not yet know the request exists. Fire pwritev_untracked and pwritev_zero_untracked from bdrv_co_pwritev_part() once the request counts as in flight and before tracked_request_begin(). They come in a pair like the events they mirror, so that a test can tell a preallocation from the writes racing with it: blkdebug matches on the event, not on the request. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev CC: Eric Blake CC: Markus Armbruster Reviewed-by: Eric Blake --- block/io.c | 3 +++ qapi/block-core.json | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index a916b236c3..a32b567264 100644 --- a/block/io.c +++ b/block/io.c @@ -2302,6 +2302,9 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, } =20 bdrv_inc_in_flight(bs); + bdrv_co_debug_event(bs, (flags & BDRV_REQ_ZERO_WRITE) ? + BLKDBG_PWRITEV_ZERO_UNTRACKED : + BLKDBG_PWRITEV_UNTRACKED); tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_WRITE); =20 if (flags & BDRV_REQ_ZERO_WRITE) { diff --git a/qapi/block-core.json b/qapi/block-core.json index aed2888147..340ee8c9e2 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3897,6 +3897,13 @@ # # @none: triggers once at creation of the blkdebug node (since 4.1) # +# @pwritev_untracked: a write, before it joins the list of tracked +# requests and so before it is ordered against any other request +# (since 11.2) +# +# @pwritev_zero_untracked: the same for a write zeroes request +# (since 11.2) +# # Since: 2.9 ## { 'enum': 'BlkdebugEvent', 'prefix': 'BLKDBG', @@ -3915,7 +3922,8 @@ 'pwritev_rmw_tail', 'pwritev_rmw_after_tail', 'pwritev', 'pwritev_zero', 'pwritev_done', 'empty_image_prepare', 'l1_shrink_write_table', 'l1_shrink_free_l2_clusters', - 'cor_write', 'cluster_alloc_space', 'none'] } + 'cor_write', 'cluster_alloc_space', 'none', + 'pwritev_untracked', 'pwritev_zero_untracked'] } =20 ## # @BlkdebugIOType: --=20 2.53.0 From nobody Sat Oct 24 00:32:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790787104; cv=none; d=zohomail.com; s=zohoarc; b=kOoQjWkgHR8ldYBJxdPPp8GGUsN2dP4s/n3pN8xxVaCaXM4aDj3/e2uHKuJAhD90aDirVgo/tTvnJWImIQ3BCOCOaECyEXMUqMe21Y+DBfhygEe4rzLG/XZhg2rRGZdg71d9NayYmcLVRuJJnZ620LDHv9YzauYBlLlI/9Cag+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790787104; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Nk+gi0rQBaHti3N6byJTfS2qwKpbxxxTWgyInRcfQLo=; b=fqrmQFUa4+Hx8G8roepVn0dNoO2CHaIS+nKWmhSXnVqYvJtZTKXP3rGuBYKIvfFc5kxi/MRmfbEcM43gpdfseijgoKC7K2tGKyEphi0rCdFxOWjMo3dn8/w2SnCKl4cquP2Al/N8MdJmD417qRjZPiCWlUPMMur+diwhjr5ewms= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790787103948768.9273412684964; Wed, 30 Sep 2026 09:51:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBxW6-0007oL-KW; Wed, 30 Sep 2026 12:50:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBxVv-0006wD-Ss for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:39 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBxVn-0003Zp-AZ for qemu-devel@nongnu.org; Wed, 30 Sep 2026 12:50:33 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49b912e4b11so33389595e9.3 for ; Wed, 30 Sep 2026 09:50:20 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01eb71d57sm4144535e9.9.2026.09.30.09.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 09:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790787020; x=1791391820; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Nk+gi0rQBaHti3N6byJTfS2qwKpbxxxTWgyInRcfQLo=; b=dDWlSbsHdS+Ekt4PUjWNuOBThHSju6yfCouHIpl9pjwIjo0Md+IijzwucTm17jQjHK HD2ke2PZm3Be2PIkCiD6L1bsmRSwGMNT3p9xJCaIBwJlo6/Zu1gUcYjRQuma8QLmnWny ptovVtFzNHB3tidp90df9RgnKzP2ZnqXP70eay7Zll7+4xiskmXo7vzy5ouSz5R0KbQa e75fTSNjXunvNJcS9Makt2AE0CtJU4YVMjAGnvZNHFToQw6QmDKxPD+mC8XTnBhomz/v UGpo1NkAaEzDeVFCfh/qZ2fEbz324c+cm3klq7GWfpTEVuz/Ip9ns3WLCeZ5wn6cXax9 v9Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790787020; x=1791391820; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Nk+gi0rQBaHti3N6byJTfS2qwKpbxxxTWgyInRcfQLo=; b=MJkh5nX6C84Cpb8b1+7l5O2O81gFTQAafomFbpzABTPuj4BbrzP/vDXDaG00Ubbc4O eVwxwpyd89YZgwTJ9iXhsoglM4UejSt8gZVfVHDj2+jlYR5spxGe/HxxDU6hNV0Gf30w PuGQi3YpgUBkLdH2GuLbKIWV1FFAxbS0Xnp6Oyaj4PkmI0vv9UKvFXp+MOCZlcsHwEBk xAKZxeyJwbqC0Owjh7A1cveiD6YcQZqb5Y5cQYBDBz/8ycU4XXWStlMEp50cCh+qj040 D0+AIY0WTp0QGSSG4vGr/JXaA8C2i3Kmye/Ga039iojz5kXC5s8Wgg9Ff6xKhQdtZuNP Bn+Q== X-Gm-Message-State: AFuF++ndECmdTqyh7QCGBsSxu2OKQNxptXn49QNE3ujFDEtze8dXAMOL TXgCfjpfcmkJTeNT5w6GQ20WBW0/qb6jv2K+uSoIQ2mHDw8/YPFWOVtq9purUkLnTTg46qB5Qvx u9LcJ X-Gm-Gg: AYBFou0PGfqIa9L6JYwY7btUfpUHvqFerupnj1Sz6+DC+1etneSJ9B1Soau+Iwaehwm w3By/dziR7fmg0GJzWl4wVLG28xTLTs1+qTNP/2pb7unsKC6R79qQLaACos+/KSd3OVezu41YxI FBQeX2u32V3h2xuEkJphBJajIaQQ9fcLCLWam7Jy8ez2AQNZdp5rKFqvaIIZB1GNSSK+PuUrIdq +dfd/y+Si7g74KtgSmWvVyhthvRg/yI2WOM2mm/a8nz0Pp+p+y6cm/etIOJVquPikwriMcKFNGB h9EOOXd2Gi6nOoaGn+gRKasyw0JFX+xTUDxTL9gG8GpCuh5CMZhuvicpUjoYnGpkwpJrXPvilqa e8TbEabrmENvxNGQXBTk/In3oNDevlJgQshLnWZtHVV9fAJkrwvIsH55Lvt7Hw+FtDObOUNHeTB mohWFn0tHc1KBrEZnqubjPgJz/sSx9NKRAHTruzLGXWWjPLkuXItNzmfzry3vADDVjczE= X-Received: by 2002:a05:600c:1f87:b0:49d:174e:2a1e with SMTP id 5b1f17b1804b1-4a01afe1e05mr37788825e9.19.1790787019885; Wed, 30 Sep 2026 09:50:19 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: den@openvz.org, qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , Andrey Drobyshev Subject: [PATCH 13/13] iotests/298: cover the preallocation races Date: Wed, 30 Sep 2026 18:49:59 +0200 Message-ID: <20260930165000.303236-14-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930165000.303236-1-den@openvz.org> References: <20260930165000.303236-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790787104635158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev Three cases the filter has to get right, all deterministic: a write the preallocation cannot reach goes through without waiting for it, a write into the range it covers does not, and a write zeroes over data written inside that range is not skipped as already zero. The second one cannot wait for the write to finish, because that is what it is checking does not happen, and the data survives either way: a preallocation that finds the write still in flight gives up. It asks whether the write got past the filter at all instead, by leaving a breakpoint below it. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Vladimir Sementsov-Ogievskiy CC: Andrey Drobyshev Reviewed-by: Eric Blake --- tests/qemu-iotests/298 | 64 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/298.out | 4 +-- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/298 b/tests/qemu-iotests/298 index 23e7789d09..866e00f8e0 100755 --- a/tests/qemu-iotests/298 +++ b/tests/qemu-iotests/298 @@ -27,6 +27,7 @@ GiB =3D MiB * 1024 disk =3D os.path.join(iotests.test_dir, 'disk') overlay =3D os.path.join(iotests.test_dir, 'overlay') refdisk =3D os.path.join(iotests.test_dir, 'refdisk') +racedisk =3D os.path.join(iotests.test_dir, 'racedisk') drive_opts =3D f'node-name=3Ddisk,driver=3D{iotests.imgfmt},' \ f'file.node-name=3Dfilter,file.driver=3Dpreallocate,' \ f'file.file.node-name=3Dfile,file.file.filename=3D{disk}' @@ -225,6 +226,69 @@ class TestPreallocAsyncWrites(iotests.QMPTestCase): proc.close() =20 =20 +class TestPreallocateRaces(iotests.QMPTestCase): + # blkdebug under the filter holds the preallocation before it is track= ed. + opts =3D f'driver=3Dpreallocate,prealloc-align=3D65536,prealloc-size= =3D262144,' \ + f'file.driver=3Dblkdebug,file.image.driver=3Dfile,' \ + f'file.image.filename=3D{racedisk}' + + def setUp(self): + self.proc =3D None + with open(racedisk, 'wb') as f: + f.truncate(MiB) + + def tearDown(self): + if self.proc: + self.proc.close() + os.remove(racedisk) + + def qemu_io(self, *args): + self.proc =3D iotests.QemuIoInteractive('-g', *args, '--image-opts= ', + self.opts) + return self.proc + + def test_write_below_preallocation(self): + proc =3D self.qemu_io('--object', 'iothread,id=3Dt0') + proc.cmd('break pwritev_zero_untracked prealloc') + proc.cmd('aio_write -q -t t0 -P 0xaa 1M 64k') + proc.cmd('wait_break prealloc') + + # Returns while the preallocation is parked only if it never waite= d. + out =3D proc.cmd('write -P 0xcc 4k 4k') + + proc.cmd('resume prealloc') + proc.cmd('aio_flush') + self.assertIn('wrote 4096/4096', str(out)) + + def test_write_into_preallocation(self): + proc =3D self.qemu_io('--object', 'iothread,id=3Dt0', + '--object', 'iothread,id=3Dt1') + proc.cmd('break pwritev_zero_untracked prealloc') + proc.cmd('aio_write -q -t t0 -P 0xaa 1M 64k') + proc.cmd('wait_break prealloc') + proc.cmd('break pwritev late') + proc.cmd('aio_write -q -t t1 -P 0xbb 1152k 64k') + + # A held-back write never finishes; ask whether it got past the fi= lter. + late =3D proc.cmd('resume late') + + proc.cmd('remove_break late') + proc.cmd('resume prealloc') + proc.cmd('aio_flush') + data =3D proc.cmd('read -P 0xbb 1152k 64k') + + self.assertIn('Could not resume request', str(late)) + self.assertNotIn('Pattern verification failed', str(data)) + + def test_write_zeroes_over_written_data(self): + proc =3D self.qemu_io() + proc.cmd('write -q -z 1M 128k') + proc.cmd('write -q -P 0xaa 1M 64k') + proc.cmd('write -q -z 1M 256k') + out =3D proc.cmd('read -P 0 1M 64k') + self.assertNotIn('Pattern verification failed', str(out)) + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2'], required_fmts=3D['preallocate= '], require_hmp=3DTrue) diff --git a/tests/qemu-iotests/298.out b/tests/qemu-iotests/298.out index 6323079e08..52d796e60b 100644 --- a/tests/qemu-iotests/298.out +++ b/tests/qemu-iotests/298.out @@ -1,5 +1,5 @@ -.............. +................. ---------------------------------------------------------------------- -Ran 14 tests +Ran 17 tests =20 OK --=20 2.53.0