From nobody Mon Feb 9 19:05:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605617797; cv=none; d=zohomail.com; s=zohoarc; b=aHexvoEVgkZ/LkhA/VkfRbodMXQ+a0Pt1Q0aFqF8aLJmTNSEv6gXUarQ+gbPdUcUGtB+E4Uas4wqBllu2Jqz6hyTUoPxTmLaRyGdixeNt5X96D/L1+c1Ng/cqhMaG3EiUnwqKgdAjuLD/hUYrpQD3PfcHe8utpK1CYyXPhx/Qf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605617797; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xXPEfz8haGq163NwmbyKxxmwTZ1GPxdTv7rubnP96Bg=; b=AxkDvDJYhUtNEk55D3c6Bf4f3caGcKo4DhwSWupN2oxBUQObKCYLfKaMiNpY7OK3GQOlLocdYRHVvRKQP3QecgI56gWgRDt9WcUbjhnnDgpqfGx8ibaXdA9DEzB/Fct+LykBqnORdrY7LpnA0FjMqh72mJ7VxuYRzP8w7UsM6x8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605617797075432.27701314962303; Tue, 17 Nov 2020 04:56:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-OPnSLxN1OlW3rvLy0abB6A-1; Tue, 17 Nov 2020 07:56:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 779888030C8; Tue, 17 Nov 2020 12:56:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A3845C1D7; Tue, 17 Nov 2020 12:56:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D5DCF5813E; Tue, 17 Nov 2020 12:56:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AHCuKgL004684 for ; Tue, 17 Nov 2020 07:56:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id E72F75C1D7; Tue, 17 Nov 2020 12:56:20 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-10.ams2.redhat.com [10.36.115.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E9445C1CF; Tue, 17 Nov 2020 12:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605617795; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xXPEfz8haGq163NwmbyKxxmwTZ1GPxdTv7rubnP96Bg=; b=Bm7/nLQfIBNCupoOU/TKhOHR1RKCueooBOygdp7BOD6U4HjbOM/bBy2nIeeUz3fj083j5I ciNDlq9/JRbmFPp1eASV8ku4u5L2q7RUCwAMTdy63o4DnkEmMQbSDkjMupe2sILlPJ7AID Q5awuVWUZKo4UtZcEWPuhtIfCo02C/Y= X-MC-Unique: OPnSLxN1OlW3rvLy0abB6A-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/4] nodedev: dont rely on ignoring errors on missing properties Date: Tue, 17 Nov 2020 12:56:06 +0000 Message-Id: <20201117125608.177278-3-berrange@redhat.com> In-Reply-To: <20201117125608.177278-1-berrange@redhat.com> References: <20201117125608.177278-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) The udevProcessStorage method relies on udevGetIntProperty ignoring errors about non-existant properties and instead setting the value to zero. In theory when seeing ID_CDROM=3D1, you might expect that devices which are not CDs will get ID_CDROM=3D0, but that's not what happens in practice. Instead the property simply won't get set at all. IOW, the code does not need to care about the value of the property, merely whether it exists or not. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/node_device/node_device_udev.c | 35 ++++++------------------------ 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index b1b1886c54..e48e62dab8 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -962,37 +962,16 @@ udevProcessStorage(struct udev_device *device, =20 if (!storage->drive_type || STREQ(def->caps->data.storage.drive_type, "generic")) { - int val =3D 0; - const char *str =3D NULL; - /* All floppy drives have the ID_DRIVE_FLOPPY prop. This is * needed since legacy floppies don't have a drive_type */ - if (udevGetIntProperty(device, "ID_DRIVE_FLOPPY", &val, 0) < 0) + if (udevHasDeviceProperty(device, "ID_DRIVE_FLOPPY")) + storage->drive_type =3D g_strdup("floppy"); + else if (udevHasDeviceProperty(device, "ID_CDROM")) + storage->drive_type =3D g_strdup("cd"); + else if (udevHasDeviceProperty(device, "ID_DRIVE_FLASH_SD")) + storage->drive_type =3D g_strdup("sd"); + else if (udevKludgeStorageType(def) !=3D 0) goto cleanup; - else if (val =3D=3D 1) - str =3D "floppy"; - - if (!str) { - if (udevGetIntProperty(device, "ID_CDROM", &val, 0) < 0) - goto cleanup; - else if (val =3D=3D 1) - str =3D "cd"; - } - - if (!str) { - if (udevGetIntProperty(device, "ID_DRIVE_FLASH_SD", &val, 0) <= 0) - goto cleanup; - if (val =3D=3D 1) - str =3D "sd"; - } - - if (str) { - storage->drive_type =3D g_strdup(str); - } else { - /* If udev doesn't have it, perhaps we can guess it. */ - if (udevKludgeStorageType(def) !=3D 0) - goto cleanup; - } } =20 if (STREQ(def->caps->data.storage.drive_type, "cd")) { --=20 2.28.0