qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/3] hostmem: Detect and cache fs type for file hostmem


From: David Hildenbrand
Subject: Re: [PATCH 1/3] hostmem: Detect and cache fs type for file hostmem
Date: Wed, 19 Apr 2023 09:28:21 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0

On 19.04.23 00:57, Peter Xu wrote:
Detect the file system for a memory-backend-file object and cache it within
the object if possible when CONFIG_LINUX (using statfs).

Only support the two important types of memory (tmpfs, hugetlbfs) and keep
the rest as "unknown" for now.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
  backends/hostmem-file.c  | 37 ++++++++++++++++++++++++++++++++++++-
  include/sysemu/hostmem.h |  1 +
  2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 25141283c4..2484e45a11 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -18,13 +18,17 @@
  #include "sysemu/hostmem.h"
  #include "qom/object_interfaces.h"
  #include "qom/object.h"
+#ifdef CONFIG_LINUX
+#include <sys/vfs.h>
+#include <linux/magic.h>
+#endif
OBJECT_DECLARE_SIMPLE_TYPE(HostMemoryBackendFile, MEMORY_BACKEND_FILE) struct HostMemoryBackendFile {
      HostMemoryBackend parent_obj;
-
+    __fsword_t fs_type;
      char *mem_path;
      uint64_t align;
      bool discard_data;
@@ -52,6 +56,15 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error 
**errp)
          return;
      }
+#ifdef CONFIG_LINUX
+    struct statfs fs;
+    if (!statfs(fb->mem_path, &fs)) {
+        fb->fs_type = fs.f_type;
+    } else {
+        fb->fs_type = 0;
+    }
+#endif
+


Instead of using statfs, why not implement something like qemu_fd_getpagesize(), that also relies on HUGETLBFS_MAGIC already, meaning

        size_t qemu_fd_type(int fd)

which uses fstatfs() instead? As an abstraction, as Daniel suggests, use a new enum to return the type -- "0" meaning "unknown".

Then you can even avoid the caching in hostmem code and simply call it directly from uffd code.

--
Thanks,

David / dhildenb




reply via email to

[Prev in Thread] Current Thread [Next in Thread]