[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 07/33] util: introduce qemu_file_get_page_size()
From: |
Xiao Guangrong |
Subject: |
[Qemu-devel] [PATCH v5 07/33] util: introduce qemu_file_get_page_size() |
Date: |
Wed, 28 Oct 2015 22:26:05 +0000 |
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 <address@hidden>
---
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 7276299..0b68a7a 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 892d2d8..32b4d1f 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 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;
--
1.8.3.1
- [Qemu-devel] [PATCH v5 00/33] implement vNVDIMM, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 02/33] acpi: add aml_sizeof, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 01/33] acpi: add aml_derefof, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 04/33] acpi: add aml_concatenate, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 03/33] acpi: add aml_create_field, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 06/33] acpi: add aml_method_serialized, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 05/33] acpi: add aml_object_type, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 07/33] util: introduce qemu_file_get_page_size(),
Xiao Guangrong <=
- [Qemu-devel] [PATCH v5 08/33] exec: allow memory to be allocated from any kind of path, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 10/33] hostmem-file: clean up memory allocation, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 09/33] exec: allow file_ram_alloc to work on file, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 11/33] hostmem-file: use whole file size if possible, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 12/33] pc-dimm: remove DEFAULT_PC_DIMMSIZE, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 15/33] stubs: rename qmp_pc_dimm_device_list.c, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 14/33] pc-dimm: drop the prefix of pc-dimm, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 13/33] pc-dimm: make pc_existing_dimms_capacity static and rename it, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 17/33] dimm: abstract dimm device from pc-dimm, Xiao Guangrong, 2015/10/28
- [Qemu-devel] [PATCH v5 18/33] dimm: get mapped memory region from DIMMDeviceClass->get_memory_region, Xiao Guangrong, 2015/10/28