From patchwork Sun Oct 11 03:52:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 528648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DE39F1402B7 for ; Sun, 11 Oct 2015 07:01:20 +1100 (AEDT) Received: from localhost ([::1]:46066 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zl0KU-0004lA-PF for incoming@patchwork.ozlabs.org; Sat, 10 Oct 2015 16:01:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zl0Hp-0008RR-OR for qemu-devel@nongnu.org; Sat, 10 Oct 2015 15:58:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zl0Ho-0003fy-N5 for qemu-devel@nongnu.org; Sat, 10 Oct 2015 15:58:33 -0400 Received: from mga03.intel.com ([134.134.136.65]:60642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zl0Ho-0003bu-HZ for qemu-devel@nongnu.org; Sat, 10 Oct 2015 15:58:32 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 10 Oct 2015 12:58:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,664,1437462000"; d="scan'208";a="661782974" Received: from xiaoreal1.sh.intel.com (HELO xiaoreal1.sh.intel.com.sh.intel.com) ([10.239.48.79]) by orsmga003.jf.intel.com with ESMTP; 10 Oct 2015 12:58:29 -0700 From: Xiao Guangrong To: pbonzini@redhat.com, imammedo@redhat.com Date: Sun, 11 Oct 2015 11:52:39 +0800 Message-Id: <1444535584-18220-8-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1444535584-18220-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1444535584-18220-1-git-send-email-guangrong.xiao@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Cc: Xiao Guangrong , ehabkost@redhat.com, kvm@vger.kernel.org, mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, dan.j.williams@intel.com, rth@twiddle.net Subject: [Qemu-devel] [PATCH v3 07/32] util: introduce qemu_file_get_page_size() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 ef21efb..9c8c0c4 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -286,4 +286,5 @@ void os_mem_prealloc(int fd, char *area, size_t sz); int qemu_read_password(char *buf, int buf_size); +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 f8ea783..ed3424e 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -306,28 +306,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 a0fcdc2..6b5c612 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -380,6 +380,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; diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 08f5a9c..1ff1fae 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;