Skip to content

Commit

Permalink
RedfishClientPkg/ComputerSystemCollectionDxe: handle more scenarios
Browse files Browse the repository at this point in the history
This change defines two more error returns and allow feature driver to
handle the scenarios while 1) the resource is not owned by feature
driver. 2) feature driver owns this resource but there is nothing to
manage on this resource now.
Detail changes are:
- Use "%a:" instead of "%a," in debug macro.
- Add two error return from EdkIIRedfishResourceConfigIdentify().
  - EFI_UNSUPPORTED: this resource is not owned by feature driver.
  Caller should ignore this resource.
  - EFI_NOT_FOUND: this resource is owned by feature driver but
  there is nothing to handle now. Caller may ignore rest of
  operations and proceed to next Redfish resource.
- Add error return from EdkIIRedfishResourceConfigCheck().
  - EFI_UNSUPPORTED: this resource it not owned by feature driver.
  Caller should ignore this URI.

Signed-off-by: Nickle Wang <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
Cc: Nick Ramirez <[email protected]>
Reviewed-by: Abner Chang <[email protected]>
  • Loading branch information
nicklela committed Nov 28, 2023
1 parent 3a83948 commit 33e26a4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Redfish feature driver implementation - ComputerSystemCollection
(C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -32,11 +33,11 @@ HandleResource (
// Resource match
//

DEBUG ((REDFISH_DEBUG_TRACE, "%a, process resource for: %s\n", __func__, Uri));
DEBUG ((REDFISH_DEBUG_TRACE, "%a: process resource for: %s\n", __func__, Uri));

Status = GetRedfishSchemaInfo (Private->RedfishService, Private->JsonStructProtocol, Uri, &SchemaInfo);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to get schema information from: %s %r\n", __func__, Uri, Status));
DEBUG ((DEBUG_ERROR, "%a: failed to get schema information from: %s %r\n", __func__, Uri, Status));
return Status;
}

Expand All @@ -50,15 +51,19 @@ HandleResource (
Status = EdkIIRedfishResourceConfigIdentify (&SchemaInfo, Uri, Private->InformationExchange);
if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) {
DEBUG ((DEBUG_MANAGEABILITY, "%a, \"%s\" is not handled by us\n", __func__, Uri));
DEBUG ((DEBUG_MANAGEABILITY, "%a: \"%s\" is not handled by us\n", __func__, Uri));
return EFI_SUCCESS;
} else if (Status == EFI_NOT_FOUND) {
DEBUG ((DEBUG_MANAGEABILITY, "%a: \"%s\" has nothing to handle\n", __func__, Uri));
RedfisSetRedfishUri (L"/Systems/{1}", Uri);
return EFI_SUCCESS;
}

DEBUG ((DEBUG_ERROR, "%a, fail to identify resource: \"%s\": %r\n", __func__, Uri, Status));
DEBUG ((DEBUG_ERROR, "%a: fail to identify resource: \"%s\": %r\n", __func__, Uri, Status));
return Status;
}
} else {
DEBUG ((REDFISH_DEBUG_TRACE, "%a, history record found: %s\n", __func__, ConfigLang));
DEBUG ((REDFISH_DEBUG_TRACE, "%a: history record found: %s\n", __func__, ConfigLang));
//
// Set exchange information
//
Expand All @@ -70,15 +75,15 @@ HandleResource (
AllocateZeroPool (sizeof (REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG));

if (Private->InformationExchange->ReturnedInformation.ConfigureLanguageList.List == NULL) {
DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG.\n", __func__));
DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG.\n", __func__));
return EFI_OUT_OF_RESOURCES;
}

Private->InformationExchange->ReturnedInformation.ConfigureLanguageList.List[0].Index = Index;
Private->InformationExchange->ReturnedInformation.ConfigureLanguageList.List[0].ConfigureLang =
(EFI_STRING)AllocateCopyPool (StrSize (ReturnedConfigLang), (VOID *)ReturnedConfigLang);
} else {
DEBUG ((DEBUG_ERROR, "%a, GetArrayIndexFromArrayTypeConfigureLang fail: %r\n", __func__, Status));
DEBUG ((DEBUG_ERROR, "%a: GetArrayIndexFromArrayTypeConfigureLang fail: %r\n", __func__, Status));
}

FreePool (ConfigLang);
Expand All @@ -91,13 +96,18 @@ HandleResource (
DEBUG ((REDFISH_DEBUG_TRACE, "%a Check for %s\n", __func__, Uri));
Status = EdkIIRedfishResourceConfigCheck (&SchemaInfo, Uri);
if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: \"%s\" is not handled by us\n", __func__, Uri));
return EFI_SUCCESS;
}

