Projects
home:dongzhihai
qemu
_service:tar_scm:backup-memory-bakcup-hugepages...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:tar_scm:backup-memory-bakcup-hugepages-hugepages-files-maybe.patch of Package qemu
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
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2