Skip to content

Commit

Permalink
RedfishClientPkg: use Redfish HTTP protocol in drivers and libraries
Browse files Browse the repository at this point in the history
- Use Redfish HTTP protocol to query Redfish resources in Redfish drivers
and libraries. This takes the benefit of reusing cached HTTP response
from other Redfish drivers. By reducing the number of HTTP operation,
this improves the Redfish performance.
- Remove GetResourceByUri(), CreatePayloadToPostResource() and
CreatePayloadToPatchResource() functions to remove the dependency of
RedfishLib.

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 85873f3 commit daa90b9
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 319 deletions.
4 changes: 2 additions & 2 deletions RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ ProvisioningBiosResource (
// Keep location of new resource.
//
if (NewResourceLocation != NULL) {
RedfisSetRedfishUri (ConfigureLang, NewResourceLocation);
RedfishSetRedfishUri (ConfigureLang, NewResourceLocation);
}

//
Expand Down Expand Up @@ -745,7 +745,7 @@ RedfishIdentifyResourceCommon (
//
// Keep URI and ConfigLang mapping
//
RedfisSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Uri);
RedfishSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Uri);
//
// Set the configuration language in the RESOURCE_INFORMATION_EXCHANGE.
// This information is sent back to the parent resource (e.g. the collection driver).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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.
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -1274,7 +1275,7 @@ ProvisioningComputerSystemResource (
// Keep location of new resource.
//
if (NewResourceLocation != NULL) {
RedfisSetRedfishUri (ConfigureLang, NewResourceLocation);
RedfishSetRedfishUri (ConfigureLang, NewResourceLocation);
}

//
Expand Down Expand Up @@ -1621,7 +1622,7 @@ RedfishIdentifyResourceCommon (
//
// Keep URI and ConfigLang mapping
//
RedfisSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Uri);
RedfishSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Uri);
//
// Set the configuration language in the RESOURCE_INFORMATION_EXCHANGE.
// This information is sent back to the parent resource (e.g. the collection driver).
Expand Down
5 changes: 3 additions & 2 deletions RedfishClientPkg/Features/Memory/V1_7_1/Common/MemoryCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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.
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -2190,7 +2191,7 @@ ProvisioningMemoryResource (
// Keep location of new resource.
//
if (NewResourceLocation != NULL) {
RedfisSetRedfishUri (ConfigureLang, NewResourceLocation);
RedfishSetRedfishUri (ConfigureLang, NewResourceLocation);
}

//
Expand Down Expand Up @@ -2537,7 +2538,7 @@ RedfishIdentifyResourceCommon (
//
// Keep URI and ConfigLang mapping
//
RedfisSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Uri);
RedfishSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Uri);
//
// Set the configuration language in the RESOURCE_INFORMATION_EXCHANGE.
// This information is sent back to the parent resource (e.g. the collection driver).
Expand Down
101 changes: 19 additions & 82 deletions RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,13 @@
#ifndef REDFISH_FEATURE_UTILITY_LIB_H_
#define REDFISH_FEATURE_UTILITY_LIB_H_

#include <Library/RedfishLib.h>
#include <Protocol/EdkIIRedfishPlatformConfig.h>
#include <Protocol/EdkIIRedfishInterchangeData.h>
#include <RedfishJsonStructure/RedfishCsCommon.h>
#include <Library/RedfishHttpLib.h>

#define REDFISH_ENABLE_SYSTEM_REBOOT() PcdSetBoolS(PcdRedfishSystemRebootRequired, TRUE)

/**
Read redfish resource by given resource URI.
@param[in] Service Redfish srvice instacne to make query.
@param[in] ResourceUri Target resource URI.
@param[out] Response HTTP response from redfish service.
@retval EFI_SUCCESS Resrouce is returned successfully.
@retval Others Errors occur.
**/
EFI_STATUS
GetResourceByUri (
IN REDFISH_SERVICE *Service,
IN EFI_STRING ResourceUri,
OUT REDFISH_RESPONSE *Response
);

