[CRIU] Re: [PATCH 3/5] restorer: do page-size reads in a while loop

Adrian Reber adrian at lisas.de
Wed Aug 22 05:27:45 EDT 2012


On Tue, Aug 21, 2012 at 08:36:13PM +0400, Pavel Emelyanov wrote:
> On 08/21/2012 07:20 PM, Adrian Reber wrote:
> > When reading pages-*.img over a network socket using read() and size
> > PAGE_SIZE it might not always be possible to read the complete
> > PAGE_SIZE in one read(). Therefore read in while loop until PAGE_SIZE
> > has actually been read.
> > 
> > Signed-off-by: Adrian Reber <adrian at lisas.de>
> > ---
> >  restorer.c |   14 +++++++++-----
> >  1 files changed, 9 insertions(+), 5 deletions(-)
> > 
> > diff --git a/restorer.c b/restorer.c
> > index 95a7922..48011cb 100644
> > --- a/restorer.c
> > +++ b/restorer.c
> > @@ -343,6 +343,7 @@ long __export_restore_task(struct task_restore_core_args *args)
> >  	 * Read page contents.
> >  	 */
> >  	while (1) {
> > +		long i = 0;
> >  		ret = sys_read(args->fd_pages, &va, sizeof(va));
> >  		if (!ret)
> >  			break;
> > @@ -353,11 +354,14 @@ long __export_restore_task(struct task_restore_core_args *args)
> >  			goto core_restore_end;
> >  		}
> >  
> > -		ret = sys_read(args->fd_pages, (void *)va, PAGE_SIZE);
> > -		if (ret != PAGE_SIZE) {
> > -			write_num_n(__LINE__);
> > -			write_num_n(ret);
> > -			goto core_restore_end;
> > +		while (i != PAGE_SIZE) {
> > +			ret = sys_read(args->fd_pages, (void *)va, PAGE_SIZE - i);
> > +			if (ret < 0) {
> 
> Shouldn't this be "<=" to catch closed socket case.

Yes, thanks. Fixed.

		Adrian


More information about the CRIU mailing list