From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvkCk-0000sd-Nb for qemu-devel@nongnu.org; Mon, 09 Nov 2015 06:01:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZvkCg-0002Sh-JQ for qemu-devel@nongnu.org; Mon, 09 Nov 2015 06:01:42 -0500 Received: from mga02.intel.com ([134.134.136.20]:20052) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvkCg-0002SR-9J for qemu-devel@nongnu.org; Mon, 09 Nov 2015 06:01:38 -0500 References: <1446184587-142784-1-git-send-email-guangrong.xiao@linux.intel.com> <1446184587-142784-8-git-send-email-guangrong.xiao@linux.intel.com> <20151109122452-mutt-send-email-mst@redhat.com> From: Xiao Guangrong Message-ID: <56407B96.108@linux.intel.com> Date: Mon, 9 Nov 2015 18:55:18 +0800 MIME-Version: 1.0 In-Reply-To: <20151109122452-mutt-send-email-mst@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v6 07/33] util: introduce qemu_file_get_page_size() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: ehabkost@redhat.com, kvm@vger.kernel.org, gleb@kernel.org, mtosatti@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, imammedo@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, rth@twiddle.net On 11/09/2015 06:33 PM, Michael S. Tsirkin wrote: > On Fri, Oct 30, 2015 at 01:56:01PM +0800, Xiao Guangrong wrote: >> There are three places use the some logic to get the page size on >> the file path or file fd >> >> This patch introduces qemu_file_get_page_size() to unify the code >> >> Signed-off-by: Xiao Guangrong >> --- >> include/qemu/osdep.h | 1 + >> target-ppc/kvm.c | 21 +++------------------ >> util/oslib-posix.c | 16 ++++++++++++++++ >> util/oslib-win32.c | 5 +++++ >> 4 files changed, 25 insertions(+), 18 deletions(-) >> >> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h >> index b568424..d4dde02 100644 >> --- a/include/qemu/osdep.h >> +++ b/include/qemu/osdep.h >> @@ -302,4 +302,5 @@ int qemu_read_password(char *buf, int buf_size); >> */ >> pid_t qemu_fork(Error **errp); >> >> +size_t qemu_file_get_page_size(const char *mem_path); >> #endif >> diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c >> index ac70f08..c661f1c 100644 >> --- a/target-ppc/kvm.c >> +++ b/target-ppc/kvm.c >> @@ -308,28 +308,13 @@ static void kvm_get_smmu_info(PowerPCCPU *cpu, struct kvm_ppc_smmu_info *info) >> >> static long gethugepagesize(const char *mem_path) >> { >> - struct statfs fs; >> - int ret; >> - >> - do { >> - ret = statfs(mem_path, &fs); >> - } while (ret != 0 && errno == EINTR); >> + long size = qemu_file_get_page_size(mem_path); >> >> - if (ret != 0) { >> - fprintf(stderr, "Couldn't statfs() memory path: %s\n", >> - strerror(errno)); >> + if (!size) { >> exit(1); >> } >> >> -#define HUGETLBFS_MAGIC 0x958458f6 >> - >> - if (fs.f_type != HUGETLBFS_MAGIC) { >> - /* Explicit mempath, but it's ordinary pages */ >> - return getpagesize(); >> - } >> - >> - /* It's hugepage, return the huge page size */ >> - return fs.f_bsize; >> + return size; >> } >> >> static int find_max_supported_pagesize(Object *obj, void *opaque) >> diff --git a/util/oslib-posix.c b/util/oslib-posix.c >> index 914cef5..ad94c5a 100644 >> --- a/util/oslib-posix.c >> +++ b/util/oslib-posix.c >> @@ -360,6 +360,22 @@ static size_t fd_getpagesize(int fd) >> return getpagesize(); >> } >> >> +size_t qemu_file_get_page_size(const char *path) >> +{ >> + size_t size = 0; >> + int fd = qemu_open(path, O_RDONLY); >> + >> + if (fd < 0) { >> + fprintf(stderr, "Could not open %s.\n", path); >> + goto exit; >> + } >> + >> + size = fd_getpagesize(fd); >> + qemu_close(fd); >> +exit: >> + return size; >> +} >> + >> void os_mem_prealloc(int fd, char *area, size_t memory) >> { >> int ret; > > So this is opening the file for the sole purpose of > doing the fstatfs on it. Seems strange, just do statfs instead. > In fact, maybe we want statfs_getpagesize. It is just to reuse the code of fd_getpagesize() which already has the logic to check pagesize. > >> diff --git a/util/oslib-win32.c b/util/oslib-win32.c >> index 09f9e98..a18aa87 100644 >> --- a/util/oslib-win32.c >> +++ b/util/oslib-win32.c >> @@ -462,6 +462,11 @@ size_t getpagesize(void) >> return system_info.dwPageSize; >> } >> >> +size_t qemu_file_get_page_size(const char *path) >> +{ >> + return getpagesize(); >> +} >> + >> void os_mem_prealloc(int fd, char *area, size_t memory) >> { >> int i; > > And why is this needed on win32? It is not actually used, just make osdep.h happy which has qemu_file_get_page_size() declare. BTW, i will drop this patch for now on.