diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c b/RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c index 00a69f748..e873f05ca 100644 --- a/RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c +++ b/RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c @@ -2,7 +2,7 @@ Redfish feature driver implementation - common functions (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
- Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent @@ -67,7 +67,7 @@ RedfishConsumeResourceCommon ( // No change // DEBUG ((DEBUG_MANAGEABILITY, "%a, ETAG: %s has no change, ignore consume action\n", __func__, Private->Uri)); - Status = EFI_ALREADY_STARTED; + Status = EFI_SUCCESS; goto ON_RELEASE; } @@ -2154,17 +2154,17 @@ 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 ResourceId[16]; + REDFISH_RESPONSE Response; if (IS_EMPTY_STRING (ConfigureLang) || (Private == NULL)) { return EFI_INVALID_PARAMETER; } - EtagStr = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); AsciiSPrint (ResourceId, sizeof (ResourceId), "%d", Index); Status = ProvisioningMemoryProperties ( @@ -2180,27 +2180,27 @@ 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)); + DEBUG ((DEBUG_ERROR, "%a, post Bios resource for %s failed: %r\n", __func__, ConfigureLang, Status)); goto RELEASE_RESOURCE; } - ASSERT (NewResourceLocation != NULL); - // - // Keep location of new resource. + // Per Redfish spec. the URL of new resource will be returned in "Location" header. // - if (NewResourceLocation != NULL) { - RedfishSetRedfishUri (ConfigureLang, NewResourceLocation); + Status = GetHttpResponseLocation (&Response, &NewResourceLocation); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: cannot find new location: %r\n", __func__, Status)); + goto RELEASE_RESOURCE; } // - // Handle Etag + // Keep location of new resource. // - if (EtagStr != NULL) { - SetEtagWithUri (EtagStr, NewResourceLocation); - FreePool (EtagStr); + if (NewResourceLocation != NULL) { + DEBUG ((DEBUG_MANAGEABILITY, "%a: Location: %s\n", __func__, NewResourceLocation)); + RedfishSetRedfishUri (ConfigureLang, NewResourceLocation); } RELEASE_RESOURCE: @@ -2255,18 +2255,18 @@ ProvisioningMemoryExistResource ( IN REDFISH_RESOURCE_COMMON_PRIVATE *Private ) { - EFI_STATUS Status; - EFI_STRING ConfigureLang; - CHAR8 *EtagStr; - CHAR8 *Json; + EFI_STATUS Status; + EFI_STRING ConfigureLang; + CHAR8 *Json; + REDFISH_RESPONSE Response; if (Private == NULL) { return EFI_INVALID_PARAMETER; } - EtagStr = NULL; Json = NULL; ConfigureLang = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); ConfigureLang = RedfishGetConfigLanguage (Private->Uri); if (ConfigureLang == NULL) { @@ -2293,23 +2293,17 @@ 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)); } - // - // Handle Etag - // - if (EtagStr != NULL) { - SetEtagWithUri (EtagStr, Private->Uri); - FreePool (EtagStr); - } - ON_RELEASE: + RedfishHttpFreeResponse (&Response); + if (Json != NULL) { FreePool (Json); } @@ -2429,18 +2423,18 @@ RedfishUpdateResourceCommon ( IN CHAR8 *InputJson ) { - EFI_STATUS Status; - CHAR8 *Json; - EFI_STRING ConfigureLang; - CHAR8 *EtagStr; + EFI_STATUS Status; + CHAR8 *Json; + EFI_STRING ConfigureLang; + REDFISH_RESPONSE Response; if ((Private == NULL) || IS_EMPTY_STRING (InputJson)) { return EFI_INVALID_PARAMETER; } - EtagStr = NULL; Json = NULL; ConfigureLang = NULL; + ZeroMem (&Response, sizeof (REDFISH_RESPONSE)); ConfigureLang = RedfishGetConfigLanguage (Private->Uri); if (ConfigureLang == NULL) { @@ -2467,23 +2461,17 @@ 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)); } - // - // Handle Etag - // - if (EtagStr != NULL) { - SetEtagWithUri (EtagStr, Private->Uri); - FreePool (EtagStr); - } - ON_RELEASE: + RedfishHttpFreeResponse (&Response); + if (Json != NULL) { FreePool (Json); } diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c index 4a6e34287..c4a363cdf 100644 --- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c +++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c @@ -51,7 +51,7 @@ RedfishResourceProvisioningResource ( } ZeroMem (&Response, sizeof (Response)); - Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -62,20 +62,20 @@ RedfishResourceProvisioningResource ( ASSERT (Private->Payload != NULL); Status = RedfishProvisioningResourceCommon (Private, !PostMode); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: failed to provision resource to: %s: %r\n", __func__, Uri, Status)); + } else { + // + // Get latest ETag on URI and keep it in variable. + // + SetEtagFromUri (Private->RedfishService, Private->Uri, TRUE); + } // // Release resource // - if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); - RedfishHttpResetResource (Uri); - Private->Payload = NULL; - } + RedfishHttpFreeResponse (&Response); + Private->Payload = NULL; return Status; } @@ -116,7 +116,7 @@ RedfishResourceConsumeResource ( } ZeroMem (&Response, sizeof (Response)); - Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -154,42 +154,15 @@ RedfishResourceConsumeResource ( GetHttpResponseEtag (ExpectedResponse, &Etag); Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag); if (EFI_ERROR (Status)) { - if (Status != EFI_ALREADY_STARTED) { - DEBUG ((DEBUG_ERROR, "%a, failed to consume resource from: %s: %r\n", __func__, Uri, Status)); - } - } else { - // - // Keep etag after consuming pending settings. - // - if (Etag != NULL) { - SetEtagWithUri (Etag, Private->Uri); - } + DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", __func__, Private->Uri, Status)); } // // Release resource // - if (Private->Payload != NULL) { - if (Response.Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); - } - - if (PendingSettingResponse.Payload != NULL) { - RedfishFreeResponse ( - PendingSettingResponse.StatusCode, - PendingSettingResponse.HeaderCount, - PendingSettingResponse.Headers, - PendingSettingResponse.Payload - ); - } - - Private->Payload = NULL; - } + RedfishHttpFreeResponse (&Response); + RedfishHttpFreeResponse (&PendingSettingResponse); + Private->Payload = NULL; if (Private->Json != NULL) { FreePool (Private->Json); @@ -267,7 +240,7 @@ RedfishResourceUpdate ( } ZeroMem (&Response, sizeof (Response)); - Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -282,22 +255,19 @@ RedfishResourceUpdate ( Status = RedfishUpdateResourceCommon (Private, Private->Json); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a, failed to update resource from: %s: %r\n", __func__, Uri, Status)); + DEBUG ((DEBUG_ERROR, "%a: failed to update resource to: %s: %r\n", __func__, Uri, Status)); + } else { + // + // Get latest ETag on URI and keep it in variable. + // + SetEtagFromUri (Private->RedfishService, Private->Uri, TRUE); } // // Release resource // - if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); - RedfishHttpResetResource (Uri); - Private->Payload = NULL; - } + RedfishHttpFreeResponse (&Response); + Private->Payload = NULL; if (Private->Json != NULL) { FreePool (Private->Json); @@ -340,7 +310,7 @@ RedfishResourceCheck ( } ZeroMem (&Response, sizeof (Response)); - Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -366,15 +336,8 @@ RedfishResourceCheck ( // // Release resource // - if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); - Private->Payload = NULL; - } + RedfishHttpFreeResponse (&Response); + Private->Payload = NULL; if (Private->Json != NULL) { FreePool (Private->Json); @@ -417,7 +380,7 @@ RedfishResourceIdentify ( } ZeroMem (&Response, sizeof (Response)); - Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE); + Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri)); return Status; @@ -438,15 +401,8 @@ RedfishResourceIdentify ( // // Release resource // - if (Private->Payload != NULL) { - RedfishFreeResponse ( - Response.StatusCode, - Response.HeaderCount, - Response.Headers, - Response.Payload - ); - Private->Payload = NULL; - } + RedfishHttpFreeResponse (&Response); + Private->Payload = NULL; if (Private->Json != NULL) { FreePool (Private->Json); @@ -528,11 +484,6 @@ RedfishResourceStop ( Private->RedfishService = NULL; } - if (Private->Payload != NULL) { - RedfishCleanupPayload (Private->Payload); - Private->Payload = NULL; - } - return EFI_SUCCESS; } diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf index 43039b9f4..687c1a39d 100644 --- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf +++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf @@ -32,12 +32,11 @@ BaseMemoryLib DebugLib EdkIIRedfishResourceConfigLib - RedfishLib + RedfishHttpLib RedfishFeatureUtilityLib RedfishResourceIdentifyLib UefiLib UefiDriverEntryPoint - RedfishHttpCacheLib [Protocols] gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED