]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Update cache management in HTTP boot driver.
authorFu Siyuan <siyuan.fu@intel.com>
Mon, 14 Sep 2015 09:05:12 +0000 (09:05 +0000)
committersfu5 <sfu5@Edk2>
Mon, 14 Sep 2015 09:05:12 +0000 (09:05 +0000)
The original HTTP boot driver always save the received message body in its cache,
it bring a large of memory allocation during HTTP download. This patch updates
the HTTP boot driver to only cache data when caller doesn't provide a buffer for
download (which is usually used when caller want to get the required buffer size).

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18448 6f19259b-4bc3-4df7-8a09-765794883524

NetworkPkg/HttpBootDxe/HttpBootClient.c

index 3b4afc396f01071b272df5014a51ba5685fb6f27..5669c5f37ce1f511879fe117d34f8420cf2a12d3 100644 (file)
@@ -458,22 +458,6 @@ HttpBootGetBootFileCallback (
   }\r
 \r
   CallbackData = (HTTP_BOOT_CALLBACK_DATA *) Context;\r
   }\r
 \r
   CallbackData = (HTTP_BOOT_CALLBACK_DATA *) Context;\r
-\r
-  //\r
-  // Save the data into cache list.\r
-  //\r
-  NewEntityData = AllocatePool (sizeof (HTTP_BOOT_ENTITY_DATA));\r
-  if (NewEntityData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  if (CallbackData->NewBlock) {\r
-    NewEntityData->Block = CallbackData->Block;\r
-    CallbackData->Block = NULL;\r
-  }\r
-  NewEntityData->DataLength = Length;\r
-  NewEntityData->DataStart  = (UINT8*) Data;\r
-  InsertTailList (&CallbackData->Cache->EntityDataList, &NewEntityData->Link);\r
-\r
   //\r
   // Copy data if caller has provided a buffer.\r
   //\r
   //\r
   // Copy data if caller has provided a buffer.\r
   //\r
@@ -486,6 +470,22 @@ HttpBootGetBootFileCallback (
     CallbackData->CopyedSize += MIN (Length, CallbackData->BufferSize - CallbackData->CopyedSize);\r
   }\r
 \r
     CallbackData->CopyedSize += MIN (Length, CallbackData->BufferSize - CallbackData->CopyedSize);\r
   }\r
 \r
