[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 13/17] util/mmap-alloc: qemu_fd_getfs()
From: |
Juan Quintela |
Subject: |
[PULL 13/17] util/mmap-alloc: qemu_fd_getfs() |
Date: |
Mon, 24 Apr 2023 13:01:15 +0200 |
From: Peter Xu <peterx@redhat.com>
This new helper fetches file system type for a fd. Only Linux is
implemented so far. Currently only tmpfs and hugetlbfs are defined,
but it can grow as needed.
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
include/qemu/mmap-alloc.h | 7 +++++++
util/mmap-alloc.c | 28 ++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h
index 2825e231a7..8344daaa03 100644
--- a/include/qemu/mmap-alloc.h
+++ b/include/qemu/mmap-alloc.h
@@ -1,8 +1,15 @@
#ifndef QEMU_MMAP_ALLOC_H
#define QEMU_MMAP_ALLOC_H
+typedef enum {
+ QEMU_FS_TYPE_UNKNOWN = 0,
+ QEMU_FS_TYPE_TMPFS,
+ QEMU_FS_TYPE_HUGETLBFS,
+ QEMU_FS_TYPE_NUM,
+} QemuFsType;
size_t qemu_fd_getpagesize(int fd);
+QemuFsType qemu_fd_getfs(int fd);
/**
* qemu_ram_mmap: mmap anonymous memory, the specified file or device.
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 5ed7d29183..ed14f9c64d 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -27,8 +27,36 @@
#ifdef CONFIG_LINUX
#include <sys/vfs.h>
+#include <linux/magic.h>
#endif
+QemuFsType qemu_fd_getfs(int fd)
+{
+#ifdef CONFIG_LINUX
+ struct statfs fs;
+ int ret;
+
+ if (fd < 0) {
+ return QEMU_FS_TYPE_UNKNOWN;
+ }
+
+ do {
+ ret = fstatfs(fd, &fs);
+ } while (ret != 0 && errno == EINTR);
+
+ switch (fs.f_type) {
+ case TMPFS_MAGIC:
+ return QEMU_FS_TYPE_TMPFS;
+ case HUGETLBFS_MAGIC:
+ return QEMU_FS_TYPE_HUGETLBFS;
+ default:
+ return QEMU_FS_TYPE_UNKNOWN;
+ }
+#else
+ return QEMU_FS_TYPE_UNKNOWN;
+#endif
+}
+
size_t qemu_fd_getpagesize(int fd)
{
#ifdef CONFIG_LINUX
--
2.39.2
- [PULL 00/17] Migration 20230420 patches, Juan Quintela, 2023/04/24
- [PULL 03/17] migration: Update atomic stats out of the mutex, Juan Quintela, 2023/04/24
- [PULL 06/17] migration: Make precopy_bytes atomic, Juan Quintela, 2023/04/24
- [PULL 02/17] migration: Merge ram_counters and ram_atomic_counters, Juan Quintela, 2023/04/24
- [PULL 07/17] migration: Make downtime_bytes atomic, Juan Quintela, 2023/04/24
- [PULL 05/17] migration: Make dirty_sync_missed_zero_copy atomic, Juan Quintela, 2023/04/24
- [PULL 12/17] migration: Handle block device inactivation failures better, Juan Quintela, 2023/04/24
- [PULL 01/17] migration: remove extra whitespace character for code style, Juan Quintela, 2023/04/24
- [PULL 09/17] migration: Make postcopy_requests atomic, Juan Quintela, 2023/04/24
- [PULL 08/17] migration: Make dirty_sync_count atomic, Juan Quintela, 2023/04/24
- [PULL 13/17] util/mmap-alloc: qemu_fd_getfs(),
Juan Quintela <=
- [PULL 10/17] migration: Rename duplicate to zero_pages, Juan Quintela, 2023/04/24
- [PULL 04/17] migration: Make multifd_bytes atomic, Juan Quintela, 2023/04/24
- [PULL 11/17] migration: Rename normal to normal_pages, Juan Quintela, 2023/04/24
- [PULL 15/17] migration/postcopy: Detect file system on dest host, Juan Quintela, 2023/04/24
- [PULL 14/17] vl.c: Create late backends before migration object, Juan Quintela, 2023/04/24
- [PULL 17/17] migration: Pass migrate_caps_check() the old and new caps, Juan Quintela, 2023/04/24
- [PULL 16/17] migration: rename enabled_capabilities to capabilities, Juan Quintela, 2023/04/24
- Re: [PULL 00/17] Migration 20230420 patches, Richard Henderson, 2023/04/24