public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [edk2-redfish-client][PATCH 07/13] RedfishClientPkg/BiosDxe: ues RedfishHttpLib
@ 2024-02-29  8:54 Nickle Wang via groups.io
  2024-03-04  1:58 ` Chang, Abner via groups.io
  0 siblings, 1 reply; 2+ messages in thread
From: Nickle Wang via groups.io @ 2024-02-29  8:54 UTC (permalink / raw)
  To: devel; +Cc: Abner Chang, Igor Kulchytskyy

Use EDK2 RedfishHttpLib to replace RedfishHttpCacheLib and RedfishLib

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../Features/Bios/v1_0_9/Dxe/BiosDxe.inf      |   3 +-
 .../Features/Bios/v1_0_9/Common/BiosCommon.c  |  92 +++++++-------
 .../Features/Bios/v1_0_9/Dxe/BiosDxe.c        | 113 +++++-------------
 3 files changed, 74 insertions(+), 134 deletions(-)

diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
index 6ba4c3cfa..a2ac18e61 100644
--- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
+++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
@@ -32,14 +32,13 @@
   BaseMemoryLib
   DebugLib
   EdkIIRedfishResourceConfigLib
-  RedfishLib
+  RedfishHttpLib
   RedfishFeatureUtilityLib
   RedfishVersionLib
   RedfishResourceIdentifyLib
   UefiLib
   UefiDriverEntryPoint
   RedfishAddendumLib
-  RedfishHttpCacheLib
 
 [Protocols]
   gEdkIIRedfishConfigHandlerProtocolGuid          ## PRODUCED
diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
index f3f993c87..1f3c30147 100644
--- a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
+++ b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
@@ -2,7 +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.
+  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -68,7 +68,7 @@ RedfishConsumeResourceCommon (
     // No change
     //
     DEBUG ((DEBUG_MANAGEABILITY, "%a, ETAG: %s has no change, ignore consume action\n", __func__, Private->Uri));
-    Status = EFI_ALREADY_STARTED;
+    Status = EFI_SUCCESS;
     goto ON_RELEASE;
   }
 
@@ -268,18 +268,18 @@ ProvisioningBiosResource (
   IN  EFI_STRING                       ConfigureLang
   )
 {
-  CHAR8       *Json;
-  CHAR8       *JsonWithAddendum;
-  EFI_STATUS  Status;
-  EFI_STRING  NewResourceLocation;
-  CHAR8       *EtagStr;
-  CHAR8       ResourceId[16];
+  CHAR8             *Json;
+  CHAR8             *JsonWithAddendum;
+  EFI_STATUS        Status;
+  EFI_STRING        NewResourceLocation;
+  CHAR8             ResourceId[16];
+  REDFISH_RESPONSE  Response;
 
   if (IS_EMPTY_STRING (ConfigureLang) || (Private == NULL)) {
     return EFI_INVALID_PARAMETER;
   }
 
-  EtagStr = NULL;
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
   AsciiSPrint (ResourceId, sizeof (ResourceId), "%d", Index);
 
   Status = ProvisioningBiosProperties (
@@ -327,27 +327,27 @@ ProvisioningBiosResource (
     JsonWithAddendum = NULL;
   }
 
-  Status = CreatePayloadToPostResource (Private->RedfishService, Private->Payload, Json, &NewResourceLocation, &EtagStr);
+  Status = RedfishHttpPostResource (Private->RedfishService, Private->Uri, Json, &Response);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, post Bios resource for %s failed: %r\n", __func__, ConfigureLang, Status));
     goto RELEASE_RESOURCE;
   }
 
-  ASSERT (NewResourceLocation != NULL);
-
   //
-  // Keep location of new resource.
+  // Per Redfish spec. the URL of new resource will be returned in "Location" header.
   //
-  if (NewResourceLocation != NULL) {
-    RedfishSetRedfishUri (ConfigureLang, NewResourceLocation);
+  Status = GetHttpResponseLocation (&Response, &NewResourceLocation);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: cannot find new location: %r\n", __func__, Status));
+    goto RELEASE_RESOURCE;
   }
 
   //
-  // Handle Etag
+  // Keep location of new resource.
   //
-  if (EtagStr != NULL) {
-    SetEtagWithUri (EtagStr, NewResourceLocation);
-    FreePool (EtagStr);
+  if (NewResourceLocation != NULL) {
+    DEBUG ((DEBUG_MANAGEABILITY, "%a: Location: %s\n", __func__, NewResourceLocation));
+    RedfishSetRedfishUri (ConfigureLang, NewResourceLocation);
   }
 
 RELEASE_RESOURCE:
@@ -360,6 +360,8 @@ RELEASE_RESOURCE:
     FreePool (Json);
   }
 
+  RedfishHttpFreeResponse (&Response);
+
   return Status;
 }
 
@@ -402,19 +404,19 @@ ProvisioningBiosExistResource (
   IN  REDFISH_RESOURCE_COMMON_PRIVATE  *Private
   )
 {
-  EFI_STATUS  Status;
-  EFI_STRING  ConfigureLang;
-  CHAR8       *EtagStr;
-  CHAR8       *Json;
-  CHAR8       *JsonWithAddendum;
+  EFI_STATUS        Status;
+  EFI_STRING        ConfigureLang;
+  CHAR8             *Json;
+  CHAR8             *JsonWithAddendum;
+  REDFISH_RESPONSE  Response;
 
   if (Private == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
-  EtagStr       = NULL;
   Json          = NULL;
   ConfigureLang = NULL;
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
 
   ConfigureLang = RedfishGetConfigLanguage (Private->Uri);
   if (ConfigureLang == NULL) {
@@ -473,23 +475,17 @@ ProvisioningBiosExistResource (
 
   DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for %s\n", __func__, ConfigureLang));
   //
-  // PUT back to instance
+  // PATCH back to instance
   //
-  Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr);
+  Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status));
   }
 
-  //
-  // Handle Etag
-  //
-  if (EtagStr != NULL) {
-    SetEtagWithUri (EtagStr, Private->Uri);
-    FreePool (EtagStr);
-  }
-
 ON_RELEASE:
 
+  RedfishHttpFreeResponse (&Response);
+
   if (Json != NULL) {
     FreePool (Json);
   }
@@ -609,19 +605,19 @@ RedfishUpdateResourceCommon (
   IN     CHAR8                            *InputJson
   )
 {
-  EFI_STATUS  Status;
-  CHAR8       *Json;
-  CHAR8       *JsonWithAddendum;
-  EFI_STRING  ConfigureLang;
-  CHAR8       *EtagStr;
+  EFI_STATUS        Status;
+  CHAR8             *Json;
+  CHAR8             *JsonWithAddendum;
+  EFI_STRING        ConfigureLang;
+  REDFISH_RESPONSE  Response;
 
   if ((Private == NULL) || IS_EMPTY_STRING (InputJson)) {
     return EFI_INVALID_PARAMETER;
   }
 
-  EtagStr       = NULL;
   Json          = NULL;
   ConfigureLang = NULL;
+  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
 
   ConfigureLang = RedfishGetConfigLanguage (Private->Uri);
   if (ConfigureLang == NULL) {
@@ -680,23 +676,17 @@ RedfishUpdateResourceCommon (
 
   DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s\n", __func__, ConfigureLang));
   //
-  // PUT back to instance
+  // PATCH back to instance
   //
-  Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr);
+  Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status));
   }
 
-  //
-  // Handle Etag
-  //
-  if (EtagStr != NULL) {
-    SetEtagWithUri (EtagStr, Private->Uri);
-    FreePool (EtagStr);
-  }
-
 ON_RELEASE:
 
+  RedfishHttpFreeResponse (&Response);
+
   if (Json != NULL) {
     FreePool (Json);
   }
diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
index a442d446b..1ca920640 100644
--- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
+++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
@@ -57,7 +57,7 @@ RedfishResourceProvisioningResource (
   }
 
   ZeroMem (&Response, sizeof (Response));
-  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
     return Status;
@@ -68,20 +68,20 @@ RedfishResourceProvisioningResource (
   ASSERT (Private->Payload != NULL);
 
   Status = RedfishProvisioningResourceCommon (Private, !PostMode);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: failed to provision resource to: %s: %r\n", __func__, Uri, Status));
+  } else {
+    //
+    // Get latest ETag on URI and keep it in variable.
+    //
+    SetEtagFromUri (Private->RedfishService, Private->Uri, TRUE);
+  }
 
   //
   // Release resource
   //
-  if (Private->Payload != NULL) {
-    RedfishFreeResponse (
-      Response.StatusCode,
-      Response.HeaderCount,
-      Response.Headers,
-      Response.Payload
-      );
-    RedfishHttpResetResource (Uri);
-    Private->Payload = NULL;
-  }
+  RedfishHttpFreeResponse (&Response);
+  Private->Payload = NULL;
 
   return Status;
 }
@@ -122,7 +122,7 @@ RedfishResourceConsumeResource (
   }
 
   ZeroMem (&Response, sizeof (Response));
-  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
     return Status;
@@ -131,7 +131,7 @@ RedfishResourceConsumeResource (
   //
   // Check and see if "@Redfish.Settings" exist or not.
   //
-  ZeroMem (&PendingSettingResponse, sizeof (REDFISH_RESPONSE));
+  ZeroMem (&PendingSettingResponse, sizeof (PendingSettingResponse));
   PendingSettingUri = NULL;
   Status            = GetPendingSettings (
                         Private->RedfishService,
@@ -161,42 +161,15 @@ RedfishResourceConsumeResource (
   GetHttpResponseEtag (ExpectedResponse, &Etag);
   Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
   if (EFI_ERROR (Status)) {
-    if (Status != EFI_ALREADY_STARTED) {
-      DEBUG ((DEBUG_ERROR, "%a, failed to consume resource from: %s: %r\n", __func__, Uri, Status));
-    }
-  } else {
-    //
-    // Keep etag after consuming pending settings.
-    //
-    if (Etag != NULL) {
-      SetEtagWithUri (Etag, Private->Uri);
-    }
+    DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n", __func__, Private->Uri, Status));
   }
 
   //
   // Release resource
   //
-  if (Private->Payload != NULL) {
-    if (Response.Payload != NULL) {
-      RedfishFreeResponse (
-        Response.StatusCode,
-        Response.HeaderCount,
-        Response.Headers,
-        Response.Payload
-        );
-    }
-
-    if (PendingSettingResponse.Payload != NULL) {
-      RedfishFreeResponse (
-        PendingSettingResponse.StatusCode,
-        PendingSettingResponse.HeaderCount,
-        PendingSettingResponse.Headers,
-        PendingSettingResponse.Payload
-        );
-    }
-
-    Private->Payload = NULL;
-  }
+  RedfishHttpFreeResponse (&Response);
+  RedfishHttpFreeResponse (&PendingSettingResponse);
+  Private->Payload = NULL;
 
   if (Private->Json != NULL) {
     FreePool (Private->Json);
@@ -278,7 +251,7 @@ RedfishResourceUpdate (
   }
 
   ZeroMem (&Response, sizeof (Response));
-  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
     return Status;
@@ -293,22 +266,19 @@ RedfishResourceUpdate (
 
   Status = RedfishUpdateResourceCommon (Private, Private->Json);
   if (EFI_ERROR (Status)) {
-    DEBUG ((DEBUG_ERROR, "%a, failed to update resource from: %s: %r\n", __func__, Uri, Status));
+    DEBUG ((DEBUG_ERROR, "%a: failed to update resource to: %s: %r\n", __func__, Uri, Status));
+  } else {
+    //
+    // Get latest ETag on URI and keep it in variable.
+    //
+    SetEtagFromUri (Private->RedfishService, Private->Uri, TRUE);
   }
 
   //
   // Release resource
   //
-  if (Private->Payload != NULL) {
-    RedfishFreeResponse (
-      Response.StatusCode,
-      Response.HeaderCount,
-      Response.Headers,
-      Response.Payload
-      );
-    RedfishHttpResetResource (Uri);
-    Private->Payload = NULL;
-  }
+  RedfishHttpFreeResponse (&Response);
+  Private->Payload = NULL;
 
   if (Private->Json != NULL) {
     FreePool (Private->Json);
@@ -351,7 +321,7 @@ RedfishResourceCheck (
   }
 
   ZeroMem (&Response, sizeof (Response));
-  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
     return Status;
@@ -377,15 +347,8 @@ RedfishResourceCheck (
   //
   // Release resource
   //
-  if (Private->Payload != NULL) {
-    RedfishFreeResponse (
-      Response.StatusCode,
-      Response.HeaderCount,
-      Response.Headers,
-      Response.Payload
-      );
-    Private->Payload = NULL;
-  }
+  RedfishHttpFreeResponse (&Response);
+  Private->Payload = NULL;
 
   if (Private->Json != NULL) {
     FreePool (Private->Json);
@@ -428,7 +391,7 @@ RedfishResourceIdentify (
   }
 
   ZeroMem (&Response, sizeof (Response));
-  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
+  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL, &Response, TRUE);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
     return Status;
@@ -449,15 +412,8 @@ RedfishResourceIdentify (
   //
   // Release resource
   //
-  if (Private->Payload != NULL) {
-    RedfishFreeResponse (
-      Response.StatusCode,
-      Response.HeaderCount,
-      Response.Headers,
-      Response.Payload
-      );
-    Private->Payload = NULL;
-  }
+  RedfishHttpFreeResponse (&Response);
+  Private->Payload = NULL;
 
   if (Private->Json != NULL) {
     FreePool (Private->Json);
@@ -539,11 +495,6 @@ RedfishResourceStop (
     Private->RedfishService = NULL;
   }
 
-  if (Private->Payload != NULL) {
-    RedfishCleanupPayload (Private->Payload);
-    Private->Payload = NULL;
-  }
-
   return EFI_SUCCESS;
 }
 
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#116147): https://edk2.groups.io/g/devel/message/116147
Mute This Topic: https://groups.io/mt/104640228/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [edk2-redfish-client][PATCH 07/13] RedfishClientPkg/BiosDxe: ues RedfishHttpLib
  2024-02-29  8:54 [edk2-devel] [edk2-redfish-client][PATCH 07/13] RedfishClientPkg/BiosDxe: ues RedfishHttpLib Nickle Wang via groups.io
@ 2024-03-04  1:58 ` Chang, Abner via groups.io
  0 siblings, 0 replies; 2+ messages in thread