/**
Check if this is the Redpath array. Usually the Redpath array represents
Expand All @@ -47,7 +28,7 @@ GetResourceByUri (
@param[out] ArraySignatureClose String to the close of array signature.
@retval EFI_SUCCESS Index is found.
@retval EFI_NOT_FOUND The non-array configure language string is retured.
@retval EFI_NOT_FOUND The non-array configure language string is returned.
@retval EFI_INVALID_PARAMETER The format of input ConfigureLang is wrong.
@retval Others Errors occur.
Expand Down Expand Up @@ -100,7 +81,7 @@ CopyConfiglanguageList (

/**
Get number of node from the string. Node is seperated by '/'.
Get number of node from the string. Node is separated by '/'.
@param[in] NodeString The node string to parse.
Expand All @@ -118,10 +99,10 @@ GetNumberOfRedpathNodes (
@param[in] NodeString The node string to parse.
@param[in] Index Index of the node.
@param[out] EndOfNodePtr Pointer to receive the poitner to
@param[out] EndOfNodePtr Pointer to receive the pointer to
the last character of node string.
@retval EFI_STRING the begining of the node string.
@retval EFI_STRING the beginning of the node string.
**/
EFI_STRING
Expand All @@ -140,7 +121,7 @@ GetRedpathNodeByIndex (
@param[out] Index The array index number.
@retval EFI_SUCCESS Index is found.
@retval EFI_NOT_FOUND The non-array configure language string is retured.
@retval EFI_NOT_FOUND The non-array configure language string is returned.
@retval EFI_INVALID_PARAMETER The format of input ConfigureLang is wrong.
@retval Others Errors occur.
Expand Down Expand Up @@ -188,7 +169,7 @@ DestroyConfiglanguageList (
@param[in] DestConfigLang Pointer to the node's configure language string.
The memory pointed by ConfigLang must be allocated
through memory allocation interface. Becasue we will replace
through memory allocation interface. Because we will replace
the pointer in this function.
@param[in] MaxtLengthConfigLang The maximum length of ConfigLang.
@param[in] ConfigLangInstance Pointer to Collection member instance.
Expand Down Expand Up @@ -244,7 +225,7 @@ ApplyFeatureSettingsStringType (

/**
Apply property value to UEFI HII database in numric type.
Apply property value to UEFI HII database in numeric type.
@param[in] Schema Property schema.
@param[in] Version Property schema version.
Expand Down Expand Up @@ -356,7 +337,7 @@ ApplyFeatureSettingsNumericArrayType (
@param[in] Schema Property schema.
@param[in] Version Property schema version.
@param[in] ConfigureLang Configure language refers to this property.
@param[in] ArrayHead Head of Redfich CS boolean array value.
@param[in] ArrayHead Head of Redfish CS boolean array value.
@retval EFI_SUCCESS New value is applied successfully.
@retval Others Errors occur.
Expand All @@ -370,70 +351,26 @@ ApplyFeatureSettingsBooleanArrayType (
IN RedfishCS_bool_Array *ArrayHead
);

/**
Create HTTP payload and send them to redfish service with POST method.
@param[in] Service Redfish service.
@param[in] TargetPayload Target payload
@param[in] Json Data in JSON format.
@param[out] Location Returned location string from Redfish service.
@param[out] Etag Returned ETAG string from Redfish service.
@retval EFI_SUCCESS Data is sent to redfish service successfully.
@retval Others Errors occur.
**/
EFI_STATUS
CreatePayloadToPostResource (
IN REDFISH_SERVICE *Service,
IN REDFISH_PAYLOAD *TargetPayload,
IN CHAR8 *Json,
OUT EFI_STRING *Location,
OUT CHAR8 **Etag
);

/**
Create HTTP payload and send them to redfish service with PATCH method.
@param[in] Service Redfish service.
@param[in] TargetPayload Target payload
@param[in] Json Data in JSON format.
@param[out] Etag Returned ETAG string from Redfish service.
@retval EFI_SUCCESS Data is sent to redfish service successfully.
@retval Others Errors occur.
**/
EFI_STATUS
CreatePayloadToPatchResource (
IN REDFISH_SERVICE *Service,
IN REDFISH_PAYLOAD *TargetPayload,
IN CHAR8 *Json,
OUT CHAR8 **Etag
);

/**
Save Redfish URI in database for further use.
@param[in] ConfigLang ConfigLang to save
@param[in] Uri Redfish Uri to save
@retval EFI_INVALID_PARAMETR SystemId is NULL or EMPTY
@retval EFI_INVALID_PARAMETER SystemId is NULL or EMPTY
@retval EFI_SUCCESS Redfish uri is saved
**/
EFI_STATUS
RedfisSetRedfishUri (
RedfishSetRedfishUri (
IN EFI_STRING ConfigLang,
IN EFI_STRING Uri
);

/**
Get the property name by given Configure Langauge.
Get the property name by given Configure Language.
@param[in] ResourceUri URI of root of resource.
@param[in] ConfigureLang Configure Language string.
Expand Down Expand Up @@ -576,7 +513,7 @@ GetOdataId (

/**
Return config language from given URI and prperty name. It's call responsibility to release returned buffer.
Return config language from given URI and property name. It's call responsibility to release returned buffer.
@param[in] Uri The URI to match
@param[in] PropertyName The property name of resource. This is optional.
Expand Down Expand Up @@ -790,7 +727,7 @@ MatchPropertyWithJsonContext (

/**
Create string array and append to arry node in Redfish JSON convert format.
Create string array and append to array node in Redfish JSON convert format.
@param[in,out] Head The head of string array.
@param[in] StringArray Input string array.
Expand All @@ -809,7 +746,7 @@ AddRedfishCharArray (

/**
Create numeric array and append to arry node in Redfish JSON convert format.
Create numeric array and append to array node in Redfish JSON convert format.
@param[in,out] Head The head of string array.
@param[in] NumericArray Input numeric array.
Expand All @@ -828,7 +765,7 @@ AddRedfishNumericArray (

/**
Create boolean array and append to arry node in Redfish JSON convert format.
Create boolean array and append to array node in Redfish JSON convert format.
@param[in,out] Head The head of string array.
@param[in] BooleanArray Input boolean array.
Expand Down Expand Up @@ -871,7 +808,7 @@ CompareRedfishStringArrayValues (
Check and see if value in Redfish numeric array are all the same as the one
from HII configuration.
@param[in] Head The head of Redfish CS numeraic array.
@param[in] Head The head of Redfish CS numeric array.
@param[in] NumericArray Input numeric array.
@param[in] ArraySize The size of NumericArray.
Expand Down Expand Up @@ -914,9 +851,9 @@ CompareRedfishBooleanArrayValues (
This is just a simple check.
@param[in] RedfishVagueKeyValuePtr The vague key value sets on Redfish service.
@param[in] RedfishVagueKeyValueNumber The numebr of vague key value sets
@param[in] RedfishVagueKeyValueNumber The number of vague key value sets
@param[in] ConfigVagueKeyValuePtr The vague configuration on platform.
@param[in] ConfigVagueKeyValueNumber The numebr of vague key value sets
@param[in] ConfigVagueKeyValueNumber The number of vague key value sets
@retval TRUE All values are the same.
FALSE There is some difference.
Expand Down
5 changes: 4 additions & 1 deletion RedfishClientPkg/Include/Library/RedfishVersionLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file defines the Redfish version Library interface.
(C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand All @@ -10,9 +11,11 @@
#ifndef REDFISH_VERSION_LIB_H_
#define REDFISH_VERSION_LIB_H_

#include <Library/RedfishLib.h>

/**
Query HTTP request to BMC with given redfish service and return redfish
version information. If there is troulbe to get Redfish version on BMC,
version information. If there is trouble to get Redfish version on BMC,
The value of PcdDefaultRedfishVersion is returned.
It's call responsibility to release returned buffer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Library/EdkIIRedfishResourceConfigLib.h>
#include <Library/RedfishFeatureUtilityLib.h>
#include <Library/RedfishPlatformConfigLib.h>
#include <Library/RedfishHttpLib.h>

EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL *mRedfishResourceConfigProtocol = NULL;
EFI_HANDLE mCachedHandle;
Expand Down Expand Up @@ -56,7 +57,8 @@ GetRedfishSchemaInfo (
return EFI_INVALID_PARAMETER;
}

Status = GetResourceByUri (RedfishService, Uri, &Response);
ZeroMem (&Response, sizeof (Response));
Status = RedfishHttpGetResource (RedfishService, Uri, &Response, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to get resource from %s: %r", __func__, Uri, Status));
return Status;
Expand Down Expand Up @@ -90,6 +92,10 @@ GetRedfishSchemaInfo (
//
// Release resource.
//
if (Response.Payload != NULL) {
RedfishHttpFreeResource (&Response);
}

JsonStructProtocol->DestoryStructure (JsonStructProtocol, Header);
FreePool (JsonText);
RedfishFreeResponse (Response.StatusCode, Response.HeaderCount, Response.Headers, Response.Payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
MemoryAllocationLib
RedfishFeatureUtilityLib
RedfishPlatformConfigLib
RedfishHttpLib

[Protocols]
gEdkIIRedfishResourceConfigProtocolGuid ## CONSUMES ##
Expand Down
Loading

0 comments on commit daa90b9

Please sign in to comment.