qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PULL 15/15] hostmem: no need to check for host_memory_backend_mr_inited() in alloc()
Date: Tue, 27 Nov 2018 15:36:37 +0100	[thread overview]
Message-ID: <1543329397-48407-16-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1543329397-48407-1-git-send-email-pbonzini@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

memfd_backend_memory_alloc/file_backend_memory_alloc both needlessly
are are calling host_memory_backend_mr_inited() which creates an
illusion that alloc could be called multiple times but it isn't, it's
called once from UserCreatable complete().

Suggested-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 backends/hostmem-file.c  | 24 ++++++++++++------------
 backends/hostmem-memfd.c |  4 ----
 2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 639c8d4..7cd3a2b 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -42,6 +42,9 @@ static void
 file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
 {
     HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend);
+#ifdef CONFIG_LINUX
+    gchar *path;
+#endif
 
     if (!backend->size) {
         error_setg(errp, "can't create backend with size 0");
@@ -54,18 +57,15 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
 #ifndef CONFIG_POSIX
     error_setg(errp, "-mem-path not supported on this host");
 #else
-    if (!host_memory_backend_mr_inited(backend)) {
-        gchar *path;
-        backend->force_prealloc = mem_prealloc;
-        path = object_get_canonical_path(OBJECT(backend));
-        memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
-                                 path,
-                                 backend->size, fb->align,
-                                 (backend->share ? RAM_SHARED : 0) |
-                                 (fb->is_pmem ? RAM_PMEM : 0),
-                                 fb->mem_path, errp);
-        g_free(path);
-    }
+    backend->force_prealloc = mem_prealloc;
+    path = object_get_canonical_path(OBJECT(backend));
+    memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
+                                     path,
+                                     backend->size, fb->align,
+                                     (backend->share ? RAM_SHARED : 0) |
+                                     (fb->is_pmem ? RAM_PMEM : 0),
+                                     fb->mem_path, errp);
+    g_free(path);
 #endif
 }
 
diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c
index 1c3579e..2eb9c82 100644
--- a/backends/hostmem-memfd.c
+++ b/backends/hostmem-memfd.c
@@ -44,10 +44,6 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
         return;
     }
 
-    if (host_memory_backend_mr_inited(backend)) {
-        return;
-    }
-
     backend->force_prealloc = mem_prealloc;
     fd = qemu_memfd_create(TYPE_MEMORY_BACKEND_MEMFD, backend->size,
                            m->hugetlb, m->hugetlbsize, m->seal ?
-- 
1.8.3.1

  parent reply	other threads:[~2018-11-27 14:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27 14:36 [Qemu-devel] [PULL v2 00/15] Misc patches for QEMU 3.1-rc3 Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 01/15] target/i386: kvm: add VMX migration blocker Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 02/15] cpus: run work items for all vCPUs if single-threaded Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 03/15] lsi: Reselection needed to remove pending commands from queue Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 04/15] migration: savevm: consult migration blockers Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 05/15] vmstate: constify VMStateField Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 06/15] vl: Improve error message when we can't load fw_cfg from file Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 07/15] vhost-user-bridge: fix recvmsg iovlen Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 08/15] vl.c: remove outdated comment Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 09/15] checkpatch: g_test_message does not need a trailing newline Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 10/15] target/i386: Generate #UD when applying LOCK to a register destination Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 11/15] MAINTAINERS: Add some missing entries related to accelerators Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 12/15] MAINTAINERS: Add an entry for the Firmware Configuration (fw_cfg) device Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 13/15] configure: fix elf2dmp check Paolo Bonzini
2018-11-27 14:36 ` [Qemu-devel] [PULL 14/15] hostmem-memfd: honour share=on/off property Paolo Bonzini
2018-11-27 14:36 ` Paolo Bonzini [this message]
2018-11-27 15:43 ` [Qemu-devel] [PULL v2 00/15] Misc patches for QEMU 3.1-rc3 Peter Maydell
2018-11-27 15:47   ` Laurent Vivier
2018-11-27 15:59     ` Paolo Bonzini
2018-11-27 18:36 ` Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2018-11-26 19:40 [Qemu-devel] [PULL " Paolo Bonzini
2018-11-26 19:40 ` [Qemu-devel] [PULL 15/15] hostmem: no need to check for host_memory_backend_mr_inited() in alloc() Paolo Bonzini

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=1543329397-48407-16-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).