Skip to content

Commit

Permalink
RedfishClientPkg/MemoryDxe: ues RedfishHttpLib
Browse files Browse the repository at this point in the history
Remove RedfishHttpCacheLib and use EDK2 RedfishHttpLib.

Signed-off-by: Nickle Wang <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
  • Loading branch information
nicklela committed Feb 29, 2024
1 parent f899697 commit 7960d6e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 131 deletions.
86 changes: 37 additions & 49 deletions RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Redfish feature driver implementation - common functions
(C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 (
Expand All @@ -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:
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
111 changes: 31 additions & 80 deletions RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -528,11 +484,6 @@ RedfishResourceStop (
Private->RedfishService = NULL;
}

if (Private->Payload != NULL) {
RedfishCleanupPayload (Private->Payload);
Private->Payload = NULL;
}

return EFI_SUCCESS;
}

Expand Down
Loading

0 comments on commit 7960d6e

Please sign in to comment.