From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752111AbbERM6K (ORCPT ); Mon, 18 May 2015 08:58:10 -0400 Received: from mail.kernel.org ([198.145.29.136]:57731 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751288AbbERM52 (ORCPT ); Mon, 18 May 2015 08:57:28 -0400 Date: Mon, 18 May 2015 09:57:23 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Peter Zijlstra , Jiri Olsa , LKML , David Ahern , Adrian Hunter , Andi Kleen , Frederic Weisbecker , Stephane Eranian Subject: Re: [PATCH 03/40] perf tools: Introduce copyfile_offset() function Message-ID: <20150518125723.GG15972@kernel.org> References: <1431909055-21442-1-git-send-email-namhyung@kernel.org> <1431909055-21442-4-git-send-email-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1431909055-21442-4-git-send-email-namhyung@kernel.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Mon, May 18, 2015 at 09:30:18AM +0900, Namhyung Kim escreveu: > The copyfile_offset() function is to copy source data from given > offset to a destination file with an offset. It'll be used to build > an indexed data file. > > Signed-off-by: Namhyung Kim >>From looking at this patchkit before I recalled that some got Acks, from Jiri, please try to collect those :-) Doing it now, applying this patch. - Arnaldo > --- > tools/perf/util/util.c | 38 +++++++++++++++++++++++++++++--------- > tools/perf/util/util.h | 1 + > 2 files changed, 30 insertions(+), 9 deletions(-) > > diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c > index 6104afb7e1ef..0c264bc685ac 100644 > --- a/tools/perf/util/util.c > +++ b/tools/perf/util/util.c > @@ -145,11 +145,38 @@ static int slow_copyfile(const char *from, const char *to, mode_t mode) > return err; > } > > +int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size) > +{ > + void *ptr; > + loff_t pgoff; > + > + pgoff = off_in & ~(page_size - 1); > + off_in -= pgoff; > + > + ptr = mmap(NULL, off_in + size, PROT_READ, MAP_PRIVATE, ifd, pgoff); > + if (ptr == MAP_FAILED) > + return -1; > + > + while (size) { > + ssize_t ret = pwrite(ofd, ptr + off_in, size, off_out); > + if (ret < 0 && errno == EINTR) > + continue; > + if (ret <= 0) > + break; > + > + size -= ret; > + off_in += ret; > + off_out -= ret; > + } > + munmap(ptr, off_in + size); > + > + return size ? -1 : 0; > +} > + > int copyfile_mode(const char *from, const char *to, mode_t mode) > { > int fromfd, tofd; > struct stat st; > - void *addr; > int err = -1; > > if (stat(from, &st)) > @@ -166,15 +193,8 @@ int copyfile_mode(const char *from, const char *to, mode_t mode) > if (tofd < 0) > goto out_close_from; > > - addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fromfd, 0); > - if (addr == MAP_FAILED) > - goto out_close_to; > - > - if (write(tofd, addr, st.st_size) == st.st_size) > - err = 0; > + err = copyfile_offset(fromfd, 0, tofd, 0, st.st_size); > > - munmap(addr, st.st_size); > -out_close_to: > close(tofd); > if (err) > unlink(to); > diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h > index c4fe38ac8c00..8bce58b47a82 100644 > --- a/tools/perf/util/util.h > +++ b/tools/perf/util/util.h > @@ -252,6 +252,7 @@ int mkdir_p(char *path, mode_t mode); > int rm_rf(char *path); > int copyfile(const char *from, const char *to); > int copyfile_mode(const char *from, const char *to, mode_t mode); > +int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); > > s64 perf_atoll(const char *str); > char **argv_split(const char *str, int *argcp); > -- > 2.4.0