[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 13/21] hw/uefi: add var-service-json.c + qapi for NV vars.
From: |
Gerd Hoffmann |
Subject: |
Re: [PATCH v2 13/21] hw/uefi: add var-service-json.c + qapi for NV vars. |
Date: |
Tue, 7 Jan 2025 17:16:40 +0100 |
> > + lseek(uv->jsonfd, 0, SEEK_SET);
> > + rc = write(uv->jsonfd, gstr->str, gstr->len);
> > + if (rc != gstr->len) {
> > + warn_report("%s: write error", __func__);
> > + }
> > + rc = ftruncate(uv->jsonfd, gstr->len);
> > + if (rc != 0) {
> > + warn_report("%s: ftruncate error", __func__);
> > + }
> > + fsync(uv->jsonfd);
>
> Although the fsync helps, re-writing the file in-place is a ad idea for data
> integrity on host OS crash. Especially if the new data is shorter, we would
> easily end up with a file containing old and new data making it unparsable
> (assuming the parser doesn't ignore trailing data).
I've tried to minimize the number of syscalls for the update, hoping to
also minimize the chance for corruption.
> I'd like to suggest the write to temp file + rename dance to get atomic
> replacement. The problem with that is that it hits the DAC/MAC security
> restrictions we put QEMU under :-(
Yep. If we want allow libvirt passing file handles to qemu we can't do
the rename dance.
> My next best idea is to re-arrange things thus:
>
> lseek(fd, 0)
> ftruncate(fd, 0)
> fsync(fd)
> write(fd, str)
> fsync(fd)
>
> so we should at least reduce the liklihood of getting a mix of
> old and new data - empty file is better than a mix of data.
On parse errors the complete file content is simply ignored, so it
should not make much of a difference whenever the file is empty or
corrupted.
Reorder the calls to first ftruncate then write looks reasonable.
Not sure the extra fsync makes sense.
take care,
Gerd
- [PATCH v2 07/21] hw/uefi: add var-service-auth.c, (continued)
- [PATCH v2 07/21] hw/uefi: add var-service-auth.c, Gerd Hoffmann, 2025/01/07
- [PATCH v2 06/21] hw/uefi: add var-service-vars.c, Gerd Hoffmann, 2025/01/07
- [PATCH v2 11/21] hw/uefi: add var-service-pkcs7-stub.c, Gerd Hoffmann, 2025/01/07
- [PATCH v2 08/21] hw/uefi: add var-service-policy.c, Gerd Hoffmann, 2025/01/07
- [PATCH v2 10/21] hw/uefi: add var-service-pkcs7.c, Gerd Hoffmann, 2025/01/07
- [PATCH v2 12/21] hw/uefi: add var-service-siglist.c, Gerd Hoffmann, 2025/01/07
- [PATCH v2 14/21] hw/uefi: add trace-events, Gerd Hoffmann, 2025/01/07
- [PATCH v2 15/21] hw/uefi: add UEFI_VARS to Kconfig, Gerd Hoffmann, 2025/01/07
- [PATCH v2 13/21] hw/uefi: add var-service-json.c + qapi for NV vars., Gerd Hoffmann, 2025/01/07
- [PATCH v2 17/21] hw/uefi: add uefi-vars-sysbus device, Gerd Hoffmann, 2025/01/07
- [PATCH v2 16/21] hw/uefi: add to meson, Gerd Hoffmann, 2025/01/07
- [PATCH v2 18/21] hw/uefi: add uefi-vars-isa device, Gerd Hoffmann, 2025/01/07
- [PATCH v2 20/21] docs: add uefi variable service documentation, Gerd Hoffmann, 2025/01/07
- [PATCH v2 21/21] hw/uefi: add MAINTAINERS entry, Gerd Hoffmann, 2025/01/07
- [PATCH v2 19/21] hw/arm: add uefi variable support to virt machine type, Gerd Hoffmann, 2025/01/07
- Re: [PATCH v2 00/21] hw/uefi: add uefi variable service, Daniel P . Berrangé, 2025/01/07
- Re: [PATCH v2 00/21] hw/uefi: add uefi variable service, Marc-André Lureau, 2025/01/08