From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 6FC44D80101 for ; Thu, 4 Jan 2024 08:57:19 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=wO9FUIQb11FOibz30ym8DT/tl0/ytafnn2dy7Lln3kw=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1704358638; v=1; b=rVK+OIpWNfxZFOnqaYlm/PHWq4Y7smph9fT6LAxb5itsnPZBHuljX2eIdF1aUSz6Sh80aT5W pPzL6hMjS2H1HJdBODntfSBSpgQKEKAl2z9HzCeJZWJN8Gt3JmkFdBeo8tnIb2jtYqj+YBtRMvR R/4I7xN8pCqIewVFbr0dj4Kc= X-Received: by 127.0.0.2 with SMTP id TDNOYY7687511xk2M7Gl3Lgw; Thu, 04 Jan 2024 00:57:18 -0800 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.73]) by mx.groups.io with SMTP id smtpd.web10.50192.1704358637115412329 for ; Thu, 04 Jan 2024 00:57:17 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IdpwP8LsoTiK6/84YTHfbIqOCdWjaL7uNztZQCPjcFCu0kNn4036zjAXrTzAnhIBGV8YivwQCxPZH+6Spkboii5Y9nUzIfTKJF1jVuXSMCmaT69RzA01tNzQEO2H33gvJCSV5COU7EiZ0jexEyLDVP3xkLPRz7pLkDNibtAgSNxkWpuGR6Va9BlJJ0342XpyhUzB5XvwtZdkPjMGrXBoFZqOLqcOmiveGkUjOBG0VwpB+OcLlyDpdJhAMRByDIQ+zNRzD/GYBHF7RZCfaLKO/ntohN42ENAsZMJieDQdDOH+ymM8LrB4aa9C11j1pjepk8qDQre5QoCYo9R18brEfg== 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=12YoTrnYgKO7HqhBc7iJFlZYqo/F2GwrIXdetFbvbB0=; b=dbKIf3O4FGAO8+kKk6V6MhOMozUgy3Wnqnlw6KR1z+yNy0+bgfFdDCeYrb3tP0Nzbl3uQiUsWQ5WPzpEYyKepp87/H8NM6tzXP8l12Nsy7OpUaQGH9RTa2l4A1Yt4tk7kwF0Brpiig/Fr//FZr15mUPn8/ye9G0j3+GDjTC6lvGDI6iaXQPhif/7MnJWJ4+ZMeiYV0Z+qwRtdwUTQ9F0Pfwhm8s08XzsWvyz/oAySIznzKTxQY9IVlud9A9ujdSemPYqMAIsSAzc2LkviEe0jQrevYF5Thp++mLqw7jiN4P5l3qN83HDHzhcgpGXdtPPGfmwAU4yIyCwjMJmEZGcDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) X-Received: from BL1PR13CA0286.namprd13.prod.outlook.com (2603:10b6:208:2bc::21) by SA0PR12MB4399.namprd12.prod.outlook.com (2603:10b6:806:98::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.15; Thu, 4 Jan 2024 08:57:14 +0000 X-Received: from BL6PEPF0001AB54.namprd02.prod.outlook.com (2603:10b6:208:2bc:cafe::a3) by BL1PR13CA0286.outlook.office365.com (2603:10b6:208:2bc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.7 via Frontend Transport; Thu, 4 Jan 2024 08:57:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by BL6PEPF0001AB54.mail.protection.outlook.com (10.167.241.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7159.9 via Frontend Transport; Thu, 4 Jan 2024 08:57:14 +0000 X-Received: from TPE-L1-ABNCHANG.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 4 Jan 2024 02:57:12 -0600 From: "Chang, Abner via groups.io" To: CC: Nickle Wang , Igor Kulchytskyy , Mike Maslenkin Subject: [edk2-devel] [edk2-redfish-client][PATCH V2] RedfishClientPkg: Add ETag PCD and revise Redfish ETag functions Date: Thu, 4 Jan 2024 16:56:51 +0800 Message-ID: <20240104085651.41-1-abner.chang@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB54:EE_|SA0PR12MB4399:EE_ X-MS-Office365-Filtering-Correlation-Id: 8025671c-3604-47f5-2f6b-08dc0d032556 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: j0hBvjqCofcEQEyLI0OENYg80l89zXa7TpiXdy7tEGxP//0T4iVZjulNACbnzHL7ia4zhfj8JwzK3vwfcwDVtpC40EEhEqCxXgzJ1XLWThnYBD/fibU6HDyPGg7DJZKDoJz430krnqnwO21HQJcgpOwF+KFBni3cez64Ud9mmxXcnbdyHxyClZbXhUE3EqHEfhCCYoihbkn4jFW/DTl/6fIQeC8gb8OvnnUN4LToRoJlJOZ86yM4IOuurKoXLnEHGrb7FHwfGOGUtAQ6ioJfu3wAov+eNjFjblfXyDlUMaSU6OgqtHlFqUm6ECXLNfDcNh/IyjaKX1rq7dp7KCktub06MGHVlVQ4mARP61915KjUblZvojtDnMfVDLdtWzDunvHE2muv3wJquk6ErhY7RauKOhEQwnmAUNypQ99+4lCIuqc7/Z7VTkBzgA0aZ0EVcGB35CNSJJi2he4KOLFJZYxPxW9GZhVXrVYcQYu0pRw6eEkUJmFTSlyRSMQCHLTtLawO+Y89NhctqfoZilLZZ/LjVueRwJ65BMU1yB8mr9UFfOmAvUsiEFjLZbl2Feuf7fyT0cfTWCu3xt3vgS0UO4E4CehLEO8pmK2aw/rh8SeOZpqTaUzvE2TnM5EFbD7h27saNqFNXAKjsVOL8drO3TJx1Nf0OEgq8xKo4koUyiK7t3WP1QP89IKNazLENiS9muQJuTXGevkdscJN0UrwrkSp+2pQfg97Sv0RS92+goEvIJMMsXbz/Te3l70Z+tEYJwfzkxJ4H6mtv+yKhEZaWz51iu0vpq0HsTIKlKenabEoG8rRHuMSl8s/TcgbVsTA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2024 08:57:14.1454 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8025671c-3604-47f5-2f6b-08dc0d032556 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB54.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4399 Precedence: Bulk 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,abner.chang@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: uvTdhK0I8YQ69neVmSDkphfSx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=rVK+OIpW; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") From: Abner Chang Add PCD to disable ETag capability for the case Redfish service doesn't support ETag. Signed-off-by: Abner Chang Cc: Nickle Wang Cc: Igor Kulchytskyy Cc: Mike Maslenkin --- RedfishClientPkg/RedfishClientPkg.dec | 2 + .../RedfishFeatureUtilityLib.inf | 1 + .../Library/RedfishFeatureUtilityLib.h | 46 +++- .../Features/Bios/v1_0_9/Dxe/BiosDxe.c | 18 +- .../v1_0_4/Common/BootOptionCommon.c | 4 +- .../BootOption/v1_0_4/Dxe/BootOptionDxe.c | 16 +- .../v1_5_0/Dxe/ComputerSystemDxe.c | 16 +- .../Features/Memory/V1_7_1/Dxe/MemoryDxe.c | 16 +- .../RedfishFeatureUtilityLib.c | 208 ++++++++++++------ 9 files changed, 197 insertions(+), 130 deletions(-) diff --git a/RedfishClientPkg/RedfishClientPkg.dec b/RedfishClientPkg/Redfi= shClientPkg.dec index b350facae0..8adef327fb 100644 --- a/RedfishClientPkg/RedfishClientPkg.dec +++ b/RedfishClientPkg/RedfishClientPkg.dec @@ -76,6 +76,8 @@ gEfiRedfishClientPkgTokenSpaceGuid.PcdDefaultRedfishVersion|L"v1"|VOID*|= 0x10000004 ## The number of seconds that the firmware will wait before system reboo= t gEfiRedfishClientPkgTokenSpaceGuid.PcdRedfishSystemRebootTimeout|5|UINT1= 6|0x20000002 + ## Default capability of Redfish service side ETAG support + gEfiRedfishClientPkgTokenSpaceGuid.PcdRedfishServiceEtagSupported|TRUE|B= OOLEAN|0x10000005 =20 [PcdsDynamicEx] ## The flag used to indicate that system reboot is required due to syste= m configuration change diff --git a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatu= reUtilityLib.inf b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/Redfis= hFeatureUtilityLib.inf index 718273b248..fde6a176d0 100644 --- a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.inf +++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.inf @@ -54,6 +54,7 @@ =20 [Pcd] gEfiRedfishClientPkgTokenSpaceGuid.PcdRedfishSystemRebootRequired + gEfiRedfishClientPkgTokenSpaceGuid.PcdRedfishServiceEtagSupported =20 [Guids] =20 diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h b/= RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h index 9513a65617..834ea0fcfe 100644 --- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h +++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h @@ -81,7 +81,7 @@ CopyConfiglanguageList ( =20 /** =20 - Get number of node from the string. Node is seperated by '/'. + Get number of node from the string. Node is separated by '/'. =20 @param[in] NodeString The node string to parse. =20 @@ -559,6 +559,19 @@ GetEtagWithUri ( IN EFI_STRING Uri ); =20 +/** + + This function returns a boolean of ETAG support on Redfish service side. + + @retval TRUE ETAG is supported on Redfish service. + @retval FALSE ETAG is not supported on Redfish service. + +**/ +BOOLEAN +CheckIsServerEtagSupported ( + VOID + ); + /** =20 Get @odata.id from give HTTP payload. It's call responsibility to releas= e returned buffer. @@ -931,22 +944,33 @@ CompareRedfishPropertyVagueValues ( ); =20 /** + Find "ETag" from either HTTP header or Redfish response. =20 - Find "ETag" and "Location" from either HTTP header or Redfish response. + @param[in] Response HTTP response + @param[out] Etag String buffer to return ETag =20 - @param[in] Response HTTP response - @param[out] Etag String buffer to return ETag - @param[out] Location String buffer to return Location + @retval EFI_SUCCESS ETag is returned in Etag + @retval EFI_UNSUPPORTED ETag is unsupported + @retval EFI_INVALID_PARAMETER Response, Etag or both are NULL. =20 - @retval EFI_SUCCESS Data is found and returned. - @retval Others Errors occur. +**/ +EFI_STATUS +GetHttpResponseEtag ( + IN REDFISH_RESPONSE *Response, + OUT CHAR8 **Etag + ); + +/** + Find "Location" from either HTTP header or Redfish response. + + @param[in] Response HTTP response + @param[out] Location String buffer to return Location =20 **/ EFI_STATUS -GetEtagAndLocation ( - IN REDFISH_RESPONSE *Response, - OUT CHAR8 **Etag, OPTIONAL - OUT EFI_STRING *Location OPTIONAL +GetHttpResponseLocation ( + IN REDFISH_RESPONSE *Response, + OUT EFI_STRING *Location ); =20 /** diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c b/RedfishC= lientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c index 2a49c5cd22..14e854c861 100644 --- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c @@ -153,14 +153,10 @@ RedfishResourceConsumeResource ( ASSERT (Private->Json !=3D NULL); =20 // - // Find etag in HTTP response header + // Searching for etag in HTTP response header // - Etag =3D NULL; - Status =3D GetEtagAndLocation (ExpectedResponse, &Etag, NULL); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __fu= nc__)); - } - + Etag =3D NULL; + GetHttpResponseEtag (ExpectedResponse, &Etag); Status =3D RedfishConsumeResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { if (Status !=3D EFI_ALREADY_STARTED) { @@ -365,12 +361,8 @@ RedfishResourceCheck ( // // Find etag in HTTP response header // - Etag =3D NULL; - Status =3D GetEtagAndLocation (&Response, &Etag, NULL); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __fu= nc__)); - } - + Etag =3D NULL; + GetHttpResponseEtag (&Response, &Etag); Status =3D RedfishCheckResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __= func__, Uri, Status)); diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionC= ommon.c b/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionComm= on.c index 0d4c2162c6..0b9a72abc3 100644 --- a/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.c +++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.c @@ -455,9 +455,9 @@ RedfishProvisioningResourceCommon ( } =20 // - // per Redfish spec. the URL of new resource will be returned in "Locati= on" header. + // Per Redfish spec. the URL of new resource will be returned in "Locati= on" header. // - Status =3D GetEtagAndLocation (&Response, NULL, &NewResourceLocation); + Status =3D GetHttpResponseLocation (&Response, &NewResourceLocation); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: cannot find new location: %r\n", __func__, S= tatus)); goto RELEASE_RESOURCE; diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.= c b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c index ba090c51d3..204c6b0757 100644 --- a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c +++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c @@ -154,12 +154,8 @@ RedfishResourceConsumeResource ( // // Find etag in HTTP response header // - Etag =3D NULL; - Status =3D GetEtagAndLocation (ExpectedResponse, &Etag, NULL); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __fu= nc__)); - } - + Etag =3D NULL; + GetHttpResponseEtag (ExpectedResponse, &Etag); Status =3D RedfishConsumeResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", = __func__, Private->Uri, Status)); @@ -358,12 +354,8 @@ RedfishResourceCheck ( // // Find etag in HTTP response header // - Etag =3D NULL; - Status =3D GetEtagAndLocation (&Response, &Etag, NULL); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __fu= nc__)); - } - + Etag =3D NULL; + GetHttpResponseEtag (&Response, &Etag); Status =3D RedfishCheckResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: failed to check resource= from: %s: %r\n", __func__, Uri, Status)); diff --git a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSy= stemDxe.c b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSys= temDxe.c index 0bbaa92bf4..7805bcf36b 100644 --- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe= .c +++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe= .c @@ -149,12 +149,8 @@ RedfishResourceConsumeResource ( // // Find etag in HTTP response header // - Etag =3D NULL; - Status =3D GetEtagAndLocation (ExpectedResponse, &Etag, NULL); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __fu= nc__)); - } - + Etag =3D NULL; + GetHttpResponseEtag (ExpectedResponse, &Etag); Status =3D RedfishConsumeResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { if (Status !=3D EFI_ALREADY_STARTED) { @@ -359,12 +355,8 @@ RedfishResourceCheck ( // // Find etag in HTTP response header // - Etag =3D NULL; - Status =3D GetEtagAndLocation (&Response, &Etag, NULL); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __fu= nc__)); - } - + Etag =3D NULL; + GetHttpResponseEtag (&Response, &Etag); Status =3D RedfishCheckResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __= func__, Uri, Status)); diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c b/Redf= ishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c index 9230078051..b87da775b3 100644 --- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c +++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c @@ -149,12 +149,8 @@ RedfishResourceConsumeResource ( // // Find etag in HTTP response header // - Etag =3D NULL; - Status =3D GetEtagAndLocation (ExpectedResponse, &Etag, NULL); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __fu= nc__)); - } - + Etag =3D NULL; + GetHttpResponseEtag (ExpectedResponse, &Etag); Status =3D RedfishConsumeResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { if (Status !=3D EFI_ALREADY_STARTED) { @@ -359,12 +355,8 @@ RedfishResourceCheck ( // // Find etag in HTTP response header // - Etag =3D NULL; - Status =3D GetEtagAndLocation (&Response, &Etag, NULL); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __fu= nc__)); - } - + Etag =3D NULL; + GetHttpResponseEtag (&Response, &Etag); Status =3D RedfishCheckResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __= func__, Uri, Status)); diff --git a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatu= reUtilityLib.c b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishF= eatureUtilityLib.c index 1c2d40f622..7709a9d1a2 100644 --- a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.c +++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.c @@ -133,6 +133,11 @@ SetEtagFromUri ( REDFISH_RESPONSE Response; EFI_STRING PendingSettingUri; =20 + if (!CheckIsServerEtagSupported ()) { + DEBUG ((DEBUG_INFO, "%a: WARNING - ETAG is not supported\n", __func__)= ); + return EFI_SUCCESS; + } + if ((RedfishService =3D=3D NULL) || IS_EMPTY_STRING (Uri)) { return EFI_INVALID_PARAMETER; } @@ -157,9 +162,9 @@ SetEtagFromUri ( // // Find etag in HTTP response header // - Status =3D GetEtagAndLocation (&Response, &Etag, NULL); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __fu= nc__)); + Status =3D GetHttpResponseEtag (&Response, &Etag); + if (EFI_ERROR (Status) && (Status !=3D EFI_UNSUPPORTED)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get ETag from HTTP header\n", __fu= nc__)); Status =3D EFI_NOT_FOUND; goto ON_RELEASE; } @@ -241,6 +246,11 @@ SetEtagWithUri ( EFI_STATUS Status; CHAR8 *AsciiUri; =20 + if (!CheckIsServerEtagSupported ()) { + DEBUG ((DEBUG_INFO, "%a: WARNING - ETAG is not supported\n", __func__)= ); + return EFI_SUCCESS; + } + if (IS_EMPTY_STRING (EtagStr) || IS_EMPTY_STRING (Uri)) { return EFI_INVALID_PARAMETER; } @@ -286,6 +296,11 @@ GetEtagWithUri ( return NULL; } =20 + if (!CheckIsServerEtagSupported ()) { + DEBUG ((DEBUG_INFO, "%a: WARNING - ETAG is not supported\n", __func__)= ); + return NULL; + } + Status =3D RedfishLocateProtocol ((VOID **)&mEtagProtocol, &gEdkIIRedfis= hETagProtocolGuid); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: fail to locate gEdkIIRedfishETagProtocolGuid= : %r\n", __func__, Status)); @@ -1726,44 +1741,39 @@ RedfishFeatureGetUnifiedArrayTypeConfigureLang ( } =20 /** + Find "ETag" from either HTTP header or Redfish response. =20 - Find "ETag" and "Location" from either HTTP header or Redfish response. + @param[in] Response HTTP response + @param[out] Etag String buffer to return ETag =20 - @param[in] Response HTTP response - @param[out] Etag String buffer to return ETag - @param[out] Location String buffer to return Location - - @retval EFI_SUCCESS Data is found and returned. - @retval Others Errors occur. + @retval EFI_SUCCESS ETag is returned in Etag + @retval EFI_UNSUPPORTED ETag is unsupported + @retval EFI_INVALID_PARAMETER Response, Etag or both are NULL. =20 **/ EFI_STATUS -GetEtagAndLocation ( - IN REDFISH_RESPONSE *Response, - OUT CHAR8 **Etag, OPTIONAL - OUT EFI_STRING *Location OPTIONAL +GetHttpResponseEtag ( + IN REDFISH_RESPONSE *Response, + OUT CHAR8 **Etag ) { + EFI_STATUS Status; EDKII_JSON_VALUE JsonValue; EDKII_JSON_VALUE OdataValue; CHAR8 *OdataString; - CHAR8 *AsciiLocation; EFI_HTTP_HEADER *Header; - EFI_STATUS Status; =20 - if (Response =3D=3D NULL) { + if ((Response =3D=3D NULL) || (Etag =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } =20 - if ((Etag =3D=3D NULL) && (Location =3D=3D NULL)) { - return EFI_SUCCESS; - } - Status =3D EFI_SUCCESS; - - if (Etag !=3D NULL) { - *Etag =3D NULL; - + *Etag =3D NULL; + if (!CheckIsServerEtagSupported ()) { + // Don't look for ETAG header or property in this case. + DEBUG ((DEBUG_INFO, "%a: WARNING - No ETag support on Redfish service.= \n", __func__)); + return EFI_UNSUPPORTED; + } else { if (*(Response->StatusCode) =3D=3D HTTP_STATUS_200_OK) { Header =3D HttpFindHeader (Response->HeaderCount, Response->Headers,= HTTP_HEADER_ETAG); if (Header !=3D NULL) { @@ -1793,51 +1803,94 @@ GetEtagAndLocation ( =20 if (*Etag =3D=3D NULL) { Status =3D EFI_NOT_FOUND; + DEBUG ((DEBUG_ERROR, "%a: Failed to retrieve ETag from HTTP response= paylaod.\n", __func__)); } } =20 - if (Location !=3D NULL) { - *Location =3D NULL; - AsciiLocation =3D NULL; + return Status; +} =20 - if (*(Response->StatusCode) =3D=3D HTTP_STATUS_200_OK) { - Header =3D HttpFindHeader (Response->HeaderCount, Response->Headers,= HTTP_HEADER_LOCATION); - if (Header !=3D NULL) { - AsciiLocation =3D AllocateCopyPool (AsciiStrSize (Header->FieldVal= ue), Header->FieldValue); - ASSERT (AsciiLocation !=3D NULL); - } +/** + Find "Location" from either HTTP header or Redfish response. + + @param[in] Response HTTP response + @param[out] Location String buffer to return Location + +**/ +EFI_STATUS +GetHttpResponseLocation ( + IN REDFISH_RESPONSE *Response, + OUT EFI_STRING *Location + ) +{ + EFI_STATUS Status; + EDKII_JSON_VALUE JsonValue; + EDKII_JSON_VALUE OdataValue; + CHAR8 *OdataString; + CHAR8 *AsciiLocation; + EFI_HTTP_HEADER *Header; + + if ((Response =3D=3D NULL) || (Location =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D EFI_SUCCESS; + *Location =3D NULL; + AsciiLocation =3D NULL; + if (*(Response->StatusCode) =3D=3D HTTP_STATUS_200_OK) { + Header =3D HttpFindHeader (Response->HeaderCount, Response->Headers, H= TTP_HEADER_LOCATION); + if (Header !=3D NULL) { + AsciiLocation =3D AllocateCopyPool (AsciiStrSize (Header->FieldValue= ), Header->FieldValue); + ASSERT (AsciiLocation !=3D NULL); } + } =20 - // - // No header is returned. Search payload for location. - // - if ((*Location =3D=3D NULL) && (Response->Payload !=3D NULL)) { - JsonValue =3D RedfishJsonInPayload (Response->Payload); - if (JsonValue !=3D NULL) { - OdataValue =3D JsonObjectGetValue (JsonValueGetObject (JsonValue),= "@odata.id"); - if (OdataValue !=3D NULL) { - OdataString =3D (CHAR8 *)JsonValueGetAsciiString (OdataValue); - if (OdataString !=3D NULL) { - AsciiLocation =3D AllocateCopyPool (AsciiStrSize (OdataString)= , OdataString); - ASSERT (AsciiLocation !=3D NULL); - } + // + // No header is returned. Search payload for location. + // + if ((*Location =3D=3D NULL) && (Response->Payload !=3D NULL)) { + JsonValue =3D RedfishJsonInPayload (Response->Payload); + if (JsonValue !=3D NULL) { + OdataValue =3D JsonObjectGetValue (JsonValueGetObject (JsonValue), "= @odata.id"); + if (OdataValue !=3D NULL) { + OdataString =3D (CHAR8 *)JsonValueGetAsciiString (OdataValue); + if (OdataString !=3D NULL) { + AsciiLocation =3D AllocateCopyPool (AsciiStrSize (OdataString), = OdataString); + ASSERT (AsciiLocation !=3D NULL); } - - JsonValueFree (JsonValue); } - } =20 - if (AsciiLocation !=3D NULL) { - *Location =3D StrAsciiToUnicode (AsciiLocation); - FreePool (AsciiLocation); - } else { - Status =3D EFI_NOT_FOUND; + JsonValueFree (JsonValue); } } =20 + if (AsciiLocation !=3D NULL) { + *Location =3D StrAsciiToUnicode (AsciiLocation); + FreePool (AsciiLocation); + } else { + Status =3D EFI_NOT_FOUND; + DEBUG ((DEBUG_ERROR, "%a: Failed to retrieve Location from HTTP respon= se paylaod.\n", __func__)); + } + return Status; } =20 +/** + + This function returns a boolean of ETAG support on Redfish service side. + + @retval TRUE ETAG is supported on Redfish service. + @retval FALSE ETAG is not supported on Redfish service. + +**/ +BOOLEAN +CheckIsServerEtagSupported ( + VOID + ) +{ + return FixedPcdGetBool (PcdRedfishServiceEtagSupported); +} + /** =20 Create HTTP payload and send them to redfish service with PATCH method. @@ -1861,7 +1914,7 @@ CreatePayloadToPatchResource ( { REDFISH_PAYLOAD Payload; EDKII_JSON_VALUE ResourceJsonValue; - REDFISH_RESPONSE PostResponse; + REDFISH_RESPONSE PatchResponse; EFI_STATUS Status; =20 if ((Service =3D=3D NULL) || (TargetPayload =3D=3D NULL) || IS_EMPTY_STR= ING (Json)) { @@ -1876,8 +1929,8 @@ CreatePayloadToPatchResource ( goto EXIT_FREE_JSON_VALUE; } =20 - ZeroMem (&PostResponse, sizeof (REDFISH_RESPONSE)); - Status =3D RedfishPatchToPayload (TargetPayload, Payload, &PostResponse)= ; + ZeroMem (&PatchResponse, sizeof (REDFISH_RESPONSE)); + Status =3D RedfishPatchToPayload (TargetPayload, Payload, &PatchResponse= ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a:%d Failed to PATCH payload to Redfish service= .\n", __func__, __LINE__)); =20 @@ -1885,7 +1938,7 @@ CreatePayloadToPatchResource ( DEBUG ((DEBUG_ERROR, "%a: Request:\n", __func__)); DumpRedfishPayload (DEBUG_ERROR, Payload); DEBUG ((DEBUG_ERROR, "%a: Response:\n", __func__)); - DumpRedfishResponse (__func__, DEBUG_ERROR, &PostResponse); + DumpRedfishResponse (__func__, DEBUG_ERROR, &PatchResponse); DEBUG_CODE_END (); goto EXIT_FREE_JSON_VALUE; } @@ -1893,16 +1946,20 @@ CreatePayloadToPatchResource ( // // Find ETag // - Status =3D GetEtagAndLocation (&PostResponse, Etag, NULL); - if (EFI_ERROR (Status)) { + Status =3D GetHttpResponseEtag (&PatchResponse, Etag); + if (Status =3D=3D EFI_UNSUPPORTED) { + Status =3D EFI_SUCCESS; + DEBUG ((DEBUG_INFO, "%a: WARNING - ETAG is not supported on Redfish se= rvice.\n", __func__)); + } else { Status =3D EFI_DEVICE_ERROR; + DEBUG ((DEBUG_ERROR, "%a: Fail to get Location header nor proerty from= HTTP response payload.\n", __func__)); } =20 RedfishFreeResponse ( - PostResponse.StatusCode, - PostResponse.HeaderCount, - PostResponse.Headers, - PostResponse.Payload + PatchResponse.StatusCode, + PatchResponse.HeaderCount, + PatchResponse.Headers, + PatchResponse.Payload ); =20 EXIT_FREE_JSON_VALUE: @@ -1935,7 +1992,7 @@ CreatePayloadToPostResource ( IN REDFISH_PAYLOAD *TargetPayload, IN CHAR8 *Json, OUT EFI_STRING *Location, - OUT CHAR8 **Etag + OUT CHAR8 **Etag OPTIONAL ) { REDFISH_PAYLOAD Payload; @@ -1943,7 +2000,7 @@ CreatePayloadToPostResource ( REDFISH_RESPONSE PostResponse; EFI_STATUS Status; =20 - if ((Service =3D=3D NULL) || (TargetPayload =3D=3D NULL) || IS_EMPTY_STR= ING (Json) || (Location =3D=3D NULL) || (Etag =3D=3D NULL)) { + if ((Service =3D=3D NULL) || (TargetPayload =3D=3D NULL) || IS_EMPTY_STR= ING (Json) || (Location =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } =20 @@ -1970,12 +2027,22 @@ CreatePayloadToPostResource ( goto EXIT_FREE_JSON_VALUE; } =20 + Status =3D GetHttpResponseEtag (&PostResponse, Etag); + if (Status =3D=3D EFI_UNSUPPORTED) { + Status =3D EFI_SUCCESS; + DEBUG ((DEBUG_INFO, "%a: WARNING - ETAG is not supported on Redfish se= rvice.\n", __func__)); + } else if (EFI_ERROR (Status)) { + Status =3D EFI_DEVICE_ERROR; + DEBUG ((DEBUG_ERROR, "%a: Fail to get ETAG header nor ETAG propertyfro= m HTTP response payload.\n", __func__)); + } + // // per Redfish spec. the URL of new resource will be returned in "Locati= on" header. // - Status =3D GetEtagAndLocation (&PostResponse, Etag, Location); + Status =3D GetHttpResponseLocation (&PostResponse, Location); if (EFI_ERROR (Status)) { Status =3D EFI_DEVICE_ERROR; + DEBUG ((DEBUG_ERROR, "%a: Fail to get Location header nor proerty from= HTTP response payload.\n", __func__)); } =20 RedfishFreeResponse ( @@ -3117,6 +3184,11 @@ CheckEtag ( { CHAR8 *EtagInDb; =20 + if (!CheckIsServerEtagSupported ()) { + DEBUG ((DEBUG_INFO, "%a: WARNING - ETAG is not supported, always retur= ns FALSE to consume resource (Performance would be reduced).\n", __func__))= ; + return FALSE; + } + if (IS_EMPTY_STRING (Uri)) { return FALSE; } --=20 2.37.1.windows.1 -=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 (#113153): https://edk2.groups.io/g/devel/message/113153 Mute This Topic: https://groups.io/mt/103519287/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-