Skip to content

Commit

Permalink
RedfishClientPkg/Features: use RedfishProtocolFeaturesLib
Browse files Browse the repository at this point in the history
- Use RedfishProtocolFeaturesLib in collection feature driver
to get resource all together.
- Use Redfish Resource Config2 Protocol in non-collection feature
driver to receive the resource from collection feature driver.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Reviewed-by: Simon Wang (SW-GPU) <simowang@nvidia.com>
Reviewed-by: Nick Ramirez <nramirez@nvidia.com>
  • Loading branch information
nicklela authored and jgarver committed Dec 6, 2023
1 parent 926bcfd commit f57ebb8
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#include "SecureBootDatabaseCommon.h"

REDFISH_RESOURCE_COMMON_PRIVATE *mRedfishResourcePrivate = NULL;
EFI_HANDLE mRedfishResourceConfigProtocolHandle = NULL;
EDKII_REDFISH_TASK_PROTOCOL *mRedfishTaskProtocol = NULL;
REDFISH_RESOURCE_COMMON_PRIVATE *mRedfishResourcePrivate = NULL;
EFI_HANDLE mRedfishResourceConfig2ProtocolHandle = NULL;
EDKII_REDFISH_TASK_PROTOCOL *mRedfishTaskProtocol = NULL;

/**
This function return the "Members@odata.count" in given collection URI.
Expand Down Expand Up @@ -693,11 +693,6 @@ RedfishProvisioningResourceCommon (
return EFI_INVALID_PARAMETER;
}

Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT);
if (IS_EMPTY_STRING (Private->Json)) {
return EFI_OUT_OF_RESOURCES;
}

RedfishSecureBootKey = NULL;
SecureBootKeyName = NULL;
SecureBootDatabase = NULL;
Expand Down Expand Up @@ -773,10 +768,6 @@ RedfishProvisioningResourceCommon (
);
}

if (Private->Json != NULL) {
FreePool (Private->Json);
}

if (SecureBootKeyName != NULL) {
FreePool (SecureBootKeyName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,29 @@
#include "../Common/SecureBootDatabaseCommon.h"

extern REDFISH_RESOURCE_COMMON_PRIVATE *mRedfishResourcePrivate;
extern EFI_HANDLE mRedfishResourceConfigProtocolHandle;
extern EFI_HANDLE mRedfishResourceConfig2ProtocolHandle;
extern EDKII_REDFISH_TASK_PROTOCOL *mRedfishTaskProtocol;

/**
Provision redfish resource by given URI.
@param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
@param[in] This Pointer to EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL instance.
@param[in] Uri Target URI to create resource.
@param[in] PostMode TRUE if the resource does not exist, post method is used.
FALSE if the resource exist but property is missing, put method is used.
@param[in] JsonText The JSON data in ASCII string format. This is optional.
@param[in] HttpPostMode TRUE if resource does not exist, HTTP POST method is used.
FALSE if the resource exist but some of properties are missing,
HTTP PUT method is used.
@retval EFI_SUCCESS Value is returned successfully.
@retval Others Some error happened.
**/
EFI_STATUS
RedfishResourceProvisioningResource (
IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This,
IN EFI_STRING Uri,
IN BOOLEAN PostMode
IN EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL *This,
IN EFI_STRING Uri,
IN CHAR8 *JsonText OPTIONAL,
IN BOOLEAN HttpPostMode
)
{
REDFISH_RESOURCE_COMMON_PRIVATE *Private;
Expand All @@ -42,23 +45,34 @@ RedfishResourceProvisioningResource (
}

ZeroMem (&Response, sizeof (Response));
Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE_PROTOCOL (This);
Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_RESOURCE2_PROTOCOL (This);

if (Private->RedfishService == NULL) {
return EFI_NOT_READY;
}

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;
if (IS_EMPTY_STRING (JsonText)) {
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->Payload = Response.Payload;
if (Private->Payload != NULL) {
Private->Json = JsonDumpString (RedfishJsonInPayload (Private->Payload), EDKII_JSON_COMPACT);
}
} else {
Private->Payload = NULL;
Private->Json = AllocateCopyPool (AsciiStrSize (JsonText), JsonText);
}

Private->Uri = Uri;
Private->Payload = Response.Payload;
ASSERT (Private->Payload != NULL);
if (IS_EMPTY_STRING (Private->Json)) {
return EFI_OUT_OF_RESOURCES;
}

Status = RedfishProvisioningResourceCommon (Private, !PostMode);
Status = RedfishProvisioningResourceCommon (Private, !HttpPostMode);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to provision resource to: %s: %r\n", __func__, Uri, Status));
}
Expand All @@ -71,6 +85,11 @@ RedfishResourceProvisioningResource (
Private->Payload = NULL;
}

if (Private->Json != NULL) {
FreePool (Private->Json);
Private->Json = NULL;
}

return Status;
}

