[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 06/11] softmmu/physmem: Fail creation of new files in file
From: |
Peter Xu |
Subject: |
Re: [PATCH v3 06/11] softmmu/physmem: Fail creation of new files in file_ram_open() with readonly=true |
Date: |
Wed, 23 Aug 2023 16:22:06 -0400 |
On Wed, Aug 23, 2023 at 05:34:06PM +0200, David Hildenbrand wrote:
> Currently, if a file does not exist yet, file_ram_open() will create new
> empty file and open it writable. However, it even does that when
> readonly=true was specified.
>
> Specifying O_RDONLY instead to create a new readonly file would
> theoretically work, however, ftruncate() will refuse to resize the new
> empty file and we'll get a warning:
> ftruncate: Invalid argument
> And later eventually more problems when actually mmap'ing that file and
> accessing it.
>
> If someone intends to let QEMU open+mmap a file read-only, better
> create+resize+fill that file ahead of time outside of QEMU context.
>
> We'll now fail with:
> ./qemu-system-x86_64 \
> -object memory-backend-file,id=ram0,mem-path=tmp,readonly=true,size=1g
> qemu-system-x86_64: can't open backing store tmp for guest RAM: No such file
> or directory
>
> All use cases of readonly files (R/O NVDIMMs, VM templating) work on
> existing files, so silently creating new files might just hide user
> errors when accidentally specifying a non-existent file.
>
> Note that the only memory-backend-file will end up calling
> memory_region_init_ram_from_file() -> qemu_ram_alloc_from_file() ->
> file_ram_open().
>
> Move error reporting to the single caller.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
Acked-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
- [PATCH v3 04/11] softmmu/physmem: Remap with proper protection in qemu_ram_remap(), (continued)
- [PATCH v3 04/11] softmmu/physmem: Remap with proper protection in qemu_ram_remap(), David Hildenbrand, 2023/08/23
- [PATCH v3 02/11] softmmu/physmem: Distinguish between file access mode and mmap protection, David Hildenbrand, 2023/08/23
- [PATCH v3 07/11] softmmu/physmem: Never return directories from file_ram_open(), David Hildenbrand, 2023/08/23
- [PATCH v3 05/11] softmmu/physmem: Bail out early in ram_block_discard_range() with readonly files, David Hildenbrand, 2023/08/23
- [PATCH v3 06/11] softmmu/physmem: Fail creation of new files in file_ram_open() with readonly=true, David Hildenbrand, 2023/08/23
- Re: [PATCH v3 06/11] softmmu/physmem: Fail creation of new files in file_ram_open() with readonly=true,
Peter Xu <=
- [PATCH v3 11/11] machine: Improve error message when using default RAM backend id, David Hildenbrand, 2023/08/23
- Re:[PATCH v3 11/11] machine: Improve error message when using default RAM backend id, ThinerLogoer, 2023/08/25
- Re: [PATCH v3 11/11] machine: Improve error message when using default RAM backend id, David Hildenbrand, 2023/08/25
- Re: [PATCH v3 11/11] machine: Improve error message when using default RAM backend id, Markus Armbruster, 2023/08/25
- Re: [PATCH v3 11/11] machine: Improve error message when using default RAM backend id, David Hildenbrand, 2023/08/25
- Re: [PATCH v3 11/11] machine: Improve error message when using default RAM backend id, Markus Armbruster, 2023/08/25
- Re: [PATCH v3 11/11] machine: Improve error message when using default RAM backend id, David Hildenbrand, 2023/08/25
- Re: [PATCH v3 11/11] machine: Improve error message when using default RAM backend id, David Hildenbrand, 2023/08/25
- Re: [PATCH v3 11/11] machine: Improve error message when using default RAM backend id, Philippe Mathieu-Daudé, 2023/08/29
Re: [PATCH v3 11/11] machine: Improve error message when using default RAM backend id, Mario Casquero, 2023/08/29