@@ -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
@@ -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)
@@ -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;
@@ -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;
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 <guangrong.xiao@linux.intel.com> --- 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(-)