Expand All @@ -89,8 +108,8 @@ RedfishResourceProvisioningResource (
**/
EFI_STATUS
RedfishResourceGetInfo (
IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This,
OUT REDFISH_SCHEMA_INFO *Info
IN EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL *This,
OUT REDFISH_SCHEMA_INFO *Info
)
{
if ((This == NULL) || (Info == NULL)) {
Expand All @@ -108,17 +127,19 @@ RedfishResourceGetInfo (
/**
Consume resource from given URI.
@param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
@param[in] This Pointer to EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL instance.
@param[in] Uri The target URI to consume.
@param[in] JsonText The JSON data in ASCII string format. This is optional.
@retval EFI_SUCCESS Value is returned successfully.
@retval Others Some error happened.
**/
EFI_STATUS
RedfishResourceConsumeResource (
IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This,
IN EFI_STRING Uri
IN EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL *This,
IN EFI_STRING Uri,
IN CHAR8 *JsonText OPTIONAL
)
{
return EFI_UNSUPPORTED;
Expand All @@ -127,17 +148,19 @@ RedfishResourceConsumeResource (
/**
Update resource to given URI.
@param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
@param[in] This Pointer to EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL instance.
@param[in] Uri The target URI to consume.
@param[in] JsonText The JSON data in ASCII string format. This is optional.
@retval EFI_SUCCESS Value is returned successfully.
@retval Others Some error happened.
**/
EFI_STATUS
RedfishResourceUpdate (
IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This,
IN EFI_STRING Uri
IN EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL *This,
IN EFI_STRING Uri,
IN CHAR8 *JsonText OPTIONAL
)
{
return EFI_UNSUPPORTED;
Expand All @@ -146,17 +169,19 @@ RedfishResourceUpdate (
/**
Check resource on given URI.
@param[in] This Pointer to EFI_HP_REDFISH_HII_PROTOCOL instance.
@param[in] This Pointer to EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL instance.
@param[in] Uri The target URI to consume.
@param[in] JsonText The JSON data in ASCII string format. This is optional.
@retval EFI_SUCCESS Value is returned successfully.
@retval Others Some error happened.
**/
EFI_STATUS
RedfishResourceCheck (
IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This,
IN EFI_STRING Uri
IN EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL *This,
IN EFI_STRING Uri,
IN CHAR8 *JsonText OPTIONAL
)
{
return EFI_UNSUPPORTED;
Expand All @@ -165,8 +190,9 @@ RedfishResourceCheck (
/**
Identify resource on given URI.
@param[in] This Pointer to EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL instance.
@param[in] This Pointer to EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL instance.
@param[in] Uri The target URI to consume.
@param[in] JsonText The JSON data in ASCII string format. This is optional.
@retval EFI_SUCCESS This is target resource which we want to handle.
@retval EFI_UNSUPPORTED This is not the target resource.
Expand All @@ -175,14 +201,16 @@ RedfishResourceCheck (
**/
EFI_STATUS
RedfishResourceIdentify (
IN EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *This,
IN EFI_STRING Uri
IN EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL *This,
IN EFI_STRING Uri,
IN CHAR8 *JsonText OPTIONAL
)
{
return EFI_SUCCESS;
}

EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL mRedfishResourceConfig = {
EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL mRedfishResourceConfig2 = {
EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL_REVISION,
RedfishResourceProvisioningResource,
RedfishResourceConsumeResource,
RedfishResourceUpdate,
Expand Down Expand Up @@ -402,8 +430,8 @@ RedfishResourceUnload (
ImageHandle,
&gEdkIIRedfishConfigHandlerProtocolGuid,
ConfigHandler,
&gEdkIIRedfishResourceConfigProtocolGuid,
&mRedfishResourcePrivate->RedfishResourceConfig,
&gEdkIIRedfishResourceConfig2ProtocolGuid,
&mRedfishResourcePrivate->RedfishResourceConfig2,
NULL
);

Expand Down Expand Up @@ -439,15 +467,15 @@ RedfishResourceEntryPoint (
return EFI_ALREADY_STARTED;
}

mRedfishResourceConfigProtocolHandle = ImageHandle;
mRedfishResourceConfig2ProtocolHandle = ImageHandle;

mRedfishResourcePrivate = AllocateZeroPool (sizeof (REDFISH_RESOURCE_COMMON_PRIVATE));
if (mRedfishResourcePrivate == NULL) {
return EFI_OUT_OF_RESOURCES;
}

CopyMem (&mRedfishResourcePrivate->ConfigHandler, &mRedfishConfigHandler, sizeof (EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL));
CopyMem (&mRedfishResourcePrivate->RedfishResourceConfig, &mRedfishResourceConfig, sizeof (EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL));
CopyMem (&mRedfishResourcePrivate->RedfishResourceConfig2, &mRedfishResourceConfig2, sizeof (EDKII_REDFISH_RESOURCE_CONFIG2_PROTOCOL));

//
// Publish config handler protocol and resource protocol.
Expand All @@ -456,8 +484,8 @@ RedfishResourceEntryPoint (
&ImageHandle,
&gEdkIIRedfishConfigHandlerProtocolGuid,
&mRedfishResourcePrivate->ConfigHandler,
&gEdkIIRedfishResourceConfigProtocolGuid,
&mRedfishResourcePrivate->RedfishResourceConfig,
&gEdkIIRedfishResourceConfig2ProtocolGuid,
&mRedfishResourcePrivate->RedfishResourceConfig2,
NULL
);
if (EFI_ERROR (Status)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
[Protocols]
gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED
gEfiRestJsonStructureProtocolGuid ## CONSUMED
gEdkIIRedfishResourceConfigProtocolGuid ## PRODUCED
gEdkIIRedfishResourceConfig2ProtocolGuid ## PRODUCED
gEdkIIRedfishTaskProtocolGuid ## CONSUMED

[Pcd]
Expand Down
Loading

0 comments on commit f57ebb8

Please sign in to comment.