From nobody Wed May 14 12:20:37 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1737988126033669.4868735030714; Mon, 27 Jan 2025 06:28:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces@nongnu.org>) id 1tcQ2e-0003SJ-0D; Mon, 27 Jan 2025 09:24: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 <mjt@tls.msk.ru>) id 1tcQ2a-0002u9-7o; Mon, 27 Jan 2025 09:24:40 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <mjt@tls.msk.ru>) id 1tcQ2Y-00030u-76; Mon, 27 Jan 2025 09:24:39 -0500 Received: from localhost.tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by isrv.corpit.ru (Postfix) with ESMTP id 3D8F4E0F6E; Mon, 27 Jan 2025 17:24:11 +0300 (MSK) Received: by localhost.tls.msk.ru (Postfix, from userid 1000) id 85C1051D89; Mon, 27 Jan 2025 17:18:03 +0300 (MSK) From: Michael Tokarev <mjt@tls.msk.ru> To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Fabiano Rosas <farosas@suse.de>, Peter Xu <peterx@redhat.com>, Michael Tokarev <mjt@tls.msk.ru> Subject: [Stable-9.2.1 18/41] migration: Add more error handling to analyze-migration.py Date: Mon, 27 Jan 2025 17:17:32 +0300 Message-Id: <20250127141803.3514882-18-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: <qemu-stable-9.2.1-20250127154029@cover.tls.msk.ru> References: <qemu-stable-9.2.1-20250127154029@cover.tls.msk.ru> 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=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1737988127660019000 Content-Type: text/plain; charset="utf-8" From: Fabiano Rosas <farosas@suse.de> The analyze-migration script was seen failing in s390x in misterious ways. It seems we're reaching the VMSDFieldStruct constructor without any fields, which would indicate an empty .subsection entry, a VMSTATE_STRUCT with no fields or a vmsd with no fields. We don't have any of those, at least not without the unmigratable flag set, so this should never happen. Add some debug statements so that we can see what's going on the next time the issue happens. Reviewed-by: Peter Xu <peterx@redhat.com> Message-Id: <20250109185249.23952-2-farosas@suse.de> Signed-off-by: Fabiano Rosas <farosas@suse.de> (cherry picked from commit 86bee9e0c761a3d0e67c43b44001fd752f894cb0) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py index 8a254a5b6a..f2457b1dde 100755 --- a/scripts/analyze-migration.py +++ b/scripts/analyze-migration.py @@ -429,6 +429,9 @@ def __init__(self, desc, file): super(VMSDFieldStruct, self).__init__(desc, file) self.data =3D collections.OrderedDict() =20 + if 'fields' not in self.desc['struct']: + raise Exception("No fields in struct. VMSD:\n%s" % self.desc) + # When we see compressed array elements, unfold them here new_fields =3D [] for field in self.desc['struct']['fields']: @@ -477,6 +480,10 @@ def read(self): raise Exception("Subsection %s not found at offset %x"= % ( subsection['vmsd_name'], self.file.tell())) name =3D self.file.readstr() version_id =3D self.file.read32() + + if not subsection: + raise Exception("Empty description for subsection: %s"= % name) + self.data[name] =3D VMSDSection(self.file, version_id, sub= section, (name, 0)) self.data[name].read() =20 @@ -574,10 +581,13 @@ def __init__(self, filename): } self.filename =3D filename self.vmsd_desc =3D None + self.vmsd_json =3D "" =20 - def read(self, desc_only =3D False, dump_memory =3D False, write_memor= y =3D False): + def read(self, desc_only =3D False, dump_memory =3D False, + write_memory =3D False): # Read in the whole file file =3D MigrationFile(self.filename) + self.vmsd_json =3D file.read_migration_debug_json() =20 # File magic data =3D file.read32() @@ -635,9 +645,11 @@ def read(self, desc_only =3D False, dump_memory =3D Fa= lse, write_memory =3D False): file.close() =20 def load_vmsd_json(self, file): - vmsd_json =3D file.read_migration_debug_json() - self.vmsd_desc =3D json.loads(vmsd_json, object_pairs_hook=3Dcolle= ctions.OrderedDict) + self.vmsd_desc =3D json.loads(self.vmsd_json, + object_pairs_hook=3Dcollections.Ordere= dDict) for device in self.vmsd_desc['devices']: + if 'fields' not in device: + raise Exception("vmstate for device %s has no fields" % de= vice['name']) key =3D (device['name'], device['instance_id']) value =3D ( VMSDSection, device ) self.section_classes[key] =3D value @@ -666,31 +678,34 @@ def default(self, o): =20 jsonenc =3D JSONEncoder(indent=3D4, separators=3D(',', ': ')) =20 -if args.extract: - dump =3D MigrationDump(args.file) +if not any([args.extract, args.dump =3D=3D "state", args.dump =3D=3D "desc= "]): + raise Exception("Please specify either -x, -d state or -d desc") =20 - dump.read(desc_only =3D True) - print("desc.json") - f =3D open("desc.json", "w") - f.truncate() - f.write(jsonenc.encode(dump.vmsd_desc)) - f.close() - - dump.read(write_memory =3D True) - dict =3D dump.getDict() - print("state.json") - f =3D open("state.json", "w") - f.truncate() - f.write(jsonenc.encode(dict)) - f.close() -elif args.dump =3D=3D "state": - dump =3D MigrationDump(args.file) - dump.read(dump_memory =3D args.memory) - dict =3D dump.getDict() - print(jsonenc.encode(dict)) -elif args.dump =3D=3D "desc": +try: dump =3D MigrationDump(args.file) - dump.read(desc_only =3D True) - print(jsonenc.encode(dump.vmsd_desc)) -else: - raise Exception("Please specify either -x, -d state or -d desc") + + if args.extract: + dump.read(desc_only =3D True) + + print("desc.json") + f =3D open("desc.json", "w") + f.truncate() + f.write(jsonenc.encode(dump.vmsd_desc)) + f.close() + + dump.read(write_memory =3D True) + dict =3D dump.getDict() + print("state.json") + f =3D open("state.json", "w") + f.truncate() + f.write(jsonenc.encode(dict)) + f.close() + elif args.dump =3D=3D "state": + dump.read(dump_memory =3D args.memory) + dict =3D dump.getDict() + print(jsonenc.encode(dict)) + elif args.dump =3D=3D "desc": + dump.read(desc_only =3D True) + print(jsonenc.encode(dump.vmsd_desc)) +except Exception: + raise Exception("Full JSON dump:\n%s", dump.vmsd_json) --=20 2.39.5