1 Star 0 Fork 120

Jiabo Feng/qemu

forked from src-openEuler/qemu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backup-memory-bakcup-hugepages-hugepages-files-maybe.patch 3.09 KB
一键复制 编辑 原始数据 按行查看 历史
Jiabo Feng 提交于 2024-04-01 08:48 . QEMU update to version 8.2.0-4:
From c28455a0bac4bbf171d1f19e162557377a85e96c Mon Sep 17 00:00:00 2001
From: Ming Yang <yangming73@huawei.com>
Date: Sat, 23 Mar 2024 16:32:46 +0800
Subject: [PATCH] [backup] memory: bakcup hugepages: hugepages files maybe
leftover
old info:
commit id:
3cb1b0ce091998532a30793e3272925da4e6f3aa
old messages:
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>
Signed-off-by: Ming Yang <yangming73@huawei.com>
---
include/qemu/mmap-alloc.h | 4 ++++
system/physmem.c | 9 ++++++++-
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 8344daaa03..63e4edfd2f 100644
--- a/include/qemu/mmap-alloc.h
+++ b/include/qemu/mmap-alloc.h
@@ -1,6 +1,10 @@
#ifndef QEMU_MMAP_ALLOC_H
#define QEMU_MMAP_ALLOC_H
+#define HUGETLBFS_MAGIC 0x958458f6
+
+size_t qemu_fd_getfiletype(int fd);
+
typedef enum {
QEMU_FS_TYPE_UNKNOWN = 0,
QEMU_FS_TYPE_TMPFS,
diff --git a/system/physmem.c b/system/physmem.c
index a63853a7bc..f14d64819b 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -1329,7 +1329,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) {
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index ed14f9c64d..6890ad676c 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -30,6 +30,28 @@
#include <linux/magic.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;
+ }
+}
+
QemuFsType qemu_fd_getfs(int fd)
{
#ifdef CONFIG_LINUX
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/JiaboFeng/qemu.git
git@gitee.com:JiaboFeng/qemu.git
JiaboFeng
qemu
qemu
master

搜索帮助