Skip to content

Commit

Permalink
RedfishClientPkg/Features: use Redfish HTTP protocol
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
Cc: Nick Ramirez <[email protected]>
  • Loading branch information
nicklela committed Nov 6, 2023
1 parent daa90b9 commit 16876a5
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 196 deletions.
76 changes: 54 additions & 22 deletions RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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);

//
Expand Down Expand Up @@ -359,6 +369,8 @@ ProvisioningBiosResource (
FreePool (Json);
}

RedfishHttpFreeResource (&Response);

return Status;
}

Expand Down Expand Up @@ -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;
Expand All @@ -414,6 +427,7 @@ ProvisioningBiosExistResource (
EtagStr = NULL;
Json = NULL;
ConfigureLang = NULL;
ZeroMem (&Response, sizeof (REDFISH_RESPONSE));

ConfigureLang = RedfishGetConfigLanguage (Private->Uri);
if (ConfigureLang == NULL) {
Expand Down Expand Up @@ -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
//
Expand All @@ -497,6 +517,8 @@ ProvisioningBiosExistResource (
FreePool (ConfigureLang);
}

RedfishHttpFreeResource (&Response);

return Status;
}

Expand Down Expand Up @@ -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;
Expand All @@ -608,6 +631,7 @@ RedfishUpdateResourceCommon (
EtagStr = NULL;
Json = NULL;
ConfigureLang = NULL;
ZeroMem (&Response, sizeof (REDFISH_RESPONSE));

ConfigureLang = RedfishGetConfigLanguage (Private->Uri);
if (ConfigureLang == NULL) {
Expand Down Expand Up @@ -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
//
Expand All @@ -691,6 +721,8 @@ RedfishUpdateResourceCommon (
FreePool (ConfigureLang);
}

RedfishHttpFreeResource (&Response);

return Status;
}

Expand Down
59 changes: 17 additions & 42 deletions RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
UefiLib
UefiDriverEntryPoint
RedfishAddendumLib
RedfishHttpLib

[Protocols]
gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED
Expand Down
Loading

0 comments on commit 16876a5

Please sign in to comment.