Blame SOURCES/0167-daemon-fstrim-Turn-discard-operation-is-not-supporte.patch

e76f14
From be25e1106975afe3be160953a85e0054694eb526 Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Fri, 5 Aug 2016 12:18:53 +0100
e76f14
Subject: [PATCH] daemon: fstrim: Turn "discard operation is not supported"
e76f14
 into ENOTSUP.
e76f14
e76f14
Because we run the external fstrim command we don't have access to the
e76f14
kernel errno when it fails.  However in the case where it prints this
e76f14
specific error message, turn that into errno ENOTSUP.
e76f14
e76f14
(cherry picked from commit 116a41d04877fda40bc986abc43e98f6c787a59e)
e76f14
---
e76f14
 daemon/fstrim.c      | 8 +++++++-
e76f14
 generator/actions.ml | 4 ++++
e76f14
 2 files changed, 11 insertions(+), 1 deletion(-)
e76f14
e76f14
diff --git a/daemon/fstrim.c b/daemon/fstrim.c
e76f14
index 1ad3630..527acfd 100644
e76f14
--- a/daemon/fstrim.c
e76f14
+++ b/daemon/fstrim.c
e76f14
@@ -105,7 +105,13 @@ do_fstrim (const char *path,
e76f14
 
e76f14
   r = commandv (&out, &err, argv);
e76f14
   if (r == -1) {
e76f14
-    reply_with_error ("%s", err);
e76f14
+    /* If the error is about the kernel operation not being supported
e76f14
+     * for this filesystem type, then return errno ENOTSUP here.
e76f14
+     */
e76f14
+    if (strstr (err, "discard operation is not supported"))
e76f14
+      reply_with_error_errno (ENOTSUP, "%s", err);
e76f14
+    else
e76f14
+      reply_with_error ("%s", err);
e76f14
     return -1;
e76f14
   }
e76f14
 
e76f14
diff --git a/generator/actions.ml b/generator/actions.ml
e76f14
index a515c4c..6cadc32 100644
e76f14
--- a/generator/actions.ml
e76f14
+++ b/generator/actions.ml
e76f14
@@ -10588,6 +10588,10 @@ filesystem, the host filesystem, qemu and the host kernel.
e76f14
 If this support isn't present it may give an error or even
e76f14
 appear to run but do nothing.
e76f14
 
e76f14
+In the case where the kernel vfs driver does not support
e76f14
+trimming, this call will fail with errno set to C<ENOTSUP>.
e76f14
+Currently this happens when trying to trim FAT filesystems.
e76f14
+
e76f14
 See also C<guestfs_zero_free_space>.  That is a slightly
e76f14
 different operation that turns free space in the filesystem
e76f14
 into zeroes.  It is valid to call C<guestfs_fstrim> either
e76f14
-- 
aa0300
2.7.4
e76f14