//
// The target property does not exist, do the provision to create property.
//
DEBUG ((REDFISH_DEBUG_TRACE, "%a provision for %s\n", __func__, Uri));
Status = EdkIIRedfishResourceConfigProvisionging (&SchemaInfo, Uri, Private->InformationExchange, FALSE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to provision with GET mode: %r\n", __func__, Status));
DEBUG ((DEBUG_ERROR, "%a: failed to provision with GET mode: %r\n", __func__, Status));
}

return Status;
Expand All @@ -109,7 +119,7 @@ HandleResource (
DEBUG ((REDFISH_DEBUG_TRACE, "%a consume for %s\n", __func__, Uri));
Status = EdkIIRedfishResourceConfigConsume (&SchemaInfo, Uri);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to consume resource for: %s: %r\n", __func__, Uri, Status));
DEBUG ((DEBUG_ERROR, "%a: failed to consume resource for: %s: %r\n", __func__, Uri, Status));
}

//
Expand All @@ -118,7 +128,7 @@ HandleResource (
DEBUG ((REDFISH_DEBUG_TRACE, "%a update for %s\n", __func__, Uri));
Status = EdkIIRedfishResourceConfigUpdate (&SchemaInfo, Uri);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to update resource for: %s: %r\n", __func__, Uri, Status));
DEBUG ((DEBUG_ERROR, "%a: failed to update resource for: %s: %r\n", __func__, Uri, Status));
}

return Status;
Expand All @@ -145,7 +155,7 @@ HandleCollectionResource (
return EFI_NOT_READY;
}

DEBUG ((REDFISH_DEBUG_TRACE, "%a, process collection for: %s\n", __func__, Private->CollectionUri));
DEBUG ((REDFISH_DEBUG_TRACE, "%a: process collection for: %s\n", __func__, Private->CollectionUri));

//
// Convert JSON text to C structure.
Expand All @@ -157,7 +167,7 @@ HandleCollectionResource (
(EFI_REST_JSON_STRUCTURE_HEADER **)&Collection
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, ToStructure() failed: %r\n", __func__, Status));
DEBUG ((DEBUG_ERROR, "%a: ToStructure() failed: %r\n", __func__, Status));
return Status;
}

Expand All @@ -182,7 +192,7 @@ HandleCollectionResource (
if (MemberUri != NULL) {
Status = HandleResource (Private, MemberUri);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, process ComputerSystemCollection resource: %a failed: %r\n", __func__, UriData->Uri, Status));
DEBUG ((DEBUG_ERROR, "%a: process ComputerSystemCollection resource: %a failed: %r\n", __func__, UriData->Uri, Status));
}

FreePool (MemberUri);
Expand Down Expand Up @@ -216,19 +226,19 @@ CreateCollectionResource (
return EFI_INVALID_PARAMETER;
}

DEBUG ((REDFISH_DEBUG_TRACE, "%a, create resource for collection for: %s\n", __func__, Private->CollectionUri));
DEBUG ((REDFISH_DEBUG_TRACE, "%a: create resource for collection for: %s\n", __func__, Private->CollectionUri));

Status = GetSupportedSchemaVersion (REDFISH_SCHEMA_NAME, &SchemaInfo);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to find supported schema from HII database: %r\n", __func__, Status));
DEBUG ((DEBUG_ERROR, "%a: failed to find supported schema from HII database: %r\n", __func__, Status));
return Status;
}

DEBUG ((REDFISH_DEBUG_TRACE, "%a, supported schema: %a %a.%a.%a\n", __func__, SchemaInfo.Schema, SchemaInfo.Major, SchemaInfo.Minor, SchemaInfo.Errata));
DEBUG ((REDFISH_DEBUG_TRACE, "%a: supported schema: %a %a.%a.%a\n", __func__, SchemaInfo.Schema, SchemaInfo.Major, SchemaInfo.Minor, SchemaInfo.Errata));

Status = EdkIIRedfishResourceConfigProvisionging (&SchemaInfo, Private->CollectionUri, Private->InformationExchange, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to create resource for: %s: %r\n", __func__, Private->CollectionUri, Status));
DEBUG ((DEBUG_ERROR, "%a: failed to create resource for: %s: %r\n", __func__, Private->CollectionUri, Status));
}

