From nobody Sun May 19 13:07:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+103324+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+103324+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1682030894325180.59958592959129; Thu, 20 Apr 2023 15:48:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wY0kYY1788612xYeKzF59rkH; Thu, 20 Apr 2023 15:48:13 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.52]) by mx.groups.io with SMTP id smtpd.web11.990.1682030892591065447 for ; Thu, 20 Apr 2023 15:48:13 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gq+6DtcIuv3ylFqgkoPSdqKMiXK1lLOJs+QBlRE8MPHzXN+kq1Ntkb1wBz73J9zNzN52tF1RCjUDD6hvUpz8s0Wbe9Nh++9YOF6dUzNbbey8q1VaI+zBvuGrgBHekg7da0QaHBbE4QCv8BIpE6m9t+9XHGkM8h8GsZf77lrHnReNdPbU4npK5ZPox5VRxvLrm0Oo9Qxs5KW7+jljYrFxg6GpHx5FBSUFomZyXfOIBh/AaWUMqArxDI3TUOy0Z6lkCXYeoXUSs/EvBaviDMVaR5dv2wb0ke+YyA0kpUx9mWTI0e8cQEOZKJJLAw6sT7I1kjXSSs/J7jWveYqVhmdamg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6xQlFlQkqxAN46VyCv92nMlYgeTVStthStOnSCSYRYE=; b=P+9umUFRKai0Q55CYA6lYiSh/73xlUweParGwhYQ6B5qvu6K+94LE5fx+bN82ZQHTWIUotGnSyEtLyAcmUsWBe4ylKLsSsaegvt8TIv5bfd58701ovWF/bfrrMyoNgtmU1fMkpSWFRHEn6hwH9OuwRLKnu+QWZBQ4EGgOrRG3po/qHGKvg64ftXXHr5yMxRqlGBTn1X2ZD+0WBiznV9XWPYz81QfdsJCSZP5VdCCuJHof4jK0DVsk0GDalTZyrGorTbZbor3EECooLz8ruP+6wolzP+FLr1Zn7iHFJLcYlus0dIpB29PhmemlDqilE6jK7l9NmzapsULmQuqiqN26A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ami.com; dmarc=pass action=none header.from=ami.com; dkim=pass header.d=ami.com; arc=none X-Received: from BLAPR10MB5185.namprd10.prod.outlook.com (2603:10b6:208:328::16) by DS7PR10MB4942.namprd10.prod.outlook.com (2603:10b6:5:3ab::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 22:48:08 +0000 X-Received: from BLAPR10MB5185.namprd10.prod.outlook.com ([fe80::d79d:9060:94d8:b4b0]) by BLAPR10MB5185.namprd10.prod.outlook.com ([fe80::d79d:9060:94d8:b4b0%7]) with mapi id 15.20.6319.022; Thu, 20 Apr 2023 22:48:08 +0000 From: "Igor Kulchytskyy via groups.io" To: "devel@edk2.groups.io" CC: Abner Chang , Nickle Wang Subject: [edk2-devel] [PATCH V2] RedfishPkg: Remove the Discover Token global variables Thread-Topic: [PATCH V2] RedfishPkg: Remove the Discover Token global variables Thread-Index: AQHZc9osnqIepGtfo024iNPmDDdI2A== Date: Thu, 20 Apr 2023 22:48:07 +0000 Message-ID: <20230420224759.925-1-igork@ami.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BLAPR10MB5185:EE_|DS7PR10MB4942:EE_ x-ms-office365-filtering-correlation-id: 46b3a247-23f2-4d32-4f68-08db41f14f7b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: LS6VR7sPUl4VcyhwYZqLuVz/cptRXIFwVDy5W0sF9xULjE0sxfHk9nLKOx813JGKlOUCPtGxu0sHg7+7Q6xDwIE0Xo0KimU5H82zusY7bu9bdBR6xHInq8bVILcxaQb8G7k8yn0Dff/1JBxPx0my3XXEQgLecems8SqRBBfUUTcuPybu24gbYwd2uQl3wjGm9MJtuJE+b4RlBWpXKTqX6TZPgpP3yK2n+9+MMyo8TeHxln6jDQ84WEFudkK2AAS9cTEHaioN6+aruP54wNPhgIoinZES6LoGCaL57ZB/FewNJHvc4fQbWQsXENt+oKLcnxN7hlrB9dNPesflJz5ufg2jHXQO5sj8/KPVQupaCfJVqVKrpDgPJO+j/r3c6+kwfa1KtRhs1VEZHKpvizExQjtzmaRu9bIKJ6fz15eC4U0l0V650Y78kuUEk3ioHX9ir/spocHvgvo6X/C8AL+UBV9V6gawerV7Co+D6TOTzoNUrBOFyz8R3RQEjWLsGaSWSNX9mJ4B0flgnQf243kPfCxsz6xUyFS1frAlitKEgm51ms9kmC2DDyA6yPWwpZm4QJEs/ZAXTkiCsPjKl1z6omAzurxp/RypAr3dIyKbetc5+K6hkC3K0+J+kbr3JKj5wgMaam86jMHjpRpRM38Mdg== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?QZjQoU8OLacqZejqV9xDMAlCT38A0VxPUVmE1Kloe70IVvyDW2XTrmHEKe?= =?iso-8859-1?Q?CTNezBUr6WV9uJAX3gsCbkkL4xmA0yyRu8UEJbqIDgT1SgyBWt8nSV9uYV?= =?iso-8859-1?Q?+LtZiUGoMBPhsw5UMf9Bal9p+gYke0spPdtujQmDtqEV3ag2gf2OZ/gCjh?= =?iso-8859-1?Q?a8aFseNSLrJQSMHm3QKB0XsX1XiWA/QuzHIygMF/BhmNxX8HokyiD/DB9l?= =?iso-8859-1?Q?hHdgDJ+rysUKxCz1jk1MR+hAzh43/FSRrnHYeGJid0bpKZDjbEF61qo8u7?= =?iso-8859-1?Q?tMMwg0gD4x52NrLUdLCZwkowcpr7rU1agzaU3DjxsF0DY58fOZ/BJMrS3V?= =?iso-8859-1?Q?6XaNXG8JBWfS3Ttkkv3QuUS7s5ya8wXrd2IPToo2gWgFweyhiWGFiX17HD?= =?iso-8859-1?Q?pzq4tzK7DDMJPrwcgOYftrld1oedJBWcKo1JzsNNnTY7uw0MONDkdeFrb2?= =?iso-8859-1?Q?IiXKTIMTjck6ahlSVMkTLs1SDHdId0pEs7NJAzykTu2CpicXtYOqrVjclC?= =?iso-8859-1?Q?Iop0eNpzoPRiMn5ywfONtyn7vKjEFVnUn2AOHIqhTnHeLi6fWS7l+i5kRY?= =?iso-8859-1?Q?CWxR7tmlWLJ2KYDVy4fKyczGAl2xTPq3BwrdX319UoqUybDHYCxaWg+zmc?= =?iso-8859-1?Q?CC1Fw8DkuEc3shYb/mgpk7Fhm/TXI1ykoU9S/8vERnLkF8jIQRLeqpNVx2?= =?iso-8859-1?Q?jndy+EWiaYqsjF8p1rUwAnxMHaKyB2Gd1ZUV7a7D9P8uoQ7aM/bhITeD5f?= =?iso-8859-1?Q?ZwGnskpNTM/RB1tZ2F2b4FelZ6LyEF+r18baKbrBwzRb2vDT7vGEymO/xY?= =?iso-8859-1?Q?j8ZSLzK06tv3v/8CzUtMjeh9W0NEAdNWQyHMtvOg26ZKtlB4DObJoNNrdZ?= =?iso-8859-1?Q?sGlD8X1XVf2gwbNrr7L2fO53/C7AoWrJD4xZsvpBAE/Cq8U08uDKQ5JinN?= =?iso-8859-1?Q?t7+UQch1V8tNRpQVOeClzQwVSkGwc/M9MrfzBhidob6msGWozvXg8ZueJz?= =?iso-8859-1?Q?RG1jkhF2BBaGWWHilbH7ClILgx2WohQIPEHP/SWVa45xRn+057Ep81m7SM?= =?iso-8859-1?Q?Tfgi+rIzOwzcz+buVGyJqKdOyKON2zyH8fp9bkkcMMVjlMerswM4BB0RHJ?= =?iso-8859-1?Q?au4puyBsIrcuzBR/kgGN2TO/6OkAy/yH/DJrttQ1+8y1rydj5tqib8QulY?= =?iso-8859-1?Q?uOZ2gIx9Y4YF6qFLeP8HVcOQSI2i6NUJVpbEDdOdAvCoRkYBZckGD6Bufz?= =?iso-8859-1?Q?5aK89WUekowqaqlkSLZ7zN+pQWraQ3CCX7pshbMoxYGhsE0aHf7e4yYtI2?= =?iso-8859-1?Q?Swo6zQGSv/4yO7t3JKOtaUhlBBRUfb687AK3dZ0LRYgZXaa1Zam3iOUXut?= =?iso-8859-1?Q?gki/Q9FukL+r/8xApXmneVOVqMBbjGU7KQL+M13XXKe5GTUn/+LsnUMGFa?= =?iso-8859-1?Q?9/VtyFJqqI4AcAK/flkI57EK1Hrvlnl+bsdv5wTuLfbjoPHONtmsuupSyz?= =?iso-8859-1?Q?+YG3dftHYwmX4jRUNWm/kVXmJHmJEmC1W53iGTVn1m/GRnJYdYwgG0TXfc?= =?iso-8859-1?Q?ImJgpHDojJFaJAQHh8/dBNHih/GnjfSLUT5Ado/O03HAtldLKjbOlEbJih?= =?iso-8859-1?Q?SRWijgcBupOkNMKiV5QYZnUAdx/4Huox0h?= MIME-Version: 1.0 X-OriginatorOrg: ami.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5185.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46b3a247-23f2-4d32-4f68-08db41f14f7b X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2023 22:48:07.8675 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 27e97857-e15f-486c-b58e-86c2b3040f93 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: c5MvCCpLQ43JYjaZrgLV9gCZsKj1eiAvADZjNPez6SCOVs+1lH8cMhRVsH9LecYs X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB4942 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,igork@ami.com X-Gm-Message-State: TKKGleBPH5cX2lLmsv43q2AWx1787277AA= Content-Language: en-US Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1682030893; bh=1AUpJ3EheuOUIdEjyeVAImhjQRmT7uP6t/TZhipewls=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=rCo+cSdvvL6gNNaeNmzZ0BCnutz2TOJ2nwz3qiCuyJ9Fcjqv5RHBPl7JuWLsKSo7QA+ SivJS24RHlv463GbfHhEgsIMvIcgeLyz8oCLKx9eHhnAVfypSauF8eNzo4Jl12KalfML4 GVf+aKr2HuWHVk2O4qq1XK/pPUzyv/JLd0M= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1682030895546100002 Content-Type: text/plain; charset="utf-8" gRedfishDiscoveredToken may be allocated several times, if multiple NIC installed on the system. To avoid this issue Discover Token related global variables replaced with the local variables. Cc: Abner Chang Cc: Nickle Wang Cc: Igor Kulchytskyy Signed-off-by: Igor Kulchytskyy Reviewed-by: Abner Chang --- RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c | 143 +++++++= +------------ RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c | 88 +++++++= +---- RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h | 28 +++- 3 files changed, 140 insertions(+), 119 deletions(-) diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c b= /RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c index 993ad338b6..161731b211 100644 --- a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c @@ -22,12 +22,6 @@ EFI_HANDLE gEfiRedfishDiscoverContro= llerHandle =3D NULL; EFI_REDFISH_DISCOVER_PROTOCOL *gEfiRedfishDiscoverProtocol =3D NUL= L; BOOLEAN gRedfishDiscoverActivated =3D FAL= SE; BOOLEAN gRedfishServiceDiscovered =3D FAL= SE; -// -// Network interfaces discovered by EFI Redfish Discover Protocol. -// -UINTN gNumberOfNetworkInterfaces; -EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *gNetworkInterfaceInstances =3D NU= LL; -EFI_REDFISH_DISCOVERED_TOKEN *gRedfishDiscoveredToken =3D NU= LL; /// /// Driver Binding Protocol instance @@ -58,13 +52,6 @@ RedfishConfigStopRedfishDiscovery ( gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent); } - // - // Stop Redfish service discovery. - // - gEfiRedfishDiscoverProtocol->AbortAcquireRedfishService ( - gEfiRedfishDiscoverProtocol, - gNetworkInterfaceInstances - ); gEfiRedfishDiscoverControllerHandle =3D NULL; gEfiRedfishDiscoverProtocol =3D NULL; gRedfishDiscoverActivated =3D FALSE; @@ -318,36 +305,38 @@ RedfishServiceDiscoveredCallback ( EFI_REDFISH_DISCOVERED_TOKEN *RedfishDiscoveredToken; EFI_REDFISH_DISCOVERED_INSTANCE *RedfishInstance; - if (gRedfishServiceDiscovered) { - // - // Only support one Redfish service on platform. - // - return; - } - RedfishDiscoveredToken =3D (EFI_REDFISH_DISCOVERED_TOKEN *)Context; - RedfishInstance =3D RedfishDiscoveredToken->DiscoverList.RedfishI= nstances; + gBS->CloseEvent (RedfishDiscoveredToken->Event); + // - // Only pick up the first found Redfish service. + // Only support one Redfish service on platform. // - if (RedfishInstance->Status =3D=3D EFI_SUCCESS) { - gRedfishConfigData.RedfishServiceInfo.RedfishServiceRestExHandle =3D R= edfishInstance->Information.RedfishRestExHandle; - gRedfishConfigData.RedfishServiceInfo.RedfishServiceVersion =3D R= edfishInstance->Information.RedfishVersion; - gRedfishConfigData.RedfishServiceInfo.RedfishServiceLocation =3D R= edfishInstance->Information.Location; - gRedfishConfigData.RedfishServiceInfo.RedfishServiceUuid =3D R= edfishInstance->Information.Uuid; - gRedfishConfigData.RedfishServiceInfo.RedfishServiceOs =3D R= edfishInstance->Information.Os; - gRedfishConfigData.RedfishServiceInfo.RedfishServiceOsVersion =3D R= edfishInstance->Information.OsVersion; - gRedfishConfigData.RedfishServiceInfo.RedfishServiceProduct =3D R= edfishInstance->Information.Product; - gRedfishConfigData.RedfishServiceInfo.RedfishServiceProductVer =3D R= edfishInstance->Information.ProductVer; - gRedfishConfigData.RedfishServiceInfo.RedfishServiceUseHttps =3D R= edfishInstance->Information.UseHttps; - gRedfishServiceDiscovered =3D T= RUE; + if (!gRedfishServiceDiscovered) { + RedfishInstance =3D RedfishDiscoveredToken->DiscoverList.RedfishInstan= ces; + // + // Only pick up the first found Redfish service. + // + if (RedfishInstance->Status =3D=3D EFI_SUCCESS) { + gRedfishConfigData.RedfishServiceInfo.RedfishServiceRestExHandle =3D= RedfishInstance->Information.RedfishRestExHandle; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceVersion =3D= RedfishInstance->Information.RedfishVersion; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceLocation =3D= RedfishInstance->Information.Location; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceUuid =3D= RedfishInstance->Information.Uuid; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceOs =3D= RedfishInstance->Information.Os; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceOsVersion =3D= RedfishInstance->Information.OsVersion; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceProduct =3D= RedfishInstance->Information.Product; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceProductVer =3D= RedfishInstance->Information.ProductVer; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceUseHttps =3D= RedfishInstance->Information.UseHttps; + gRedfishServiceDiscovered =3D= TRUE; + } + + // + // Invoke RedfishConfigHandlerInstalledCallback to execute + // the initialization of Redfish Configure Handler instance. + // + RedfishConfigHandlerInstalledCallback (gRedfishConfigData.Event, &gRed= fishConfigData); } - // - // Invoke RedfishConfigHandlerInstalledCallback to execute - // the initialization of Redfish Configure Handler instance. - // - RedfishConfigHandlerInstalledCallback (gRedfishConfigData.Event, &gRedfi= shConfigData); + FreePool (RedfishDiscoveredToken); } /** @@ -371,6 +360,7 @@ RedfishDiscoverProtocolInstalled ( UINTN NetworkInterfaceIndex; EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface; EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken; + UINTN NumberOfNetworkInterfaces; DEBUG ((DEBUG_INFO, "%a: New network interface is installed on system by= EFI Redfish discover driver.\n", __func__)); @@ -408,36 +398,29 @@ RedfishDiscoverProtocolInstalled ( } } - // - // Check the new found network interface. - // - if (gNetworkInterfaceInstances !=3D NULL) { - FreePool (gNetworkInterfaceInstances); - } - Status =3D gEfiRedfishDiscoverProtocol->GetNetworkInterfaceList ( gEfiRedfishDiscoverProtocol, gRedfishConfigData.Image, - &gNumberOfNetworkInterfaces, - &gNetworkInterfaceInstances + &NumberOfNetworkInterfaces, + &ThisNetworkInterface ); - if (EFI_ERROR (Status) || (gNumberOfNetworkInterfaces =3D=3D 0)) { + if (EFI_ERROR (Status) || (NumberOfNetworkInterfaces =3D=3D 0)) { DEBUG ((DEBUG_ERROR, "%a: No network interfaces found on the handle.\n= ", __func__)); return; } - gRedfishDiscoveredToken =3D AllocateZeroPool (gNumberOfNetworkInterfaces= * sizeof (EFI_REDFISH_DISCOVERED_TOKEN)); - if (gRedfishDiscoveredToken =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED= _TOKEN.\n", __func__)); - return; - } - - ThisNetworkInterface =3D gNetworkInterfaceInstances; - ThisRedfishDiscoveredToken =3D gRedfishDiscoveredToken; // // Loop to discover Redfish service on each network interface. // - for (NetworkInterfaceIndex =3D 0; NetworkInterfaceIndex < gNumberOfNetwo= rkInterfaces; NetworkInterfaceIndex++) { + for (NetworkInterfaceIndex =3D 0; NetworkInterfaceIndex < NumberOfNetwor= kInterfaces; NetworkInterfaceIndex++) { + ThisRedfishDiscoveredToken =3D (EFI_REDFISH_DISCOVERED_TOKEN *)Allocat= eZeroPool (sizeof (EFI_REDFISH_DISCOVERED_TOKEN)); + if (ThisRedfishDiscoveredToken =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVER= ED_TOKEN.\n", __func__)); + return; + } + + ThisRedfishDiscoveredToken->Signature =3D REDFISH_DISCOVER_TOKEN_SIGNA= TURE; + // // Initial this Redfish Discovered Token // @@ -449,13 +432,11 @@ RedfishDiscoverProtocolInstalled ( &ThisRedfishDiscoveredToken->Event ); if (EFI_ERROR (Status)) { + FreePool (ThisRedfishDiscoveredToken); DEBUG ((DEBUG_ERROR, "%a: Failed to create event for Redfish discove= red token.\n", __func__)); - goto ErrorReturn; + return; } - ThisRedfishDiscoveredToken->Signature =3D REDF= ISH_DISCOVER_TOKEN_SIGNATURE; - ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound =3D 0; - ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances =3D NULL; // // Acquire for Redfish service which is reported by // Redfish Host Interface. @@ -467,21 +448,23 @@ RedfishDiscoverProtocolInstalled ( EFI_REDFISH_DISCOVER_HOST_INTE= RFACE, ThisRedfishDiscoveredToken ); - ThisNetworkInterface++; - ThisRedfishDiscoveredToken++; - } - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Acquire Redfish service fail.\n", __func__)); - goto ErrorReturn; + // + // Free Redfish Discovered Token if Discover Instance was not created = and + // Redfish Service Discovered Callback event was not triggered. + // + if ((ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound =3D= =3D 0) || + EFI_ERROR (ThisRedfishDiscoveredToken->DiscoverList.RedfishInstanc= es->Status)) + { + gBS->CloseEvent (ThisRedfishDiscoveredToken->Event); + DEBUG ((DEBUG_ERROR, "%a: Free Redfish discovered token - %x.\n", __= func__, ThisRedfishDiscoveredToken)); + FreePool (ThisRedfishDiscoveredToken); + } + + ThisNetworkInterface++; } return; - -ErrorReturn: - if (gRedfishDiscoveredToken !=3D NULL) { - FreePool (gRedfishDiscoveredToken); - } } /** @@ -498,25 +481,9 @@ RedfishConfigHandlerDriverUnload ( IN EFI_HANDLE ImageHandle ) { - EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken; - UINTN NumberOfNetworkInterfacesIndex; - RedfishConfigDriverCommonUnload (ImageHandle); RedfishConfigStopRedfishDiscovery (); - if (gRedfishDiscoveredToken !=3D NULL) { - ThisRedfishDiscoveredToken =3D gRedfishDiscoveredToken; - for (NumberOfNetworkInterfacesIndex =3D 0; NumberOfNetworkInterfacesIn= dex < gNumberOfNetworkInterfaces; NumberOfNetworkInterfacesIndex++) { - if (ThisRedfishDiscoveredToken->Event !=3D NULL) { - gBS->CloseEvent (ThisRedfishDiscoveredToken->Event); - } - - FreePool (ThisRedfishDiscoveredToken); - ThisRedfishDiscoveredToken++; - } - - gRedfishDiscoveredToken =3D NULL; - } return EFI_SUCCESS; } diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c b/RedfishPk= g/RedfishDiscoverDxe/RedfishDiscoverDxe.c index 583c6f78e1..a56e2406aa 100644 --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverDxe.c @@ -1095,8 +1095,11 @@ RedfishServiceGetNetworkInterface ( { EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterfaceIn= tn; EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface; + EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance; - if ((NetworkIntfInstances =3D=3D NULL) || (NumberOfNetworkIntfs =3D=3D N= ULL) || (ImageHandle =3D=3D NULL)) { + if ((This =3D=3D NULL) || (NetworkIntfInstances =3D=3D NULL) || (NumberO= fNetworkIntfs =3D=3D NULL) || + (ImageHandle =3D=3D NULL)) + { return EFI_INVALID_PARAMETER; } @@ -1107,12 +1110,26 @@ RedfishServiceGetNetworkInterface ( return EFI_NOT_FOUND; } + RestExInstance =3D EFI_REDFISH_DISOVER_DATA_FROM_DISCOVER_PROTOCOL (This= ); + + // + // Check the new found network interface. + // + if (RestExInstance->NetworkInterfaceInstances !=3D NULL) { + FreePool (RestExInstance->NetworkInterfaceInstances); + RestExInstance->NetworkInterfaceInstances =3D NULL; + } + ThisNetworkInterface =3D (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *)Alloc= ateZeroPool (sizeof (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE) * mNumNetworkI= nterface); if (ThisNetworkInterface =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } - *NetworkIntfInstances =3D ThisNetworkInterface; + *NetworkIntfInstances =3D ThisNetworkInterface; + + RestExInstance->NetworkInterfaceInstances =3D ThisNetworkInterface; + RestExInstance->NumberOfNetworkInterfaces =3D 0; + ThisNetworkInterfaceIntn =3D (EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INT= ERNAL *)GetFirstNode (&mEfiRedfishDiscoverNetworkInterface); while (TRUE) { ThisNetworkInterface->IsIpv6 =3D FALSE; @@ -1130,7 +1147,7 @@ RedfishServiceGetNetworkInterface ( ThisNetworkInterface->SubnetPrefixLength =3D ThisNetworkInterfaceIntn-= >SubnetPrefixLength; ThisNetworkInterface->VlanId =3D ThisNetworkInterfaceIntn-= >VlanId; - (*NumberOfNetworkIntfs)++; + RestExInstance->NumberOfNetworkInterfaces++; if (IsNodeAtEnd (&mEfiRedfishDiscoverNetworkInterface, &ThisNetworkInt= erfaceIntn->Entry)) { break; } @@ -1139,6 +1156,8 @@ RedfishServiceGetNetworkInterface ( ThisNetworkInterface++; } + *NumberOfNetworkIntfs =3D RestExInstance->NumberOfNetworkInterfaces; + return EFI_SUCCESS; } @@ -1178,7 +1197,6 @@ RedfishServiceAcquireService ( { EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *Instance; EFI_STATUS Status1; - EFI_STATUS Status2; BOOLEAN NewInstance; UINTN NumNetworkInterfaces; UINTN NetworkInterfacesIndex; @@ -1215,7 +1233,6 @@ RedfishServiceAcquireService ( for (NetworkInterfacesIndex =3D 0; NetworkInterfacesIndex < NumNetworkIn= terfaces; NetworkInterfacesIndex++) { Status1 =3D EFI_SUCCESS; - Status2 =3D EFI_SUCCESS; NewInstance =3D FALSE; Instance =3D GetInstanceByOwner (ImageHandle, TargetNetworkInterfac= eInternal, Flags & ~EFI_REDFISH_DISCOVER_VALIDATION); // Check if we can re= -use previous instance. if (Instance =3D=3D NULL) { @@ -1223,6 +1240,7 @@ RedfishServiceAcquireService ( Instance =3D (EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE *)AllocateZer= oPool (sizeof (EFI_REDFISH_DISCOVERED_INTERNAL_INSTANCE)); if (Instance =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "%a:Memory allocation fail.\n", __func__)); + return EFI_OUT_OF_RESOURCES; } InitializeListHead (&Instance->Entry); @@ -1258,9 +1276,12 @@ RedfishServiceAcquireService ( DEBUG ((DEBUG_ERROR, "%a:Redfish service discovery through SSDP is n= ot supported\n", __func__)); return EFI_UNSUPPORTED; } else { - if (EFI_ERROR (Status1) && EFI_ERROR (Status2)) { - FreePool ((VOID *)Instance); - DEBUG ((DEBUG_ERROR, "%a:Something wrong on Redfish service discov= ery Status1=3D%x, Status2=3D%x.\n", __func__, Status1, Status2)); + if (EFI_ERROR (Status1)) { + if (NewInstance) { + FreePool ((VOID *)Instance); + } + + DEBUG ((DEBUG_ERROR, "%a:Something wrong on Redfish service discov= ery Status1=3D%r.\n", __func__, Status1)); } else { if (NewInstance) { InsertTailList (&mRedfishDiscoverList, &Instance->Entry); @@ -1387,13 +1408,6 @@ ReleaseNext:; } } -EFI_REDFISH_DISCOVER_PROTOCOL mRedfishDiscover =3D { - RedfishServiceGetNetworkInterface, - RedfishServiceAcquireService, - RedfishServiceAbortAcquire, - RedfishServiceReleaseService -}; - /** This function create an EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL = for the given network interface. @@ -1713,12 +1727,20 @@ BuildupNetworkInterface ( NewNetworkInterfaceInstalled =3D FALSE; NetworkInterface->EfiRedfishDiscoverProtocolHandle =3D NULL; - Status =3D gBS->Inst= allProtocolInterface ( - &Net= workInterface->EfiRedfishDiscoverProtocolHandle, - &gEf= iRedfishDiscoverProtocolGuid, - EFI_= NATIVE_INTERFACE, - (VOI= D *)&mRedfishDiscover - ); + + RestExInstance->Signature =3D EFI_REDFISH_DISCOVER_DATA_SIGNATUR= E; + + RestExInstance->RedfishDiscoverProtocol.GetNetworkInterfaceList = =3D RedfishServiceGetNetworkInterface; + RestExInstance->RedfishDiscoverProtocol.AcquireRedfishService = =3D RedfishServiceAcquireService; + RestExInstance->RedfishDiscoverProtocol.AbortAcquireRedfishServi= ce =3D RedfishServiceAbortAcquire; + RestExInstance->RedfishDiscoverProtocol.ReleaseRedfishService = =3D RedfishServiceReleaseService; + + Status =3D gBS->InstallProtocolInterface ( + &NetworkInterface->EfiRedfishDiscoverProtocolHan= dle, + &gEfiRedfishDiscoverProtocolGuid, + EFI_NATIVE_INTERFACE, + (VOID *)&RestExInstance->RedfishDiscoverProtocol + ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: Fail to install EFI_REDFISH_DISCOVER= _PROTOCOL\n", __func__)); } @@ -1815,6 +1837,7 @@ StopServiceOnNetworkInterface ( EFI_HANDLE DiscoverProtocolHandle; EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL *ThisNetworkInterface; EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL *RestExInstance; + EFI_REDFISH_DISCOVER_PROTOCOL *RedfishDiscoverProtoco= l; for (Index =3D 0; Index < (sizeof (gRequiredProtocol) / sizeof (REDFISH_= DISCOVER_REQUIRED_PROTOCOL)); Index++) { Status =3D gBS->HandleProtocol ( @@ -1854,12 +1877,29 @@ StopServiceOnNetworkInterface ( // client which uses .EFI Redfish discover protocol. // if (DiscoverProtocolHandle !=3D NULL) { - gBS->DisconnectController (DiscoverProtocolHandle, NULL, NUL= L); - Status =3D gBS->UninstallProtocolInterface ( + Status =3D gBS->HandleProtocol ( DiscoverProtocolHandle, &gEfiRedfishDiscoverProtocolGuid, - (VOID *)&mRedfishDiscover + (VOID **) &RedfishDiscoverProtocol ); + if (!EFI_ERROR (Status)) { + RestExInstance =3D EFI_REDFISH_DISOVER_DATA_FROM_DISCOVER_= PROTOCOL (RedfishDiscoverProtocol); + // + // Stop Redfish service discovery. + // + RedfishDiscoverProtocol->AbortAcquireRedfishService ( + RedfishDiscoverProtocol, + RestExInstance->NetworkInterfac= eInstances + ); + + + gBS->DisconnectController (DiscoverProtocolHandle, NULL, N= ULL); + Status =3D gBS->UninstallProtocolInterface ( + DiscoverProtocolHandle, + &gEfiRedfishDiscoverProtocolGuid, + (VOID *)&RestExInstance->RedfishDiscoverPr= otocol + ); + } } return Status; diff --git a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h b/Redf= ishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h index 2704cd955d..d24c4081d9 100644 --- a/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h +++ b/RedfishPkg/RedfishDiscoverDxe/RedfishDiscoverInternal.h @@ -117,17 +117,31 @@ typedef struct { = ///< on this network interface. } EFI_REDFISH_DISCOVER_NETWORK_INTERFACE_INTERNAL; +// +// Redfish Discover Instance signature +// + +#define EFI_REDFISH_DISCOVER_DATA_SIGNATURE SIGNATURE_32 ('E', 'R', 'D', = 'D') + +#define EFI_REDFISH_DISOVER_DATA_FROM_DISCOVER_PROTOCOL(a) \ + CR (a, EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL, RedfishDiscoverPr= otocol, EFI_REDFISH_DISCOVER_DATA_SIGNATURE) + // // Internal structure used to maintain REST EX properties. // typedef struct { - LIST_ENTRY Entry; ///< Link list entry. - EFI_HANDLE OpenDriverAgentHandle; ///< The agent to op= en network protocol. - EFI_HANDLE OpenDriverControllerHandle; ///< The controller = handle to open network protocol. - EFI_HANDLE RestExChildHandle; ///< The child handl= e created through REST EX Service Protocol. - EFI_HANDLE RestExControllerHandle; ///< The controller = handle which provide REST EX protocol. - EFI_REST_EX_PROTOCOL *RestExProtocolInterface; ///< Pointer to EFI_= REST_EX_PROTOCOL. - UINT32 RestExId; ///< The identifier = installed on REST EX controller handle. + LIST_ENTRY Entry; //= /< Link list entry. + UINT32 Signature; //= /< Instance signature. + EFI_HANDLE OpenDriverAgentHandle; //= /< The agent to open network protocol. + EFI_HANDLE OpenDriverControllerHandle; //= /< The controller handle to open network protocol. + EFI_HANDLE RestExChildHandle; //= /< The child handle created through REST EX Service Protocol. + EFI_HANDLE RestExControllerHandle; //= /< The controller handle which provide REST EX protocol. + EFI_REST_EX_PROTOCOL *RestExProtocolInterface; //= /< Pointer to EFI_REST_EX_PROTOCOL. + UINT32 RestExId; //= /< The identifier installed on REST EX controller handle. + UINTN NumberOfNetworkInterfaces; //= /< Number of network interfaces can do Redfish service discovery. + EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *NetworkInterfaceInstances; //= /< Network interface instances. It's an array of instances. The number of e= ntries + //= /< in array is indicated by NumberOfNetworkInterfaces. + EFI_REDFISH_DISCOVER_PROTOCOL RedfishDiscoverProtocol; //= /< EFI_REDFISH_DISCOVER_PROTOCOL protocol. } EFI_REDFISH_DISCOVER_REST_EX_INSTANCE_INTERNAL; /** -- 2.37.1.windows.1 -The information contained in this message may be confidential and propriet= ary to American Megatrends (AMI). This communication is intended to be read= only by the individual or entity to whom it is addressed or by their desig= nee. If the reader of this message is not the intended recipient, you are o= n notice that any distribution of this message, in any form, is strictly pr= ohibited. Please promptly notify the sender by reply e-mail or by telephone= at 770-246-8600, and then delete or destroy all copies of the transmission. -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#103324): https://edk2.groups.io/g/devel/message/103324 Mute This Topic: https://groups.io/mt/98400001/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-