qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, David Hildenbrand <david@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Juan Quintela <quintela@redhat.com>,
	Leonardo Bras Soares Passos <lsoaresp@redhat.com>
Subject: Re: [PATCH 1/3] hostmem: Detect and cache fs type for file hostmem
Date: Wed, 19 Apr 2023 08:01:34 +0100	[thread overview]
Message-ID: <ZD+RzsSiNX/lIyGI@redhat.com> (raw)
In-Reply-To: <20230418225749.1049185-2-peterx@redhat.com>

On Tue, Apr 18, 2023 at 06:57:47PM -0400, 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
> +
>      name = host_memory_backend_get_name(backend);
>      ram_flags = backend->share ? RAM_SHARED : 0;
>      ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
> @@ -181,6 +194,28 @@ static void file_backend_unparent(Object *obj)
>      }
>  }
>  
> +const char *file_memory_backend_get_fs_type(Object *obj)
> +{
> +#ifdef CONFIG_LINUX
> +    HostMemoryBackendFile *fb = (HostMemoryBackendFile *)
> +        object_dynamic_cast(obj, TYPE_MEMORY_BACKEND_FILE);
> +
> +    if (!fb) {
> +        goto out;
> +    }
> +
> +    switch (fb->fs_type) {
> +    case TMPFS_MAGIC:
> +        return "tmpfs";
> +    case HUGETLBFS_MAGIC:
> +        return "hugetlbfs";
> +    }
> +
> +out:
> +#endif
> +    return "unknown";
> +}

I rather feel this should be returning an enm, not strings, so
the caller just does a plain equality test rather than string
comparisons


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2023-04-19  7:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 22:57 [PATCH 0/3] migration/hostmem: Allow to fail early for postcopy on specific fs type Peter Xu
2023-04-18 22:57 ` [PATCH 1/3] hostmem: Detect and cache fs type for file hostmem Peter Xu
2023-04-19  7:01   ` Daniel P. Berrangé [this message]
2023-04-19  7:28   ` David Hildenbrand
2023-04-19 14:46     ` Peter Xu
2023-04-18 22:57 ` [PATCH 2/3] vl.c: Create late backends before migration object Peter Xu
2023-04-18 22:57 ` [PATCH 3/3] migration/postcopy: Detect file system on dest host Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZD+RzsSiNX/lIyGI@redhat.com \
    --to=berrange@redhat.com \
    --cc=david@redhat.com \
    --cc=lsoaresp@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).