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