qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: "David Hildenbrand" <david@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Thiner Logoer" <logoerthiner1@163.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Elena Ufimtseva" <elena.ufimtseva@oracle.com>,
	"Jagannathan Raman" <jag.raman@oracle.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Ani Sinha" <anisinha@redhat.com>,
	"Xiao Guangrong" <xiaoguangrong.eric@gmail.com>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Greg Kurz" <groug@kaod.org>, "Eric Blake" <eblake@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>
Subject: [PATCH v4 05/11] softmmu/physmem: Bail out early in ram_block_discard_range() with readonly files
Date: Wed,  6 Sep 2023 14:04:57 +0200	[thread overview]
Message-ID: <20230906120503.359863-6-david@redhat.com> (raw)
In-Reply-To: <20230906120503.359863-1-david@redhat.com>

fallocate() will fail, let's print a nicer error message.

Suggested-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 softmmu/physmem.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 88482bd32a..c520c2ac55 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -3481,6 +3481,16 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
              * so a userfault will trigger.
              */
 #ifdef CONFIG_FALLOCATE_PUNCH_HOLE
+            /*
+             * fallocate() will fail with readonly files. Let's print a
+             * proper error message.
+             */
+            if (rb->flags & RAM_READONLY_FD) {
+                error_report("ram_block_discard_range: Discarding RAM"
+                             " with readonly files is not supported");
+                goto err;
+
+            }
             /*
              * We'll discard data from the actual file, even though we only
              * have a MAP_PRIVATE mapping, possibly messing with other
-- 
2.41.0



  parent reply	other threads:[~2023-09-06 12:07 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06 12:04 [PATCH v4 00/11] memory-backend-file related improvements and VM templating support David Hildenbrand
2023-09-06 12:04 ` [PATCH v4 01/11] nvdimm: Reject writing label data to ROM instead of crashing QEMU David Hildenbrand
2023-09-06 12:04 ` [PATCH v4 02/11] softmmu/physmem: Distinguish between file access mode and mmap protection David Hildenbrand
2023-09-06 12:04 ` [PATCH v4 03/11] backends/hostmem-file: Add "rom" property to support VM templating with R/O files David Hildenbrand
2023-09-06 12:04 ` [PATCH v4 04/11] softmmu/physmem: Remap with proper protection in qemu_ram_remap() David Hildenbrand
2023-09-06 12:04 ` David Hildenbrand [this message]
2023-09-06 12:04 ` [PATCH v4 06/11] softmmu/physmem: Fail creation of new files in file_ram_open() with readonly=true David Hildenbrand
2023-09-06 12:04 ` [PATCH v4 07/11] softmmu/physmem: Never return directories from file_ram_open() David Hildenbrand
2023-09-07 10:31   ` Mario Casquero
2023-09-07 10:35     ` David Hildenbrand
2023-09-06 12:05 ` [PATCH v4 08/11] docs: Don't mention "-mem-path" in multi-process.rst David Hildenbrand
2023-09-06 12:05 ` [PATCH v4 09/11] docs: Start documenting VM templating David Hildenbrand
2023-09-06 12:05 ` [PATCH v4 10/11] softmmu/physmem: Hint that "readonly=on, rom=off" exists when opening file R/W for private mapping fails David Hildenbrand
2023-09-06 12:05 ` [PATCH v4 11/11] machine: Improve error message when using default RAM backend id David Hildenbrand
2023-09-11  7:41 ` [PATCH v4 00/11] memory-backend-file related improvements and VM templating support David Hildenbrand

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=20230906120503.359863-6-david@redhat.com \
    --to=david@redhat.com \
    --cc=anisinha@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=danielhb413@gmail.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=elena.ufimtseva@oracle.com \
    --cc=groug@kaod.org \
    --cc=imammedo@redhat.com \
    --cc=jag.raman@oracle.com \
    --cc=logoerthiner1@163.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=xiaoguangrong.eric@gmail.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).