Skip to content

Commit

Permalink
RedfishClientPkg/Memory: implement compatible schema support.
Browse files Browse the repository at this point in the history
implement compatible schema support to memory driver.

Signed-off-by: Nickle Wang <[email protected]>
  • Loading branch information
nicklela committed Sep 4, 2024
1 parent 8a194fe commit 0610c20
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 15 deletions.
86 changes: 71 additions & 15 deletions RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ CHAR8 MemoryEmptyJson[] = "{\"@odata.id\": \"\", \"@odata.type\": \"#Memory.v1_

REDFISH_RESOURCE_COMMON_PRIVATE *mRedfishResourcePrivate = NULL;
EFI_HANDLE mRedfishResourceConfigProtocolHandle = NULL;
REDFISH_SCHEMA_INFO mSchemaInfo = {
{ RESOURCE_SCHEMA },
{ RESOURCE_SCHEMA_MAJOR },
{ RESOURCE_SCHEMA_MINOR },
{ RESOURCE_SCHEMA_ERRATA }
};

/**
Consume resource from given URI.
Expand All @@ -37,6 +43,7 @@ RedfishConsumeResourceCommon (
EFI_REDFISH_MEMORY_V1_7_1 *Memory;
EFI_REDFISH_MEMORY_V1_7_1_CS *MemoryCs;
EFI_STRING ConfigureLang;
CHAR8 *PatchedJson;

if ((Private == NULL) || IS_EMPTY_STRING (Json)) {
return EFI_INVALID_PARAMETER;
Expand All @@ -45,16 +52,25 @@ RedfishConsumeResourceCommon (
Memory = NULL;
MemoryCs = NULL;
ConfigureLang = NULL;
PatchedJson = NULL;

if (PcdGetBool (PcdRedfishCompatibleSchemaSupport)) {
Status = RedfishSetCompatibleSchemaVersion (&mSchemaInfo, Json, &PatchedJson);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, cannot set compatible schema version: %r\n", __func__, Status));
return Status;
}
}

Status = Private->JsonStructProtocol->ToStructure (
Private->JsonStructProtocol,
NULL,
Json,
(PatchedJson == NULL ? Json : PatchedJson),
(EFI_REST_JSON_STRUCTURE_HEADER **)&Memory
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, ToStructure() failed: %r\n", __func__, Status));
return Status;
goto ON_RELEASE;
}

MemoryCs = Memory->Memory;
Expand Down Expand Up @@ -1264,12 +1280,18 @@ RedfishConsumeResourceCommon (
//
// Release resource.
//
Private->JsonStructProtocol->DestoryStructure (
Private->JsonStructProtocol,
(EFI_REST_JSON_STRUCTURE_HEADER *)Memory
);
if (Memory != NULL) {
Private->JsonStructProtocol->DestoryStructure (
Private->JsonStructProtocol,
(EFI_REST_JSON_STRUCTURE_HEADER *)Memory
);
}

return EFI_SUCCESS;
if (PatchedJson != NULL) {
FreePool (PatchedJson);
}

return Status;
}

EFI_STATUS
Expand All @@ -1293,6 +1315,7 @@ ProvisioningMemoryProperties (
BOOLEAN *BooleanValue;
INT32 *IntegerValue;
CHAR8 **AsciiStringArrayValue;
CHAR8 *PatchedJson;

if ((JsonStructProtocol == NULL) || (ResultJson == NULL) || IS_EMPTY_STRING (InputJson) || IS_EMPTY_STRING (ConfigureLang)) {
return EFI_INVALID_PARAMETER;
Expand All @@ -1302,17 +1325,26 @@ ProvisioningMemoryProperties (

*ResultJson = NULL;
PropertyChanged = FALSE;
Memory = NULL;
PatchedJson = NULL;

if (PcdGetBool (PcdRedfishCompatibleSchemaSupport)) {
Status = RedfishSetCompatibleSchemaVersion (&mSchemaInfo, InputJson, &PatchedJson);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, cannot set compatible schema version: %r\n", __func__, Status));
return Status;
}
}

Memory = NULL;
Status = JsonStructProtocol->ToStructure (
JsonStructProtocol,
NULL,
InputJson,
(PatchedJson == NULL ? InputJson : PatchedJson),
(EFI_REST_JSON_STRUCTURE_HEADER **)&Memory
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, ToStructure failure: %r\n", __func__, Status));
return Status;
goto ON_RELEASE;
}

MemoryCs = Memory->Memory;
Expand Down Expand Up @@ -2135,13 +2167,21 @@ ProvisioningMemoryProperties (
DEBUG ((DEBUG_ERROR, "%a, ToJson() failed: %r\n", __func__, Status));
}

ON_RELEASE:

//
// Release resource.
//
JsonStructProtocol->DestoryStructure (
JsonStructProtocol,
(EFI_REST_JSON_STRUCTURE_HEADER *)Memory
);
if (Memory != NULL) {
JsonStructProtocol->DestoryStructure (
JsonStructProtocol,
(EFI_REST_JSON_STRUCTURE_HEADER *)Memory
);
}

if (PatchedJson != NULL) {
FreePool (PatchedJson);
}

if (EFI_ERROR (Status)) {
return Status;
Expand Down Expand Up @@ -2506,8 +2546,24 @@ RedfishIdentifyResourceCommon (
EFI_STATUS Status;
EFI_STRING EndOfChar;
REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG_LIST ConfigLangList;
CHAR8 *PatchedJson;

PatchedJson = NULL;

if (PcdGetBool (PcdRedfishCompatibleSchemaSupport)) {
Status = RedfishSetCompatibleSchemaVersion (&mSchemaInfo, Json, &PatchedJson);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, cannot set compatible schema version: %r\n", __func__, Status));
return Status;
}
}

Supported = RedfishIdentifyResource (Private->Uri, (PatchedJson == NULL ? Json : PatchedJson));
if (PatchedJson != NULL) {
FreePool (PatchedJson);
PatchedJson = NULL;
}

Supported = RedfishIdentifyResource (Private->Uri, Json);
if (Supported) {
Status = RedfishFeatureGetUnifiedArrayTypeConfigureLang (RESOURCE_SCHEMA, RESOURCE_SCHEMA_VERSION, CONFIG_LANG_ARRAY_PATTERN, &ConfigLangList);
if (EFI_ERROR (Status)) {
Expand Down
2 changes: 2 additions & 0 deletions RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
RedfishResourceIdentifyLib
UefiLib
UefiDriverEntryPoint
PcdLib

[Protocols]
gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED
Expand All @@ -46,6 +47,7 @@
[Pcd]
gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaStringSize
gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaVersionSize
gEfiRedfishClientPkgTokenSpaceGuid.PcdRedfishCompatibleSchemaSupport

[Depex]
TRUE

0 comments on commit 0610c20

Please sign in to comment.