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 598D178003C for ; Mon, 8 Jan 2024 02:49:32 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=7PfX/hxftU5axS1BOH7ODZzhHEihsYoZZsjOzafyMsY=; 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=1704682170; v=1; b=vaXWRF+hdzletspfsdc2GBbbUzz/hHDssRHxedzat8wOeOIjjCfYBCZLSuXboe0sFik95VTP r45t6d8z7NR/q6KiIorVqvHZYEKSQFUc/oeU0gIzWXV0a2fsMhXAPygkl0YiD/1OEfDFm/pHWhm L1KigrnauQDSwf4rMHYL74aE= X-Received: by 127.0.0.2 with SMTP id b4LgYY7687511xL7Z28Cazlm; Sun, 07 Jan 2024 18:49:30 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.58]) by mx.groups.io with SMTP id smtpd.web10.31501.1704682170210759320 for ; Sun, 07 Jan 2024 18:49:30 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jsN5E95WEOEecx+MrM4Wv8aDueLMF+d9iT/XvP4eA89SuKeQa0kYk6V61GKQL11Bz2qz/jMaberU+o5IyiWw6rK4LMGl8UhLB919wuKdnSqDFgQEumChuNLiFXg00DlNSI/yoDSUXx6k9Zyb1ox5gYVv8DWhsgNaCv3rqMcyHJwJvgcgPU/nrGgpwuFVnVehxbf8rrxVewnuvbLHNhDnCrj+XLXcEPEfzbto7WydZEUYGtuIIQuey5qVx3pipiMn+FgwM1ldFVchtfC9d3p9TYNOy4SH+5JgzKtRGYKGcjiYiHhFiqEhIumk33NamXZNMFwY/25EUi6lGub+em6m0Q== 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=gNGOa3Hidx2eBzquHUQ1MGCQv+4pOrXs4Z+gicv1LgM=; b=GjkmK8xug4hg3L0y/4st3AlRd2w7T2CsMHK/RwC0NKuGKuphUWuTOO7EOxGdeuAD4GVfx+d2sGdP+D9YnZAOHunBYDgW4VdnFuZ1DopAJ0G0oAyBfoFzJy1TwDRkfQ+lDWMcgxCjsfQK+8pbPuQozCgcMsdRP/k+HxqQzMxHwKx7JTZCBsAJ6NBX+ue16V+OSIpw8t4BQCLvVFm5eWqOYUdkakfC/ZP5ABCaTjxRNP9DFatAjzaQQGz8vmtPJpKcl4+Iu3RdLGjPUhKb1vVC6dwNbt+DxTS5PiCJI/liV80v7IFus+6R+TihkZ5Zz+v3e3+d4ozso8/VPgRMls0ctg== 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 SA1P222CA0029.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:22c::24) by SA0PR12MB4511.namprd12.prod.outlook.com (2603:10b6:806:95::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.21; Mon, 8 Jan 2024 02:49:27 +0000 X-Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:22c:cafe::a3) by SA1P222CA0029.outlook.office365.com (2603:10b6:806:22c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.21 via Frontend Transport; Mon, 8 Jan 2024 02:49:27 +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 SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7181.13 via Frontend Transport; Mon, 8 Jan 2024 02:49:27 +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; Sun, 7 Jan 2024 20:49:25 -0600 From: "Chang, Abner via groups.io" To: CC: Nickle Wang , Igor Kulchytskyy , Mike Maslenkin Subject: [edk2-devel] [edk2-redfish-client][PATCH V4] RedfishClientPkg: Add ETag PCD and revise Redfish ETag functions Date: Mon, 8 Jan 2024 10:49:13 +0800 Message-ID: <20240108024913.9-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: SA2PEPF00001509:EE_|SA0PR12MB4511:EE_ X-MS-Office365-Filtering-Correlation-Id: 4bf9d287-4847-4272-02e1-08dc0ff46e55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: toZIl6VOwo/ZOUu2eEDr22NNARtPwpmeMDK+kUq5eGZV9Cwz5rzkCmu0J0JR2OSwW60vflAO/cPsJcTojOj5dRuU9kDtD4z7H+H7A8GMOgysMIKoRBsYD2j5yS+625u9ACscEDGbNeupERcGLD3igkoQs8o7jwCOqTYQge2K0cmP1VzQTzoL75ukZpslcPXbfFvtRI6CarAHYWoJqBFOk4mjyAolJ8ylL1v7xHParmUVSmKDV42kIjPC/WaHMtnU16fI+1TIfo40Vaa2GFC8PcPXb4kJYQuSAp38X+Suu1kzBJQfXEMkxwD+slquv9/epyxobTIV13+AlbQnEoIIzprSgsJfOF0MrerOHOY8QqDbikyRvNYG9+Tp4WoMR+WutBEzSiSlCY3Ycl4/B/P76rCUomdQkIUqx76XXxFgM0TH5CBLqibRJ5eF9NH4J70lmOVshn+29ngCeNM4t52X7+geZ2oLCn7JzkjBySJuTj7ex7z0+mk6ym2XcIbFYbHCx7OSnEyXEmgt5D/4nLjrYN+OAWSoiJqhOcoGq2rmM5bU6wdR6TlOFNLr6+5QdihDFuZtDh/Ao3r7rwkPZ+HV8runUY51+pMiVf1+nYtEkMhSzsZqlF130lDnea5SPFhLYBCKZx8FIkyCDpU6s7cZNLLcBsmlbXt9J4A4hE3XDGz7RZCz4PmKUQpKxgRjoAR8/OnFaiRbrolAvjfByZvmfIe6n/cq03gG4QPmeHoV8kRJb+r+7vcmsleAsBItSNjkZcVQDhvNEXMgOQPBZgD5QU+ZwqbAW7paRokqXzNQ2rTL7B2CRFd0K4E6D8zAQnLQ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2024 02:49:27.6644 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4bf9d287-4847-4272-02e1-08dc0ff46e55 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: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4511 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: CdZ92LrIEX8wqmpwyXw7DAnpx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Spam-Flag: yes X-Spam-Level: ************ X-GND-Spam-Score: 190 X-GND-Status: SPAM Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=vaXWRF+h; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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 | 3 + .../RedfishFeatureUtilityLib.inf | 2 + .../Library/RedfishFeatureUtilityLib.h | 47 +++- .../Features/Bios/v1_0_9/Dxe/BiosDxe.c | 19 +- .../v1_0_4/Common/BootOptionCommon.c | 5 +- .../BootOption/v1_0_4/Dxe/BootOptionDxe.c | 17 +- .../v1_5_0/Dxe/ComputerSystemDxe.c | 13 +- .../Features/Memory/V1_7_1/Dxe/MemoryDxe.c | 17 +- .../RedfishFeatureUtilityLib.c | 209 ++++++++++++------ 9 files changed, 204 insertions(+), 128 deletions(-) diff --git a/RedfishClientPkg/RedfishClientPkg.dec b/RedfishClientPkg/Redfi= shClientPkg.dec index b350facae0..ce3b6d9752 100644 --- a/RedfishClientPkg/RedfishClientPkg.dec +++ b/RedfishClientPkg/RedfishClientPkg.dec @@ -3,6 +3,7 @@ # # (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
# Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent ## @@ -76,6 +77,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..63330c8e9d 100644 --- a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.inf +++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.inf @@ -3,6 +3,7 @@ # # (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights re= served. +# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -54,6 +55,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..0f8aede5c4 100644 --- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h +++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h @@ -3,6 +3,7 @@ =20 (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -81,7 +82,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 +560,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 +945,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..f40f2d85af 100644 --- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c @@ -3,6 +3,7 @@ =20 (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -153,14 +154,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 +362,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..0b9f2bf284 100644 --- a/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.c +++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Common/BootOptionCommon.c @@ -3,6 +3,7 @@ =20 (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -455,9 +456,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..dc2bd9da85 100644 --- a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c +++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c @@ -3,6 +3,7 @@ =20 (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved= . + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -154,12 +155,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 +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 ((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..5927b5fa7a 100644 --- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe= .c +++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe= .c @@ -3,6 +3,7 @@ =20 (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -150,11 +151,7 @@ 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__)); - } - + GetHttpResponseEtag (ExpectedResponse, &Etag); Status =3D RedfishConsumeResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { if (Status !=3D EFI_ALREADY_STARTED) { @@ -360,11 +357,7 @@ 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__)); - } - + 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..4a6e342879 100644 --- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c +++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c @@ -3,6 +3,7 @@ =20 (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -149,12 +150,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 +356,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..aa723264e8 100644 --- a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.c +++ b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtili= tyLib.c @@ -3,6 +3,7 @@ =20 (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -133,6 +134,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 +163,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 +247,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 +297,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 +1742,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 +1804,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 +1915,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 +1930,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 +1939,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 +1947,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 Location pro= perty 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 +1993,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 +2001,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 +2028,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 property fr= om 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 Location pro= erty from HTTP response payload.\n", __func__)); } =20 RedfishFreeResponse ( @@ -3117,6 +3185,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 (#113344): https://edk2.groups.io/g/devel/message/113344 Mute This Topic: https://groups.io/mt/103590679/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-