libguestfs/SOURCES/0050-daemon-fstrim.c-Run-the-fstrim-command-twice.patch
2025-05-06 16:22:44 +03:00

41 lines
1.3 KiB
Diff

From 4c7c0bca7a433ad03cdbc9128f53a1904758f8fb Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 25 Apr 2025 15:14:24 +0100
Subject: [PATCH] daemon/fstrim.c: Run the fstrim command twice
In upstream kernels, for XFS, you may have to run fstrim twice for it
to be effective.
Fixes: https://issues.redhat.com/browse/RHEL-88508
Related: https://issues.redhat.com/browse/RHEL-88450
Thanks: Eric Sandeen
(cherry picked from commit ca87485eea79d2c8943458f8f4ff12e72ce2eb0b)
---
daemon/fstrim.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/daemon/fstrim.c b/daemon/fstrim.c
index 3928f8bb..474ef72d 100644
--- a/daemon/fstrim.c
+++ b/daemon/fstrim.c
@@ -101,8 +101,19 @@ do_fstrim (const char *path,
ADD_ARG (argv, i, buf);
ADD_ARG (argv, i, NULL);
+ /* Run the command twice to workaround
+ * https://issues.redhat.com/browse/RHEL-88450
+ */
+ r = commandv (&out, &err, argv);
+ if (r == -1) goto error;
+ if (verbose)
+ fprintf (stderr, "%s\n", out);
+ free (out); out = NULL;
+ free (err); err = NULL;
+
r = commandv (&out, &err, argv);
if (r == -1) {
+ error:
/* If the error is about the kernel operation not being supported
* for this filesystem type, then return errno ENOTSUP here.
*/