1 Star 0 Fork 109

panchenbo / qemu

forked from src-openEuler / qemu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
hugepages-hugepages-files-maybe-leftover.patch 3.15 KB
一键复制 编辑 原始数据 按行查看 历史
From 3cb1b0ce091998532a30793e3272925da4e6f3aa Mon Sep 17 00:00:00 2001
From: Jiajie Li <lijiajie11@huawei.com>
Date: Mon, 7 Feb 2022 14:31:34 +0800
Subject: [PATCH 1/2] hugepages: hugepages files maybe leftover
Before qemu uses the hugepage memory directory /dev/hugepages/libvirt/qemu/xxx,
The directory may be deleted because of the destroy virtual machine.
Cause qemu to create files directly under /dev/hugepages/libvirt/qemu/.
After the file is created, the file is not cleaned up by unlink,
and when the virtual machine is destroyed, libvirt will only clean up
/dev/hugepages/libvirt/qemu/xxx directory. After creating the hugepage file,
execute unlink to clean up the file to fix the problem.
Signed-off-by: Jinhua Cao <caojinhua1@huawei.com>
Signed-off-by: Jiajie Li <lijiajie11@huawei.com>
---
include/qemu/mmap-alloc.h | 3 +++
softmmu/physmem.c | 10 +++++++++-
util/mmap-alloc.c | 22 ++++++++++++++++++++++
3 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h
index 90d0eee705..707202e5be 100644
--- a/include/qemu/mmap-alloc.h
+++ b/include/qemu/mmap-alloc.h
@@ -1,6 +1,9 @@
#ifndef QEMU_MMAP_ALLOC_H
#define QEMU_MMAP_ALLOC_H
+#define HUGETLBFS_MAGIC 0x958458f6
+
+size_t qemu_fd_getfiletype(int fd);
size_t qemu_fd_getpagesize(int fd);
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 3524c04c2a..3b9a61448c 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -1496,7 +1496,14 @@ static int file_ram_open(const char *path,
/* @path names a file that doesn't exist, create it */
fd = open(path, O_RDWR | O_CREAT | O_EXCL, 0644);
if (fd >= 0) {
- *created = true;
+ info_report("open %s success \n", path);
+ /* if fd file type is HUGETLBFS_MAGIC, unlink it, */
+ /* in case to prevent residue after qemu killed */
+ if (qemu_fd_getfiletype(fd) == HUGETLBFS_MAGIC) {
+ unlink(path);
+ } else {
+ *created = true;
+ }
break;
}
} else if (errno == EISDIR) {
@@ -1515,6 +1522,7 @@ static int file_ram_open(const char *path,
fd = mkstemp(filename);
if (fd >= 0) {
+ info_report("mkstemp %s success \n", filename);
unlink(filename);
g_free(filename);
break;
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 893d864354..4993dd5bfa 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -29,6 +29,28 @@
#include <sys/vfs.h>
#endif
+size_t qemu_fd_getfiletype(int fd)
+{
+ struct statfs fs;
+ int ret;
+
+ if (fd != -1) {
+ do {
+ ret = fstatfs(fd, &fs);
+ } while (ret != 0 && errno == EINTR);
+
+ if (ret != 0) {
+ fprintf(stderr, "Couldn't fstatfs() fd: %s\n",
+ strerror(errno));
+ return -1;
+ }
+ return fs.f_type;
+ } else {
+ fprintf(stderr, "fd is invalid \n");
+ return -1;
+ }
+}
+
size_t qemu_fd_getpagesize(int fd)
{
#ifdef CONFIG_LINUX
--
2.27.0
1
https://gitee.com/panchenbo/qemu.git
git@gitee.com:panchenbo/qemu.git
panchenbo
qemu
qemu
master

搜索帮助