mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0166-sparsify-Exit-with-error-code-3-if-fstrim-is-not-sup.patch

e76f14
From e93dd9f2736f84942e1171a61b6f6739c3242f2f Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Fri, 5 Aug 2016 12:09:59 +0100
e76f14
Subject: [PATCH] sparsify: Exit with error code 3 if fstrim is not supported
e76f14
 by the appliance.
e76f14
e76f14
This replaces the indirect exception catching from
e76f14
commit 931aec5b8846ce63b0e2b6beba5861a019b5f694 with a direct feature
e76f14
test.
e76f14
e76f14
Fixes commit 931aec5b8846ce63b0e2b6beba5861a019b5f694.
e76f14
e76f14
(cherry picked from commit 97b6b4a4ebc6f6e333ee448f61e1d6142cfffe27)
e76f14
---
e76f14
 sparsify/in_place.ml | 19 +++++++------------
e76f14
 1 file changed, 7 insertions(+), 12 deletions(-)
e76f14
e76f14
diff --git a/sparsify/in_place.ml b/sparsify/in_place.ml
e76f14
index 389ea44..5cd03ef 100644
e76f14
--- a/sparsify/in_place.ml
e76f14
+++ b/sparsify/in_place.ml
e76f14
@@ -29,7 +29,7 @@ open Cmdline
e76f14
 
e76f14
 module G = Guestfs
e76f14
 
e76f14
-let rec run disk format ignores machine_readable zeroes =
e76f14
+let run disk format ignores machine_readable zeroes =
e76f14
   (* Connect to libguestfs. *)
e76f14
   let g = open_guestfs () in
e76f14
 
e76f14
@@ -40,17 +40,6 @@ let rec run disk format ignores machine_readable zeroes =
e76f14
   Sys.set_signal Sys.sigquit (Sys.Signal_handle set_quit);
e76f14
   g#set_pgroup true;
e76f14
 
e76f14
-  try
e76f14
-    perform g disk format ignores machine_readable zeroes quit
e76f14
-  with
e76f14
-    G.Error msg as exn ->
e76f14
-      if g#last_errno () = G.Errno.errno_ENOTSUP then (
e76f14
-        (* for exit code 3, see man page *)
e76f14
-        error ~exit_code:3 (f_"discard/trim is not supported: %s") msg;
e76f14
-      )
e76f14
-      else raise exn
e76f14
-
e76f14
-and perform g disk format ignores machine_readable zeroes quit =
e76f14
   (* XXX Current limitation of the API.  Can remove this hunk in future. *)
e76f14
   let format =
e76f14
     match format with
e76f14
@@ -62,6 +51,12 @@ and perform g disk format ignores machine_readable zeroes quit =
e76f14
   if not (quiet ()) then Progress.set_up_progress_bar ~machine_readable g;
e76f14
   g#launch ();
e76f14
 
e76f14
+  (* If discard is not supported in the appliance, we must return exit
e76f14
+   * code 3.  See the man page.
e76f14
+   *)
e76f14
+  if not (g#feature_available [|"fstrim"|]) then
e76f14
+    error ~exit_code:3 (f_"discard/trim is not supported");
e76f14
+
e76f14
   (* Discard non-ignored filesystems that we are able to mount, and
e76f14
    * selected swap partitions.
e76f14
    *)
e76f14
-- 
aa0300
2.7.4
e76f14