From nobody Tue Sep 9 03:16:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1738081779254768.4066415298263; Tue, 28 Jan 2025 08:29:39 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id AB90F1794; Tue, 28 Jan 2025 11:29:38 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1A17D1B39; Tue, 28 Jan 2025 11:28:35 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3E9C91645; Tue, 28 Jan 2025 11:28:28 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id BF6A51794 for ; Tue, 28 Jan 2025 11:28:27 -0500 (EST) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-6-2syzjg62OTSLzJUbaCl1Xg-1; Tue, 28 Jan 2025 11:28:24 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B67E41956059 for ; Tue, 28 Jan 2025 16:28:23 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.2]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E659D19560AA for ; Tue, 28 Jan 2025 16:28:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738081706; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fYTwxF3P8XOt4+l7wPvGTj+iC1iEJlZRqoSbQJj1ZVk=; b=FM1a4xN+vfIDwRTiElW5Jd3MA631OFbnF6YLkvnfW21/SorCrJ+m65KJuhwe+sBxEV6SSr Y97fuTrWPKq3XpKr609cmFMRgS8rlXNPc3/YQYkYwYiPJvhGRtRspCTq4FsIC7BeF7RVGi CDilPtmdeSamoqV0tuW7a1AsVzQ7Q+A= X-MC-Unique: 2syzjg62OTSLzJUbaCl1Xg-1 X-Mimecast-MFC-AGG-ID: 2syzjg62OTSLzJUbaCl1Xg From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH v2 01/15] qemu: Handle quirks of 'device' field of BLOCK_IO_ERROR event in monitor code Date: Tue, 28 Jan 2025 17:28:05 +0100 Message-ID: <98dcfc71adae75ff59f9086bd7b8eef0279c900d.1738081457.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: GBm716flFCttZfCjz5qUIv64c_kWyXhXQRGb6q4mShY_1738081703 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KKOCIBUUOMRZXPU4ZGCZAP6U3BBBL7WI X-Message-ID-Hash: KKOCIBUUOMRZXPU4ZGCZAP6U3BBBL7WI X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1738081779827019000 Content-Type: text/plain; charset="utf-8" BLOCK_IO_ERROR's 'device' field is an empty string in case when it isn't applicable as it was originally mandatory in the qemu API docs. Move the logic that convert's empty string back to NULL from 'qemuProcessHandleIOError()' to 'qemuMonitorJSONHandleIOError()' This also fixes a hypothetical NULL-dereference if qemu would indeed report an IO error without the 'device' field present. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_monitor_json.c | 9 ++++++++- src/qemu/qemu_process.c | 3 --- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 9f417d27c6..5ca76d2d80 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -708,8 +708,15 @@ qemuMonitorJSONHandleIOError(qemuMonitor *mon, virJSON= Value *data) action =3D "ignore"; } - if ((device =3D virJSONValueObjectGetString(data, "device")) =3D=3D NU= LL) + if ((device =3D virJSONValueObjectGetString(data, "device")) =3D=3D NU= LL) { VIR_WARN("missing device in disk io error event"); + } else { + /* 'device' was documented as mandatory in the qemu event, but lat= er became + * optional, in which case an empty string is sent by qemu. Conver= t it back + * to NULL */ + if (*device =3D=3D '\0') + device =3D NULL; + } nodename =3D virJSONValueObjectGetString(data, "node-name"); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 34a755a49a..edcd8ac3a8 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -840,9 +840,6 @@ qemuProcessHandleIOError(qemuMonitor *mon G_GNUC_UNUSED, virObjectLock(vm); priv =3D QEMU_DOMAIN_PRIVATE(vm); - if (*diskAlias =3D=3D '\0') - diskAlias =3D NULL; - if (diskAlias) disk =3D qemuProcessFindDomainDiskByAliasOrQOM(vm, diskAlias, NULL= ); else if (nodename) --=20 2.48.1