return Status;
Expand Down Expand Up @@ -283,14 +293,14 @@ CollectionHandler (
return EFI_INVALID_PARAMETER;
}

DEBUG ((REDFISH_DEBUG_TRACE, "%a, collection handler for %s\n", __func__, Private->CollectionUri));
DEBUG ((REDFISH_DEBUG_TRACE, "%a: collection handler for %s\n", __func__, Private->CollectionUri));

//
// Query collection from Redfish service.
//
Status = GetResourceByUri (Private->RedfishService, Private->CollectionUri, &Private->RedResponse);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, unable to get resource from: %s :%r\n", __func__, Private->CollectionUri, Status));
DEBUG ((DEBUG_ERROR, "%a: unable to get resource from: %s :%r\n", __func__, Private->CollectionUri, Status));
goto ON_RELEASE;
}

Expand Down Expand Up @@ -350,6 +360,7 @@ RedfishCollectionFeatureCallback (

RedfishService = Private->RedfishService;
if (RedfishService == NULL) {
DEBUG ((DEBUG_ERROR, "%a: no Redfish service configured\n", __func__));
return EFI_NOT_READY;
}

Expand All @@ -368,7 +379,7 @@ RedfishCollectionFeatureCallback (
//
ResourceUri = (EFI_STRING)AllocateZeroPool (MAX_URI_LENGTH * sizeof (CHAR16));
if (ResourceUri == NULL) {
DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for full URI.\n", __func__));
DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for full URI.\n", __func__));
return EFI_OUT_OF_RESOURCES;
}

Expand All @@ -386,7 +397,7 @@ RedfishCollectionFeatureCallback (

Status = CollectionHandler (Private);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, CollectionHandler failure: %r\n", __func__, Status));
DEBUG ((DEBUG_ERROR, "%a: CollectionHandler failure: %r\n", __func__, Status));
}

return EFI_SUCCESS;
Expand Down Expand Up @@ -492,7 +503,7 @@ EfiRestJasonStructureProtocolIsReady (
(VOID **)&mRedfishCollectionPrivate->JsonStructProtocol
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to locate gEfiRestJsonStructureProtocolGuid: %r\n", __func__, Status));
DEBUG ((DEBUG_ERROR, "%a: failed to locate gEfiRestJsonStructureProtocolGuid: %r\n", __func__, Status));
}

gBS->CloseEvent (Event);
Expand Down Expand Up @@ -528,7 +539,7 @@ EdkIIRedfishFeatureProtocolIsReady (
(VOID **)&FeatureProtocol
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to locate gEdkIIRedfishFeatureProtocolGuid: %r\n", __func__, Status));
DEBUG ((DEBUG_ERROR, "%a: failed to locate gEdkIIRedfishFeatureProtocolGuid: %r\n", __func__, Status));
gBS->CloseEvent (Event);
return;
}
Expand All @@ -540,7 +551,7 @@ EdkIIRedfishFeatureProtocolIsReady (
(VOID *)mRedfishCollectionPrivate
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to register %s: %r\n", __func__, REDFISH_MANAGED_URI, Status));
DEBUG ((DEBUG_ERROR, "%a: failed to register %s: %r\n", __func__, REDFISH_MANAGED_URI, Status));
}

mRedfishCollectionPrivate->FeatureProtocol = FeatureProtocol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ EdkIIRedfishResourceConfigUpdate (
@param[in] Uri The target URI to consume.
@retval EFI_SUCCESS Value is returned successfully.
@retval EFI_UNSUPPORTED This resource is not owned by feature driver.
Caller should ignore this resource.
@retval Others Some error happened.
**/
Expand All @@ -94,7 +96,12 @@ EdkIIRedfishResourceConfigCheck (
@param[in] InformationExchange Pointer to RESOURCE_INFORMATION_EXCHANGE.
@retval EFI_SUCCESS This is target resource which we want to handle.
@retval EFI_UNSUPPORTED This is not the target resource.
@retval EFI_UNSUPPORTED This resource is not owned by feature driver.
Caller should ignore this resource.
@retval EFI_NOT_FOUND This resource is owned by feature driver but there
is nothing to handle now. Caller may ignore the
rest of operations like check(), provisioning(),
consume() and update().
@retval Others Some error happened.
**/
Expand Down

0 comments on commit 33e26a4

Please sign in to comment.