From nobody Sun Feb 8 15:01:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618329453; cv=none; d=zohomail.com; s=zohoarc; b=Mpi61+MzP8nVleUS2hNkCDauxaDJ32DKCAOFe/8ea7vY4OCK+32AvZWyv/HopZ9qBTWCS4USNvKJ/bxevO1ZBl3eHU/fUSCb/R1OBXjDMCJITmyGT7RG2nqwR2t1yOzSZvBm5Ysr8TYsRAaMB9rhwy9V5tytkK8JHXrMd2GYFhc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618329453; 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=u7+IrVvQfjO+OGatlaK+TGyV6+qpSeEWo6T9E6B2Obc=; b=FsdL65P+nsVCD4jTYMxiwG+L7buHtuD3nDya0h3tCOL5raHrPJ/+d4FLcsMfNxCsZ9RjfSo8fTEkbLFcFzT/dbOC68HO/dh2twHgELdhln4w5+dssN+h49F0F9f5lqJZL8tRVLqb7Vb7gUZZnzLNDwFgBmPLJksHwE0oOK0PSr0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618329453667428.98156218360157; Tue, 13 Apr 2021 08:57:33 -0700 (PDT) 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-563-ZdrpYeeWPLyOyFhnfKJlSg-1; Tue, 13 Apr 2021 11:57:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7DB287A83B; Tue, 13 Apr 2021 15:57:23 +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 A96BA5D768; Tue, 13 Apr 2021 15:57:23 +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 6653F44A5E; Tue, 13 Apr 2021 15:57:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13DFvLAF014712 for ; Tue, 13 Apr 2021 11:57:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 97C2A39A60; Tue, 13 Apr 2021 15:57:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.221]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C82D59456 for ; Tue, 13 Apr 2021 15:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618329452; 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=u7+IrVvQfjO+OGatlaK+TGyV6+qpSeEWo6T9E6B2Obc=; b=QUHyqebBs0VDvmYnjWm0/XMzgz/Jws0sJjUwx6qN+RyNsOtFJuE7iGD7e1JrRFB/9XwfA4 P62M429DU9OzCoUtZM43dhf6AVJRBNWsXjpxXnBYTlWDokMkUOMfJYZFd53gg43dy8B3DO j9rIULqtcewKHjh8nlEL1W9Gf7mXC44= X-MC-Unique: ZdrpYeeWPLyOyFhnfKJlSg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 1/3] nodedev: Wait for device initialization in all public API callbacks Date: Tue, 13 Apr 2021 17:57:13 +0200 Message-Id: <713d1633d570e39324f4030d58be8ec5cef4ccc2.1618329176.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.15 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Although I have not experienced this in real life, there is a possible race condition when creating new device, getting its XML or parent or listing its capabilities. If the nodedev driver is still enumerating devices (in a separate thread) and one of virNodeDeviceGetXMLDesc(), virNodeDeviceGetParent(), virNodeDeviceNumOfCaps(), virNodeDeviceListCaps() or virNodeDeviceCreate() is called then it can lead to spurious results because the device enumeration thread is removing devices from or adding them to the internal list of devices (among with their states). Therefore, wait for things to settle down before proceeding with nodeDeviceCreate(). Signed-off-by: Michal Privoznik --- src/node_device/node_device_driver.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 5f8995172d..7aee8201e8 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -340,6 +340,9 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr device, =20 virCheckFlags(0, NULL); =20 + if (nodeDeviceInitWait() < 0) + return NULL; + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return NULL; def =3D virNodeDeviceObjGetDef(obj); @@ -368,6 +371,9 @@ nodeDeviceGetParent(virNodeDevicePtr device) virNodeDeviceDef *def; char *ret =3D NULL; =20 + if (nodeDeviceInitWait() < 0) + return NULL; + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return NULL; def =3D virNodeDeviceObjGetDef(obj); @@ -395,6 +401,9 @@ nodeDeviceNumOfCaps(virNodeDevicePtr device) virNodeDeviceDef *def; int ret =3D -1; =20 + if (nodeDeviceInitWait() < 0) + return -1; + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return -1; def =3D virNodeDeviceObjGetDef(obj); @@ -423,6 +432,9 @@ nodeDeviceListCaps(virNodeDevicePtr device, int ret =3D -1; size_t i =3D 0; =20 + if (nodeDeviceInitWait() < 0) + return -1; + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return -1; def =3D virNodeDeviceObjGetDef(obj); @@ -1399,6 +1411,9 @@ nodeDeviceCreate(virNodeDevice *device, =20 virCheckFlags(0, -1); =20 + if (nodeDeviceInitWait() < 0) + return -1; + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return -1; =20 --=20 2.26.3