From nobody Mon Feb 9 20:09:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1592514396; cv=none; d=zohomail.com; s=zohoarc; b=SSoSJca5sx6qMss5bvbMwCvOBMdpqk/G3KvvUoaKycFFGBv4DSvVdYeuaIhHGaptaFYcrf6jQrU9OOoibnZVWQWJGz1VT4ER4XehRJ9skYFqdMiuaAbeBYH3+vjI9m9y4pzmoO8GZuBhqtxFV5U2DedJTfDitmJHuiljXxp6goU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592514396; h=Content-Type:Content-Transfer-Encoding:Cc: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=SRAvtoqXGzSJy4iTD8KVOUh5IIAZWYEzo8XpC8JyUKU=; b=ZqpSuQsAaOxfp2IsxyjLLHmyYBrHTBHmIsBSbkJTovtH1XGRvMTAjVMxj1IQVuI+1hCWr5f19AOJDpB7pHzeXdbiV7fmU0Ei2i3GyrLghKRbGWhOXiTXbwbt+8xoWbnNa9BDVYRqp5HGax5FLAvLbcPherxu3BirbI8LGPk0HKg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1592514396530739.9414764939539; Thu, 18 Jun 2020 14:06:36 -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-461-FRfqZ-P6PGeQKY42_O6s7g-1; Thu, 18 Jun 2020 17:06:32 -0400 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 848EE801503; Thu, 18 Jun 2020 21:06:27 +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 653275C1D0; Thu, 18 Jun 2020 21:06:27 +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 36312833CF; Thu, 18 Jun 2020 21:06:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05IL6Btp002533 for ; Thu, 18 Jun 2020 17:06:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 78B3E60E1C; Thu, 18 Jun 2020 21:06:11 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-51.phx2.redhat.com [10.3.114.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2ABE860BF4; Thu, 18 Jun 2020 21:06:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592514395; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=SRAvtoqXGzSJy4iTD8KVOUh5IIAZWYEzo8XpC8JyUKU=; b=dbAAptfYozslnJLdsuYmaImcxV72x4N8aVVauwBF6TD90gWzMZzeXIIP89qz2Wru1NpRbf ZZogbGHbObx5/NKsCCYZUJVrW7VAEUvXLLRc/7YPLHk36IVuts/hjxOvONlXufn0pDDwzT vuP8imJBOFwF8aZt1yEsVs3hM4A/0dQ= X-MC-Unique: FRfqZ-P6PGeQKY42_O6s7g-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v4 04/12] nodedev: refactor nodeDeviceFindNewDevice() Date: Thu, 18 Jun 2020 16:05:57 -0500 Message-Id: <20200618210605.12308-5-jjongsma@redhat.com> In-Reply-To: <20200618210605.12308-1-jjongsma@redhat.com> References: <20200618210605.12308-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, eskultet@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 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" In preparation for creating mediated devices in libvirt, we will need to wait for new mediated devices to be created as well. Refactor nodeDeviceFindNewDevice() so that we can re-use the main logic from this function to wait for different device types by passing a different 'find' function. Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 41 +++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index ba7ea50e5b..d6255a43c8 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -447,6 +447,10 @@ nodeDeviceGetTime(time_t *t) } =20 =20 +typedef virNodeDevicePtr (*nodeDeviceFindNewDeviceFunc)(virConnectPtr conn, + const void* opaque= ); + + /* When large numbers of devices are present on the host, it's * possible for udev not to realize that it has work to do before we * get here. We thus keep trying to find the new device we just @@ -462,8 +466,8 @@ nodeDeviceGetTime(time_t *t) */ static virNodeDevicePtr nodeDeviceFindNewDevice(virConnectPtr conn, - const char *wwnn, - const char *wwpn) + nodeDeviceFindNewDeviceFunc func, + const void *opaque) { virNodeDevicePtr device =3D NULL; time_t start =3D 0, now =3D 0; @@ -474,7 +478,7 @@ nodeDeviceFindNewDevice(virConnectPtr conn, =20 virWaitForDevices(); =20 - device =3D nodeDeviceLookupSCSIHostByWWN(conn, wwnn, wwpn, 0); + device =3D func(conn, opaque); =20 if (device !=3D NULL) break; @@ -488,6 +492,35 @@ nodeDeviceFindNewDevice(virConnectPtr conn, } =20 =20 +typedef struct _NewSCSIHostFuncData NewSCSIHostFuncData; +struct _NewSCSIHostFuncData +{ + const char *wwnn; + const char *wwpn; +}; + + +static virNodeDevicePtr +nodeDeviceFindNewSCSIHostFunc(virConnectPtr conn, + const void *opaque) +{ + const NewSCSIHostFuncData *data =3D opaque; + + return nodeDeviceLookupSCSIHostByWWN(conn, data->wwnn, data->wwpn, 0); +} + + +static virNodeDevicePtr +nodeDeviceFindNewSCSIHost(virConnectPtr conn, + const char *wwnn, + const char *wwpn) +{ + NewSCSIHostFuncData data =3D { .wwnn =3D wwnn, .wwpn =3D wwpn}; + + return nodeDeviceFindNewDevice(conn, nodeDeviceFindNewSCSIHostFunc, &d= ata); +} + + static bool nodeDeviceHasCapability(virNodeDeviceDefPtr def, virNodeDevCapType type) { @@ -538,7 +571,7 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) return NULL; =20 - device =3D nodeDeviceFindNewDevice(conn, wwnn, wwpn); + device =3D nodeDeviceFindNewSCSIHost(conn, wwnn, wwpn); /* We don't check the return value, because one way or another, * we're returning what we get... */ =20 --=20 2.21.3