all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH swtpm 02/16] swtpm setup: file: always just clear header rather than unlinking
Date: Tue, 14 Oct 2025 16:39:13 +0200	[thread overview]
Message-ID: <20251014143946.160679-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20251014143946.160679-1-f.ebner@proxmox.com>

When using a FUSE export as the target file, it cannot be unlinked.
For block devices, the header is cleared, do the same for files.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/swtpm_setup/swtpm_backend_file.c | 42 +++++++++++-----------------
 1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/src/swtpm_setup/swtpm_backend_file.c b/src/swtpm_setup/swtpm_backend_file.c
index a0d0f4d..d4ca2c5 100644
--- a/src/swtpm_setup/swtpm_backend_file.c
+++ b/src/swtpm_setup/swtpm_backend_file.c
@@ -57,36 +57,28 @@ static int check_access(void *state,
     return ret == 0 || errno == ENOENT ? 0 : 1;
 }
 
-/* Delete state from file: if regular file, unlink, if blockdev, zero header so
- * swtpm binary will treat it as a new instance. */
+/* Delete state from file: zero header so swtpm binary will treat it as a new
+ * instance. */
 static int delete_state(void *state) {
     const struct file_state *fstate = (struct file_state*)state;
     int fd;
 
-    if (fstate->is_blockdev) {
-        char zerobuf[8] = {0}; /* swtpm header has 8 byte */
-        fd = open(fstate->path, O_WRONLY);
-        if (fd < 0) {
-            logerr(gl_LOGFILE, "Couldn't open file for clearing %s: %s\n",
-                   fstate->path, strerror(errno));
-            return 1;
-        }
-        /* writing less bytes than requested is bad, but won't set errno */
-        errno = 0;
-        if (write(fd, zerobuf, sizeof(zerobuf)) < (long)sizeof(zerobuf)) {
-            logerr(gl_LOGFILE, "Couldn't write file for clearing %s: %s\n",
-                   fstate->path, strerror(errno));
-            close(fd);
-            return 1;
-        }
-        close(fd);
-    } else {
-        if (unlink(fstate->path)) {
-            logerr(gl_LOGFILE, "Couldn't unlink file for clearing %s: %s\n",
-                   fstate->path, strerror(errno));
-            return 1;
-        }
+    char zerobuf[8] = {0}; /* swtpm header has 8 byte */
+    fd = open(fstate->path, O_WRONLY);
+    if (fd < 0) {
+        logerr(gl_LOGFILE, "Couldn't open file for clearing %s: %s\n",
+               fstate->path, strerror(errno));
+        return 1;
     }
+    /* writing less bytes than requested is bad, but won't set errno */
+    errno = 0;
+    if (write(fd, zerobuf, sizeof(zerobuf)) < (long)sizeof(zerobuf)) {
+        logerr(gl_LOGFILE, "Couldn't write file for clearing %s: %s\n",
+               fstate->path, strerror(errno));
+        close(fd);
+        return 1;
+    }
+    close(fd);
 
     return 0;
 }
-- 
2.47.3



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-10-14 14:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 14:39 [pve-devel] [PATCH-SERIES qemu/swtpm/storage/qemu-server 00/16] fix #4693: drive: allow non-raw image formats for TPM state drive Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu 01/16] d/rules: enable fuse Fiona Ebner
2025-10-17 13:09   ` Daniel Kral
2025-10-17 14:03     ` Fiona Ebner
2025-10-14 14:39 ` Fiona Ebner [this message]
2025-10-14 14:39 ` [pve-devel] [PATCH storage 03/16] common: add pve-vm-image-format standard option for VM image formats Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 04/16] tests: cfg2cmd: remove invalid mocking of qmp_cmd Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 05/16] migration: offline volumes: drop deprecated special casing for TPM state Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 06/16] qmp client: better abstract peer in preparation for qemu-storage-daemon Fiona Ebner
2025-10-17 12:38   ` Daniel Kral
2025-10-17 13:36     ` Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 07/16] monitor: qmp: precise error message by logging peer type Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 08/16] helpers: add functions for qemu-storage-daemon instances Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 09/16] monitor: qmp: allow 'qsd' peer type for qemu-storage-daemon Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 10/16] monitor: align interface of qmp_cmd() with other helpers Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 11/16] machine: include +pve version when getting installed machine version Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 12/16] blockdev: support attaching to qemu-storage-daemon Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 13/16] blockdev: attach: also return whether attached blockdev is read-only Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 14/16] introduce QSD module for qemu-storage-daemon functionality Fiona Ebner
2025-10-17 13:08   ` Daniel Kral
2025-10-17 14:46     ` Fiona Ebner
2025-10-20  8:47   ` Laurent GUERBY
2025-10-20  9:49     ` Fiona Ebner
2025-10-20 10:00       ` Fiona Ebner
2025-10-20 11:27       ` Laurent GUERBY
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 15/16] tpm: support non-raw volumes via FUSE exports for swtpm Fiona Ebner
2025-10-14 14:39 ` [pve-devel] [PATCH qemu-server 16/16] fix #4693: drive: allow non-raw image formats for TPM state drive Fiona Ebner
2025-10-17 13:17 ` [pve-devel] [PATCH-SERIES qemu/swtpm/storage/qemu-server 00/16] " Daniel Kral

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=20251014143946.160679-3-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal