From nobody Sun Nov 16 01:08:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762273960; cv=none; d=zohomail.com; s=zohoarc; b=lS+h7kXKfOaff661KHkAht78TkOOmiCORLyoITa9FZlukWZ8/Js8zBY2tkoQxBoV+z5RRdmenkMUfdXwVNPr/X8UmPnBNpH92kOFcxQpjKVlRnqqs1zUzz0W2p860RoObfDqaugB6K9s3LI440YjPXcG+0jNUbquVv25nFTFXi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762273960; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CWdMa1znnBSu2wgLltL31AcGV76n2oLZuhzJyyM3hwg=; b=A2xn+CCqEReDc076jX16mIouJ18kDi/fJUbStD81LfqkpIeaDXyuPuAcORRUmdgTSFIkXKe9+zl2GxAX/w3oiRxO6aUh9Uv2F/srOwIMVs6DPQk+45/PSlQh8mXiG4nTodlv+USp8LkP7iLDnvnyFN6kgVUL2xOAuGSiQjtcG8Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762273960645513.1830504115909; Tue, 4 Nov 2025 08:32:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGJwl-0007gT-EV; Tue, 04 Nov 2025 11:31:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwI-0007ce-7d for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwB-0003yL-Rr for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:18 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-u6uullqNMMWk8Q-kPUlf3g-1; Tue, 04 Nov 2025 11:31:08 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-b7067f229b8so458987766b.2 for ; Tue, 04 Nov 2025 08:31:08 -0800 (PST) Received: from [192.168.10.48] ([151.95.110.222]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b723d3a3d6dsm248826866b.15.2025.11.04.08.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 08:31:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762273874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CWdMa1znnBSu2wgLltL31AcGV76n2oLZuhzJyyM3hwg=; b=Uf6VzoSyzOQHdXSutxFx1wxIKiWbKDenmx7w63Wssg1fdzceKC3KmhHaAzvQxnaxbM93Iq JHv9zz+hvFY/9bEORzNSVadyUrXFkJ4cRujrDzxCNE9xDzGuZ75J5H20yagLN6njy4G1kQ sTtHMGRoIQWqAGfHT8nhcaGfDRDlo1k= X-MC-Unique: u6uullqNMMWk8Q-kPUlf3g-1 X-Mimecast-MFC-AGG-ID: u6uullqNMMWk8Q-kPUlf3g_1762273867 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762273866; x=1762878666; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CWdMa1znnBSu2wgLltL31AcGV76n2oLZuhzJyyM3hwg=; b=FNp7K+330ER14FGh37Ghlur5g9tQebUGVcxH759yhSy2VrNTrRLUfajDltlVu48gjs +RZUhqCu9XIEb9oyRV9ND0eopRPOHUZuWIHphR81c1+ANWaeRcMo+2HpyhB2oBHO9l+u eUKoY1ctt2uxRAg6wrQNcgOr1+4GStxF68RD9rPVPbMP7PRW4Er5i8o+VEkBbxM0P7Ru 3afO3PdIrnUg+fVqfW5eJLxWb2+txMVkTRwN5kK+PyfCMlDXyxFX6DMOg/yjVnbg8pgJ uepka0++b9jfmpbvyusaCRp8b+ODzYOoDgpp0QnrT36pXi1DowjEyowvM9LwZJynluzu JCvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762273866; x=1762878666; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CWdMa1znnBSu2wgLltL31AcGV76n2oLZuhzJyyM3hwg=; b=NJgMC4rPbt6iVTpriSKgc0GxEqrEVVGYG1leluj+4lgt5Z3I4p9YhQbd0bh0g+QC5T sbEs6hiw0a7LgmPWBwLIKGIGVtRXOixubkNllQlDj+FtfnfIDXtT+JXfMVgOVdGaRUXI pBECYcL36nMyoH7wF7D0KB9bLtLMD302jvwqhFEM+Z+i2SmN2VDtN8bkeQtYh2fCwLXR sdmYt/ToQvSAH/8PwJFH8yB6lcchPjiFw0r+GrHGxXA91QKGNKot1tEM74pK7tKRB3ib 6DvWM2xHL08/CdPwT2P9E7h6OsSk5gkLThiQYPo0ayyop0GbziIr4J65RTqQwGEEqvbT EMtw== X-Gm-Message-State: AOJu0YwudlI11I2ZNc+bv5dgj8Hfok6Ucz/21QOfxexcJH8JHXMpK/U4 ebp19mVXvgeWJfBr29DGHEHKOX3emiy/tkFMRKM4yj7/7ud3+Ru3U7VuQEZYNP+O9LrF6LfFLgb ATEKe3qF13hhem4/5T71EAy9vPEuzlazF6GJH+IbJ1ddBoKUwxS8d0blUVTP3Rb5jVU8zZ9RUcy CYLvtxXo+QCxJd6uXyzQdTALVrq1cfsqBaXgyT0trN X-Gm-Gg: ASbGncsPa7LGNKm+8g8nRaVwGwBft4NgdTbHOYoT68/SeCQVLXuyx/hjy4YxH2KeQWk KP+zFRizU84K2pzBy2QZTfsUjfqiSYJAUFII4xTQRWHqonihCHR2dJkLzH9DT+syOWqtFaW3vMN DY7VkPOyWVS1QGFaI3LCGFwn8w2yANlclOTmcwFMmEuuxSfqM4rqX9eBnrBvq1fGJxcZ0yMWEuA gup84PsnHcXHihFBP/0BZu+rOhTHvitPm1JJ4rV8c6KpFMeqPugJAfU38EEPTs4HHbC0BpPRLQU rKESpuHVMyD+EKHRxXi0CWGxuI7QwLJoVuT2cbn7KGYNR9rJ+JGuGS3M9vr9qRthqGwuqcVUCR/ JtIL9ptgkrATWCeWileO8DlwE6vu+jPZur/0VSt5XovmXNEfzhd4f5TqlLsuV/RpufdduSjXzvK sMv2rx X-Received: by 2002:a17:907:724b:b0:b43:b740:b35d with SMTP id a640c23a62f3a-b70704b95afmr1857181266b.33.1762273866583; Tue, 04 Nov 2025 08:31:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgiWTNigbEv10AEYJe4BdwZsngYwVhyNsSDi8INqz/6G8HofgC48SncRK/MLxpVvnsDASahg== X-Received: by 2002:a17:907:724b:b0:b43:b740:b35d with SMTP id a640c23a62f3a-b70704b95afmr1857177866b.33.1762273866089; Tue, 04 Nov 2025 08:31:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy Subject: [PULL 1/8] scripts/checkpatch.pl: remove bogus patch prefix warning Date: Tue, 4 Nov 2025 17:30:55 +0100 Message-ID: <20251104163102.738889-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251104163102.738889-1-pbonzini@redhat.com> References: <20251104163102.738889-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.788, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1762273968352158500 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Remove the 'patch prefix exists, appears to be a -p0 patch' warning entirely as it is fundamentally flawed and can only produce false positives. Sometimes I create test files with names 'a' and 'b', and then get surprised seeing this warning. It was not easy to understand where it comes from. How it works: 1. It extracts prefixes (a/, b/) from standard diff output 2. Checks if files/directories with these names exist in the project root 3. Warns if they exist, claiming it's a '-p0 patch' issue This logic is wrong because: - Standard diff/patch tools always use a/ and b/ prefixes by default - The existence of files named 'a' or 'b' in the working directory is completely unrelated to patch format - The working directory state may not correspond to the patch content (different commits, branches, etc.) - In QEMU project, there are no single-letter files/directories in root, so this check can only generate false positives The correct way to detect -p0 patches would be to analyze the path format within the patch itself (e.g., absolute paths or paths without prefixes), not check filesystem state. So, let's finally drop it. Signed-off-by: Vladimir Sementsov-Ogievskiy Link: https://lore.kernel.org/r/20251030201319.858480-1-vsementsov@yandex-t= eam.ru Signed-off-by: Paolo Bonzini --- scripts/checkpatch.pl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d3d75f3f139..d0f4537f25e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1741,13 +1741,7 @@ sub process { } } elsif ($line =3D~ /^\+\+\+\s+(\S+)/) { $realfile =3D $1; - $realfile =3D~ s@^([^/]*)/@@ if (!$file); - - $p1_prefix =3D $1; - if (!$file && $tree && $p1_prefix ne '' && - -e "$root/$p1_prefix") { - WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); - } + $realfile =3D~ s@^[^/]*/@@ if (!$file); =20 if (defined $fileinfo && !$fileinfo->{isgit}) { $fileinfo->{lineend} =3D $oldhere; --=20 2.51.1 From nobody Sun Nov 16 01:08:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762273991; cv=none; d=zohomail.com; s=zohoarc; b=dJ6oXBvG3JYlQkmlOag1E83AIKhAf4GoWd2DdfzIq6tGbhghY1ozavtxaO9+ZDBzAxLISxR86++cagbkXuzPVkjXtJJOEeyvtUuLxUGe67VEeo2iB2gjTdm2y+ulogslfaT5C43swr2OK+qF0hzOf9jJuKBCm8IeSF8V6npkUUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762273991; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=y5zycgEsXQM6pRKEG7JhYUW0ECHZFhS5oVojreimnMA=; b=TsRdQ+aisBOFH4yxFtN6DRI1m0Q5CaHaGkWPqmHckaBB+TnKlP3iFEWfCN5IioNjD/0z1KnCsTz+FyhJMYfWlR0F5vbkps8uER0T6DdCxJpWslQ8adex1QqWJNwC3JqedXg0rGHBsR8FW5yvhuO0k2o7prh1PkSd/vdak4AqSP8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762273991239704.881031697129; Tue, 4 Nov 2025 08:33:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGJwp-0007jg-Dh; Tue, 04 Nov 2025 11:31:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwI-0007cd-7D for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwA-0003xw-MB for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:17 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-4oQdSMysOqKfWR0uoR8T3g-1; Tue, 04 Nov 2025 11:31:11 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-b707e22ebeeso695253766b.3 for ; Tue, 04 Nov 2025 08:31:10 -0800 (PST) Received: from [192.168.10.48] ([151.95.110.222]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b7240348d93sm244411266b.68.2025.11.04.08.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 08:31:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762273872; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y5zycgEsXQM6pRKEG7JhYUW0ECHZFhS5oVojreimnMA=; b=TfTPqXt9fgROtMKIR+l7UnYeysQ6uLm7fu4WTWm+h/wVoDlI4mL+/zNUqrmOSJkepxwpO4 ffPYeNUXTR/0EH6Wf/Nr21qXgPjtEahsOQUQEb9FA9BvXw06CVgPtWpk8pIbEbmGClm+Wo 2bydusWRODL0LWyOHbfL8Fsq+4hPB2Q= X-MC-Unique: 4oQdSMysOqKfWR0uoR8T3g-1 X-Mimecast-MFC-AGG-ID: 4oQdSMysOqKfWR0uoR8T3g_1762273870 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762273869; x=1762878669; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y5zycgEsXQM6pRKEG7JhYUW0ECHZFhS5oVojreimnMA=; b=gmZHZU52hrQmQOq2jMOQS9GfbxEyxczqySFw7tffhLRbbb5t0wsbQK1LJtxILikCtF iS8EkGn8d/kf42412i1RfBKByEJimbIb8Zu5/EO/2W5WUH4u8k2GmLC5JaAXiGMYOUGu i4WHEiOenpqlcSfgWyssyNcr7jMgTDQSvWhmHlA+gJXwFENlH68V9Es16pvjVeCiTMIY EhaRRAar9qQ/8fofUkbRB9bdhCI0mHYdEqD8UhJQ3OT5l6K4DsGQVJbSLp7X1NmMzCc8 KkA+dwshmaJSih88gGhTzxcYUJNRmdhARClkn8qOzvsM6Xx3vuaI2P/ow27hUnYXeIf3 nQpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762273869; x=1762878669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y5zycgEsXQM6pRKEG7JhYUW0ECHZFhS5oVojreimnMA=; b=LaaZybtom/M+25lhSrGoP0KpqGRBCQh8RCMMr27qQ6TsHvZ0ycVXktTJKylN2NCe6P ajGN7I9Aq7iTRjh5LN5oKZjBJJHLGoKj94eya6vNcymItGaUKXcYNLXc6ocdj1wPZoTl cUP3Zbw1eXYXMsuU/QI7f8bOF+kaHG9wVc/yavtQGBc3uFho3nd2tXePgg/drP3crk1f JHANldSbzFMe2DB1v39tSzB6ZOWt9zTb22u19Ra4C00+yM7JAEsleGT5fdNC0JvH/wWX NS5xp6mHPzcry0GBQkdiWHocV4tyrxMJ5w25L72+mflk2btIPEPtV0P0zr2XUkyi3pf2 vKPA== X-Gm-Message-State: AOJu0YySm7M8KKReptizV6ACJl+5p4/WXHd1WyBKjUXlv6wH14Gpg9wd UcT5ua02hU9S2AZVEMLw1YeGs58t6XhLPYIMb/CXrvrBWxcUN3WiZEuDoey8EgM6d6DWKdlgTEg MZGwmnQIfWxxKx+BBKloKzo8OgNBtnQ27R4oqRmPPaYlnOkh5UsytKdch5dNfGI/8/rEyyIpVPg gcRXcBSyheSrI0xCDtEk9DHFb6jbhLmmYocSQ/VMBA X-Gm-Gg: ASbGnctMjLCGi7YU9CdBMCyikmHaxJ5K1Kbr18l9n/dLUamoG1j63jzkXt5jKSxXfrQ aTzndoxA4h8k1a0x67f45KZbsV/yy235IHw47HESWywrl1McX9Hk9H1K6yGoznPOD5R5/fiXHmw t3wp3xNdCWgDE4iKHfeTfKPxMuTLQHGDYGqzKRIE/5UJTtP83NU+aAYZfJsSoj516nYdn6onJCg rZtvG4xDP7oz7UnbbwRixltTocfqq+5divo7H2IN+c2yBLibuYm+udgHsyuSr7V+EtT2Z0FrxMW KFezXcjdUbW8vZR1ocuOIq4T/LCJv6TOy435NF8Q6PQSumpUK4hDuquP4kSI/i+V+gpsLUttEYZ KRzigTJTrfxJdL9JAqSp9J24HGtFMmGujtacMzKz6kSy8mi0/gidPbULrRI3Py7NPlkdo9KmBgH YlSUmR X-Received: by 2002:a17:907:1c11:b0:b72:5640:ac15 with SMTP id a640c23a62f3a-b725640b0dcmr238405066b.26.1762273868950; Tue, 04 Nov 2025 08:31:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcUxRkaAmXVlf6EtOp0/PfR6MwhnGZAM7MiUYN4UCAdpSDqkK7O15ewQZempzi+oh53FJbhw== X-Received: by 2002:a17:907:1c11:b0:b72:5640:ac15 with SMTP id a640c23a62f3a-b725640b0dcmr238401966b.26.1762273868370; Tue, 04 Nov 2025 08:31:08 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 2/8] rust/util: add ensure macro Date: Tue, 4 Nov 2025 17:30:56 +0100 Message-ID: <20251104163102.738889-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251104163102.738889-1-pbonzini@redhat.com> References: <20251104163102.738889-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.788, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1762273992321158500 Content-Type: text/plain; charset="utf-8" The macro is similar to anyhow::ensure but uses QEMU's variation on anyhow::Error. It can be used to easily check a condition and format an error message. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/timer/hpet/src/device.rs | 21 ++++++---- rust/hw/timer/hpet/src/fw_cfg.rs | 7 ++-- rust/util/src/error.rs | 71 ++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 13 deletions(-) diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/devi= ce.rs index 23f2eefd1cd..3564aa79c6e 100644 --- a/rust/hw/timer/hpet/src/device.rs +++ b/rust/hw/timer/hpet/src/device.rs @@ -25,7 +25,10 @@ bindings::{address_space_memory, address_space_stl_le, hwaddr}, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder, MEMTXATTRS_UNSP= ECIFIED, }; -use util::timer::{Timer, CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND}; +use util::{ + ensure, + timer::{Timer, CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND}, +}; =20 use crate::fw_cfg::HPETFwConfig; =20 @@ -728,14 +731,14 @@ fn post_init(&self) { } =20 fn realize(&self) -> util::Result<()> { - if self.num_timers < HPET_MIN_TIMERS || self.num_timers > HPET_MAX= _TIMERS { - Err(format!( - "hpet.num_timers must be between {HPET_MIN_TIMERS} and {HP= ET_MAX_TIMERS}" - ))?; - } - if self.int_route_cap =3D=3D 0 { - Err("hpet.hpet-intcap property not initialized")?; - } + ensure!( + (HPET_MIN_TIMERS..=3DHPET_MAX_TIMERS).contains(&self.num_timer= s), + "hpet.num_timers must be between {HPET_MIN_TIMERS} and {HPET_M= AX_TIMERS}" + ); + ensure!( + self.int_route_cap !=3D 0, + "hpet.hpet-intcap property not initialized" + ); =20 self.hpet_id.set(HPETFwConfig::assign_hpet_id()?); =20 diff --git a/rust/hw/timer/hpet/src/fw_cfg.rs b/rust/hw/timer/hpet/src/fw_c= fg.rs index bb4ea8909ad..777fc8ef45e 100644 --- a/rust/hw/timer/hpet/src/fw_cfg.rs +++ b/rust/hw/timer/hpet/src/fw_cfg.rs @@ -5,6 +5,7 @@ use std::ptr::addr_of_mut; =20 use common::Zeroable; +use util::{self, ensure}; =20 /// Each `HPETState` represents a Event Timer Block. The v1 spec supports /// up to 8 blocks. QEMU only uses 1 block (in PC machine). @@ -36,7 +37,7 @@ unsafe impl Zeroable for HPETFwConfig {} }; =20 impl HPETFwConfig { - pub(crate) fn assign_hpet_id() -> Result { + pub(crate) fn assign_hpet_id() -> util::Result { assert!(bql::is_locked()); // SAFETY: all accesses go through these methods, which guarantee // that the accesses are protected by the BQL. @@ -47,9 +48,7 @@ pub(crate) fn assign_hpet_id() -> Result { fw_cfg.count =3D 0; } =20 - if fw_cfg.count =3D=3D 8 { - Err("Only 8 instances of HPET are allowed")?; - } + ensure!(fw_cfg.count !=3D 8, "Only 8 instances of HPET are allowed= "); =20 let id: usize =3D fw_cfg.count.into(); fw_cfg.count +=3D 1; diff --git a/rust/util/src/error.rs b/rust/util/src/error.rs index bfa5a8685bc..2a57c7fd5fd 100644 --- a/rust/util/src/error.rs +++ b/rust/util/src/error.rs @@ -86,6 +86,19 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } } =20 +impl From> for Error { + #[track_caller] + fn from(msg: Cow<'static, str>) -> Self { + let location =3D panic::Location::caller(); + Error { + msg: Some(msg), + cause: None, + file: location.file(), + line: location.line(), + } + } +} + impl From for Error { #[track_caller] fn from(msg: String) -> Self { @@ -126,6 +139,17 @@ fn from(error: anyhow::Error) -> Self { } =20 impl Error { + #[track_caller] + #[doc(hidden)] + pub fn format(args: fmt::Arguments) -> Self { + if let Some(msg) =3D args.as_str() { + Self::from(msg) + } else { + let msg =3D fmt::format(args); + Self::from(msg) + } + } + /// Create a new error, prepending `msg` to the /// description of `cause` #[track_caller] @@ -311,6 +335,53 @@ unsafe fn cloned_from_foreign(c_error: *const bindings= ::Error) -> Self { } } =20 +/// Ensure that a condition is true, returning an error if it is false. +/// +/// This macro is similar to [`anyhow::ensure`] but returns a QEMU [`Resul= t`]. +/// If the condition evaluates to `false`, the macro returns early with an= error +/// constructed from the provided message. +/// +/// # Examples +/// +/// ``` +/// # use util::{ensure, Result}; +/// # fn check_positive(x: i32) -> Result<()> { +/// ensure!(x > 0, "value must be positive"); +/// # Ok(()) +/// # } +/// ``` +/// +/// ``` +/// # use util::{ensure, Result}; +/// # const MIN: i32 =3D 123; +/// # const MAX: i32 =3D 456; +/// # fn check_range(x: i32) -> Result<()> { +/// ensure!( +/// x >=3D MIN && x <=3D MAX, +/// "{} not between {} and {}", +/// x, +/// MIN, +/// MAX +/// ); +/// # Ok(()) +/// # } +/// ``` +#[macro_export] +macro_rules! ensure { + ($cond:expr, $fmt:literal, $($arg:tt)*) =3D> { + if !$cond { + let e =3D $crate::Error::format(format_args!($fmt, $($arg)*)); + return $crate::Result::Err(e); + } + }; + ($cond:expr, $err:expr $(,)?) =3D> { + if !$cond { + let s =3D ::std::borrow::Cow::<'static, str>::from($err); + return $crate::Result::Err(s.into()); + } + }; +} + #[cfg(test)] mod tests { use std::ffi::CStr; --=20 2.51.1 From nobody Sun Nov 16 01:08:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762273962; cv=none; d=zohomail.com; s=zohoarc; b=XQBkdiG5AX1BQnhMNT2b3wsa7hvmJ6P8noDGTxPknXvvCiu7eiOUuY1yB29pw9oErjxJPDMo81MeIJRoSbqHKlyYOoNLhljjKYfmJiXXX555rlg/l5tBzt+zvVCS4vrSFcRxLDhE+Jh1ALLB9YhzsGAvBLjVw5AXRdaJ9wWs7j4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762273962; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jWcRKatFGdRs6oGcB9rOvC9PoikvUkyBckrYRemBUEA=; b=QhjKgufYtfZCmFc9VZM6nWWO9fUCZlId+Ly7KnWsQWG98Hs/p1eh+GBpvfnm0VG0VbAFNGgE0eoeC4944ZT86cRv2uy/IdEdlRDCcYZUYufYm88hbqROCpQuPlTRPlKbS1hM5WzMxrLVwwcfGv87g0B3Yhlf7K5Zcd5u8pf3GrI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762273962319728.9824554712122; Tue, 4 Nov 2025 08:32:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGJwe-0007fo-1T; Tue, 04 Nov 2025 11:31:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwM-0007cn-Ir for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwH-0003z5-GF for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:24 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-Qmifns6QOT-cgTucMem2yw-1; Tue, 04 Nov 2025 11:31:14 -0500 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-b70b21e6cdbso257046966b.1 for ; Tue, 04 Nov 2025 08:31:13 -0800 (PST) Received: from [192.168.10.48] ([151.95.110.222]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-640e6a7f2a5sm2394441a12.34.2025.11.04.08.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 08:31:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762273877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jWcRKatFGdRs6oGcB9rOvC9PoikvUkyBckrYRemBUEA=; b=DqH1b6OkgmsUMdkYKRWq4JtU5cdrp/fEO+ikc6Kq34VGOVW5u7y6KP9PP2wQTXUFsgWoNN asf7KoGuAvPWlHey0QXpZenbotHZR/AS7nvALGKbArYjzkrI3QrGRytU5xtqV7qg5vkgKt +NBrXijgkw4yyYE7VTlMMgjJs8V78nk= X-MC-Unique: Qmifns6QOT-cgTucMem2yw-1 X-Mimecast-MFC-AGG-ID: Qmifns6QOT-cgTucMem2yw_1762273873 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762273871; x=1762878671; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jWcRKatFGdRs6oGcB9rOvC9PoikvUkyBckrYRemBUEA=; b=GyU6guDzXuFE9qANJQ9SLtBAJH9WkOUjhoPuFiD5xCkVyNvr+kW6p0dnEZKm3H/aoV ZEWMlcuOywkc9HEkoi0KggX/CUqZ086LpHBi+hmCwu6ja4WYJs3HRCV5x7EHTPF8YYIO h6OxBh9wWtLdB4IT6CM1GhoHTYM2FZisaZcw/VG9Waezeso8ggNGkcXwXs2i+5a9jChV yNYSjdipStPlXHTWIw2VhQWNBbAr8hVhSGwx15MZ4FMeRe02zQzUrfVkmahZqxfMA1CX 2SyNkIwxYSt6p8ERjctLDJNyJWpv76jlDtEUl3SavF+0H6Ym2flGymFzyxoDI3z/3wog Sp5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762273871; x=1762878671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jWcRKatFGdRs6oGcB9rOvC9PoikvUkyBckrYRemBUEA=; b=RDAWlcmFJ8xrza7ym0inZrNx3fSpK9cztQ/VAxidwNpXNgDIy+4xMZiKJaJsxaz0iG 4RDfXgGwFK03AErgcMzujYiYbQ/U1BJMsLISBrIbAo/kI3lJrn53VbPjEf3MC6L/z8SP +M/9vSNH8vX6iLeEMcaePh6oLW/3Mwpv0bsHQoKeWVZZG0z0DCwq3LfWmzomMcO9OruN iVlPDnZ4czaZkk1cAWIZXQn43KWhxeGUH4yz41udtZtO3EyzQY0mxnBCaUy1VVDfuj+0 AYx6g1aWJQNBjhPAKiH0FxR7U11PONc+DDjzSbl2eYAbfADui0ZCHQu0jAxRgvrqbJVI keUA== X-Gm-Message-State: AOJu0YwfplYWqHaI1uoMNgky4a5rYIMq7FRnFBDn/tFC0Mc2eorZbVAY hnZaCdmfOn8CVoSEXXDUEODthwoSkAged00pI1RAlNMzjpUqlf3UNsTpHL6LrLzgJ84zfzWm3qJ 6OCMcfG1AWq6Fxs836CRkPf5aG/jCdQOIiSPli0rsKQ4T3o+UfYDRQ0lfctZjAYfrr0WcjHdiQ/ 6oJCGAXXaryBT0LeJha7rW0qLpZKzMCojey+dOe7Ut X-Gm-Gg: ASbGncv9w1TBL5sbffcl+bySPjYcHBSNCa+E1HXttfT/78WTR+HKLCuLI3DgpZKq/bO u32AE4xWLOfKWiX14gOEvhMLQ3c6Gm0SYOKabk6nkgQZ+0ZTL8fWQVhlcAlj79tnIhDMGUDcgTA 9CTrASaLMNAs/K81mkL5yLscNgN286it9lX0iZBD11dG7WsDXZYWEUPK1ypDQyKiyZ0HyrVFnlH iNE1TJxPNX4BZrLHbS2XoM6MwaYRfRzenHnHmlk/OrBw+Xk/gLWKi9XdN1eTQ/FKnAVp4g0p4QO 8LzhZ2CkKVouSfXMBbD+5G+8FdtOksxQ/VPa7wE9tNyhpkPTWb/enq67j+QjXCX4uX7tXzYu9xN Pay7pk8CblKcRo3M1AMsQACI+jJD/nv3sGhw9T3SMt6aLq688nE6aWOh8K+gBnYfNcVPt0XNFK8 rmQY0H X-Received: by 2002:a17:907:7241:b0:b57:d5de:444a with SMTP id a640c23a62f3a-b7216f64864mr475080666b.15.1762273871320; Tue, 04 Nov 2025 08:31:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwjeR0HetxvAdI7EBecZiGIzZqrGtoblzDM8oCs5j+nR3r0Rv8iru+MOii/fH7kTP54D8v3g== X-Received: by 2002:a17:907:7241:b0:b57:d5de:444a with SMTP id a640c23a62f3a-b7216f64864mr475076566b.15.1762273870711; Tue, 04 Nov 2025 08:31:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 3/8] rust/util: use anyhow's native chaining capabilities Date: Tue, 4 Nov 2025 17:30:57 +0100 Message-ID: <20251104163102.738889-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251104163102.738889-1-pbonzini@redhat.com> References: <20251104163102.738889-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.788, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1762273976296158500 Content-Type: text/plain; charset="utf-8" This simplifies conversions, making it possible to convert any error into a QEMU util::Error with ".into()" (and therefore with "?"). The cost is having a separate constructor for when the error is a simple string, but that is made easier by the ensure! macro. If necessary, another macro similar to "anyhow!" can be returned, but for now there is no need for that. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/util/src/error.rs | 160 +++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 101 deletions(-) diff --git a/rust/util/src/error.rs b/rust/util/src/error.rs index 2a57c7fd5fd..11b574ca593 100644 --- a/rust/util/src/error.rs +++ b/rust/util/src/error.rs @@ -38,6 +38,7 @@ borrow::Cow, ffi::{c_char, c_int, c_void, CStr}, fmt::{self, Display}, + ops::Deref, panic, ptr, }; =20 @@ -49,118 +50,85 @@ =20 #[derive(Debug)] pub struct Error { - msg: Option>, - /// Appends the print string of the error to the msg if not None - cause: Option, + cause: anyhow::Error, file: &'static str, line: u32, } =20 -impl std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - self.cause.as_ref().map(AsRef::as_ref) - } +impl Deref for Error { + type Target =3D anyhow::Error; =20 - #[allow(deprecated)] - fn description(&self) -> &str { - self.msg - .as_deref() - .or_else(|| self.cause.as_deref().map(std::error::Error::descr= iption)) - .expect("no message nor cause?") + fn deref(&self) -> &Self::Target { + &self.cause } } =20 impl Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let mut prefix =3D ""; - if let Some(ref msg) =3D self.msg { - write!(f, "{msg}")?; - prefix =3D ": "; - } - if let Some(ref cause) =3D self.cause { - write!(f, "{prefix}{cause}")?; - } else if prefix.is_empty() { - panic!("no message nor cause?"); - } - Ok(()) + Display::fmt(&format_args!("{:#}", self.cause), f) } } =20 -impl From> for Error { +impl From for Error +where + anyhow::Error: From, +{ #[track_caller] - fn from(msg: Cow<'static, str>) -> Self { - let location =3D panic::Location::caller(); - Error { - msg: Some(msg), - cause: None, - file: location.file(), - line: location.line(), - } - } -} - -impl From for Error { - #[track_caller] - fn from(msg: String) -> Self { - let location =3D panic::Location::caller(); - Error { - msg: Some(Cow::Owned(msg)), - cause: None, - file: location.file(), - line: location.line(), - } - } -} - -impl From<&'static str> for Error { - #[track_caller] - fn from(msg: &'static str) -> Self { - let location =3D panic::Location::caller(); - Error { - msg: Some(Cow::Borrowed(msg)), - cause: None, - file: location.file(), - line: location.line(), - } - } -} - -impl From for Error { - #[track_caller] - fn from(error: anyhow::Error) -> Self { - let location =3D panic::Location::caller(); - Error { - msg: None, - cause: Some(error), - file: location.file(), - line: location.line(), - } + fn from(src: E) -> Self { + Self::new(anyhow::Error::from(src)) } } =20 impl Error { + /// Create a new error from an [`anyhow::Error`]. + /// + /// This wraps the error with QEMU's location tracking information. + /// Most code should use the `?` operator instead of calling this dire= ctly. + #[track_caller] + pub fn new(cause: anyhow::Error) -> Self { + let location =3D panic::Location::caller(); + Self { + cause, + file: location.file(), + line: location.line(), + } + } + + /// Create a new error from a string message. + /// + /// This is a convenience wrapper around [`Error::new`] for simple str= ing + /// errors. Most code should use the [`ensure!`](crate::ensure) macro + /// instead of calling this directly. + #[track_caller] + pub fn msg(src: impl Into>) -> Self { + Self::new(anyhow::Error::msg(src.into())) + } + #[track_caller] #[doc(hidden)] + #[inline(always)] pub fn format(args: fmt::Arguments) -> Self { - if let Some(msg) =3D args.as_str() { - Self::from(msg) - } else { - let msg =3D fmt::format(args); - Self::from(msg) - } + // anyhow::Error::msg will allocate anyway, might as well let fmt:= :format doit. + let msg =3D fmt::format(args); + Self::new(anyhow::Error::msg(msg)) } =20 /// Create a new error, prepending `msg` to the /// description of `cause` #[track_caller] pub fn with_error(msg: impl Into>, cause: impl Into<= anyhow::Error>) -> Self { - let location =3D panic::Location::caller(); - Error { - msg: Some(msg.into()), - cause: Some(cause.into()), - file: location.file(), - line: location.line(), + fn do_with_error( + msg: Cow<'static, str>, + cause: anyhow::Error, + location: &'static panic::Location<'static>, + ) -> Error { + Error { + cause: cause.context(msg), + file: location.file(), + line: location.line(), + } } + do_with_error(msg.into(), cause.into(), panic::Location::caller()) } =20 /// Consume a result, returning `false` if it is an error and @@ -326,8 +294,7 @@ unsafe fn cloned_from_foreign(c_error: *const bindings:= :Error) -> Self { }; =20 Error { - msg: FromForeign::cloned_from_foreign(error.msg), - cause: None, + cause: anyhow::Error::msg(String::cloned_from_foreign(erro= r.msg)), file: file.unwrap(), line: error.line as u32, } @@ -376,8 +343,8 @@ macro_rules! ensure { }; ($cond:expr, $err:expr $(,)?) =3D> { if !$cond { - let s =3D ::std::borrow::Cow::<'static, str>::from($err); - return $crate::Result::Err(s.into()); + let e =3D $crate::Error::msg($err); + return $crate::Result::Err(e); } }; } @@ -416,19 +383,10 @@ unsafe fn error_get_pretty<'a>(local_err: *mut bindin= gs::Error) -> &'a CStr { unsafe { CStr::from_ptr(bindings::error_get_pretty(local_err)) } } =20 - #[test] - #[allow(deprecated)] - fn test_description() { - use std::error::Error; - - assert_eq!(super::Error::from("msg").description(), "msg"); - assert_eq!(super::Error::from("msg".to_owned()).description(), "ms= g"); - } - #[test] fn test_display() { - assert_eq!(&*format!("{}", Error::from("msg")), "msg"); - assert_eq!(&*format!("{}", Error::from("msg".to_owned())), "msg"); + assert_eq!(&*format!("{}", Error::msg("msg")), "msg"); + assert_eq!(&*format!("{}", Error::msg("msg".to_owned())), "msg"); assert_eq!(&*format!("{}", Error::from(anyhow!("msg"))), "msg"); =20 assert_eq!( @@ -445,7 +403,7 @@ fn test_bool_or_propagate() { assert!(Error::bool_or_propagate(Ok(()), &mut local_err)); assert_eq!(local_err, ptr::null_mut()); =20 - let my_err =3D Error::from("msg"); + let my_err =3D Error::msg("msg"); assert!(!Error::bool_or_propagate(Err(my_err), &mut local_err)= ); assert_ne!(local_err, ptr::null_mut()); assert_eq!(error_get_pretty(local_err), c"msg"); @@ -462,7 +420,7 @@ fn test_ptr_or_propagate() { assert_eq!(String::from_foreign(ret), "abc"); assert_eq!(local_err, ptr::null_mut()); =20 - let my_err =3D Error::from("msg"); + let my_err =3D Error::msg("msg"); assert_eq!( Error::ptr_or_propagate(Err::(my_err), &mut loc= al_err), ptr::null_mut() --=20 2.51.1 From nobody Sun Nov 16 01:08:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762273984; cv=none; d=zohomail.com; s=zohoarc; b=PSFF9HxUBTvz74CCgtGwqFu3TDSBfgoE6lxl3V8vH9lnWLqv66ujTXFtxR2I+WvKeXPlKLQBScwmFGp9DDlwI9RHZPw+7xvc6XTabDilNnGn322IA/skS51k4KhKklKRkTQaNOSQChcqCpzufYfyHTFuzNQYcsa51EdrcDh+k+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762273984; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yyCxCICrU/SDz5D9OgrxQf/TXwBgksmHHfJEONyqPro=; b=h87VMuQXgshPAcXhEvIoPPrdgHog3ILc/7cduZsA/oj8SS36v/I9nQ6mrnJN1IPPCY/CpiHH6ydr/VUf9QDgnIDfpwPTR9/3p3FfOqmCmm+ZVBg8izMMhhmfC/kTkOreSkV36BmApm8attBmLmDKEVi1zF/xVccBdDOBG9YDd0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762273984778818.0905999264421; Tue, 4 Nov 2025 08:33:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGJwg-0007fz-Ou; Tue, 04 Nov 2025 11:31:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwM-0007co-Im for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwG-0003z2-RS for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:24 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-2wQZ-jcQNpu6TY_P9VINcw-1; Tue, 04 Nov 2025 11:31:15 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-b70b974b818so226714366b.1 for ; Tue, 04 Nov 2025 08:31:15 -0800 (PST) Received: from [192.168.10.48] ([151.95.110.222]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b723d3a3082sm251379166b.11.2025.11.04.08.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 08:31:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762273877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yyCxCICrU/SDz5D9OgrxQf/TXwBgksmHHfJEONyqPro=; b=RHI57N1Ys7g9itu9gmtKj6AOMFtNUggHSaDMdGwFfvad5sNpsBHGP2Ev5+/eWno5aYNgTo ScgA6yHGq5yiRzi3U3vI0jalaT+xwwr1KUKAoUGoqCxVhjDKqlHzh6YR75EFsBhWVz13Z3 AdLtiR01MUMRm58CoFG2qyS7Fl1CSi4= X-MC-Unique: 2wQZ-jcQNpu6TY_P9VINcw-1 X-Mimecast-MFC-AGG-ID: 2wQZ-jcQNpu6TY_P9VINcw_1762273874 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762273873; x=1762878673; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yyCxCICrU/SDz5D9OgrxQf/TXwBgksmHHfJEONyqPro=; b=BhiLZWrWTGr49iYI60hW3yzO4cb7xSCWi8H5/VscGQL+HGB41zL6IM0i7sjacLH40B OjHWSdp/c66ogXkGnrO2bM92kQciZ0JXRNdFPenr8vkn3xgC43iwOIZM8E/nF335r229 TEGZa86fFA8j1MLjjF5v8+RjW1yvSLcyhPK0RHh3XXYomPDLghzjqpdRcKe5JYBD+nFh 5jcxnw1w/tbpQXbixEr6JAyKsiLPpQuAsuqTUeoKfNKMfCrg3rTT/glXRQ11nRqlz+sX G/cJfkWoW15z4ORWKl/fIlD46erBtyvz4TZDFEfHMqPbYBpLR7BCCiqhVqFU4yh5Kuky Z7tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762273873; x=1762878673; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yyCxCICrU/SDz5D9OgrxQf/TXwBgksmHHfJEONyqPro=; b=YtrvUJ0bVk25K3WL98rn6Qg3l/UmPE/A4PtUgqbi/5fktApNE/vzz4kyHp3T7syMxM VcDUaaMB58dzkt2lElsxZVEUOJmK/DMR0EOy/GNCRsgYJhHWBZGn+WeDqC+XU7delKdU OlQ5YX/vUd4xQlyVSuHMqItpOwJYgMEiU2c9zIi22C+g4qMargh9OBrV9fXCrpmvDRkz lBKzCH+yuLna0VjLQCTxKcbTADMjIfLBDzGP1f4lmavQBw7cxh3rOV1qOHXAcgXrD1pL 93rN4swws5GxSkpM/Vc1CxJgG5F7lFrtGOCRG6XQ28cV0yQCf4Gb1E7cyM0gwU1ZE6gq WNig== X-Gm-Message-State: AOJu0YyTrvfBNBxt0XTC35V6FVGq2zinisSQRvk2MF1/CL/EXsSgqOJx otKBdsBLvZq6v8YI8MMb/MonqFokiRJXHWoQaj1QXKbv1vb2AGWfJxTSFbpdcCyqch4tja4FnBA MI7yV2HzprgSa0LtkxXapSQLbyrDLMuliz/0Dws4mBc/by2/ss504IeccgJII7RT+j8Pt5NOT7g 4po3dGtJWUppa4vLDcrUwniIhmQBzXbY1WY0mxBTnf X-Gm-Gg: ASbGncsldw3CoXBNx+jc7Ia8vhT1NjWEsjBY4c2svS/kCVO3lJqPV2PUFpffUtwv0cG HSTPwNLR+vimNb/rQAVP3RbgcG1fBiply5un3xSp+pSqtUp9DcrdAiX009BADnfB9UjM4BQ9vuP ADFq9jtwc64cMJufmMKmxiLJUe6RBNKSTAgBMFZieS/qo/CRUATVZ2dCGS5+cYhxgFcHQvxi7Yo fhN6bxcyCULIJKXbumedCNvZ9a2UxET9OkhanHU0O/y7zm1chQ09Ela745SHenUY+PH23dNptnw 2erJnsBUScX/g7s6VNWWKIsv52KFzTI9a9xbZEGkF69S5LZ8bKnxiAgdZJ83A9l6G3cimpqpkuW X+w/UR6BLArDSejJFzGHCS7ndwGDIupnS8UaDeG5bY8IKJLx2/rIPg0NFyTqRT60+MVX/OVCCaH 0ihig2 X-Received: by 2002:a17:907:6d20:b0:b70:b83a:73e5 with SMTP id a640c23a62f3a-b70b83a8c35mr824454766b.44.1762273872940; Tue, 04 Nov 2025 08:31:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdlbU944pOfr+uBd52FjeS2yoL85K6gDfy6iDRgAm/01jC2vbIewQPGSPt1k68q/yicnURaw== X-Received: by 2002:a17:907:6d20:b0:b70:b83a:73e5 with SMTP id a640c23a62f3a-b70b83a8c35mr824451666b.44.1762273872157; Tue, 04 Nov 2025 08:31:12 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 4/8] rust/util: replace Error::err_or_unit/err_or_else with Error::with_errp Date: Tue, 4 Nov 2025 17:30:58 +0100 Message-ID: <20251104163102.738889-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251104163102.738889-1-pbonzini@redhat.com> References: <20251104163102.738889-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.788, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1762274008454158500 Content-Type: text/plain; charset="utf-8" Introduce a simpler function that hides the creation of the Error**. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/util/src/error.rs | 52 ++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/rust/util/src/error.rs b/rust/util/src/error.rs index 11b574ca593..346577e2e53 100644 --- a/rust/util/src/error.rs +++ b/rust/util/src/error.rs @@ -14,8 +14,7 @@ //! [`ptr_or_propagate`](crate::Error::ptr_or_propagate) can be used to = build //! a C return value while also propagating an error condition //! -//! * [`err_or_else`](crate::Error::err_or_else) and -//! [`err_or_unit`](crate::Error::err_or_unit) can be used to build a `R= esult` +//! * [`with_errp`](crate::Error::with_errp) can be used to build a `Resul= t` //! //! This module is most commonly used at the boundary between C and Rust c= ode; //! other code will usually access it through the @@ -213,35 +212,21 @@ pub unsafe fn propagate(self, errp: *mut *mut binding= s::Error) { } } =20 - /// Convert a C `Error*` into a Rust `Result`, using - /// `Ok(())` if `c_error` is NULL. Free the `Error*`. + /// Pass a C `Error*` to the closure, and convert the result + /// (either the return value of the closure, or the error) + /// into a Rust `Result`. /// /// # Safety /// - /// `c_error` must be `NULL` or valid; typically it was initialized - /// with `ptr::null_mut()` and passed by reference to a C function. - pub unsafe fn err_or_unit(c_error: *mut bindings::Error) -> Result<()>= { - // SAFETY: caller guarantees c_error is valid - unsafe { Self::err_or_else(c_error, || ()) } - } + /// One exit from `f`, `c_error` must be unchanged or point to a + /// valid C [`struct Error`](bindings::Error). + pub unsafe fn with_errp T>(= f: F) -> Result { + let mut c_error: *mut bindings::Error =3D ptr::null_mut(); =20 - /// Convert a C `Error*` into a Rust `Result`, calling `f()` to - /// obtain an `Ok` value if `c_error` is NULL. Free the `Error*`. - /// - /// # Safety - /// - /// `c_error` must be `NULL` or point to a valid C [`struct - /// Error`](bindings::Error); typically it was initialized with - /// `ptr::null_mut()` and passed by reference to a C function. - pub unsafe fn err_or_else T>( - c_error: *mut bindings::Error, - f: F, - ) -> Result { - // SAFETY: caller guarantees c_error is valid - let err =3D unsafe { Option::::from_foreign(c_error) }; - match err { - None =3D> Ok(f()), - Some(err) =3D> Err(err), + // SAFETY: guaranteed by the postcondition of `f` + match (f(&mut c_error), unsafe { c_error.into_native() }) { + (result, None) =3D> Ok(result), + (_, Some(err)) =3D> Err(err), } } } @@ -432,13 +417,16 @@ fn test_ptr_or_propagate() { } =20 #[test] - fn test_err_or_unit() { + fn test_with_errp() { unsafe { - let result =3D Error::err_or_unit(ptr::null_mut()); - assert_match!(result, Ok(())); + let result =3D Error::with_errp(|_errp| true); + assert_match!(result, Ok(true)); =20 - let err =3D error_for_test(c"msg"); - let err =3D Error::err_or_unit(err.into_inner()).unwrap_err(); + let err =3D Error::with_errp(|errp| { + *errp =3D error_for_test(c"msg").into_inner(); + false + }) + .unwrap_err(); assert_eq!(&*format!("{err}"), "msg"); } } --=20 2.51.1 From nobody Sun Nov 16 01:08:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762273980; cv=none; d=zohomail.com; s=zohoarc; b=kAYJujJbyzWG2n4zLal36A0s8RjP2wr21MVzfixTDN9Rb4GhodMfVs8P1cdca/0glr4D913GIx//QjN4L2skGWp/npEs9Cf6mNYrAsMxxEOPk/UDcHfWaAZMURD0IOvZCOKS4jKK1MqvN81ndf4883JW5wmqaZu48ymfmp3IHIs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762273980; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mjIcfLdvLe3Kq7hGsddlUyAZz5HeU5g0QLiH7INvZwM=; b=HB4tlDHZ7D/91GGkkBG/NO9JODDO+CRZuk+U5rfRjCNS+TuLn8ECJldmWbWFS1eaBbOk04AcCzvLKe1BVO2yQAXir8mOl/AFTQzPs2XWfmMuiRk1omCr0Q+lNQc6kApTdQcd6ew20/yP4gc8ggDQeSzYrJFd1wr6o4bTjYPiRBw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762273980491695.3486227870011; Tue, 4 Nov 2025 08:33:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGJwg-0007g8-Sh; Tue, 04 Nov 2025 11:31:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwN-0007ct-Pp for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwI-0003zf-KN for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:26 -0500 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-0IR5SQRoPkq1-AYPv_DHhQ-1; Tue, 04 Nov 2025 11:31:18 -0500 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-b448c864d45so532432766b.2 for ; Tue, 04 Nov 2025 08:31:17 -0800 (PST) Received: from [192.168.10.48] ([151.95.110.222]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b7240348d93sm244436066b.68.2025.11.04.08.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 08:31:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762273880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mjIcfLdvLe3Kq7hGsddlUyAZz5HeU5g0QLiH7INvZwM=; b=PrMjQEK5MLrj5x1BnzEVvUKv1CrmtXJ7d2OJBJMlgkNwAE39s7rgRxjrpRb0Jt0gBEAgox RR3iAINt6UxRoa1jqL1wQhVD+0j4o7pXU5muczcijQ2gasP8NeZb6PK5GdXJCNjNIbf2va LYxZLZsde83XoriEF62wEEGEfN+97O0= X-MC-Unique: 0IR5SQRoPkq1-AYPv_DHhQ-1 X-Mimecast-MFC-AGG-ID: 0IR5SQRoPkq1-AYPv_DHhQ_1762273877 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762273876; x=1762878676; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mjIcfLdvLe3Kq7hGsddlUyAZz5HeU5g0QLiH7INvZwM=; b=m7wchAK5GLUJj14FE4Oe6Zk4zHd8HWguFjcTwrJCLM7rhqt9xg1qZo6qgj1RVKdVOO EHktAE8Z2ynPHhH95JMxAl1VYlkWvfDuV/ImIIjBIk1/kVkKOpJTPQ1iL90ecIyA60cd MzRF/MQ6ui0ozSpQp/ndfzIOuP84rBhsOznUARSsuyZUAAORx8RiQ+M/oq2Gp8h/aVVV 8jxGp2rdQCKibDM/7Hs1iIY97w/Z4nkOgJveGIMn7xakKCUHfWcxW8FWj738nw7+MO+A cBEtIeX16fEDENJYSN5bdqTaV1pGsRXh1tk+aezJqr5RZNKghp6v2Q6lCIuxhkYmCmpr cjkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762273876; x=1762878676; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mjIcfLdvLe3Kq7hGsddlUyAZz5HeU5g0QLiH7INvZwM=; b=lWYE+FD2UXQjzy0ZODe52qDs0GCzJ/YpNkAdHMDIaBEWxYgSd92Q0fLoLP1hAAQdrc 3a5zds7wFhFel2OLZrg7CUvsOAJg9uiML1GOhmnqlEVA7WIEaK8sdCDnFSbEtBYxn10c eLD+M2Iwxq2hou5lYpZ7rswDuOnC2i1GcfBEdFCwxJkQwF/gfBFFhDf/PaNgV+ifIl0b cQ3MIQ5PNuskIsz6PsGLu1J3O+IqEZNuy9eouxxURdIRL5gf46qZ/C2NbUNwMNI1jvxJ OM8oXNkg6F5C3NEFh/idc42/UbV4liese0IVqWDYA/1bDgSSKuGgXz4KC8D0Zbtfcvd2 rf4g== X-Gm-Message-State: AOJu0YyNc7+glzsrT/quTcKbmTgYGvtOBQy9bGW1U7upmXK9lDlrrYUq AAFSw9mtTBrehGVO69waHV2LTkGclRTB7zO508nKLbYS1xQ24hETF8bIZOpyrFayuzSNA1obE2v MZ2+nPG4zAuBzHoZJvgsYi3TFa2Z4VG4UQi/VXS64lZQWBis5atVM6/OyT31siKfNvZheu/vdZa RplAtJgylxzEyx6NVKbD1bdUIMzdRGEXNPM9UmEuC1 X-Gm-Gg: ASbGnctu1giWAiWLVhaDi7UAobUMQZMquwgi2r0ky3hfSn5HwnLrOdjFd30ZWHiFb9Z /nMRNEspch4NmheuVJneL+M0cbpeKwlL9OcAbnDTdQRnPAiSTFHLzCvlzMKc8PdWfdk2/CBoTNi x09yO4vbbbyYAA1l+98PVxumXVPWgPWuEmLVqLw3xNCnGApsSNDvN93/sm23FJ3TAHiDoF6SPSx L0CIpujKFHDLmtJUHdoV9ILUYq/o8KW+gjmm4J0qa2OK6TxtAlTKQnFOelsVN0JWIs2BBOICsSG Iav0cgYH0GM63/ljYctXZc/glUp/u0ZxmXkAukWFXWL/8yFTObmPF23syOuiCgM/pJ+PcA1R0k3 VyyHXFnD6r0lY00dB4GBxqhbsulvxDlv2B07hoM+TO+mjBe6q6HTm22Kfpdd1UALneSOdLySt9d ukMGcs X-Received: by 2002:a17:906:6a21:b0:b3c:bd91:28a4 with SMTP id a640c23a62f3a-b70701c77b9mr1674699166b.28.1762273876382; Tue, 04 Nov 2025 08:31:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLmBHtEgcUwSIVU7aW7EucrM39V4zDnnFiAIgwlGJchSXd82rTJV4No1ow5l8krtxVu36bSA== X-Received: by 2002:a17:906:6a21:b0:b3c:bd91:28a4 with SMTP id a640c23a62f3a-b70701c77b9mr1674694866b.28.1762273875739; Tue, 04 Nov 2025 08:31:15 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu Subject: [PULL 5/8] rust: pull error_fatal out of SysbusDeviceMethods::sysbus_realize Date: Tue, 4 Nov 2025 17:30:59 +0100 Message-ID: <20251104163102.738889-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251104163102.738889-1-pbonzini@redhat.com> References: <20251104163102.738889-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.788, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1762273982874154100 Content-Type: text/plain; charset="utf-8" Return a Result<()> from the method, and "unwrap" it into error_fatal in the caller. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 4 ++-- rust/hw/core/src/sysbus.rs | 13 ++++++------- rust/util/src/error.rs | 31 ++++++++++++++++++++++++++++++- rust/util/src/lib.rs | 2 +- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 5e9b13fdf92..04155dabe1a 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -17,7 +17,7 @@ }; use qom::{prelude::*, ObjectImpl, Owned, ParentField, ParentInit}; use system::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder= }; -use util::{log::Log, log_mask_ln}; +use util::{log::Log, log_mask_ln, ResultExt}; =20 use crate::registers::{self, Interrupt, RegisterOffset}; =20 @@ -697,7 +697,7 @@ pub fn post_load(&self, _version_id: u8) -> Result<(), = migration::InvalidError> let chr =3D unsafe { Owned::::from(&*chr) }; dev.prop_set_chr("chardev", &chr); } - dev.sysbus_realize(); + dev.sysbus_realize().unwrap_fatal(); dev.mmio_map(0, addr); dev.connect_irq(0, &irq); =20 diff --git a/rust/hw/core/src/sysbus.rs b/rust/hw/core/src/sysbus.rs index 282315fce99..68165e89295 100644 --- a/rust/hw/core/src/sysbus.rs +++ b/rust/hw/core/src/sysbus.rs @@ -4,12 +4,13 @@ =20 //! Bindings to access `sysbus` functionality from Rust. =20 -use std::{ffi::CStr, ptr::addr_of_mut}; +use std::ffi::CStr; =20 pub use bindings::SysBusDeviceClass; use common::Opaque; use qom::{prelude::*, Owned}; use system::MemoryRegion; +use util::{Error, Result}; =20 use crate::{ bindings, @@ -107,14 +108,12 @@ fn connect_irq(&self, id: u32, irq: &Owned)= { } } =20 - fn sysbus_realize(&self) { - // TODO: return an Error + fn sysbus_realize(&self) -> Result<()> { assert!(bql::is_locked()); unsafe { - bindings::sysbus_realize( - self.upcast().as_mut_ptr(), - addr_of_mut!(util::bindings::error_fatal), - ); + Error::with_errp(|errp| { + bindings::sysbus_realize(self.upcast().as_mut_ptr(), errp); + }) } } } diff --git a/rust/util/src/error.rs b/rust/util/src/error.rs index 346577e2e53..4edceff42f3 100644 --- a/rust/util/src/error.rs +++ b/rust/util/src/error.rs @@ -38,7 +38,8 @@ ffi::{c_char, c_int, c_void, CStr}, fmt::{self, Display}, ops::Deref, - panic, ptr, + panic, + ptr::{self, addr_of_mut}, }; =20 use foreign::{prelude::*, OwnedPointer}; @@ -231,6 +232,34 @@ pub unsafe fn with_errp T>(f: F) -> R } } =20 +/// Extension trait for `std::result::Result`, providing extra +/// methods when the error type can be converted into a QEMU +/// Error. +pub trait ResultExt { + /// The success type `T` in `Result`. + type OkType; + + /// Report a fatal error and exit QEMU, or return the success value. + /// Note that, unlike [`unwrap()`](std::result::Result::unwrap), this + /// is not an abort and can be used for user errors. + fn unwrap_fatal(self) -> Self::OkType; +} + +impl ResultExt for std::result::Result +where + Error: From, +{ + type OkType =3D T; + + fn unwrap_fatal(self) -> T { + // SAFETY: errp is valid + self.map_err(|err| unsafe { + Error::from(err).propagate(addr_of_mut!(bindings::error_fatal)) + }) + .unwrap() + } +} + impl FreeForeign for Error { type Foreign =3D bindings::Error; =20 diff --git a/rust/util/src/lib.rs b/rust/util/src/lib.rs index 16c89b95174..d14aa14ca77 100644 --- a/rust/util/src/lib.rs +++ b/rust/util/src/lib.rs @@ -6,4 +6,4 @@ pub mod module; pub mod timer; =20 -pub use error::{Error, Result}; +pub use error::{Error, Result, ResultExt}; --=20 2.51.1 From nobody Sun Nov 16 01:08:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762273977; cv=none; d=zohomail.com; s=zohoarc; b=Q1qzo1WFF1g5upIuBXVS2ne2KtJWZmg6tIsUSLpSbHZCE0ZcwaLgO2AOCiFv31TVw+vliNWDhjD/x+PI+/K10S02vFfgWKCyvTnp1t9k+w/ANKS7uk0/98J6RRtcwD415QqE7delwp1Nb3Ckm/b+CKJHefyHr2ZV6PobngfZ3UI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762273977; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DMqnHq9v41T505uDGP7K/juFTfDSG9AnMF+W/uZJiCk=; b=nGPiki0/4O5q3OIPVFAGQ22cKu9PojkB8Kb9wg8mKC1/EhclzE1vfzHFpXkgY7mg6zY0JpJvJZMC8Ka5S06eqfw3g1X7DBFKVmYciJpIdolvdbnOwFHdM3+RmWXmLIrCxapikEzPYPl8sRkkcn+xvZNV2jp5h4F59I2aX1VlXrY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762273977129339.24914487325316; Tue, 4 Nov 2025 08:32:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGJwq-0007ku-2A; Tue, 04 Nov 2025 11:31:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwR-0007dB-FN for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwN-00040T-4t for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:30 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-3Zo_9J8hM6u4w0GjFrtR4A-1; Tue, 04 Nov 2025 11:31:20 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-b721aa1dac9so402866b.0 for ; Tue, 04 Nov 2025 08:31:20 -0800 (PST) Received: from [192.168.10.48] ([151.95.110.222]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b723f6e26d1sm245777666b.35.2025.11.04.08.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 08:31:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762273882; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DMqnHq9v41T505uDGP7K/juFTfDSG9AnMF+W/uZJiCk=; b=TeyulT68JoKsUMfKj2Y+esvumWfaEL+nO6Va+RTyqsNobFqVwEfXCNkXqKvhOfJC2qmKQG lB66VCBmwAf+rGG6mwS49ghsrot2EAaKohWa19bWThlMrWE33prxzitOlgT5OZ1RjQdg15 i7p7FR30QuZru1qDfpG5WRDyvd5zRQw= X-MC-Unique: 3Zo_9J8hM6u4w0GjFrtR4A-1 X-Mimecast-MFC-AGG-ID: 3Zo_9J8hM6u4w0GjFrtR4A_1762273879 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762273879; x=1762878679; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DMqnHq9v41T505uDGP7K/juFTfDSG9AnMF+W/uZJiCk=; b=j5YO44Ryki//cCDo8JCdlMBTN7xvT8WqGrVnTaX0nAvJAw9jryH5zMsev2SAudox2m vapDfEfKXcIGyqTBFtaBioIhAHLXWX8SWn+/RadRlN4VYVDX/omr/4vR1f65MFXWYkWO f/V4z+NdpTn2OCxYNrvY7UGToRv8n/t54czAJlVudqNtH4SOfs9kmh62JIOE1u/HP6vQ Ec69hROTNAwM7NjrsO2OII0ivQepUwePZNWqVpN1raMDxHTdzk3ZyGiqhISXofsQosnp OW0VPnT5D5egtAD9p/GcphlWxId23Ek3oVOevTX/yctuvK0E9NZe56jarKsd4bEOFDdS 6fsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762273879; x=1762878679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DMqnHq9v41T505uDGP7K/juFTfDSG9AnMF+W/uZJiCk=; b=w33vXgTEYlVvzv4Qri91/TYflwsfemrsASTbTJzCKyXLlUDEO29lRZpA1UX26hjBU9 mEYOUpZ0hbmhdWOoycuNfITEjGSupGbsjIkAg/Ic6DARk94jRKdLd+ZH8VolazF60BFk VCUHQz0mK8MGl6Rnpnnc4cNI1nSsp0q4e4VH/PLSi9E3ME7f1wGquhGy3WJ1aDCSZpO7 jikMRfAkwjoFSC/bBQrsBmZdm/CUxiRTric3mz39CYxf8/9eIF/JKKgoN8PxN+JYA9X/ HvA37D+K4LKG/wP9OV1JYdU2JlNAMmgo15PmQos1KybYV0UR7vVfssnsEf2m44BNpPFr KUZA== X-Gm-Message-State: AOJu0YzFizqQiPmJma0kIPdfGutgcwS+qujriFYHlIUV05s7nnhyG1s9 /WbJrDUBerLAlqBNMDgX10Eon/TQ6YTbihjxeLSM0oR/nqJ5wdQrkLq4Wo89X5rZVAp7sItmGHK zK7wDBCmwfIZwYlX2m6N+fPrp0Ty04BcESR9aDfrWxCzS/vqo/R5hdhZOAMHj+NrgCAlCSAsSqQ gR2XqVQ8jNdrN2Ugw5T8ltvYsrw2ULyJC3yPWmPN7B X-Gm-Gg: ASbGncu0yr682Tm+RipyLB4faVR3KEepr+lEmIF4X5SYkywQZe6e71GzQ9mpfCOUWgl XziGRrj4wT4TVAjTwEDAGvSPOgLypx8/F8WB0Ih2XEat0LKC9dBmuLr4DZJoq0Z8xifE7Q86iv0 IonAbNttZLkBkC/RhudxGKLP0ghbThKw0gp2Bp5MmaIJ806OJGM9yKsEToQ4/yIRL7F3DMykOf8 bKWQ6K8p1nwUmppeIybRp00tttclcrC5QMz9+cyHIfrFe5S7ppb+/IT9d9JFIAcYoni6einCT7y 6GKxYDowvtCb9GYfU1dVnwtxYSg1Y83JXlH03vYvpM0P5PFBRZwvjej9T5oFWh7a/cyHzt5hXbO ApKZN7073eNxEZwXa7zNUWGDoahbHD7M/+HVn0Yp9hZqvP8PMX5fi2khsAaCDYjzuGfdNYPdR8/ psNnzj X-Received: by 2002:a17:907:6eac:b0:b72:6224:7e95 with SMTP id a640c23a62f3a-b7263023406mr23199266b.1.1762273878749; Tue, 04 Nov 2025 08:31:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEfw016HcquvKrYf/zzyMx9Rm4uJTB/FIZpL0vjHt2v+/2iYxu5o7Fvq5GZaugD11XJsYqoA== X-Received: by 2002:a17:907:6eac:b0:b72:6224:7e95 with SMTP id a640c23a62f3a-b7263023406mr23195966b.1.1762273878169; Tue, 04 Nov 2025 08:31:18 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 6/8] rust: do not add qemuutil to Rust crates Date: Tue, 4 Nov 2025 17:31:00 +0100 Message-ID: <20251104163102.738889-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251104163102.738889-1-pbonzini@redhat.com> References: <20251104163102.738889-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.788, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1762273978129158500 This fails due to https://github.com/mesonbuild/meson/pull/15076. The config-host.h file from the qemuutil dependency ends up on the rustc command line for targets that do not use structured sources. It will be reverted once Meson 1.9.2 is released. Reported-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Paolo Bonzini --- rust/chardev/meson.build | 2 +- rust/util/meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/chardev/meson.build b/rust/chardev/meson.build index d365d8dd0f4..36ada7c4546 100644 --- a/rust/chardev/meson.build +++ b/rust/chardev/meson.build @@ -39,4 +39,4 @@ _chardev_rs =3D static_library( dependencies: [glib_sys_rs, common_rs, qemu_macros], ) =20 -chardev_rs =3D declare_dependency(link_with: [_chardev_rs], dependencies: = [chardev, qemuutil]) +chardev_rs =3D declare_dependency(link_with: [_chardev_rs], dependencies: = [chardev]) diff --git a/rust/util/meson.build b/rust/util/meson.build index b0b75e93ff6..8ad344dccbd 100644 --- a/rust/util/meson.build +++ b/rust/util/meson.build @@ -43,7 +43,7 @@ _util_rs =3D static_library( dependencies: [anyhow_rs, libc_rs, foreign_rs, glib_sys_rs, common_rs, q= om, qemuutil], ) =20 -util_rs =3D declare_dependency(link_with: [_util_rs], dependencies: [qemuu= til, qom]) +util_rs =3D declare_dependency(link_with: [_util_rs]) =20 rust.test('rust-util-tests', _util_rs, dependencies: [qemuutil, qom], --=20 2.51.1 From nobody Sun Nov 16 01:08:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762273931; cv=none; d=zohomail.com; s=zohoarc; b=ePJ4wEq3R4dtQ5KJv6Q7opcEPeOcjaDJDMhyVHRuCcewJLKqcDbLfN/1k6YC5bAmJX+U1o5h8vfiDC/+vqW9r6gFNZxNZWSulTfFlFmrGhisNjhD71LZy6vq2tg5HASIn0VOR3v0GeZ6YjPE2zd+BsVwdoKrQ6DSKZnZksJQEa4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762273931; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=4SUUbBX2EZskEpcmcNIBAHfIqFByPha4S0DATWUq+gE=; b=TeP1b6rUsg44yWJTKStBbjudysS9Yb1eg7skwqVOor8P6kztiEyr8tzYFZuOW7bxKNO7QWif+rXuofr/MY1wA2dirkcCJGDu9eqgoobEkmv7i5Z++r1EfLF7+rTlfJoiAqpZyxB6q3pp8/2pGW+EaLR/ickazF9asrgumagNb3U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762273931878684.8401006562112; Tue, 4 Nov 2025 08:32:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGJwd-0007fi-Sy; Tue, 04 Nov 2025 11:31:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwR-0007d6-30 for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwN-00040y-4i for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:29 -0500 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-35qKT4lhPRq_gEbBXtKDZQ-1; Tue, 04 Nov 2025 11:31:23 -0500 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-64095177aedso4953828a12.2 for ; Tue, 04 Nov 2025 08:31:23 -0800 (PST) Received: from [192.168.10.48] ([151.95.110.222]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-640e6a5c773sm2421232a12.18.2025.11.04.08.31.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 08:31:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762273885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4SUUbBX2EZskEpcmcNIBAHfIqFByPha4S0DATWUq+gE=; b=dLP284nQMpsyxdJAYy6GpWlYLLptMtm3AlzDvMqUpDo46/gLA5jD38oD7Zno/uaIf6SQbt TD+Vs3t6GYpLr4xdA5sKE8KPR6dRg0L9FgJWfcLXhadphVlfmbfQVP6xj8TpflX6eRB02d k7QQWHo7IrHC2dBWVHrlmH9+7QTN1kY= X-MC-Unique: 35qKT4lhPRq_gEbBXtKDZQ-1 X-Mimecast-MFC-AGG-ID: 35qKT4lhPRq_gEbBXtKDZQ_1762273882 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762273882; x=1762878682; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4SUUbBX2EZskEpcmcNIBAHfIqFByPha4S0DATWUq+gE=; b=qMVFfPfVOTqh6/UYakzeIA2fQ+K1qXGYVbxwzlHgS3H5Vem4mAqZxn/g5smgr2IShl GYZxnDaXNCCDZpnBO9OFzM7MQbShz0a1D/OAKsg04Gh0Klb3ki4EkxmcBo+Xu2Ig3t4B lzRPcn0/PsdPpjgHbHzK96X8v+dTOz3Yxf/2OItQcBrXeDE/Tb1dpZQQo21zymf9IuH0 2/jhM3szmT4DGcSCzYqsMARyokwhAIg4cUgJzYc+0l4JGCvNOq8jrwvh59bwyH5eZxDY dAwxY9aAiLbdwkNDJw3O1g6PyNsvn2pRyDF7frUsAZqEbyqKn2v9pvId6zIa5PpEvLG0 CtvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762273882; x=1762878682; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4SUUbBX2EZskEpcmcNIBAHfIqFByPha4S0DATWUq+gE=; b=VIeBss5rivLC0NPUXvmB1Pkkhcdcp2lDr98VwCtR6MQnPwTHPQhxwy7qsfK8hCHaMv XJjAcGHO4RW9HhDusHxjVI8EU5O5Ug/mOXIbJQ5AtNmnjflO8aymIqsdTNZT7Vlt7Eik TOyfgFmD28NVui4WK0waBc//7rmFs3fYmV18O7/OIaFllntW2+dYnySlAA3bofxpfeRN X6movKIi/YMrfCs6IrEz+Vn7tzMvBYPLEdVPFY84+WnyMaH+s0gqoVxBSfZrqWgG5pvp yqFyQhhmeuvuAyStjrJm7hqLZRgEG7/R5fh6CFwPEYpbh+WLKGY0cedKgMRrlq+DBryb n29Q== X-Gm-Message-State: AOJu0YyfHNUunohnYXZSQwZ5hm7kcJjtdcMpSUOZW0GyUw7pKcTIoDyp mm9mqptgtAWIQz4WSBwiKDK1WFpOkQ9Ocn2agPXsEWjK7GLofAxCQnTbWK7CudZ2RI8mo7SgnAq iSq5nrdT+mFSlOnxCsfgB5ft3LXYpnhQGvOv02kQZaQXNu8FXVPWUPQyzP5oYRRlIt6Q4NXfw2d BGOyXuz99uVV2bgPSHP/v4zw9JhY4TWqxchlHBdxgU X-Gm-Gg: ASbGncu84zNcw47hOoLLepvZIMErLtlt8owNsi9+9DZYots6Ys4fc0BT9q6WyUndLl6 4YhdRHFoGjYAwL4B8415iIkaDrulKaBdXaUH3AfdZAzgQTLURRbaJ6fpXACJphCLCb41LEKFO6s 1X3BHmsLlp18o6/oWhSq1W0saz1pFlBjhwzAjn8di1QnNluzSwKOcDPwgGerotsLkODHoBL01sa 6FQfkLp98n14WvQ1ZRuW7vu6iPjLPrhi85cvgjQ2wN7k922xGJ7JAm0drMDwYzrs+m+po+gJaMq 3ib5kUlbuDZ9nKvV3mNPaNcKCzBwkO11hpbU6I1vDeL2XIW6lYSdl3sB9azeE6degpqlSkAqml2 4cI3urKWUgnGQa58TfSvpTO4emckoMprmUaRXZ2CE6YlqFal+4arSrvsyyEcQLOJDNhbyeQXwgG cmuR1R X-Received: by 2002:a05:6402:40ce:b0:640:96fe:c7b8 with SMTP id 4fb4d7f45d1cf-64096fecaaemr11152811a12.2.1762273881944; Tue, 04 Nov 2025 08:31:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFb0/fnCe/NNPopjB5fURIXwSmiNZihlIKKQblSgaMhB/C9jnmdXWwieqah52Y2xAE906GpmA== X-Received: by 2002:a05:6402:40ce:b0:640:96fe:c7b8 with SMTP id 4fb4d7f45d1cf-64096fecaaemr11152792a12.2.1762273881487; Tue, 04 Nov 2025 08:31:21 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 7/8] rust: migration: allow nested offset_of Date: Tue, 4 Nov 2025 17:31:01 +0100 Message-ID: <20251104163102.738889-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251104163102.738889-1-pbonzini@redhat.com> References: <20251104163102.738889-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.788, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1762273933198154101 Content-Type: text/plain; charset="utf-8" Nested offset_of was stabilized in Rust 1.82. Since the minimum supported version for QEMU is 1.83, allow nested field accesses in vmstate_of! Signed-off-by: Paolo Bonzini --- rust/migration/src/vmstate.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rust/migration/src/vmstate.rs b/rust/migration/src/vmstate.rs index 5a237c409ac..267f9c8e053 100644 --- a/rust/migration/src/vmstate.rs +++ b/rust/migration/src/vmstate.rs @@ -141,24 +141,24 @@ pub const fn vmstate_varray_flag(_: Phant= omData) -> VMStateFlags /// [`Owned`]: ../../qom/qom/struct.Owned.html #[macro_export] macro_rules! vmstate_of { - ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:exp= r)?])? $(, $test_fn:expr)? $(,)?) =3D> { + ($struct_name:ty, $($field_name:ident).+ $([0 .. $($num:ident).+ $(* $= factor:expr)?])? $(, $test_fn:expr)? $(,)?) =3D> { $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name), "\0") + name: ::core::concat!(::core::stringify!($($field_name).+), "\= 0") .as_bytes() .as_ptr().cast::<::std::os::raw::c_char>(), - offset: ::std::mem::offset_of!($struct_name, $field_name), - $(num_offset: ::std::mem::offset_of!($struct_name, $num),)? + offset: ::std::mem::offset_of!($struct_name, $($field_name).+), + $(num_offset: ::std::mem::offset_of!($struct_name, $($num).+),= )? $(field_exists: $crate::vmstate_exist_fn!($struct_name, $test_= fn),)? // The calls to `call_func_with_field!` are the magic that // computes most of the VMStateField from the type of the fiel= d. ..$crate::call_func_with_field!( $crate::vmstate::vmstate_base, $struct_name, - $field_name + $($field_name).+ )$(.with_varray_flag($crate::call_func_with_field!( $crate::vmstate::vmstate_varray_flag, $struct_name, - $num)) + $($num).+)) $(.with_varray_multiply($factor))?)? } }; --=20 2.51.1 From nobody Sun Nov 16 01:08:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762273956; cv=none; d=zohomail.com; s=zohoarc; b=EWICqqhCYejdNAxyhWJINB49+6DUzmlYIlI1JfsrMBnqboMeftZI0EWWrZK6V2hg98fOq3c2CNCzZUK/fiGhTrkSrTzSy1mWq5kgSVhgf3pthoTONlS5cfJa9wp5RURmBfC+uo5tL8qj/DfIcirhrEI9ekD3sadZzQuzH9Ovf0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762273956; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=R5wMIUgZnokbZXnXaaEogUQr5YE0GfAtHUj41UaNzyg=; b=i5OCktaMWg5Hk0RVqnCwVULvjhaqZTnqwyYDvk5g3qFqBnpV0MlODpSQQ+xg6Jr3VNfruv7VCyaBnaU1zH+c/WW/SeZlbOyBpauSnOV5Q7Vq0+3HE+zS+PNzVHvC9YFuHyCqH2kGDhGHNPRzlJon5loVVOHz/mTnY5UTiPaEMl4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762273956731199.9125484455111; Tue, 4 Nov 2025 08:32:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGJwm-0007gZ-76; Tue, 04 Nov 2025 11:31:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwU-0007eX-VK for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGJwQ-00041j-8i for qemu-devel@nongnu.org; Tue, 04 Nov 2025 11:31:32 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-360-Ge6hI_1bPkCtJg-xH3tIpw-1; Tue, 04 Nov 2025 11:31:25 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-b70c6ff2639so323534666b.3 for ; Tue, 04 Nov 2025 08:31:25 -0800 (PST) Received: from [192.168.10.48] ([151.95.110.222]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b723db0f1besm252182866b.31.2025.11.04.08.31.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 08:31:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762273887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R5wMIUgZnokbZXnXaaEogUQr5YE0GfAtHUj41UaNzyg=; b=VbR2njPf04EI+ItIvSmyHOy5yZGUHZ9BQfjCIMnTcovYeL9PUNW8Bfd0uy5F0iYw7oyPOt l2gNFLKl9KCXYZdWAFLTPFJbSXi4ope+UV3xNgjDiCh5VVdSTLD9GZvmifxKp3SzYcoWta 4eIliW6D7qU1FOHkVfy7iF+uAPOpGSQ= X-MC-Unique: Ge6hI_1bPkCtJg-xH3tIpw-1 X-Mimecast-MFC-AGG-ID: Ge6hI_1bPkCtJg-xH3tIpw_1762273884 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762273884; x=1762878684; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=R5wMIUgZnokbZXnXaaEogUQr5YE0GfAtHUj41UaNzyg=; b=Hzn+dK4csiYAsMpyy6dPdp2Bx/iGThsIeL3eqNZwXlTu57oEvSkkHAKWOniAb9nnMR YLPRj91lvNWO99JWAgBSSIatGnWWQRBXXSjpMi6iF6zp5dkwPCdZHsrYQakeOxdwWAQj Xsj7uT9R53X6O1/HEZrRA8YyWZqLmSKjzT4tdgaOEAFH7U3YNqrI8gkacL7tZBVbOG0v DjyOT19gljigZ5DpOLFkMTpz4hg2cWx504y8a1J/zmqnRSGmqDdHBxpCVGy1XfJn0HPx H26LAt870Vlh7Rkjle0d33GXpEJSTmw+BOGwcL4ZMW00a+rmFxn0wgZhOPrDIIufJL8L mKTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762273884; x=1762878684; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R5wMIUgZnokbZXnXaaEogUQr5YE0GfAtHUj41UaNzyg=; b=AVPK9AbtAFIqw0zrR5sybUE8lS1cMhLoHK6W5yUYT8j2/3K6rqorK72KnxH17FX02Z O99hvK9PQOlEjxW38+cexp3q+H9aBchtqICrNLINbksYRKDI115F57643bvBXr11hdtE LL/4TDGY5cLzeCThSLs6tm1IhZsveAfLZDc8+OBK0xWCwt2hvwrnShmuBR0nD9r7xEOF q8zctjHh4lLPRJWyt2mQ+TMrj15GQJOQY00Y52hQXt15OZ3zsipFjZdEkPhCWTLQQYmp qNdOy7gespDLmQcMwF6J6r3RrC9pYvxQJUsCJ8UHg5Jcvc9JY/g8FHX2nBLpSkaZ4iOl OQfw== X-Gm-Message-State: AOJu0YyUjU+16aZOun2oTyO8E82QACVTuxrGHb4WgFDh05vc+31Kp5WT WDhG/uA5/sEwSiJPHcQrP+f0MmfU4qLTe2zvTYnrKeVUoZbZYC0FEGwgA5gommRY7NpgIIbX3Pd zNvEOwXdl6bbFbHCLapar9CaSvfBZ8wl2Wp3qpNaUF9uxji988S8nCdkvjP4TY/YTK535UN0Fs5 VlfSjuI+q5ptdfNbFjnTVeY+kShRovjDNwiMr9BivC X-Gm-Gg: ASbGncv/O0Fus0XQdJfaNv6Trucg328sLJOcc6nvaT8T8kojHyl4bZY/5ubOlhWeakU yac3BenYQ0Iu4sIwSm6esAAcXAPxgs46loPos4LlnXQbSSYr1WOz5Zx/+M62p1AZkGxjZBY+8DG 1uDmKpH5EhiZ5Fcl3FrqARO6R5q5bAoixvo54bWOphcLdquYS6Ez9gIMcUfKHh+hDwqmci80o8u ZAXy/4iK3oSP1G5HJ4Y45wCu6s4T66K6wf3l9y+JBTbuntExir/Sm3V2HPtRM1foP4umolNfpeW ii03+5DVfvmHJ7qv5WnzVDm0v7sty+qdnaP00Bukv6yxtiXI346hVOl2wWVwu3KLYPujFbwdbdQ 8Z5IkviRyed3CAUHv/VQdOOqBhqp2KxSnesdgpECNHVC/ZicfjIsqhHGMdUnwpl/ZuG+2iGeqNk 2GnWAl X-Received: by 2002:a17:907:c0f:b0:b70:bbea:79e3 with SMTP id a640c23a62f3a-b70bbea7aa0mr730443166b.65.1762273883970; Tue, 04 Nov 2025 08:31:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsDNn2Q+R8BgUcyfDR6U7DNYeVSyDqStQpAuPJSKtdx+uAxBG8Xv2DkFYw2nqL0wggM6MLVQ== X-Received: by 2002:a17:907:c0f:b0:b70:bbea:79e3 with SMTP id a640c23a62f3a-b70bbea7aa0mr730439266b.65.1762273883311; Tue, 04 Nov 2025 08:31:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 8/8] rust: add back to Ubuntu 22.04 jobs Date: Tue, 4 Nov 2025 17:31:02 +0100 Message-ID: <20251104163102.738889-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251104163102.738889-1-pbonzini@redhat.com> References: <20251104163102.738889-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.788, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1762273962061158500 Content-Type: text/plain; charset="utf-8" Ubuntu is now including updated versions of Rust (up to 1.85) for its LTS releases. Adjust the CI containers and re-add --enable-rust to the Ubuntu jobs. Signed-off-by: Paolo Bonzini --- docs/about/build-platforms.rst | 10 +++++----- .gitlab-ci.d/buildtest.yml | 2 +- scripts/ci/setup/ubuntu/ubuntu-2404-aarch64.yaml | 2 +- scripts/ci/setup/ubuntu/ubuntu-2404-s390x.yaml | 2 +- tests/docker/dockerfiles/ubuntu2204.docker | 6 +++--- tests/lcitool/mappings.yml | 4 ++-- tests/lcitool/refresh | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/about/build-platforms.rst b/docs/about/build-platforms.rst index fc2743658d4..e95784cdb55 100644 --- a/docs/about/build-platforms.rst +++ b/docs/about/build-platforms.rst @@ -117,14 +117,14 @@ Rust build dependencies a newer version using ``cargo install bindgen-cli``. =20 QEMU requires Rust 1.83.0. This is available on all supported platforms - with two exception: Ubuntu LTS releases 22.04 and 24.04, and the - ``mips64el`` architecture on Debian bookworm. For all other + except for the ``mips64el`` architecture on Debian bookworm. For all ot= her architectures, Debian bookworm provides a new-enough Rust compiler in the ``rustc-web`` package. =20 - It is expected that in the future Ubuntu will provide updated packages - like the existing ``rustc-1.82`` package. The path to ``rustc`` and - ``rustdoc`` will have to be provided manually to the configure script. + For Ubuntu 22.04 ("Jammy") and 24.04 ("Noble") updated versions of + Rust are available through packages such as ``rustc-1.83`` package; + the path to ``rustc`` and ``rustdoc`` has to be provided manually to + the configure script. =20 Some distros prefer to avoid vendored crate sources, and instead use local sources from e.g. ``/usr/share/cargo/registry``. QEMU includes a diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index 21f6d7e96fe..44df116139b 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -39,7 +39,7 @@ build-system-ubuntu: - job: amd64-ubuntu2204-container variables: IMAGE: ubuntu2204 - CONFIGURE_ARGS: --enable-docs + CONFIGURE_ARGS: --enable-docs --enable-rust TARGETS: alpha-softmmu microblazeel-softmmu mips64el-softmmu MAKE_CHECK_ARGS: check-build =20 diff --git a/scripts/ci/setup/ubuntu/ubuntu-2404-aarch64.yaml b/scripts/ci/= setup/ubuntu/ubuntu-2404-aarch64.yaml index 70063db198e..d303411391f 100644 --- a/scripts/ci/setup/ubuntu/ubuntu-2404-aarch64.yaml +++ b/scripts/ci/setup/ubuntu/ubuntu-2404-aarch64.yaml @@ -119,7 +119,7 @@ packages: - python3-wheel - python3-yaml - rpm2cpio - - rustc-1.77 + - rustc-1.83 - sed - socat - sparse diff --git a/scripts/ci/setup/ubuntu/ubuntu-2404-s390x.yaml b/scripts/ci/se= tup/ubuntu/ubuntu-2404-s390x.yaml index 4f1a49be34a..4ee8630cc43 100644 --- a/scripts/ci/setup/ubuntu/ubuntu-2404-s390x.yaml +++ b/scripts/ci/setup/ubuntu/ubuntu-2404-s390x.yaml @@ -117,7 +117,7 @@ packages: - python3-wheel - python3-yaml - rpm2cpio - - rustc-1.77 + - rustc-1.83 - sed - socat - sparse diff --git a/tests/docker/dockerfiles/ubuntu2204.docker b/tests/docker/dock= erfiles/ubuntu2204.docker index b393db55a8c..602d4196249 100644 --- a/tests/docker/dockerfiles/ubuntu2204.docker +++ b/tests/docker/dockerfiles/ubuntu2204.docker @@ -124,7 +124,7 @@ RUN export DEBIAN_FRONTEND=3Dnoninteractive && \ python3-wheel \ python3-yaml \ rpm2cpio \ - rustc-1.77 \ + rustc-1.83 \ sed \ socat \ sparse \ @@ -155,8 +155,8 @@ ENV LANG "en_US.UTF-8" ENV MAKE "/usr/bin/make" ENV NINJA "/usr/bin/ninja" ENV PYTHON "/usr/bin/python3" -ENV RUSTC=3D/usr/bin/rustc-1.77 -ENV RUSTDOC=3D/usr/bin/rustdoc-1.77 +ENV RUSTC=3D/usr/bin/rustc-1.83 +ENV RUSTDOC=3D/usr/bin/rustdoc-1.83 ENV CARGO_HOME=3D/usr/local/cargo ENV PATH=3D$CARGO_HOME/bin:$PATH RUN DEBIAN_FRONTEND=3Dnoninteractive eatmydata \ diff --git a/tests/lcitool/mappings.yml b/tests/lcitool/mappings.yml index 8f0e95e1c56..a749cf8c515 100644 --- a/tests/lcitool/mappings.yml +++ b/tests/lcitool/mappings.yml @@ -70,8 +70,8 @@ mappings: =20 rust: Debian12: rustc-web - Ubuntu2204: rustc-1.77 - Ubuntu2404: rustc-1.77 + Ubuntu2204: rustc-1.83 + Ubuntu2404: rustc-1.83 =20 pypi_mappings: # Request more recent version diff --git a/tests/lcitool/refresh b/tests/lcitool/refresh index 7fbdf6f340b..df186caffe6 100755 --- a/tests/lcitool/refresh +++ b/tests/lcitool/refresh @@ -152,8 +152,8 @@ fedora_rustup_nightly_extras =3D [ ] =20 ubuntu2204_rust_extras =3D [ - "ENV RUSTC=3D/usr/bin/rustc-1.77\n", - "ENV RUSTDOC=3D/usr/bin/rustdoc-1.77\n", + "ENV RUSTC=3D/usr/bin/rustc-1.83\n", + "ENV RUSTDOC=3D/usr/bin/rustdoc-1.83\n", "ENV CARGO_HOME=3D/usr/local/cargo\n", 'ENV PATH=3D$CARGO_HOME/bin:$PATH\n', "RUN DEBIAN_FRONTEND=3Dnoninteractive eatmydata \\\n", --=20 2.51.1