[edk2] [Patch] NetworkPkg: Need update Http token status while timeout happened
Http token status should be updated to EFI_TIMEOUT while timeout happened by any abruptly interrupted (e.g. network disconnection, cable plug/unplug...). Otherwise, HttpBootDxe driver will continue treat it as no error happened, and its ReceivedSize will be updated to ContentLength directly. Moreover, If download image type is RAM Disk, the corresponding info will be registered to system. Cc: Ye Ting Cc: Fu Siyuan Cc: Gary Lin Cc: Samer El-Haj-Mahmoud Cc: Hegde Nagaraj P Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu --- NetworkPkg/HttpDxe/HttpImpl.c | 3 +++ NetworkPkg/HttpDxe/HttpProto.c | 16 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c index f4ae28a..05a96e9 100644 --- a/NetworkPkg/HttpDxe/HttpImpl.c +++ b/NetworkPkg/HttpDxe/HttpImpl.c @@ -1259,10 +1259,13 @@ Exit: Error2: NetMapInsertHead (&HttpInstance->TxTokens, ValueInItem->HttpToken, ValueInItem); Error: + + HttpCloseConnection (HttpInstance); + HttpTcpTokenCleanup (Wrap); if (HttpHeaders != NULL) { FreePool (HttpHeaders); } diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c index afa7fe4..c3608c0 100644 --- a/NetworkPkg/HttpDxe/HttpProto.c +++ b/NetworkPkg/HttpDxe/HttpProto.c @@ -1,9 +1,9 @@ /** @file Miscellaneous routines for HttpDxe driver. -Copyright (c) 2015, Intel Corporation. All rights reserved. +Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved. (C) Copyright 2016 Hewlett Packard Enterprise Development LP This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -1605,10 +1605,11 @@ HttpTcpReceiveHeader ( while (!HttpInstance->IsRxDone && ((Timeout == NULL) || EFI_ERROR (gBS->CheckEvent (Timeout { Tcp4->Poll (Tcp4); } if (!HttpInstance->IsRxDone) { +Tcp4->Cancel (Tcp4, &Rx4Token->CompletionToken); gBS->CloseEvent (Rx4Token->CompletionToken.Event); Rx4Token->CompletionToken.Status = EFI_TIMEOUT; } Status = Rx4Token->CompletionToken.Status; @@ -1671,10 +1672,11 @@ HttpTcpReceiveHeader ( while (!HttpInstance->IsRxDone && ((Timeout == NULL) || EFI_ERROR (gBS->CheckEvent (Timeout { Tcp6->Poll (Tcp6); } if (!HttpInstance->IsRxDone) { +Tcp6->Cancel (Tcp6, &Rx6Token->CompletionToken); gBS->CloseEvent (Rx6Token->CompletionToken.Event); Rx6Token->CompletionToken.Status = EFI_TIMEOUT; } Status = Rx6Token->CompletionToken.Status; @@ -1745,11 +1747,12 @@ HttpTcpReceiveBody ( HTTP_PROTOCOL *HttpInstance; EFI_TCP6_PROTOCOL *Tcp6; EFI_TCP6_IO_TOKEN *Rx6Token; EFI_TCP4_PROTOCOL *Tcp4; EFI_TCP4_IO_TOKEN *Rx4Token; - + + Status = EFI_SUCCESS; HttpInstance = Wrap->HttpInstance; Tcp4 = HttpInstance->Tcp4; Tcp6 = HttpInstance->Tcp6; Rx4Token = NULL; Rx6Token = NULL; @@ -1776,14 +1779,15 @@ HttpTcpReceiveBody ( while (!Wrap->TcpWrap.IsRxDone && ((Timeout == NULL) || EFI_ERROR (gBS->CheckEvent (Timeout { Tcp6->Poll (Tcp6); } if (!Wrap->TcpWrap.IsRxDone) { + Tcp6->Cancel (Tcp6, &Rx6Token->CompletionToken); gBS->CloseEvent (Rx6Token->CompletionToken.Event); + Rx6Token->CompletionToken.Event = NULL; Rx6Token->CompletionToken.Status = EFI_TIMEOUT; Wrap->HttpToken->Status = Rx6Token->CompletionToken.Status; - gBS->SignalEvent (Wrap->HttpToken->Event); } } else { Rx4Token = &Wrap->TcpWrap.Rx4Token; Rx4Token->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength; Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength; @@ -1799,19 +1803,21 @@ HttpTcpReceiveBody ( while (!Wrap->TcpWrap.IsRxDone && ((Timeout == NULL) || EFI_ERROR (gBS->CheckEvent (Timeout { Tcp4->Poll (Tcp4); } if (!Wrap->TcpWrap.IsRxDone) { + Tcp4->Cancel (Tcp4, &Rx4Token->CompletionToken); gBS->CloseEvent (Rx4Token->CompletionToken.Event); + Rx4Token->CompletionToken.Event = NULL; Rx4Token->CompletionToken.Status = EFI_TIMEOUT; Wrap->HttpToken->Status = Rx4Token->CompletionToken.Status; - gBS->SignalEvent (Wrap->HttpToken->Event); } } - return EFI_SUCCESS; + Status = Wrap->HttpToken->Status; + return Status; } /** Clean up Tcp Tokens while the Tcp transmission error occurs. -- 1.9.5.msysgit.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] NetworkPkg: Need update Http token status while timeout happened
On Fri, May 20, 2016 at 03:24:29PM +0800, Jiaxin Wu wrote: > Http token status should be updated to EFI_TIMEOUT while timeout > happened by any abruptly interrupted (e.g. network disconnection, > cable plug/unplug...). Otherwise, HttpBootDxe driver will continue > treat it as no error happened, and its ReceivedSize will be updated > to ContentLength directly. Moreover, If download image type is RAM > Disk, the corresponding info will be registered to system. > Hi Jiaxin, I just tested the patch. It works well for me. Here is how the patch was tested. I started OVMF to connect to the host with a tap interface with IP address 192.168.111.1 and then started the dhcp and http server on the host. A new HTTP boot entry was created from HII to download a 2.9 GB iso file. When OVMF was downloading the iso, I changed the IP to 192.168.100.1 to make the timeout deliberately. After applying the patch, OVMF went back to the BDS HII as expected. What's interesting is that, before applying the patch, OVMF just loaded the unfinished iso, created a RAMDISK, and loaded the bootloader. It's probably because that HttpTcpReceiveBody always returned EFI_SUCCESS. So, the patch does a good work :) Just one nitpicking thing: the line below HttpCloseConnection introdued trailing whitespaces. Reviewed-by: Gary Lin and Tested-by: Gary Lin Cheers, Gary Lin > Cc: Ye Ting > Cc: Fu Siyuan > Cc: Gary Lin > Cc: Samer El-Haj-Mahmoud > Cc: Hegde Nagaraj P > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jiaxin Wu > --- > NetworkPkg/HttpDxe/HttpImpl.c | 3 +++ > NetworkPkg/HttpDxe/HttpProto.c | 16 +++- > 2 files changed, 14 insertions(+), 5 deletions(-) > > diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c > index f4ae28a..05a96e9 100644 > --- a/NetworkPkg/HttpDxe/HttpImpl.c > +++ b/NetworkPkg/HttpDxe/HttpImpl.c > @@ -1259,10 +1259,13 @@ Exit: > > Error2: >NetMapInsertHead (&HttpInstance->TxTokens, ValueInItem->HttpToken, > ValueInItem); > > Error: > + > + HttpCloseConnection (HttpInstance); > + >HttpTcpTokenCleanup (Wrap); > >if (HttpHeaders != NULL) { > FreePool (HttpHeaders); >} > diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c > index afa7fe4..c3608c0 100644 > --- a/NetworkPkg/HttpDxe/HttpProto.c > +++ b/NetworkPkg/HttpDxe/HttpProto.c > @@ -1,9 +1,9 @@ > /** @file >Miscellaneous routines for HttpDxe driver. > > -Copyright (c) 2015, Intel Corporation. All rights reserved. > +Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved. > (C) Copyright 2016 Hewlett Packard Enterprise Development LP > This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD > License > which accompanies this distribution. The full text of the license may be > found at > http://opensource.org/licenses/bsd-license.php > @@ -1605,10 +1605,11 @@ HttpTcpReceiveHeader ( >while (!HttpInstance->IsRxDone && ((Timeout == NULL) || EFI_ERROR > (gBS->CheckEvent (Timeout { > Tcp4->Poll (Tcp4); >} > >if (!HttpInstance->IsRxDone) { > +Tcp4->Cancel (Tcp4, &Rx4Token->CompletionToken); > gBS->CloseEvent (Rx4Token->CompletionToken.Event); > Rx4Token->CompletionToken.Status = EFI_TIMEOUT; >} > >Status = Rx4Token->CompletionToken.Status; > @@ -1671,10 +1672,11 @@ HttpTcpReceiveHeader ( >while (!HttpInstance->IsRxDone && ((Timeout == NULL) || EFI_ERROR > (gBS->CheckEvent (Timeout { > Tcp6->Poll (Tcp6); >} > >if (!HttpInstance->IsRxDone) { > +Tcp6->Cancel (Tcp6, &Rx6Token->CompletionToken); > gBS->CloseEvent (Rx6Token->CompletionToken.Event); > Rx6Token->CompletionToken.Status = EFI_TIMEOUT; >} > >Status = Rx6Token->CompletionToken.Status; > @@ -1745,11 +1747,12 @@ HttpTcpReceiveBody ( >HTTP_PROTOCOL *HttpInstance; >EFI_TCP6_PROTOCOL *Tcp6; >EFI_TCP6_IO_TOKEN *Rx6Token; >EFI_TCP4_PROTOCOL *Tcp4; >EFI_TCP4_IO_TOKEN *Rx4Token; > - > + > + Status = EFI_SUCCESS; >HttpInstance = Wrap->HttpInstance; >Tcp4 = HttpInstance->Tcp4; >Tcp6 = HttpInstance->Tcp6; >Rx4Token = NULL; >Rx6Token = NULL; > @@ -1776,14 +1779,15 @@ HttpTcpReceiveBody ( > while (!Wrap->TcpWrap.IsRxDone && ((Timeout == NULL) || EFI_ERROR > (gBS->CheckEvent (Timeout { >Tcp6->Poll (Tcp6); > } > > if (!Wrap->TcpWrap.IsRxDone) { > + Tcp6->Cancel (Tcp6, &Rx6Token->CompletionToken); >gBS->CloseEvent (Rx6Token->CompletionToken.Event); > + Rx6Token->CompletionToken.Event = NULL; >Rx6Token->CompletionToken.Status = EFI_TIMEOUT; >Wrap->HttpToken->Status = Rx6Token->CompletionToken.Status; > - gBS->SignalEvent (Wrap->HttpToken->Event); > } >} else { > Rx4To
Re: [edk2] [Patch] NetworkPkg: Need update Http token status while timeout happened
Hi, Jiaxin The Http->Response() is a unblocking interface, that the function return status should be SUCCESS once the token has been queued to the driver. Then if there is an error later, the Status in the token should be updated and Event will be signaled. So I think the original code in HTTP driver does make sense, but the HTTP boot driver function has bug that, when download the message body, it should also check the Status in the token, not only the function. Best Regards Siyuan > -Original Message- > From: Wu, Jiaxin > Sent: Friday, May 20, 2016 3:24 PM > To: edk2-devel@lists.01.org > Cc: Ye, Ting ; Fu, Siyuan ; Gary Lin > ; Samer El-Haj-Mahmoud ; Hegde Nagaraj > P > Subject: [Patch] NetworkPkg: Need update Http token status while timeout > happened > > Http token status should be updated to EFI_TIMEOUT while timeout > happened by any abruptly interrupted (e.g. network disconnection, > cable plug/unplug...). Otherwise, HttpBootDxe driver will continue > treat it as no error happened, and its ReceivedSize will be updated > to ContentLength directly. Moreover, If download image type is RAM > Disk, the corresponding info will be registered to system. > > Cc: Ye Ting > Cc: Fu Siyuan > Cc: Gary Lin > Cc: Samer El-Haj-Mahmoud > Cc: Hegde Nagaraj P > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jiaxin Wu > --- > NetworkPkg/HttpDxe/HttpImpl.c | 3 +++ > NetworkPkg/HttpDxe/HttpProto.c | 16 +++- > 2 files changed, 14 insertions(+), 5 deletions(-) > > diff --git a/NetworkPkg/HttpDxe/HttpImpl.c > b/NetworkPkg/HttpDxe/HttpImpl.c > index f4ae28a..05a96e9 100644 > --- a/NetworkPkg/HttpDxe/HttpImpl.c > +++ b/NetworkPkg/HttpDxe/HttpImpl.c > @@ -1259,10 +1259,13 @@ Exit: > > Error2: >NetMapInsertHead (&HttpInstance->TxTokens, ValueInItem->HttpToken, > ValueInItem); > > Error: > + > + HttpCloseConnection (HttpInstance); > + >HttpTcpTokenCleanup (Wrap); > >if (HttpHeaders != NULL) { > FreePool (HttpHeaders); >} > diff --git a/NetworkPkg/HttpDxe/HttpProto.c > b/NetworkPkg/HttpDxe/HttpProto.c > index afa7fe4..c3608c0 100644 > --- a/NetworkPkg/HttpDxe/HttpProto.c > +++ b/NetworkPkg/HttpDxe/HttpProto.c > @@ -1,9 +1,9 @@ > /** @file >Miscellaneous routines for HttpDxe driver. > > -Copyright (c) 2015, Intel Corporation. All rights reserved. > +Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved. > (C) Copyright 2016 Hewlett Packard Enterprise Development LP > This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD > License > which accompanies this distribution. The full text of the license may be > found at > http://opensource.org/licenses/bsd-license.php > @@ -1605,10 +1605,11 @@ HttpTcpReceiveHeader ( >while (!HttpInstance->IsRxDone && ((Timeout == NULL) || EFI_ERROR > (gBS->CheckEvent (Timeout { > Tcp4->Poll (Tcp4); >} > >if (!HttpInstance->IsRxDone) { > +Tcp4->Cancel (Tcp4, &Rx4Token->CompletionToken); > gBS->CloseEvent (Rx4Token->CompletionToken.Event); > Rx4Token->CompletionToken.Status = EFI_TIMEOUT; >} > >Status = Rx4Token->CompletionToken.Status; > @@ -1671,10 +1672,11 @@ HttpTcpReceiveHeader ( >while (!HttpInstance->IsRxDone && ((Timeout == NULL) || EFI_ERROR > (gBS->CheckEvent (Timeout { > Tcp6->Poll (Tcp6); >} > >if (!HttpInstance->IsRxDone) { > +Tcp6->Cancel (Tcp6, &Rx6Token->CompletionToken); > gBS->CloseEvent (Rx6Token->CompletionToken.Event); > Rx6Token->CompletionToken.Status = EFI_TIMEOUT; >} > >Status = Rx6Token->CompletionToken.Status; > @@ -1745,11 +1747,12 @@ HttpTcpReceiveBody ( >HTTP_PROTOCOL *HttpInstance; >EFI_TCP6_PROTOCOL *Tcp6; >EFI_TCP6_IO_TOKEN *Rx6Token; >EFI_TCP4_PROTOCOL *Tcp4; >EFI_TCP4_IO_TOKEN *Rx4Token; > - > + > + Status = EFI_SUCCESS; >HttpInstance = Wrap->HttpInstance; >Tcp4 = HttpInstance->Tcp4; >Tcp6 = HttpInstance->Tcp6; >Rx4Token = NULL; >Rx6Token = NULL; > @@ -1776,14 +1779,15 @@ HttpTcpReceiveBody ( > while (!Wrap->TcpWrap.IsRxDone && ((Timeout == NULL) || EFI_ERROR > (gBS->CheckEvent (Timeout { >Tcp6->Poll (Tcp6); > } > > if (!Wrap->TcpWrap.IsRxDone) { > + Tcp6->Cancel (Tcp6, &Rx6Token->CompletionToken); >gBS->CloseEvent (Rx6Token->CompletionToken.Event); > + Rx6Token->CompletionToken.Event = NULL; >Rx6Token->CompletionToken.Status = EFI_TIMEOUT; >Wrap->HttpToken->Status = Rx6Token->CompletionToken.Status; > - gBS->SignalEvent (Wrap->HttpToken->Event); > } >} else { > Rx4Token = &Wrap->TcpWrap.Rx4Token; > Rx4Token->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength; > Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) > HttpMs
Re: [edk2] [Patch] NetworkPkg: Need update Http token status while timeout happened
Siyuan, I agree Http->Response() is designed to a unblocking interface. Actually, current implementation is blocking one. So, handling EFI_TIMEOUT status in the token (HttpBootDxe driver) or return directly, both of them are fine to me . But Tcp->Cancel() still should be necessary calling if we handle the case in HttpBootDxe driver. Thanks. Jiaxin > -Original Message- > From: Fu, Siyuan > Sent: Tuesday, May 24, 2016 9:17 AM > To: Wu, Jiaxin ; edk2-devel@lists.01.org > Cc: Ye, Ting ; Gary Lin ; Samer El-Haj- > Mahmoud ; Hegde Nagaraj P > Subject: RE: [Patch] NetworkPkg: Need update Http token status while > timeout happened > > Hi, Jiaxin > > The Http->Response() is a unblocking interface, that the function return > status should be SUCCESS once the token has been queued to the driver. > Then if there is an error later, the Status in the token should be updated and > Event will be signaled. > So I think the original code in HTTP driver does make sense, but the HTTP > boot driver function has bug that, when download the message body, it > should also check the Status in the token, not only the function. > > Best Regards > Siyuan > > > > -Original Message- > > From: Wu, Jiaxin > > Sent: Friday, May 20, 2016 3:24 PM > > To: edk2-devel@lists.01.org > > Cc: Ye, Ting ; Fu, Siyuan ; > > Gary Lin ; Samer El-Haj-Mahmoud ; > Hegde > > Nagaraj P > > Subject: [Patch] NetworkPkg: Need update Http token status while > > timeout happened > > > > Http token status should be updated to EFI_TIMEOUT while timeout > > happened by any abruptly interrupted (e.g. network disconnection, > > cable plug/unplug...). Otherwise, HttpBootDxe driver will continue > > treat it as no error happened, and its ReceivedSize will be updated to > > ContentLength directly. Moreover, If download image type is RAM Disk, > > the corresponding info will be registered to system. > > > > Cc: Ye Ting > > Cc: Fu Siyuan > > Cc: Gary Lin > > Cc: Samer El-Haj-Mahmoud > > Cc: Hegde Nagaraj P > > Contributed-under: TianoCore Contribution Agreement 1.0 > > Signed-off-by: Jiaxin Wu > > --- > > NetworkPkg/HttpDxe/HttpImpl.c | 3 +++ > > NetworkPkg/HttpDxe/HttpProto.c | 16 +++- > > 2 files changed, 14 insertions(+), 5 deletions(-) > > > > diff --git a/NetworkPkg/HttpDxe/HttpImpl.c > > b/NetworkPkg/HttpDxe/HttpImpl.c index f4ae28a..05a96e9 100644 > > --- a/NetworkPkg/HttpDxe/HttpImpl.c > > +++ b/NetworkPkg/HttpDxe/HttpImpl.c > > @@ -1259,10 +1259,13 @@ Exit: > > > > Error2: > >NetMapInsertHead (&HttpInstance->TxTokens, ValueInItem->HttpToken, > > ValueInItem); > > > > Error: > > + > > + HttpCloseConnection (HttpInstance); > > + > >HttpTcpTokenCleanup (Wrap); > > > >if (HttpHeaders != NULL) { > > FreePool (HttpHeaders); > >} > > diff --git a/NetworkPkg/HttpDxe/HttpProto.c > > b/NetworkPkg/HttpDxe/HttpProto.c index afa7fe4..c3608c0 100644 > > --- a/NetworkPkg/HttpDxe/HttpProto.c > > +++ b/NetworkPkg/HttpDxe/HttpProto.c > > @@ -1,9 +1,9 @@ > > /** @file > >Miscellaneous routines for HttpDxe driver. > > > > -Copyright (c) 2015, Intel Corporation. All rights reserved. > > +Copyright (c) 2015 - 2016, Intel Corporation. All rights > > +reserved. > > (C) Copyright 2016 Hewlett Packard Enterprise Development LP > > This program and the accompanying materials are licensed and made > > available under the terms and conditions of the BSD License which > > accompanies this distribution. The full text of the license may be > > found at http://opensource.org/licenses/bsd-license.php > > @@ -1605,10 +1605,11 @@ HttpTcpReceiveHeader ( > >while (!HttpInstance->IsRxDone && ((Timeout == NULL) || > > EFI_ERROR (gBS->CheckEvent (Timeout { > > Tcp4->Poll (Tcp4); > >} > > > >if (!HttpInstance->IsRxDone) { > > +Tcp4->Cancel (Tcp4, &Rx4Token->CompletionToken); > > gBS->CloseEvent (Rx4Token->CompletionToken.Event); > > Rx4Token->CompletionToken.Status = EFI_TIMEOUT; > >} > > > >Status = Rx4Token->CompletionToken.Status; @@ -1671,10 +1672,11 > > @@ HttpTcpReceiveHeader ( > >while (!HttpInstance->IsRxDone && ((Timeout == NULL) || > > EFI_ERROR (gBS->CheckEvent (Timeout { > > Tcp6->Poll (Tcp6); > >} > > > >if (!HttpInstance->IsRxDone) { > > +Tcp6->Cancel (Tcp6, &Rx6Token->CompletionToken); > > gBS->CloseEvent (Rx6Token->CompletionToken.Event); > > Rx6Token->CompletionToken.Status = EFI_TIMEOUT; > >} > > > >Status = Rx6Token->CompletionToken.Status; @@ -1745,11 +1747,12 > > @@ HttpTcpReceiveBody ( > >HTTP_PROTOCOL *HttpInstance; > >EFI_TCP6_PROTOCOL *Tcp6; > >EFI_TCP6_IO_TOKEN *Rx6Token; > >EFI_TCP4_PROTOCOL *Tcp4; > >EFI_TCP4_IO_TOKEN *Rx4Token; > > - > > + > > + Status = EFI_SUCCESS; > >HttpInstance = Wrap->HttpInstance; > >Tcp4 = HttpInstance->Tcp4; > >Tcp6 = HttpInstance->T