From patchwork Fri Oct 30 05:56:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 7524191 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 63E5A9F327 for ; Fri, 30 Oct 2015 06:03:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7E7222081C for ; Fri, 30 Oct 2015 06:03:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 94A0C20816 for ; Fri, 30 Oct 2015 06:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758630AbbJ3GDn (ORCPT ); Fri, 30 Oct 2015 02:03:43 -0400 Received: from mga09.intel.com ([134.134.136.24]:26535 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758446AbbJ3GCF (ORCPT ); Fri, 30 Oct 2015 02:02:05 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 29 Oct 2015 23:02:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,217,1444719600"; d="scan'208";a="590813880" Received: from xiaoreal1.sh.intel.com (HELO xiaoreal1.sh.intel.com.sh.intel.com) ([10.239.48.79]) by FMSMGA003.fm.intel.com with ESMTP; 29 Oct 2015 23:02:02 -0700 From: Xiao Guangrong To: pbonzini@redhat.com, imammedo@redhat.com Cc: gleb@kernel.org, mtosatti@redhat.com, stefanha@redhat.com, mst@redhat.com, rth@twiddle.net, ehabkost@redhat.com, dan.j.williams@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, Xiao Guangrong Subject: [PATCH v6 07/33] util: introduce qemu_file_get_page_size() Date: Fri, 30 Oct 2015 13:56:01 +0800 Message-Id: <1446184587-142784-8-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1446184587-142784-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1446184587-142784-1-git-send-email-guangrong.xiao@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; 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;