From nobody Sat Feb 7 22:11:41 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) 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 1715011179504398.84014767444467; Mon, 6 May 2024 08:59:39 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3D6791C76; Mon, 6 May 2024 11:59:38 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 902F61B7F; Mon, 6 May 2024 11:58:49 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A73291B7F; Mon, 6 May 2024 11:58:47 -0400 (EDT) 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 0C5951B6C for ; Mon, 6 May 2024 11:58:47 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-34vRYRHUMsuBg8zlUNulcQ-1; Mon, 06 May 2024 11:58:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 21DE13C02B4A for ; Mon, 6 May 2024 15:58:44 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89E6FEC688 for ; Mon, 6 May 2024 15:58:43 +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.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 34vRYRHUMsuBg8zlUNulcQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/2] interface_udev: Replace udevNumOfInterfacesByStatus by udevListInterfacesByStatus Date: Mon, 6 May 2024 17:58:40 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 5OJBKEQ4QWWJYATCKVENMYOI22Z3PBDQ X-Message-ID-Hash: 5OJBKEQ4QWWJYATCKVENMYOI22Z3PBDQ 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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1715011180794100001 Make the array-filling operation of udevListInterfacesByStatus optional and replace the completely redundant udevNumOfInterfacesByStatus by it. Further patches fixing the listing will not need to be duplicated. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/interface/interface_backend_udev.c | 76 ++++++++------------------ 1 file changed, 22 insertions(+), 54 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index 4091483060..826f486049 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -137,55 +137,21 @@ udevGetDevices(struct udev *udev, virUdevStatus statu= s) return enumerate; } -static int -udevNumOfInterfacesByStatus(virConnectPtr conn, virUdevStatus status, - virInterfaceObjListFilter filter) -{ - struct udev *udev =3D udev_ref(driver->udev); - struct udev_enumerate *enumerate =3D NULL; - struct udev_list_entry *devices; - struct udev_list_entry *dev_entry; - int count =3D 0; - - enumerate =3D udevGetDevices(udev, status); - - if (!enumerate) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to get number of %1$s interfaces on host"= ), - virUdevStatusString(status)); - count =3D -1; - goto cleanup; - } - - /* Do the scan to load up the enumeration */ - udev_enumerate_scan_devices(enumerate); - - /* Get a list we can walk */ - devices =3D udev_enumerate_get_list_entry(enumerate); - - /* For each item so we can count */ - udev_list_entry_foreach(dev_entry, devices) { - struct udev_device *dev; - const char *path; - g_autoptr(virInterfaceDef) def =3D NULL; - - path =3D udev_list_entry_get_name(dev_entry); - dev =3D udev_device_new_from_syspath(udev, path); - - def =3D udevGetMinimalDefForDevice(dev); - if (filter(conn, def)) - count++; - udev_device_unref(dev); - } - - cleanup: - if (enumerate) - udev_enumerate_unref(enumerate); - udev_unref(udev); - - return count; -} +/** + * udevListInterfacesByStatus: + * + * @conn: connection object + * @names: optional pointer to array to be filled with interface names + * @names_len: size of @names + * @status: status of interfaces to be listed + * @filter: ACL filter function + * + * Lists interfaces with status matching @status filling them into @names = (if + * non-NULL) and returns the number of such interfaces. + * + * In case of an error -1 is returned and no interfaces are filled into @n= ames. + */ static int udevListInterfacesByStatus(virConnectPtr conn, char **const names, @@ -222,7 +188,7 @@ udevListInterfacesByStatus(virConnectPtr conn, g_autoptr(virInterfaceDef) def =3D NULL; /* Ensure we won't exceed the size of our array */ - if (count >=3D names_len) + if (names && count >=3D names_len) break; path =3D udev_list_entry_get_name(dev_entry); @@ -230,7 +196,8 @@ udevListInterfacesByStatus(virConnectPtr conn, def =3D udevGetMinimalDefForDevice(dev); if (filter(conn, def)) { - names[count] =3D g_strdup(udev_device_get_sysname(dev)); + if (names) + names[count] =3D g_strdup(udev_device_get_sysname(dev)); count++; } udev_device_unref(dev); @@ -242,14 +209,15 @@ udevListInterfacesByStatus(virConnectPtr conn, return count; } + static int udevConnectNumOfInterfaces(virConnectPtr conn) { if (virConnectNumOfInterfacesEnsureACL(conn) < 0) return -1; - return udevNumOfInterfacesByStatus(conn, VIR_UDEV_IFACE_ACTIVE, - virConnectNumOfInterfacesCheckACL); + return udevListInterfacesByStatus(conn, NULL, 0, VIR_UDEV_IFACE_ACTIVE, + virConnectNumOfInterfacesCheckACL); } static int @@ -271,8 +239,8 @@ udevConnectNumOfDefinedInterfaces(virConnectPtr conn) if (virConnectNumOfDefinedInterfacesEnsureACL(conn) < 0) return -1; - return udevNumOfInterfacesByStatus(conn, VIR_UDEV_IFACE_INACTIVE, - virConnectNumOfDefinedInterfacesChe= ckACL); + return udevListInterfacesByStatus(conn, NULL, 0, VIR_UDEV_IFACE_INACTI= VE, + virConnectNumOfDefinedInterfacesChec= kACL); } static int --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Sat Feb 7 22:11:41 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) 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 1715011216064790.5585482717757; Mon, 6 May 2024 09:00:16 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 043F91DB5; Mon, 6 May 2024 12:00:15 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 153BA1B8C; Mon, 6 May 2024 11:58:57 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1D6C41B6C; Mon, 6 May 2024 11:58:48 -0400 (EDT) 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 602E31B77 for ; Mon, 6 May 2024 11:58:47 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-h77R0zigN2eVX9Zia-7FQA-1; Mon, 06 May 2024 11:58:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 19128834FBE for ; Mon, 6 May 2024 15:58:45 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AA06EC6A0 for ; Mon, 6 May 2024 15:58:44 +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.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: h77R0zigN2eVX9Zia-7FQA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 2/2] udevListInterfacesByStatus: Don't try to return NULL names Date: Mon, 6 May 2024 17:58:41 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: WRE6ZQINK3I6A2S23PUYRAAAYQSDD2GK X-Message-ID-Hash: WRE6ZQINK3I6A2S23PUYRAAAYQSDD2GK 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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1715011216926100001 In case when the interface is being detached/reattached it may happen that udev will return NULL from 'udev_device_get_sysname()'. As the RPC code requires nonnull strings in the return array it fails to serialize such reply: libvirt: XML-RPC error : Unable to encode message payload Fix this by simply ignoring such interfaces as there's nothing we can report in such case. A similar fix was done to 'udevConnectListAllInterfaces' in commit 2ca94317ac6. Resolves: https://issues.redhat.com/browse/RHEL-34615 Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/interface/interface_backend_udev.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index 826f486049..8bb19d7764 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -185,6 +185,7 @@ udevListInterfacesByStatus(virConnectPtr conn, udev_list_entry_foreach(dev_entry, devices) { struct udev_device *dev; const char *path; + const char *name; g_autoptr(virInterfaceDef) def =3D NULL; /* Ensure we won't exceed the size of our array */ @@ -194,10 +195,17 @@ udevListInterfacesByStatus(virConnectPtr conn, path =3D udev_list_entry_get_name(dev_entry); dev =3D udev_device_new_from_syspath(udev, path); + if (!(name =3D udev_device_get_sysname(dev))) { + /* Name can be NULL in case when the interface is being unbound + * from the driver. The list API requires names to be present = */ + VIR_DEBUG("Skipping interface '%s', name =3D=3D NULL", path); + continue; + } + def =3D udevGetMinimalDefForDevice(dev); if (filter(conn, def)) { if (names) - names[count] =3D g_strdup(udev_device_get_sysname(dev)); + names[count] =3D g_strdup(name); count++; } udev_device_unref(dev); --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org