diff options
author | David Hildenbrand <david@redhat.com> | 2023-09-06 14:04:57 +0200 |
---|---|---|
committer | David Hildenbrand <david@redhat.com> | 2023-09-19 10:23:21 +0200 |
commit | b2cccb52bd9bef2948a150d204b20119b6c3ad58 (patch) | |
tree | 17a014e68686d5418c46a8ccf975fbc612409fb0 /softmmu/physmem.c | |
parent | 9e6b9f379130c77a08c8ea67a09fc90cb30f8d09 (diff) | |
download | qemu-b2cccb52bd9bef2948a150d204b20119b6c3ad58.zip qemu-b2cccb52bd9bef2948a150d204b20119b6c3ad58.tar.gz qemu-b2cccb52bd9bef2948a150d204b20119b6c3ad58.tar.bz2 |
softmmu/physmem: Bail out early in ram_block_discard_range() with readonly files
fallocate() will fail, let's print a nicer error message.
Message-ID: <20230906120503.359863-6-david@redhat.com>
Suggested-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Diffstat (limited to 'softmmu/physmem.c')
-rw-r--r-- | softmmu/physmem.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 88482bd..c520c2a 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3482,6 +3482,16 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) */ #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 * MAP_PRIVATE/MAP_SHARED mappings. There is no easy way to |