From: Chang, Abner via groups.io @ 2024-03-04  1:58 UTC (permalink / raw)
  To: Nickle Wang, devel@edk2.groups.io; +Cc: Igor Kulchytskyy

[AMD Official Use Only - General]

Reviewed-by: Abner Chang <abner.chang@amd.com>

> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Thursday, February 29, 2024 4:55 PM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>
> Subject: [edk2-redfish-client][PATCH 07/13] RedfishClientPkg/BiosDxe: ues
> RedfishHttpLib
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Use EDK2 RedfishHttpLib to replace RedfishHttpCacheLib and RedfishLib
>
> Signed-off-by: Nickle Wang <nicklew@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
>  .../Features/Bios/v1_0_9/Dxe/BiosDxe.inf      |   3 +-
>  .../Features/Bios/v1_0_9/Common/BiosCommon.c  |  92 +++++++-------
>  .../Features/Bios/v1_0_9/Dxe/BiosDxe.c        | 113 +++++-------------
>  3 files changed, 74 insertions(+), 134 deletions(-)
>
> diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
> b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
> index 6ba4c3cfa..a2ac18e61 100644
> --- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
> +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
> @@ -32,14 +32,13 @@
>    BaseMemoryLib
>    DebugLib
>    EdkIIRedfishResourceConfigLib
> -  RedfishLib
> +  RedfishHttpLib
>    RedfishFeatureUtilityLib
>    RedfishVersionLib
>    RedfishResourceIdentifyLib
>    UefiLib
>    UefiDriverEntryPoint
>    RedfishAddendumLib
> -  RedfishHttpCacheLib
>
>  [Protocols]
>    gEdkIIRedfishConfigHandlerProtocolGuid          ## PRODUCED
> diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
> b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
> index f3f993c87..1f3c30147 100644
> --- a/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
> +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
> @@ -2,7 +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.
> +  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>
> @@ -68,7 +68,7 @@ RedfishConsumeResourceCommon (
>      // No change
>      //
>      DEBUG ((DEBUG_MANAGEABILITY, "%a, ETAG: %s has no change, ignore
> consume action\n", __func__, Private->Uri));
> -    Status = EFI_ALREADY_STARTED;
> +    Status = EFI_SUCCESS;
>      goto ON_RELEASE;
>    }
>
> @@ -268,18 +268,18 @@ ProvisioningBiosResource (
>    IN  EFI_STRING                       ConfigureLang
>    )
>  {
> -  CHAR8       *Json;
> -  CHAR8       *JsonWithAddendum;
> -  EFI_STATUS  Status;
> -  EFI_STRING  NewResourceLocation;
> -  CHAR8       *EtagStr;
> -  CHAR8       ResourceId[16];
> +  CHAR8             *Json;
> +  CHAR8             *JsonWithAddendum;
> +  EFI_STATUS        Status;
> +  EFI_STRING        NewResourceLocation;
> +  CHAR8             ResourceId[16];
> +  REDFISH_RESPONSE  Response;
>
>    if (IS_EMPTY_STRING (ConfigureLang) || (Private == NULL)) {
>      return EFI_INVALID_PARAMETER;
>    }
>
> -  EtagStr = NULL;
> +  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
>    AsciiSPrint (ResourceId, sizeof (ResourceId), "%d", Index);
>
>    Status = ProvisioningBiosProperties (
> @@ -327,27 +327,27 @@ ProvisioningBiosResource (
>      JsonWithAddendum = NULL;
>    }
>
> -  Status = CreatePayloadToPostResource (Private->RedfishService, Private-
> >Payload, Json, &NewResourceLocation, &EtagStr);
> +  Status = RedfishHttpPostResource (Private->RedfishService, Private->Uri,
> Json, &Response);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, post Bios resource for %s failed: %r\n",
> __func__, ConfigureLang, Status));
>      goto RELEASE_RESOURCE;
>    }
>
> -  ASSERT (NewResourceLocation != NULL);
> -
>    //
> -  // Keep location of new resource.
> +  // Per Redfish spec. the URL of new resource will be returned in "Location"
> header.
>    //
> -  if (NewResourceLocation != NULL) {
> -    RedfishSetRedfishUri (ConfigureLang, NewResourceLocation);
> +  Status = GetHttpResponseLocation (&Response, &NewResourceLocation);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: cannot find new location: %r\n", __func__,
> Status));
> +    goto RELEASE_RESOURCE;
>    }
>
>    //
> -  // Handle Etag
> +  // Keep location of new resource.
>    //
> -  if (EtagStr != NULL) {
> -    SetEtagWithUri (EtagStr, NewResourceLocation);
> -    FreePool (EtagStr);
> +  if (NewResourceLocation != NULL) {
> +    DEBUG ((DEBUG_MANAGEABILITY, "%a: Location: %s\n", __func__,
> NewResourceLocation));
> +    RedfishSetRedfishUri (ConfigureLang, NewResourceLocation);
>    }
>
>  RELEASE_RESOURCE:
> @@ -360,6 +360,8 @@ RELEASE_RESOURCE:
>      FreePool (Json);
>    }
>
> +  RedfishHttpFreeResponse (&Response);
> +
>    return Status;
>  }
>
> @@ -402,19 +404,19 @@ ProvisioningBiosExistResource (
>    IN  REDFISH_RESOURCE_COMMON_PRIVATE  *Private
>    )
>  {
> -  EFI_STATUS  Status;
> -  EFI_STRING  ConfigureLang;
> -  CHAR8       *EtagStr;
> -  CHAR8       *Json;
> -  CHAR8       *JsonWithAddendum;
> +  EFI_STATUS        Status;
> +  EFI_STRING        ConfigureLang;
> +  CHAR8             *Json;
> +  CHAR8             *JsonWithAddendum;
> +  REDFISH_RESPONSE  Response;
>
>    if (Private == NULL) {
>      return EFI_INVALID_PARAMETER;
>    }
>
> -  EtagStr       = NULL;
>    Json          = NULL;
>    ConfigureLang = NULL;
> +  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
>
>    ConfigureLang = RedfishGetConfigLanguage (Private->Uri);
>    if (ConfigureLang == NULL) {
> @@ -473,23 +475,17 @@ ProvisioningBiosExistResource (
>
>    DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for
> %s\n", __func__, ConfigureLang));
>    //
> -  // PUT back to instance
> +  // PATCH back to instance
>    //
> -  Status = CreatePayloadToPatchResource (Private->RedfishService, Private-
> >Payload, Json, &EtagStr);
> +  Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri,
> Json, &Response);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n",
> __func__, ConfigureLang, Status));
>    }
>
> -  //
> -  // Handle Etag
> -  //
> -  if (EtagStr != NULL) {
> -    SetEtagWithUri (EtagStr, Private->Uri);
> -    FreePool (EtagStr);
> -  }
> -
>  ON_RELEASE:
>
> +  RedfishHttpFreeResponse (&Response);
> +
>    if (Json != NULL) {
>      FreePool (Json);
>    }
> @@ -609,19 +605,19 @@ RedfishUpdateResourceCommon (
>    IN     CHAR8                            *InputJson
>    )
>  {
> -  EFI_STATUS  Status;
> -  CHAR8       *Json;
> -  CHAR8       *JsonWithAddendum;
> -  EFI_STRING  ConfigureLang;
> -  CHAR8       *EtagStr;
> +  EFI_STATUS        Status;
> +  CHAR8             *Json;
> +  CHAR8             *JsonWithAddendum;
> +  EFI_STRING        ConfigureLang;
> +  REDFISH_RESPONSE  Response;
>
>    if ((Private == NULL) || IS_EMPTY_STRING (InputJson)) {
>      return EFI_INVALID_PARAMETER;
>    }
>
> -  EtagStr       = NULL;
>    Json          = NULL;
>    ConfigureLang = NULL;
> +  ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
>
>    ConfigureLang = RedfishGetConfigLanguage (Private->Uri);
>    if (ConfigureLang == NULL) {
> @@ -680,23 +676,17 @@ RedfishUpdateResourceCommon (
>
>    DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s\n",
> __func__, ConfigureLang));
>    //
> -  // PUT back to instance
> +  // PATCH back to instance
>    //
> -  Status = CreatePayloadToPatchResource (Private->RedfishService, Private-
> >Payload, Json, &EtagStr);
> +  Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri,
> Json, &Response);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n",
> __func__, ConfigureLang, Status));
>    }
>
> -  //
> -  // Handle Etag
> -  //
> -  if (EtagStr != NULL) {
> -    SetEtagWithUri (EtagStr, Private->Uri);
> -    FreePool (EtagStr);
> -  }
> -
>  ON_RELEASE:
>
> +  RedfishHttpFreeResponse (&Response);
> +
>    if (Json != NULL) {
>      FreePool (Json);
>    }
> diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
> b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
> index a442d446b..1ca920640 100644
> --- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
> +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
> @@ -57,7 +57,7 @@ RedfishResourceProvisioningResource (
>    }
>
>    ZeroMem (&Response, sizeof (Response));
> -  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response,
> TRUE);
> +  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL,
> &Response, TRUE);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__,
> Uri));
>      return Status;
> @@ -68,20 +68,20 @@ RedfishResourceProvisioningResource (
>    ASSERT (Private->Payload != NULL);
>
>    Status = RedfishProvisioningResourceCommon (Private, !PostMode);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: failed to provision resource to: %s: %r\n",
> __func__, Uri, Status));
> +  } else {
> +    //
> +    // Get latest ETag on URI and keep it in variable.
> +    //
> +    SetEtagFromUri (Private->RedfishService, Private->Uri, TRUE);
> +  }
>
>    //
>    // Release resource
>    //
> -  if (Private->Payload != NULL) {
> -    RedfishFreeResponse (
> -      Response.StatusCode,
> -      Response.HeaderCount,
> -      Response.Headers,
> -      Response.Payload
> -      );
> -    RedfishHttpResetResource (Uri);
> -    Private->Payload = NULL;
> -  }
> +  RedfishHttpFreeResponse (&Response);
> +  Private->Payload = NULL;
>
>    return Status;
>  }
> @@ -122,7 +122,7 @@ RedfishResourceConsumeResource (
>    }
>
>    ZeroMem (&Response, sizeof (Response));
> -  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response,
> TRUE);
> +  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL,
> &Response, TRUE);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__,
> Uri));
>      return Status;
> @@ -131,7 +131,7 @@ RedfishResourceConsumeResource (
>    //
>    // Check and see if "@Redfish.Settings" exist or not.
>    //
> -  ZeroMem (&PendingSettingResponse, sizeof (REDFISH_RESPONSE));
> +  ZeroMem (&PendingSettingResponse, sizeof (PendingSettingResponse));
>    PendingSettingUri = NULL;
>    Status            = GetPendingSettings (
>                          Private->RedfishService,
> @@ -161,42 +161,15 @@ RedfishResourceConsumeResource (
>    GetHttpResponseEtag (ExpectedResponse, &Etag);
>    Status = RedfishConsumeResourceCommon (Private, Private->Json, Etag);
>    if (EFI_ERROR (Status)) {
> -    if (Status != EFI_ALREADY_STARTED) {
> -      DEBUG ((DEBUG_ERROR, "%a, failed to consume resource from: %s:
> %r\n", __func__, Uri, Status));
> -    }
> -  } else {
> -    //
> -    // Keep etag after consuming pending settings.
> -    //
> -    if (Etag != NULL) {
> -      SetEtagWithUri (Etag, Private->Uri);
> -    }
> +    DEBUG ((DEBUG_ERROR, "%a: failed to consume resource from: %s: %r\n",
> __func__, Private->Uri, Status));
>    }
>
>    //
>    // Release resource
>    //
> -  if (Private->Payload != NULL) {
> -    if (Response.Payload != NULL) {
> -      RedfishFreeResponse (
> -        Response.StatusCode,
> -        Response.HeaderCount,
> -        Response.Headers,
> -        Response.Payload
> -        );
> -    }
> -
> -    if (PendingSettingResponse.Payload != NULL) {
> -      RedfishFreeResponse (
> -        PendingSettingResponse.StatusCode,
> -        PendingSettingResponse.HeaderCount,
> -        PendingSettingResponse.Headers,
> -        PendingSettingResponse.Payload
> -        );
> -    }
> -
> -    Private->Payload = NULL;
> -  }
> +  RedfishHttpFreeResponse (&Response);
> +  RedfishHttpFreeResponse (&PendingSettingResponse);
> +  Private->Payload = NULL;
>
>    if (Private->Json != NULL) {
>      FreePool (Private->Json);
> @@ -278,7 +251,7 @@ RedfishResourceUpdate (
>    }
>
>    ZeroMem (&Response, sizeof (Response));
> -  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response,
> TRUE);
> +  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL,
> &Response, TRUE);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__,
> Uri));
>      return Status;
> @@ -293,22 +266,19 @@ RedfishResourceUpdate (
>
>    Status = RedfishUpdateResourceCommon (Private, Private->Json);
>    if (EFI_ERROR (Status)) {
> -    DEBUG ((DEBUG_ERROR, "%a, failed to update resource from: %s: %r\n",
> __func__, Uri, Status));
> +    DEBUG ((DEBUG_ERROR, "%a: failed to update resource to: %s: %r\n",
> __func__, Uri, Status));
> +  } else {
> +    //
> +    // Get latest ETag on URI and keep it in variable.
> +    //
> +    SetEtagFromUri (Private->RedfishService, Private->Uri, TRUE);
>    }
>
>    //
>    // Release resource
>    //
> -  if (Private->Payload != NULL) {
> -    RedfishFreeResponse (
> -      Response.StatusCode,
> -      Response.HeaderCount,
> -      Response.Headers,
> -      Response.Payload
> -      );
> -    RedfishHttpResetResource (Uri);
> -    Private->Payload = NULL;
> -  }
> +  RedfishHttpFreeResponse (&Response);
> +  Private->Payload = NULL;
>
>    if (Private->Json != NULL) {
>      FreePool (Private->Json);
> @@ -351,7 +321,7 @@ RedfishResourceCheck (
>    }
>
>    ZeroMem (&Response, sizeof (Response));
> -  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response,
> TRUE);
> +  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL,
> &Response, TRUE);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__,
> Uri));
>      return Status;
> @@ -377,15 +347,8 @@ RedfishResourceCheck (
>    //
>    // Release resource
>    //
> -  if (Private->Payload != NULL) {
> -    RedfishFreeResponse (
> -      Response.StatusCode,
> -      Response.HeaderCount,
> -      Response.Headers,
> -      Response.Payload
> -      );
> -    Private->Payload = NULL;
> -  }
> +  RedfishHttpFreeResponse (&Response);
> +  Private->Payload = NULL;
>
>    if (Private->Json != NULL) {
>      FreePool (Private->Json);
> @@ -428,7 +391,7 @@ RedfishResourceIdentify (
>    }
>
>    ZeroMem (&Response, sizeof (Response));
> -  Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response,
> TRUE);
> +  Status = RedfishHttpGetResource (Private->RedfishService, Uri, NULL,
> &Response, TRUE);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__,
> Uri));
>      return Status;
> @@ -449,15 +412,8 @@ RedfishResourceIdentify (
>    //
>    // Release resource
>    //
> -  if (Private->Payload != NULL) {
> -    RedfishFreeResponse (
> -      Response.StatusCode,
> -      Response.HeaderCount,
> -      Response.Headers,
> -      Response.Payload
> -      );
> -    Private->Payload = NULL;
> -  }
> +  RedfishHttpFreeResponse (&Response);
> +  Private->Payload = NULL;
>
>    if (Private->Json != NULL) {
>      FreePool (Private->Json);
> @@ -539,11 +495,6 @@ RedfishResourceStop (
>      Private->RedfishService = NULL;
>    }
>
> -  if (Private->Payload != NULL) {
> -    RedfishCleanupPayload (Private->Payload);
> -    Private->Payload = NULL;
> -  }
> -
>    return EFI_SUCCESS;
>  }
>
> --
> 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#116300): https://edk2.groups.io/g/devel/message/116300
Mute This Topic: https://groups.io/mt/104640228/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-04  1:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-29  8:54 [edk2-devel] [edk2-redfish-client][PATCH 07/13] RedfishClientPkg/BiosDxe: ues RedfishHttpLib Nickle Wang via groups.io
2024-03-04  1:58 ` Chang, Abner via groups.io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox