Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedfishClientPkg: introduce Redfish HTTP cache library #66

Merged
merged 10 commits into from
Jan 4, 2024
82 changes: 36 additions & 46 deletions RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Redfish feature driver implementation - Bios

(C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved.
Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Expand Down Expand Up @@ -55,7 +55,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;
Expand All @@ -77,6 +78,7 @@ RedfishResourceProvisioningResource (
Response.Headers,
Response.Payload
);
RedfishHttpResetResource (Uri);
Private->Payload = NULL;
}

Expand All @@ -103,13 +105,10 @@ RedfishResourceConsumeResource (
REDFISH_RESOURCE_COMMON_PRIVATE *Private;
EFI_STATUS Status;
REDFISH_RESPONSE Response;
EFI_STRING PendingSettingUri;
REDFISH_RESPONSE PendingSettingResponse;
REDFISH_RESPONSE *ExpectedResponse;
REDFISH_RESPONSE RedfishSettingsResponse;
CHAR8 *Etag;
UINTN Index;
EDKII_JSON_VALUE JsonValue;
EFI_STRING RedfishSettingsUri;
CONST CHAR8 *RedfishSettingsUriKeys[] = { "@Redfish.Settings", "SettingsObject", "@odata.id" };

if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
return EFI_INVALID_PARAMETER;
Expand All @@ -121,45 +120,32 @@ 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;
}

ZeroMem (&RedfishSettingsResponse, sizeof (REDFISH_RESPONSE));

ExpectedResponse = &Response;
RedfishSettingsUri = NULL;
JsonValue = RedfishJsonInPayload (Response.Payload);

//
// Seeking RedfishSettings URI link.
// Check and see if "@Redfish.Settings" exist or not.
//
for (Index = 0; Index < sizeof (RedfishSettingsUriKeys) / sizeof (*RedfishSettingsUriKeys); Index++) {
if (JsonValue == NULL) {
break;
}

JsonValue = JsonObjectGetValue (JsonValueGetObject (JsonValue), RedfishSettingsUriKeys[Index]);
}

if (JsonValue != NULL) {
//
// Verify RedfishSettings URI link is valid to retrieve resource or not.
//
RedfishSettingsUri = JsonValueGetUnicodeString (JsonValue);

Status = GetResourceByUri (Private->RedfishService, RedfishSettingsUri, &RedfishSettingsResponse);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, @Redfish.Settings exists, get resource from: %s failed\n", __FUNCTION__, RedfishSettingsUri));
} else {
Uri = RedfishSettingsUri;
ExpectedResponse = &RedfishSettingsResponse;
}
ZeroMem (&PendingSettingResponse, sizeof (REDFISH_RESPONSE));
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
if (!EFI_ERROR (Status)) {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", __func__, PendingSettingUri));
Private->Uri = PendingSettingUri;
ExpectedResponse = &PendingSettingResponse;
} else {
Private->Uri = Uri;
ExpectedResponse = &Response;
}

Private->Uri = Uri;
Private->Payload = ExpectedResponse->Payload;
ASSERT (Private->Payload != NULL);

Expand Down Expand Up @@ -202,12 +188,12 @@ RedfishResourceConsumeResource (
);
}

if (RedfishSettingsResponse.Payload != NULL) {
if (PendingSettingResponse.Payload != NULL) {
RedfishFreeResponse (
RedfishSettingsResponse.StatusCode,
RedfishSettingsResponse.HeaderCount,
RedfishSettingsResponse.Headers,
RedfishSettingsResponse.Payload
PendingSettingResponse.StatusCode,
PendingSettingResponse.HeaderCount,
PendingSettingResponse.Headers,
PendingSettingResponse.Payload
);
}

Expand Down Expand Up @@ -289,7 +275,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;
Expand Down Expand Up @@ -317,6 +304,7 @@ RedfishResourceUpdate (
Response.Headers,
Response.Payload
);
RedfishHttpResetResource (Uri);
Private->Payload = NULL;
}

Expand Down Expand Up @@ -359,7 +347,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;
Expand Down Expand Up @@ -430,7 +419,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;
Expand Down Expand Up @@ -695,7 +685,7 @@ RedfishExternalResourceResourceFeatureCallback (
Private->InformationExchange = InformationExchange;

//
// Find Redfish version on BMC
// Find Redfish version on Redfish service.
//
Private->RedfishVersion = RedfishGetVersion (RedfishService);

Expand Down
3 changes: 2 additions & 1 deletion RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## @file
#
# (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 @@ -39,6 +39,7 @@
UefiLib
UefiDriverEntryPoint
RedfishAddendumLib
RedfishHttpCacheLib

[Protocols]
gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Redfish feature driver implementation - ComputerSystem

(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 @@ -49,7 +49,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;
Expand All @@ -71,6 +72,7 @@ RedfishResourceProvisioningResource (
Response.Headers,
Response.Payload
);
RedfishHttpResetResource (Uri);
Private->Payload = NULL;
}

Expand All @@ -97,6 +99,9 @@ RedfishResourceConsumeResource (
REDFISH_RESOURCE_COMMON_PRIVATE *Private;
EFI_STATUS Status;
REDFISH_RESPONSE Response;
EFI_STRING PendingSettingUri;
REDFISH_RESPONSE PendingSettingResponse;
REDFISH_RESPONSE *ExpectedResponse;
CHAR8 *Etag;

if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
Expand All @@ -109,14 +114,33 @@ 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;
}

Private->Uri = Uri;
Private->Payload = Response.Payload;
//
// Check and see if "@Redfish.Settings" exist or not.
//
ZeroMem (&PendingSettingResponse, sizeof (REDFISH_RESPONSE));
Status = GetPendingSettings (
Private->RedfishService,
Response.Payload,
&PendingSettingResponse,
&PendingSettingUri
);
if (!EFI_ERROR (Status)) {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", __func__, PendingSettingUri));
Private->Uri = PendingSettingUri;
ExpectedResponse = &PendingSettingResponse;
} else {
Private->Uri = Uri;
ExpectedResponse = &Response;
}

Private->Payload = ExpectedResponse->Payload;
ASSERT (Private->Payload != NULL);

Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT);
Expand All @@ -126,7 +150,7 @@ RedfishResourceConsumeResource (
// Find etag in HTTP response header
//
Etag = NULL;
Status = GetEtagAndLocation (&Response, &Etag, NULL);
Status = GetEtagAndLocation (ExpectedResponse, &Etag, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __func__));
}
Expand All @@ -149,12 +173,24 @@ RedfishResourceConsumeResource (
// Release resource
//
if (Private->Payload != NULL) {
RedfishFreeResponse (
Response.StatusCode,
Response.HeaderCount,
Response.Headers,
Response.Payload
);
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;
}

Expand Down Expand Up @@ -233,7 +269,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;
Expand Down Expand Up @@ -261,6 +298,7 @@ RedfishResourceUpdate (
Response.Headers,
Response.Payload
);
RedfishHttpResetResource (Uri);
Private->Payload = NULL;
}

Expand Down Expand Up @@ -303,7 +341,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;
Expand Down Expand Up @@ -374,7 +413,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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## @file
#
# (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand Down Expand Up @@ -36,7 +37,7 @@
RedfishResourceIdentifyLib
UefiLib
UefiDriverEntryPoint

RedfishHttpCacheLib

[Protocols]
gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED
Expand Down
Loading