Skip to content

Commit

Permalink
RedfishClientPkg: Add ETag PCD and revise Redfish ETag functions
Browse files Browse the repository at this point in the history
Add PCD to disable ETag capability for the case Redfish
service doesn't support ETag.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Mike Maslenkin <mike.maslenkin@gmail.com>
Reviewed-by: Igor Kulchytskyy <igork@ami.com>
  • Loading branch information
changab committed Jan 9, 2024
1 parent 7c50efb commit a5c4297
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 130 deletions.
19 changes: 6 additions & 13 deletions RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved.
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -153,14 +154,10 @@ RedfishResourceConsumeResource (
ASSERT (Private->Json != NULL);

//
// Find etag in HTTP response header
// Searching for etag in HTTP response header
//
Etag = NULL;
Status = GetEtagAndLocation (ExpectedResponse, &Etag, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __func__));
}

Etag = NULL;
GetHttpResponseEtag (ExpectedResponse, &Etag);
Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
if (Status != EFI_ALREADY_STARTED) {
Expand Down Expand Up @@ -365,12 +362,8 @@ RedfishResourceCheck (
//
// Find etag in HTTP response header
//
Etag = NULL;
Status = GetEtagAndLocation (&Response, &Etag, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Etag = NULL;
GetHttpResponseEtag (&Response, &Etag);
Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __func__, Uri, Status));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -455,9 +456,9 @@ RedfishProvisioningResourceCommon (
}

//
// per Redfish spec. the URL of new resource will be returned in "Location" header.
// Per Redfish spec. the URL of new resource will be returned in "Location" header.
//
Status = GetEtagAndLocation (&Response, NULL, &NewResourceLocation);
Status = GetHttpResponseLocation (&Response, &NewResourceLocation);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: cannot find new location: %r\n", __func__, Status));
goto RELEASE_RESOURCE;
Expand Down
17 changes: 5 additions & 12 deletions RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -154,12 +155,8 @@ RedfishResourceConsumeResource (
//
// Find etag in HTTP response header
//
Etag = NULL;
Status = GetEtagAndLocation (ExpectedResponse, &Etag, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Etag = NULL;
GetHttpResponseEtag (ExpectedResponse, &Etag);
Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", __func__, Private->Uri, Status));
Expand Down Expand Up @@ -358,12 +355,8 @@ RedfishResourceCheck (
//
// Find etag in HTTP response header
//
Etag = NULL;
Status = GetEtagAndLocation (&Response, &Etag, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Etag = NULL;
GetHttpResponseEtag (&Response, &Etag);
Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: failed to check resource from: %s: %r\n", __func__, Uri, Status));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -149,12 +150,8 @@ RedfishResourceConsumeResource (
//
// Find etag in HTTP response header
//
Etag = NULL;
Status = GetEtagAndLocation (ExpectedResponse, &Etag, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __func__));
}

Etag = NULL;
GetHttpResponseEtag (ExpectedResponse, &Etag);
Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
if (Status != EFI_ALREADY_STARTED) {
Expand Down Expand Up @@ -359,12 +356,8 @@ RedfishResourceCheck (
//
// Find etag in HTTP response header
//
Etag = NULL;
Status = GetEtagAndLocation (&Response, &Etag, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Etag = NULL;
GetHttpResponseEtag (&Response, &Etag);
Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __func__, Uri, Status));
Expand Down
17 changes: 5 additions & 12 deletions RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -149,12 +150,8 @@ RedfishResourceConsumeResource (
//
// Find etag in HTTP response header
//
Etag = NULL;
Status = GetEtagAndLocation (ExpectedResponse, &Etag, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __func__));
}

Etag = NULL;
GetHttpResponseEtag (ExpectedResponse, &Etag);
Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
if (Status != EFI_ALREADY_STARTED) {
Expand Down Expand Up @@ -359,12 +356,8 @@ RedfishResourceCheck (
//
// Find etag in HTTP response header
//
Etag = NULL;
Status = GetEtagAndLocation (&Response, &Etag, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to get ETag from HTTP header\n", __func__));
}

Etag = NULL;
GetHttpResponseEtag (&Response, &Etag);
Status = RedfishCheckResourceCommon (Private, Private->Json, Etag);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, failed to check resource from: %s: %r\n", __func__, Uri, Status));
Expand Down
47 changes: 36 additions & 11 deletions RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -81,7 +82,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 Down Expand Up @@ -559,6 +560,19 @@ GetEtagWithUri (
IN EFI_STRING Uri
);

/**
This function returns a boolean of ETAG support on Redfish service side.
@retval TRUE ETAG is supported on Redfish service.
@retval FALSE ETAG is not supported on Redfish service.
**/
BOOLEAN
CheckIsServerEtagSupported (
VOID
);

/**
Get @odata.id from give HTTP payload. It's call responsibility to release returned buffer.
Expand Down Expand Up @@ -931,22 +945,33 @@ CompareRedfishPropertyVagueValues (
);

/**
Find "ETag" from either HTTP header or Redfish response.
Find "ETag" and "Location" from either HTTP header or Redfish response.
@param[in] Response HTTP response
@param[out] Etag String buffer to return ETag
@param[in] Response HTTP response
@param[out] Etag String buffer to return ETag
@param[out] Location String buffer to return Location
@retval EFI_SUCCESS ETag is returned in Etag
@retval EFI_UNSUPPORTED ETag is unsupported
@retval EFI_INVALID_PARAMETER Response, Etag or both are NULL.
@retval EFI_SUCCESS Data is found and returned.
@retval Others Errors occur.
**/
EFI_STATUS
GetHttpResponseEtag (
IN REDFISH_RESPONSE *Response,
OUT CHAR8 **Etag
);

/**
Find "Location" from either HTTP header or Redfish response.
@param[in] Response HTTP response
@param[out] Location String buffer to return Location
**/
EFI_STATUS
GetEtagAndLocation (
IN REDFISH_RESPONSE *Response,
OUT CHAR8 **Etag, OPTIONAL
OUT EFI_STRING *Location OPTIONAL
GetHttpResponseLocation (
IN REDFISH_RESPONSE *Response,
OUT EFI_STRING *Location
);

/**
Expand Down
Loading

0 comments on commit a5c4297

Please sign in to comment.