+  //\r
+  // The caller doesn't provide a buffer, save the block into cache list.\r
+  //\r
+  if (CallbackData->Cache != NULL) {\r
+    NewEntityData = AllocatePool (sizeof (HTTP_BOOT_ENTITY_DATA));\r
+    if (NewEntityData == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    if (CallbackData->NewBlock) {\r
+      NewEntityData->Block = CallbackData->Block;\r
+      CallbackData->Block = NULL;\r
+    }\r
+    NewEntityData->DataLength = Length;\r
+    NewEntityData->DataStart  = (UINT8*) Data;\r
+    InsertTailList (&CallbackData->Cache->EntityDataList, &NewEntityData->Link);\r
+  }\r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -566,10 +566,10 @@ HttpBootGetBootFile (
   //\r
 \r
   //\r
   //\r
 \r
   //\r
-  // 1. Create a temp cache item for the requested URI.\r
+  // 1. Create a temp cache item for the requested URI if caller doesn't provide buffer.\r
   //\r
   Cache = NULL;\r
   //\r
   Cache = NULL;\r
-  if (!HeaderOnly) {\r
+  if ((!HeaderOnly) && (*BufferSize == 0)) {\r
     Cache = AllocateZeroPool (sizeof (HTTP_BOOT_CACHE_CONTENT));\r
     if (Cache == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
     Cache = AllocateZeroPool (sizeof (HTTP_BOOT_CACHE_CONTENT));\r
     if (Cache == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
@@ -659,7 +659,7 @@ HttpBootGetBootFile (
   //\r
   // 2.3 Record the request info in a temp cache item.\r
   //\r
   //\r
   // 2.3 Record the request info in a temp cache item.\r
   //\r
-  if (!HeaderOnly) {\r
+  if (Cache != NULL) {\r
     Cache->RequestData = RequestData;\r
   }\r
 \r
     Cache->RequestData = RequestData;\r
   }\r
 \r
@@ -703,7 +703,7 @@ HttpBootGetBootFile (
   //\r
   // 3.2 Cache the response header.\r
   //\r
   //\r
   // 3.2 Cache the response header.\r
   //\r
-  if (!HeaderOnly) {\r
+  if (Cache != NULL) {\r
     Cache->ResponseData = ResponseData;\r
   }\r
   \r
     Cache->ResponseData = ResponseData;\r
   }\r
   \r
@@ -733,17 +733,26 @@ HttpBootGetBootFile (
   //\r
   // 3.4 Continue to receive and parse message-body if needed.\r
   //\r
   //\r
   // 3.4 Continue to receive and parse message-body if needed.\r
   //\r
+  Block = NULL;\r
   if (!HeaderOnly) {\r
     ZeroMem (&ResponseBody, sizeof (HTTP_IO_RESOPNSE_DATA));\r
     while (!HttpIsMessageComplete (Parser)) {\r
       //\r
   if (!HeaderOnly) {\r
     ZeroMem (&ResponseBody, sizeof (HTTP_IO_RESOPNSE_DATA));\r
     while (!HttpIsMessageComplete (Parser)) {\r
       //\r
-      // Allocate a new block to hold the message-body.\r
+      // Allocate a block to hold the message-body, if caller doesn't provide\r
+      // a buffer, the block will be cached and we will allocate a new one here.\r
       //\r
       //\r
-      Block = AllocatePool (HTTP_BOOT_BLOCK_SIZE);\r
-      if (Block == NULL) {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
-        goto ERROR_6;\r
+      if (Block == NULL || Context.BufferSize == 0) {\r
+        Block = AllocatePool (HTTP_BOOT_BLOCK_SIZE);\r
+        if (Block == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto ERROR_6;\r
+        }\r
+        Context.NewBlock = TRUE;\r
+        Context.Block = Block;\r
+      } else {\r
+        Context.NewBlock = FALSE;\r
       }\r
       }\r
+\r
       ResponseBody.Body       = (CHAR8*) Block;\r
       ResponseBody.BodyLength = HTTP_BOOT_BLOCK_SIZE;\r
       Status = HttpIoRecvResponse (\r
       ResponseBody.Body       = (CHAR8*) Block;\r
       ResponseBody.BodyLength = HTTP_BOOT_BLOCK_SIZE;\r
       Status = HttpIoRecvResponse (\r
@@ -758,8 +767,6 @@ HttpBootGetBootFile (
       //\r
       // Parse the new received block of the message-body, the block will be saved in cache.\r
       //\r
       //\r
       // Parse the new received block of the message-body, the block will be saved in cache.\r
       //\r
-      Context.NewBlock = TRUE;\r
-      Context.Block    = Block;\r
       Status = HttpParseMessageBody (\r
                  Parser,\r
                  ResponseBody.BodyLength,\r
       Status = HttpParseMessageBody (\r
                  Parser,\r
                  ResponseBody.BodyLength,\r
@@ -787,7 +794,7 @@ HttpBootGetBootFile (
   //\r
   // 4. Save the cache item to driver's cache list and return.\r
   //\r
   //\r
   // 4. Save the cache item to driver's cache list and return.\r
   //\r
-  if (!HeaderOnly) {\r
+  if (Cache != NULL) {\r
     Cache->EntityLength = ContentLength;\r
     InsertTailList (&Private->CacheList, &Cache->Link);\r
   }\r
     Cache->EntityLength = ContentLength;\r
     InsertTailList (&Private->CacheList, &Cache->Link);\r
   }\r