From 16876a52adaf70e44d31bd065291d918aedf59cd Mon Sep 17 00:00:00 2001 From: Nickle Wang Date: Mon, 6 Nov 2023 17:35:53 +0800 Subject: [PATCH] RedfishClientPkg/Features: use Redfish HTTP protocol Use Redfish HTTP protocol to query Redfish resources in Redfish feature drivers. This takes the benefit of reusing cached HTTP response from other feature drivers. By reducing the number of HTTP operation, this improves the Redfish performance. Signed-off-by: Nickle Wang Cc: Abner Chang Cc: Igor Kulchytskyy Cc: Nick Ramirez --- .../Features/Bios/v1_0_9/Common/BiosCommon.c | 76 +++++++++++++------ .../Features/Bios/v1_0_9/Dxe/BiosDxe.c | 59 +++++--------- .../Features/Bios/v1_0_9/Dxe/BiosDxe.inf | 1 + .../v1_5_0/Common/ComputerSystemCommon.c | 70 ++++++++++++----- .../v1_5_0/Dxe/ComputerSystemDxe.c | 50 ++++-------- .../v1_5_0/Dxe/ComputerSystemDxe.inf | 3 +- .../ComputerSystemCollectionDxe.c | 14 +--- .../ComputerSystemCollectionDxe.inf | 2 + .../Memory/V1_7_1/Common/MemoryCommon.c | 70 ++++++++++++----- .../Features/Memory/V1_7_1/Dxe/MemoryDxe.c | 50 ++++-------- .../Features/Memory/V1_7_1/Dxe/MemoryDxe.inf | 3 +- .../MemoryCollectionDxe/MemoryCollectionDxe.c | 14 +--- .../MemoryCollectionDxe.inf | 2 + .../Include/RedfishCollectionCommon.h | 2 + .../Include/RedfishResourceCommon.h | 1 + 15 files changed, 221 insertions(+), 196 deletions(-) diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c index 98288d663..3b6eab3fd 100644 --- a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c @@ -267,18 +267,22 @@ ProvisioningBiosResource ( IN EFI_STRING ConfigureLang ) { - CHAR8 *Json; - CHAR8 *JsonWithAddendum; - EFI_STATUS Status; - EFI_STRING NewResourceLocation; - CHAR8 *EtagStr; - CHAR8 ResourceId[16]; + CHAR8 *Json; + CHAR8 *JsonWithAddendum; + EFI_STATUS Status; + EFI_STRING NewResourceLocation; + CHAR8 *EtagStr; + CHAR8 ResourceId[16]; + REDFISH_RESPONSE Response; if (IS_EMPTY_STRING (ConfigureLang) || (Private == NULL)) { return EFI_INVALID_PARAMETER; } - EtagStr = NULL; + EtagStr = NULL; + Json = NULL; + NewResourceLocation = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); AsciiSPrint (ResourceId, sizeof (ResourceId), "%d", Index); Status = ProvisioningBiosProperties ( @@ -326,12 +330,18 @@ ProvisioningBiosResource ( JsonWithAddendum = NULL; } - Status = CreatePayloadToPostResource (Private->RedfishService, Private->Payload, Json, &NewResourceLocation, &EtagStr); + Status = RedfishHttpPostResource (Private->RedfishService, Private->Uri, Json, &Response); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, post Bios resource for %s failed: %r\n", __func__, ConfigureLang, Status)); goto RELEASE_RESOURCE; } + Status = GetEtagAndLocation (&Response, &EtagStr, &NewResourceLocation); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get ETag and location failed: %r\n", __func__, Status)); + goto RELEASE_RESOURCE; + } + ASSERT (NewResourceLocation != NULL); // @@ -359,6 +369,8 @@ ProvisioningBiosResource ( FreePool (Json); } + RedfishHttpFreeResource (&Response); + return Status; } @@ -401,11 +413,12 @@ ProvisioningBiosExistResource ( IN REDFISH_RESOURCE_COMMON_PRIVATE *Private ) { - EFI_STATUS Status; - EFI_STRING ConfigureLang; - CHAR8 *EtagStr; - CHAR8 *Json; - CHAR8 *JsonWithAddendum; + EFI_STATUS Status; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + CHAR8 *Json; + CHAR8 *JsonWithAddendum; + REDFISH_RESPONSE Response; if (Private == NULL) { return EFI_INVALID_PARAMETER; @@ -414,6 +427,7 @@ ProvisioningBiosExistResource ( EtagStr = NULL; Json = NULL; ConfigureLang = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); ConfigureLang = RedfishGetConfigLanguage (Private->Uri); if (ConfigureLang == NULL) { @@ -472,13 +486,19 @@ ProvisioningBiosExistResource ( DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for %s\n", __func__, ConfigureLang)); // - // PUT back to instance + // PATCH back to instance // - Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr); + Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status)); } + Status = GetEtagAndLocation (&Response, &EtagStr, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get ETag failed: %r\n", __func__, Status)); + goto ON_RELEASE; + } + // // Handle Etag // @@ -497,6 +517,8 @@ ProvisioningBiosExistResource ( FreePool (ConfigureLang); } + RedfishHttpFreeResource (&Response); + return Status; } @@ -595,11 +617,12 @@ RedfishUpdateResourceCommon ( IN CHAR8 *InputJson ) { - EFI_STATUS Status; - CHAR8 *Json; - CHAR8 *JsonWithAddendum; - EFI_STRING ConfigureLang; - CHAR8 *EtagStr; + EFI_STATUS Status; + CHAR8 *Json; + CHAR8 *JsonWithAddendum; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + REDFISH_RESPONSE Response; if ((Private == NULL) || IS_EMPTY_STRING (InputJson)) { return EFI_INVALID_PARAMETER; @@ -608,6 +631,7 @@ RedfishUpdateResourceCommon ( EtagStr = NULL; Json = NULL; ConfigureLang = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); ConfigureLang = RedfishGetConfigLanguage (Private->Uri); if (ConfigureLang == NULL) { @@ -666,13 +690,19 @@ RedfishUpdateResourceCommon ( DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s\n", __func__, ConfigureLang)); // - // PUT back to instance + // PATCH back to instance // - Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr); + Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status)); } + Status = GetEtagAndLocation (&Response, &EtagStr, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get ETag failed: %r\n", __func__, Status)); + goto ON_RELEASE; + } + // // Handle Etag // @@ -691,6 +721,8 @@ RedfishUpdateResourceCommon ( FreePool (ConfigureLang); } + RedfishHttpFreeResource (&Response); + return Status; } diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c index 9b336d3de..ee294c4bb 100644 --- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c @@ -56,7 +56,8 @@ RedfishResourceProvisioningResource ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -72,12 +73,7 @@ RedfishResourceProvisioningResource ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -122,7 +118,8 @@ RedfishResourceConsumeResource ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -151,7 +148,7 @@ RedfishResourceConsumeResource ( // RedfishSettingsUri = JsonValueGetUnicodeString (JsonValue); - Status = GetResourceByUri (Private->RedfishService, RedfishSettingsUri, &RedfishSettingsResponse); + Status = RedfishHttpGetResource (Private->RedfishService, RedfishSettingsUri, &RedfishSettingsResponse, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, @Redfish.Settings exists, get resource from: %s failed\n", __FUNCTION__, RedfishSettingsUri)); } else { @@ -195,21 +192,11 @@ RedfishResourceConsumeResource ( // if (Private->Payload != NULL) { if (Response.Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); } if (RedfishSettingsResponse.Payload != NULL) { - RedfishFreeResponse ( - RedfishSettingsResponse.StatusCode, - RedfishSettingsResponse.HeaderCount, - RedfishSettingsResponse.Headers, - RedfishSettingsResponse.Payload - ); + RedfishHttpFreeResource (&RedfishSettingsResponse); } Private->Payload = NULL; @@ -290,7 +277,8 @@ RedfishResourceUpdate ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -312,12 +300,7 @@ RedfishResourceUpdate ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -360,7 +343,8 @@ RedfishResourceCheck ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -382,12 +366,7 @@ RedfishResourceCheck ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -431,7 +410,8 @@ RedfishResourceIdentify ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -453,12 +433,7 @@ RedfishResourceIdentify ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf index 37346e50f..dbb032923 100644 --- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf @@ -39,6 +39,7 @@ UefiLib UefiDriverEntryPoint RedfishAddendumLib + RedfishHttpLib [Protocols] gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED diff --git a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Common/ComputerSystemCommon.c b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Common/ComputerSystemCommon.c index ca6d3bc30..4f0a81aec 100644 --- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Common/ComputerSystemCommon.c +++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Common/ComputerSystemCommon.c @@ -1237,17 +1237,21 @@ ProvisioningComputerSystemResource ( IN EFI_STRING ConfigureLang ) { - CHAR8 *Json; - EFI_STATUS Status; - EFI_STRING NewResourceLocation; - CHAR8 *EtagStr; - CHAR8 ResourceId[16]; + CHAR8 *Json; + EFI_STATUS Status; + EFI_STRING NewResourceLocation; + CHAR8 *EtagStr; + CHAR8 ResourceId[16]; + REDFISH_RESPONSE Response; if (IS_EMPTY_STRING (ConfigureLang) || (Private == NULL)) { return EFI_INVALID_PARAMETER; } - EtagStr = NULL; + EtagStr = NULL; + Json = NULL; + NewResourceLocation = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); AsciiSPrint (ResourceId, sizeof (ResourceId), "%d", Index); Status = ProvisioningComputerSystemProperties ( @@ -1263,12 +1267,18 @@ ProvisioningComputerSystemResource ( return Status; } - Status = CreatePayloadToPostResource (Private->RedfishService, Private->Payload, Json, &NewResourceLocation, &EtagStr); + Status = RedfishHttpPostResource (Private->RedfishService, Private->Uri, Json, &Response); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, post ComputerSystem resource for %s failed: %r\n", __func__, ConfigureLang, Status)); goto RELEASE_RESOURCE; } + Status = GetEtagAndLocation (&Response, &EtagStr, &NewResourceLocation); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get ETag and location failed: %r\n", __func__, Status)); + goto RELEASE_RESOURCE; + } + ASSERT (NewResourceLocation != NULL); // @@ -1296,6 +1306,8 @@ ProvisioningComputerSystemResource ( FreePool (Json); } + RedfishHttpFreeResource (&Response); + return Status; } @@ -1338,10 +1350,11 @@ ProvisioningComputerSystemExistResource ( IN REDFISH_RESOURCE_COMMON_PRIVATE *Private ) { - EFI_STATUS Status; - EFI_STRING ConfigureLang; - CHAR8 *EtagStr; - CHAR8 *Json; + EFI_STATUS Status; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + CHAR8 *Json; + REDFISH_RESPONSE Response; if (Private == NULL) { return EFI_INVALID_PARAMETER; @@ -1350,6 +1363,7 @@ ProvisioningComputerSystemExistResource ( EtagStr = NULL; Json = NULL; ConfigureLang = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); ConfigureLang = RedfishGetConfigLanguage (Private->Uri); if (ConfigureLang == NULL) { @@ -1376,13 +1390,19 @@ ProvisioningComputerSystemExistResource ( DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for %s\n", __func__, ConfigureLang)); // - // PUT back to instance + // PATCH back to instance // - Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr); + Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status)); } + Status = GetEtagAndLocation (&Response, &EtagStr, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get ETag failed: %r\n", __func__, Status)); + goto ON_RELEASE; + } + // // Handle Etag // @@ -1401,6 +1421,8 @@ ProvisioningComputerSystemExistResource ( FreePool (ConfigureLang); } + RedfishHttpFreeResource (&Response); + return Status; } @@ -1499,10 +1521,11 @@ RedfishUpdateResourceCommon ( IN CHAR8 *InputJson ) { - EFI_STATUS Status; - CHAR8 *Json; - EFI_STRING ConfigureLang; - CHAR8 *EtagStr; + EFI_STATUS Status; + CHAR8 *Json; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + REDFISH_RESPONSE Response; if ((Private == NULL) || IS_EMPTY_STRING (InputJson)) { return EFI_INVALID_PARAMETER; @@ -1511,6 +1534,7 @@ RedfishUpdateResourceCommon ( EtagStr = NULL; Json = NULL; ConfigureLang = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); ConfigureLang = RedfishGetConfigLanguage (Private->Uri); if (ConfigureLang == NULL) { @@ -1537,13 +1561,19 @@ RedfishUpdateResourceCommon ( DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s\n", __func__, ConfigureLang)); // - // PUT back to instance + // PATCH back to instance // - Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr); + Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status)); } + Status = GetEtagAndLocation (&Response, &EtagStr, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get ETag failed: %r\n", __func__, Status)); + goto ON_RELEASE; + } + // // Handle Etag // @@ -1562,6 +1592,8 @@ RedfishUpdateResourceCommon ( FreePool (ConfigureLang); } + RedfishHttpFreeResource (&Response); + return Status; } diff --git a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c index 5c2a4eadf..b28082fee 100644 --- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c +++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c @@ -50,7 +50,8 @@ RedfishResourceProvisioningResource ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -66,12 +67,7 @@ RedfishResourceProvisioningResource ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -110,7 +106,8 @@ RedfishResourceConsumeResource ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -150,12 +147,7 @@ RedfishResourceConsumeResource ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -234,7 +226,8 @@ RedfishResourceUpdate ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -256,12 +249,7 @@ RedfishResourceUpdate ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -304,7 +292,8 @@ RedfishResourceCheck ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -326,12 +315,7 @@ RedfishResourceCheck ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -375,7 +359,8 @@ RedfishResourceIdentify ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -397,12 +382,7 @@ RedfishResourceIdentify ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } diff --git a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.inf b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.inf index 67412f5f3..2c8882995 100644 --- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.inf +++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.inf @@ -1,6 +1,7 @@ ## @file # # (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -36,7 +37,7 @@ RedfishResourceIdentifyLib UefiLib UefiDriverEntryPoint - + RedfishHttpLib [Protocols] gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED diff --git a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c index 1e362d49c..e4fe6965a 100644 --- a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c +++ b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c @@ -247,16 +247,7 @@ ReleaseCollectionResource ( // Release resource // if (Private->RedResponse.Payload != NULL) { - RedfishFreeResponse ( - Private->RedResponse.StatusCode, - Private->RedResponse.HeaderCount, - Private->RedResponse.Headers, - Private->RedResponse.Payload - ); - Private->RedResponse.StatusCode = NULL; - Private->RedResponse.HeaderCount = 0; - Private->RedResponse.Headers = NULL; - Private->RedResponse.Payload = NULL; + RedfishHttpFreeResource (&Private->RedResponse); } if (Private->CollectionJson != NULL) { @@ -288,7 +279,8 @@ CollectionHandler ( // // Query collection from Redfish service. // - Status = GetResourceByUri (Private->RedfishService, Private->CollectionUri, &Private->RedResponse); + ZeroMem (&Private->RedResponse, sizeof (Private->RedResponse)); + Status = RedfishHttpGetResource (Private->RedfishService, Private->CollectionUri, &Private->RedResponse, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, unable to get resource from: %s :%r\n", __func__, Private->CollectionUri, Status)); goto ON_RELEASE; diff --git a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.inf b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.inf index 107d6c076..4d5e47ca9 100644 --- a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.inf +++ b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.inf @@ -3,6 +3,7 @@ # Redfish ComputerSystemCollection collection driver. # # (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -40,6 +41,7 @@ UefiBootServicesTableLib EdkIIRedfishResourceConfigLib RedfishVersionLib + RedfishHttpLib [Protocols] gEdkIIRedfishConfigHandlerProtocolGuid ## CONSUMED diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c b/RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c index 1b6f4c4ad..5e4aeeb21 100644 --- a/RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c +++ b/RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c @@ -2153,17 +2153,21 @@ ProvisioningMemoryResource ( IN EFI_STRING ConfigureLang ) { - CHAR8 *Json; - EFI_STATUS Status; - EFI_STRING NewResourceLocation; - CHAR8 *EtagStr; - CHAR8 ResourceId[16]; + CHAR8 *Json; + EFI_STATUS Status; + EFI_STRING NewResourceLocation; + CHAR8 *EtagStr; + CHAR8 ResourceId[16]; + REDFISH_RESPONSE Response; if (IS_EMPTY_STRING (ConfigureLang) || (Private == NULL)) { return EFI_INVALID_PARAMETER; } - EtagStr = NULL; + EtagStr = NULL; + Json = NULL; + NewResourceLocation = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); AsciiSPrint (ResourceId, sizeof (ResourceId), "%d", Index); Status = ProvisioningMemoryProperties ( @@ -2179,12 +2183,18 @@ ProvisioningMemoryResource ( return Status; } - Status = CreatePayloadToPostResource (Private->RedfishService, Private->Payload, Json, &NewResourceLocation, &EtagStr); + Status = RedfishHttpPostResource (Private->RedfishService, Private->Uri, Json, &Response); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, post Memory resource for %s failed: %r\n", __func__, ConfigureLang, Status)); goto RELEASE_RESOURCE; } + Status = GetEtagAndLocation (&Response, &EtagStr, &NewResourceLocation); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get ETag and location failed: %r\n", __func__, Status)); + goto RELEASE_RESOURCE; + } + ASSERT (NewResourceLocation != NULL); // @@ -2212,6 +2222,8 @@ ProvisioningMemoryResource ( FreePool (Json); } + RedfishHttpFreeResource (&Response); + return Status; } @@ -2254,10 +2266,11 @@ ProvisioningMemoryExistResource ( IN REDFISH_RESOURCE_COMMON_PRIVATE *Private ) { - EFI_STATUS Status; - EFI_STRING ConfigureLang; - CHAR8 *EtagStr; - CHAR8 *Json; + EFI_STATUS Status; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + CHAR8 *Json; + REDFISH_RESPONSE Response; if (Private == NULL) { return EFI_INVALID_PARAMETER; @@ -2266,6 +2279,7 @@ ProvisioningMemoryExistResource ( EtagStr = NULL; Json = NULL; ConfigureLang = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); ConfigureLang = RedfishGetConfigLanguage (Private->Uri); if (ConfigureLang == NULL) { @@ -2292,13 +2306,19 @@ ProvisioningMemoryExistResource ( DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for %s\n", __func__, ConfigureLang)); // - // PUT back to instance + // PATCH back to instance // - Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr); + Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status)); } + Status = GetEtagAndLocation (&Response, &EtagStr, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get ETag failed: %r\n", __func__, Status)); + goto ON_RELEASE; + } + // // Handle Etag // @@ -2317,6 +2337,8 @@ ProvisioningMemoryExistResource ( FreePool (ConfigureLang); } + RedfishHttpFreeResource (&Response); + return Status; } @@ -2415,10 +2437,11 @@ RedfishUpdateResourceCommon ( IN CHAR8 *InputJson ) { - EFI_STATUS Status; - CHAR8 *Json; - EFI_STRING ConfigureLang; - CHAR8 *EtagStr; + EFI_STATUS Status; + CHAR8 *Json; + EFI_STRING ConfigureLang; + CHAR8 *EtagStr; + REDFISH_RESPONSE Response; if ((Private == NULL) || IS_EMPTY_STRING (InputJson)) { return EFI_INVALID_PARAMETER; @@ -2427,6 +2450,7 @@ RedfishUpdateResourceCommon ( EtagStr = NULL; Json = NULL; ConfigureLang = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); ConfigureLang = RedfishGetConfigLanguage (Private->Uri); if (ConfigureLang == NULL) { @@ -2453,13 +2477,19 @@ RedfishUpdateResourceCommon ( DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s\n", __func__, ConfigureLang)); // - // PUT back to instance + // PATCH back to instance // - Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr); + Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status)); } + Status = GetEtagAndLocation (&Response, &EtagStr, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a, get ETag failed: %r\n", __func__, Status)); + goto ON_RELEASE; + } + // // Handle Etag // @@ -2478,6 +2508,8 @@ RedfishUpdateResourceCommon ( FreePool (ConfigureLang); } + RedfishHttpFreeResource (&Response); + return Status; } diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c index f34f3266f..b09727092 100644 --- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c +++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c @@ -50,7 +50,8 @@ RedfishResourceProvisioningResource ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -66,12 +67,7 @@ RedfishResourceProvisioningResource ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -110,7 +106,8 @@ RedfishResourceConsumeResource ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -150,12 +147,7 @@ RedfishResourceConsumeResource ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -234,7 +226,8 @@ RedfishResourceUpdate ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -256,12 +249,7 @@ RedfishResourceUpdate ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -304,7 +292,8 @@ RedfishResourceCheck ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -326,12 +315,7 @@ RedfishResourceCheck ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } @@ -375,7 +359,8 @@ RedfishResourceIdentify ( return EFI_NOT_READY; } - Status = GetResourceByUri (Private->RedfishService, Uri, &Response); + ZeroMem (&Response, sizeof (Response)); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -397,12 +382,7 @@ RedfishResourceIdentify ( // Release resource // if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); + RedfishHttpFreeResource (&Response); Private->Payload = NULL; } diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf index 594a87490..ab862f694 100644 --- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf +++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf @@ -1,6 +1,7 @@ ## @file # # (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -36,7 +37,7 @@ RedfishResourceIdentifyLib UefiLib UefiDriverEntryPoint - + RedfishHttpLib [Protocols] gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED diff --git a/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.c b/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.c index 1b755cde0..dce555af6 100644 --- a/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.c +++ b/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.c @@ -247,16 +247,7 @@ ReleaseCollectionResource ( // Release resource // if (Private->RedResponse.Payload != NULL) { - RedfishFreeResponse ( - Private->RedResponse.StatusCode, - Private->RedResponse.HeaderCount, - Private->RedResponse.Headers, - Private->RedResponse.Payload - ); - Private->RedResponse.StatusCode = NULL; - Private->RedResponse.HeaderCount = 0; - Private->RedResponse.Headers = NULL; - Private->RedResponse.Payload = NULL; + RedfishHttpFreeResource (&Private->RedResponse); } if (Private->CollectionJson != NULL) { @@ -288,7 +279,8 @@ CollectionHandler ( // // Query collection from Redfish service. // - Status = GetResourceByUri (Private->RedfishService, Private->CollectionUri, &Private->RedResponse); + ZeroMem (&Private->RedResponse, sizeof (Private->RedResponse)); + Status = RedfishHttpGetResource (Private->RedfishService, Private->CollectionUri, &Private->RedResponse, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, unable to get resource from: %s :%r\n", __func__, Private->CollectionUri, Status)); goto ON_RELEASE; diff --git a/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.inf b/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.inf index 05e05712e..099116783 100644 --- a/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.inf +++ b/RedfishClientPkg/Features/MemoryCollectionDxe/MemoryCollectionDxe.inf @@ -3,6 +3,7 @@ # Redfish MemoryCollection collection driver. # # (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -40,6 +41,7 @@ UefiBootServicesTableLib EdkIIRedfishResourceConfigLib RedfishVersionLib + RedfishHttpLib [Protocols] gEdkIIRedfishConfigHandlerProtocolGuid ## CONSUMED diff --git a/RedfishClientPkg/Include/RedfishCollectionCommon.h b/RedfishClientPkg/Include/RedfishCollectionCommon.h index 59cc3607f..f7730aef0 100644 --- a/RedfishClientPkg/Include/RedfishCollectionCommon.h +++ b/RedfishClientPkg/Include/RedfishCollectionCommon.h @@ -2,6 +2,7 @@ Redfish feature driver collection common header file. (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -26,6 +27,7 @@ #include #include #include +#include // // Protocols diff --git a/RedfishClientPkg/Include/RedfishResourceCommon.h b/RedfishClientPkg/Include/RedfishResourceCommon.h index b006755d6..6c20aa072 100644 --- a/RedfishClientPkg/Include/RedfishResourceCommon.h +++ b/RedfishClientPkg/Include/RedfishResourceCommon.h @@ -32,6 +32,7 @@ #include #include #include +#include // // Protocols