[PATCH v2] kexec/s390x: use mmap instead of read for slurp_file()

Michael Holzheu holzheu at linux.vnet.ibm.com
Wed Oct 28 02:57:21 PDT 2015


On Wed, 28 Oct 2015 14:46:23 +0800
Dave Young <dyoung at redhat.com> wrote:

> Hi, Michael
> 
> > @@ -552,11 +563,18 @@ char *slurp_file(const char *filename, o
> >  		if (err < 0)
> >  			die("Can not seek to the begin of file %s: %s\n",
> >  					filename, strerror(errno));
> > +		buf = slurp_fd(fd, filename, size, &nread, use_mmap);
> >  	} else {
> >  		size = stats.st_size;
> > +		if (use_mmap) {
> > +			buf = mmap(NULL, size, PROT_READ | PROT_WRITE,
> > +				   MAP_PRIVATE, fd, 0);
> > +			nread = stats.st_size;
> > +		} else {
> > +			buf = slurp_fd(fd, filename, size, &nread, 0);
> > +		}
> >  	}
> 
> Drop above changes and replace below lines with an extra use_mmap argument
> should be enough?
> 
> -	buf = slurp_fd(fd, filename, size, &nread);
> [snip]

Hmm, I don't think so.

In case of non-character devices I either mmap the file directly (use_mmap=true)
or use "slurp_fd()" (use_mmap=false). So I can't unconditionaly use slurp_fd().

The change in slurp_fd() to use anonymous mmap in case of use_mmap=true is
not really necessary. I did it nevertheless for consistency. This ensures
that the slrup_file_mmap() functions *always* returns mmaped memory.

Michael




More information about the kexec mailing list