Blob Blame History Raw
From be25e1106975afe3be160953a85e0054694eb526 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 5 Aug 2016 12:18:53 +0100
Subject: [PATCH] daemon: fstrim: Turn "discard operation is not supported"
 into ENOTSUP.

Because we run the external fstrim command we don't have access to the
kernel errno when it fails.  However in the case where it prints this
specific error message, turn that into errno ENOTSUP.

(cherry picked from commit 116a41d04877fda40bc986abc43e98f6c787a59e)
---
 daemon/fstrim.c      | 8 +++++++-
 generator/actions.ml | 4 ++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/daemon/fstrim.c b/daemon/fstrim.c
index 1ad3630..527acfd 100644
--- a/daemon/fstrim.c
+++ b/daemon/fstrim.c
@@ -105,7 +105,13 @@ do_fstrim (const char *path,
 
   r = commandv (&out, &err, argv);
   if (r == -1) {
-    reply_with_error ("%s", err);
+    /* If the error is about the kernel operation not being supported
+     * for this filesystem type, then return errno ENOTSUP here.
+     */
+    if (strstr (err, "discard operation is not supported"))
+      reply_with_error_errno (ENOTSUP, "%s", err);
+    else
+      reply_with_error ("%s", err);
     return -1;
   }
 
diff --git a/generator/actions.ml b/generator/actions.ml
index a515c4c..6cadc32 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -10588,6 +10588,10 @@ filesystem, the host filesystem, qemu and the host kernel.
 If this support isn't present it may give an error or even
 appear to run but do nothing.
 
+In the case where the kernel vfs driver does not support
+trimming, this call will fail with errno set to C<ENOTSUP>.
+Currently this happens when trying to trim FAT filesystems.
+
 See also C<guestfs_zero_free_space>.  That is a slightly
 different operation that turns free space in the filesystem
 into zeroes.  It is valid to call C<guestfs_fstrim> either
-- 
1.8.3.1