From nobody Sat Feb 7 07:31:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1592317706; cv=none; d=zohomail.com; s=zohoarc; b=efvt2rehe2j1sn4t8jJ2pbzLP1IhGUZ+HKabBGrFhkVqDm/1zlVfDW6TPE1i2OlbI2AKMpZIzqOIHbT8Oy2AzdDpouVNKqDSR6sRpSujhuDhCuEGW5tLrhd/m3PmDM1I5ldRfrRN/9V9M6r//sLWejasa7YNv8XlK1Qq0qTgsZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592317706; 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=5lGC7CPzBqUeau0wkem9GXtfUh47cOpncobTRU/QsZg=; b=ilrZGL/JSbK5M3cOZfnwP2QsWZ8PehR85jxSd4w0/8utMZ7drcm0qWNjvjIIQ/xZtjV7oMrmmvvZBHAtOXiBsWfVcxkWLm1+SAZ3tco07Q5MeyQ6M3AFJT0C0xh0MyDnbLF+U3vFVkRpZXyPvs6/AhvS10uuxUiVgBM0iv/2AMk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1592317706161877.0764338373276; Tue, 16 Jun 2020 07:28:26 -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-439-dBV3hGlYP46QBwI6hTroug-1; Tue, 16 Jun 2020 10:28:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F51018585D2; Tue, 16 Jun 2020 14:28:17 +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 3B3B31002394; Tue, 16 Jun 2020 14:28:17 +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 BDB5B833CA; Tue, 16 Jun 2020 14:28:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05GES5QN020337 for ; Tue, 16 Jun 2020 10:28:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id F39DB7A029; Tue, 16 Jun 2020 14:28:04 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A67007890A; Tue, 16 Jun 2020 14:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592317704; 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=5lGC7CPzBqUeau0wkem9GXtfUh47cOpncobTRU/QsZg=; b=TUlWSp2JH6l3sKJye4b9VEN8cEGhFOG0yDaRaiqQR7cGbyG3DlvH2TnSNaJ8GpepdEVW3p DhaL4pza6soKPqIddCBcjjShgIdo9FVmTpMVfB5nt/MH6cGf3D0P4S71uQUFgdu7NCHCsh rjjo68xR9xvDo4uZUNll4lolirVl4lw= X-MC-Unique: dBV3hGlYP46QBwI6hTroug-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v3 04/11] nodedev: refactor nodeDeviceFindNewDevice() Date: Tue, 16 Jun 2020 09:27:52 -0500 Message-Id: <20200616142759.4625-5-jjongsma@redhat.com> In-Reply-To: <20200616142759.4625-1-jjongsma@redhat.com> References: <20200616142759.4625-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 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 Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 39 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index ba7ea50e5b..629d4bcf91 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,33 @@ 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 +569,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